mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 21:03:53 +00:00
083d376e6598628362ee91c2da170febd83590f4
43 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
f355497087 |
Delete include context maps from parse_tree_int[012].
compiler/prog_item.m:
We used to record information about include declarations
in parse_tree_int[012] in two forms:
- as a pair of maps from module names to contexts (one each for
includes in the interface and implementation sections), and
- as a single map from module names to an include_module_info, which
recorded the section of its appearance along with its context.
The second of these data structures is derived from the first,
in a process that can result in the generation of diagnostic messages.
In the absence of any issues reported by these diagnostics, the two forms
contain the same information.
Avoid this redundancy by keeping only the second form in the parse trees
of .int0, .int and .int2 files. (.int3 files cannot contain include_module
declarations.)
Since .int2 files may contain include_module declarations only in
the interface section, change the representation of the second form
to a type that expresses this invariant: int_include_module_map,
which is a subtype of the existing type include_module_map.
compiler/comp_unit_interface.m:
compiler/convert_parse_tree.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/parse_tree_out.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
Conform to the change above.
compiler/item_util.m:
Add a utility predicate for use by new code above.
|
||
|
|
5ae7d25740 |
Delete import/use context maps from parse_tree_int[012].
compiler/prog_item.m:
We used to record information about import and use declarations
in parse_tree_int[012] in two forms:
- as a quartet of maps from module names to contexts (one each for
int imports, int uses, imp imports and imp uses), and
- as a single map from module names to a section_import_and_or_use,
which recorded the section and kind (import or use) of its appearance
along with its one context, except for the case of modules that have
an use_module declaration in the interface section and an import_module
declaration in the implementation section.
The second of these data structures is derived from the first,
in a process that can result in the generation of diagnostic messages.
In the absence of any issues reported by these diagnostics, the two forms
contain the same information.
Avoid this redundancy by keeping only the second form in the parse trees
of .int0, .int and .int2 files. (For .int3 files, which can contain
only import_modules, and only in the interface section, this redundancy
has not been present even before now.)
Since .int and .int2 files may contain only use_module declarations
and not import_module declarations, change the representation of the
second form to a type that expresses this invariant: the new type
section_use_map, which is a subtype of the existing type
section_import_and_or_use_map.
For .int2 files, we could use an even tighter type right now, but
a fix for Mantis bug #563 would have to undo such a change, so
don't bother.
compiler/comp_unit_interface.m:
Delete the code that used to construct the first form above
for these interface file kinds. Conform to the changes above.
compiler/convert_parse_tree.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/parse_tree_out.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
Conform to the changes above.
compiler/item_util.m:
Add new, specialized versions of existing utility predicates
to make that conformance possible.
|
||
|
|
faf9ebf5e3 |
Don't provide for implicit imports in .intN parse trees.
compiler/prog_item.m:
The ptiN_import_use_map fields in the representations of .int0, .int
and .int2 files had the same type as the ptms_import_use_map field
in the parse trees of .m files, which is where they were derived from.
However, while the ptms_import_use_map field needs to be able to represent
implicit imports, the parse trees of .int0, .int and .int2 files
should never include any implicit imports, and in fact any implicit
imports in these fields were already ignored.
Encode the invariant that interface files never include implicit imports
in the types of these fields.
compiler/comp_unit_interface.m:
Discard the implicit part of the source file's import_and_or_use_map
when computing the contents of .int0, .int and .int2 files.
compiler/item_util.m:
Provide the facilities used by the updated code in the modules above.
compiler/convert_parse_tree.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
Conform to the changes above.
|
||
|
|
ea4f95a7ed |
Use var_tables in lco.m, and when dumping goals.
Since this is the first converted module that dumps out goals when
debugging trace flags are enabled, this required generalizing the code
that does that, to take either varsets or var_tables as a means of
specifying the names of variables. We do this via a new type,
var_name_source, which contains either a varset or a var_table.
Almost all of this diff is there to implement this generalization.
A large part of it affects code in the parse_tree package that we use
to write out the parts of HLDS goals that are defined by types defined
in that package. Since we want to avoid making any part of the parse_tree
package dependent on the hlds package, this required defining the
var_name_source type in the parse_tree package, which in turn requires
var_table.m to be in that same package.
compiler/lco.m:
Convert this module to use var_tables instead of varsets and vartypes.
compiler/var_table.m:
Move this module from the hlds package to the parse_tree package.
To make this, possible, move the parts that required access to the HLDS
to hlds_pred.m, from where it was usually invoked.
Export some utility predicates to allow the moved code to work
in hlds_pred.m without access to the actual definition of the
var_table type.
Define the var_name_source type.
Add some utility functions for use by code writing out variable names.
compiler/hlds_pred.m:
Add the code moved from var_table.m.
compiler/vartypes.m:
Move this module from the hlds package to the parse_tree package,
for symmetry with var_table.m. It did not depend on being in hlds
in any way.
compiler/hlds.m:
compiler/parse_tree.m:
Move vartypes.m and var_table.m from the hlds package
to the parse_tree package.
compiler/hlds_out_goal.m:
Change all the predicates in this module to take a var_name_source
instead of a prog_varset.
Fix some comments.
compiler/hlds_out_util.m:
Change some of the predicates in this module (those called from
hlds_out_goal.m) to take a var_name_source instead of a prog_varset.
compiler/parse_tree_out_term.m:
Provide variants of some existing predicates and functions that take
var_name_sources instead of varsets. The code of the copies
duplicates the logic of the originals, though I hope that this
duplication can be done away with at the end of the transition.
(The best solution would be to use a typeclass with methods
that convert vars to their names, but we would want to ensure
that the compiler can specialize all the affected predicates
and functions to the two instances of this typeclass, which is
something that we cannot do yet. In the meantime, the lack of
any generalization in the old versions preserves their performance.)
tools/sort_imports:
tools/filter_sort_imports:
A new tool that automatically sorts any occurrences of consecutive
":- import_module" declarations in the named files. The sorting is done
in filter_sort_imports; sort_imports loops over the named files.
After automatically replacing all occurrences of hlds.{vartypes,var_table}
in import_module declarations with their parse_tree versions, the updated
import_module declarations were usually out of order with respect to
their neighbours. I used this script to fix that, and some earlier
out-of-order imports.
compiler/accumulator.m:
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_heap_ops.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_trail_ops.m:
compiler/analysis.m:
compiler/arg_info.m:
compiler/build_mode_constraints.m:
compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/check_promise.m:
compiler/closure_analysis.m:
compiler/closure_gen.m:
compiler/code_info.m:
compiler/code_loc_dep.m:
compiler/common.m:
compiler/compile_target_code.m:
compiler/complexity.m:
compiler/const_prop.m:
compiler/constraint.m:
compiler/continuation_info.m:
compiler/convert_parse_tree.m:
compiler/coverage_profiling.m:
compiler/cse_detection.m:
compiler/ctgc.datastruct.m:
compiler/ctgc.util.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/direct_arg_in_out.m:
compiler/disj_gen.m:
compiler/distance_granularity.m:
compiler/equiv_type_hlds.m:
compiler/exception_analysis.m:
compiler/file_names.m:
compiler/float_regs.m:
compiler/follow_vars.m:
compiler/format_call.m:
compiler/generate_dep_d_files.m:
compiler/get_dependencies.m:
compiler/goal_expr_to_goal.m:
compiler/goal_mode.m:
compiler/goal_path.m:
compiler/goal_store.m:
compiler/goal_util.m:
compiler/granularity.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_clauses.m:
compiler/hlds_code_util.m:
compiler/hlds_error_util.m:
compiler/hlds_goal.m:
compiler/hlds_llds.m:
compiler/hlds_out_pred.m:
compiler/hlds_rtti.m:
compiler/hlds_statistics.m:
compiler/inlining.m:
compiler/inst_check.m:
compiler/inst_test.m:
compiler/inst_user.m:
compiler/instance_method_clauses.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/intermod_analysis.m:
compiler/interval.m:
compiler/introduce_exists_casts.m:
compiler/introduce_parallelism.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/llds.m:
compiler/llds_out_data.m:
compiler/llds_out_file.m:
compiler/llds_out_util.m:
compiler/lookup_switch.m:
compiler/loop_inv.m:
compiler/make.module_target.m:
compiler/make.util.m:
compiler/make_goal.m:
compiler/make_hlds_separate_items.m:
compiler/make_hlds_types.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/middle_rec.m:
compiler/ml_accurate_gc.m:
compiler/ml_args_util.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_commit_gen.m:
compiler/ml_disj_gen.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_gen_info.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/ml_unify_gen.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
compiler/mlds_to_c_data.m:
compiler/mlds_to_c_func.m:
compiler/mlds_to_c_global.m:
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_stmt.m:
compiler/mlds_to_java_type.m:
compiler/mmc_analysis.m:
compiler/mode_comparison.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/mode_ordering.m:
compiler/modecheck_call.m:
compiler/modecheck_coerce.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/module_cmds.m:
compiler/old_type_constraints.m:
compiler/opt_debug.m:
compiler/optimize.m:
compiler/options_file.m:
compiler/ordering_mode_constraints.m:
compiler/par_loop_control.m:
compiler/parse_item.m:
compiler/parse_string_format.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_to_term.m:
compiler/parse_util.m:
compiler/pd_debug.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/peephole.m:
compiler/polymorphism.m:
compiler/polymorphism_info.m:
compiler/polymorphism_lambda.m:
compiler/polymorphism_type_class_info.m:
compiler/polymorphism_type_info.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/pred_name.m:
compiler/pred_table.m:
compiler/prog_item.m:
compiler/prog_rep.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/push_goals_together.m:
compiler/qual_info.m:
compiler/quantification.m:
compiler/rbmm.execution_path.m:
compiler/rbmm.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.points_to_graph.m:
compiler/rbmm.points_to_info.m:
compiler/rbmm.region_resurrection_renaming.m:
compiler/rbmm.region_transformation.m:
compiler/recompilation.used_file.m:
compiler/recompilation.version.m:
compiler/recompute_instmap_deltas.m:
compiler/resolve_unify_functor.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/saved_vars.m:
compiler/set_of_var.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_conj.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_ite.m:
compiler/simplify_goal_scope.m:
compiler/simplify_goal_switch.m:
compiler/simplify_goal_unify.m:
compiler/simplify_info.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/smm_common.m:
compiler/ssdebug.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/stack_opt.m:
compiler/stm_expand.m:
compiler/store_alloc.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.domain.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.lbu.m:
compiler/structure_reuse.lfu.m:
compiler/structure_sharing.analysis.m:
compiler/structure_sharing.domain.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_constr_build.m:
compiler/term_constr_data.m:
compiler/term_constr_initial.m:
compiler/term_constr_main.m:
compiler/term_constr_main_types.m:
compiler/term_constr_util.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/term_util.m:
compiler/trace_gen.m:
compiler/trailing_analysis.m:
compiler/transform_llds.m:
compiler/try_expand.m:
compiler/tupling.m:
compiler/type_assign.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_debug.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unify_gen_construct.m:
compiler/unify_gen_deconstruct.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/var_locn.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
|
||
|
|
05b806ea9f | Delete an already-addressed XXX. | ||
|
|
f80261cd00 |
Put the include_module_map into the module_info.
compiler/hlds_module.m:
Add this slot in the module_info.
Get the caller of module_info_init specify the value of this new field,
as well as another field whose value is known at module_info_init time
(see below).
compiler/make_hlds_separate_items.m:
Return the include_module_map from the parse tree of the augmented module.
compiler/make_hlds_passes.m:
Pass the include_module_map to the predicate that initializes
the module_info. Move the call to that predicate so that has
the same position in the text as in the dataflow order.
|
||
|
|
068fc20006 |
Improve error management in convert_parse_tree.m.
compiler/hlds_module.m:
compiler/prog_item.m:
Record the identity of predicates and functions that have misplaced
attempts at definition in the interface section using the
pred_pf_name_arity type instead of the pf_sym_name_arity type.
They both specify an arity, but only in pred_pf_name_arity is it clear
*which kind* of arity this is.
compiler/convert_parse_tree.m:
Record external declarations and foreign_procs in the interface
as misplaced attempts at predicate or function definition using
pred_pf_name_arity, so that the code obviously has no arity bugs,
whereas the old code merely had no obvious bugs. (It did actually work.)
Record fact_table pragmas in the interface as similar misplaced attempts
as predicate or function definition, *if* the pragma contains
a pred_or_func indication.
Factor out some common code.
compiler/hlds_pred.m:
Add predicates to return a pred_info's arity as pred_form_arity
and as user_arity.
compiler/make_hlds_separate_items.m:
compiler/typecheck_errors.m:
Conform to the changes above.
tests/invalid_nodepend/external_in_interface.{m,err_exp}:
tests/invalid_nodepend/foreign_proc_in_interface.{m,err_exp}:
tests/invalid_nodepend/fact_table_in_interface.{m,err_exp}:
Three new test cases to test the
tests/invalid_nodepend/Mmakefile:
Enable the new tests.
tests/invalid/external2.m:
Fix typo in comment.
|
||
|
|
2622ee1e81 |
Don't wrap up pragmas of known kinds ...
... when adding them to the HLDS.
compiler/make_hlds_separate_items.m:
The parse trees of .opt and .trans_opt files contain slots
for specific kinds of pragmas. The presence of these slots,
and not others, encodes invariants about which kinds of pragmas
may occur in which kinds of files. However, for compatibility
with old code for adding pragmas to the HLDS, we wrapped up
all kind-specific pragmas in more general pragmas: either decl pragmas,
or gen pragmas.
This diff stops doing this, and instead returns all kind-specific pragmas
from .opt and .trans_opt files in separate kind-specific lists.
This allows the code that adds these pragmas to the hLDS to be streamlined.
(When intermodule optimization is enabled, .opt and .trans_opt files
contain *tons* of these pragmas.)
compiler/add_pragma.m:
Add predicates for adding known kinds of pragmas without them
being wrapped as generic decl or gen pragmas.
compiler/make_hlds_passes.m:
Get the pragma-kind-specific lists of pragmas from
make_hlds_separate_items.m, and use the new predicates
in add_pragma.m to add them to the HLDS.
|
||
|
|
a253493d42 |
Fix a bug in adding .opt files to the HLDS.
This fixes the failure of tests/submodules/ts with --intermod-opt.
compiler/make_hlds_passes.m:
Establish the invariant that for item kinds that may occur in both
.intN files and .opt files, items from .opt files always follow
items from .intN files. Document the reason for the invariant.
compiler/make_hlds_separate_items.m:
Fix code that broke this invariant for items created during the
processing of other items.
|
||
|
|
d64961d79d |
Use checked types/insts/modes in parse_tree_module_src.
This means that we can do the exact same checks (and, if needed, generate
the exact same error messages) when generating interface files as when
generating target language code.
This should also allow us to simplify the process of adding type, inst
and mode definitions to the HLDS.
compiler/prog_item.m:
As above.
Delete unused function.
compiler/error_util.m:
Add mechanisms that allow us to distinguish (a) error specs that represent
a type, inst or mode name definition being invalid, from (b) other error
specs.
compiler/check_type_inst_mode_defns.m:
Improve the error messages we generate, in several ways.
First, for each message, specify a real severity. When the messages
could be seen only when generating interface files, making them all
warnings was fine and preserved old behavior, but since soon these
will be the only place for these checks, we need to call errors errors.
Second, specify, in the phase, which errors represent a invalid type,
inst or mode definition, and which don't.
Third, improve the wording of messages. In some places, do this by
being clearer about the distinction between declarations and definitions.
In others, do it by including more information in the message. In yet
others, do it by recovering some kinds of mistakes (mostly items being
in the wrong section) enough to avoid avalanche errors.
Fourth, fix a bug. If a type ctor has an exported *declaration*,
then it is ok for any foreign type definitions for that type_ctor
being in the implementation section, but if the type_ctor has an
exported Mercury *definition*, then any foreign_type definitions
must be in the interface section as well. The code that handled
both these situations did not enforce that.
Fifth, fix another bug: do not include foreign type definitions
in the source definitions of a type_ctor twice, once as a "du" (sic)
definition, and once as itself.
compiler/convert_parse_tree.m:
Check type, inst and mode definitions in raw_compilation_units
when creating parse_tree_module_srcs.
compiler/comp_unit_interface.m:
Make the code constructing interface files work from the checked maps
in parse_tree_module_srcs.
compiler/make_hlds_passes.m:
Set the flags that say we have found invalid type, inst or mode definitions
from the error specs constructed during the creation of the checked
type, inst and mode maps.
compiler/add_type.m:
Comment out an error message for a condition that will be detected and
reported by check_type_inst_mode_defns.m.
compiler/make_hlds_separate_items.m:
For now, turn checked maps of type, inst and mode definitions
back to item lists for addition to the HLDS. Adding whole checked
definitions to the HLDS will be done by a future change.
compiler/make_hlds_error.m:
Fix misleading indentation in an error message.
compiler/parse_tree_out.m:
Conform to the changes above.
Generate output whose indentation does not depend on tab settings.
compiler/check_raw_comp_unit.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
Conform to the changes above.
compiler/parse_type_defn.m:
Fix misleading error message for ":- type <name> = <type>".
tests/debugger/foreign_type.{m,exp}:
Delete a redundant type declaration to avoid a warning, and update
the .exp file to expect the new line numbers.
tests/invalid/any_mode.err_exp:
tests/invalid/bug436.err_exp:
tests/invalid/bug476.err_exp:
tests/invalid/exported_foreign_enum.err_exp:
tests/invalid/fe_unmapped_nonverbose.err_exp:
tests/invalid/fe_unmapped_verbose.err_exp:
tests/invalid/foreign_enum_invalid.err_exp:
tests/invalid/foreign_solver_type.err_exp:
tests/invalid/foreign_type_visibility.err_exp:
tests/invalid/pragma_qual_error.err_exp:
tests/invalid/repeated_field_name.err_exp:
tests/invalid/subtype_foreign.err_exp:
tests/invalid/type_with_no_defn.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/user_field_access_decl_conflict.err_exp:
tests/invalid_nodepend/bad_foreign_type.err_exp:
tests/invalid_nodepend/bigtest.err_exp:
tests/invalid_nodepend/invalid_typeclass.err_exp:
tests/invalid_nodepend/types.err_exp:
tests/invalid_nodepend/uu_type.err_exp:
tests/invalid_nodepend/where_abstract_enum.err_exp:
Expect the new error messages.
tests/invalid/abstract_solver_type.{m,err_exp}:
tests/warnings/abstract_solver_type.{m,exp}:
Move the abstract_solver_type test case from invalid to warnings, because
this diff changes its only error to be only a warning.
tests/invalid/Mmakefile
|
||
|
|
4548706b85 |
Switch to checked type/inst/mode maps for .int0.
compiler/prog_item.m:
As above.
compiler/comp_unit_interface.m:
compiler/convert_parse_tree.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/parse_tree_out.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
Conform to the change above.
|
||
|
|
4126519139 |
Separate subtypes from du types in parse trees.
compiler/prog_data.m:
Split type_details_sub from type_details_du, and separate
parse_tree_sub_type from parse_tree_du_type. This gets us two things:
- It allows us to encode the prohibition on user-specified equality and
comparison predicates, and "where direct_arg is" clauses,
on subtype definitions.
- It gives us data types we can use to represent (a) only subtype
definitions, and (b) only non-subtype du definitions.
Note that this diff deliberately leaves the HLDS representation
of subtypes unchanged. This is because while a subtype *definition*
may not specify e.g. equality and comparison predicates, a subtype *can*
have equality and comparison predicates; it just has to get them from
its base type. And the same applies to direct args.
compiler/parse_type_defn.m:
Enforce the invariant that subtypes may not have user-specified equality
and comparison predicates, or "where direct_arg is" clauses.
If we find a subtype definition that does have one or both of these
non-allowed and now-nonrepresentable components, we do still want to
return the rest of the type definition, in order to avoid misleading
error messages about that type having no definition at all. To make this
possible, allow the parsing predicate to return error_specs "alongside",
as well as "instead of", the item or marker being parsed.
compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_class.m:
Handle these "alongside" error messages.
compiler/prog_item.m:
Separate out subtypes from other du types in type definition maps.
compiler/add_type.m:
Delete a semantic check that is now in parse_type_defn.m.
Conform to the change to the representations of subtypes/du types
in the parse tree.
compiler/item_util.m:
Add a new utility function for subtypes.
compiler/check_type_inst_mode_defns.m:
compiler/comp_unit_interface.m:
compiler/convert_parse_tree.m:
compiler/decide_type_repn.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/intermod.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
compiler/prog_type.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
Conform to the change to the representations of subtypes/du types
in the parse tree.
|
||
|
|
12605f8c10 |
Use checked type/inst/modes in parse_tree_int[123]s.
With this change, we guarantee that if any type, inst or mode
has inconsistent definitions in its defining module, those inconsistencies
will not make it into the the module's .int/.int2/.int3 files, where
they would confuse any compiler invocation that reads them in.
compiler/prog_item.m:
Replace {type,inst,mode}_ctor_defn_maps, which are unchecked,
with {type,inst,mode}_ctor_checked_maps in parse_tree_int[123]s.
To make this possible,
- generalize the items containing inst and mode definitions the way that
items containing type definitions have been generalized previously,
to allow them to store particular *kinds* of inst or mode definitions;
- move the definitions of type_ctor_checked_map and its components
here from check_type_inst_mode_defns.m; and
- add similar, but simpler, definitions for {inst,mode}_ctor_checked_map.
compiler/check_type_inst_mode_defns.m:
Delete the type definitions moved to prog_item.m.
Modify the checking process slightly to allow it to check properly
the definitions we now put into .int, .int2 and .int3 files.
Add code to check inst and mode definitions as well as type definitions.
Since insts and modes have only one non-abstract kind of definition,
these codes are much simpler than the code for checking types.
compiler/comp_unit_interface.m:
Construct checked type, inst and mode definitions to put into
.int, .int2 and .int3 files. The .int2 and .int3 parts were
reasonably simple, but the .int part requires some detailed
case-by-case analysis.
compiler/convert_parse_tree.m:
Check the type, inst and mode definitions read in from .int/.int2/.int3
files when creating their parse trees. If those files were generated
by a compiler that has this diff, then this checking process should
not find any problems.
compiler/equiv_type.m:
Operate on checked type, inst and mode definitions instead of their
unchecked versions.
Delete an unneeded field from a structure.
compiler/error_util.m:
Add {qual,unqual}_{inst,mode}_ctor as format components, so that
any error messages about inst and mode definitions do not have to convert
inst_ctors and mode_ctors to symname/arity pairs.
compiler/item_util.m:
Add some utility predicates and functions needed by the changes above.
compiler/module_qual.collect_mq_info.m:
Since checked type, inst and mode definitions can contain info that is
derived from both the interface and implementation sections of a module,
add the capability to get only the *publicly* declared types, insts and
modes from their respective kinds of checked definitions.
compiler/module_qual.qualify_items.m:
Module qualify checked type, inst and mode definitions.
compiler/module_qual.qual_errors.m:
Treat references to inst_ctors and mode_ctors in qualification error
messages the same way as we treat type_ctors.
Also replace mq_ids that are intended to represent classes with class_ids,
to represent the intent better.
compiler/parse_tree_out.m:
Output the updated parse_trees of .int/.int2/.int3 files.
compiler/prog_data.m:
Add an XXX about a future change.
compiler/decide_type_repn.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
compiler/pred_table.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
Conform to the changes above.
library/maybe.m:
Add utility predicates needed by the code above.
NEWS:
Announce the new predicates in maybe.m.
tools/intdiffall:
A script that shows differences between the automatically generated
interface files between stage 1 and stage 2, which helped debug this diff.
|
||
|
|
428aa400eb |
Introduce aug_make_int_unit.
compiler/prog_item.m:
Split aug_compilation_unit into two types. One, aug_make_int_unit,
is a new type, and it is a version of the old aug_compilation_unit
that contains only what is needed when making .int{,0,2} files.
The other, the new aug_compilation_unit, contains what is needed
when generating target language code. Both encode in their argument types
stronger invariants that the old aug_compilation_unit type did.
compiler/comp_unit_interface.m:
compiler/decide_type_repn.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.m:
compiler/parse_tree_out.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
Conform to the change above.
In some cases, this means passing around aug_make_int_units instead of
aug_compilation_units.
In a few cases, it means creating two copies of a predicate,
one for aug_compilation_units and one for aug_make_int_units.
In such cases, factor out any commonalities between the copies.
In many cases, it means updates to account for the specialized types
of the fields of aug_compilation_unit or aug_make_int_unit.
In some cases, it means deleting code that was always unreachable,
but the not-tight-enough types did not make this fact visible.
(Due to this effect, this diff removes more lines than it adds.)
|
||
|
|
b3748a367b |
Separate self-FIM languages by module section.
compiler/prog_item.m:
Split the parse_tree_module_src that holds the languages for which
the module needs a self-foreign-import into two, depending on the
section (interface or implementation) into which the self-FIM should go.
compiler/convert_parse_tree.m:
When computing the self-FIM languages, put each one into its section.
compiler/comp_unit_interface.m:
Don't compute the interface self-FIMs, since they are now available
in the parse_tree_module_src.
Document why we *do* compute the implementation self-FIMs
for the interface file we are constructing.
compiler/check_raw_comp_unit.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
Conform to the changes above.
|
||
|
|
5c3d4fe4f0 |
Replace module_and_imports with aug_compilation_unit.
compiler/module_imports.m:
Delete the module_and_imports type, and replace its uses with
aug_compilation_units.
The structure of module_and_imports used to be private, but the
structure of aug_compilation_units is public. Delete the getter/setter
predicates on module_and_imports structures that can now be done
using field names on aug_compilation_units. Delete, along with this,
the infrastructure for keeping track of which module_and_imports fields
are ever accessed. It has served its purpose, but it won't be needed
anymore.
Change types that used to include module_and_imports to include
aug_compilation_units instead.
Rename any types, predicates and functions that used to contain
the "module_and_imports" string in their name.
compiler/prog_item.m:
Move the version number map to be the last field of aug_compilation_units,
as it used to be in module_and_imports structures, since this fits better.
compiler/get_dependencies.m:
Make the name of a predicate more reflective of the type it returns.
compiler/comp_unit_interface.m:
compiler/deps_map.m:
compiler/equiv_type.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_separate_items.m:
compiler/mercury_compile_main.m:
compiler/module_qual.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
|
||
|
|
d84571c0c2 |
Delete redundant fields in aug_compilation_units.
compiler/prog_item.m:
Delete the module name and module name context fields from
aug_compilation_units, since the same info is available from
the parse_tree_module_src field.
compiler/comp_unit_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/item_util.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_separate_items.m:
compiler/mercury_compile_main.m:
compiler/module_imports.m:
compiler/module_qual.m:
compiler/prog_item_stats.m:
compiler/write_deps_file.m:
Conform to the change above.
|
||
|
|
f1927afe0b |
Break a source file info parse_tree_module_srcs ...
... instead of into raw_compilation_units. Besides being more convenient to
work on, a parse_tree_module_src encodes in its type a significant number
of invariants that a raw_compilation unit does not.
compiler/split_parse_tree_src.m:
Immediately after creating a raw_compilation_unit for one of the modules
in a potentially multi-module source file, convert it to a
parse_tree_module_src.
Fix an old problem that can come up in contrived erroneous code.
Specifically, when a submodule is both nested inside its parent module,
*and* it also has an explicit include_module declaration, we used to
record the contexts of both "inclusions", after generating an error
message. The more rigorous checking that later code now does on the
resulting inclusion map would look at this "duplicate inclusion"
and generate *another* error message. To avoid this redundant message,
do not record the contexts of erroneous inclusions for which a message
has already been generated.
compiler/grab_modules.m:
Operate on parse_tree_module_srcs instead of raw_compilation_units.
This allows us to avoid having code for doing what converting the
raw_compilation_unit to a parse_tree_module_src has already done.
In fact, that conversion code does a better job. The old code assumed
that all implicitly available modules are used in the interface,
whereas in fact only some should be used in the interface, with
the rest being used in the implementation section.
compiler/module_imports.m:
Make the predicates that create module_and_imports structures
take a parse_tree_module_src instead of a raw_compilation_unit
as input. For now, we convert the parse_tree_module_src back to
a raw_compilation_unit for further processing, but I intend
a later diff to change this. Nevertheless, one immediate change
is that init_module_and_imports now stores the *actual*
parse_tree_module_src in the module_and_imports structure,
not a dummy.
compiler/prog_item.m:
Do not include a list of foreign_enum items in the interface section
of a parse_tree_module_src, since such items are not allowed to occur
in interface sections.
For the same reason, delete the field for foreign_enums in the interface
sections of .int0 and .int files.
compiler/check_raw_comp_unit.m:
Operate on parse_tree_module_srcs instead of raw_compilation_units.
compiler/comp_unit_interface.m:
Operate on parse_tree_module_srcs instead of raw_compilation_units.
Do not expect any foreign_enum items in interface sections, since
they are not allowed there.
compiler/read_modules.m:
Provide a mechanism to remember having read a parse_tree_module_src.
compiler/write_module_interface_files.m:
Operate on parse_tree_module_srcs instead of raw_compilation_units.
compiler/get_dependencies.m:
Add a new version of an existing utility predicate. The old one operated
on raw item lists, the new one operates on parse_tree_module_srcs.
To make this possible, factor out the code pieces that operate on
each non-ignored kind of item.
compiler/item_util.m:
Add some new utility predicates/functions.
compiler/convert_parse_tree.m:
Conform to the change in prog_item.m. (We already generated an error
message for a foreign_enum item in the interface, but still passed around
a list of foreign_enum items that was guaranteed to be stay empty.)
compiler/make.module_dep_file.m:
Conform to the changes above.
Use explicit streams in one place.
Do not pass an unneeded argument.
compiler/check_parse_tree_type_defns.m:
compiler/equiv_type.m:
compiler/make_hlds_separate_items.m:
Conform to the change in prog_item.m.
compiler/mercury_compile_main.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
Conform to the changes above.
library/map.m:
library/tree234.m:
Add foldl6, foldl6_values and foldr6 predicates. An earlier version
of this diff needed foldl6, and I added the others for symmetry.
NEWS:
Announce the new library predicates.
tests/invalid/bad_mutable.m:
Export something, to avoid a warning about not exporting anything.
tests/invalid_submodules/duplicate_module.m:
tests/invalid_submodules/duplicate_module_test.m:
Update programming style.
|
||
|
|
e627efcf50 |
A start on getting type_repn info from .int files.
compiler/du_type_layout.m:
Add a first draft of the code that will eventually get type representation
information from .int files. Invoke the new code only if undocumented,
developer-only experiment flags are set, and when invoked, compare
its output with the output of the old algorithm it is intended to
eventually replace.
The new code is not yet complete, and thus has not yet been tested.
compiler/prog_item.m:
Add a new field to the augmented compilation unit data type
that is intended to hold the .int file of the main module, the module
that the augmented compilation unit is for. For every module imported
by the main module, we read its .int or .int2 file and get the
representation information for the types they define from those files,
but we need this info for the main module's own types as well.
Add "need type representation information" as reason for reading
a .int file.
Break some types down into smaller types, to allow their components
to be manipulated individually by du_type_layout.m.
Start using uint8, not uint, in situations where we want to store
values that select bits in words, which fit into 6 bits.
Add XXXs where we could, and maybe should switch to uint8s.
Add extra documentation.
compiler/grab_modules.m:
Read in the main module's own .int file.
Replace a bool with a bespoke type.
compiler/module_imports.m:
Provide a slot for the main module's own interface file,
which will be used to set the new slot in augmented compilation units.
compiler/comp_unit_interface.m:
Put the exact same type_ctor_repn_map into .int2 files as .int files.
This should prevent the scenario where a compilation reads
e.g. mod_x.int2, gains access to the definitions of the exported types
of module mod_x, but then needs to read mod_x.int as well to find out
how those types are represented. Since neither type checking nor any
other semantic analysis pass pays any attention to type_repn items,
the additional type_repn items in mod_x.int2 cannot turn an otherwise
illegal program into a legal one.
compiler/hlds_data.m:
Clarify a comment.
compiler/maybe_error.m:
Provide a utility predicate.
compiler/prog_data.m:
Add XXXs about possible future improvements.
compiler/decide_type_repn.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_type_repn.m:
compiler/parse_type_repn.m:
compiler/prog_item_stats.m:
compiler/write_deps_file.m:
Conform to the changes above.
|
||
|
|
e1e2136dbb |
Centralize HLDS building in make_hlds_passes.m.
compiler/add_mutable_aux_preds.m:
compiler/add_solver.m:
When invoked on mutables and solver types respectively, these modules
added did all the additions to the HLDS directly themselves,
in two phases: first declarations, then definitions.
Change this so that instead, they simply return the items needed
to declare and define mutables and solver types to make_hlds_passes.m,
which will then add them to the HLDS with the other items of the same kind.
compiler/make_hlds_passes.m:
Add to the HLDS the items returned by add_mutable_aux_preds.m and
add_solver.m. Doing the adding here makes it much easier to see
both the full set of items that mutables and solver types, as well as
the dependencies between them and other kinds of items.
compiler/add_foreign_proc.m:
Add a utility predicate for use by the code above.
compiler/add_pragma.m:
Add a utility predicate for use by the code above, replacing another,
which can now be kept private.
compiler/make_hlds.m:
Define types that are now needed in more than one of its submodules.
compiler/make_hlds_separate_items.m:
Delete the type definitions that have been moved to make_hlds.m.
compiler/hlds_module.m:
Rename pred_c_names as pred_target_names, since they can also refer to
C# and Java names.
Change the predicates that add pred_target_names so that they add them
to just the data structure that contains them, not the whole module_info.
This makes the code of the callers clearer.
Fix a bug I introduced when I changed make_hlds_passes.m to add items
by kind, not by position in an item block. The bug was that the
reference manual promised that in the event of a code sequence such as
:- initialise foo/2.
:- mutable(bar, int, 561, ground, [untrailed]).
:- initialise baz/2.
the initialization of bar would happen *between* the calls to
foo/2 and baz/2, but since make_hlds_passes.m processed all initialise
declarations together, this could not happen. The fix is to record
initializations in a map whose key is an item sequence number
(which cannot be item_no_seq_num), and then take the initialization
sequence from those keys.
compiler/parse_type_defn.m:
Include valid seq_nums (the seq_num of the solver type definition)
in the mutable items returned for solver types, for use in the
pred_target_names map in hlds_module.m.
compiler/mercury_compile_llds_back_end.m:
compiler/ml_top_gen.m:
Conform to the change in hlds_module.m.
|
||
|
|
dcb728e22a |
Record section info with lists of items.
compiler/make_hlds.m:
Make the representation of sec_lists and ims_lists more efficient.
The old definition of sec_list(T), where T is item_X_info for some X, was
:- type sec_list(T) == list(sec_item(T)).
:- type sec_item(T)
---> sec_item(sec_info, T).
while the new definition is
:- type sec_list(T) == list(sec_sub_list(T)).
:- type sec_sub_list(T)
---> sec_sub_list(sec_info, list(T)).
The change to the ims_list type is analogous.
The new definition has sevaral advantages.
- There is no need to allocate a sec_item cell for each item_X_info.
- The parse trees from which we take the item_X_infos already have them
in a list. The old representation had to rebuild this list around the
sec_items, while the new representation does not: it allocates just
one cell for each list in each parse_tree.
- To ensure that the predicate built the list of sec_infos in the old
approach, it built this list accumulator style by appending to the front
in order to guarantee tail recursion. Preserving the original order
in the final result thus requires a list reversal with yet more
memory allocation.
The one disadvantage of the new type definition is that it requires
a two level traversal: first of the sublists, then of the items within
them. However, even this minor disadvantage is offset by the fact that
it allows for a simple form of loop invariant optimization. Specifically,
for some item kinds, computations on the sec_info can be done once
per sublist, and do not have to be repeated once per item.
compiler/make_hlds_separate_items.m:
Accumulate item_X_infos in the form of cords of sublists. Being able
to append to these cords in constant time means that we never have to
reverse or re-reverse lists of items, and the cords are trivial to
transform to sec_lists and ims_lists at the end.
compiler/make_hlds_passes.m:
Add the list of each kind of item to the HLDS using the two level loop
described above.
compiler/add_class.m:
compiler/add_mode.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma.m:
compiler/add_pred.m:
Export predicates that add whole two level lists of items, not just
predicates that add a single item. Move computations from the inner loop
to the outer loop when possible.
|
||
|
|
8ba45b7892 |
Compute section infos directly.
compiler/make_hlds_separate_items.m:
The code that creates lists of items for us to add to the HLDS
attaches a section info to each item, to tell the code that
does the adding about the section that the item was found in,
since that governs several aspects of how the entity defined by the item
should be treated.
This code was ancient; it is was updated only minimally during the
switchover from Fergus's item-lists-everywhere design to my
use-file-kind-specific-parse-trees design. It was also convoluted;
the section infos for the two sections (interface and implementation)
were computed in several stages, whose code was spread over three
sets of predicates.
This diff replaces this old code with code that computes those
section infos directly. The new code is much shorter, and the computation
of the section infos for e.g. parse_tree_int1 files is all in one place,
making it much easier to understand.
Add XXXs for ancient problems that were hid by the old design
but which the new design makes jump out at the reader.
Delete predicates used by the old approach that are not needed anymore.
Any needed parts were effectively inlined into the new code.
compiler/item_util.m:
Delete the code used by the new approach that is not needed anymore.
Any needed parts were effectively inlined into the new code.
compiler/prog_item.m:
Delete types that are no longer needed, some of which haven't been
needed for a while.
Delete references to the functions deleted from item_util.m.
With the new code in make_hlds_separate_items.m, they should not be
needed.
compiler/prog_item_stats.m:
Delete commented-out references to types deleted from prog_item.m.
compiler/module_imports.m:
Delete references in comments to types deleted from prog_item.m.
|
||
|
|
a19a5f0267 |
Delete the Erlang backend from the compiler.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_backend.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
compiler/erlang_rtti.m:
compiler/mercury_compile_erl_back_end.m:
Delete these modules, which together constitute the Erlang backend.
compiler/notes/compiler_design.html:
Delete references to the deleted modules.
compiler/parse_tree_out_type_repn.m:
Update the format we use to represent the sets of foreign_type and
foreign_enum declarations for a type as part of its item_type_repn_info,
now that Erlang is no longer a target language.
compiler/parse_type_repn.m:
Accept both the updated version of the item_type_repn_info and the
immediately previous version, since the installed compiler will
initially generate that previous version. However, stop accepting
an even older version that we stopped generating several months ago.
compiler/parse_pragma_foreign.m:
When the compiler finds a reference to Erlang as a foreign language,
add a message about support for Erlang being discontinued to the error
message.
Make the code parsing foreign_decls handle the term containing
the foreign language the same way as the codes parsing foreign
codes, procs, types and enums.
Add a mechanism to help parse_mutable.m to do the same.
compiler/parse_mutable.m:
When the compiler finds a reference to Erlang as a foreign language,
print an error message about support for Erlang being discontinued.
compiler/compute_grade.m:
When the compiler finds a reference to Erlang as a grade component,
print an informational message about support for Erlang being discontinued.
compiler/pickle.m:
compiler/make.build.m:
Delete Erlang foreign procs and types.
compiler/add_foreign_enum.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_type.m:
compiler/check_libgrades.m:
compiler/check_parse_tree_type_defns.m:
compiler/code_gen.m:
compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/const_struct.m:
compiler/convert_parse_tree.m:
compiler/dead_proc_elim.m:
compiler/decide_type_repn.m:
compiler/deps_map.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/foreign.m:
compiler/globals.m:
compiler/granularity.m:
compiler/handle_options.m:
compiler/hlds_code_util.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/int_emu.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/lco.m:
compiler/llds_out_file.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_separate_items.m:
compiler/make_hlds_warn.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/ml_code_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_target_util.m:
compiler/ml_top_gen.m:
compiler/mlds.m:
compiler/mlds_dump.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_cs_type.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_type.m:
compiler/module_imports.m:
compiler/parse_pragma_foreign.m:
compiler/parse_tree_out.m:
compiler/polymorphism.m:
compiler/pragma_c_gen.m:
compiler/prog_data.m:
compiler/prog_data_foreign.m:
compiler/prog_foreign.m:
compiler/prog_item.m:
compiler/simplify_goal_scope.m:
compiler/special_pred.m:
compiler/string_encoding.m:
compiler/top_level.m:
compiler/uint_emu.m:
compiler/write_deps_file.m:
Remove references to Erlang as a backend or as a target language.
tests/invalid/bad_foreign_code.{m,err_exp}:
tests/invalid/bad_foreign_decl.{m,err_exp}:
tests/invalid/bad_foreign_enum.{m,err_exp}:
tests/invalid/bad_foreign_export.{m,err_exp}:
tests/invalid/bad_foreign_export_enum.{m,err_exp}:
tests/invalid/bad_foreign_import_module.{m,err_exp}:
tests/invalid/bad_foreign_proc.{m,err_exp}:
tests/invalid/bad_foreign_type.{m,err_exp}:
Add a test for Erlang as an invalid foreign language. Expect both the
new error message for this new error, and the updated list of now-valid
foreign languages on all errors.
|
||
|
|
c96f19e56f |
Put type_repn items into a map.
compiler/make_hlds_separate_items.m:
We used to return the type_repn items we read in from interface files
as a list. However, this list could have duplicates, because in the
presence of intermodule optimization, we can read more than one
interface file for a module, e.g. a .int3 file as an indirect dependency
and a .int file as an int_for_opt dependency (i.e. an interface file
that we need to make sense of some things in a .opt file).
This diff keeps the type_repn items from only one interface file per
module, the file that contains strictly more type representation
information.
Return this information in the form in which we will want to use it,
a map that enables lookups. Doing it here should be faster than having
it done elsewhere, since we can exploit the data structure we use
to reject redundant type_repns from subsumed interface files to
build the final version of the map directly, without having to go through
any intermediate versions.
compiler/hlds_module.m:
Store type_repn information in the HLDS in map form.
compiler/make_hlds_passes.m:
Record type_repn information in the HLDS in map form.
compiler/du_type_layout.m:
Delete the code that used to build this map, since that jobs is now done
in make_hlds_separate_items.m.
|
||
|
|
5c52cf0cde |
Standardize on "sym_name_arity" ...
... replacing "sym_name_AND_arity". |
||
|
|
9789375cc5 |
Make pre-HLDS passes use file-kind-specific parse trees.
Replacing item blocks file-kind-specific kinds of section markers with
file-kind-specific parse trees has several benefits.
- It allows us to encode the structural invariants of each kind of file
we read in within the type of its representation. This makes the detection
of any accidental violations of those invariants trivial.
- Since each file-kind-specific parse tree has separate lists for separate
kinds of items, code that wants to operate on one or a few kinds of items
can just operate on those kinds of items, without having to traverse
item blocks containing many other kinds of items as well. The most
important consequence of this is not the improved efficiency, though
that is nice, but the increased clarity of the code.
- The new design is much more flexible. For example, it should be possible
to record that e.g. an interface file we read in as a indirect dependency
(i.e. a file we read not because its module was imported by the module
we are compiling, but because its module was imported by *another* imported
module) should be used *only* for the purpose it was read in for. This should
avoid situations where deleting an import of A from a module, because it
is not needed anymore, leads the compiler to generate an error message
about a missing import of module B. This can happen if (a) module B
always *should* have been imported, since it is used, but (b) module A's
import of module B lead to module B's interface being available *without*
an import of B.
Specifically, this flexibility should enable us to establish each module's
.int file as the single source of truth about how values of each type
defined in that module should be represented. When compiling each source
file, this approach requires the compiler to read in that module's .int file
but using only the type_repn items from that .int file, and nothing else.
- By recording a single parse tree for each file we have read, instead of
a varying number of item blocks, it should be significantly easier to
derive the contents of .d files directly from the records of those
parse trees, *without* having to maintain a separate set of fields
in the module_and_imports structure for that purpose. We could also
trivially avoid any possibility of inconsistencies between these two
different sources of truth. (We currently fill in the fields used to
drive the generation of .d files using two different pieces of code,
one used for --generate-dependencies and one used for all other invocations,
and these two *definitely* generate inconsistent results, as the significant
differences in .d files between (a) just after an invocation of
--generate-dependencies and (b) just after any other compiler invocation
can witness.)
This change is big and therefore hard to review. Therefore in many files,
this change adds "XXX CLEANUP" comments to draw attention to places that
have issues that should be fixed, but whose fixes should come later, in
separate diffs.
compiler/module_imports.m:
The compiler uses the module_and_imports structure defined here
to go from a raw compilation unit (essentially a module to be compiled)
to an augmented compilation unit (a raw compilation unit together
with all the interface and optimization files its compilation needs).
We used to store the contents of both the source file and of
the interface and optimization files in the module_and_imports structure
as item blocks. This diff replaces all those item blocks with
file-kind-specific parse trees, for the reasons mentioned above.
Separate out the .int0 files of ancestors modules from the .intN
files for N>0 of directly imported modules. (Their item blocks
used to be stored in the same list.)
Maintain a database of the source, interface and optimization files
we have read in so far. We use it to avoid reading in interface files
if we have already read in a file for the same module that contains
strictly more information (either an interface file with a smaller
number as a suffix, or the source file itself).
Shorten some field names.
compiler/prog_item.m:
Define data structures for storing information about include_module,
import_module and use_module declarations, both in a form that allows
the representation of possibly erroneous code in actual source files,
and in checked-and-cleaned-up form which is guaranteed to be free
of the relevant kinds of errors. Add a block comment at the start
of the module about the need for this distinction.
Define parse_tree_module_src, a data structure for representing
the source code of a single module. This is different from the existing
parse_tree_src type, which represents the contents of a single source file
but which may contain *more* than one module, and also different from
a raw_compilation_unit, which is based on item blocks and is thus
unable to express to invariants such as "no clauses in the interface".
Modify the existing parse_tree_intN types to express the distinction
mentioned just above, and to unify them "culturally", i.e. if they
store the same information, make them store it using the same types.
Fix a mistake by allowing promises to appear in .opt files.
I originally ruled them out because the code that generates .opt files
does not have any code to write out promises, but some of the predicates
whose clauses it writes out have goal_type_promise, which means that
they originated as promises, and get written out as promises.
Split the existing pragma item kind into three item kinds, which have
different invariants applying to them.
- The decl (short for declarative) pragmas give the compiler some
information, such as that a predicate is obsolete or that we
want to type specialize some predicate or function, that is in effect
part of the module's interface. Decl pragmas may appear in module
interfaces, and the compiler may put them into interface files;
neither statement is true of the other two kinds of pragmas.
- The impl (short for implementation) pragmas are named so
precisely because they may appear only in implementation sections.
They give the compiler information that is private to that module.
Examples include foreign_decls, foreign_codes, foreign_procs,
and promises of clause equivalence, and requests for inlining,
tabling etc. These will never be put into interface files,
though some of them can affect the compilation of other modules
by being included in .opt files.
- The gen (short for generated) pragmas can never (legally) appear
in source files at all. They record the results of compiler
analyses e.g. about which arguments of a predicate are unused,
or what exceptions a function can throw, and accordingly they
should only ever occur in compiler-generated interface files.
Use the new type differences between the three kinds of pragmas
to encode the above invariants about which kinds of pragmas can appear
where into the various kinds of parse trees.
Make the augmented compilation unit, which is computed from
the final module_and_imports structure, likewise switch from
storing item blocks to storing the whole parse trees of the
files that went into its construction. With each such parse tree,
record *why* we read it, since this controls what permissions
the source module being compiled has for access to the entities
in the parse tree.
Simplify the contains_foreign_code type, since one of three
function symbols was equivalent to one possible use of another
function symbol.
Provide a way to record which method of which class a compiler-generated
predicate is for. (See hlds_pred.m below.)
Move the code of almost all utility operations to item_util.m
(which is imported by many fewer modules than prog_item.m),
keeping just the most "popular" ones.
compiler/item_util.m:
Move most of the previously-existing utility operations here from
prog_item.m, most in a pretty heavily modified form.
Add a whole bunch of other utility operations that are needed
in more than one other module.
compiler/convert_parse_tree.m:
Provide predicates to convert from raw compilation units to
parse_tree_module_srcs, and vice versa (though the reverse
shouldn't be needed much longer).
Update the conversion operations between the general parse_tree_int
and the specific parse_tree_intN forms for the changes in prog_item.m
mentioned above. In doing so, use a consistent approach, based on
new operations in item_util.m, to detect errors such as duplicate
include_module and import/use_module declarations in all kinds
of parse trees.
Enforce the invariants that the types of parse trees of various kinds
can now express in types, generating error messages for their violations.
Delete some utility operations that have been moved to item_util.m
because now they are also needed by other modules.
compiler/grab_modules.m:
Delete code that did tests on raw compilation units that are now done
when that raw compilation unit is converted to a parse_tree_module_src.
Use the results of the checks done during that conversion to decide
which modules are imported/used and in which module section.
Record a single reason for why we reading in each interface and
optimization file. The code of make_hlds_separate_items.m will use
this reason to set up the appropriate permissions for each item
in those files.
Use separate code for handling different kinds of interface and
optimization files. Using generic traversal code was acceptable economy
when we used the same data structure for every kind of interface file,
but now that we *can* express different invariants for different kinds
of interface and optimization file, we want to execute not just different
code for each kind of file, but the data structures we want to work on
are also of different types. Using file-kind-specific code is a bit
longer, but it is significantly simpler and more robust, and it is
*much* easier to read and understand.
Delete the code that separates the parts of the implementation section
that are exported to submodules, and the part that isn't, since that task
is now done in make_hlds_separate_items.m.
Pass a database of the files we have read through the relevant predicates.
Give some predicates more meaningful names.
compiler/notes/interface_files.html:
Note a problem with the current operation of grab_modules.
compiler/get_dependencies.m:
Add operations to gather implicit references to builtin modules
(which have to be made available even without an explicit import_module
or use_module declaration) in all kinds of parse trees. These have
more code overall, but will be at runtime, since we need only look at
the item kinds that may *have* such implicit references.
Add a mechanism to record the result of these gathering operations
in import_and_or_use_maps.
Give some types, function symbols, predicates and variables
more meaningful names.
compiler/make_hlds_separate_items.m:
When we stored the contents of the source module and the
interface and optimization files we read in to augment it
in the module_and_imports structure as a bunch of item blocks,
the job of this module was to separate out the different kinds of items
in the item blocks, returning a single list of each kind of item,
with each such item being packaged up with its status (which encodes
a set of permissions saying what the source module is allowed
to do with it).
Now that the module_and_imports structure stores this info in
file-kind-specific parse trees, all of which have separate lists
for each kind of item and none of which contain item blocks,
the job of this module has changed. Now its job is to convert
the reason why each file was read in into the (one or more) statuses
that apply to the different kinds of items stored in it, wrap up
each item with its status, and return the resulting overall list
of status/item pairs for each kind of item.
compiler/read_modules.m:
Add predicates that, when reading an interface file, return its contents
in the tightest possible file-kind-specific parse tree.
Refine the database of files we have read to allow us to store
more file-kind-specific parse trees.
Don't require that files in the database have associated timestamps,
since in some cases, we read files we can put into the database
*without* getting their timestamps.
Allow the database to record that an attempt to read a file failed.
compiler/split_parse_tree_src.m:
Rearchitect how this module separates out nested submodules from within
the main module in a file.
Another of the jobs of this module is to generate error messages for
when module A includes module B twice, whether via nesting or via
include_module declarations, with one special exception for the case
where A's interface contains nested submodule A.B's interface,
and A's implementation contains nested submodule A.B's implementation.
The problem ironically was that while it reported duplicate include_module
declarations as errors, split_parse_tree_src.m also *generated*
duplicate include_module declarations. Since it replaced each nested
submodule occurrence with an include_module declaration, in the scenario
above, it generated two include_module declarations for A.B. Even worse,
the interface incarnation of submodule A.B could contain
(the interface of) its own nested submodule A.B.C, while its
implementation incarnation could contain (the implementation section of)
A.B.C. Each occurrence of A.B.C would be its only occurrence in the
including part of its parent A.B, which means local tests for duplicates
do not work. (I found this out the hard way.)
The solution we now adopt adds include_module declarations to the
parents of any submodule only once the parse tree of the entire
file has been processed, since only then do we know all the
includer/included relationships among nested modules. Until then,
we just record such relationships in a database as we discover them,
reporting duplicates when needed (e.g. when A includes B twice
*in the same section*), but not reporting duplicates when not needed
(e.g. when A.B includes A.B.C in *different* sections).
compiler/prog_data.m:
Add a new type, pf_sym_name_and_arity, that exactly specifies
a predicate or function. It is a clone of the existing simple_call_id
type, but its name does NOT imply that the predicate or function
is being called.
Add XXXs that call for some other improvements in type names.
compiler/prog_data_foreign.m:
Give a type, and the operations on that type, a more specific name.
compiler/error_util.m:
Add an id field to all error_specs, which by convention should be
filled in with $pred. Print out the value in this field if the compiler
is invoked with the developer-only option --print-error-spec-id.
This allows a person debugging the compiler find out where in the code
an undesired error message is coming from significantly easier
than was previously possible.
Most of the modules that have changes only "to conform to the changes
above" will be for this change. In many cases, the updated code
will also simplify the creation of the affected error_specs.
Fix a bug that looked for a phase in only one kind of error_spec.
Add some utility operations needed by other parts of this change.
Delete a previously internal function that has been moved to
mdbcomp/prim_data.m to make it accessible in other modules as well.
compiler/Mercury.options:
Ask the compiler to warn about dead predicates in every module
touched by this change (at least in one its earlier versions).
compiler/add_foreign_enum.m:
Replace a check for an inappropriately placed foreign_enum declaration
with a sanity check, since with this diff, the error should be caught
earlier.
compiler/add_mutable_aux_preds.m:
Delete a check for an inappropriately placed mutable declaration,
since with this diff, the error should be caught earlier.
compiler/add_pragma.m:
Instead of adding pass2 and pass3 pragmas, add decl and impl and
generated pragmas.
Delete the tests for generated pragma occurring anywhere except
.opt files, since those tests are now done earlier.
Shorten some too-long predicate names.
compiler/comp_unit_interface.m:
Operate on as specific kinds of parse trees as the interface of this
module will allow. (We could operate on more specific parse trees
if we changed the interface, but that is future work).
Use the same predicates for handling duplicate include_module,
import_module and use_module declarations as everywhere else.
Delete the code of an experiment that shouldn't be needed anymore.
compiler/equiv_type.m:
Replace code that operated on item blocks with code that operates
on various kinds of parse trees.
Move a giant block of comments to the front, where it belongs.
compiler/hlds_module.m:
Add a field to the module_info that lets us avoid generating
misleading error messages above missing definitions of predicates
or functions when those definitions were present but were not
added to the HLDS because they had errors.
Give a field and its access predicates a more specific name.
Mark a spot where an existing type cannot express everything
it is supposed to.
compiler/hlds_pred.m:
For predicates which the compiler creates to represent a class method
(the virtual function, in OOP terms), record not just this fact,
but the id of the class and of the method. Using this extra info
in progress messages (with mmc -V) prevents the compiler from printing e.g.
% Checking typeclass constraints on class method
% Checking typeclass constraints on class method
% Checking typeclass constraints on class method
when checking three such predicates.
compiler/make.m:
Provide a slot in the make_info structure to allow the database
of the files we have read in to be passed around.
compiler/make_hlds_error.m:
Delete predicates that are needed in just one other module,
and have therefore been moved there.
compiler/make_hlds_passes.m:
Add decl, impl and generated pragma separately, instead of adding
pass2 and pass3 pragmas separately.
Do not generate error messages for clauses, initialises or finalises
in module interfaces, since with this diff, such errors should be
caught earlier.
compiler/mercury_compile_main.m:
compiler/recompilation.check.m:
Explicitly pass around the expanded database of parse trees
of files that have been read in.
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.m:
compiler/module_qual.qualify_items.m:
Collect module qualification information, and do module qualification
respectively on parse trees of various kinds, not item blocks.
Take information about what the module may do with the contents
of each interface or optimization file from the record of why
we read that file, not from the section markers in item blocks.
Break up some too-large predicates by carving smaller ones out of them.
compiler/options.m:
Add an option to control whether errors and/or warnings detecting
when deciding what should go into a .intN file be printed,
thus (potentially) preventing the creation of that file.
Add commented-out documentation for a previously totally undocumented
option.
doc/user_guide.texi:
Document the new option.
NEWS:
Announce the new option.
Mention that we now generate warnings for unused import_module and
use_module declarations in the interface even if the module has
submodules.
compiler/write_module_interface_files.m:
Let the new option control whether we filter out any messages generated
when deciding what should go into a .intN file.
compiler/parse_item.m:
Delete actually_read_module_opt, since it is no longer needed;
its callers now call actually_read_module_{plain,trans}_opt instead.
Delete unneeded arguments from some predicates.
compiler/parse_module.m:
Delete some long unused predicates.
compiler/parse_pragma.m:
When parsing pragmas, wrap them up in the new decl, impl or generated
pragma kinds.
compiler/parse_tree_out.m:
Add predicates to write out each of the file-kind-specific parse trees.
compiler/parse_tree_out_pragma.m:
Add predicates to write out decl, impl and generated pragmas.
compiler/polymorphism.m:
Add a conditionally-enabled progress message, which can be useful
in tracking down problems.
compiler/prog_item_stats.m:
Conform NOT to the changes above beyond what is needed to let this module
compile. Let that work be done the next time the functionality of
this module is needed, by which time the affected data structures
maybe have changed further.
compiler/typecheck.m:
Fix a performance problem. With intermodule optimization, we read in
.opt files, some of which (e.g. list.opt and int.opt) contain promises.
These promises are read in as predicates with goal_type_promise,
but they do not have declarations of the types of their arguments
(since promises do not have declarations as such). Those argument types
therefore have to be inferred. That inference replaces the original
"I don't know" argument types with their actual types.
The performance problem is that when we change the recorded argument types
of a predicate, we require another loop over all the predicates in the
module, so that any calls to this predicate can be checked against
the updated types. This is as it should be for callable predicates,
but promises are not callable. So if all the *only* predicates whose
recorded argument types change during the first iteration to fixpoint
are promises, then a second iteration is not needed, yet we used to do it.
The fix is to replace the "Have the recorded types of this predicate
changed?" boolean flag with a bespoke enum that says "Did the checking
of this predicate discover a need for another iteration", and not
setting it when processing predicates whose type is goal_type_promise.
compiler/typecheck_errors.m:
Do not generate an error message for a predicate missing its clauses
is the clauses existed but were not added to the HLDS because they were
in the interface section.
When reporting on ambiguities (when a call can match more than one
predicate or function), sort the possible matches before reporting
them.
compiler/accumulator.m:
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_mode.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/canonicalize_interface.m:
compiler/check_for_missing_type_defns.m:
compiler/check_parse_tree_type_defns.m:
compiler/check_promise.m:
compiler/check_raw_comp_unit.m:
compiler/check_typeclass.m:
compiler/common.m:
compiler/compile_target_code.m:
compiler/compiler_util.m:
compiler/dead_proc_elim.m:
compiler/deps_map.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/du_type_layout.m:
compiler/field_access.m:
compiler/find_module.m:
compiler/float_regs.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/handle_options.m:
compiler/hlds_out_module.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/inst_check.m:
compiler/intermod.m:
compiler/introduce_parallelism.m:
compiler/layout_out.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_warn.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_llds_back_end.m:
compiler/ml_top_gen.m:
compiler/mmakefiles.m:
compiler/mode_errors.m:
compiler/mode_robdd.equiv_vars.m:
compiler/modes.m:
compiler/module_qual.qual_errors.m:
compiler/oisu_check.m:
compiler/old_type_constraints.m:
compiler/options_file.m:
compiler/parse_class.m:
compiler/parse_dcg_goal.m:
compiler/parse_goal.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_inst_mode_name.m:
compiler/parse_mutable.m:
compiler/parse_sym_name.m:
compiler/parse_type_defn.m:
compiler/parse_type_name.m:
compiler/parse_type_repn.m:
compiler/parse_types.m:
compiler/parse_util.m:
compiler/parse_vars.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/prog_event.m:
compiler/prog_mode.m:
compiler/purity.m:
compiler/qual_info.m:
compiler/recompilation.version.m:
compiler/resolve_unify_functor.m:
compiler/simplify_goal.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_ite.m:
compiler/simplify_proc.m:
compiler/state_var.m:
compiler/stratify.m:
compiler/style_checks.m:
compiler/superhomogeneous.m:
compiler/table_gen.m:
compiler/term_constr_errors.m:
compiler/term_errors.m:
compiler/termination.m:
compiler/trace_params.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/write_deps_file.m:
compiler/xml_documentation.m:
Conform to the changes above.
mdbcomp/prim_data.m:
Move a utility function on pred_or_funcs here from a compiler module,
to make it available to other compiler modules as well.
scripts/compare_s1s2_lib:
A new script that helped debug this diff, and may help debug
similar diffs the future. It can compare (a) .int* files, (b) .*opt
files, (c) .mh/.mih files or (d) .c files between the stage 1 and
stage 2 library directories. The reason for the restriction
to the library directory is that any problems affecting the
generation of any of these kinds of files are likely to manifest
themselves in the library directory, and if they do, the bootcheck
won't go on to compile any of the other stage 2 directories.
tests/debugger/breakpoints.a.m:
tests/debugger/breakpoints.b.m:
Move import_module declarations to the implementation section
when they are not used in the interface. Until now, the compiler
has ignored this, but this diff causes the compiler to generate
a warning for such misplaced import_module declarations even modules
that have submodules. The testing of such warnings is not the point
of the breakpoints test.
tests/invalid/Mercury.options:
Since the missing_interface_import test case tests error messages
generated during an invocation of mmc --make-interface, add the
new option that *allows* that invocation to generate error messages.
tests/invalid/ambiguous_overloading_error.err_exp:
tests/invalid/max_error_line_width.err_exp:
tests/warnings/ambiguous_overloading.exp:
Expect the updated error messages for ambiguity, in which
the possible matches are sorted.
tests/invalid/bad_finalise_decl.m:
tests/invalid/bad_initialise_decl.m:
Fix programming style.
tests/invalid/bad_item_in_interface.err_exp:
Expect an error message for a foreign_export_enum item in the interface,
where it should not be.
tests/invalid/errors.err_exp:
Expect the expanded wording of a warning message.
tests/invalid/foreign_enum_invalid.err_exp:
Expect a different wording for an error message. It is more "standard"
but slightly less informative.
tests/invalid_submodules/children2.m:
Move a badly placed import_module declaration, to avoid having
the message the compiler now generates for it from affecting the test.
tests/submodules/parent2.m:
Move a badly placed import_module declaration, to avoid having
the message the compiler now generates for it from affecting the test.
Update programming style.
|
||
|
|
ab8c2771f7 |
Move towards generating .opt/.trans_opt files via items.
compiler/prog_item.m:
Add types for representing .opt and .trans_opt files that specify
exactly what kinds of items may appear in them.
Provide a mechanism for representing just the kinds of pragmas
that we may want to put into .opt files to represent a predicate marker.
To make the above possible, generalize the item_pragma_info type.
Do not store the "maybe attributes" field in all pragmas; store it
in just the one pragma for which it had pragma-specific code (which code
is dubious anyway). Its only use is to suppress error messages about
incorrect pragmas if that pragma was created by the compiler, on the
theory that the user cannot do anything about any such error messages.
However, if such errors are never reported to anyone, then they won't
be fixed. I think it is better to allow such problems to be discovered,
even if they cause a bit of annoyance to the discoverer. The default
content of the field as set by the parser, item_origin_user, can be
misleading anway; it is correct when the pragma is read in from a .m file
or from a .int* file, but it is wrong when read in from a .*opt file,
since the contents of those are decided by the compiler.
Store a varset and tvarset in structure sharing and reuse pragmas,
since without this, one cannot print them out properly.
compiler/intermod.m:
Change the predicates that write out .opt and .trans_opt files
to return as large a fraction of the parse trees of those files
as possible, as a step towards generating those files not directly,
but by building and then writing out those parse trees. For now,
we cannot do this fully for .opt files, because for a few item kinds,
it is far from obvious how to represent as a item what we write out.
Leave the opening and closing of the file streams for writing out
.opt and .trans_opt files to our caller, because for .opt files,
this allows us to avoid having to open the file *twice*.
Put the output of result-of-analysis pragmas into a standard order.
Factor out as common code the process for deciding what should go into
.opt files.
Give a field of the intermod_info structure a more precise name.
compiler/mercury_compile_front_end.m:
Hold the stream of the .opt file open between the two different pieces
of code that write out the two different parts of .opt files.
If --experiment5 is set, write out the parse tree of the .opt file
to the .optx file, to enable comparison with the .opt file.
compiler/mercury_compile_middle_passes.m:
If --experiment5 is set, write out the parse tree of the .trans_opt file
to the .trans_optx file, to enable comparison with the .trans_opt file.
Reset a memo table for structure_{sharing,reuse}.analysis.
compiler/structure_reuse.analysis.m:
compiler/structure_sharing.analysis.m:
Don't take an I/O state pair as arguments, since we needed them *only*
for that reset, and for progress messages.
Give the main predicates more descriptive names.
compiler/trailing_analysis.m:
Give the main predicate a more descriptive names.
compiler/closure_analysis.m:
Don't take an I/O state pair as arguments, since we needed them *only*
for progress messages.
compiler/add_pragma.m:
Don't ignore an error, since one of the other changes in this diff
could have fixed its cause.
compiler/convert_interface.m:
Export utility functions needed by code added by this diff.
ompiler/lp_rational.m:
Tighten the inst of an output argument for use by intermod.m.
Bring programming style up to date.
compiler/parse_pragma.m:
Don't put a maybe attributes field into item_pragma_infos.
Include the varset in structure sharing and reuse pragmas.
Use simplest_spec where possible.
compiler/parse_tree_out.m:
Add predicates for writing out the new parse trees of .opt and
.trans_opt files.
compiler/parse_tree_out_pragma.m:
Add predicates needed by the new code in parse_tree_out.m.
compiler/add_mutable_aux_preds.m:
compiler/canonicalize_interface.m:
compiler/comp_unit_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/item_util.m:
compiler/make_hlds_error.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.qualify_items.m:
compiler/prog_item_stats.m:
compiler/recompilation.version.m:
Conform to the changes above.
|
||
|
|
d5ade25753 |
Implement the obsolete_proc pragma.
While the existing obsolete pragma declares an entire predicate or function
obsolete, the new obsolete_proc pragma does this for only THE NAMED MODE
of a predicate or function.
NEWS:
doc/reference_manual.texi:
Mention and document the new pragma.
compiler/prog_item.m:
Add the new pragma. Rename the old pragma to "obsolete_pred". (This affects
only the compiler's internal name; the user visible name stays the same.)
Move a type definition next to its related types.
compiler/parse_pragma.m:
Read in the new pragma.
compiler/hlds_pred.m:
Create a slot in proc_infos for the information in the new pragma.
compiler/add_pragma.m:
Add the new pragma to the HLDS.
To avoid adding to the substantial existing code duplication in this
module, factor out two commonly recurring pieces of code: one that
looks up the (hopefully unique) pred_id specified by a pragma, and
one that looks up and (if found) transforms the procedure specified
by a pragma.
Use error-message phraseology consistent with that employed by
the newly-factored-out predicate even in places that cannot use them.
Move the code handling foreign_export pragma here from add_foreign_proc.m
to take advantage of the newly-factored out predicates.
compiler/add_foreign_proc.m:
Delete the code moved to add_pragma.m.
Fix the structure of the remaining code by putting related code fragments
next to each other.
compiler/simplify_goal_call.m:
Generate warnings to obsolete procedures as well as obsolete predicates.
compiler/parse_tree_out_pragma.m:
Output the new pragma.
Factor out existing common code.
compiler/hlds_code_util.m:
Put a predicate's arguments into a more meaningful order.
compiler/make_hlds_error.m:
Allow the caller of report_undefined_pred_or_func_error to specify
whether the error applies to a predicate or a function. Most callers
don't have that info, but some do, and using this info when available
allows us to generate a more specific error message.
compiler/add_clause.m:
Conform to the changes above.
Make a predicate easier to read by moving unimportant code out-of-line.
compiler/intermod.m:
Conform to the changes above. Do this in a way that is adaptable to
making intermod.m generate lists of items instead of simply writing
stuff out, even though this makes the diff to this file more complex
than immediately necessary.
compiler/add_mutable_aux_preds.m:
compiler/add_pragma_type_spec.m:
compiler/canonicalize_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/item_util.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.qualify_items.m:
compiler/prog_data_pragma.m:
compiler/prog_item_stats.m:
compiler/recompilation.version.m:
Conform to the changes above.
compiler/options.m:
Provide a simple way for the configure script to test for the presence
of this new addition.
tests/invalid/obsolete_proc_pragma.{m,err_exp}:
A test case for the new pragma.
tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
Enable the new test case, and set it to run with --halt-at-warn.
tests/invalid/bug83.err_exp:
tests/invalid/require_tailrec_invalid.err_exp:
Update these two files to expect updated error messages.
|
||
|
|
8e62f93c4d |
Use maps for several kinds of items in interface file parse trees.
Using lists to store type-, inst- and mode definitions, foreign enum
definitions and type representation items does nothing to enforce
uniqueness requirements, such as "every inst constructor should have
at most one one non-abstract definition in the interface of a module".
However, one can encode such requirements using maps.
This diff therefore changes the representation of these kinds of items
inside the interface-kind-specific parse trees of interface files to use
these kinds of maps. It does not take advantage of the possilities
offered by this diff; that is for a later change.
compiler/prog_item.m:
Make the change described above.
Since after this diff, the info in foreign_enum pragmas will be in a map,
while the info in other kinds of pragmas will still be in a list, avoid
the possibility of being able to represent invalid states by giving
foreign enums their own item kind, separate from that of pragmas.
Since foreign export enums are handled very similarly to foreign enum
pragmas in many places, given them their own item kind as well.
Update the predicates converting generic interface file parse trees
to interface-kind-specific parse trees, and vice versa, to conform
to the changes above.
compiler/comp_unit_interface.m:
Convert lists to maps before putting them into interface-kind-specific
parse trees where the above change requires it.
compiler/hlds_module.m:
Delete types that contain almost exactly the same info as the item
information we now keep for foreign enum and foreign export enum items.
Include the item status next to foreign enum items, since that is the
one piece of info the deleted types had that we need.
compiler/parse_pragma.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_pragma.m:
Parse and print out foreign enums and foreign export enums as their
own item kinds, not as kinds of pragmas.
compiler/add_foreign_enum.m:
compiler/canonicalize_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/make_hlds.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qual_errors.m:
compiler/module_qual.qualify_items.m:
compiler/prog_item_stats.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
Conform to the changes above.
|
||
|
|
0584bc300d |
Expand obsolete pragmas with an optional "suggested replacements" field.
doc/reference_manual.texi:
NEWS:
Document the extension.
compiler/prog_item.m:
Add a field to the representation of obsolete pragmas to hold
an optional list of suggested possible replacements.
compiler/parse_pragma.m:
Parse the optional second argument in obsolete pragmas.
Improve the error messages we generate for several kinds of errors
we may encounter when parsing pragmas by making them more specific.
compiler/hlds_pred.m:
Since an obsolete pragma now contains more than one bit of information
(present vs not present), change their representation from a simple marker
to a field containing the possible replacements.
Make a comment about access stats more useful by sorting its contents
on frequency of access, and putting it before the structure it is about.
compiler/simplify_goal_call.m:
When generating warnings about calls to obsolete predicates or functions,
mention the suggested replacements, if there are any.
compiler/add_pragma.m:
Fill in the new field when adding an obsolete pragma to the HLDS.
compiler/globals.m:
Add a function for use by new codee in parse_pragma.m.
compiler/canonicalize_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/hlds_out_pred.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out_pragma.m:
compiler/prog_item_stats.m:
compiler/recompilation.version.m:
compiler/table_gen.m:
Conform to the changes above.
tests/invalid/bad_foreign_code.err_exp:
tests/invalid/bad_foreign_enum.err_exp:
tests/invalid/bad_foreign_export.err_exp:
Expect the improved error messages from parse_pragma.m.
tests/warnings/simple_code.{m,exp}:
Add tests of the new forms of the obsolete pragma.
|
||
|
|
615d2795c8 |
Take foreign_import_modules out of the item type.
compiler/prog_item.m:
Even though we express foreign import module declarations syntactically
as pragmas, semantically, they are much closer to import_module
declarations. This means that the treatment they require in most places
in the compiler is similar to the treatment of import_module declarations,
and quite different from the treatment of other kinds of items.
Therefore this diff takes foreign_import_module declarations (FIMs
for short) out of item type. From now on, in parse trees and their
components, FIMs are stored in data structures of their own, next to
import_module declarations.
compiler/parse_types.m:
Provide a mechanism for the parser to return FIMs as an entity kind
of its own, not as an item.
compiler/comp_unit_interface.m:
Conform to the changes above, and give a predicate a more specific name.
compiler/module_qual.m:
Conform to the changes above, and require .int3 files to contain no FIMs.
compiler/canonicalize_interface.m:
compiler/check_raw_comp_unit.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/hlds_module.m:
compiler/item_util.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_separate_items.m:
compiler/module_imports.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_module.m:
compiler/parse_pragma.m:
compiler/parse_tree_out.m:
compiler/prog_item_stats.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/split_parse_tree_src.m:
Conform to the changes above.
|
||
|
|
b70bdb2d95 |
Delete the context field from item_blocks.
compiler/prog_item.m:
The context field in item_blocks was used only in setting the context
fields of other item blocks. There was no end user, and many places
that created item_blocks ab initio put a dummy value into the field
anyway, so this diff deletes the field.
The intent is to prepare for future changes to the module_and_imports
structure that replace lists of item blocks, each which may be
of any section, with just one list of items, one list of includes
and one list of avails per section kind.
In some places, this should allow us to avoid searching item blocks
for the right sections; in other places, it should allow us to replace
two nested loops (on blocks and on e.g. items) with just one loop
(e.g. on items).
We do still record section contexts during parsing, because this is
needed for the context of some error messages (e.g. the one we generate
for an implementation section in a submodule that is included in the
interface section of its parent module).
compiler/check_raw_comp_unit.m:
compiler/comp_unit_interface.m:
compiler/deps_map.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_separate_items.m:
compiler/module_imports.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.m:
compiler/module_qual.qualify_items.m:
compiler/modules.m:
compiler/parse_module.m:
compiler/parse_tree_out.m:
compiler/prog_item_stats.m:
compiler/recompilation.check.m:
compiler/split_parse_tree_src.m:
Conform to the change above.
|
||
|
|
de0a5f13b7 |
Delete item_nothing.
compiler/prog_item.m:
Delete item_nothing as an alternative in the item type.
These items never occur in parse trees, being handled fully at the time
when the parse tree is constructed. Nevertheless, their presence in
the item type required code that handles parse trees to worry NOW about
how they should handle item_nothings in case a possible future change
let them survive the parse tree construction process.
compiler/parse_types.m:
Replace item_nothing with iom_handled in the item_or_marker type,
whose values are used only during the parse tree construction process.
The replacement is significantly simplified compared with the original,
containing only the functionality that our current use cases need.
compiler/parse_error.m:
Remove rme_warn_item_nothing from the read_module_error type.
It was being added to error sets, but nothing ever tested for its presence.
Its task as a signifier of the presence of a compilation-stopping error
now belongs to the severity of the associated error_specs.
compiler/parse_item.m:
Fix the logic of the code that decides whether the format of the
version_numbers_map item is recorded in an obsolete format
(i.e. whether its *own* version is too old). Specificially,
treat non-numerical "version number" terms as being malformed,
not as being obsolete.
compiler/canonicalize_interface.m:
compiler/check_raw_comp_unit.m:
compiler/comp_unit_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/item_util.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/modules.m:
compiler/parse_module.m:
compiler/parse_pragma.m:
compiler/parse_tree_out.m:
compiler/prog_item_stats.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
Conform to the changes above.
|
||
|
|
df47de186b |
Tighten module accessibility rules.
NEWS:
Announce this fact.
compiler/modules.m:
If module m.n imports module x.y.z, require it to import its ancestor
modules (x and x.y).
If module m.n imports module x.y.z in the interface, require it to import
its ancestor modules (x and x.y) in the interface.
If module m.n imports module x.y.z, require us to see an include for z in
x.y, if we see an interface file for x.y.
Given a module m.n, require us to see an include for n in m's private
interface file.
These rules are tighter than the rules we enforced before.
Report any violations of the above rules when generating code for m.n.
Previously, we also reported violations when generating interface files.
compiler/prog_item.m:
For each item block, record which module it came from. (We have long
recorded which *section* of that module it came from.) This is needed
by some of the new functionality in modules.m.
Likewise, record the module name in the module components (from which
item blocks are later constructed).
compiler/parse_module.m:
Record the module name in module components and item blocks.
compiler/check_raw_comp_unit.m:
compiler/comp_unit_interface.m:
compiler/deps_map.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_separate_items.m:
compiler/module_imports.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
compiler/prog_item_stats.m:
compiler/recompilation.check.m:
compiler/split_parse_tree_src.m:
Conform to the changes above.
tests/invalid/missing_parent_import.err_exp:
Expect an additional error message we now generate.
tests/invalid/sub_c.err_exp:
tests/invalid/test_nested.err_exp:
Expect the more specific error messages we now generate.
|
||
|
|
e08b8505e9 | Import the parents of *all* imported modules. | ||
|
|
5cf4d9608f |
Make foreign_import_module a separate kind of item.
compiler/prog_item.m:
Change foreign_import_module from being a kind of pragma item, to being
an item in its own right. Although we use pragma syntax to represent them,
they are NOT allowed in source files. (Though we do not yet enforce this.)
compiler/add_pragma.m:
compiler/comp_unit_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m
compiler/hlds_module.m::
compiler/intermod.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/modules.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_pragma.m:
compiler/prog_item_stats.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/write_module_interface_files.m:
Conform to the change above by treating the item kind as the pragma kind
it replaced.
compiler/parse_pragma.m:
As above, but also improve variable names.
compiler/item_util.m:
Conform to the change above, but treat the item kind differently from
the pragma kind it replaced, by not stating that foreign_import_module items
require the presence of *other* module imports. (They don't.)
|
||
|
|
fb97df69ed |
Make "compute type representations" a separate pass.
The ultimate purpose of this diff is to prepare for future improvements
in type representations, allowing values of some data types to be represented
more compactly than up to now.
The main way this diff does that is by creating a separate pass for deciding
how values of each type should be represented. We have traditionally decided
data representations for each type as its type definition was processed
during the make_hlds pass, but these decisions were always tentative,
and could be overridden later, e.g. when we processed foreign_type or
foreign_enum pragmas for the type. This dispersed decision making algorithm
is hard to understand, and therefore to change.
This diff centralizes decisions about type representations in a separate
pass that does nothing else. It leaves the algorithm distributed among
several files (du_type_layout.m, make_tags.m, and add_foreign_enum.m) for now,
to make reviewing this diff easier, but soon after it is committed I intend
to move all the relevant code to du_type_layout.m, to centralize the decision
code in "space" as well as in time.
For the reason why this pass runs before any of the semantic analysis
passes, instead of after all of them as I originally intended and as we
discussed on m-dev in late october 2017, see the big comment at the start of
du_type_layout.m.
As per another part of that same discussion on m-dev, this diff
makes a start on implementing a new type of item, the type_repn item,
which is intended *only* to be used in compiler-generated interface files,
*not* in source files. It is only a start because we can use these items
only *after* the creation of a separate type representation decision pass,
and this diff is already very big. The code for making the compiler understand
these items will be added later. The code for generating them will be added
later still, once the code for understanding them has been installed on
all our systems.
Since I was going to be working on the affected code anyway, this diff
also carries out two other decisions that came out of that discussion:
- the deletion of the ability to reserve a tag in a type for HAL,
either via a compiler option or via a pragma, and
- the deletion of the ability to represent a functor using the address
of a statically allocated object (which we haven't used and won't use,
because it slows down accesses to *all the other functors* of the type).
compiler/mercury_compile_front_end.m:
Invoke the new pass for making decisions about type representations
after the make_hlds pass. (We used to do only the final part of it then.)
Fix a bad dump stage name.
Add an extra check for what it means for a module to be error free.
Make a sub-switch explicit.
compiler/hlds.m:
compiler/make_hlds.m:
Move the modules that implement the new pass from the make_hlds package
to the hlds package, to give the compiler's top level access to them.
Make the same move for the modules that the new pass's modules need.
Since they are now part of hlds, they cannot reach into make_hlds,
and I think this is a cleaner solution than forwarding predicates.
Delete some forwarding predicates that are no longer needed.
compiler/notes/compiler_design.html:
Document the updated location of the moved modules.
Add an XXX to note a place where the documentation has not been
updated in the past.
compiler/du_type_layout.m:
Add code to implement the new pass.
Keep the algorithm for deciding type representations as close
to the previously used algorithm as possible, since this diff
is already big enough. (The previous algorithm was scattered across
add_type.m, add_foreign_enum.m, and make_hlds_passes.m.)
Simplifications and optimizations will come later, after this module
is merged with make_tags.m and with (at least) the foreign_enum half of
add_foreign_enum.m.
compiler/make_tags.m:
Keep the functionality of this module, which does both the first part
of deciding type representations (tentatively assigning tags to functors,
an assignment that may be overridden later), and the last part (packing
multiple adjacent less-than-word-sized enum args into a single word,
if possible.), but simplify it where possible, and note possibilities
for further improvements.
compiler/add_foreign_enum.m:
This module has two halves, one dealing with foreign_enum pragmas
and one dealing with foreign_export_enum pragmas.
Change the half that deals with foreign_enum pragmas to just build
a data structure that du_type_layout.m will need to make its decisions,
this structure being a map from type_ctors to the foreign enum
specification applicable to the current target language. Include
in this structure a component that add_foreign_enum.m itself can use
to report better error messages for duplicate foreign_enum pragmas;
this component records, for each type_ctor and language, the context
of the previous foreign_enum pragma for that combo.
Change the input for the half that deals with foreign_export_enum pragmas
to reflect the fact that it is invoked by du_type_layout.m after all
decisions about type representations have already been made.
compiler/add_special_pred.m:
Move this module from the make_hlds package to the hlds package,
since the code that adds special preds for type is now called from
du_type_layout.m.
Change the names of predicates to make clear whether they add
only the declaration of a predicate, only its definition, or both.
Don't try to pre-guess whether the implementation of a type's
compare predicate will need an index predicate. Let the code
that generates calls to the index predicate both declare and define
the index predicate. This change removes the potential for
inconsistencies between the two pieces of code.
compiler/add_pred.m:
Move this module from the make_hlds package to the hlds package,
since add_special_pred.m needs access to it.
compiler/add_type.m:
When adding a type definition to the HLDS, don't try to decide
its representation. Any such decision was tentative anyway, due
to the possibility of e.g. the later processing of foreign_type
or foreign_enum pragmas for the type. Likewise, don't try to
create the special (unify, compare) predicates for the type.
Leave both tasks to the du_type_layout pass.
Likewise, don't try to pack the representation of types, or record
no_tag types in the table of no_tag types, during the post-processing
pass either; leave both of these to du_type_layout as well.
Rename the predicate that post_processes type definitions to reflect
the two tasks left for it to do.
compiler/prog_data.m:
Do not store width information about the arguments of those data
constructors in the parse tree. That information is not computed
until later; until then, it was always filled in with dummy values.
(But see hlds_data.m below.)
Use bespoke types to represent the presence or absence of user-specified
unify and compare predicates.
Change the representation of data constructors to use a single "maybe"
type, not two lists, to denote the presence or absence of existentially
typed arguments.
Give the HLDS the ability to hold representation information about
abstract types that in the future we will get from type_repn items
in the defining modules' interface files.
Delete the uses_reserved_tag type, since we never use reserved tags
anymore.
compiler/prog_item.m:
Add the new type_repn item type, which is not used yet.
Delete the reserve_tag pragma.
Fix an earlier mistake in the wording of a context message.
compiler/hlds_data.m:
Put all the fields of hlds_du_type (the type definition variant dealing
with discriminated union types) that deal with type representation
issues in a single "maybe" field that is set to "no" before the
type representation decision pass has been run.
Add new type, constructor_repn, that stores the same information as the old
constructor type (defined in prog_data.m), PLUS the information
describing how terms with that data constructor are stored.
Likewise, add a new type ctor_arg_rep, which likewise stores
the widths of each constructor argument. When we implement
argument reordering, we would store the offset of the arg as well.
Since the parse tree representations of constructors and their arguments
don't store representation information anymore, the cons_table they
are stored in doesn't either. Make the lookup of representation information
for a given constructor possible by adding a map to the new "maybe" field
of hlds_du_type.
Provide some utility predicates.
Optimize some existing predicates.
Rename some types to better reflect their meaning.
compiler/hlds_module.m:
Provide a slot in the module_info for storing the information
gathered by make_hlds.m that is needed by the new pass.
compiler/make_hlds_separate_items.m:
When we see either a foreign_enum or a foreign_export_enum pragma,
return values of a bespoke type for them (a type defined in
hlds_module.m), instead of an item_pragma. This makes handling them
considerably easier.
compiler/make_hlds_passes.m:
With the changes in this diff, adding a type to the HLDS won't
decide its representation. Therefore delete the code that used
to loop over foreign_export_enum pragmas; in the absence of
the final type representation information, it won't work right.
Record the information that the du_type_layout pass will need
in the module_info.
compiler/add_pragma.m:
Delete the code for passing on foreign_enum and foreign_export_enum
pragmas to add_foreign_enum.m; they are now passed to add_foreign_enum.m
by du_type_layout.m.
Move a utility predicate to make_hlds_error.m, to allow add_foreign_enum.m
to call it.
compiler/make_hlds_error.m:
Add the utility predicate moved from add_pragma.m.
Move the module from the make_hlds to the hlds package.
compiler/module_qual.m:
Provide a mechanism for recording error messages about e.g. undefined
types without recording that we found an undefined type. This sounds
strange, but there is a valid use case.
When a type definition declares a functor's argument to be of an
undefined type, that error is usually fatal; we stop the compiler
from proceeding even to typechecking, since the typechecker will
probably abort with a map lookup failure. Most other references
to undefined types are similarly fatal for the same reason. However,
if e.g. a foreign_export_enum pragma refers to an undefined type,
that error *won't* be visible to the typechecker, and therefore
won't crash it. The error will still cause the compiler to exit
without generating any target language code, but at least it will be
able to run the typechecker and other semantic analysis passes.
Without this change, the compiler will report only one error in
the ee_invalid.m test case; with it, it reports *every* error
in the test case expected output.
compiler/module_qual.qualify_items.m:
Use the capability describe above for undefined types in
foreign_export_enum pragmas.
compiler/module_qual.qual_errors.m:
Delete a (somewhat incorrect) copy of a predicate in prog_item.m,
to reduce code duplication.
compiler/prog_type.m:
Add ways to represent abstract types whose representations are nevertheless
known (from type_repn items in the defining modules' interface files)
to be notag or dummy types. This will be needed to fix Mantis bug #441,
a fix that will probably be one of the first later changes to build
on this diff.
Delete a type moved to type_util.m.
compiler/type_util.m:
Provide extra versions of some predicates, with the difference between
the old and the new versions being that one requires type representations
to have been decided already, and the other one does not.
Move the definition of the ctor_defn type here from prog_type.m,
since prog_type.m itself does not use it, but type_util.m does.
Give some predicates more meaningful names.
compiler/parse_type_defn.m:
Simplify the code for parsing type definitions, to make it easier
to reuse to parse type_repn items.
Add a sanity check that requires existential constraints to have
*some* existential variables to apply to.
Allow "type_is_representable_in_n_bits" as a synonym for
"type_is_abstract_enum", since in the future we want to be able to pack
e.g. multiple int8s, not just multiple enums, into a single word.
Generate more specific error messages for some classes of malformed input.
compiler/parse_type_repn.m:
New module to parse type_repn items.
compiler/polymorphism.m:
Make some predicates that operate on type constructors take
the type constructors themselves as input arguments, not a whole type
*using* that type constructor. Put the arguments of those predicates
in a more standard order.
Note that some predicates don't belong in this module.
compiler/special_pred.m:
Make the code that decides whether a special predicate for a type
constructor can be defined lazily avoid using type representation
information. (Actually, we now make decisions about lazy vs eager
definitions after type representation is available, but that was
not so in an earlier version of this change, and the new code
is more robust.)
compiler/unify_proc.m:
When we decide to generate code for a compare predicate that needs
the type to have an index predicate, don't presume that the index
predicate has already been declared and defined; instead, declare
and define it then and there. (Index predicates are *never* called
from anywhere else.)
Pack the information needed to define a special predicate
into a single structure, to simplify the above.
Since the creation of a clause for a compare predicate may now require
the declaration and definition of an index predicate, the module_info
field of the unify_proc_info is now a writeable field.
Give some predicates and function symbols more meaningful names.
Note some problems with the existing code.
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_mode.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_solver.m:
compiler/check_typeclass.m:
compiler/code_info.m:
compiler/comp_unit_interface.m:
compiler/ctgc.selector.m:
compiler/ctgc.util.m:
compiler/default_func_mode.m:
compiler/det_report.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/erl_code_gen.m:
compiler/export.m:
compiler/foreign.m:
compiler/get_dependencies.m:
compiler/goal_expr_to_goal.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_out_module.m:
compiler/inst_check.m:
compiler/inst_test.m:
compiler/inst_util.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/make_hlds_warn.m:
compiler/ml_accurate_gc.m:
compiler/ml_simplify_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/mode_util.m:
compiler/modecheck_goal.m:
compiler/module_qual.collect_mq_info.m:
compiler/modules.m:
compiler/parse_item.m:
compiler/parse_pragma.m:
compiler/parse_tree.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_pragma.m:
compiler/post_term_analysis.m:
compiler/proc_requests.m:
compiler/prog_item_stats.m:
compiler/qual_info.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/resolve_unify_functor.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/simplify_goal_ite.m:
compiler/stack_opt.m:
compiler/state_var.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/superhomogeneous.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/term_norm.m:
compiler/trailing_analysis.m:
compiler/type_constraints.m:
compiler/type_ctor_info.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/untupling.m:
compiler/unused_imports.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
Conform to the changes above.
tests/invalid/Mmakefile:
Disable the reserve_tag test case, as it is not applicable anymore.
tests/invalid/exported_foreign_enum.{m,err_exp}:
tests/invalid/pragma_qual_error.{m,err_exp}:
Delete reserve_tag pragmas from these test cases, and its effects
from the expected outputs.
tests/invalid/bad_foreign_type.err_exp:
tests/invalid/bigtest.err_exp:
tests/invalid/foreign_enum_invalid.err_exp:
tests/invalid/type_lhs_var.err_exp:
tests/invalid/uu_type.err_exp:
tests/invalid/where_abstract_enum.err_exp:
tests/invalid/where_direct_arg.err_exp:
Expect the updated messages for some errors.
tests/valid/Mmake.valid.common:
tests/valid/Mmakefile:
Disable any reserve_tag test cases, as they are not applicable anymore.
|
||
|
|
2ac8465659 |
Make the code adding new types to the HLDS readable.
The motivation for this diff was that I wanted the compiler to generate
a warning if a module declared the same type twice. (During the cleanup
of unify_proc.m I did recently, I found and fixed such a duplicate
declaration.)
compiler/add_type.m:
The old code of module_add_type_defn was not just long (210+ lines),
it is also very complex.
Part of this complexity was sort-of justified. It dealt with adding
three separate kinds of item_type_defns: abstract type "definitions",
which are actually declarations; the definitions of Mercury types,
and the definitions of foreign types. A single type could have more than
one of these (e.g. declaration and a definition, or a Mercury definition
and a foreign definition), and it had to be prepared to process these
in any order.
Part of this complexity was self-inflicted. The parts of the predicate
that dealt with the same kind of definition were not always next to each
other, and for some parts, it wasn't even clear *what* kind of definition
it was dealing with. It did the same tests on both the old and updated
versions of definitions, when those definitions were guaranteed to be
identical; the "updating" predicate was a no-op. And it used completely
different code for detecting and handling related errors.
This diff fixes the above problems. It separates the task of adding
an item_type_defn to the HLDS into three subtasks, done in three separate
predicates: adding type declarations, adding Mercury definitions, and
adding foreign definitions. It specializes each predicate to its task,
and simplifies its decision flow. It also delegates the creation of
(most) error messages to separate predicates. Together, these changes
make each of module_add_type_defn_{abstract,mercury,foreign} easily
understandable.
Generate a warning if a type is declared twice, i.e. if e.g.
":- type x." is followed by another ":- type x.".
Call module_info_incr_errors to register the presence of errors in just
one central place. (Before, some of the places that generated error
messages incremented the error count, and some places didn't.)
Improve the wording of some error messages.
Refer to type names in error messages by unqualified sym_names
in cases where the module qualifier being elided is obvious from
the name of the module being compiled.
Add documentation.
Add descriptions of potential future improvements.
Add some XXXs at places that I think deserve them.
Give some predicates and variables better names.
compiler/prog_data.m:
Change the parse tree representation of type definitions by
explicitly specifying a type for storing the contents of each kind
of type definition.
compiler/hlds_data.m:
Give a predicate a better name.
Use one of the new types in prog_data.m in the HLDS version of type
definitions, to minimize differences between the parse tree and HLDS
versions.
compiler/add_foreign_enum.m:
compiler/add_pragma.m:
compiler/add_special_pred.m:
compiler/check_typeclass.m:
compiler/du_type_layout.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/foreign.m:
compiler/get_dependencies.m:
compiler/hlds_code_util.m:
compiler/hlds_out_module.m:
compiler/inst_check.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_separate_items.m:
compiler/make_tags.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/module_qual.qualify_items.m:
compiler/parse_pragma.m:
compiler/parse_tree_out.m:
compiler/parse_type_defn.m:
compiler/post_term_analysis.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/resolve_unify_functor.m:
compiler/simplify_goal_ite.m:
compiler/special_pred.m:
compiler/switch_util.m:
compiler/term_norm.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
Conform to the changes in prog_data.m.
library/io.m:
library/store.m:
Delete duplicate type declarations that add_type.m now complains about.
tests/invalid/bad_foreign_type.{m,err_exp}:
Extend this test to test the new warning.
Expect the updated versions of some error messages.
tests/invalid/extra_info_prompt.err_exp:
tests/invalid/foreign_type_visibility.err_exp:
tests/invalid/user_eq_dummy.err_exp:
Expect the updated versions of some error messages.
|
||
|
|
61d0c67243 |
Improve diagnostics for foreign_{export_,}enum pragmas.
We can now generate error messages for types that have both foreign_enum
and reserve_tag pragmas, which we couldn't before. (In some cases,
we used to get a compiler abort.)
compiler/add_foreign_enum.m:
Don't stop after finding the first problem with a foreign_export_enum
or foreign_enum pragma; if a pragma has more than one problem,
generate reports for them all.
When reporting that the type named in a foreign_export_enum or
foreign_enum is not an enum type, have the error message say *why*.
Fill in the two new fields in exported_enum_infos (see below).
compiler/make_hlds_passes.m:
Add reserve_tag pragmas to the HLDS before adding foreign_export_enum
and foreign_enum pragmas. Since such a pragma would convert an enum
type into a non-enum type, this is needed to ensure that the code
in add_foreign_enum.m that checks whether a type is an enum type
is operating on data that is final. Without that, it may make
wrong decisions.
compiler/make_hlds_separate_items.m:
compiler/add_pragma.m:
Provide the support needed by the new code in make_hlds_passes.m.
In add_pragma.m, rename some insts to avoid name ambiguities,
and simplify an if-then-else.
compiler/hlds_module.m:
Add two fields to exported_enum_infos, to make processing them easier.
(We couldn't do this earlier, since add_foreign_enum.m didn't have
access to the final forms of the bodies of du type definitions,
which is where the values of the two new fields come from.)
compiler/export.m:
compiler/ml_type_gen.m:
Simplify some code using the new fields in exported_enum_infos.
compiler/error_util.m:
Provide a mechanism to control whether sym_names in cons_ids
are module qualified or not. This is "needed" by the new error
messages created in add_foreign_enum.m.
compiler/check_promise.m:
compiler/det_report.m:
compiler/parse_inst_mode_name.m:
compiler/typecheck_errors.m:
Conform to the change to error_util.m.
compiler/make_tags.m:
Clean up some code and some comments.
tests/invalid/exported_foreign_enum.{m,err_exp}:
A new test case to test the new capability to print more than one
error message for the same pragma.
tests/invalid/Mmakefile:
Enable the new test case.
tests/invalid/ee_invalid.err_exp:
Expect improved error messages.
|
||
|
|
5649f36c80 |
Handle "use_module in interface, import_module in implementation".
If a module m1 imports module m2 using a use_module declaration in its
interface section but also imports it using an import_module declaration
in its implementation section, then references to entities defined in m2
in the interface of m1 must be module qualified, but similar references
in the implementation of m1 need NOT be module qualified.
The Mercury compiler has long had a bug that allowed entities imported
in the implementation of module m1 to be used in the interface of m1,
against the rules of the language. When I fixed that bug on 2015 nov 11,
the compiler became unable to properly process the situation described
in the paragraph above, because it still had another bug, which was that
it had a single setting for module qualification requirements: either it
was required *everywhere* in m1, or it was required *nowhere* in m1.
This diff fixes that bug (mantis bug 401) by allowing different requirements
in this respect in the interface of m1 versus its implementation.
It also changes the de-facto meaning of what exactly a use_module declaration
requires. The reference manual says only:
Uses of entities imported using @code{use_module} declarations
@emph{must} be explicitly module qualified.
This WAS unambiguous when it was written in june 1997, a few months before
submodules were added to the language. With a flat module system, there were
no nested module names, so either the module name was present, or it wasn't.
In the presence of nested modules, though, it IS ambiguous: HOW MUCH of
the module name must be present? The reference manual is silent on this.
At the moment, in the presence of a use_module for module ma.mb.mc,
a predicate p1 in ma.mb.mc may of course be referred to as ma.mb.mc.p1,
but may also be referred to as mb.mc.p1, or even just mc.p1. The specification
of mc is always required, but exactly WHICH of the previous module name
components are required depends on whether e.g. ma or ma.mb were themselves
imported via use_module or import_module declarations. The code implementing
the check (find_matches_in_permissions_map in module_qual.id_set.m) is itself
not too clear.
This diff changes the rules so that all references to anything imported
via a use_module declarations have to be fully qualified. This is stricter
than the existing rule, but it is MUCH simpler, and it better matches
the original intent of use_module declarations, which is the avoidance
of ALL POSSIBILITY of ambiguity.
NEWS:
doc/reference_manual.texi:
Document this change to the language.
compiler/prog_item.m:
Change the representation of sections in .int* files. Previously,
we recorded whether the interface file that the section was from
was read for an `import_module' or a `use_module' declaration.
We now allow the recording of the fact that it had both declarations,
a use_module in the interface and an import_module in the implementation.
compiler/modules.m:
Treat modules that have both a `use_module' declaration in interface
and an `import_module' declaration in the implementation as being of this
new internal section kind.
Add some infrastructure for debugging similar problems in the future.
compiler/module_qual.id_set.m:
Change the permissions system. Instead of recording *independently*
whether (a) an entity may be used in the interface and (b) whether
references to it must be qualified, record *separately* whether
(a) it may be used in the interface, and if so with what qualification
requirements, and (b) what its qualification requirements are in the
implementation. Unlike the old permission setup, the new one allows us
to express the "use_module in interface, import_module in implementation"
situation.
Implement the change to the language, by requiring full module
qualification of entities imported via use_module declarations.
This allows us to use a single parameterized piece of code to handle
both unqualified and qualified references, whereas before we used
separate pieces of code for them.
Change the way we handle errors in module qualification. Instead of
looking only for precise matches only, and looking for the possible causes
of errors only if we find either no matches or two or more matches, we now
return the near-miss matches as well, the ones that we need to decide
on what error message we want to generate. While this is slightly slower,
it is *much* simpler, since it allows us to avoid duplicating the search
code: once for precise matches only, once for no-match errors, and once
for multiple-match errors.
compiler/module_qual.collect_mq_info.m:
Set permissions for symbol access according to the new permissions system.
Code that previously triggered the bug will use the new interface file
section kind, and can now have its permissions record correctly.
compiler/module_qual.qual_errors.m:
Use a single predicate to generate error messages for all situations
in which there is not a single precise match for a module qualification.
This allows us to diagnose multiple potential problems with a single
lookup.
Change the wording of an existing error message to avoid a possibly-untrue
implication.
compiler/hlds_data.m:
Rename a field of the type_defn type to better document its meaning.
compiler/make_hlds.m:
Document the meaning of the need_qualifier field in sec_infos.
compiler/add_type.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.m:
compiler/pred_table.m:
compiler/parse_tree_out.m:
compiler/prog_item_stats.m:
Conform to the above changes.
mdbcomp/sym_name.m:
Add a utility predicate for use in looking for near-miss matches
in module qualification.
Make the documentation of a related predicate more precise.
tests/invalid/bad_instance.m:
tests/submodules/class.m:
tests/submodules/nested.m:
tests/submodules/nested3.m:
tests/submodules/parent.m:
Make names fully module qualified where the language rules now require it.
tests/submodules/deeply_nested.m:
Comment out a part of the test that tested the partially qualified names,
since these are now not allowed.
tests/invalid/errors.err_exp:
Expect a now-improved error message.
tests/invalid/test_nested.err_exp:
tests/invalid/transitive_import.err_exp:
tests/invalid/undef_type.err_exp:
Expect a now less-likely-to-mislead error message.
tests/valid_seq/int_impl_imports.m:
tests/valid_seq/int_impl_imports_2.m:
The test case for mantis bug 401.
tests/valid_seq/Mmakefile:
Enable the new test case.
|
||
|
|
5251d1fdd6 |
Add `:- pragma consider_used(predname/arity)'.
Sometimes, one wants to keep some predicates around even if they are not
currently being used. Adding this pragma for such a predicate will shut up
dead procedure/predicate warnings both for the named predicate and for the
other predicates it calls, both directly and indirectly.
With two of these pragmas added to compiler/stratify.m, the number of
predicates being reported as dead goes from 25 to 0.
compiler/prog_item.m:
Define the new pragma.
compiler/prog_io_pragma.m:
Parse the new pragma.
compiler/parse_tree_out_pragma.m:
Write out the new pragma, if needed.
compiler/add_pragma.m:
Add the new pragma to the HLDS in the form of a marker on the named
predicate.
compiler/hlds_pred.m:
Define that marker.
compiler/dead_proc_elim.m:
If a predicate has that marker, consider all its procedures to be live.
compiler/comp_unit_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/hlds_out_pred.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.qual_errors.m:
compiler/module_qual.qualify_items.m:
compiler/prog_item_stats.m:
compiler/recompilation.version.m:
compiler/table_gen.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
tests/invalid/bad_consider_used.{m,err_exp}:
New test case to test the handling of invalid consider_used pragmas.
tests/invalid/Mmakefile:
Add the new test case.
|
||
|
|
c6cbc43448 |
Add new require_tail_recursion pragma.
This patch allows the pragma to be parsed, and records the information from
the pragma in the proc_info structure for the relevant procedures.
The patch uses the pragma for the MLDS backend. However because mutual
recursion is not yet supported on the MLDS backend, mutually recursive calls
are ignored by the pragma.
The patch also documents the pragma in the reference manual, this
documentation is commented out until it is implemented for both LLDS and
MLDS backends.
The patch does not implement the SCC feature discussed on the mailing list.
That can be added later.
compiler/prog_data.m:
compiler/prog_item.m:
Add new require_tail_recursion pragma.
compiler/prog_io_pragma.m:
Parse the new pragma.
Remove the arity_and_modes type and use pred_name_arity_mpf_mmode
type from prog_item.m
compiler/parse_tree_out_pragma.m:
Support pretty printing the new pragma.
compiler/hlds_pred.m:
Add require_tailrec_info to the proc_info structure.
compiler/add_pragma.m:
Add information from the pragma to the proc_info structure after
parsing.
compiler/compiler_util.m:
Add a general warning_or_error type.
compiler/mlds.m:
Add require_tailrec_info to MLDS functions.
compiler/ml_proc_gen.m:
Copy the require_tailrec_info information from the HLDS to the MLDS.
compiler/ml_tailcall.m:
Generate errors and warnings with respect to the require_tail_recursion
pragma.
compiler/mercury_compile.m:
compiler/mercury_compile_mlds_back_end.m:
Return errors from the MLDS tailcall optimisation pass.
compiler/add_pragma.m:
compiler/comp_unit_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/item_util.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.qual_errors.m:
compiler/module_qual.qualify_items.m:
compiler/prog_item_stats.m:
compiler/recompilation.version.m:
compiler/write_module_interface_files.m:
Conform to changes in prog_item.m.
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_type_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
Conform to changes in mlds.m.
doc/reference_manual.texi
Document the require_tail_recursion pragma
tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
tests/invalid/require_tail_recursion.err_exp:
tests/invalid/require_tail_recursion.m:
Add require_tail_recursion test case
|
||
|
|
1c3cd5d843 |
Carve make_hlds_separate_items.m out of make_hlds_passes.m.
compiler/make_hlds_separate_items.m:
New submodule of make_hlds_passes.m containing the code that
separates the different kinds of items in the augmented compilation
unit.
compiler/make_hlds_passes.m:
Include the submodule, and delete the code moved to it.
compiler/notes/compiler_design.html:
Document the new module.
|