Files
mercury/compiler/inst.m
David Overton 82378c381b Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80

Allow polymorphic ground insts.  This change assumes that all inst
parameters in the mode declaration for a predicate or function are
constrained to be ground-shared.  This is a temporary measure until we
work out a nice syntax to allow the programmer to tell the compiler that
certain inst parameters may be treated as ground insts.  Since we don't
currently support unconstrained inst parameters anyway, this shouldn't
cause a problem.

	TODO:
		- Add syntax, something like `:- mode p(in(I)) <= ground(I).',
		  to specify that an inst parameter represents a ground inst.
		- Allow abstract ground insts that are treated in a similar
		  way to what we've done here with ground inst parameters.
		- Make mode checking more efficient (i.e. rewrite the mode
		  system).

compiler/inst.m:
	Add a new alternative for ground insts:
		`constrained_inst_var(inst_var)'.
	Define the type `inst_var_sub'.

compiler/inst_match.m:
	Change inst_matches_initial so that it:
		- handles constrained_inst_vars correctly;
		- returns the inst_var substitutions necessary for the call;
		- handles inst_matches_initial(ground(...), bound(...), ...)
		  properly (this requires knowing the type of the variable).

	  The last change has also been made for inst_matches_final
	  and inst_matches_binding.  However, the check is disabled for
	  now because, without alias tracking, the mode checker
	  becomes too conservative.

compiler/hlds_pred.m:
compiler/mode_info.m:
compiler/simplify.m:
compiler/det_util.m:
	Include the inst_varset in the proc_info, mode_info and simplify_info.
	Add a vartypes field to the det_info.
	Remove the vartypes field from the simplify_info since it is
	now in the det_info.
	Use record syntax for these data structures and their access predicates
	to make future changes easier.

compiler/prog_io.m:
	When processing pred and func mode declarations, convert all inst_var(V)
	insts to ground(shared, constrained_inst_var(V)).

compiler/prog_data.m:
compiler/hlds_data.m:
compiler/make_hlds.m:
compiler/mode_util.m:
	Use inst_vars instead of inst_params.

compiler/modes.m:
compiler/modecheck_call.m:
compiler/unique_modes.m:
compiler/mode_util.m:
	When checking or recomputing initial insts of a call, build up
	an inst_var substitution (using the modified
	inst_matches_initial) and apply this to the final insts of the
	called procedure before checking/recomputing them.

compiler/mode_util.m:
	Make sure that recompute_instmap_delta recomputes the
	instmap_deltas for lambda_goals even when RecomputeAtomic = no.

compiler/type_util.m:
	Add a new predicate, type_util__cons_id_arg_types which
	nondeterministically returns the cons_ids and argument types for a
	given type.
	Add a new predicate type_util__get_consid_non_existential_arg_types
	which is the same as type_util__get_existential_arg_types except
	that it fails rather than aborting for existenially typed arguments.

compiler/accumulator.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/common.m:
compiler/continuation_info.m:
compiler/deforest.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/dnf.m:
compiler/follow_code.m:
compiler/goal_store.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_util.m:
compiler/instmap.m:
compiler/lambda.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/mercury_to_mercury.m:
compiler/modecheck_unify.m:
compiler/module_qual.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_io_util.m:
compiler/prog_rep.m:
compiler/saved_vars.m:
compiler/stack_layout.m:
compiler/table_gen.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Pass inst_varsets and types where needed.
	Changes to reflect change in definition of the inst data type.

compiler/inlining.m:
	Recompute the instmap deltas for a procedure after inlining.
	This bug showed up compiling tests/hard_coded/lp.m with
	inlining and deforestation turned on: deforestation was
	getting incorrect instmap deltas from inlining, causing
	the transformation to break mode-correctness.  It has only
	just shown up because of the added call to
	`inst_matches_initial' from within `recompute_instmap_delta'.

tests/invalid/Mmakefile:
tests/invalid/unbound_inst_var.m:
tests/invalid/unbound_inst_var.err_exp:
tests/valid/Mmakefile:
tests/valid/unbound_inst_var.m:
	Move the `unbound_inst_var' test case from `invalid' to `valid'
	and extend its coverage a bit.
2000-10-13 13:56:17 +00:00

113 lines
3.9 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 1997, 1999-2000 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
%
% inst.m - Contains the (inst) data type.
% Main author: bromage
%
%-----------------------------------------------------------------------------%
:- module (inst).
:- interface.
% This module should NOT import hlds*.m. Any types which are needed in
% both the insts and in the HLDS should be defined here, rather than
% in hlds*.m, because insts are part of the parse tree and the parse tree
% should not depend on the HLDS.
%
% XXX Currently we have to import hlds_data for the `cons_id' type.
% I think the cons_ids in insts only use a subset of the functors
% of the `cons_id' type, and so we could define a new type
% `abstract_cons_id' and use that here instead of `cons_id'.
:- import_module prog_data, hlds_data.
:- import_module list, map.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- type (inst)
---> any(uniqueness)
; free
; free(type)
; bound(uniqueness, list(bound_inst))
% The list(bound_inst) must be sorted
; ground(uniqueness, ground_inst_info)
% The ground_inst_info holds extra information
% about the ground inst.
; not_reached
; inst_var(inst_var)
% A defined_inst is possibly recursive
% inst whose value is stored in the
% inst_table. This is used both for
% user-defined insts and for
% compiler-generated insts.
; defined_inst(inst_name)
% An abstract inst is a defined inst which
% has been declared but not actually been
% defined (yet).
; abstract_inst(sym_name, list(inst)).
:- type uniqueness
---> shared % there might be other references
; unique % there is only one reference
; mostly_unique % there is only one reference
% but there might be more on
% backtracking
; clobbered % this was the only reference, but
% the data has already been reused
; mostly_clobbered.
% this was the only reference, but
% the data has already been reused;
% however, there may be more references
% on backtracking, so we will need to
% restore the old value on backtracking
% The ground_inst_info type gives extra information about ground insts.
:- type ground_inst_info
---> higher_order(pred_inst_info)
% The ground inst is higher-order.
; constrained_inst_var(inst_var)
% The ground inst is an inst variable that is
% constrained to be ground.
; none.
% No extra information is available.
% higher-order predicate terms are given the inst
% `ground(shared, higher_order(PredInstInfo))'
% where the PredInstInfo contains the extra modes and the determinism
% for the predicate. Note that the higher-order predicate term
% itself must be ground.
:- type pred_inst_info
---> pred_inst_info(
pred_or_func, % is this a higher-order func
% mode or a higher-order pred
% mode?
list(mode), % the modes of the additional
% (i.e. not-yet-supplied)
% arguments of the pred;
% for a function, this includes
% the mode of the return value
% as the last element of the
% list.
determinism % the determinism of the
% predicate or function
).
:- type bound_inst ---> functor(cons_id, list(inst)).
:- type inst_var_sub == map(inst_var, inst).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
% Empty for now.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%