[m-rev.] for review: make java grade not imply intermodule optimisation
Peter Wang
novalazy at gmail.com
Thu Jun 11 14:41:28 AEST 2009
Bootchecked in hlc.gc. Successfully compiled and ran Mercury compiler and
minizinc tools in java grade without intermodule optimisation.
Branches: main
Make the java (and il) grade not require intermodule optimisation. It did so
because the compiler needs be able to expand out equivalence types, even if
the equivalence is defined in the implementation section of another module.
Simon had, later on, implemented a better solution, where the definitions of
abstract equivalence types are written to the _implementation_ sections of
interface files (plus supporting imports and definitions).
This change therefore just stops the java grades implying intermodule
optimisation, and fixes a couple of problems that surfaced. I also made the
changes for the il grade (untested).
compiler/equiv_type_hlds.m:
Expand out equivalence types in the cons_table part of the HLDS.
compiler/type_ctor_info.m:
Create type_ctor_infos for equivalence types even on java (and il)
as they will be referred to by generated code.
compiler/add_type.m:
Add special predicates for equivalence types even on java (and il)
as they will be referred to by RTTI structures.
compiler/hlds_code_util.m:
Delete are_equivalence_types_expanded as it is no longer used.
compiler/handle_options.m:
compiler/options.m:
tests/invalid/Mercury.options:
tests/invalid/purity/Mmakefile:
Delete the --automatic-intermodule-optimization developer option.
compiler/special_pred.m:
Fix formatting.
diff --git a/compiler/add_type.m b/compiler/add_type.m
index 2512f65..28bd068 100644
--- a/compiler/add_type.m
+++ b/compiler/add_type.m
@@ -415,22 +415,13 @@ process_type_defn(TypeCtor, TypeDefn,
!FoundError, !ModuleInfo, !Specs) :-
!.FoundError = yes
;
!.FoundError = no,
- (
- % Equivalence types are fully expanded on the IL and Java backends,
- % so the special predicates aren't required.
- are_equivalence_types_expanded(!.ModuleInfo),
- Body = hlds_eqv_type(_)
- ->
- true
- ;
- % XXX kind inference:
- % We set the kinds to `star'. This will be different when we have
- % a kind system.
- prog_type.var_list_to_type_list(map.init, Args, ArgTypes),
- construct_type(TypeCtor, ArgTypes, Type),
- add_special_preds(TVarSet, Type, TypeCtor, Body, Context, Status,
- !ModuleInfo)
- )
+ % XXX kind inference:
+ % We set the kinds to `star'. This will be different when we have
+ % a kind system.
+ prog_type.var_list_to_type_list(map.init, Args, ArgTypes),
+ construct_type(TypeCtor, ArgTypes, Type),
+ add_special_preds(TVarSet, Type, TypeCtor, Body, Context, Status,
+ !ModuleInfo)
).
% Check_foreign_type ensures that if we are generating code for a specific
diff --git a/compiler/equiv_type_hlds.m b/compiler/equiv_type_hlds.m
index 6bf0c9a..ad6fecf 100644
--- a/compiler/equiv_type_hlds.m
+++ b/compiler/equiv_type_hlds.m
@@ -74,14 +74,17 @@ replace_in_hlds(!ModuleInfo) :-
module_info_set_type_table(Types, !ModuleInfo),
module_info_set_maybe_recompilation_info(MaybeRecompInfo, !ModuleInfo),
- InstCache0 = map.init,
-
module_info_get_inst_table(!.ModuleInfo, Insts0),
- replace_in_inst_table(EqvMap, Insts0, Insts, InstCache0, InstCache1),
+ InstCache0 = map.init,
+ replace_in_inst_table(EqvMap, Insts0, Insts, InstCache0, InstCache),
module_info_set_inst_table(Insts, !ModuleInfo),
+ module_info_get_cons_table(!.ModuleInfo, ConsTable0),
+ replace_in_cons_table(EqvMap, ConsTable0, ConsTable),
+ module_info_set_cons_table(ConsTable, !ModuleInfo),
+
module_info_predids(PredIds, !ModuleInfo),
- list.foldl2(replace_in_pred(EqvMap), PredIds, !ModuleInfo, InstCache1, _).
+ list.foldl2(replace_in_pred(EqvMap), PredIds, !ModuleInfo, InstCache, _).
:- pred add_type_to_eqv_map(type_ctor::in, hlds_type_defn::in,
eqv_map::in, eqv_map::out, set(type_ctor)::in, set(type_ctor)::out)
@@ -289,6 +292,42 @@ replace_in_maybe_inst_det(EqvMap,
inst_det_known(Inst0, Det),
varset.init(TVarSet),
replace_in_inst(EqvMap, Inst0, Inst, _, TVarSet, _, !Cache).
+%-----------------------------------------------------------------------------%
+
+:- pred replace_in_cons_table(eqv_map::in, cons_table::in, cons_table::out)
+ is det.
+
+replace_in_cons_table(EqvMap, !ConsTable) :-
+ map.map_values(replace_in_cons_defns(EqvMap), !ConsTable).
+
+:- pred replace_in_cons_defns(eqv_map::in, cons_id::in,
+ list(hlds_cons_defn)::in, list(hlds_cons_defn)::out) is det.
+
+replace_in_cons_defns(EqvMap, _ConsId, !ConsDefns) :-
+ list.map(replace_in_cons_defn(EqvMap), !ConsDefns).
+
+:- pred replace_in_cons_defn(eqv_map::in,
+ hlds_cons_defn::in, hlds_cons_defn::out) is det.
+
+replace_in_cons_defn(EqvMap, ConsDefn0, ConsDefn) :-
+ ConsDefn0 = hlds_cons_defn(TypeCtor, TVarSet0, TypeParams, KindMap,
+ ExistQTVars, ProgConstraints, ConstructorArgs0, Context),
+ list.map_foldl(replace_in_constructor_arg(EqvMap),
+ ConstructorArgs0, ConstructorArgs, TVarSet0, TVarSet),
+ ConsDefn = hlds_cons_defn(TypeCtor, TVarSet, TypeParams, KindMap,
+ ExistQTVars, ProgConstraints, ConstructorArgs, Context).
+
+:- pred replace_in_constructor_arg(eqv_map::in,
+ constructor_arg::in, constructor_arg::out,
+ tvarset::in, tvarset::out) is det.
+
+replace_in_constructor_arg(EqvMap, CtorArg0, CtorArg, !TVarSet) :-
+ CtorArg0 = ctor_arg(MaybeFieldName, Type0, Context),
+ replace_in_type(EqvMap, Type0, Type, _Changed, !TVarSet, no, _),
+ CtorArg = ctor_arg(MaybeFieldName, Type, Context).
+
+%-----------------------------------------------------------------------------%
+
:- pred replace_in_pred(eqv_map::in, pred_id::in,
module_info::in, module_info::out,
inst_cache::in, inst_cache::out) is det.
diff --git a/compiler/handle_options.m b/compiler/handle_options.m
index f5c1b16..161669f 100644
--- a/compiler/handle_options.m
+++ b/compiler/handle_options.m
@@ -479,10 +479,6 @@ postprocess_options_2(OptionTable0, Target,
GC_Method, TagsMethod0,
TagsMethod = TagsMethod0
),
- globals.lookup_bool_option(!.Globals, highlevel_data, HighLevelData),
- globals.lookup_bool_option(!.Globals,
- automatic_intermodule_optimization, AutoIntermodOptimization),
-
% Implicit parallelism requires feedback information, however this
% error should only be shown in a parallel grade, otherwise implicit
% parallelism should be disabled.
@@ -550,14 +546,6 @@ postprocess_options_2(OptionTable0, Target,
GC_Method, TagsMethod0,
% --high-level-data. But this has been (mostly?) fixed now.
% So we should investigate re-enabling static ground terms.
% Currently mlds_to_il.m doesn't support them yet?
- % - intermodule optimization
- % This is only required for high-level data and is needed
- % so that abstract equivalence types can be expanded. They
- % need to be expanded because .NET requires that the structural
- % representation of a type is known at all times.
- % - dead procedure optimization
- % intermodule optimization pulls in a lot of code which isn't
- % needed, so ensure that this dead code is removed.
% - no library grade installation check with `mmc --make'.
(
@@ -579,17 +567,6 @@ postprocess_options_2(OptionTable0, Target,
GC_Method, TagsMethod0,
globals.set_option(static_ground_cells, bool(no), !Globals),
globals.set_option(libgrade_install_check, bool(no), !Globals),
- (
- HighLevelData = yes,
- AutoIntermodOptimization = yes
- ->
- globals.set_option(intermodule_optimization, bool(yes),
- !Globals),
- globals.set_option(optimize_dead_procs, bool(yes), !Globals)
- ;
- true
- ),
-
% On the .NET backend we will be using a language independent
% debugger not mdb. Thus --debug has to imply --target-debug.
( given_trace_level_is_none(TraceLevel) = no ->
@@ -652,14 +629,6 @@ postprocess_options_2(OptionTable0, Target,
GC_Method, TagsMethod0,
% XXX Previously static ground terms used to not work with
% --high-level-data. But this has been (mostly?) fixed now.
% So we should investigate re-enabling static ground terms.
- % - intermodule optimization
- % This is only required for high-level data and is needed
- % so that abstract equivalence types can be expanded. They
- % need to be expanded because Java requires that the structural
- % representation of a type is known at all times.
- % - dead procedure optimization
- % intermodule optimization pulls in a lot of code which isn't
- % needed, so ensure that this dead code is removed.
% - no library grade installation check with `mmc --make'.
% - no pretest equality check
% Because it assumes pointers can be cast to integers.
@@ -682,16 +651,7 @@ postprocess_options_2(OptionTable0, Target,
GC_Method, TagsMethod0,
globals.set_option(static_ground_cells, bool(no), !Globals),
globals.set_option(put_nondet_env_on_heap, bool(yes), !Globals),
globals.set_option(libgrade_install_check, bool(no), !Globals),
- globals.set_option(should_pretest_equality, bool(no), !Globals),
-
- (
- AutoIntermodOptimization = yes,
- globals.set_option(intermodule_optimization, bool(yes),
- !Globals),
- globals.set_option(optimize_dead_procs, bool(yes), !Globals)
- ;
- AutoIntermodOptimization = no
- )
+ globals.set_option(should_pretest_equality, bool(no), !Globals)
;
( Target = target_c
; Target = target_il
diff --git a/compiler/hlds_code_util.m b/compiler/hlds_code_util.m
index d99f35d..2b04552 100644
--- a/compiler/hlds_code_util.m
+++ b/compiler/hlds_code_util.m
@@ -24,10 +24,6 @@
%-----------------------------------------------------------------------------%
- % Are equivalence types fully expanded on this backend?
- %
-:- pred are_equivalence_types_expanded(module_info::in) is semidet.
-
% Find out how a function symbol (constructor) is represented
% in the given type.
%
@@ -65,17 +61,6 @@
%-----------------------------------------------------------------------------%
-are_equivalence_types_expanded(ModuleInfo) :-
- module_info_get_globals(ModuleInfo, Globals),
- globals.lookup_bool_option(Globals, highlevel_data, HighLevelData),
- HighLevelData = yes,
- globals.get_target(Globals, Target),
- ( Target = target_il
- ; Target = target_java
- ).
-
-%-----------------------------------------------------------------------------%
-
cons_id_to_tag(ModuleInfo, Type, ConsId) = Tag:-
(
ConsId = int_const(I),
diff --git a/compiler/options.m b/compiler/options.m
index d745a55..ee8b749 100644
--- a/compiler/options.m
+++ b/compiler/options.m
@@ -569,7 +569,6 @@
; opt_space % Default is to optimize time.
; intermodule_optimization
; read_opt_files_transitively
- ; automatic_intermodule_optimization
; use_opt_files
; use_trans_opt_files
; transitive_optimization
@@ -1376,7 +1375,6 @@ option_defaults_2(special_optimization_option, [
opt_space - special,
intermodule_optimization - bool(no),
read_opt_files_transitively - bool(yes),
- automatic_intermodule_optimization - bool(yes),
use_opt_files - bool(no),
use_trans_opt_files - bool(no),
transitive_optimization - bool(no),
@@ -2207,10 +2205,6 @@ long_option("intermod-opt",
intermodule_optimization).
long_option("intermodule-optimization", intermodule_optimization).
long_option("intermodule-optimisation", intermodule_optimization).
long_option("read-opt-files-transitively", read_opt_files_transitively).
-long_option("automatic-intermodule-optimization",
- automatic_intermodule_optimization).
-long_option("automatic-intermodule-optimisation",
- automatic_intermodule_optimization).
long_option("use-opt-files", use_opt_files).
long_option("use-trans-opt-files", use_trans_opt_files).
long_option("transitive-intermodule-optimization",
@@ -4581,12 +4575,6 @@ options_help_optimization -->
"\tOnly read the inter-module optimization information",
"\tfor directly imported modules, not the transitive",
"\tclosure of the imports.",
- /* Developer only option
- ** Used in tests/invalid/Mercury.options
- "--no-automatic-intermodule-optimization",
- "\tDon't automatically enable intermodule optimization for"
- "\tthose backends which require it.",
- */
"--use-opt-files",
"\tPerform inter-module optimization using any",
"\t`.opt' files which are already built,",
diff --git a/compiler/special_pred.m b/compiler/special_pred.m
index ecb9259..9fe27be 100644
--- a/compiler/special_pred.m
+++ b/compiler/special_pred.m
@@ -300,7 +300,10 @@
is_builtin_type_special_preds_defined_in_mercury(TypeCtor, TypeName)
:-
compiler_generated_rtti_for_builtins(ModuleInfo) :-
module_info_get_globals(ModuleInfo, Globals),
globals.get_target(Globals, Target),
- ( Target = target_il ; Target = target_java ; Target = target_erlang ).
+ ( Target = target_il
+ ; Target = target_java
+ ; Target = target_erlang
+ ).
%-----------------------------------------------------------------------------%
diff --git a/compiler/type_ctor_info.m b/compiler/type_ctor_info.m
index bbb36d0..acf64c9 100644
--- a/compiler/type_ctor_info.m
+++ b/compiler/type_ctor_info.m
@@ -150,21 +150,19 @@ gen_type_ctor_gen_infos([TypeCtor | TypeCtors],
TypeTable, ModuleName,
unexpected(this_file, Msg)
).
- % Should we create a type_ctor_info for the given type constructor?
- % The answer is yes, with four exceptions:
+ % Check if we should generate a type_ctor_info for this type.
+ % These are the cases that we have to check:
%
% - The builtin types which have no hlds_type_defn
% (i.e. no declaration and no definition).
%
- % - The builtin types which have a fake type body and as such have to have
- % hand-defined RTTI (types such as private_builtin.type_info which is
- % defined as a discriminated union type).
- %
% - The builtin types which are declared abstract and are not defined
% (i.e. they have a declaration, but no definition).
%
- % - All the rest of the types (types with a definition, or both a
- % declaration and a definition). XXX This "explanation" does make sense.
+ % - The builtin types which have a fake type body and as such have to have
+ % hand-defined RTTI.
+ %
+ % - All the rest of the types.
%
:- pred create_type_ctor_gen(module_info::in, type_table::in, type_ctor::in,
module_name::in, string::in, int::in, hlds_type_defn::out) is semidet.
@@ -195,13 +193,7 @@ create_type_ctor_gen(ModuleInfo, TypeTable,
TypeCtor, TypeModuleName,
impl_type_ctor(ModuleNameString, TypeName, TypeArity, _)
)
;
- % All the other types.
- \+ type_ctor_has_hand_defined_rtti(TypeCtor, TypeBody),
- (
- are_equivalence_types_expanded(ModuleInfo)
- =>
- TypeBody \= hlds_eqv_type(_)
- )
+ true
)
).
diff --git a/tests/invalid/Mercury.options b/tests/invalid/Mercury.options
index 9c992e5..1e9fb2c 100644
--- a/tests/invalid/Mercury.options
+++ b/tests/invalid/Mercury.options
@@ -9,47 +9,31 @@ MCFLAGS-any_mode = --infer-types
# were imported in the interface or the implementation. The error
# is reported correctly when building the `.opt' file.
MCFLAGS-assert_in_interface = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization \
--verbose-error-messages
-MCFLAGS-actual_expected = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-children = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
+MCFLAGS-actual_expected = --no-intermodule-optimization
+MCFLAGS-children = --no-intermodule-optimization
MCFLAGS-duplicate_modes = --verbose-error-messages
MCFLAGS-ee_invalid = --verbose-error-messages
-MCFLAGS-exported_mode = --infer-all --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-exported_unify = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-exported_unify3 = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
+MCFLAGS-exported_mode = --infer-all --no-intermodule-optimization
+MCFLAGS-exported_unify = --no-intermodule-optimization
+MCFLAGS-exported_unify3 = --no-intermodule-optimization
MCFLAGS-foreign_decl_line_number = --no-errorcheck-only
--line-numbers --compile-only
MCFLAGS-foreign_enum_invalid = --verbose-error-messages
MCFLAGS-foreign_type_line_number = --no-errorcheck-only
--line-numbers --compile-only
-MCFLAGS-foreign_type_missing = --grade il --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
+MCFLAGS-foreign_type_missing = --grade il --no-intermodule-optimization
MCFLAGS-foreign_singleton = --halt-at-warn
MCFLAGS-foreign_type = --compile-only
-MCFLAGS-foreign_type_2 = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-foreign_type_visibility = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-ii_parent = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-ii_parent.ii_child = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
+MCFLAGS-foreign_type_2 = --no-intermodule-optimization
+MCFLAGS-foreign_type_visibility = --no-intermodule-optimization
+MCFLAGS-ii_parent = --no-intermodule-optimization
+MCFLAGS-ii_parent.ii_child = --no-intermodule-optimization
MCFLAGS-illtyped_compare = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization \
--verbose-error-messages
-MCFLAGS-import_in_parent = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-import_in_parent.sub = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-imported_mode = --infer-all --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
+MCFLAGS-import_in_parent = --no-intermodule-optimization
+MCFLAGS-import_in_parent.sub = --no-intermodule-optimization
+MCFLAGS-imported_mode = --infer-all --no-intermodule-optimization
MCFLAGS-impure_method_impl = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization \
--verbose-error-messages
MCFLAGS-invalid_event = --event-set-file-name invalid_event_spec
MCFLAGS-invalid_mllibs = --no-errorcheck-only --no-verbose-make \
@@ -59,21 +43,17 @@ MCFLAGS-instance_var_bug = --verbose-error-messages
MCFLAGS-loopcheck = --warn-inferred-erroneous \
--verbose-error-messages
MCFLAGS-method_impl = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization \
--verbose-error-messages
MCFLAGS-missing_det_decls = --no-infer-det --verbose-error-messages
MCFLAGS-missing_interface_import = --make-interface
-MCFLAGS-missing_interface_import2 = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-missing_parent_import = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
+MCFLAGS-missing_interface_import2 = --no-intermodule-optimization
+MCFLAGS-missing_parent_import = --no-intermodule-optimization
MCFLAGS-mode_inf = --infer-all --verbose-error-messages
MCFLAGS-mpj1 = --infer-all --verbose-error-messages
MCFLAGS-multisoln_func = --infer-types --verbose-error-messages
MCFLAGS-no_exports = --halt-at-warn --verbose-error-messages
MCFLAGS-nonexistent_import = --no-verbose-make --make nonexistent_import
-MCFLAGS-overloading = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
+MCFLAGS-overloading = --no-intermodule-optimization
MCFLAGS-pragma_c_code_no_det = --warn-inferred-erroneous
MCFLAGS-record_syntax_errors = --verbose-error-messages
MCFLAGS-string_format_bad = --halt-at-warn --warn-known-bad-format-calls \
@@ -81,8 +61,7 @@ MCFLAGS-string_format_bad = --halt-at-warn
--warn-known-bad-format-calls \
MCFLAGS-string_format_unknown = --halt-at-warn --warn-known-bad-format-calls \
--warn-unknown-format-calls
MCFLAGS-sub_c = --verbose-error-messages \
- --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
+ --no-intermodule-optimization
MCFLAGS-synth_attr_error = --event-set-file-name synth_attr_error_spec
MCFLAGS-syntax_error_event = --event-set-file-name syntax_error_event_spec
@@ -91,25 +70,16 @@ MCFLAGS-syntax_error_event = --event-set-file-name
syntax_error_event_spec
MCFLAGS-trailed_mutable = --no-use-trail
MCFLAGS-test_nested = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization \
--verbose-error-messages
-MCFLAGS-transitive_import = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-transitive_import2 = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-transitive_import_class = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-transitive_import_class2 = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-transitive_import_class3 = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
+MCFLAGS-transitive_import = --no-intermodule-optimization
+MCFLAGS-transitive_import2 = --no-intermodule-optimization
+MCFLAGS-transitive_import_class = --no-intermodule-optimization
+MCFLAGS-transitive_import_class2 = --no-intermodule-optimization
+MCFLAGS-transitive_import_class3 = --no-intermodule-optimization
MCFLAGS-typeclass_mode = --infer-all
-MCFLAGS-undef_mod_qual = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-undef_symbol = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
-MCFLAGS-unresolved_overloading = --no-intermodule-optimization \
- --no-automatic-intermodule-optimization
+MCFLAGS-undef_mod_qual = --no-intermodule-optimization
+MCFLAGS-undef_symbol = --no-intermodule-optimization
+MCFLAGS-unresolved_overloading = --no-intermodule-optimization
# Include the verbose part of the error message where we have one.
#
diff --git a/tests/invalid/purity/Mmakefile b/tests/invalid/purity/Mmakefile
index 434e4a3..7901702 100644
--- a/tests/invalid/purity/Mmakefile
+++ b/tests/invalid/purity/Mmakefile
@@ -31,7 +31,7 @@ include $(TESTS_DIR)/Mmake.common
# than when compiling the main module. So we disable intermodule optimization
# for these tests.
override EXTRA_MCFLAGS += \
- --no-intermodule-optimization --no-automatic-intermodule-optimization
+ --no-intermodule-optimization
# Module-specific options should go in Mercury.options so they
# can be found by `mmc --make'.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list