Commit Graph

41 Commits

Author SHA1 Message Date
Zoltan Somogyi
c5b64d36ea Convert (C->T;E) to (if C then T else E). 2015-10-18 08:21:53 +11:00
Zoltan Somogyi
bbb2535eb5 Break up mercury_to_mercury.m.
With almost 6000 lines, mercury_to_mercury.m was one of the biggest modules
of compiler, but it was far from cohesive. This diff carves seven new modules
out of it, each of which is much more cohesive. The stuff remaining in
mercury_to_mercury.m is still not as cohesive as one would like, but it is
now small enough that moving its individually-cohesive parts into modules
of their own would be overkill.

Three consequences of the old mercury_to_mercury.m's lack of cohesion
were that

- the order of predicate declarations often did not match the order of
  their implementation;
- related predicates were not grouped together;
- even when they were grouped together, the order of those groups
  was often random.

This diff fixes all three of these problems for all eight successor modules
of mercury_to_mercury.m: the seven new modules, and the new
mercury_to_mercury.m itself.

In some cases, this diff adds or improves the documentation of the predicates
in mercury_to_mercury.m's successor modules. In some other cases, it just
documents the lack of documentation :-(. In yet other cases, it removes
"documentation" that says nothing that isn't obvious from the predicate's name.

There are some algorithmic changes, but they are all trivial.

compiler/parse_tree_out.m:
    New module containing the code to print out the top levels of parse trees,
    including most sorts of items.

compiler/parse_tree_out_clause.m:
    New module containing the code to print out clauses and goals.

compiler/parse_tree_out_pragma.m:
    New module containing the code to print out pragmas.

compiler/parse_tree_out_pred_decl.m:
    New module containing the code to print out predicate, function and
    mode declarations. It is separate from parse_tree_out.m because a
    significant number of compiler modules need only its functionality,
    and not parse_tree_out.m's functionality.

compiler/parse_tree_out_inst.m:
    New module containing the code to print out insts and modes.

compiler/parse_tree_out_term.m:
    New module containing the code to print out variables and terms.

compiler/parse_tree_out_info.m:
    New module containing the infrastructure of both mercury_to_mercury.m
    and the other new modules.

compiler/parse_tree.m:
    Include the new modules.

compiler/notes/compiler_design.html:
    Document the new modules.

compiler/Mercury.options:
    Transfer an option from mercury_to_mercury.m to the successor module
    that needs it.

compiler/*.m:
    Import one of the new modules either as well as, or instead of,
    mercury_to_mercury.m. In most cases, we need to import only one
    or two of mercury_to_mercury.m's successor modules; nowhere do we
    need to import all eight.

    Clean up some code in termination.m around a call to one of the
    new modules.

tools/speedtest:
    Replace mercury_to_mercury.m on the list of the ten largest modules
    of the compiler.
2015-09-06 21:01:11 +10:00
Zoltan Somogyi
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.
2015-08-25 00:38:49 +10:00
Zoltan Somogyi
1aee1b8ade Don't put variable names in clauses in .opt files.
After this diff, a change in the source file that affects only variable names
won't cause the recompilation of the other modules that use the changed
module's .opt file. (I got a bunch of such unnecessary recompilations when
giving new names to many of varset.m's variables.)

compiler/prog_data.m:
    Add a new type named var_name_print to replace the boolean that used
    to specify whether we wanted to print the variable number as a suffix
    after the variable name. This new type allows us to specify not just that
    e.g. a variable numbered 10 and named Example should be printed as
    Example or as Example_10, but also as V_10.

compiler/intermod.m:
    Use this capability to print variables in only the V_N form when
    putting clauses in .opt files. After this diff, a change in the source
    file that affects only variable names won't cause the recompilation
    of the other modules that use the change module's .opt file.

    Convert (C->T;E) into (if C then T else E).

compiler/mercury_to_mercury.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_mode.m:
compiler/hlds_out_module.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
    Generalize mercury_var_to_string, and the predicates that call it
    directly or indirectly, to take an argument of the var_name_print type
    instead of the old AppendVarNum boolean.

    Put the argument lists of the affected predicates in a better order,
    with related parameters being next to each other, and moving more global
    parameters before more local parameters.

    Add versions of mercury_var_to_string to mercury_vars_to_string
    that assume the print_name_only value for the var_name_print parameter,
    since this is typically what we want when we generate error messages.

    In hlds_out_pred.m, add another type, write_which_modes, to replace
    another boolean parameter.

compiler/add_foreign_proc.m:
compiler/add_pragma_type_spec.m:
compiler/check_typeclass.m:
compiler/code_loc_dep.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/field_access.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/hlds_desc.m:
compiler/layout_out.m:
compiler/liveness.m:
compiler/llds_out_instr.m:
compiler/make_hlds_warn.m:
compiler/mercury_to_mercury.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/pd_debug.m:
compiler/post_typecheck.m:
compiler/prog_ctgc.m:
compiler/prog_io_item.m:
compiler/prog_io_mutable.m:
compiler/prog_io_type_defn.m:
compiler/prog_io_typeclass.m:
compiler/prog_util.m:
compiler/purity.m:
compiler/push_goals_together.m:
compiler/rbmm.live_variable_analysis.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/saved_vars.m:
compiler/stack_opt.m:
compiler/structure_reuse.indirect.m:
compiler/type_assign.m:
compiler/type_constraints.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
    Conform to the above changes.
2015-08-22 14:42:28 +10:00
Zoltan Somogyi
13b6f03f46 Module qualify end_module declarations.
compiler/*.m:
    Module qualify the end_module declarations. In some cases, add them.

compiler/table_gen.m:
    Remove an unused predicate, and inline another in the only place
    where it is used.

compiler/add_pragma.m:
    Give some predicates more meaningful names.
2014-09-04 00:24:52 +02:00
Zoltan Somogyi
16bd4acd2f Shorten lines longer than 79 characters.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Shorten lines longer than 79 characters.
2012-10-24 05:49:47 +00:00
Zoltan Somogyi
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.
2012-04-23 03:34:49 +00:00
Zoltan Somogyi
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.
2012-03-27 23:21:33 +00:00
Zoltan Somogyi
a128f27105 Make the mode analysis pass return errors as a single list of error
Estimated hours taken: 10
Branches: main

Make the mode analysis pass return errors as a single list of error
specifications, instead of printing those error specifications out
in bits and pieces as it goes along.

Since the mode analysis code now does not need the I/O state to print out
error messages, don't pass the I/O state around in it. Use trace goals
when we need to print progress messages or debugging output.

compiler/modes.m:
compiler/unique_modes.m:
compiler/modecheck_unify.m:
compiler/modecheck_call.m:
	Implement the change described above.

	Rationalize the argument orders of some predicates.

compiler/modes.m:
compiler/unify_proc.m:
	Move the code for modechecking the procedures in the requested unify
	procedure queue from unify_proc.m to modes.m, since that is where
	all the related code is. Export a small, abstract part of the
	representation of the request queue from unify_proc.m to make this
	possible.

compiler/mode_debug.m:
	Delete the checkpoint predicate's I/O state arguments.

compiler/mode_errors.m:
	Replace predicates that print some error messages with functions
	that just return their error specifications.

	Delete some unused predicates.

	Replace a boolean with a purpose-specific type.

	Rationalize the argument orders of some predicates.

compiler/cse_detection.m:
compiler/delay_partial_inst.m:
	Don't pass around the I/O state, since it is now not needed.

	Rename a predicate to avoid ambiguity.

compiler/mercury_compile.m:
	Conform to the changes above. Amongst other things, this means
	printing the error specifications returned by mode analysis.

compiler/pd_util.m:
compiler/try_expand.m:
	Conform to the changes above.

compiler/error_util.m:
	Fix a typo.

tests/invalid/bigtest.err_exp:
tests/invalid/constrained_poly_insts.err_exp:
	Update these expected outputs for the new order of the error messages.
	(Before the error specifications are printed, they are sorted by
	context; this sorting did not occur in the old version.)
2009-07-21 02:08:56 +00:00
Zoltan Somogyi
5ad9a27793 Speed up the compiler's handling of code that constructs large ground terms
Estimated hours taken: 80
Branches: main

Speed up the compiler's handling of code that constructs large ground terms
by specializing the treatment of such code.

This diff reduces the compilation time for training_cars_full.m from 106.9
seconds to 30.3 seconds on alys, my laptop. The time on tools/speedtest
stays pretty much the same.

compiler/hlds_goal.m:
	Record the classification of from_ground_term scopes as purely
	constructing terms, purely deconstructing them or something other.

	Fix an old potential bug: variables inside the construct_how fields
	of unifications weren't being renamed along with other variables.
	This is a bug if any part of the compiler later looks at those
	variables. (I am not sure whether or not this happens.)

compiler/superhomogenous.m:
	Provisionally mark newly constructed static terms as being
	from_ground_term_construct. Mode checking will either confirm this
	or change the scope kind.

compiler/options.m:
compiler/handle_options.m:
	Add a new option, from_ground_term_threshold, that allows the user to
	set the boundary between ground terms that get scopes and ground terms
	do not. I plan to experiment with different settings later.

compiler/modes.m:
	Make this classification. For scopes that construct ground terms,
	use a specialized algorithm that avoids quadratic behavior.
	(It does not access the unify_inst_table, which is where the
	factor of N other than the length of the goal list came from.)
	The total size of the instmap_deltas, if printed out, still looks like
	O(N^2) in size, but due to structure sharing it needs only O(N) memory.

	For scopes that construct ground terms, set the determinism information
	so that det_analysis.m doesn't have to traverse such scopes.

	When handling disjunctions, check whether some nonlocals of the
	disjunctions are constructed by from_ground_term_construct scopes.
	For any such nonlocals, set their insts to just ground, throwing away
	the precise information we have about exactly what function symbols
	they and ALL their subterms are bound to. This is HUGE win, since
	it allows us avoid spending a lot of time building a huge merge_inst
	table, which later passes of the compiler (e.g. equiv_type_hlds) would
	then have to spend similarly huge times traversing.

	This approach does have a down side. If lots of arms of a disjunction
	bind a nonlocal to a large ground term, but a few bind it to a SMALL
	ground term, a term below the from_ground_term_threshold, this
	optimization won't kick in. That could be one purpose of the new
	option. It isn't documented yet; I will seek feedback about its
	usefulness first.

compiler/modecheck_unify.m:
	Handle the three different kinds of right hand sides separately.
	This yields a small speedup, because now we don't test rhs_vars and
	rhs_functors (the common right hand sides) for a special case
	(goals containing "any" insts) that is applicable only to
	rhs_lambda_goals.

compiler/unique_modes.m:
	Don't traverse scopes that construct ground terms, since modes.m has
	already done everything that needs to be done.

compiler/det_analysis.m:
	Don't traverse scopes that construct ground terms, since modes.m has
	already done the needed work.

compiler/instmap.m:
	Add a new predicate for use by modes.m.

	Many predicate names in this module were quite uninformative; give them
	informative names.

compiler/polymorphism.m:
	If this pass invalidates the from_ground_term_construct invariants,
	then mark the relevant scope as from_ground_term_other.

	Delete two unused access predicates.

compiler/equiv_type_hlds.m:
	Don't traverse scopes that construct ground terms, since modes.m
	ensures that their instmap deltas do not contain typed insts, and
	thus the scope cannot contain types that need to be expanded.

	Convert some predicates to single clauses.

compiler/goal_form.m:
compiler/goal_util.m:
	In predicates that test goals for various properties, don't traverse
	scopes that construct ground terms when the outcome of the test
	is the same for all such scopes.

	Convert some predicates to single clauses.

compiler/simplify.m:
	Do not look for common structs in from_ground_term_construct scopes,
	both because this speeds up the compiler, and because retaining
	references to ground terms is in fact a pessimization, not an
	optimization. This is because (a) those references need to be stored in
	stack slots across calls, and (b) the C code generators ensure that
	the cells representing ground terms will be shared as needed.

	If all arms of a switch are from_ground_term_construct scopes,
	do not merge the instmap_deltas from those arms, since this is
	both time-consuming (even after the other changes in this diff)
	and extremely unlikely to improve the instmap_delta.

	Disable common_struct in from_ground_term_construct scopes,
	since for these scopes, it is actually a pessimization.

	Do not delete from_ground_term_construct scopes, since many
	compiler passes can now use them.

	Do some manual deforestation, break up some large predicates,
	and give better names to some.

compiler/liveness.m
	Special-case the handling from_ground_term_construct scopes. This
	allows us to traverse them just once instead of three times, and this
	traversal is simpler and faster than any of the three.

	In some traversals, we were switching on the goal type twice; once
	in e.g. detect_liveness_in_goal_2, and once by calling
	goal_expr_has_subgoals. Eliminate the double switching by merging
	the relevant predicates. (The double-switching structure was easier
	to work with before we had multi-cons-id switches.)

compiler/typecheck.m:
	Move a lookup after a test, so we don't have to do it if the test
	fails.

	Provide a specialized mode for a predicate. This should allow the
	compiler to eliminate an argument and a test in the common case.

	Note a possible chance for a speedup.

compiler/typecheck_info.m:
	Don't apply empty substitutions to the types of a possibly very large
	set of variables.

compiler/quantification.m:
	Don't quantify from_ground_term_construct scopes. They are created
	correctly quantified, and any compiler pass that invalidates that
	quantification also removes the from_ground_term_construct mark.

	Don't apply empty renamings to a possibly very large set of variables.

	Move the code for handling scopes to its own predicate, to avoid
	overwhelming the code that handles other kinds of goals. Even from
	this, factor out the renaming code, since it is needed only for
	some kinds of scopes.

	Make some predicate names better reflect what the predicate does.

compiler/pd_cost.m:
	For from_ground_term_construct scopes, instead of computing their cost
	by adding up the costs of the goals inside, make their cost a constant,
	since binding a variable to a static term takes constant time.

compiler/pd_info.m:
	Add prefixes on field names to avoid ambiguities.

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/closure_analysis.m:
compiler/constraint.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/distance_granularity.m:
compiler/exception_analysis.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/format_call.m:
compiler/granularity.m:
compiler/higher_order.m:
compiler/implicit_parallelism.m:
compiler/inlining.m:
compiler/interval.m:
compiler/lambda.m:
compiler/lco.m:
compiler/live_vars.m:
compiler/loop_inv.m:
compiler/middle_rec.m:
compiler/mode_util.m:
compiler/parallel_to_plain_conj.m:
compiler/saved_vars.m:
compiler/stm_expand.m:
compiler/store_alloc.m:
compiler/stratify.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.lbu.m:
compiler/structure_sharing.analysis.m:
compiler/switch_detection.analysis.m:
compiler/trail_analysis.m:
compiler/term_pass1.m:
compiler/tupling.m:
compiler/unneeded_code.m:
compiler/untupling.m:
compiler/unused_args.m:
	These passes have nothing to do in from_ground_term_construct scopes,
	so don't traverse them.

	In some modules (e.g. dead_proc_elim), some traversals had to be kept.

	In loop_inv.m, replace a code structure that updated accumulators
	with functions (which prevented the natural use of state variables),
	that in lots of places reconstructed the term it had just
	deconstructed, and obscured the identical handling of different kinds
	of goals, with a structure based on predicates, state variables and
	shared code for different goal types where possible.

	In store_alloc.m, avoid some double switching on the same value.

	In stratify.m, unneeded_code.m and unused_args.m, rename predicates
	to avoid ambiguities.

compiler/goal_path.m:
compiler/goal_util.m:
compiler/implementation_defined_literals.m:
compiler/intermode.m:
compiler/mark_static_terms.m:
compiler/ml_code_gen.m:
compiler/mode_ordering.m:
compiler/ordering_mode_constraints.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/rbmm.actual_region_arguments.m:
compiler/rbmm.add_rbmm_goal_infos.m:
compiler/rbmm.condition_renaming.m:
compiler/rbmm.execution_path.m:
compiler/rbmm.region_transformation.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.lfu.m:
compiler/structure_reuse.versions.m:
compiler/term_const_build.m:
compiler/term_traversal.m:
compiler/unused_imports.m:
	Mark places where we cannot (yet) special case
	from_ground_term_construct scopes.

	In structure_reuse.lfu.m, turn nested if-then-elses into a switch in.

compiler/size_prof.m:
	Turn from_ground_term_construct scopes into from_ground_term_other
	scopes, since in term size profiling grades, we need to attach sizes to
	terms.

	Give predicates better names.

compiler/*.m:
	Minor changes to conform to the changes above.

compiler/make_hlds_passes.m:
	With -S, print statistics after the third pass over items, since
	this is the time-consuming one.

compiler/mercury_compile.m:
	Conform to the new names of some predicates.

	When declining to output a HLDS dump because it would be identical to
	the previous dump, don't confuse the user either by being silent about
	the decision, or by leaving an old dump laying around that could be
	mistaken for a new one.

tools/binary:
tools/binary_step:
	Bring these tools up to date.

compiler/Mmakefile:
	Add an int3s target for use by the new code in the tools. The
	Mmakefiles in the other directories with Mercury code already have
	such a target.

compiler/notes/allocation.html:
	Fix an out-of-date reference.

tests/debugger/polymorphic_ground_term.{m,inp,exp}:
	New test case to check whether liveness.m handles typeinfo liveness
	of ground terms correctly.

tests/debugger/Mmakefile:
	Enable the new test case.

tests/debugger/polymorphic_output.{m,exp}:
	Fix tab/space mixup.
2008-12-23 01:38:03 +00:00
Zoltan Somogyi
a00596c283 The file modules.m contains lots of different kinds of functionality.
Estimated hours taken: 16
Branches: main

The file modules.m contains lots of different kinds of functionality.
While much of it belongs together, much of it does not. This diff moves
most of the functionality that does not belong with the rest to several
new modules:

	libs.file_util
	parse_tree.deps_map
	parse_tree.file_names
	parse_tree.module_cmds
	parse_tree.module_imports
	parse_tree.read_module
	parse_tree.write_deps_file

To make them coherent, move some predicates from hlds.passes_aux,
parse_tree.prog_io and parse_tree.prog_out to the new modules, making them
more accessible, reducing the required access from the hlds package to
parse_tree, or from the parse_tree package to libs.

In the same spirit, this diff also moves some simple predicates and functions
dealing with sym_names from prog_util.m to mdbcomp/prim_data.m. This allows
several modules to avoid depending on parse_tree.prog_util.

Rename some of the moved predicates and function symbols where this avoids
ambiguity. (There were several that differed from other predicates or function
symbols only in arity.)

Replace several uses of bools with purpose-specific types. This makes some
of the code significantly easier to read.

This diff moves modules.m from being by far the largest module, to being
only the seventh largest, from 8900+ lines to just 4200+. It also reduces
the number of modules that import parse_tree.modules considerably; most
modules that imported it now import only one or two of the new modules instead.

Despite the size of the diff, there should be no algorithmic changes.

compiler/modules.m:
compiler/passes_aux.m:
compiler/prog_io.m:
compiler/prog_out.m:
	Delete the moved functionality.

compiler/file_util.m:
	New module in the libs package. Its predicates search for files
	and do simple error or progress reporting.

compiler/file_names.m:
	New module in the parse_tree package. It contains predicates for
	converting module names to file names.

compiler/module_cmds.m:
	New module in the parse_tree package. Its predicates handle the
	commands for manipulating interface files of various kinds.

compiler/module_import.m:
	New module in the parse_tree package. It contains the module_imports
	type and its access predicates, and the predicates that compute
	various sorts of direct dependencies (those caused by imports)
	between modules.

compiler/deps_map.m:
	New module in the parse_tree package. It contains the data structure
	for recording indirect dependencies between modules, and the predicates
	for creating it.

compiler/read_module.m:
	New module in the parse_tree package. Its job is reading in modules,
	both human-written and machine-written (such as interface and
	optimization files).

compiler/write_deps_file.m:
	New module in the parse_tree package. Its job is writing out
	makefile fragments.

compiler/libs.m:
compiler/parse_tree.m:
	Include the new modules.

compiler/notes/compiler_design.m:
	Document the new modules.

mdbcomp/prim_data.m:
compiler/prog_util.m:
	Move the predicates that operate on nothing but sym_names from
	prog_util to prim_data.

	Move get_ancestors from modules to prim_data.

compiler/prog_item.m:
	Move stuff that looks for foreign code in a list of items here from
	modules.m.

compiler/source_file_map.m:
	Note why this module needs to be in the parse_tree package.

compiler/add_pred.m:
compiler/add_special_pred.m:
compiler/analysis.file.m:
compiler/analysis.m:
compiler/assertion.m:
compiler/check_typeclass.m:
compiler/compile_target_code.m:
compiler/cse_detection.m:
compiler/det_analysis.m:
compiler/elds_to_erlang.m:
compiler/exception_analysis.m:
compiler/export.m:
compiler/fact_table.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/hlds_pred.m:
compiler/intermod.m:
compiler/llds_out.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_passes.m:
compiler/maybe_mlds_to_gcc.pp:
compiler/mercury_compile.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/optimize.m:
compiler/passes_aux.m:
compiler/proc_gen.m:
compiler/prog_foreign.m:
compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/prog_mutable.m:
compiler/prog_out.m:
compiler/pseudo_type_info.m:
compiler/purity.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/simplify.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.direct.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/term_constr_main.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/trans_opt.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_info.m:
compiler/unify_proc.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
	Minor changes to conform to the changes above.
2008-07-21 03:10:29 +00:00
Zoltan Somogyi
672f77c4ec Add a new compiler option. --inform-ite-instead-of-switch.
Estimated hours taken: 20
Branches: main

Add a new compiler option. --inform-ite-instead-of-switch. If this is enabled,
the compiler will generate informational messages about if-then-elses that
it thinks should be converted to switches for the sake of program reliability.

Act on the output generated by this option.

compiler/simplify.m:
	Implement the new option.

	Fix an old bug that could cause us to generate warnings about code
	that was OK in one duplicated copy but not in another (where a switch
	arm's code is duplicated due to the case being selected for more than
	one cons_id).

compiler/options.m:
	Add the new option.

	Add a way to test for the bug fix in simplify.

doc/user_guide.texi:
	Document the new option.

NEWS:
	Mention the new option.

library/*.m:
mdbcomp/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
	Convert if-then-elses to switches at most of the sites suggested by the
	new option. At the remaining sites, switching to switches would have
	nontrivial downsides. This typically happens with the switched-on type
	has many functors, and we treat one or two specially (e.g. cons/2 in
	the cons_id type).

	Perform misc cleanups in the vicinity of the if-then-else to switch
	conversions.

	In a few cases, improve the error messages generated.

compiler/accumulator.m:
compiler/hlds_goal.m:
	(Rename and) move insts for particular kinds of goal from
	accumulator.m to hlds_goal.m, to allow them to be used in other
	modules. Using these insts allowed us to eliminate some if-then-elses
	entirely.

compiler/exprn_aux.m:
	Instead of fixing some if-then-elses, delete the predicates containing
	them, since they aren't used, and (as pointed out by the new option)
	would need considerable other fixing if they were ever needed again.

compiler/lp_rational.m:
	Add prefixes to the names of the function symbols on some types,
	since without those prefixes, it was hard to figure out what type
	the switch corresponding to an old if-then-else was switching on.

tests/invalid/reserve_tag.err_exp:
	Expect a new, improved error message.
2007-11-23 07:36:01 +00:00
Zoltan Somogyi
07b216c4fb Treat trace goals as quantifying the variables that occur in their io() and/or
Estimated hours taken: 2
Branches: main

Treat trace goals as quantifying the variables that occur in their io() and/or
state() components.

compiler/hlds_goal.m:
	Extend trace scopes with a field for recording the set of quantified
	variables.

compiler/add_clause.m:
	Record the list of quantified variables.

compiler/quantification.m:
	Treat the list of quantified variables as for other scopes.

compiler/hlds_out.m:
	Write out the new field.

compiler/mercury_to_mercury.m:
	Reorder the arguments of some predicates to make them easier to curry,
	e.g. for the new code in hlds_out.m.

	Rename some predicates to avoid ambiguities.

compiler/*.m:
	Conform to the changes in hlds_goal.m and/or mercury_to_mercury.m.

tests/hard_coded/trace_goal_3.{m,exp}:
	New test case to test the new functionality.

tests/hard_coded/Mmakefile:
	Enable the new test case.
2006-11-06 07:55:14 +00:00
Peter Ross
84ffc0924d Fix --warn-unused-imports warnings in some of the modules.
Estimated hours taken: 4
Branches: main

library/*.m:
compiler/*.m:
	Fix --warn-unused-imports warnings in some of the modules.
2006-09-27 06:17:09 +00:00
Julien Fischer
aeeedd2c13 Standardize formatting of comments at the beginning of modules.
compiler/*.m:
	Standardize formatting of comments at the beginning of modules.
2006-07-31 08:32:11 +00:00
Julien Fischer
459847a064 Move the univ, maybe, pair and unit types from std_util into their own
Estimated hours taken: 18
Branches: main

Move the univ, maybe, pair and unit types from std_util into their own
modules.  std_util still contains the general purpose higher-order programming
constructs.

library/std_util.m:
	Move univ, maybe, pair and unit (plus any other related types
	and procedures) into their own modules.

library/maybe.m:
	New module.  This contains the maybe and maybe_error types and
	the associated procedures.

library/pair.m:
	New module.  This contains the pair type and associated procedures.

library/unit.m:
	New module. This contains the types unit/0 and unit/1.

library/univ.m:
	New module. This contains the univ type and associated procedures.

library/library.m:
	Add the new modules.

library/private_builtin.m:
	Update the declaration of the type_ctor_info struct for univ.

runtime/mercury.h:
	Update the declaration for the type_ctor_info struct for univ.

runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
	Update the definition of MR_Univ.

runtime/mercury_init.h:
	Fix a comment: ML_type_name is now exported from type_desc.m.

compiler/mlds_to_il.m:
	Update the the name of the module that defines univs (which are
	handled specially by the il code generator.)

library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
	Conform to the above changes.  Import the new modules where they
	are needed; don't import std_util where it isn't needed.

	Fix formatting in lots of modules.  Delete duplicate module
	imports.

tests/*:
	Update the test suite to confrom to the above changes.
2006-03-29 08:09:58 +00:00
Zoltan Somogyi
a9a2825ace Replace __ with . as the module qualifier everywhere in all the modules
Estimated hours taken: 0.5
Branches: main

profiler/*.m:
deep_profiler/*.m:
compiler/*.m:
	Replace __ with . as the module qualifier everywhere in all the modules
	of the profiler and deep profiler and in some modules of the compiler.
2006-03-09 04:56:47 +00:00
Zoltan Somogyi
f9fe8dcf61 Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 8
Branches: main

Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.

The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.

compiler/det_analysis.m:
	Keep track of goals to the right of the current goal that could fail,
	and include them in the error representation if required.

compiler/det_report.m:
	Include the list of failing goals to the right in the representations
	of determinism errors involving committed committed choice goals.

	Convert the last part of this module that wasn't using error_util
	to use error_util. Make most parts of this module just construct
	error message specifications; print those specifications (using
	error_util) in only a few places.

compiler/hlds_out.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
compiler/compiler_util.m:
	Error_util is still changing reasonably often, and yet it is
	included in lots of modules, most of which need only a few simple
	non-parse-tree-related predicates from it (e.g. unexpected).
	Move those predicates to a new module, compiler_util.m. This also
	eliminates some undesirable dependencies from libs to parse_tree.

compiler/libs.m:
	Include compiler_util.m.

compiler/notes/compiler_design.html:
	Document compiler_util.m, and fix the documentation of some other
	modules.

compiler/*.m:
	Import compiler_util instead of or in addition to error_util.
	To make this easier, consistently use . instead of __ for module
	qualifying module names.

tests/invalid/det_errors_cc.{m,err_exp}:
	Add this new test case to test the error messages for cc contexts.

tests/invalid/det_errors_deet.{m,err_exp}:
	Add this new test case to test the error messages for unifications
	inside function symbols.

tests/invalid/Mmakefile:
	Add the new test cases.

tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
	Change the expected output to conform to the change in det_report.m,
	which is now more consistent.
2005-10-28 02:11:03 +00:00
Zoltan Somogyi
b2012c0c0e Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
Estimated hours taken: 8
Branches: main

compiler/*.m:
	Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
	and 'mer_mode'. This is to avoid the need to parenthesize these type
	names in some contexts, and to prepare for the possibility of a parser
	that considers those words to be reserved words.

	Rename some other uses of those names (e.g. as item types in
	recompilation.m).

	Delete some redundant synonyms (prog_type, mercury_type) for mer_type.

	Change some type names (e.g. mlds__type) and predicate names (e.g.
	deforest__goal) to make them unique even without module qualification.

	Rename the function symbols (e.g. pure, &) that need to be renamed
	to avoid the need to parenthesize them. Make their replacement names
	more expressive.

	Convert some more modules to four space indentation.

	Avoid excessively long lines, such as those resulting from the
	automatic substitution of 'mer_type' for 'type'.
2005-10-24 04:14:34 +00:00
Zoltan Somogyi
2f06c5b8fe Don't just detect when successive unifications unify the same variable with
Estimated hours taken: 6
Branches: main

Don't just detect when successive unifications unify the same variable with
incompatible function symbols: also issue a warning.

compiler/ml_code_gen.m:
compiler/stratify.m:
compiler/table_gen.m:
mdbcomp/trace_counts.m:
	Fix pieces of code that get the new warning.

compiler/modecheck_unify.m:
	When detecting such unifications, add warnings for them, except if
	the initial inst of the current restricts the set of allowed bindings
	of the input arguments. If the initial inst of X is bound(f), then
	an otherwise correct unification Y = g may fail if Y has been computed
	from X. (We don't whether it has, so we have to be conservative.)
	There are examples of such code in the library, e.g. functor in
	deconstruct.m.

	Factor out some common code.

compiler/mode_errors.m:
	Add the infrastructure needed for printing warnings, and the two forms
	of this warning in particular.

compiler/mode_info.m:
	Extend the mode_info structure to make room for warnings, and for the
	initial inst of the procedure arguments.

	Switch to four-space indentation.

compiler/inst_util.m:
	Add a predicate that tests whether an inst may restrict the set of
	possible cons_ids a variable may be bound to.

	Change the argument order of some predicates to allow them to be
	used in higher order code. We don't need to make the switched-on
	argument the first argument anymore.

	Switch to four-space indentation.

compiler/hlds_goal.m:
	Change the argument order of some predicates to allow the use of state
	variables.

compiler/higher_order.m:
compiler/instmap.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/mode_ordering.m:
compiler/modecheck_call.m:
compiler/trace.m:
	Conform to the changed argument orders described above.

	Switch to four-space indentation.

compiler/common.m:
compiler/inst_match.m:
compiler/hlds_pred.m:
compiler/lambda.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/modes.m:
compiler/pd_util.m:
compiler/post_typecheck.m:
compiler/unique_modes.m:
	Conform to the changed argument orders described above.

tests/invalid/occurs.err_exp:
	Expect the extra warning.

tests/warnings/Mmakefile:
	Enable the unify_f_g test case I accidentally committed earlier.

tests/warnings/unify_f_g.{m,err_exp}:
	Finalize that test case.

tests/warnings/simple_code.err_exp:
	Expect the extra warning.
2005-08-27 09:42:10 +00:00
Zoltan Somogyi
8b8b3b7d3f Replace the some() HLDS goal with a more general scope() goal, which can be
Estimated hours taken: 12
Branches: main

Replace the some() HLDS goal with a more general scope() goal, which can be
used not just for existential quantification but also for other purposes.

The main such purposes are new goal types that allow the programmer
to annotate arbitrary goals, and not just whole procedure bodies, with the
equivalents of promise_pure/promise_semipure and promise_only_solution:

	promise_pure ( <impure/semipure goal> )
	promise_semipure ( <impure goal> )

	promise_equivalent_solutions [OutVar1, OutVar2] (
		<cc_multi/cc_nondet goal that computed OutVar1 & OutVar2>
	)

Both are intended to be helpful in writing constraint solvers, as well as in
other situations.

doc/reference_manual.texi:
	Document the new constructs.

library/ops.m:
	Add the keywords of the new constructs to the list of operators.
	Since they work similarly to the "some" operator, they have the same
	precedence.

compiler/hlds_goal.m:
	Replace the some(Vars, SubGoal) HLDS construct, with its optional
	keep_this_commit attribute, with the new scope(Reason, SubGoal)
	construct. The Reason argument may say that this scope is an
	existential quantification, but it can also say that it represents
	a purity promise, the introduction of a single-solution context
	with promise_equivalent_solutions, or a decision by a compiler pass.

	It can also say that the scope represents a set of goals that all arise
	from the unraveling of a unification between a variable and a ground
	term. This was intended to speed up mode checking by significantly
	reducing the number of delays and wakeups, but the cost of the scopes
	themselves turned out to be bigger than the gain in modechecking speed.

	Update the goal_path_step type to refer to scope goals instead of just
	existential quantification.

compiler/prog_data.m:
	Add new function symbols to the type we use to represent goals in items
	to stand for the new Mercury constructs.

compiler/prog_io_goal.m:
	Add code to read in the new language constructs.

compiler/prog_io_util.m:
	Add a utility predicate for use by the new code in prog_io_goal.m.

compiler/make_hlds.m:
	Convert the item representation of the new constructs to the HLDS
	representation.

	Document how the from_ground_term scope reason would work, but do not
	enable the code.

compiler/purity.m:
	When checking the purity of goals, respect the new promise_pure and
	promise_semipure scopes. Generate warnings if such scopes are
	redundant.

compiler/det_analysis.m:
	Make the insides of promise_equivalent_solutions goals single solution
	contexts.

compiler/det_report.m:
	Provide mechanisms for reporting inappropriate usage of
	promise_equivalent_solutions goals.

compiler/instmap.m:
	Add a utility predicate for use by one of the modules above.

compiler/deep_profiling.m:
	Use one of the new scope reasons to prevent simplify from optimizing
	away commits of goals that have been made impure, instead of the old
	keep_this_commit goal feature.

compiler/modes.m:
	Handle from_ground_term scopes when present; for now, they won't be
	present, since make_hlds isn't creating them.

compiler/options.m:
	Add two new compiler options, for use by implementors only, to allow
	finer control over the amount of output one gets with --debug-modes.
	(I used them when debugging the performance of the from_ground_term
	scope reason.) The options are --debug-modes-minimal and
	--debug-modes-verbose.

compiler/handle_options.m:
	Make the options that are meaningful only in the presence of
	--debug-modes imply --debug-modes, since this allows more convenient
	(shorter) invocations.

compiler/mode_debug.m:
	Respect the new options when deciding how much data to print
	when debugging of the mode checking process is enabled.

compiler/switch_detect.m:
	Rename a predicate to make it differ from another predicate by more
	than just its arity.

compiler/passes_aux.m:
	Bring this module up to date with our current style guidelines,
	by using state variable syntax where appropriate.

compiler/*.m:
	Minor changes to conform to the change in the HLDS and/or parse tree
	goal type.

mdbcomp/program_representation.m:
	Rename the some goal to the scope goal, and the same for path steps,
	to keep them in sync with the HLDS.

browser/declarative_tree.m:
	Conform to the change in goal representations.

tests/hard_coded/promise_equivalent_solutions_test.{m,exp}:
	A new test case to test the handling of the
	promise_equivalent_solutions construct.

tests/hard_coded/Mmakefile:
	Enable the new test.

tests/hard_coded/purity/promise_pure_test.{m,exp}:
	A new test case to test the handling of the promise_pure and
	promise_semipure constructs.

tests/hard_coded/purity/Mmakefile:
	Enable the new test.

tests/invalid/promise_equivalent_solutions.{m,err_exp}:
	A new test case to test the error messages for improper use of the
	promise_pure and promise_semipure constructs.

tests/invalid/Mmakefile:
	Enable the new test.
2005-03-24 05:34:41 +00:00
Zoltan Somogyi
3c60c0e485 Change a bunch of modules to import only one module per line, even
Estimated hours taken: 4
Branches: main

compiler/*.m:
	Change a bunch of modules to import only one module per line, even
	from the library.

compiler/mlds_to_il.m:
compiler/mlds_to_managed.m:
	Convert these modules to our current coding style. Use state variables
	where appropriate. Use predmode declarations where possible.
2005-03-22 06:40:32 +00:00
Zoltan Somogyi
4969c4d2e1 Streamline the facilities for debugging of the modechecking proces,
Estimated hours taken: 2
Branches: main

compiler/mode_debug.m:
	Streamline the facilities for debugging of the modechecking proces,
	to provide some hope of them being applicable to the debugging of
	performance problems that arise when modechecking large procedures.

	Do not print the list of variables whose instantiation state is
	unchanged unless asked to do so via the new option
	--debug-modes-verbose.

	Look up option values at fewer points.

	Allow the dumping of traces for the mode checking of a selected
	predicate only, via the new options --debug-modes-pred-id.

compiler/mode_info.m:
	Make the data structure we use to record the instmap at the last
	checkpoint be the instmap, which is searchable in log-n time,
	instead of an assoc list, which is searchable only in linear time.
	When N is the tens of thousands, this matters a lot.

	Extend the data structure to store the results of option lookups.
	Compensate for this by moving the rarely used parts of mode_info
	into a separate, rarely updated data structure.

compiler/handle_options.m:
	Make the two new options imply the old --debug-modes.

compiler/options.m:
doc/user_guide.texi:
	Handle and document the two new options.
2005-02-24 00:35:28 +00:00
Zoltan Somogyi
20cd51e70a This is a cleanup diff; there are no changes in algorithms.
Estimated hours taken: 8
Branches: main

This is a cleanup diff; there are no changes in algorithms.

compiler/delay_info.m:
compiler/instmap.m:
compiler/inst_match.m:
compiler/inst_util.m:
compiler/make.module_target.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/mode_util.m:
compiler/process_util.m:
compiler/prog_io_goal.m:
compiler/prog_io.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
compiler/recompilation.check.m:
compiler/recompilation.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/unique_modes.m:
	Bring these modules up to date with our current style guidelines.
	Switch to predmode syntax and state variable notation where
	appropriate. Switch argument orders where this makes it possible
	to use state variable notation. Use the svmap and svset modules
	where appropriate. Fix inconsistent indentation; in some places,
	fix inconsistent placement of comments.

compiler/passes_aux.m:
compiler/modecheck_unify.m:
compiler/mercury_compile.m:
compiler/post_typecheck.m:
compiler/prog_io_dcg.m:
compiler/mode_ordering.m:
compiler/inst_graph.m:
compiler/polymorphism.m:
compiler/prog_io_util.m:
compiler/mode_debug.m:
compiler/mode_robdd.check.m:
compiler/transform.m:
	Minor changes to conform to the changed argument orders of some
	predicates in the cleaned up modules. Also, some minor cleanups.
2004-12-23 06:49:21 +00:00
Zoltan Somogyi
885fd4a387 Remove almost all dependencies by the modules of parse_tree.m on the modules
Estimated hours taken: 12
Branches: main

Remove almost all dependencies by the modules of parse_tree.m on the modules
of hlds.m. The only such dependencies remaining now are on type_util.m.

compiler/hlds_data.m:
compiler/prog_data.m:
	Move the cons_id type from hlds_data to prog_data, since several parts
	of the parse tree data structure depend on it (particularly insts).
	Remove the need to import HLDS modules in prog_data.m by making the
	cons_ids that refer to procedure ids refer to them via a new type
	that contains shrouded pred_ids and proc_ids. Since pred_ids and
	proc_ids are abstract types in hlds_data, add predicates to hlds_data
	to shroud and unshroud them.

	Also move some other types, e.g. mode_id and class_id, from hlds_data
	to prog_data.

compiler/hlds_data.m:
compiler/prog_util.m:
	Move predicates for manipulating cons_ids from hlds_data to prog_util.

compiler/inst.m:
compiler/prog_data.m:
	Move the contents of inst.m to prog_data.m, since that is where it
	belongs, and since doing so eliminates a circular dependency.
	The separation doesn't serve any purpose any more, since we don't
	need to import hlds_data.m anymore to get access to the cons_id type.

compiler/mode_util.m:
compiler/prog_mode.m:
compiler/parse_tree.m:
	Move the predicates in mode_util that don't depend on the HLDS to a new
	module prog_mode, which is part of parse_tree.m.

compiler/notes/compiler_design.m:
	Mention prog_mode.m, and delete the mention of inst.m.

compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
	Move the predicates that depend on HLDS out of mercury_to_mercury.m
	to hlds_out.m. Export from mercury_to_mercury.m the predicates needed
	by the moved predicates.

compiler/hlds_out.m:
compiler/prog_out.m:
	Move predicates for printing parts of the parse tree out of hlds_out.m
	to prog_out.m, since mercury_to_mercury.m needs to use them.

compiler/purity.m:
compiler/prog_out.m:
	Move predicates for printing purities from purity.m, which is part
	of check_hlds.m, to prog_out.m, since mercury_to_mercury.m needs to use
	them.

compiler/passes_aux.m:
compiler/prog_out.m:
	Move some utility predicates (e.g. for printing progress messages) from
	passes_aux.m to prog_out.m, since some predicates in submodules of
	parse_tree.m need to use them.

compiler/foreign.m:
compiler/prog_data.m:
	Move some types from foreign.m to prog_data.m to allow the elimination
	of some dependencies on foreign.m from submodules of parse_tree.m.

compiler/*.m:
	Conform to the changes above, mostly by updating lists of imported
	modules and module qualifications. In some cases, also do some local
	cleanups such as converting predicate declarations to predmode syntax
	and fixing white space.
2004-06-14 04:17:03 +00:00
Zoltan Somogyi
9c9c610f5a This diff changes modes.m, unique_modes.m and mode_info.m to make them easier
Estimated hours taken: 6
Branches: main

This diff changes modes.m, unique_modes.m and mode_info.m to make them easier
to read and to maintain, but contains no changes in algorithms whatsoever.

compiler/modes.m:
compiler/unique_modes.m:
compiler/mode_info.m:
	Convert these modules to our current coding standards. Use state
	variable notation when appropriate, reordering arguments as necessary.
	Delete predicates whose only purpose was to ease programming with DCGs.

	Remove the IO state from the mode_info structure, and pass it
	separately to the (relatively few) predicates that need it. This
	avoids using complicated (and as yet unsupported) modes or lying
	to the compiler (we used to do the latter), and we are no longer
	forced into that choice by being limited to a single hidden (DCG)
	variable.

	Use more expressive variable names and factor out code as appropriate.

compiler/*.m:
	Conform to the changes in the above two modules.
2003-11-06 03:42:36 +00:00
Zoltan Somogyi
9551640f55 Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Import only one compiler module per line. Sort the blocks of imports.
	This makes it easier to merge in changes.

	In a couple of places, remove unnecessary imports.
2003-03-15 03:09:14 +00:00
Fergus Henderson
7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
	New files.  One module for each of the major components of the
	Mercury compiler.  These modules contain (as separate sub-modules)
	all the other modules in the Mercury compiler, except gcc.m and
	mlds_to_gcc.m.

Mmakefile:
compiler/Mmakefile:
	Handle the fact that the top-level module is now `top_level',
	not `mercury_compile' (since `mercury_compile' is a sub-module
	of `top_level').

compiler/Mmakefile:
	Update settings of *FLAGS-<modulename> to use the appropriate
	nested module names.

compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
	Convert the `recompilation_*' modules into sub-modules of the
	`recompilation' module.

compiler/*.m:
compiler/*.pp:
	Module-qualify the module names in `:- module', `:- import_module',
	and `:- use_module' declarations.

compiler/base_type_info.m:
compiler/base_type_layout.m:
	Deleted these unused empty modules.

compiler/prog_data.m:
compiler/globals.m:
	Move the `foreign_language' type from prog_data to globals.

compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
	Import `globals', for `foreign_language'.

Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
	Rename the %.check.c targets as %.check_hdr.c,
	to avoid conflicts with compiler/recompilation.check.c.
2002-03-20 12:37:56 +00:00
Simon Taylor
5277d159cb Use the globals stored in the module_info rather than in the
Estimated hours taken: 0.1

compiler/mode_debug.m:
compiler/typecheck.m
	Use the globals stored in the module_info rather than in the
	io__state to look up the --debug-modes or --debug-types options.
	This saves memory by avoiding updating the io__state in the
	mode_info or typecheck_info.
2000-11-15 00:47:59 +00:00
Thomas Conway
5c955626f2 These changes make var' and term' polymorphic.
Estimated hours taken: 20

These changes make `var' and `term' polymorphic. This allows us to make
variables and terms representing types of a different type to those
representing program terms and those representing insts.

These changes do not *fix* any existing problems (for instance
there was a messy conflation of program variables and inst variables,
and where necessary I've just called varset__init(InstVarSet) with
an XXX comment).

NEWS:
	Mention the changes to the standard library.

library/term.m:
	Make term, var and var_supply polymorphic.
	Add new predicates:
		term__generic_term/1
		term__coerce/2
		term__coerce_var/2
		term__coerce_var_supply/2

library/varset.m:
	Make varset polymorphic.
	Add the new predicate:
		varset__coerce/2

compiler/prog_data.m:
	Introduce type equivalences for the different kinds of
	vars, terms, and varsets that we use (tvar and tvarset
	were already there but have been changed to use the
	polymorphic var and term).

	Also change the various kinds of items to use the appropriate
	kinds of var/varset.

compiler/*.m:
	Thousands of boring changes to make the compiler type correct
	with the different types for type, program and inst vars and
	varsets.
1998-11-20 04:10:36 +00:00
Fergus Henderson
73131e8df3 Undo Zoltan's bogus update of all the copyright dates.
Estimated hours taken: 0.75

library/*.m:
compiler/*.m:
	Undo Zoltan's bogus update of all the copyright dates.
	The dates in the copyright header should reflect the years
	in which the file was modified (and no, changes to the
	copyright header itself don't count as modifications).
1998-01-23 12:57:08 +00:00
Zoltan Somogyi
bb4442ddc1 Update copyright dates for 1998.
Estimated hours taken: 0.5

compiler/*.m:
	Update copyright dates for 1998.
1998-01-13 10:06:08 +00:00
Fergus Henderson
04b720630b Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne".
1997-07-27 15:09:59 +00:00
Andrew Bromage
9b7f11c6dd Reorganisation of modules to do with the inst data type.
Estimated hours taken: 20

Reorganisation of modules to do with the inst data type.

This is actually the first installment of the alias tracking mode
checker in disguise.  A very good disguise.  The rationale for
this reorganisation is to reduce coupling in the part of the mode
checker which is _not_ in this change (ie most of it).

Alias tracking requires a new kind of inst, alias(inst_key), where
an inst_key is a handle on some other sub-inst.  With it goes a
data structure in which to store dereferenced insts and all the
operations which go with it.  This code will go in the new module
inst.m so that it doesn't have to go in prog_data.m.  (I briefly
considered putting it in instmap.m however this introduces some
bad coupling since instmap.m imports hlds_module.m.  Putting it
in prog_data.m would cause hlds_*.m to depend on prog_data.m,
but we have designed things so that the dependencies go in the
other direction.)

The remainder of the reorganisation is a general cleanup: the
inst testing predicates (inst_is_*) have been moved out of
mode_util because they are not actually operations on modes at
all, and have been moved into inst_match.  inst_match has then
been split because otherwise it would be 2000 lines long and
will get significantly bigger when aliasing is added.  Roughly
speaking, any operations which create new insts from old ones
have been moved into a new module, inst_util while any operations
which test the values of insts remain in inst_match.

Also included are the removal of some NU-Prologisms since the
NU-Prolog version of the compiler is no longer supported.  Two
changes here:

	- Removal of some when declarations.
	- A gross hack in inst_is_*_2, where two copies of
	  the same inst were passed into the predicate so that
	  one could be switched on.  Thank NU-Prolog's lack of
	  common subexpression elimination.

compiler/inst.m:
	New module which contains the data types inst, uniqueness,
	pred_inst_info, bound_inst.

compiler/inst_util.m:
	New module which contains predicates which perform mode
	checking-like operations on insts.

	Moved in:
		abstractly_unify_inst, abstractly_unify_inst_functor,
		inst_merge, make_mostly_uniq_inst (from inst_match.m)

compiler/inst_match.m:
	Moved out:
		inst_merge, make_mostly_uniq_inst,
		abstractly_unify_inst, abstractly_unify_inst_functor
			(to inst_util.m)

	Moved in:
		inst_is_*, inst_list_is_*, bound_inst_list_is_*
			(from mode_util.m)

	Now exported:
		unique_matches_initial/2, unique_matches_final/2
		inst_contains_instname/3, pred_inst_matches/3
		(They are required by inst_util.m, and they are
		useful in their own right.)

compiler/instmap.m:
	instmap_delta_lookup_var/3 reincarnated as
	instmap_delta_search_var/3.  The reason for this change is
	that previously, instmap_delta_lookup_var simply returned
	`free' if the searched-for var did not occur in the
	instmap_delta.  This is somewhat non-obvious behaviour.
	instmap_delta_search_var/3 fails in such a situation.

compiler/mode_util.m:
	Moved out:
		inst_is_*, inst_list_is_*, bound_inst_list_is_*
			(to inst_match.m)
		(These are not really operations on modes.)

compiler/modecheck_call.m:
	Moved in modecheck_higher_order_func_call/5, from modecheck_unify.m

compiler/modecheck_unify.m:
	Moved out modecheck_higher_order_func_call/5, to modecheck_call.m
	where it should have been all along.

compiler/prog_data.m:
	Moved out the types inst, uniqueness, pred_inst_info,
	bound_inst (to inst.m).

compiler/common.m:
compiler/cse_detection.m:
compiler/fact_table.m:
compiler/higher_order.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/liveness.m:
compiler/llds.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/polymorphism.m:
compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/prog_util.m:
compiler/simplify.m:
compiler/switch_detection.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
	Miscellaneous minor changes to cope with the above changes.

compiler/notes/compiler_design.html:
	Document the new modules.
1997-07-24 01:27:21 +00:00
Simon Taylor
27d156bbb5 Implemented a :- use_module directive. This is the same as
Estimated hours taken: 14

Implemented a :- use_module directive. This is the same as
:- import_module, except all uses of the imported items
must be explicitly module qualified.

:- use_module is implemented by ensuring that unqualified versions
of items only get added to the HLDS symbol tables if they were imported
using import_module.

Indirectly imported items (from `.int2' files) and items declared in `.opt'
files are treated as if they were imported with use_module, since all uses
of them should be module qualified.

compiler/module_qual.m
	Keep two sets of type, mode and inst ids, those which can
	be used without qualifiers and those which can't.

	Renamed some predicates which no longer have unique names since
	'__' became a synonym for ':'.

	Made mq_info_set_module_used check whether the current item is in
	the interface, rather than relying on its caller to do the check.

	Removed init_mq_info_module, since make_hlds.m now uses the
	mq_info built during the module qualification pass.

compiler/prog_data.m
	Added a pseudo-declaration `used', same as `imported' except uses of
	the following items must be module qualified.

	Added a type need_qualifier to describe whether uses of an item
	need to be module qualified.

compiler/make_hlds.m
	Keep with the import_status whether current item was imported
	using a :- use_module directive.

	Use the mq_info structure passed in instead of building a new one.

	Ensure unqualified versions of constructors only get added to the
	cons_table if they can be used without qualification.

compiler/hlds_module.m
	Added an extra argument to predicate_table_insert of type
	need_qualifier.

	Only add predicates to the name and name-arity indices if they
	can be used without qualifiers.

	Changed the structure of the module-name-arity index, so that
	lookups can be made without an arity, such as when type-checking
	module qualified higher-order predicate constants. This does not
	change the interface to the module_name_arity index.

	Factored out some common code in predicate_table_insert which
	applies to both predicates and functions.

compiler/hlds_pred.m
	Removed the opt_decl import_status. It isn't needed any more
	since all uses of items declared in .opt files must now be
	module qualified.

	Added some documentation about when the clauses_info is valid.

compiler/intermod.m
	Ensure that predicate and function calls in the `.opt' file are
	module qualified. Use use_module instead of import_module in
	`.opt' files.

compiler/modules.m
	Handle use_module directives.

	Report a warning if both use_module and import_module declarations
	exist for the same module.

compiler/mercury_compile.m
	Collect inter-module optimization information before module
	qualification, since it can't cause conflicts any more. This means
	that the mq_info structure built in module_qual.m can be reused in
	make_hlds.m, instead of building a new one.

compiler/prog_out.m
	Add a predicate prog_out__write_module_list, which was moved
	here from module_qual.m.

compiler/typecheck.m
	Removed code to check that predicates declared in `.opt' files
	were being used appropriately, since this is now handled by
	use_module.

compiler/*.m
	Added missing imports, mostly for prog_data and term.

NEWS
compiler/notes/todo.html
doc/reference_manual.texi
	Document `:- use_module'.

tests/valid/intermod_lambda_test.m
tests/valid/intermod_lambda_test2.m
tests/invalid/errors.m
tests/invalid/errors2.m
	Test cases.
1997-06-29 23:11:42 +00:00
Tyson Dowd
cbcb23d17b Enable --warn-interface-imports by default.
Estimated hours taken: 3

Enable --warn-interface-imports by default. This was turned off while
list and term were defined in mercury_builtin.m, since it caused many
warnings.

Fix all the unused interface imports that have been added since then.

compiler/options.m:
	Enable --warn-interface-imports by default.

compiler/module_qual.m:
	Fix formatting inconsistencies with module names in warning
	messages. (".m" was not appended to module names if there was
	only one module).

compiler/*.m:
library/*.m:
tests/invalid/type_loop.m:
tests/warnings/*.m:
	Remove usused interface imports, or move them into
	implementation (mostly bool, list and std_util).
1997-05-21 02:16:53 +00:00
Tyson Dowd
327a5131e2 Remove support for term_to_type and type_to_term implemented as special
Estimated hours taken: 5

Remove support for term_to_type and type_to_term implemented as special
preds.  Remove support for one-cell and one-or-two-cell type_infos (now
shared-one-or-two-cell type_infos). Move definitions that were in
mercury_builtin.m back to where they belong.

This code has been removed because it is no longer used, and was no
longer being maintained but was still quite complex.

compiler/globals.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/options.m:
	Remove one_cell and one_or_two_cell from type_info methods.

compiler/polymorphism.m:
	Remove term_to_type and type_to_term support.
	Remove one_cell and one_or_two_cell from type_info methods.
	Fix documentation to reflect the new situation.

compiler/special_pred.m:
compiler/unify_proc.m:
	Remove term_to_type and type_to_term support.

library/list.m:
	Put the definition of `list' back into list.m

library/mercury_builtin.m:
	Take the definitions of `list', `term', `var', `var__supply',
	etc, out of this module.
	Remove type_to_term, term_to_type, det_term_to_type,
	term__init_var_supply, term__create_var, term__var_to_int
	and term__context_init.
	Remove references to USE_TYPE_TO_TERM and #ifdefs around
	SHARED_ONE_OR_TWO_CELL_TYPE_INFO.

library/std_util.m:
	Remove references ONE_OR_TWO_CELL_TYPE_INFO, and code that
	handles one-cell typeinfo comparisons.

library/term.m:
	Add type_to_term, term_to_type, det_term_to_type,
	term__init_var_supply, term__create_var, term__var_to_int
	and term__context_init back to term.m.
	Add new implementation of type_to_term/2.

library/uniq_array.m:
	Fix a typo in a comment - term_to_type/3 instead of term_to_type/2.

runtime/call.mod:
	Remove special case code for unify, compare, index for
	one-cell typeinfos.
	Remove code for type_to_term/2.

runtime/type_info.h:
	Remove references to ONE_CELL_TYPE_INFO or ONE_OR_TWO_CELL_TYPE_INFO.
	Make sure only SHARED_ONE_OR_TWO_CELL_TYPE_INFO.
	Remove references to USE_TYPE_TO_TERM.

compiler/base_type_layout.m:
compiler/bytecode_gen.m:
compiler/code_util.m:
compiler/delay_slot.m:
compiler/det_util.m:
compiler/fact_table.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/mode_debug.m:
compiler/tree.m:
library/bag.m:
library/queue.m:
	Import module `list' or `term' (or both).
1997-05-20 01:52:55 +00:00
Zoltan Somogyi
8974c199b3 Add predicates for printing out insts in a structured form.
Estimated hours taken: 1.5

mercury_to_mercury:
	Add predicates for printing out insts in a structured form.
	The resulting printed insts are not fully syntactically valid,
	but they are much better for debugging than the output of the
	existing predicates.

mode_info:
	Add an extra field to the mode_info structure. This field, which
	is set and used only when --debug-modes was given, holds the binding
	of each variable at the last mode checkpoint.

mode_debug:
	At each mode checkpoint, print full insts only for the variables
	whose inst has changed since the last checkpoint. Print these insts
	using the new predicates in mercury_to_mercury.

	This change also introduces tabs in many places in the code
	where the original code used groups of eight spaces.
1997-04-03 01:17:56 +00:00
Zoltan Somogyi
f23324f5fa This change fixes two bugs, in quantification and liveness.
Estimated hours taken: 10

This change fixes two bugs, in quantification and liveness. I made the changes
to the other files while trying to find them; they ought to be useful in
trying to find similar bugs in the future.

The compiler now bootstraps with agressive inlining enabled.

quantification:
	Fix a bug that switched two different accumulators of the same type
	when processing pragma_c_codes.

liveness:
	Fix a bug that could cause a variable to end up in both the post-death
	and post-birth set of the same goal.

options:
	Reenable inlining.

hlds_out, mercury_to_mercury:
	If -D v is given, include the number of each variable at the end of
	its name (e.g. Varname_20).

	The predicates involved (a few from mercury_to_mercury and many from
	hlds_out) now have an extra argument that says whether this should be
	done or not. (It is not done when printing clauses e.g. for .opt
	files.)

	The bug in quantification was causing the improper substitution of
	one variable for another, but both had the same name; such bugs would
	be very difficult to find without this change.

constraint, det_report, intermod, make_hlds, mercury_to_c, mode_debug,
mode_errors, module_qual, typecheck:
	Call predicates in hlds_out or mercury_to_mercury with the extra
	argument.

saved_vars:
	Thread the io__state through this module to allow debugging.

mercury_compile:
	Call saved_vars via its new interface.

	Fix an inadvertent use of an out-of-date ModuleInfo.

goal_util, hlds_goal:
	Minor formatting cleanup.

code_gen:
	Clean up the import sequence.
1996-12-30 11:31:17 +00:00
Andrew Bromage
06e05928e1 Makes instmap and instmap_delta into ADTs.
Estimated hours taken: 38

Makes instmap and instmap_delta into ADTs.

compiler/code_gen.m:
compiler/code_info.m:
compiler/cse_detection.m:
compiler/det_analysis.m:
compiler/dnf.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/lookup_switch.m:
compiler/mode_debug.m:
compiler/mode_info.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/polymorphism.m:
compiler/simplify.m:
compiler/store_alloc.m:
compiler/switch_detection.m:
compiler/transform.m:
compiler/uniq_modes.m:
compiler/unused_args.m:
	Miscellaneous minor changes to use the new instmap.m

compiler/constraint.m:
	Removed unnecessary duplication of code in constraint__checkpoint/4
	and constraint__no_output_vars/2.

compiler/det_util.m:
	Changed no_output_vars/4 to det_no_output_vars/4, moved body
	of code to instmap.m.

compiler/instmap.m:
	Added abstract types instmap/0, instmap_delta/0.

	Added predicates:
		instmap__init_reachable/1, instmap__init_unreachable/1,
		instmap_delta_init_reachable/1,
		instmap_delta_init_unreachable/1, instmap__is_reachable/1,
		instmap__is_unreachable/1, instmap_delta_is_reachable/1,
		instmap_delta_is_unreachable/1, instmap__from_assoc_list/2,
		instmap_delta_from_assoc_list/2, instmap__vars/2,
		instmap__vars_list/2, instmap_delta_changed_vars/2,
		instmap_delta_lookup_var/3, instmap__set/3,
		instmap_delta_insert/4, instmap_delta_apply_instmap_delta/3,
		instmap_delta_restrict/3, instmap_delta_delete_vars/3,
		instmap__no_output_vars/4, instmap_delta_apply_sub/4,
		instmap__to_assoc_list/2, instmap_delta_to_assoc_list/2.

	Renamed predicates:
		instmap__lookup_var/3 (was instmap_lookup_var/3)
		instmap__lookup_vars/3 (was instmap_lookup_vars/3)
		instmap__apply_instmap_delta/3 (was apply_instmap_delta/3)
		instmap__merge/5 (was instmap_merge/5)
		instmap__restrict/3 (was instmap_restrict/3)

	Moved predicates:
		merge_instmap_delta/5 (from mode_util.m)

	Removed predicates:
		instmapping_lookup_var/3

compiler/mode_util.m:
	Moved merge_instmap_delta/5 to instmap.m
1996-11-19 01:18:24 +00:00
Andrew Bromage
5c149e55b2 Mode analyser reorganisation.
Estimated hours taken: 20

Mode analyser reorganisation.

compiler/mode_util.m:
	Removed: instmap_init/1,  apply_instmap_delta/3, instmap_lookup_var/3,
	instmapping_lookup_var/3, instmap_restrict/3, map_restrict/3 (all
	moved to instmap.m).

compiler/hlds_goal.m:
	Removed the declarations of instmap_delta, instmap and instmapping.

compiler/mode_errors.m:
	Added report_mode_errors/2 (was modecheck_report_errors, from
	modes.m).

compiler/modes.m:
	Predicates now exported:
		modecheck_goal/4
		modecheck_goal_expr/5 (previously named modecheck_goal_2/5)
		handle_extra_goals/8
		mode_context_to_unify_context/3

	Moved to mode_errors.m:
		modecheck_report_errors/2

	Moved to instmap.m:
		compute_instmap_delta/4
		instmap_merge/3
		instmap_lookup_vars (was instmap_lookup_arg_list/3)
		compute_instmap_delta/4

	Moved to mode_debug.m:
		Type port/0
		mode_checkpoint/4

	Moved to modecheck_call.m:
		modecheck_call_pred/7
		modecheck_higher_order_call/10
		modecheck_higher_order_pred_call/4
		modecheck_higher_order_func_call/7

	Moved to modecheck_unify.m:
		modecheck_unification/9
		categorize_unify_var_var/12
		categorize_unify_var_functor/11
		categorize_unify_var_lambda/9

	Moved to mode_info.m:
		mode_info_error/4
		mode_info_add_error/3

compiler/code_gen.pp, compiler/code_info.m, compiler/constraint.m,
compiler/cse_detection.m, compiler/det_analysis.m, compiler/det_util.m,
compiler/dnf.m, compiler/goal_util.m, compiler/higher_order.m,
compiler/hlds_out.m, compiler/hlds_pred.m, compiler/live_vars.m,
compiler/liveness.m, compiler/lookup_switch.m, compiler/polymorphism.m,
compiler/simplify.m, compiler/store_alloc.m, compiler/switch_detection.m,
compiler/transform.m, compiler/unused_args.m:
	Imported instmap.m

New files:

compiler/instmap.m:
	Handle operations associated with instmaps.

compiler/modecheck_unify.m:
	Handle mode checking of unifications.

compiler/modecheck_call.m:
	Handle mode checking of calls

compiler/mode_debug.m:
        Code to trace the actions of the mode checker.
1996-10-17 05:28:01 +00:00