mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 11:54:02 +00:00
083d376e6598628362ee91c2da170febd83590f4
133 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
f8429e128e | Put types before in insts in argument lists. | ||
|
|
ac05623367 |
Associate a type with an inst.
Many predicates working on the inst of a variable (or part of the value of
a variable) need to know the type of (that part of) the variable, but
in some contexts, the type is not available at compile time. (One instance
is the type of an existentially typed argument.) Because of this, the
compiler used to pass a maybe(mer_type) with each mer_inst.
Act on an old XXX to change this to pass a mer_type with each mer_inst,
with the mer_type being a type variable if the type is not known statically.
This is conceptually cleaner, and should also be faster, due to avoiding
yes() wrappers in the usual case where the type *is* available.
compiler/inst_match.m:
compiler/inst_merge.m:
compiler/inst_test.m:
As above.
compiler/inst_util.m:
Update the names as well as the types of two utility predicates.
Add a function for returning the canonical representation of no type
information being available.
compiler/instmap.m:
Conform to the changes above.
compiler/type_util.m:
Add a new utility predicate for use by inst_match.m. The old code
in inst_match.m called a nondet predicate as a semidet test
by throwing away all its output arguments. The new utility predicate
avoids the wasted work of constructing those arguments.
|
||
|
|
d76c7bf617 |
Break up inst_util.m and mode_util.m.
This step significantly improves module cohesion.
compiler/inst_abstract_unify.m:
New module carved out of inst_util.m, which does abstract unifications
on insts.
compiler/inst_merge.m:
New module carved out of inst_util.m, which merges insts.
compiler/inst_lookup.m:
New module carved partly out of inst_util.m and partly out of mode_util.m,
which looks up insts in the module_info, and then possibly expands out
the result.
compiler/mode_test.m:
New module carved out of mode_util.m, whose predicates
perform tests on modes.
compiler/mode_top_functor.m:
New module carved out of mode_util.m, which computes top_functor_modes
from modes.
compiler/inst_mode_type_prop.m:
New module carved out of mode_util.m, which propagates type information
into both insts and modes.
compiler/recompute_instmap_deltas.m:
New module carved out of mode_util.m, which recomputes goals'
instmap_deltas.
compiler/inst_test.m:
Move here the predicates in inst_util.m that perform tests on insts.
compiler/inst_util.m:
compiler/mode_util.m:
Delete the code that this diff moves to other modules.
compiler/check_hlds.m:
Add the new modules to the check_hlds package, the package that also
contains inst_util.m and mode_util.m. (Some of these modules could
be argued to fit better in the hlds package, but moving them there
would not be desirable while they depend on code that is still in the
check_hlds package.)
compiler/notes/compiler_design.html:
Document the new modules.
compiler/add_pragma_tabling.m:
compiler/arg_info.m:
compiler/bytecode_gen.m:
compiler/closure_analysis.m:
compiler/complexity.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/det_report.m:
compiler/direct_arg_in_out.m:
compiler/distance_granularity.m:
compiler/equiv_type_hlds.m:
compiler/error_msg_inst.m:
compiler/fact_table.m:
compiler/float_regs.m:
compiler/follow_code.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_pred.m:
compiler/hlds_rtti.m:
compiler/inlining.m:
compiler/inst_match.m:
compiler/inst_user.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/interval.m:
compiler/introduce_exists_casts.m:
compiler/lambda.m:
compiler/lco.m:
compiler/liveness.m:
compiler/lookup_util.m:
compiler/loop_inv.m:
compiler/mark_tail_calls.m:
compiler/ml_args_util.m:
compiler/ml_code_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_util.m:
compiler/mode_constraints.m:
compiler/mode_errors.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/oisu_check.m:
compiler/par_conj_gen.m:
compiler/pd_util.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/proc_requests.m:
compiler/prog_rep.m:
compiler/push_goals_together.m:
compiler/rbmm.region_transformation.m:
compiler/saved_vars.m:
compiler/simplify_goal_switch.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/ssdebug.m:
compiler/stack_opt.m:
compiler/stm_expand.m:
compiler/stratify.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.domain.m:
compiler/superhomogeneous.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/term_pass2.m:
compiler/term_util.m:
compiler/tupling.m:
compiler/unify_gen_construct.m:
compiler/unify_gen_util.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/untupling.m:
compiler/unused_args.m:
Conform to the changes above by importing the required new modules,
sometimes in addition to inst_util.m or mode_util.m, but more usually
instead of them.
|
||
|
|
0d7c8a7654 |
Specify pred or func for all pragmas.
*/*.m:
As above.
configure.ac:
Require the installed compiler to support this capability.
|
||
|
|
a818e42cb9 |
Put bigger/slower-varying inputs before others.
compiler/inst_match.m:
compiler/inst_test.m:
As above.
compiler/common.m:
compiler/constraint.m:
compiler/goal_mode.m:
compiler/hlds_pred.m:
compiler/inst_util.m:
compiler/instmap.m:
compiler/mode_comparison.m:
compiler/mode_errors.m:
compiler/mode_util.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/pd_info.m:
compiler/simplify_goal_disj.m:
compiler/unique_modes.m:
compiler/unused_args.m:
Conform to the changes above.
|
||
|
|
3a21e5e374 |
Move two predicates to better homes.
compiler/type_util.m:
compiler/inst_util.m:
Move two predicates that operate on types but are used only by code
that manipulates insts from type_util.m to inst_util.m. The reason
is that both predicates lose higher order inst information, and fixing
that will require them to operate on insts as well. Moving them now
should make the diff with the fix easier to review.
compiler/inst_match.m:
compiler/inst_test.m:
Conform to the moves above.
|
||
|
|
7bdca312ec |
Clean up more modechecking code.
compiler/inst_match.m:
Change the predicates that compare two insts to make the nested switch
(first on one inst, then the other), make the nesting explicit.
Give a predicate a more meaningful name.
Add XXXs on dodgy code.
|
||
|
|
cd081d83cb |
Clean up some modechecking code.
compiler/inst_match.m:
Replace a bool and a maybe with bespoke types, so that during a debugging
session, there is no need to waste time on trying to remember what e.g.
a "no" stands for.
compiler/modes.m:
Put the code that checks each arg's final inst into its own predicate,
to make the result easier to observe in mdb.
Don't thread a goal through the code that checks final insts,
since the code never updated or even looked at the goals.
Delete this pair of goals from the argument lists of the ancestors
of this predicate whenever possible, including an exported predicate.
compiler/modecheck_unify.m:
Put a piece of code making a tricky decision into its own predicate,
to allow breakpoints on that predicate to show the result of the decision.
Conform to the change in modes.m.
|
||
|
|
15aa457e12 | Delete $module arg from calls to unexpected. | ||
|
|
8547e1634b |
Fix some things reported by --warn-inconsistent-pred-order-clauses.
compiler/arg_info.m:
compiler/bytecode_data.m:
compiler/common.m:
compiler/compile_target_code.m:
compiler/delay_info.m:
compiler/det_util.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/from_ground_term_util.m:
compiler/hlds_out_goal.m:
compiler/inst_match.m:
compiler/inst_util.m:
compiler/mode_constraint_robdd.m:
compiler/ordering_mode_constraints.m:
compiler/simplify_info.m:
compiler/switch_detection.m:
compiler/type_util.m:
compiler/unique_modes.m:
As above.
compiler/Mercury.options:
Note a module that is not worth fixing this way.
|
||
|
|
b96dacdcac |
Make a bunch of switches complete.
compiler/exception_analysis.m:
compiler/frameopt.m:
compiler/get_dependencies.m:
compiler/labelopt.m:
compiler/ml_global_data.m:
compiler/ml_optimize.m:
compiler/options_file.m:
compiler/parse_class.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/type_util.m:
compiler/var_locn.m:
As above.
compiler/inst_match.m:
Fix a stray piece of code.
compiler/loop_inv.m:
Add a module qualification.
compiler/opt_util.m:
Delete two unused predicates.
|
||
|
|
1da267e9f0 |
Fix a bug in handling instances with --warn-unused-imports.
This fixes Mantis bug #412. compiler/unused_imports.m: Consider that an instance declaration makes a module "used" only if it occurs in the module being compiled, not in an imported or ancestor module. (Mantis bug 412 was caused by instance declarations in implicitly imported modules.) Fixing #412 also exposed another bug. When computing the set of modules used by predicates, we considered (besides some non-type entities) only the types of the predicate's arguments, not the types of non-argument variables. In one case in the compiler (mmc_analysis.m), this lead to some actually-used modules not being marked as such, which lead to false unused-import warnings to be generated for them. Fix this by scanning the types of all variables in all of a predicate's procedures, not just the arguments. Improve the infrastructure for debugging similar problems. Note some possibilities for future improvement. Change a predicate name to fit the naming scheme. compiler/analysis.m: Add an XXX about a possible improvement. compiler/hlds_out_module.m: Make the output we generate for instance methods more readable. As part of this, fix an old bug in the printing of the instance table: the first line of the first method of each concrete instance declaration was accidentally commented out. compiler/parse_tree_out.m: Export a different utility predicate for hlds_out_module.m. Make its name conform to the scheme used by related predicates. browser/browse.m: compiler/add_mutable_aux_preds.m: compiler/add_pred.m: compiler/add_special_pred.m: compiler/check_for_missing_type_defns.m: compiler/check_promise.m: compiler/exception_analysis.m: compiler/handle_options.m: compiler/inst_match.m: compiler/mercury_to_mercury.m: compiler/ml_tailcall.m: compiler/module_qual.m: compiler/op_mode.m: compiler/parse_inst_mode_defn.m: compiler/parse_tree_out_clause.m: compiler/parse_tree_out_info.m: compiler/parse_tree_out_inst.m: compiler/parse_tree_out_pragma.m: compiler/parse_tree_out_pred_decl.m: compiler/parse_tree_out_term.m: compiler/parse_type_defn.m: compiler/parse_type_name.m: compiler/parse_util.m: compiler/parse_vars.m: compiler/prog_ctgc.m: compiler/recompilation.usage.m: compiler/resolve_unify_functor.m: compiler/term_constr_main.m: compiler/term_constr_main_types.m: compiler/write_deps_file.m: library/bt_array.m: Delete unused imports. compiler/module_qual.qual_errors.m: Import a module that the parent module_qual.m doesn't import anymore. tests/warnings/bug412.{m,exp}: The test case for this bug. tests/warnings/Mmakefile: tests/warnings/Mercury.options: Enable the new test case. tests/invalid/import_in_parent.err_exp: Update the expected output for this test case. The parent module does not use the imported module (bool) at all, so this is what the error message says after this diff, though its submodule does use bool. |
||
|
|
cfcfde1db7 |
Simplify the representation of modes of unifications.
Unifications (x = y) have long had two descriptions of their modes.
One is the unify_mode, which used to look like this:
(initx -> finalx) - (inity -> finaly)
and other is the uni_mode, which used to look like this:
(initx - inity) -> (finalx - finaly)
Each unification had one unify_mode, and each unification that includes
a function symbol had one uni_mode per argument of that function symbol.
The two forms of mode information looked similar enough to be easily
confusable, but were subtly different. As it turns out, there was no
particular reason for the difference, so this diff eliminates the
uni_mode type, and the difference along with it.
What rationale there was for the uni_mode type was that the two modes
it represented (one for each side of the unification) both had their
initial and final insts directly available. This is not true for modes
in general: a value of the mer_mode type could have the form
"InitInst -> FinalInst" (which this diff renames "from_to_mode(InitInst,
FinalInst)", but could also be a "user_defined_inst(...)", which required
a table lookup to turn it into an initial/final pair of insts. This matters,
because almost all code that processes the modes of unifications
works with the initial and final insts.
This diff therefore creates a new type, from_to_insts, which represents
mode information only in the form of terms such as "from_to_insts(InitInst,
FinalInst)", and makes a unify_mode take two values of this type, not mer_mode,
as arguments.
As discussed on m-rev, this diff also renames the old, deceptively named
"arg_mode" type: its new name is "top_functor_mode".
compiler/prog_data.m:
compiler/hlds_goal.m:
As mentioned above, avoid using "->" as a function symbol, and replace
both -> and - with bespoke function symbols.
compiler/mode_util.m:
Add some utility predicates and functions on the new types, and
delete the old utility routines that operated on uni_modes.
Code that uses the new functions and predicates should have a higher level
of abstraction than the code that used to do the same job "manually".
compiler/*.m:
Conform to the changes above, using the new utility predicates and
functions where relevant. In several cases, this required fixing
confusion of the kind described at the top. In all but one case,
the confusion affected only variable names, but in one case,
deconstruct_functor in make_goal.m, it caused a bug. The bug has
had no effect up till now because deconstruct_functor is called
only from three places: try_expand.m, stm_expand.m, and untupling.m.
The incorrect mode (which was the nonsensical ground -> free)
generated by the code of try_expand.m itself was discarded and
overwritten when try_expand.m invoked the modechecker. (I don't
know whether this bugfix makes that invocation redundant or not.)
The other two modules, stm_expand.m and untupling.m, may do something
similar, but in any case, they don't yet work for other reasons.
(A bootcheck with --untupling causes a compiler abort when compiling
deep_profiler/query.m in stage 2 both without and with this fix.)
Delete no-longer-needed imports of the pair module (and of some other
modules).
Put the arguments of some predicates into a more logical order.
In bytecode_gen.m, replace clauses with disjunctions, and delete the
arguments that this step has revealed to be unused.
|
||
|
|
8f1137710e | Delete an unneeded predicate argument. | ||
|
|
c6ab550db8 |
Remove the code for automatic initialization of solver vars.
We haven't supported it in years, and keeping it in the compiler
is just a maintenance burden and a performance problem.
mdbcomp/prim_data.m:
Delete the spec_pred_init functor, since we don't support special
"init" predicates anymore.
compiler/prog_data.m:
Delete the slot in solver type details that record the name of the
auto-initialization predicate.
compiler/prog_io_type_defn.m:
Don't allow a type definition to specify an auto-initialization predicate.
compiler/options.m:
compiler/globals.m:
Delete the option that allowed support for auto-initialization to be
turned back on.
compiler/inst_match.m:
compiler/inst_util.m:
Delete comments about auto-initialization.
compiler/mode_info.m:
Delete the record of whether we have variables that can be
auto-initialized (we never do anymore) and the flag that controls whether
auto-initialization is permitted or not.
compiler/modecheck_conj.m:
Simplify the code that modechecks conjunctions, since it no longer
has to figure out where to insert auto-initializations of solver vars.
compiler/modecheck_goal.m:
Delete the code that ensured that if one branch of a branched
control structure auto-initialized a solver variable, then they
all did.
compiler/modecheck_unify.m:
Don't auto-initializate variables before unifications.
compiler/modecheck_util.m:
Delete the code that auto-initialized solver variables at the ends
of procedure bodies if this needed to be done and wasn't done before.
compiler/add_special_pred.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/get_dependencies.m:
compiler/hlds_module.m:
compiler/hlds_pred.m:
compiler/modecheck_call.m:
compiler/modes.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
compiler/post_term_analysis.m:
compiler/smm_common.m:
compiler/special_pred.m:
compiler/term_constr_errors.m:
compiler/term_constr_initial.m:
compiler/term_util.m:
compiler/termination.m:
compiler/trace_params.m:
compiler/type_util.m:
compiler/unify_proc.m:
Delete code that handled stuff related to auto-initialization,
and now always take the path that would normally be taken in the
absence of auto-initialization.
deep_profiler/read_profile.m:
runtime/mercury_layout_util.c:
runtime/mercury_stack_trace.c:
util/mdemangle.c:
Remove code that recognized the compiler-generated name of initialization
predicates.
tests/debugger/solver_test.m:
tests/hard_coded/solver_construction_init_test.m:
tests/hard_coded/solver_disj_inits.m:
tests/hard_coded/solver_ite_inits.m:
tests/invalid/missing_init_pred.m:
tests/invalid/zinc2mer_lib.m:
tests/valid/fz_conf.m:
tests/valid/solver_type_bug_2.m:
tests/valid/solver_type_mutable_bug.m:
These tests tested the handling of auto-initialization, which we
no longer support. Keep them around (and a bit more visible than
inside the git repo) in case we need them again, but add a comment
to each saying that the test is disabled.
tests/debugger/Mercury.options:
tests/debugger/Mmakefile:
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/Mmakefile:
Disable those tests.
tests/warnings/non_term_user_special.{m,exp}:
Part of this test tested the handling of auto-initialization;
delete that part.
tests/warnings/Mercury.options:
Delete the flag required by the deleted part, since we don't support it
anymore.
|
||
|
|
181bdfeee8 |
Alternative fix for bug 264.
compiler/inst_match.m:
Ensure that if an inst matches ground(_, none_or_default_func), all
functions occurring in it match the default function mode. This
means that terms can contain nondefault functions, but such terms
cannot be passed somewhere where that information may be lost.
This fixes some correctness issues in the code, which is worth doing
even with the already existing fix.
|
||
|
|
0be00e30f8 |
Refactor parts of compiler/inst_{util,match}.m
compiler/inst_util.m:
Move the predicates for testing whether an inst contains or matches
a nondefault function mode from here to compiler/inst_match.m, as
they primarily make use of, and are used by, code from that module.
compiler/inst_match.m:
Rename {pred_inst,ho_inst_info}_is_nondefault_func_mode to
{pred_inst,ho_inst_info}_matches_ground, and negate the meaning.
Most uses of the old version were themselves negated.
Provide a version that takes an inst_match_info and passes it through
to pred_inst_matches_2. This makes it suitable for use in inst_matches_*,
where it might otherwise cause an infinite loop due to not recording
the expansions it has seen so far.
It will be needed in inst_matches_* to properly disallow nondefault
functions from matching ground, but that is left for a separate change.
|
||
|
|
db464ca661 | Consistently refer to "default" function modes instead of "standard". | ||
|
|
b2ae55c29c |
Change 'none' to 'none_or_default_func' in ho_inst_info.
This value of ho_inst_info is used for first-order values as well as for functions that have the default inst, and the new name better reflects that. Places using this value have been checked for correctness. Issues that need to be looked at have been marked with XXX, although have not been addressed in this change. compiler/prog_data.m: Update the type. compiler/inst_match.m: Add XXX comments. This module needs to check for non-default function insts in a bunch of places. compiler/inst_util.m: Add XXX comments. We lose information about non-default function insts when merging bound and any. The information needs to be either preserved or disallowed entirely. compiler/float_regs.m: Add XXX comments. This module may miss cases involving default function insts. compiler/modecheck_unify.m: Add XXX comment. We should exclude pred and non-default func lambda non-locals from becoming locked, an addition to default functions. compiler/*.m: No special handling is required for other modules. |
||
|
|
5f8bd5f09d | Delete unused imports. | ||
|
|
7f5a08eb37 |
Split parts of inst_match.m into a new module, inst_test.m
Most modules that imported inst_match did so in order to use
predicates such as inst_is_ground to test properties of insts.
These predicates are split into a new module, leaving the more
complex parts of inst_match to be imported in fewer places.
This makes it easier to change inst_match (for example, to
address mantis bug 264) without unintentional changes to
the rest of the compiler.
compiler/inst_test.m:
New module containing code from inst_match.m.
compiler/check_hlds.m:
Include the new module.
compiler/inst_match.m:
Move code to the new module.
compiler/inst_util.m:
Move inst_expand and inst_expand_and_remove_constrained_inst_vars
here rather than the new module, since they make more sense here.
compiler/build_mode_constraints.m:
compiler/cse_detection.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/det_report.m:
compiler/fact_table.m:
compiler/float_regs.m:
compiler/goal_util.m:
compiler/interval.m:
compiler/loop_inv.m:
compiler/modecheck_goal.m:
compiler/pd_util.m:
compiler/prog_rep.m:
compiler/simplify_goal_call.m:
compiler/size_prof.m:
compiler/stm_expand.m:
compiler/structure_sharing.domain.m:
compiler/switch_detection.m:
compiler/term_util.m:
compiler/trace_gen.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
Only import inst_test.
compiler/common.m:
compiler/instmap.m:
compiler/mode_util.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/simplify_goal_disj.m:
Import inst_test in addition to inst_match.
compiler/lco.m:
compiler/simplify_goal_switch.m:
Import inst_test and inst_util, but not inst_match.
|
||
|
|
c5b64d36ea | Convert (C->T;E) to (if C then T else E). | ||
|
|
62ec97d443 |
Report imports shadowed by other imports.
If a module has two or more import_module or use_module declarations
for the same module, (typically, but not always, one being in its interface
and one in its implementation), generate an informational message about
each redundant declaration if --warn-unused-imports is enabled.
compiler/hlds_module.m:
We used to record the set of imported/used modules, and the set of
modules imported/used in the interface of the current module. However,
these sets
- did not record the distinction between imports and uses;
- did not allow distinction between single and multiple imports/uses;
- did not record the locations of the imports/uses.
The first distinction was needed only by module_qual.m, which *did*
pay attention to it; the other two were not needed at all.
To generate messages for imports/uses shadowing other imports/uses,
we need all three, so change the data structure storing such information
for *direct* imports to one that records all three of the above kinds
of information. (For imports made by read-in interface and optimization
files, the old set of modules approach is fine, and this diff leaves
the set of thus *indirectly* imported module names alone.)
compiler/unused_imports.m:
Use the extra information now available to generate a
severity_informational message about any import or use that is made
redundant by an earlier, more general import or use.
Fix two bugs in the code that generated warnings for just plain unused
modules.
(1) It did not consider that a use of the builtin type char justified
an import of char.m, but without that import, the type is not visible.
(2) It scanned cons_ids in goals in procedure bodies, but did not scan
cons_ids that have been put into the const_struct_db. (I did not update
the code here when I added the const_struct_db.)
Also, add a (hopefully temporary) workaround for a bug in
make_hlds_passes.m, which is noted below.
However, there are at least three problems that prevent us from enabling
--warn-unused-imports by default.
(1) In some places, the import of a module is used only by clauses for
a predicate that also has foreign procs. When compiled in a grade that
selects one of those foreign_procs as the implementation of the predicate,
the clauses are discarded *without* being added to the HLDS at all.
This leads unused_imports.m to generate an uncalled-for warning in such
cases. To fix this, we would need to preserve the Mercury clauses for
*all* predicates, even those with foreign procs, and do all the semantic
checks on them before throwing them away. (I tried to do this once, and
failed, but the task should be easier after the item list change.)
(2) We have two pieces of code to generate import warnings. The one in
unused_imports.m operates on the HLDS after type and mode checking,
while module_qual.m operates on the parse tree before the creation of
the HLDS. The former is more powerful, since it knows e.g. what types and
modes are used in the bodies of predicates, and hence can generate warnings
about an import being unused *anywhere* in a module, as opposed to just
unused in its interface.
If --warn-unused-imports is enabled, we will get two separate set of
reports about an interface import being unused in the interface,
*unless* we get a type or mode error, in which case unused_imports.m
won't be invoked. But in case we do get such errors, we don't want to
throw away the warnings from module_qual.m. We could store them and
throw them away only after we know we won't need them, or just get
the two modules to generate identical error_specs for each warning,
so that the sort_and_remove_dups of the error specs will do the
throwing away for us for free, if we get that far.
(3) The valid/bug100.m test case was added as a regression test for a bug
that was fixed in module_qual.m. However the bug is still present in
unused_imports.m.
compiler/make_hlds_passes.m:
Give hlds_module.m the extra information it now needs for each item_avail.
Add an XXX for a bug that cannot be fixed right now: the setting of
the status of abstract instances to abstract_imported. (The "abstract"
part is correct; the "imported" part may not be.)
compiler/intermod.m:
compiler/try_expand.m:
compiler/xml_documentation.m:
Conform to the change in hlds_module.m.
compiler/module_qual.m:
Update the documentation of the relationship of this module
with unused_imports.m.
compiler/hlds_data.m:
Document a problem with the status of instance definitions.
compiler/hlds_out_module.m:
Update the code that prints out the module_info to conform to the change
to hlds_module.m.
Print status information about instances, which was needed to diagnose
one of the bugs in unused_imports.m. Format the output for instances
nicer.
compiler/prog_item.m:
Add a convenience predicate.
compiler/prog_data.m:
Remove a type synonym that makes things harder to understand, not easier.
compiler/modules.m:
Delete an XXX that asks for the feature this diff implements.
Add another XXX about how that feature could be improved.
compiler/Mercury.options.m:
Add some more modules to the list of modules on which the compiler
should be invoked with --no-warn-unused-imports.
compiler/*.m:
library/*.m:
mdbcomp/*.m:
browser/*.m:
deep_profiler/*.m:
mfilterjavac/*.m:
Delete unneeded imports. Many of these shadow other imports, and some
are just plain unneeded, as shown by --warn-unused-imports. In a few
modules, there were a *lot* of unneeded imports, but most had just
one or two.
In a few cases, removing an import from a module, because it *itself*
does not need it, required adding that same import to those of its
submodules which *do* need it.
In a few cases, conform to other changes above.
tests/invalid/Mercury.options:
Test the generation of messages about import shadowing on the existing
import_in_parent.m test case (although it was also tested very thoroughly
when giving me the information needed for the deletion of all the
unneeded imports above).
tests/*/*.{m,*exp}:
Delete unneeded imports, and update any expected error messages
to expect the now-smaller line numbers.
|
||
|
|
89628ae791 |
More speedups of inst handling code.
On tools/speedtest -l -m, my tests show a speedup of about 2%, but
on Dirk's stress test module, for which the compiler (used to) spend
almost all its time handling insts, the speedup is about 40%.
This diff also contains some small incidental changes I stumbled upon
the "need" for while working on the main change.
compiler/prog_data.m:
The existing inst_test_results type used to be able to hold the results
of four tests about a bound inst. Add two more: the set of inst vars that
may occur in the inst, and whether a type constructor has already been
propagated into the cons_ids of the bound insts.
Put the fields of the the unify_inst and merge_inst inst_names into
a more sensible order.
Define types that hold the information stored in specific kinds of
inst_names, for use by hlds_data.m (see below).
compiler/inst_user.m:
For each user defined bound inst that matches exactly one parameterless
type, propagate its type constructor into it, and record the fact that
it has been done. This avoids having to do it many times later.
Also record the set of inst vars in each inst, again to avoid having
to repeat the test many times later.
compiler/mercury_compile_front_end.m:
Invoke the inst_user module as soon after inst_check.m as we can.
compiler/hlds_data.m:
Make the structure of six subtables of the inst table private, to allow
them to be experimented with (and possibly changed) without code changes
being required in other modules.
The unify_inst_table, the ground_inst_table and the any_inst_table
used to be maps whose keys were inst_names, but they were each only ever
used with one kind of inst_name. Change their keys to the new types
unify_inst_info, ground_inst_info and any_inst_info, which each contain
the information in the unify_inst, ground_inst and any_inst inst_names
respectively. That way, the searches in the maps will perform comparisons
that don't need to switch on what kind of inst_name they are dealing with,
and instead go directly to comparing the arguments.
With the unify_inst_table, also go a step further. The unify_inst_info
has two fields that are equivalent to booleans. Comparing these
at every level of the map is wasteful, so switch the representation
of the unify_inst_table from one map to four maps, one map for each
possible combination of those booleans. This way, the two booleans
in the unify_inst_info key are tested just once, when the applicable map
is selected.
The merge_inst_table used to have a pair of insts as keys. Replace that
with the merge_inst_info type, which also holds a pair of insts,
but on which comparisons should be a bit faster, since it is not
polymorphic, and thus does not need an implicit typeinfo passed along.
Provide a combined search_insert operation on each of the inst_tables,
since their pattern of use is exactly that: search the table, and if
the key is not found, insert a marker that says the entry is being
worked on. This avoid one traversal of a possibly-large tree, with
its associated (possibly very expensive) comparisons.
For each inst table, provide conversion predicates to and from
sorted association lists, for use by equiv_type_hlds.m
compiler/equiv_type_hlds.m:
Expand equivalence types in the new structure of the inst tables.
compiler/inst_util.m:
Use the new search_insert predicates for the various inst_tables.
If one of the two insts being unified is free, then avoid using
the unify_inst_table, since just doing the abstract unification
is faster, and does not pollute the unify_inst_table.
If both insts being merged are bound insts, then avoid using the
merge_inst_table, since (a) the lookup is slower than just doing
the merge, and (b) it can pollute the merge_inst_table to the extent
that *all other lookups* in it become very slow.
compiler/inst_match.m:
Use test result information in bound insts to speed up the corresponding
tests.
compiler/set_of_var.m:
Change the representation of sets of vars back to sparse_bitsets.
I changed them to tree_bitsets several years ago to avoid some bad
worst-case behavior with sparse_bitsets (which occurred when repeatedly
appending to the "ends" of sets), but other algorithmic changes have
since avoiding using set_of_vars in ways that induce that behavior,
and now my benchmarking tells me that the bottleneck operation is
conversion of set_of_vars to lists of vars. This is faster with
sparse_bitsets, since unlike tree_bitsets, they don't have to unravel
a tree structure.
compiler/mode_util.m:
Export a predicate now needed by inst_user.m, and clean up the code a bit,
factoring out repeated code.
compiler/modecheck_util.m:
Modify an equality comparison of two insts to compare the instantiation
states themselves, but NOT the test results about those instantiation
states, since these can differ if the two insts have different histories.
compiler/hlds_code_util.m:
compiler/hlds_out_mode.m:
compiler/hlds_out_module.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/polymorphism.m:
compiler/prog_mode.m:
compiler/recompilation.usage.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
Conform to the changes above.
The following changes are mostly incidental.
compiler/hlds_args.m:
Speed up a predicate by avoiding the materialization of a list
that is needed only for a test.
compiler/instmap.m:
Clarify some code.
compiler/liveness.m:
Avoid computing some value when it is not needed.
compiler/mode_errors.m:
Avoid referring to "arguments" (plural) for errors involving *one*
argument.
compiler/mode_info.m:
Move the documentation of some predicates to their declarations.
compiler/modecheck_unify.m:
Compute some data closer to where it is needed, to reduce the number
of stack slots needed.
tests/invalid/constrained_poly_insts2.err_exp:
Expect the updated error message from mode_errors.m (with "argument"
in singular), as well as module qualified insts, since having inst_user.m
push type_ctors into the definitions of named inst module qualifies
the bound_insts inside those definitions.
|
||
|
|
71edaf52e6 |
Fix problems with higher-order inst matching with polymorphic modes.
These changes allow the compiler to accept the contravariance_poly.m test case that requires higher order pred insts to be contravariant in the initial argument insts. Previously the compiler would have rejected it, if not for the hack that allows ground to match incomplete bound insts. compiler/inst_match.m: pred_inst_argmodes_matches enabled the cs_reverse mode when matching initial insts, which causes handle_inst_var_subs to swap the insts for the inst var substitution calculation. The insts are swapped back for inst matching, but cs_reverse remained effective. A recursive call to match two insts would swap the insts *again*, to the wrong order. The fix is to invert cs_reverse to cs_forward when the insts are swapped back for matching. In pred_inst_argmodes_matches apply the incrementally calculated inst var substitution before matching. compiler/modecheck_util.m: Make handle_implied_mode use inst_matches_initial_no_implied_modes_sub. The non-sub variant does not compute inst var substitutions and fails where the higher-order argument inst has an inst variable (as in contravariance_poly.m), then handle_implied_mode incorrectly deduces that the call is to an implied mode. |
||
|
|
491bb0ab5f |
Do not allow ground insts to match incomplete bound insts.
The mode checker contains a hack where ground matches bound insts even if the bound inst is incomplete for the type. The stated reason is that otherwise the mode checker is too conservative in the absence of alias tracking. However, it runs counter to the typical behaviour expected of the compiler. Disable the hack, thus rejecting more mode-incorrect code but also some mode-correct code. Some compiler-generated unify predicates would now be rejected. We retain the hack only for those predicates. NOTE: this change exposes some bugs which will be fixed in subsequent changes. A few test cases will fail for now: contravariance_poly.m and some declarative debugging test cases. compiler/hlds_pred.m: Add helper predicate `is_unify_pred'. compiler/inst_match.m: Add a variant of `inst_matches_final_typed' to select if ground matches incomplete bound insts. Do not allow ground to match incomplete bound insts in `inst_matches_final_3' unless explicitly enabled. Do not allow ground to match incomplete bound insts in `inst_matches_binding_3'. compiler/modes.m: Use lax `ground_matches_bound_always' behaviour for checking the final insts of compiler-generated unify predicates only. NEWS: Announce change. |
||
|
|
33be5c8f72 |
Restore a fix to handle_inst_var_subs_2.
A previous change improved the precision of inst matching by making handle_inst_var_subs_2 recurse on the abstract unification of InstA and SubInstB, Recurse(InstA, abstractly_unify_inst(InstA, SubInstB)) The change was temporarily reverted because it is susceptible to infinite recursion when abstractly_unify_inst returns an inst containing larger and larger "unify_insts" in each successive call. compiler/inst_match.m: Restore the fix but avoid infinite recursion. tests/EXPECT_FAIL_TESTS.all_grades: Enable invalid/constrained_poly_insts2 again. |
||
|
|
8e92031e02 |
Revert a fix for constrained polymorphic modes.
Commit
|
||
|
|
338b5cb98e |
Fix some bugs with constrained polymorphic modes.
1. An inst variable from the head of the clause could be bound in the body. The mode error in the call `P(X)' was not detected because the inst variable I could be bound to ground. :- pred p(pred(T), T). :- mode p(pred(in(I =< ground)) is det, in) is det. p(P, X) :- P(X). 2. In David Overton's thesis, a get_subst function produces an inst substitution from the callee's initial insts to the arguments' initial insts, and the substitution is applied to all insts from the callee. In the implementation we actually build the substitution while matching the arguments' insts with the callee's insts, but we lost some precision by not applying the incremental substitutions built as we match a list of insts. 3. We rename apart the callee's inst variables from our own, but did not keep the merged inst varset. When a renamed inst variable appears in a mode error it would be printed without its original name. (could this avert more serious problems?) 4. inst_merge_3 was missing a case. Some of these bugs may not be apparent due to the hack in inst_matches_final_3 which allows a ground inst to match any bound inst. A similar hack exists in inst_matches_binding_3. compiler/inst_util.m: Handle in inst_merge_3 the case InstA \= constrained_inst_var(_, _), InstB = constrained_inst_var(_, _). Move InstA = not_reached case to inst_merge_2 to maintain inst_merge(not_reached, InstB @ constrained_inst_var(_, _)) = InstB compiler/inst_match.m: Improve precision of inst var substitution computed in handle_inst_var_subs_2, following dmo's thesis. compiler/mode_util.m: compiler/modecheck_call.m: Keep the merged inst varsets after renaming. compiler/mode_info.m: Add "head inst vars" in mode_info structure. compiler/modecheck_util.m: Add get_constrained_inst_vars to extract constrained inst vars from a list of mode. Make modecheck_var_has_inst_list_* fail if the computed substitution would change the constraints of any head inst variables. compiler/modes.m: Initialise mode_info with head inst variables. compiler/pd_info.m: compiler/pd_util.m: Conform to change in mode_info_init (not specifically tested). compiler/prog_mode.m: Export inst_apply_substitution. Make rename_apart_inst_vars return the merged inst varset. Fix comments. tests/invalid/Mmakefile: tests/invalid/constrained_poly_insts2.err_exp: tests/invalid/constrained_poly_insts2.m: tests/valid/Mmakefile: tests/valid/constrained_poly_multi.m: Add test cases. NEWS: Announce fix. |
||
|
|
500948d549 |
Break up mdbcomp/prim_data.m. The new modules have much better cohesion.
mdbcomp/sym_name.m:
New module, containing the part of the old prim_data.m that
dealt with sym_names.
mdbcomp/builtin_modules.m:
New module, containing the part of the old prim_data.m that
dealt with builtin modules.
mdbcomp/prim_data.m:
Remove the things that are now in the two new modules.
mdbcomp/mdbcomp.m:
deep_proiler/Mmakefile:
slice/Mmakefile:
Add the two new modules.
browser/*.m:
compiler/*.m:
deep_proiler/*.m:
mdbcomp/*.m:
slice/*.m:
Conform to the above changes.
|
||
|
|
4b44c29c2e |
Fix mantis bug 311.
compiler/simplify_goal_disj.m:
Look for the conditions that lead to the bug (a disjunction that
further instantiates an already partially instantiated variable).
Generate an error message when found, PROVIDED that this happens
in a context in which the surrounding procedure can succeed
more than once. (If it cannot, then you cannot invoke an all-solutions
predicate on it, and the bug cannot happen.)
This condition (a model_non surrounding procedure) was motivated
by mdbcomp/feedback.m, which does not compile without it.
compiler/simplify_info.m:
The simplify_info type used to contain four different kinds of fields:
1 static fields; set and then never changed, such as the id of the
containing procedure
2 global information, such as the varset and vartypes, which are updated
as new variable are added, and whose updates need to be kept regardless
of what part of the procedure is analyzed next
3 information about the context surrounding the goal currently being
analyzed, such as the number of lambda expressions we are inside
4 information about the point in the code before the goal currently being
analyzed, such as the set of equivalences that currently hold between
variables (part of common_info).
The code of the simplify_goal*.m modules used to have jump through hoops
to handle 3 and 4 properly, given that the simplify_info was being
threaded through code in a way that was suitable only for 1 and 2.
This change takes categories 3 and 4 out of the simplify_info.
It creates a new type, simplify_nested_context, for category 3,
and adds information about the ability of the procedure surrounding
the current point to succeed more than once (needed for the bug311 fix)
to this new type.
compiler/simplify_tasks.m:
Rename the do_once task to mark_code_model_changes, since this
expresses what the task is much less ambiguously.
compiler/simplify_goal*.m:
compiler/simplify_proc.m:
compiler/common.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
Conform to the changes to simplify_info (and simplify_tasks).
Pass the current instmap and common_info (the two category 4 fields)
separately.
Mark some places that could be improved.
compiler/hlds_out_mode.m:
Generate easier-to-understand debugging output. I needed this to track
down a bug in my initial fix.
compiler/inst_match.m:
Remove a redundant unification that couldn't fail (since it was invoked
only if the exact same unification succeeded a few lines earlier).
Apply another minor optimizations.
compiler/instmap.m:
Remove references to the alias branch. It won't be coming back.
compiler/error_util.m:
Fix some documentation.
mdbcomp/feedback.m:
Put related stuff together.
tests/warnings/bug311.{m,err_exp}:
New test case for the bug.
tests/warnings/Mmakefile:
Enable the new test case.
|
||
|
|
16bd4acd2f |
Shorten lines longer than 79 characters.
Estimated hours taken: 2 Branches: main compiler/*.m: Shorten lines longer than 79 characters. |
||
|
|
14713ee3ce |
Fix compilation of the compiler in non C grades.
Branches: main Fix compilation of the compiler in non C grades. compiler/equiv_type_hlds.m: compiler/hlds_out_mode.m: compiler/inst_match.m: compiler/make.util.m: Provide Mercury clauses for various foreign_procs that have been added recently. |
||
|
|
c650eaddd2 |
A bunch of individually small changes to speed up the compiler when compiling
Estimated hours taken: 8
Branches: main
A bunch of individually small changes to speed up the compiler when compiling
training_cars_full.m. Altogether, the changes speed up the compiler on that
task by a bit more than 11% when the target grade is asm_fast.gc, and by a bit
more than 7% when the target grade is hlc.gc. (Several of the changes affect
the code that optimizes the LLDS; we don't have corresponding optimizers
for the MLDS.)
compiler/c_util.m:
Specialize the code that prints out quoted strings for the target
language. We don't want to check the target language during
the conversion of EVERY SINGLE CHARACTER.
compiler/dead_proc_elim.m:
When we analyze the module for inlining, we are only after the
use counts of procedures. We do not need to traverse ground structures
to get those counts.
compiler/dupelim.m:
Do the search and insertion in the standardized code sequence map
in one pass.
compiler/global_data.m:
compiler/ml_global_data.m:
Do the search and insertion in the scalar data map in one pass.
library/bimap.m:
Add a search_insert predicate to make possible the changes in
{ml_,}global_data.m.
NEWS:
Mention the new predicate in bimap.m.
compiler/inst_match.m:
Do searches and insertions in sets of expansions in one pass.
Highlight discrepancies between comments on the declarations
of two predicates and comments on their code.
compiler/llds_out_global.m:
compiler/post_typecheck.m:
Reorder the bodies of some test conditions to put the cheaper and
more-frequently-failing tests first.
compiler/labelopt.m:
compiler/opt_util.m:
Do not require opt_util to return a list of code addresses that
labelopt then throws away; allow opt_util.m not to gather those
addresses in the first place (if the unused_args optimization
is applied to it, which it is by default.)
In opt_util.m, make an unnecessarily-exported predicate private.
compiler/prog_data.m:
Use predicates in varset.m that do directly what we want, instead
of using a different predicate and then post-processing its output.
(The code was originally written before the directly useful predicate
in varset.m was available.)
compiler/type_util.m:
Specialize the frequently occurring case of no typeclass constraints
at all.
compiler/typecheck_info.m:
Give the field names of some types identifying prefixes.
Make a function symbol's name more meaningful.
compiler/typecheck.m:
compiler/typecheck_errors.m:
Conform to the changes in typecheck_info.m.
|
||
|
|
932f7256ba |
A large part of the cost of a large ground term is incurred not when the
Estimated hours taken: 40 Branches: main A large part of the cost of a large ground term is incurred not when the term is constructed, but when it is used. The inst of the term will be huge, and will typically have to be traversed many times. Some of those traversals would be linear if not for the fact that, in order to avoid infinite loops on recursive insts, the predicate doing the traversal has to keep a set of the insts visited so far. When the traversal is in the middle of the ground term's inst, it is looking up that inst in a set of the insts of its containing terms all the way up to the root. When the ground term contains a list with many repeated elements near the start, the cost of the traversal is cubic in the length of the list: a linear number of set membership tests, each of which tests the current inst against a linear number of large insts, the test itself being linear. This diff aims to totally sidestep all that. It extends the mer_inst type to allow (but not require) the creator of an inst to record what the outcome of some tests on the inst would be. Is it ground? Does it contain "any"? What inst names and types may it contain? If the creator records this answer, which the code that creates ground terms does, then many tests will now run in CONSTANT time, not linear, quadratic or cubic. We do this only for bound insts. While the concept can apply to all insts, for small insts it can cost more to interpret the results term than to do the test directly. Insts cannot be large without being composed mostly of bound insts, so by recording this info only for bound insts, we can speed up the handling of all large insts. This also has the side benefit that in many cases, a traversal that operates on an inst will often do so in order to compute an updated version of that inst. In many cases, the updated version is the same as the original version, but since the traversal has to be prepared for updates, it makes a copy of the inst anyway. The result of the traversal is thus an inst that has the same value as the original inst but not the same address. This makes it useless to try to do equality checks of related insts in constant time by looking at the pointers. With this diff, many such traversals can be avoided, allowing the updated inst to keep the address as well as the value of the corresponding original inst. Without this diff, the compiler takes more than 10 seconds to compile zm_rcpsp_cpx.m, with most of that time being spent in mode checking. With this diff, it takes less than 5 seconds. Basically, mode checking went from 6+ seconds to 1. The profile of the compiler is now flat on this input; no single pass takes much more time than the others. The speed of the compiler is unaffected on tools/speedtest. (Actually, it gets a very slight speedup, but it is in the noise.) compiler/prog_data.m: Change the bound/2 functor of the mer_inst type to bound/3, adding a field that gives the outcome of some common tests performed on insts. When we attach insts to the variables representing parts of ground terms, we mark the insts accordingly. This allows us to perform many tests on insts in constant time, not in a time that is linear, quadratic or worse in the size of the inst. compiler/add_pragma.m: compiler/const_prop.m: compiler/distance_granularity.m: compiler/equiv_type_hlds.m: compiler/float_regs.m: compiler/hlds_code_util.m: compiler/hlds_goal.m: compiler/inst_check.m: compiler/inst_match.m: compiler/inst_util.m: compiler/lco.m: compiler/mercury_to_mercury.m: compiler/mode_constraints.m: compiler/mode_debug.m: compiler/mode_util.m: compiler/modecheck_goal.m: compiler/modecheck_unify.m: compiler/modecheck_util.m: compiler/module_qual.m: compiler/pd_util.m: compiler/polymorphism.m: compiler/prog_io.m: compiler/prog_io_util.m: compiler/prog_mode.m: compiler/prog_util.m: compiler/recompilation.usage.m: compiler/recompilation.version.m: compiler/simplify.m: compiler/try_expand.m: compiler/unique_modes.m: compiler/unused_imports.m: compiler/xml_documentation.m: Conform to the above change. Obviously, this required the modification of most predicates dealing with insts. Where the original predicates used multiple clauses, inconsistent variable names and/or bad grouping or ordering of code, this diff fixes that. More to the point, while in many places, the new code ignores the new field in input insts as either not relevant or not useful, in several places, the new code - pays attention to this field in input insts and executes less or faster code if the result of some test it needs is already available in it, or - fills in the field in insts it generates as output. Most, but not all, of changes in the first of those two categories were in inst_util.m and inst_match.m. compiler/hlds_out_mode.m: When writing out insts, or converting them to term form as the first step in printing them out, print the new field if we are generating debug output (such as a HLDS dump), but do not do so if we are generating actual Mercury code (such as a .opt file). Reorder the arguments of many predicates to move the context argument BEFORE the argument representing the object to be printed or converted to a term, since this allows us to use list.map on lists of such objects. compiler/hlds_out_util.m: Define a type that allows us to distinguish between the two. compiler/hlds_out_goal.m: compiler/hlds_out_module.m: compiler/hlds_out_pred.m: Thread values of this flag type through a bunch of predicates as needed. compiler/intermod.m: Specify output_mercury when writing clauses for optimization files. This is needed because mode-specific clauses can have insts in their heads. (The mode declarations in .int* files are written out by a separate set of predicates, in mercury_to_mercury.m, which ALWAYS ignore the new field.) compiler/prog_util.m: There were two predicates named construct_qualified_term, with different arities: one took a context, the other didn't. Rename the former to avoid the ambiguity. compiler/goal_expr_to_goal.m: Conform to the change to prog_util.m. compiler/prog_io.m: There were two predicates named constrain_inst_vars_in_mode; rename one. Add an XXX about why they are here in the first place. compiler/format_call.m: Give some type and field names prefixes to avoid some ambiguities. |
||
|
|
55bc393ded |
Replace the misleading names of several predicates.
Estimated hours taken: 2 Branches: main compiler/type_util.m: Replace the misleading names of several predicates. The old names talked about testing a type, type definition or variable to see whether it is a solver type, when the test they actually implemented also succeeded if they were NOT a solver type, but contained a component that was a solver type. Add versions of some of these predicates that take only a type table, and not a whole module_info, as input. (The type table is the only part of the module_info that the old predicates actually use.) I have plans to use these predicates in a later diff. Give some other predicates better names as well. compiler/modecheck_conj.m: Rename a predicate along similar lines. compiler/cse_detection.m: compiler/exception_analysis.m: compiler/inst_match.m: compiler/inst_util.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/simplify.m: compiler/trailing_analysis.m: Conform to the above changes. |
||
|
|
a54ae6232d |
Instead of first testing whether an inst exists in a set
Estimated hours taken: 8 Branches: main compiler/inst_match.m: Instead of first testing whether an inst exists in a set and then inserting it if does not, use a single predicate that does both the membership test and the insertion (if the membership test failed) in one pass. This speeds up compilation of one version of the rcpsp_cpx stress test by about 9%, with negligible effect on tools/speedtest. Some cleanups that should have been committed before this diff follow. Change the structure of many of the predicates in this module from containing multiple clauses, to a single clause with an explicit disjunction, which (where relevant) now gets a require_comple_switch wrapper. In several cases, this change has shown that we were missing code for handling some kinds of insts. For example, some predicates handled free/0 but not free/1, even though there was no reason for the difference. This diff fixes such oversights in places where the right action seems obvious to me, and adds XXXs in places where I see no obvious fix. Rename several predicates and function symbols to avoid ambiguities. Add some XXXs on potential problems. library/*set*.m: Implement this insert_new predicate for all the implementations of sets we have. The code in each case is copied from the code of insert, with code to return a set unchanged replaced with `fail'. NEWS: Mention the new predicates. |
||
|
|
73c32fc475 |
Improve the performance of the compiler further on the zm_rcpsp_cpx.m
Estimated hours taken: 16 Branches: main Improve the performance of the compiler further on the zm_rcpsp_cpx.m stress test, reducing the compilation time of a variant of that test from 135 seconds to 92. (The biggest remaining bottleneck is the divide_by_set predicate called from liveness.m; eliminating that bottleneck should get about a factor of 3 further speedup. I am now working on that.) These changes make the compiler about 1.2% slower on tools/speedtest. However, the overall effect of my previous change and this one is still positive for tools/speedtest. In any case, the big speedup in the worst case trumps the slight slowdown in average cases. compiler/equiv_type_hlds.m: Avoid quadratic behavior in code that replaces types in insts in the uni-modes of unifications by building a cache of the results of the test that checks whether an inst may contain a type (most don't). In a sequence of unifications in which each unification has an argument that was built by a previous unification, this cache should mean that most of the time, the test does not need to recurse into the inst of the argument. Rename some predicates to avoid ambiguity. Change some predicates from several clauses (with inconsistent argument names in the debugger) to single clauses with explicit switches. compiler/inst_match.m: Avoid quadratic behavior in the code that tests whether an inst is ground, which is called a lot by common subexpression elimination. Both the cause and the fix (a cache of recent test results) are similar to equiv_type_hlds.m. compiler/common.m: Delete some unused predicate arguments to make calls slightly faster. Remove a double negation. compiler/simplify.m: Conform to the changes to common.m. compiler/hlds_out_mode.m: Add code to print out uni-modes in a structured fashion, optionally printing the address in memory at which each inst is stored. This was needed to find the information that lead to the fix to inst_match.m. Move some predicates that are used ONLY for dumping HLDS components for debugging, NOT for generating any interface files, here from mercury_to_mercury.m. They should have been here in the first place. Change the names of some of those predicates to avoid ambiguities. compiler/mercury_to_mercury.m: Remove the predicates moved to hlds_out_mode.m. Change the names of some predicates to avoid ambiguities. Export some predicates now needed by hlds_out_mode.m. Change some predicates from several clauses (with inconsistent argument names in the debugger) to single clauses with explicit switches. compiler/hlds_out_goal.m: When given the dump option 'y', invoke the new predicates in hlds_out_mode.m to print structured uni-modes. compiler/hlds_out_module.m: Fix the code to print inst tables; the old code generated hard-to-read output due to missing newlines and odd punctuation. Give some predicates more meaningful names. compiler/hlds_out_pred.m: If the dump options call only for the printing of the inst and mode tables, do not dump any predicates. Give some predicates more meaningful names. compiler/handle_options.m: Add implications about dump options: if the user asks for information about a detail, he/she is also asking for the things that contain that detail, since otherwise the question of whether to print detail would never ever come up. This is needed to implement the change to hlds_out_pred.m without repeating many tests at the dumping of each predicate (the creation of HLDS dumps is slow enough already). doc/user_guide.texi: Document the new dump options. compiler/intermod.m: Change the names of some predicates to avoid ambiguities. compiler/prog_data.m: Fix formatting. compiler/mode_debug.m: compiler/recompilation.usage.m: compiler/recompilation.version.m: Conform to the changes above. |
||
|
|
b86f973fa9 |
Allow the use of Mercury abstract machine float registers for passing
Branches: main Allow the use of Mercury abstract machine float registers for passing double-precision float arguments in higher order calls. In of itself this is not so useful for typical Mercury code. However, as all non-local procedures are potentially the targets of higher order calls, without this change first order calls to non-local procedures could not use float registers either. That is the actual motivation for this change. The basic mechanism is straightforward. As before, do_call_closure_* is invoked to place the closure's hidden arguments into r1, ..., rN, and extra input arguments shifted into rN+1, etc. With float registers, extra input arguments may also be in f1, f2, etc. and the closure may also have hidden float arguments. Optimising for calls, we order the closure's hidden arguments so that all float register arguments come after all regular register arguments in the vector. Having the arguments out of order does complicate code which needs to deconstruct closures, but that is not so important. Polymorphism complicates things. A closure with type pred(float) may be passed to a procedure expecting pred(T). Due to the `float' argument type, the closure expects its argument in a float register. But when passed to the procedure, the polymorphic argument type means it would be called with the argument in a regular register. Higher-order insts already contain information about the calling convention, without which a higher-order term cannot be called. We extend higher-order insts to include information about the register class required for each argument. For example, we can distinguish between: pred(in) is semidet /* arg regs: [reg_f] */ and pred(in) is semidet /* arg regs: [reg_r] */ Using this information, we can create a wrapper around a higher-order variable if it appears in a context requiring a different calling convention. We do this in a new HLDS pass, called float_regs.m. Note: Mercury code has a tendency to lose insts for higher-order terms, then "recover" them by hacky means. The float_regs pass depends on higher-order insts; it is impossible to create a wrapper for a procedure without knowing how to call it. The float_regs pass will report errors which we otherwise accepted, due to higher-order insts being unavailable. It should be possible for the user to adjust the code to satisfy the pass, though the user may not understand why it should be necessary. In most cases, it probably really *is* unnecessary. We may be able to make the float_regs pass more tolerant of missing higher-order insts in the future. Class method calls do not use float registers because I didn't want to deal with them yet. compiler/options.m: compiler/handle_options.m: Always enable float registers in low-level C grades when floats are wider than a word. compiler/make_hlds_passes.m: Always allow double word floats to be stored unboxed in cells on C grades. compiler/hlds_goal.m: Add an extra field to `generic_call' which gives the register class to use for each argument. This is set by the float_regs pass. compiler/prog_data.m: Add an extra field to `pred_inst_info' which records the register class to use for each argument. This is set by the float_regs pass. compiler/hlds_pred.m: Add a field to `proc_sub_info' which lists the headvars which must be passed via regular registers despite their types. Add a field to `pred_sub_info' to record the original unsubstituted argument types for instance method predicates. compiler/check_typeclass.m: In the pred_info of an instance method predicate, record the original argument types before substituting the type variables for the instance. compiler/float_regs.m: compiler/transform_hlds.m: Add the new HLDS pass. compiler/mercury_compile_middle_passes.m: Run the new pass if float registers are enabled. compiler/lambda.m: Export the predicate to produce a predicate from a lambda. This is reused by float_regs.m to create wrapper closures. Add an argument to `expand_lambda' to set the reg_r_headvars field on the newly created procedure. Delete some unused fields from `lambda_info'. compiler/arg_info.m: Make `generate_proc_arg_info' no longer always use regular registers for calls to exported procedures. Do always use regular registers for class methods calls. Add a version of `make_arg_infos' which takes an explicit list of argument registers. Rename the previous version. Add `generic_call_arg_reg_types' to return the argument registers for a generic call. Add a version of `compute_in_and_out_vars' which additionally separates arguments for float and regular registers. compiler/call_gen.m: Use float registers for argument passing in higher-order calls, as directed by the new field in `generic_call'. compiler/code_util.m: Add a function to encode the number of regular and float register arguments when making a higher-order call. compiler/llds.m: Say that the `do_call_closure_N' functions only work for zero float register arguments. compiler/follow_vars.m: compiler/interval.m: Account for the use of float registers by generic call goals in these passes. compiler/unify_gen.m: Move float register arguments to the end of a closure's hidden arguments vector, after regular register arguments. Count hidden regular and float register arguments separately, but encode them in the same word in the closure. This is preferable to using two words because it reduces the differences between grades with and without float registers present. Disable generating code which creates a closure from an existing closure, if float registers exist. That code does not understand the reordered hidden arguments vector yet. compiler/continuation_info.m: Replace an argument's type_info in the closure layout if the argument is a float *and* is passed via a regular register, when floats are normally passed via float registers. Instead, give it the type_info for `private_builtin.float_box'. compiler/builtin_lib_types.m: Add function to return the type of `private_builtin.float_box/0'. compiler/hlds_out_goal.m: compiler/hlds_out_pred.m: compiler/mercury_to_mercury.m: Dump the new fields added to `generic_call', `pred_inst_info' and `proc_sub_info'. compiler/prog_type.m: Add helper predicate. compiler/*.m: Conform to changes. library/private_builtin.m: Add a type `float_box'. runtime/mercury_ho_call.h: Describe the modified closure representation. Rename the field which counts the number of hidden arguments to prevent it being used incorrectly, as it now encodes two numbers (potentially). Add macros to unpack the encoded field. runtime/mercury_ho_call.c: Update the description of how higher-order calls work. Update code which extracts closure arguments to take account the arguments being reordered in the hidden arguments vector. runtime/mercury_deep_copy.c: runtime/mercury_deep_copy_body.h: runtime/mercury_layout_util.c: runtime/mercury_ml_expand_body.h: Update code which extracts closure arguments to take account the arguments being reordered in the hidden arguments vector. runtime/mercury_type_info.c: runtime/mercury_type_info.h: Add helper function. tools/make_spec_ho_call: Update the generated do_call_closure_* functions to place float register arguments. tests/hard_coded/Mercury.options: tests/hard_coded/Mmakefile: tests/hard_coded/ho_float_reg.exp: tests/hard_coded/ho_float_reg.m: Add new test case. tests/hard_coded/copy_pred.exp: tests/hard_coded/copy_pred.m: tests/hard_coded/deconstruct_arg.exp: tests/hard_coded/deconstruct_arg.exp2: tests/hard_coded/deconstruct_arg.m: Extend test cases with float arguments in closures. tests/debugger/higher_order.exp2: Add alternative output, changed due to closure wrapping. tests/hard_coded/ho_univ_to_type.m: Adjust test case so that the float_regs pass does not report errors about missing higher-order insts. compiler/notes/compiler_design.html: Describe the new module. Delete a duplicated paragraph. compiler/notes/todo.html: TODO: Delete one hundred billion year old todos. |
||
|
|
295415090e |
Convert almost all remaining modules in the compiler to use
Estimated hours taken: 6 Branches: main compiler/*.m: Convert almost all remaining modules in the compiler to use "$module, $pred" instead of "this_file" in error messages. In a few cases, the old error message was misleading, since it contained an incorrect, out-of-date or cut-and-pasted predicate name. tests/invalid/unresolved_overloading.err_exp: Update an expected output containing an updated error message. |
||
|
|
9ae7fe6b70 |
Change the argument ordering of predicates in the set module.
Branches: main Change the argument ordering of predicates in the set module. library/set.m: Change predicate argument orders to match the versions in the svset module. Group function definitions with the corresponding predicates rather than at the end of the file. Delete Ralph's comments regarding the argument order in the module interface: readers of the library reference guide are unlikely to be interested in his opinion of the argument ordering ten or so years ago. Add extra modes for set.map/3 and set.map_fold/5. library/svset.m: library/eqvclass.m: library/tree234.m: library/varset.m: browser/*.m: compiler/*.m: deep_profiler/*.m: mdbcomp/trace_counts.m: extras/moose/grammar.m: extras/moose/lalr.m: extras/moose/moose.m: tests/hard_coded/bitset_tester.m: Conform to the above change. NEWS: Announce the above changes. |
||
|
|
322e498a50 |
Change places where we create an empty map and the immediately do a det_insert
Branches: main Change places where we create an empty map and the immediately do a det_insert into it to use the recently added singleton map function. compiler/add_pragma.m: compiler/common.m: compiler/dep_par_conj.m: compiler/higher_order.m: compiler/hlds_data.m: compiler/inst_match.m: compiler/lco.m: compiler/modecheck_goal.m: compiler/modules.m: compiler/polymorphism.m: compiler/pred_table.m: compiler/rbmm.region_resurrection_renaming.m: compiler/simplify.m: compiler/stack_layout.m: compiler/stack_opt.m: compiler/stm_expand.m: compiler/switch_util.m: compiler/term_pass2.m: compiler/tupling.m: compiler/type_constraints.m: compiler/type_ctor_info.m: compiler/unneeded_code.m: deep_profiler/autopar_search_callgraph.m: deep_profiler/html_format.m: As above. |
||
|
|
9f68c330f0 |
Change the argument order of many of the predicates in the map, bimap, and
Branches: main
Change the argument order of many of the predicates in the map, bimap, and
multi_map modules so they are more conducive to the use of state variable
notation, i.e. make the order the same as in the sv* modules.
Prepare for the deprecation of the sv{bimap,map,multi_map} modules by
removing their use throughout the system.
library/bimap.m:
library/map.m:
library/multi_map.m:
As above.
NEWS:
Announce the change.
Separate out the "highlights" from the "detailed listing" for
the post-11.01 NEWS.
Reorganise the announcement of the Unicode support.
benchmarks/*/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
extras/*/*.m:
mdbcomp/*.m:
profiler/*.m:
tests/*/*.m:
ssdb/*.m:
samples/*/*.m
slice/*.m:
Conform to the above change.
Remove any dependencies on the sv{bimap,map,multi_map} modules.
|
||
|
|
8a28e40c9b |
Add the predicates sorry, unexpected and expect to library/error.m.
Estimated hours taken: 2 Branches: main Add the predicates sorry, unexpected and expect to library/error.m. compiler/compiler_util.m: library/error.m: Move the predicates sorry, unexpected and expect from compiler_util to error. Put the predicates in error.m into the same order as their declarations. compiler/*.m: Change imports as needed. compiler/lp.m: compiler/lp_rational.m: Change imports as needed, and some minor cleanups. deep_profiler/*.m: Switch to using the new library predicates, instead of calling error directly. Some other minor cleanups. NEWS: Mention the new predicates in the standard library. |
||
|
|
4451a4f995 |
Swap order of arguments of `set_tree234.member/2' to match other
Branches: main
library/set_tree234.m:
Swap order of arguments of `set_tree234.member/2' to match other
modules.
compiler/dead_proc_elim.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/format_call.m:
compiler/inst_match.m:
compiler/llds_out_instr.m:
compiler/passes_aux.m:
compiler/post_typecheck.m:
compiler/switch_detection.m:
compiler/typecheck.m:
library/list.m:
Conform to change.
library/set.m:
library/set_ctree234.m:
library/set_ordlist.m:
library/set_unordlist.m:
Fix typos in documentation.
|
||
|
|
62d7496a7e |
Significant further improvements in the worst-case behavior of the compiler
Estimated hours taken: 16
Branches: main
Significant further improvements in the worst-case behavior of the compiler
when working on code such as zm_eq20.m and zm_coerce_tuples.m. On my laptop,
zm_eq20.m and zm_coerce_tuples.m now compile in 2.5s and 12.9s respectively;
the times before were 86.4s and 54.0s. The sizes of the stage 110 HLDS dumps
(the stage just after lambda expansion) go from 8.5Mb and 760Mb (!) to
just 0.4Mb and 7.4Mb respectively.
compiler/polymorphism.m:
Remember not just which typeinfos we have constructed, but also what
type_ctor_infos, base_typeclass_infos and typeclass_infos we have
constructed, so that we don't have to construct them again for code
that is executed later.
The maintenance of the additional maps adds some overhead that in
typical code probably cannot be made back through the resulting
reductions in the workload of later compiler passes. However,
the avoidance of horrible worst-case behavior trumps small increases
in normal-case runtime.
For zm_coerce_tuples, polymorphism.m now generates as good HLDS code
as can be expected within each lambda expression. There is still
a lot of duplicated code, with each copy being in a different lambda
expression, but factoring out these commonalities will require a
fundamentally different approach.
Avoid using the misleading prefix "TypeClassInfo_" on the names of
variables holding base_typeclass_infos.
compiler/ml_elim_nested.m:
Don't look for static definitions where they cannot occur anymore.
When deciding whether a definition needs to be hoisted out,
don't look for it being used in later static definitions,
since all the static definitions are now elsewhere.
In order to avoid running the compiler out of nondet stack space
on zm_coerce_tuples.m, avoid the use of enumerating all the
definitions in a potentially huge piece of MLDS by backtracking.
compiler/hlds_rtti.m:
Avoid enumerating all the members of a potentially huge list
by backtracking in order to avoid running the compiler out of nondet
stack space on zm_coerce_tuples.m.
I first tried to do this by constructing the list with det code,
but this turned out not to fix the underlying problem, which was that
almost all of the list's elements were copies of each other, and we
then had to get rid of the copies. The actual fix is to gather the
types we need directly as a set.
Provide restrict_rtti_varmaps for use by lambda.m.
Give the field names of the rtti_varmaps type a distinguishing prefix.
compiler/lambda.m:
The fundamental reason for the bad performance of the equiv_type_hlds
pass on zm_coerce_tuples.m was that even with the recent improvements
to polymorphism.m, a couple of big predicates had about ten thousand
variables each, and when lambda.m created about 200 new procedures
from the lambda expressions inside them, it duplicated those huge
vartypes and rtti_varmaps for each one.
The fix is to restrict the vartypes and the rtti_varmaps of both
the newly created procedures and the old procedure they were taken from
to the variables that actually occur in them.
We could potentially avoid the need to restrict the rtti_varmap
of the original procedure for the new procedures created for lambda
goals by having polymorphism.m give each rhs_lambda_goal its own
rtti_varmap in the first place, but that would be future work.
Use the "no lambda" version of quantification after the lambda pass,
since we have just removed all the lambdas from the goal being
quantified.
Give the predicates of this module more expressive names.
compiler/mercury_compile.m:
Conform to the change in lambda.m.
compiler/equiv_type_hlds.m:
Use specialized versions of the predicates in equiv_type.m, since
the general versions do some things (finding circularities, recording
used modules) that this pass does not need. Use some new predicates
from the standard library to reduce overhead.
compiler/ml_optimize.m:
In order to avoid running the compiler out of nondet stack space
on zm_coerce_tuples.m, avoid the use of enumerating all the members
of a potentially huge list by backtracking.
Move a cheap test before a more expensive one.
compiler/modes.m:
compiler/modecheck_unify.m:
Avoid some unnecessary overheads when modechecking typeinfos and
related variables. One overhead was iteration over a list of exactly
one element, another is a redundant lookup of the variable's type,
and the third is the redundant setting of the unify context.
compiler/inst_match.m:
Use set_tree234s instead sets to keep track of expansions in one group
of predicates indicated by benchmarking.
library/list.m:
Add a new predicate, list.find_first_match, which is a version of
filter that returns only the first matching item. This is for use
in ml_elim_nested.m.
Make list.sort_and_remove_dups remove duplicates as it goes,
not all at the end, since this (a) allows us to avoid a separate
duplicate-elimination pass at the end, and (b) any duplicate eliminated
in one merge pass reduces the workload for any later merge passes.
Put some code in its proper order, since preserving tail recursion
in Prolog is no longer an issue.
library/map.m:
Add versions of map.foldl{,2,3} and map.map_foldl{,2,3} that do not
pass the key to the higher order argument, for use by some of the
compiler modules above.
Group the declarations of all the foldr predicates together.
library/tree.m:
Make the same changes as in map.m, in order to implement map.m's new
predicates.
library/varset.m:
Minor style improvements.
library/set_tree234.m:
Fix a wrong comment.
NEWS:
Mention the new additions to the library.
|
||
|
|
d69ba1a1f0 |
Include the type_ctor in cons_ids for user-defined types.
Estimated hours taken: 32 Branches: main Include the type_ctor in cons_ids for user-defined types. The intention is two-fold: - It prepares for a future in which we allow more than one function symbol to with the same name to be defined in a module. - It makes the HLDS code more self-contained. In many places, processing construction and deconstruction unifications required knowing which type the cons_id belongs to, but until now, code couldn't know that unless it kept track of the type of the variable unified with the cons_id. With this diff, user-defined cons_ids are represented as cons(SymName, Arity, TypeCtor) The last field is filled in during post-typecheck. After that time, any module qualification in the SymName (which may initially be partial) is redundant, since it is also available in the TypeCtor. In the future, we could make all those SymNames be just unqualified(_) at that time. We could also replace the current maps in HLDS type definitions with full cons_id keys with just name/arity keys (since the module qualifier is a given for any given type definition), we could also support partially qualified cons_ids in source code using a map from name/arity pairs to a list of all the type_ctors that have function symbols with that name/arity, instead of our current practice of inserting all possible partially module qualified version of every cons_id into a single giant table, and we could do the same thing with the field names table. This diff also separates tuples out from user-defined types, since in many respects they are different (they don't have a single type_ctor, for starters). It also separates out character constants, since they were alreay treated specially in most places, though not in some places where they *ought* to have been treated specially. Take the opportunity to give some other cons_ids better names. compiler/prog_data.m: Make the change described above, and document it. Put the implementations of the predicates declared in each part of this module next to the declarations, instead of keeping all the code until the very end (where it was usually far from their declarations). Remove three predicates with identical definitions from inst_match.m, inst_util.m and mode_constraints.m, and put the common definition in prog_data.m. library/term_io.m: Add a new predicate that is basically a reversible version of the existing function espaced_char, since the definition of char_consts needs reversibilty. compiler/post_typecheck.m: For functors of user-defined types, record their type_ctor. For tuples and char constants, record them as such. compiler/builtin_lib_types.m: compiler/parse_tree.m: compiler/notes/compiler_design.html: New module to centralize knowledge about builtin types, specially handled library types, and their function symbols. Previously, the stuff now in this module used to be in several different places, including prog_type.m and stm_expand.m, and some of it was duplicated. mdbcomp/prim_data.m: Add some predicates now needed by builtin_lib_types.m. compiler/builtin_ops.m: Factor out some duplicated code. compiler/add_type.m: Include the relevant type_ctors in the cons_ids generated in type definitions. compiler/hlds_data.m: Document an existing type better. Rename a cons_tag in sync with its corresponding cons_id. Put some declarations into logical order. compiler/hlds_out.m: Rename a misleadingly-named predicate. compiler/prog_ctgc.m: compiler/term_constr_build.m: Add XXXs for questionable existing code. compiler/add_clause.m: compiler/add_heap_ops.m: compiler/add_pragma.m: compiler/add_pred.m: compiler/add_trail_ops.m: compiler/assertion.m: compiler/bytecode_gen.m: compiler/closure_analysis.m: compiler/code_info.m: compiler/complexity.m: compiler/ctgc_selector.m: compiler/dead_proc_elim.m: compiler/deep_profiling.m: compiler/delay_partial_inst.m: compiler/dependency_graph.m: compiler/det_analysis.m: compiler/det_report.m: compiler/distance_granularity.m: compiler/erl_rtti.m: compiler/erl_unify_gen.m: compiler/export.m: compiler/field_access.m: compiler/foreign.m: compiler/format_call.m: compiler/hhf.m: compiler/higher_order.m: compiler/hlds_code_util.m: compiler/hlds_desc.m: compiler/hlds_goal.m: compiler/implementation_defined_literals.m: compiler/inst_check.m: compiler/inst_graph.m: compiler/inst_match.m: compiler/inst_util.m: compiler/instmap.m: compiler/intermod.m: compiler/interval.m: compiler/lambda.m: compiler/lco.m: compiler/make_tags.m: compiler/mercury_compile.m: compiler/mercury_to_mercury.m: compiler/middle_rec.m: compiler/ml_closure_gen.m: compiler/ml_code_gen.m: compiler/ml_code_util.m: compiler/ml_switch_gen.m: compiler/ml_type_gen.m: compiler/ml_unify_gen.m: compiler/ml_util.m: compiler/mlds_to_c.m: compiler/mlds_to_java.m: compiler/mode_constraints.m: compiler/mode_errors.m: compiler/mode_ordering.m: compiler/mode_util.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/module_qual.m: compiler/polymorphism.m: compiler/prog_ctgc.m: compiler/prog_event.m: compiler/prog_io_util.m: compiler/prog_mode.m: compiler/prog_mutable.m: compiler/prog_out.m: compiler/prog_type.m: compiler/prog_util.m: compiler/purity.m: compiler/qual_info.m: compiler/rbmm.add_rbmm_goal_infos.m: compiler/rbmm.execution_path.m: compiler/rbmm.points_to_analysis.m: compiler/rbmm.region_transformation.m: compiler/recompilation.usage.m: compiler/rtti.m: compiler/rtti_out.m: compiler/rtti_to_mlds.m: compiler/simplify.m: compiler/simplify.m: compiler/special_pred.m: compiler/ssdebug.m: compiler/stack_opt.m: compiler/stm_expand.m: compiler/stratify.m: compiler/structure_reuse.direct.detect_garbagem: compiler/superhomoegenous.m: compiler/switch_detection.m: compiler/switch_gen.m: compiler/switch_util.m: compiler/table_gen.m: compiler/term_constr_build.m: compiler/term_norm.m: compiler/try_expand.m: compiler/type_constraints.m: compiler/type_ctor_info.m: compiler/type_util.m: compiler/typecheck.m: compiler/typecheck_errors.m: compiler/unify_gen.m: compiler/unify_proc.m: compiler/unify_modes.m: compiler/untupling.m: compiler/unused_imports.m: compiler/xml_documentation.m: Minor changes, mostly to ignore the type_ctor in cons_ids in places where it is not needed, take the type_ctor from the cons_id in places where it is more convenient, conform to the new names of some cons_ids, conform to the changes in hlds_out.m, and/or add now-needed imports of builtin_lib_types.m. In some places, the handling previously applied to cons/2 (which included tuples and character constants as well as user-defined function symbols) is now applied only to user-defined function symbols or to user-defined function symbols and tuples, as appropriate, with character constants being handled more like the other kinds of constants. In inst_match.m, rename a whole bunch of predicates to avoid ambiguities. In prog_util.m, remove two predicates that did almost nothing yet were far too easy to misuse. |
||
|
|
ea84652184 |
"Fix" a problem whose workaround by Julien was committed recently.
Estimated hours taken: 6 Branches: main "Fix" a problem whose workaround by Julien was committed recently. The immediate symptom was a code generator abort caused by a model_non goal in a model_det context: a det procedure whose body was multi. The reason why the body was multi was that a disjunction with no outputs was not recognized as having no outputs, because instmap_delta_no_output_vars_2 does not succeed if the old and new insts of a variable specify non-overlapping sets of function symbols. This diff does not fix the actual problem (though it does document it), but it does make it much less likely to occur by making the mishandled situation much less likely to occur. compiler/instmap.m: Document the problem with instmap_delta_no_output_vars_2. Simplify the code of instmap_delta_no_output_vars_2. compiler/mode_util.m: When recomputing instmap_deltas of deconstruction unifications, abstractly unify the inst of the LHS variable before and after the deconstruction. If the cons_id does not appear among the possible cons_ids in the old inst, this will make the final inst not_reached, and avoid the problem situation for later. compiler/Mercury.options: Remove Julien's workaround, since it is not needed anymore. doc/user_guide.texi: Document the --dump-hlds-options a bit better. This helped in tracking down the problem. tests/hard_coded/Mmakefile: Reenable an old test that this change now enables us to pass. The following are style fixes only. compiler/compile_target_code.m: Fix formatting in the code affected by the workaround. compiler/handle_options.m: Add a dump alias to help diagnose determinism problems. compiler/inlining.m: compiler/inst_util.m: Minor style fixes. compiler/inst_match.m: Put the predicates into more logical groups. Move documentation of exported predicates from the implementation section to the interface section. Add a prefix to field names, to avoid ambiguity. Avoid the use of with_type and with_inst. Avoid the use of faux field accesses when it makes the actual steps harder to understand. Make the initial values of inst_match_info explicit. Abort when the lists of a cons_id's argument variables and argument modes are of different lengths. |
||
|
|
097b45acec |
Fix two problems that together caused bug Mantis bug #44.
Estimated hours taken: 12 Branches: main Fix two problems that together caused bug Mantis bug #44. The first bug was that unify_gen.m wasn't checking whether a variable it was adding to a closure was of dummy type or not. The second bug was that the code for recognizing whether a type is dummy or not recognized only two cases: builtin dummy types such as io.state, and types with one function symbol of arity zero. In this program, there is a notag wrapper around a dummy type. Since the representation of a notag type is always the same as the type it wraps, this notag type should be recognized as a dummy type too. compiler/unify_gen.m: Fix the first bug by adding the required checks. compiler/code_info.m: Add a utility predicate to factor out some now common code in unify_gen.m. (The modifications to all the following files were to fix the second bug.) compiler/hlds_data.m: compiler/prog_type.m: Change the type_category type (in prog_type.m) and the enum_or_dummy type (in hlds_data.m) to separate out the representation of notag types from other du types. This allows the fix for the second bug, and incidentally allows some parts of the compiler to avoid the same tests over and over. To ensure that all places in the compiler that could need special handling for notag types get them, rename those types to type_ctor_category (since it does *not* take argument types into account) and du_type_kind respectively. Since the type_ctor_category type needs to be modified anyway, change it to allow code that manipulates values of the type to factor out common code fragments. Rename some predicates, and turn some into functions where this helps to make code (either here or in clients) more robust. compiler/make_tags.m: When creating a HLDS representation for a du type, record whether it is a notag type (we already recorded whether it is enum or dummy). compiler/type_util.m: Fix the predicate that tests for dummy types by recognizing the third way a type can be a dummy type. Don't test for dummyness of the argument when deciding whether a type could be a notag types; just record it as a notag type, and let later lookup code use the new fixed algorithm to do the right thing. Add a type for recording the is_dummy_type/is_not_dummy_type distinction. Rename some predicates, and turn some into functions where this helps to make code (either here or in clients) more robust. Add an XXX about possible redundant code. compiler/llds.m: Use the new type instead of booleans in some places. compiler/add_pragma.m: compiler/add_special_pred.m: compiler/add_type.m: compiler/bytecode_gen.m: compiler/continuation_info.m: compiler/ctgc.selector.m: compiler/ctgc.util.m: compiler/equiv_type_hlds.m: compiler/erl_call_gen.m: compiler/erl_code_gen.m: compiler/erl_code_util.m: compiler/erl_unify_gen.m: compiler/exception_analysis.m: compiler/export.m: compiler/foreign.m: compiler/higher_order.m: compiler/hlds_data.m: compiler/hlds_out.m: compiler/hlds_pred.m: compiler/inst_match.m: compiler/intermod.m: compiler/llds_out.m: compiler/ml_call_gen.m: compiler/ml_closure_gen.m: compiler/ml_code_gen.m: compiler/ml_code_util.m: compiler/ml_simplify_switch.m: compiler/ml_switch_gen.m: compiler/ml_type_gen.m: compiler/ml_unify_gen.m: compiler/mlds.m: compiler/mlds_to_c.m: compiler/mlds_to_gcc.m: compiler/mlds_to_il.m: compiler/mlds_to_java.m: compiler/opt_debug.m: compiler/opt_util.m: compiler/polymorphism.m: compiler/pragma_c_gen.m: compiler/prog_type.m: compiler/rtti_to_mlds.m: compiler/simplify.m: compiler/special_pred.m: compiler/stack_layout.m: compiler/switch_gen.m: compiler/switch_util.m: compiler/table_gen.m: compiler/term_constr_util.m: compiler/term_norm.m: compiler/trace_gen.m: compiler/trailing_analysis.m: compiler/type_ctor_info.m: compiler/type_util.m: compiler/unify_proc.m: compiler/var_locn.m: Conform to the changes above. Make a few analyses more precise by using the new detail in the type_ctor_category type to make less conservative assumptions about du types that are either notag or dummy. In ctgc.selector.m, ctgc.util.m, make_tags.m, mlds_to_java.m and special_pred.m, add XXXs about possible bugs. tests/valid/fzn_debug_abort.m: Add the bug demo program from Mantis as a regression test. tests/valid/Mmakefile: tests/valid/Mercury.options: Enable the new test, and run it with the old bug-inducing option. |
||
|
|
7460aadbf8 |
Implement higher-order any' insts. Pred or func expressions with an any'
Estimated hours taken: 100 Branches: main Implement higher-order `any' insts. Pred or func expressions with an `any' inst may bind non-local solver variables, but themselves must not be called in a negated context. (The existing ground pred and func expressions may not bind non-local solver variables, but may be called in a negated context.) Higher-order `any' insts are specified by using `any_pred' and `any_func' in place of `pred' and `func', respectively. We implement these insts by adding a new field to the any/1 constructor of mer_inst, which is identical to the ground_inst_info field of the ground/2 constructor. Both are given the new type `ho_inst_info'. We then relax the locking of non-local variables in these pred and func expressions, and extend call/N and apply/N to also accept the new insts (provided the variables are not locked). We also store the groundness (ho_ground or ho_any) of each lambda expression in a unification, in a new field in the rhs_lambda_goal constructor. NEWS: Mention the new feature. compiler/prog_data.m: Rename the ground_inst_info type ho_inst_info, and update its documentation. Add the ho_inst_info field to the any constructor in mer_inst. compiler/hlds_goal.m: Add the rhs_groundness field to rhs_lambda_goal in unify_rhs. compiler/inst_match.m: Propagate inst matching into the pred_inst_infos of any insts, if they exist. compiler/inst_util.m: Propagate abstract unification and inst merging into the pred_inst_infos of any insts, if they exist. May use of this information when building ground, any, shared and mostly_unique versions of insts. compiler/modecheck_call.m: Allow an `any' inst as the pred (func) argument to call/N (apply/N), but check that the variable is not locked. If the variable is locked, report a mode error which suggests using the ground inst. (We could also suggest that the goal be made impure, but it is best to point users towards the pure approach.) compiler/modecheck_unify.m: Relax the locking of non-locals when processing non-ground lambda goals. Update documentation. compiler/mode_util.m: Propagate type information into the pred_inst_infos of any insts. compiler/mode_errors.m: Change the purity error "lambda should be impure" to "lambda should be any", since this is better advice. Also provide an example of correct syntax if the verbose errors option is given. compiler/prog_io_goal.m: Parse the new kinds of expressions, returning the groundness along with the existing information about lambda expressions. compiler/superhomogeneous.m: Use the above groundness when building the lambda unification. compiler/prog_io_util.m: Parse the new kind of insts, filling in the new ho_inst_info field where appropriate. compiler/polymorphism.m: Handle the new fields. Assume that the shorthand form of lambda expressions always defines a ground inst -- if users want non-ground higher-order expressions they will need to use an explicit any_pred or any_func expression. compiler/equiv_type_hlds.m: Replace equivalent types in the pred_inst_infos of `any' insts. compiler/module_qual.m: Module qualify the pred_inst_infos of `any' insts. compiler/recompilation.usage.m: compiler/unused_imports.m: Look for items or imports used by insts in the pred_inst_infos of `any' insts. compiler/hlds_out.m: compiler/mercury_to_mercury.m: Output the new lambda expressions and insts in the correct format. compiler/type_util.m: Treat all pred and func types as solver types. (Effectively they are, since all such types can now have non-ground values, with call/N and apply/N acting as constraints.) compiler/lambda.m: Pass the groundness value when building procedures for lambda expressions. This is not currently required for anything. doc/reference_manual.texi: Document the new feature, and update existing documentation on solver types and negated contexts. tests/valid/Mmakefile: tests/valid/ho_any_inst.m: New test case for some valid code using higher-order any insts. tests/invalid/Mmakefile: tests/invalid/ho_any_inst.err_exp: tests/invalid/ho_any_inst.m: New test case for some illegal code. tests/invalid/anys_in_negated_contexts.err_exp: Update expected error message for this test case. We now report that the expression should be `any', rather than impure. compiler/*.m: Handle the new fields. |