mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 14:25:56 +00:00
Estimated hours taken: 32 Branches: main Include the type_ctor in cons_ids for user-defined types. The intention is two-fold: - It prepares for a future in which we allow more than one function symbol to with the same name to be defined in a module. - It makes the HLDS code more self-contained. In many places, processing construction and deconstruction unifications required knowing which type the cons_id belongs to, but until now, code couldn't know that unless it kept track of the type of the variable unified with the cons_id. With this diff, user-defined cons_ids are represented as cons(SymName, Arity, TypeCtor) The last field is filled in during post-typecheck. After that time, any module qualification in the SymName (which may initially be partial) is redundant, since it is also available in the TypeCtor. In the future, we could make all those SymNames be just unqualified(_) at that time. We could also replace the current maps in HLDS type definitions with full cons_id keys with just name/arity keys (since the module qualifier is a given for any given type definition), we could also support partially qualified cons_ids in source code using a map from name/arity pairs to a list of all the type_ctors that have function symbols with that name/arity, instead of our current practice of inserting all possible partially module qualified version of every cons_id into a single giant table, and we could do the same thing with the field names table. This diff also separates tuples out from user-defined types, since in many respects they are different (they don't have a single type_ctor, for starters). It also separates out character constants, since they were alreay treated specially in most places, though not in some places where they *ought* to have been treated specially. Take the opportunity to give some other cons_ids better names. compiler/prog_data.m: Make the change described above, and document it. Put the implementations of the predicates declared in each part of this module next to the declarations, instead of keeping all the code until the very end (where it was usually far from their declarations). Remove three predicates with identical definitions from inst_match.m, inst_util.m and mode_constraints.m, and put the common definition in prog_data.m. library/term_io.m: Add a new predicate that is basically a reversible version of the existing function espaced_char, since the definition of char_consts needs reversibilty. compiler/post_typecheck.m: For functors of user-defined types, record their type_ctor. For tuples and char constants, record them as such. compiler/builtin_lib_types.m: compiler/parse_tree.m: compiler/notes/compiler_design.html: New module to centralize knowledge about builtin types, specially handled library types, and their function symbols. Previously, the stuff now in this module used to be in several different places, including prog_type.m and stm_expand.m, and some of it was duplicated. mdbcomp/prim_data.m: Add some predicates now needed by builtin_lib_types.m. compiler/builtin_ops.m: Factor out some duplicated code. compiler/add_type.m: Include the relevant type_ctors in the cons_ids generated in type definitions. compiler/hlds_data.m: Document an existing type better. Rename a cons_tag in sync with its corresponding cons_id. Put some declarations into logical order. compiler/hlds_out.m: Rename a misleadingly-named predicate. compiler/prog_ctgc.m: compiler/term_constr_build.m: Add XXXs for questionable existing code. compiler/add_clause.m: compiler/add_heap_ops.m: compiler/add_pragma.m: compiler/add_pred.m: compiler/add_trail_ops.m: compiler/assertion.m: compiler/bytecode_gen.m: compiler/closure_analysis.m: compiler/code_info.m: compiler/complexity.m: compiler/ctgc_selector.m: compiler/dead_proc_elim.m: compiler/deep_profiling.m: compiler/delay_partial_inst.m: compiler/dependency_graph.m: compiler/det_analysis.m: compiler/det_report.m: compiler/distance_granularity.m: compiler/erl_rtti.m: compiler/erl_unify_gen.m: compiler/export.m: compiler/field_access.m: compiler/foreign.m: compiler/format_call.m: compiler/hhf.m: compiler/higher_order.m: compiler/hlds_code_util.m: compiler/hlds_desc.m: compiler/hlds_goal.m: compiler/implementation_defined_literals.m: compiler/inst_check.m: compiler/inst_graph.m: compiler/inst_match.m: compiler/inst_util.m: compiler/instmap.m: compiler/intermod.m: compiler/interval.m: compiler/lambda.m: compiler/lco.m: compiler/make_tags.m: compiler/mercury_compile.m: compiler/mercury_to_mercury.m: compiler/middle_rec.m: compiler/ml_closure_gen.m: compiler/ml_code_gen.m: compiler/ml_code_util.m: compiler/ml_switch_gen.m: compiler/ml_type_gen.m: compiler/ml_unify_gen.m: compiler/ml_util.m: compiler/mlds_to_c.m: compiler/mlds_to_java.m: compiler/mode_constraints.m: compiler/mode_errors.m: compiler/mode_ordering.m: compiler/mode_util.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/module_qual.m: compiler/polymorphism.m: compiler/prog_ctgc.m: compiler/prog_event.m: compiler/prog_io_util.m: compiler/prog_mode.m: compiler/prog_mutable.m: compiler/prog_out.m: compiler/prog_type.m: compiler/prog_util.m: compiler/purity.m: compiler/qual_info.m: compiler/rbmm.add_rbmm_goal_infos.m: compiler/rbmm.execution_path.m: compiler/rbmm.points_to_analysis.m: compiler/rbmm.region_transformation.m: compiler/recompilation.usage.m: compiler/rtti.m: compiler/rtti_out.m: compiler/rtti_to_mlds.m: compiler/simplify.m: compiler/simplify.m: compiler/special_pred.m: compiler/ssdebug.m: compiler/stack_opt.m: compiler/stm_expand.m: compiler/stratify.m: compiler/structure_reuse.direct.detect_garbagem: compiler/superhomoegenous.m: compiler/switch_detection.m: compiler/switch_gen.m: compiler/switch_util.m: compiler/table_gen.m: compiler/term_constr_build.m: compiler/term_norm.m: compiler/try_expand.m: compiler/type_constraints.m: compiler/type_ctor_info.m: compiler/type_util.m: compiler/typecheck.m: compiler/typecheck_errors.m: compiler/unify_gen.m: compiler/unify_proc.m: compiler/unify_modes.m: compiler/untupling.m: compiler/unused_imports.m: compiler/xml_documentation.m: Minor changes, mostly to ignore the type_ctor in cons_ids in places where it is not needed, take the type_ctor from the cons_id in places where it is more convenient, conform to the new names of some cons_ids, conform to the changes in hlds_out.m, and/or add now-needed imports of builtin_lib_types.m. In some places, the handling previously applied to cons/2 (which included tuples and character constants as well as user-defined function symbols) is now applied only to user-defined function symbols or to user-defined function symbols and tuples, as appropriate, with character constants being handled more like the other kinds of constants. In inst_match.m, rename a whole bunch of predicates to avoid ambiguities. In prog_util.m, remove two predicates that did almost nothing yet were far too easy to misuse.
479 lines
17 KiB
Mathematica
479 lines
17 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2001-2007, 2009 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.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% File: inst_graph.m.
|
|
% Author: dmo.
|
|
%
|
|
% This module defines operations on instantiation graphs. The purpose of the
|
|
% data structure and of the operations on it are defined in chapter 6 of
|
|
% David Overton's PhD thesis.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module hlds.inst_graph.
|
|
:- interface.
|
|
|
|
:- import_module parse_tree.prog_data.
|
|
|
|
:- import_module io.
|
|
:- import_module list.
|
|
:- import_module map.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- type inst_graph == map(prog_var, node).
|
|
|
|
:- type node
|
|
---> node(
|
|
map(cons_id, list(prog_var)),
|
|
% If the variable that maps to this node occurs on the
|
|
% left hand side of any var-functor unifications,
|
|
% this map gives, for each functor that occurs in such
|
|
% unifications, the identities of the variables
|
|
% chosen by the transformation to hyperhomogeneous form
|
|
% to represent the arguments of that functor inside
|
|
% the cell variable.
|
|
|
|
maybe_parent
|
|
% Specifies whether
|
|
).
|
|
|
|
:- type maybe_parent
|
|
---> top_level
|
|
% The variable in whose node this maybe_parent value occurs
|
|
% doesn't appear on the right hand side of any var-functor
|
|
% unifications.
|
|
|
|
; parent(prog_var).
|
|
% The variable in whose node this maybe_parent value occurs
|
|
% does appear on the right hand side of a var-functor unification:
|
|
% the argument of parent identifies the variable on the left hand
|
|
% side. The definition of hyperhomogeneous form guarantees that
|
|
% this variable is unique.
|
|
|
|
% Initialise an inst_graph. Adds a node for each variable, and
|
|
% initializes each node to have no parents and no children.
|
|
%
|
|
:- pred init(list(prog_var)::in, inst_graph::out) is det.
|
|
|
|
% set_parent(Parent, Child, Graph0, Graph):
|
|
%
|
|
% Sets Parent to be the parent node of Child. Aborts if Child
|
|
% already has a parent.
|
|
%
|
|
:- pred set_parent(prog_var::in, prog_var::in, inst_graph::in, inst_graph::out)
|
|
is det.
|
|
|
|
% top_level_node(InstGraph, VarA, VarB):
|
|
%
|
|
% Succeeds iff VarB is the top_level node reachable from VarA in InstGraph.
|
|
%
|
|
:- pred top_level_node(inst_graph::in, prog_var::in, prog_var::out) is det.
|
|
|
|
% descendant(InstGraph, VarA, VarB):
|
|
%
|
|
% Succeeds iff VarB is a descendant of VarA in InstGraph.
|
|
%
|
|
:- pred descendant(inst_graph::in, prog_var::in, prog_var::out) is nondet.
|
|
|
|
% reachable(InstGraph, VarA, VarB):
|
|
%
|
|
% Succeeds iff VarB is a descendant of VarA in InstGraph,
|
|
% or if VarB *is* VarA.
|
|
%
|
|
:- pred reachable(inst_graph::in, prog_var::in, prog_var::out) is multi.
|
|
|
|
% reachable(InstGraph, Vars, VarB):
|
|
%
|
|
% Succeeds iff VarB is a descendant in InstGraph of any VarA in Vars.
|
|
%
|
|
:- pred reachable_from_list(inst_graph::in, list(prog_var)::in, prog_var::out)
|
|
is nondet.
|
|
|
|
% foldl_reachable(Pred, InstGraph, Var, !Acc):
|
|
%
|
|
% Performs a foldl operation over all variables V for which
|
|
% reachable(InstGraph, Var, V) is true.
|
|
%
|
|
:- pred foldl_reachable(pred(prog_var, T, T)::pred(in, in, out) is det,
|
|
inst_graph::in, prog_var::in, T::in, T::out) is det.
|
|
|
|
% foldl_reachable_from_list(Pred, InstGraph, Vars, !Acc):
|
|
%
|
|
% Performs a foldl operation over all variables V for which
|
|
% reachable_from_list(InstGraph, Vars, V) is true.
|
|
%
|
|
:- pred foldl_reachable_from_list(
|
|
pred(prog_var, T, T)::pred(in, in, out) is det,
|
|
inst_graph::in, list(prog_var)::in, T::in, T::out) is det.
|
|
|
|
% A version of foldl_reachable with two accumulators.
|
|
%
|
|
:- pred foldl_reachable2(
|
|
pred(prog_var, T, T, U, U)::pred(in, in, out, in, out) is det,
|
|
inst_graph::in, prog_var::in, T::in, T::out, U::in, U::out) is det.
|
|
|
|
% A version of foldl_reachable_from_list with two accumulators.
|
|
%
|
|
:- pred foldl_reachable_from_list2(
|
|
pred(prog_var, T, T, U, U)::pred(in, in, out, in, out) is det,
|
|
inst_graph::in, list(prog_var)::in, T::in, T::out, U::in, U::out)
|
|
is det.
|
|
|
|
:- pred same_graph_corresponding_nodes(inst_graph::in,
|
|
prog_var::in, prog_var::in, prog_var::out, prog_var::out) is multi.
|
|
|
|
:- pred two_graphs_corresponding_nodes(inst_graph::in, inst_graph::in,
|
|
prog_var::in, prog_var::in, prog_var::out, prog_var::out) is multi.
|
|
|
|
:- pred corresponding_nodes_from_lists(inst_graph::in, inst_graph::in,
|
|
list(prog_var)::in, list(prog_var)::in, prog_var::out, prog_var::out)
|
|
is nondet.
|
|
|
|
% Merge two inst_graphs by renaming the variables in the second
|
|
% inst_graph. Also return the variable substitution map.
|
|
%
|
|
:- pred merge(inst_graph::in, prog_varset::in, inst_graph::in, prog_varset::in,
|
|
inst_graph::out, prog_varset::out, map(prog_var, prog_var)::out)
|
|
is det.
|
|
|
|
% % Join two inst_graphs together by taking the maximum unrolling
|
|
% % of the type tree of each variable from the two graphs.
|
|
% %
|
|
% :- pred join(inst_graph::in, prog_varset::in, inst_graph::in,
|
|
% prog_varset::in, inst_graph::out, prog_varset::out) is det.
|
|
|
|
% Print the given inst_graph over the given varset in a format
|
|
% suitable for debugging output.
|
|
%
|
|
:- pred dump(inst_graph::in, prog_varset::in, io::di, io::uo) is det.
|
|
|
|
% XXX This should probably go in list.m.
|
|
%
|
|
:- pred corresponding_members(list(T)::in, list(U)::in, T::out, U::out)
|
|
is nondet.
|
|
|
|
% Values of this type are intended to contain all the info related
|
|
% to inst_graphs for a predicate that needs to be stored in the pred_info.
|
|
:- type inst_graph_info.
|
|
|
|
% Create an empty inst_graph_info.
|
|
%
|
|
:- func inst_graph_info_init = inst_graph_info.
|
|
|
|
:- func interface_inst_graph(inst_graph_info) = inst_graph.
|
|
:- func 'interface_inst_graph :='(inst_graph_info, inst_graph) =
|
|
inst_graph_info.
|
|
|
|
:- func interface_vars(inst_graph_info) = list(prog_var).
|
|
:- func 'interface_vars :='(inst_graph_info, list(prog_var)) = inst_graph_info.
|
|
|
|
:- func interface_varset(inst_graph_info) = prog_varset.
|
|
:- func 'interface_varset :='(inst_graph_info, prog_varset) = inst_graph_info.
|
|
|
|
:- func implementation_inst_graph(inst_graph_info) = inst_graph.
|
|
:- func 'implementation_inst_graph :='(inst_graph_info, inst_graph) =
|
|
inst_graph_info.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module hlds.hlds_out.
|
|
:- import_module libs.compiler_util.
|
|
|
|
:- import_module set.
|
|
:- import_module term.
|
|
:- import_module term_io.
|
|
:- import_module varset.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
init(Vars, InstGraph) :-
|
|
map.init(InstGraph0),
|
|
list.foldl(init_var, Vars, InstGraph0, InstGraph).
|
|
|
|
:- pred init_var(prog_var::in, inst_graph::in, inst_graph::out) is det.
|
|
|
|
init_var(Var, InstGraph0, InstGraph) :-
|
|
map.det_insert(InstGraph0, Var, node(map.init, top_level), InstGraph).
|
|
|
|
set_parent(Parent, Child, InstGraph0, InstGraph) :-
|
|
map.lookup(InstGraph0, Child, node(Functors, MaybeParent0)),
|
|
(
|
|
MaybeParent0 = top_level,
|
|
map.det_update(InstGraph0, Child, node(Functors, parent(Parent)),
|
|
InstGraph)
|
|
;
|
|
MaybeParent0 = parent(_),
|
|
unexpected(this_file, "set_parent: node already has parent")
|
|
).
|
|
|
|
top_level_node(InstGraph, Var, TopLevel) :-
|
|
map.lookup(InstGraph, Var, node(_, MaybeParent)),
|
|
(
|
|
MaybeParent = parent(Parent),
|
|
top_level_node(InstGraph, Parent, TopLevel)
|
|
;
|
|
MaybeParent = top_level,
|
|
TopLevel = Var
|
|
).
|
|
|
|
descendant(InstGraph, Var, Descendant) :-
|
|
set.init(Seen),
|
|
descendant_2(InstGraph, Seen, Var, Descendant).
|
|
|
|
:- pred descendant_2(inst_graph::in, set(prog_var)::in, prog_var::in,
|
|
prog_var::out) is nondet.
|
|
|
|
descendant_2(InstGraph, Seen, Var, Descendant) :-
|
|
map.lookup(InstGraph, Var, node(Functors, _)),
|
|
map.member(Functors, _ConsId, Args),
|
|
list.member(Arg, Args),
|
|
(
|
|
Descendant = Arg
|
|
;
|
|
( Arg `set.member` Seen ->
|
|
fail
|
|
;
|
|
descendant_2(InstGraph, Seen `set.insert` Arg, Arg, Descendant)
|
|
)
|
|
).
|
|
|
|
reachable(_InstGraph, Var, Var).
|
|
reachable(InstGraph, Var, Reachable) :-
|
|
descendant(InstGraph, Var, Reachable).
|
|
|
|
reachable_from_list(InstGraph, Vars, Reachable) :-
|
|
list.member(Var, Vars),
|
|
reachable(InstGraph, Var, Reachable).
|
|
|
|
foldl_reachable(P, InstGraph, Var, !Acc) :-
|
|
% A possible alternate implementation:
|
|
% aggregate(reachable(InstGraph, Var), P, !Acc).
|
|
foldl_reachable_aux(P, InstGraph, Var, set.init, !Acc).
|
|
|
|
:- pred foldl_reachable_aux(pred(prog_var, T, T)::pred(in, in, out) is det,
|
|
inst_graph::in, prog_var::in, set(prog_var)::in, T::in, T::out) is det.
|
|
|
|
foldl_reachable_aux(P, InstGraph, Var, Seen, !Acc) :-
|
|
P(Var, !Acc),
|
|
map.lookup(InstGraph, Var, node(Functors, _)),
|
|
map.foldl((pred(_ConsId::in, Args::in, MAcc0::in, MAcc::out) is det :-
|
|
list.foldl((pred(Arg::in, LAcc0::in, LAcc::out) is det :-
|
|
( Arg `set.member` Seen ->
|
|
LAcc = LAcc0
|
|
;
|
|
foldl_reachable_aux(P, InstGraph, Arg, Seen `set.insert` Arg,
|
|
LAcc0, LAcc)
|
|
)
|
|
), Args, MAcc0, MAcc)
|
|
), Functors, !Acc).
|
|
|
|
foldl_reachable_from_list(P, InstGraph, Vars, !Acc) :-
|
|
list.foldl(foldl_reachable(P, InstGraph), Vars, !Acc).
|
|
|
|
foldl_reachable2(P, InstGraph, Var, !Acc1, !Acc2) :-
|
|
% A possible alternate implementation:
|
|
% aggregate2(reachable(InstGraph, Var), P, !Acc1, !Acc2).
|
|
foldl_reachable_aux2(P, InstGraph, Var, set.init, !Acc1, !Acc2).
|
|
|
|
:- pred foldl_reachable_aux2(
|
|
pred(prog_var, T, T, U, U)::pred(in, in, out, in, out) is det,
|
|
inst_graph::in, prog_var::in, set(prog_var)::in, T::in, T::out,
|
|
U::in, U::out) is det.
|
|
|
|
foldl_reachable_aux2(P, InstGraph, Var, Seen, !Acc1, !Acc2) :-
|
|
P(Var, !Acc1, !Acc2),
|
|
map.lookup(InstGraph, Var, node(Functors, _)),
|
|
map.foldl2((pred(_ConsId::in, Args::in, MAcc10::in, MAcc1::out,
|
|
MAcc20::in, MAcc2::out) is det :-
|
|
list.foldl2((pred(Arg::in, LAccA0::in, LAccA::out,
|
|
LAccB0::in, LAccB::out) is det :-
|
|
( Arg `set.member` Seen ->
|
|
LAccA = LAccA0,
|
|
LAccB = LAccB0
|
|
;
|
|
foldl_reachable_aux2(P, InstGraph, Arg, Seen `set.insert` Arg,
|
|
LAccA0, LAccA, LAccB0, LAccB)
|
|
)
|
|
), Args, MAcc10, MAcc1, MAcc20, MAcc2)
|
|
), Functors, !Acc1, !Acc2).
|
|
|
|
foldl_reachable_from_list2(P, InstGraph, Vars, !Acc1, !Acc2) :-
|
|
list.foldl2(foldl_reachable2(P, InstGraph), Vars,
|
|
!Acc1, !Acc2).
|
|
|
|
same_graph_corresponding_nodes(InstGraph, A, B, V, W) :-
|
|
two_graphs_corresponding_nodes(InstGraph, InstGraph, A, B, V, W).
|
|
|
|
two_graphs_corresponding_nodes(InstGraphA, InstGraphB, A, B, V, W) :-
|
|
corresponding_nodes_2(InstGraphA, InstGraphB,
|
|
set.init, set.init, A, B, V, W).
|
|
|
|
:- pred corresponding_nodes_2(inst_graph::in, inst_graph::in,
|
|
set(prog_var)::in, set(prog_var)::in, prog_var::in, prog_var::in,
|
|
prog_var::out, prog_var::out) is multi.
|
|
|
|
corresponding_nodes_2(_, _, _, _, A, B, A, B).
|
|
corresponding_nodes_2(InstGraphA, InstGraphB, SeenA0, SeenB0, A, B, V, W) :-
|
|
not (
|
|
A `set.member` SeenA0,
|
|
B `set.member` SeenB0
|
|
),
|
|
|
|
map.lookup(InstGraphA, A, node(FunctorsA, _)),
|
|
map.lookup(InstGraphB, B, node(FunctorsB, _)),
|
|
|
|
SeenA = SeenA0 `set.insert` A,
|
|
SeenB = SeenB0 `set.insert` B,
|
|
|
|
( map.member(FunctorsA, ConsId, ArgsA) ->
|
|
( map.is_empty(FunctorsB) ->
|
|
list.member(V0, ArgsA),
|
|
corresponding_nodes_2(InstGraphA, InstGraphB, SeenA, SeenB,
|
|
V0, B, V, W)
|
|
;
|
|
map.search(FunctorsB, ConsId, ArgsB),
|
|
corresponding_members(ArgsA, ArgsB, V0, W0),
|
|
corresponding_nodes_2(InstGraphA, InstGraphB, SeenA, SeenB,
|
|
V0, W0, V, W)
|
|
)
|
|
;
|
|
map.member(FunctorsB, _ConsId, ArgsB),
|
|
list.member(W0, ArgsB),
|
|
corresponding_nodes_2(InstGraphA, InstGraphB, SeenA, SeenB,
|
|
A, W0, V, W)
|
|
).
|
|
|
|
corresponding_nodes_from_lists(InstGraphA, InstGraphB, VarsA, VarsB, V, W) :-
|
|
corresponding_members(VarsA, VarsB, A, B),
|
|
two_graphs_corresponding_nodes(InstGraphA, InstGraphB, A, B, V, W).
|
|
|
|
corresponding_members([A | _], [B | _], A, B).
|
|
corresponding_members([_ | As], [_ | Bs], A, B) :-
|
|
corresponding_members(As, Bs, A, B).
|
|
|
|
merge(InstGraph0, VarSet0, NewInstGraph, NewVarSet, InstGraph, VarSet, Sub) :-
|
|
varset.merge_subst_without_names(VarSet0, NewVarSet, VarSet, Sub0),
|
|
(
|
|
map.map_values(pred(_::in, term.variable(V, _)::in, V::out) is semidet,
|
|
Sub0, Sub1)
|
|
->
|
|
Sub = Sub1
|
|
;
|
|
unexpected(this_file, "merge: non-variable terms in substitution")
|
|
),
|
|
map.foldl((pred(Var0::in, Node0::in, IG0::in, IG::out) is det :-
|
|
Node0 = node(Functors0, MaybeParent),
|
|
map.map_values(
|
|
(pred(_::in, Args0::in, Args::out) is det :-
|
|
map.apply_to_list(Args0, Sub, Args)),
|
|
Functors0, Functors),
|
|
Node = node(Functors, MaybeParent),
|
|
map.lookup(Sub, Var0, Var),
|
|
map.det_insert(IG0, Var, Node, IG)
|
|
), NewInstGraph, InstGraph0, InstGraph).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% join(InstGraphA, VarSetA, InstGraphB, VarSetB,
|
|
% InstGraph, VarSet) :-
|
|
% solutions((pred(V::out) is nondet :-
|
|
% map.member(InstGraphB, V, node(_, top_level))
|
|
% ), VarsB),
|
|
% list.foldl2(join_nodes(InstGraphB, VarSetB), VarsB, InstGraphA,
|
|
% InstGraph, VarSetA, VarSet).
|
|
%
|
|
% :- pred join_nodes(inst_graph, prog_varset, prog_var, inst_graph, inst_graph,
|
|
% prog_varset, prog_varset).
|
|
% :- mode join_nodes(in, in, in, in, out, in, out) is det.
|
|
%
|
|
% join_nodes(_, _, _, _, _, _, _) :- error("join_nodes: NYI").
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
dump(InstGraph, VarSet, !IO) :-
|
|
map.foldl(dump_node(VarSet), InstGraph, !IO).
|
|
|
|
:- pred dump_node(prog_varset::in, prog_var::in, node::in,
|
|
io::di, io::uo) is det.
|
|
|
|
dump_node(VarSet, Var, Node, !IO) :-
|
|
Node = node(Functors, MaybeParent),
|
|
io.write_string("%% ", !IO),
|
|
term_io.write_variable(Var, VarSet, !IO),
|
|
io.write_string(": ", !IO),
|
|
(
|
|
MaybeParent = parent(Parent),
|
|
term_io.write_variable(Parent, VarSet, !IO)
|
|
;
|
|
MaybeParent = top_level
|
|
),
|
|
io.nl(!IO),
|
|
map.foldl(dump_functor(VarSet), Functors, !IO).
|
|
|
|
:- pred dump_functor(prog_varset::in, cons_id::in, list(prog_var)::in,
|
|
io::di, io::uo) is det.
|
|
|
|
dump_functor(VarSet, ConsId, Args, !IO) :-
|
|
io.write_string("%%\t", !IO),
|
|
write_cons_id_and_arity(ConsId, !IO),
|
|
(
|
|
Args = [_ | _],
|
|
io.write_char('(', !IO),
|
|
io.write_list(Args, ", ", dump_var(VarSet), !IO),
|
|
io.write_char(')', !IO)
|
|
;
|
|
Args = []
|
|
),
|
|
io.nl(!IO).
|
|
|
|
:- pred dump_var(prog_varset::in, prog_var::in, io::di, io::uo) is det.
|
|
|
|
dump_var(VarSet, Var, !IO) :-
|
|
term_io.write_variable(Var, VarSet, !IO).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- type inst_graph_info
|
|
---> inst_graph_info(
|
|
interface_inst_graph :: inst_graph,
|
|
% Inst graph derived from the mode
|
|
% declarations, if there are any.
|
|
% If there are no mode declarations
|
|
% for the pred, this is the same as
|
|
% the implementation_inst_graph.
|
|
|
|
interface_vars :: list(prog_var),
|
|
% Vars that appear in the head of the
|
|
% mode declaration constraint.
|
|
|
|
interface_varset :: prog_varset,
|
|
% Varset used for interface_inst_graph.
|
|
|
|
implementation_inst_graph :: inst_graph
|
|
% Inst graph derived from the body of
|
|
% the predicate.
|
|
).
|
|
|
|
inst_graph_info_init = inst_graph_info(InstGraph, [], VarSet, InstGraph) :-
|
|
varset.init(VarSet),
|
|
map.init(InstGraph).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- func this_file = string.
|
|
|
|
this_file = "inst_graph.m".
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module inst_graph.
|
|
%-----------------------------------------------------------------------------%
|