mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 22:35:41 +00:00
Estimated hours taken: 30 Branches: main Change the representation of types in the compiler. We also add some support for handling kinds, which will be used later when we have a kind system. There are a number of places where kinds are not yet handled correctly -- we assume that all kinds will be `star'. Each of these locations is flagged with a comment that contains "XXX kind inference:". compiler/prog_data.m: Implement the new version of type (type). Change the definition of type_param to be a variable instead of a term, since all parameters must be variables anyway. Implement versions of varset.merge_* which work with tvarsets and produce renamings instead of substitutions. Renamings are more convenient than substitutions because we don't need to know the kinds of type variables in order to build the renaming, and in any case the substitutions shouldn't have anything other than variables in the range so renamings will be more efficient and safe. Define the type of kinds, and provide a couple of utility predicates to operate on them. compiler/prog_io.m: Parse type definition heads as a sym_name and list of type_params, rather than a functor. Handle this change in other predicates. Allow parse errors to be returned by get_with_type/3, and handle these errors. Remove parse_type/2. This predicate didn't do any processing, it just forwarded handling to convert_type/2. compiler/prog_io_typeclass.m: Change type_is_functor_and_vars to handle the new representation of types. In doing so, we retain the old behaviour that pure predicates pass this test, but no other pred or func types. This behaviour is arguably incorrect, but there is little point changing the behaviour at the moment. Instead we should remove these kind of restrictions entirely, but that should be done later. compiler/prog_io_util.m: Provide predicates to both parse and unparse types. We need to unparse types before printing them out, since we do a lot of special case handling when printing out terms and we don't want to duplicate this functionality for types. compiler/module_qual.m: Remove report_invalid_type. We now report ill-formed types during parsing. compiler/superhomogeneous.m: Handle errors from the parsing of type expressions. compiler/prog_out.m: Provide a predicate to convert builtin_types to their string names, and vice-versa. compiler/prog_type.m: Add a bunch of simple tests to use on types which may have kind annotations present. In such cases, types do not have a canonical representation so the simple handling of these tests is not what we want. (Note that these are only required in early phases. The kind annotations -- when they are implemented -- will be removed before type checking.) Consistently handle the application of renamings, substitutions and recursive substitutions to various data structures. compiler/mercury_to_mercury.m: Implement mercury_output_type, mercury_format_type and mercury_type_to_string. These convert the type to a term before formatting -- the reason for this is so that appropriate parentheses are used when formatting operators. This results in some slight changes to error messages, which are reflected in changes to the expected output files in the tests. Remove the old version of mercury_type_to_string. Change the argument ordering of mercury_format_var to be consistent with mercury_format_type. (Other predicates in this module should probably be changed in a similar way, since this argument ordering is more amenable to higher-order programming. But that can be left for another change.) compiler/type_util.m: Implement type unification. The behaviour is much the same as the previous behaviour, except that we now handle apply/N types properly, and we also allow for kind annotations. Implement an occurs check for types. Remove the example definition of replace_eqv_type. It isn't used and would no longer work anyway even if it would have worked before. Add a tvar_kind_map field to ctor_defn. The functions type_info_type and type_ctor_info_type now return types with `void' as their argument, rather than the type that the type_info or type_ctor_info was for. Remove type_util.real_vars/2, since it no longer does anything different from prog_type.vars/2. Remove the commented out implementation of type_to_ctor_and_args/3. Its implementation is in prog_type.m, and has changed significantly in any case. compiler/add_clause.m: Move parse_purity_annotation/3 to prog_io_util.m. compiler/check_typeclass.m: Remove apply_substitution_to_var_list/3, since we now have predicates in prog_type.m to handle such things. compiler/continuation_info.m: compiler/trace.m: Use prog_type.vars/2 instead of type_util.real_vars/2. The two predicates have the same meaning now since type_infos don't contain any type variables. compiler/hlds_data.m: Add tvar_kind_map fields to hlds_type_defn and hlds_class_defn. compiler/hlds_pred.m: Add a tvar_kind_map field to pred_info. compiler/polymorphism.m: Add a tvar_kind_map field to poly_info. Remove unify_corresponding_types, which is no longer used. compiler/hlds_out.m: Use mercury_output_type/5 instead of term_io__write_term/4 and mercury_output_term/5. compiler/post_typecheck.m: Build the void substitution directly rather than building intermediate lists. compiler/recompilation.version.m: Use term__list_subsumes instead of type_list_subsumes, which now operates only on types. This follows up on what was suggested in an XXX comment. compiler/typecheck_errors.m: Use unparse_type/2 to format error messages. compiler/typecheck_info.m: Don't export write_type_with_bindings/5. It is no longer used outside of this module. compiler/*.m: Conform to the above changes. library/rtti_implementation.m: Fix a syntax error that went undetected in our previous implementation, and amazingly enough was compiled correctly anyway. library/term.m: Move the versions of term__unify, term__unify_list and term__list_subsumes that were implemented specifically for types to here. The version of term_unify that takes a list of bound variables (i.e., variables that should not be bound any further) is used by the subsumption check, which in turn is used by recompilation.version.m. tests/invalid/kind.err_exp: tests/invalid/tc_err1.err_exp: tests/invalid/tc_err2.err_exp: tests/misc_tests/pretty_print_test.exp: Update the expected output of these tests to match what we now do.
767 lines
24 KiB
Mathematica
767 lines
24 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1998-2000, 2003-2005 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: rl_dump.m
|
|
% Main author: stayl
|
|
%
|
|
% Output a human readable representation of RL for debugging.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
:- module aditi_backend__rl_dump.
|
|
|
|
:- interface.
|
|
|
|
:- import_module aditi_backend__rl.
|
|
:- import_module hlds__hlds_module.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred rl_dump__write_procedure(module_info, rl_proc, io__state, io__state).
|
|
:- mode rl_dump__write_procedure(in, in, di, uo) is det.
|
|
|
|
:- pred rl_dump__write_instruction(module_info, relation_info_map,
|
|
rl_instruction, io__state, io__state).
|
|
:- mode rl_dump__write_instruction(in, in, in, di, uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- implementation.
|
|
|
|
:- import_module hlds__hlds_out.
|
|
:- import_module hlds__hlds_pred.
|
|
:- import_module parse_tree__mercury_to_mercury.
|
|
:- import_module parse_tree__prog_data.
|
|
|
|
:- import_module bool.
|
|
:- import_module list.
|
|
:- import_module map.
|
|
:- import_module require.
|
|
:- import_module set.
|
|
:- import_module std_util.
|
|
:- import_module term.
|
|
:- import_module term_io.
|
|
:- import_module varset.
|
|
|
|
rl_dump__write_procedure(ModuleInfo, Proc) -->
|
|
{ Proc = rl_proc(Name, Inputs, Outputs, MemoedRels,
|
|
RelationInfo, Instructions, SCC) },
|
|
io__write_string("% Procedure for\n"),
|
|
{ OutputProcName = (pred(PredProcId::in, IO0::di, IO::uo) is det :-
|
|
PredProcId = proc(PredId, _ProcId),
|
|
module_info_pred_info(ModuleInfo, PredId, PredInfo),
|
|
PredName = pred_info_name(PredInfo),
|
|
io__write_string("%\t", IO0, IO1),
|
|
io__write_string(PredName, IO1, IO2),
|
|
io__nl(IO2, IO)
|
|
) },
|
|
list__foldl(OutputProcName, SCC),
|
|
io__write_string("% Memoed relations "),
|
|
{ set__to_sorted_list(MemoedRels, MemoedList) },
|
|
rl_dump__write_list(rl_dump__write_relation_id(RelationInfo),
|
|
MemoedList),
|
|
io__write_string("\n\nPROCEDURE "),
|
|
{ rl__proc_name_to_string(Name, NameStr) },
|
|
io__write_string(NameStr),
|
|
io__write_string("("),
|
|
rl_dump__write_list(rl_dump__write_relation_id(RelationInfo),
|
|
Inputs),
|
|
comma,
|
|
rl_dump__write_list(rl_dump__write_relation_id(RelationInfo),
|
|
Outputs),
|
|
io__write_string(")\n{\n"),
|
|
{ map__keys(RelationInfo, RelationIds) },
|
|
list__foldl(rl_dump__declare_relation(ModuleInfo, RelationInfo),
|
|
RelationIds),
|
|
io__nl,
|
|
list__foldl(rl_dump__write_instruction(ModuleInfo, RelationInfo),
|
|
Instructions),
|
|
io__write_string("}\n\n\n\n").
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred rl_dump__declare_relation(module_info::in,
|
|
map(relation_id, relation_info)::in, relation_id::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__declare_relation(ModuleInfo, RelationInfos, RelId) -->
|
|
{ map__lookup(RelationInfos, RelId, RelInfo) },
|
|
{ RelInfo = relation_info(RelType, Types, Index, _) },
|
|
rl_dump__verbose_write_relation_id(RelationInfos, RelId),
|
|
io__write_string(" : "),
|
|
(
|
|
{ RelType = permanent(proc(PredId, _)) },
|
|
io__write_string("base relation `"),
|
|
{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
|
|
{ PredName = pred_info_name(PredInfo) },
|
|
{ PredArity = pred_info_orig_arity(PredInfo) },
|
|
io__write_string(PredName),
|
|
io__write_string("'/"),
|
|
io__write_int(PredArity)
|
|
;
|
|
{ RelType = temporary(State) },
|
|
io__write_string("temporary ("),
|
|
io__write(State),
|
|
io__write_string(")")
|
|
),
|
|
{ varset__init(TVarSet) },
|
|
{ TypesStr = mercury_type_list_to_string(TVarSet, Types) },
|
|
io__write_strings([" [", TypesStr, "] : "]),
|
|
io__write_list(Index, " ", mercury_output_index_spec),
|
|
io__write_string(".\n").
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
rl_dump__write_instruction(ModuleInfo, RelationInfo,
|
|
join(Output, Input1, Input2, JoinType, Exprn,
|
|
SemiJoinInfo, TrivialJoinInfo) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = join("),
|
|
rl_dump__write_relation_id(RelationInfo, Input1),
|
|
comma,
|
|
rl_dump__write_relation_id(RelationInfo, Input2),
|
|
comma,
|
|
io__nl,
|
|
io__write_string("\t\t"),
|
|
rl_dump__write_join_type(ModuleInfo, JoinType),
|
|
(
|
|
{ SemiJoinInfo = yes(SemiTuple) },
|
|
io__write_string(" (semi-join tuple "),
|
|
io__write(SemiTuple),
|
|
io__write_string(")")
|
|
;
|
|
{ SemiJoinInfo = no }
|
|
),
|
|
rl_dump__write_trivial_join_or_subtract(TrivialJoinInfo),
|
|
comma,
|
|
io__nl,
|
|
rl_dump__write_goal(ModuleInfo, Exprn),
|
|
io__write_string(").\t"),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(ModuleInfo, RelationInfo,
|
|
subtract(Output, Input1, Input2, SubType,
|
|
Exprn, TrivialSubtractInfo) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = subtract("),
|
|
rl_dump__write_relation_id(RelationInfo, Input1),
|
|
comma,
|
|
rl_dump__write_relation_id(RelationInfo, Input2),
|
|
comma,
|
|
rl_dump__write_subtract_type(ModuleInfo, SubType),
|
|
comma,
|
|
rl_dump__write_trivial_join_or_subtract(TrivialSubtractInfo),
|
|
io__nl,
|
|
rl_dump__write_goal(ModuleInfo, Exprn),
|
|
io__write_string(").\t"),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(ModuleInfo, RelationInfo,
|
|
difference(Output, Input1, Input2, Type) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = difference("),
|
|
rl_dump__write_relation_id(RelationInfo, Input1),
|
|
comma,
|
|
rl_dump__write_relation_id(RelationInfo, Input2),
|
|
comma,
|
|
rl_dump__write_difference_type(ModuleInfo, Type),
|
|
io__write_string(").\t"),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(ModuleInfo, RelationInfo,
|
|
project(Output, Input, Exprn, OtherOutputs, Type) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = project("),
|
|
rl_dump__write_relation_id(RelationInfo, Input),
|
|
comma,
|
|
rl_dump__write_project_type(ModuleInfo, Type),
|
|
io__nl,
|
|
rl_dump__write_goal(ModuleInfo, Exprn),
|
|
io__nl,
|
|
io__write_string("\t"),
|
|
io__write_list(OtherOutputs, ",\n",
|
|
rl_dump__write_project_output(ModuleInfo, RelationInfo)),
|
|
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(ModuleInfo, RelationInfo,
|
|
union(Output, Inputs, UnionType) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = union("),
|
|
rl_dump__write_list(rl_dump__write_relation_id(RelationInfo), ",\n\t",
|
|
Inputs),
|
|
io__write_string("\n\t"),
|
|
comma,
|
|
rl_dump__write_union_type(ModuleInfo, UnionType),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
union_diff(Union, Input1, Input2, Diff, Index, CopyInfo) - Comment) -->
|
|
|
|
rl_dump__write_output_rel(RelationInfo, Diff),
|
|
io__write_string(" = union_diff("),
|
|
rl_dump__write_relation_id(RelationInfo, Input1),
|
|
io__write_string(" => "),
|
|
rl_dump__write_relation_id(RelationInfo, Union),
|
|
comma,
|
|
rl_dump__write_relation_id(RelationInfo, Input2),
|
|
comma,
|
|
mercury_output_index_spec(Index),
|
|
comma,
|
|
io__write(CopyInfo),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(ModuleInfo, RelationInfo,
|
|
insert(UoOutput, DiInput, Input, Type, CopyInfo) - Comment) -->
|
|
io__write_string("insert("),
|
|
rl_dump__write_relation_id(RelationInfo, DiInput),
|
|
io__write_string(" => "),
|
|
rl_dump__write_relation_id(RelationInfo, UoOutput),
|
|
comma,
|
|
rl_dump__write_relation_id(RelationInfo, Input),
|
|
comma,
|
|
rl_dump__write_insert_type(ModuleInfo, Type),
|
|
comma,
|
|
io__write(CopyInfo),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
sort(Output, Input, Attrs) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = sort("),
|
|
rl_dump__write_relation_id(RelationInfo, Input),
|
|
comma,
|
|
rl_dump__write_sort_attr_list(Attrs),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
init(RelationId) - Comment) -->
|
|
io__write_string("init("),
|
|
rl_dump__write_output_rel(RelationInfo, RelationId),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(ModuleInfo, RelationInfo,
|
|
insert_tuple(Output, Input, Exprn) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = insert_tuple("),
|
|
rl_dump__write_relation_id(RelationInfo, Input),
|
|
comma,
|
|
io__nl,
|
|
rl_dump__write_goal(ModuleInfo, Exprn),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
add_index(Output, Input) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = add_index("),
|
|
rl_dump__write_relation_id(RelationInfo, Input),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
clear(RelationId) - Comment) -->
|
|
io__write_string("clear("),
|
|
rl_dump__write_relation_id(RelationInfo, RelationId),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
unset(RelationId) - Comment) -->
|
|
io__write_string("unset("),
|
|
rl_dump__write_relation_id(RelationInfo, RelationId),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, _RelationInfo,
|
|
label(LabelId) - Comment) -->
|
|
io__write_string("\nlabel("),
|
|
{ rl__label_id_to_string(LabelId, String) },
|
|
io__write_string(String),
|
|
io__write_string(")\n"),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
conditional_goto(Cond, LabelId) - Comment) -->
|
|
io__write_string("conditional_goto("),
|
|
rl_dump__write_goto_cond(RelationInfo, Cond),
|
|
comma,
|
|
{ rl__label_id_to_string(LabelId, String) },
|
|
io__write_string(String),
|
|
io__write_string(").\n"),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, _, goto(LabelId) - Comment) -->
|
|
io__write_string("goto("),
|
|
{ rl__label_id_to_string(LabelId, String) },
|
|
io__write_string(String),
|
|
io__write_string(").\n"),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
ref(Output, Input) - Comment) -->
|
|
rl_dump__write_relation_id(RelationInfo, Output),
|
|
io__write_string(" = "),
|
|
rl_dump__write_relation_id(RelationInfo, Input),
|
|
io__write_string("."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
copy(Output, Input) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = copy("),
|
|
rl_dump__write_relation_id(RelationInfo, Input),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
make_unique(Output, Input) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = make_unique("),
|
|
rl_dump__write_relation_id(RelationInfo, Input),
|
|
io__write_string(")."),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_ModuleInfo, RelationInfo,
|
|
call(Name, InputArgs, OutputArgs, Saved) - Comment) -->
|
|
io__write_string("call("),
|
|
{ rl__proc_name_to_string(Name, NameStr) },
|
|
io__write_string(NameStr),
|
|
comma,
|
|
rl_dump__write_list(rl_dump__write_relation_id(RelationInfo),
|
|
InputArgs),
|
|
comma,
|
|
rl_dump__write_list(rl_dump__write_output_rel(RelationInfo),
|
|
OutputArgs),
|
|
comma,
|
|
{ set__to_sorted_list(Saved, SavedList) },
|
|
rl_dump__write_list(rl_dump__write_relation_id(RelationInfo),
|
|
SavedList),
|
|
|
|
io__write_string(").\n\t"),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(ModuleInfo, RelationInfo,
|
|
aggregate(Output, Input, Initial, Update) - Comment) -->
|
|
rl_dump__write_output_rel(RelationInfo, Output),
|
|
io__write_string(" = aggregate("),
|
|
rl_dump__write_relation_id(RelationInfo, Input),
|
|
comma,
|
|
io__nl,
|
|
io__write_string("\t"),
|
|
{ Initial = proc(IPredId, IProcId) },
|
|
hlds_out__write_pred_proc_id(ModuleInfo, IPredId, IProcId),
|
|
comma,
|
|
{ Update = proc(UPredId, UProcId) },
|
|
hlds_out__write_pred_proc_id(ModuleInfo, UPredId, UProcId),
|
|
io__write_string(").\n"),
|
|
rl_dump__write_comment(Comment),
|
|
io__nl.
|
|
|
|
rl_dump__write_instruction(_, _, comment - Comment) -->
|
|
io__write_strings(["\n%\n% ", Comment, "\n%\n\n"]),
|
|
io__nl.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred rl_dump__write_join_type(module_info::in, join_type::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_join_type(_, nested_loop) -->
|
|
io__write_string("nested_loop").
|
|
rl_dump__write_join_type(_, hash(Attrs1, Attrs2)) -->
|
|
io__write_string("hash("),
|
|
rl_dump__write_list(io__write, ", ", Attrs1),
|
|
io__write_string(", "),
|
|
rl_dump__write_list(io__write, ", ", Attrs2),
|
|
io__write_string(")").
|
|
rl_dump__write_join_type(_, sort_merge(Attr1, Attr2)) -->
|
|
io__write_string("sort_merge("),
|
|
rl_dump__write_sort_spec(Attr1),
|
|
comma,
|
|
rl_dump__write_sort_spec(Attr2),
|
|
io__write_string(")").
|
|
rl_dump__write_join_type(ModuleInfo, index(Spec, Range)) -->
|
|
io__write_string("index("),
|
|
mercury_output_index_spec(Spec),
|
|
comma,
|
|
rl_dump__write_key_range(ModuleInfo, Range),
|
|
io__write_string(")").
|
|
|
|
:- pred rl_dump__write_subtract_type(module_info::in, subtract_type::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_subtract_type(_, semi_nested_loop) -->
|
|
io__write_string("semi_nested_loop").
|
|
rl_dump__write_subtract_type(_, semi_sort_merge(SortAttr1, SortAttr2)) -->
|
|
io__write_string("semi_sort_merge("),
|
|
rl_dump__write_sort_spec(SortAttr1),
|
|
comma,
|
|
rl_dump__write_sort_spec(SortAttr2),
|
|
io__write_string(")").
|
|
rl_dump__write_subtract_type(_, semi_hash(Attrs1, Attrs2)) -->
|
|
io__write_string("semi_hash("),
|
|
rl_dump__write_list(io__write, ", ", Attrs1),
|
|
io__write_string(", "),
|
|
rl_dump__write_list(io__write, ", ", Attrs2),
|
|
io__write_string(")").
|
|
rl_dump__write_subtract_type(ModuleInfo, semi_index(Spec, Range)) -->
|
|
io__write_string("semi_index("),
|
|
mercury_output_index_spec(Spec),
|
|
comma,
|
|
rl_dump__write_key_range(ModuleInfo, Range),
|
|
io__write_string(")").
|
|
|
|
:- pred rl_dump__write_difference_type(module_info::in, difference_type::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_difference_type(_, sort_merge(SortAttr)) -->
|
|
io__write_string("sort_merge("),
|
|
rl_dump__write_sort_spec(SortAttr),
|
|
io__write_string(")").
|
|
|
|
:- pred rl_dump__write_project_type(module_info::in, project_type::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_project_type(_, filter) -->
|
|
io__write_string("filter").
|
|
rl_dump__write_project_type(ModuleInfo, index(Spec, Range)) -->
|
|
io__write_string("index("),
|
|
mercury_output_index_spec(Spec),
|
|
comma,
|
|
rl_dump__write_key_range(ModuleInfo, Range),
|
|
io__write_string(")").
|
|
|
|
:- pred rl_dump__write_union_type(module_info::in, union_type::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_union_type(_, sort_merge(SortAttr)) -->
|
|
io__write_string("sort_merge("),
|
|
rl_dump__write_sort_spec(SortAttr),
|
|
io__write_string(")").
|
|
|
|
:- pred rl_dump__write_insert_type(module_info::in, insert_type::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_insert_type(_, append) -->
|
|
io__write_string("append").
|
|
rl_dump__write_insert_type(_ModuleInfo, index(IndexSpec)) -->
|
|
io__write_string("index("),
|
|
mercury_output_index_spec(IndexSpec),
|
|
io__write_string(")").
|
|
|
|
:- pred rl_dump__write_trivial_join_or_subtract(
|
|
maybe(trivial_join_or_subtract_info)::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_trivial_join_or_subtract(TrivialJoinInfo) -->
|
|
(
|
|
{ TrivialJoinInfo = yes(trivial_join_or_subtract_info(Tuple,
|
|
MaybeProject)) },
|
|
io__write_string(" (trivial input "),
|
|
io__write(Tuple),
|
|
(
|
|
{ MaybeProject = yes(_) },
|
|
io__write_string(" projected")
|
|
;
|
|
{ MaybeProject = no },
|
|
io__write_string(" not projected")
|
|
),
|
|
io__write_string(")")
|
|
;
|
|
{ TrivialJoinInfo = no }
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred rl_dump__write_key_range(module_info::in, key_range::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_key_range(ModuleInfo, key_range(LBound, UBound, _, _)) -->
|
|
io__write_string("key_range("),
|
|
rl_dump__write_key_tuple(ModuleInfo, LBound),
|
|
comma,
|
|
rl_dump__write_key_tuple(ModuleInfo, UBound),
|
|
io__write_string(")").
|
|
|
|
:- pred rl_dump__write_key_tuple(module_info::in,
|
|
bounding_tuple::in, io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_key_tuple(_, infinity) -->
|
|
io__write_string("infinity").
|
|
rl_dump__write_key_tuple(_ModuleInfo, bound(Attrs)) -->
|
|
io__write_string("["),
|
|
io__write_list(Attrs, ", ", rl_dump__write_key_attr_pair),
|
|
io__write_string("]").
|
|
|
|
:- pred rl_dump__write_key_attr_pair(pair(int, key_attr)::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_key_attr_pair(Index - Attr) -->
|
|
io__write_int(Index),
|
|
io__write_string(" - "),
|
|
rl_dump__write_key_attr(Attr).
|
|
|
|
:- pred rl_dump__write_key_attr(key_attr::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_key_attr(Attr) -->
|
|
{ Attr = infinity },
|
|
io__write(Attr).
|
|
rl_dump__write_key_attr(Attr) -->
|
|
{ Attr = input_field(_) },
|
|
io__write(Attr).
|
|
rl_dump__write_key_attr(functor(ConsId, _, Args)) -->
|
|
hlds_out__write_cons_id(ConsId),
|
|
io__write_string("("),
|
|
io__write_list(Args, ", ", rl_dump__write_key_attr),
|
|
io__write_string(")").
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred rl_dump__write_sort_spec(sort_spec::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_sort_spec(attributes(Attrs)) -->
|
|
rl_dump__write_sort_attr_list(Attrs).
|
|
rl_dump__write_sort_spec(sort_var(Var)) -->
|
|
io__write_string("sort_var("),
|
|
io__write_int(Var),
|
|
io__write_string(")").
|
|
|
|
:- pred rl_dump__write_sort_attr_list(sort_attrs::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_sort_attr_list(Attrs) -->
|
|
rl_dump__write_list(io__write, ", ", Attrs).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred rl_dump__write_goto_cond(map(relation_id, relation_info)::in,
|
|
goto_cond::in, io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_goto_cond(RelationInfo, empty(RelationId)) -->
|
|
io__write_string("empty("),
|
|
rl_dump__write_relation_id(RelationInfo, RelationId),
|
|
io__write_string(")").
|
|
rl_dump__write_goto_cond(RelationInfo, and(Cond1, Cond2)) -->
|
|
rl_dump__write_goto_cond(RelationInfo, Cond1),
|
|
comma,
|
|
rl_dump__write_goto_cond(RelationInfo, Cond2).
|
|
rl_dump__write_goto_cond(RelationInfo, or(Cond1, Cond2)) -->
|
|
rl_dump__write_goto_cond(RelationInfo, Cond1),
|
|
io__write_string(" ; "),
|
|
rl_dump__write_goto_cond(RelationInfo, Cond2).
|
|
rl_dump__write_goto_cond(RelationInfo, not(Cond)) -->
|
|
io__write_string("not("),
|
|
rl_dump__write_goto_cond(RelationInfo, Cond),
|
|
io__write_string(")").
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred rl_dump__write_comment(string::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_comment(Comment) -->
|
|
( { Comment = "" } ->
|
|
[]
|
|
;
|
|
io__write_string("% "),
|
|
io__write_string(Comment)
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred rl_dump__write_output_rel(map(relation_id, relation_info)::in,
|
|
output_rel::in, io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_output_rel(RelationInfo, output_rel(RelationId, Indexes)) -->
|
|
rl_dump__write_relation_id(RelationInfo, RelationId),
|
|
( { Indexes = [] } ->
|
|
[]
|
|
;
|
|
rl_dump__write_list(mercury_output_index_spec, ", ", Indexes)
|
|
).
|
|
|
|
:- pred rl_dump__write_relation_id(map(relation_id, relation_info)::in,
|
|
relation_id::in, io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_relation_id(_, RelationId) -->
|
|
{ rl__relation_id_to_string(RelationId, RelationIdStr) },
|
|
io__write_string(RelationIdStr).
|
|
|
|
:- pred rl_dump__verbose_write_relation_id(
|
|
map(relation_id, relation_info)::in,
|
|
relation_id::in, io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__verbose_write_relation_id(RelationInfo, RelationId) -->
|
|
{ map__lookup(RelationInfo, RelationId, RelInfo) },
|
|
{ RelInfo = relation_info(_, _, _, Name) },
|
|
io__write_string(Name).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred rl_dump__write_project_output(module_info::in,
|
|
map(relation_id, relation_info)::in, pair(output_rel, rl_goal)::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_project_output(ModuleInfo, RelationInfo,
|
|
Relation - RelationExprn) -->
|
|
rl_dump__write_output_rel(RelationInfo, Relation),
|
|
io__write_string(" <- "),
|
|
io__nl,
|
|
rl_dump__write_goal(ModuleInfo, RelationExprn),
|
|
io__nl.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred rl_dump__write_goal(module_info::in, rl_goal::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_goal(ModuleInfo, RLGoal) -->
|
|
{ RLGoal = rl_goal(_, VarSet, _, _, Inputs,
|
|
MaybeOutputs, GoalList, Bounds) },
|
|
(
|
|
{ Inputs = no_inputs }
|
|
;
|
|
{ Inputs = one_input(InputVars) },
|
|
io__write_string("\tinputs: "),
|
|
rl_dump__write_var_list(VarSet, InputVars),
|
|
io__write_string("\n\t"),
|
|
( { Bounds \= [] } ->
|
|
rl_dump__write_list(
|
|
rl_dump__write_bounds(ModuleInfo, VarSet),
|
|
Bounds)
|
|
;
|
|
[]
|
|
)
|
|
;
|
|
{ Inputs = two_inputs(Inputs1, Inputs2) },
|
|
io__write_string("\tinputs: "),
|
|
rl_dump__write_var_list(VarSet, Inputs1),
|
|
io__write_string(" "),
|
|
rl_dump__write_var_list(VarSet, Inputs2),
|
|
io__write_string("\n\t"),
|
|
( { Bounds \= [] } ->
|
|
rl_dump__write_list(
|
|
rl_dump__write_bounds(ModuleInfo, VarSet),
|
|
Bounds)
|
|
;
|
|
[]
|
|
)
|
|
),
|
|
io__write_string("\n"),
|
|
( { MaybeOutputs = yes(Outputs) } ->
|
|
io__write_string("\toutputs: "),
|
|
rl_dump__write_var_list(VarSet, Outputs),
|
|
io__nl
|
|
;
|
|
[]
|
|
),
|
|
hlds_out__write_goal_list(GoalList, ModuleInfo,
|
|
VarSet, yes, 2, ",\n", no).
|
|
|
|
:- pred rl_dump__write_bounds(module_info::in, prog_varset::in,
|
|
rl_var_bounds::in, io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_bounds(ModuleInfo, VarSet, Bounds) -->
|
|
{ map__to_assoc_list(Bounds, BoundList) },
|
|
io__write_string("\n\t["),
|
|
io__write_list(BoundList, "\n\t",
|
|
rl_dump__write_bound_pair(ModuleInfo, VarSet)),
|
|
io__write_string("\n\t]"),
|
|
io__nl.
|
|
|
|
:- pred rl_dump__write_bound_pair(module_info::in, prog_varset::in,
|
|
pair(prog_var, pair(key_term))::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_bound_pair(ModuleInfo, VarSet,
|
|
Var - (LowerBound - UpperBound)) -->
|
|
mercury_output_var(Var, VarSet, yes),
|
|
io__write_string(" -> "),
|
|
rl_dump__write_key_term(ModuleInfo, VarSet, LowerBound),
|
|
io__write_string(" - "),
|
|
rl_dump__write_key_term(ModuleInfo, VarSet, UpperBound).
|
|
|
|
:- pred rl_dump__write_key_term(module_info::in, prog_varset::in, key_term::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_key_term(_ModuleInfo, VarSet, var - Vars0) -->
|
|
{ set__to_sorted_list(Vars0, Vars) },
|
|
( { Vars = [] } ->
|
|
io__write_string("infinity")
|
|
;
|
|
io__write_string("var"),
|
|
rl_dump__write_var_list(VarSet, Vars)
|
|
).
|
|
rl_dump__write_key_term(ModuleInfo, VarSet,
|
|
functor(ConsId, _, Args) - Vars0) -->
|
|
hlds_out__write_cons_id(ConsId),
|
|
io__write_string("("),
|
|
io__write_list(Args, ", ",
|
|
rl_dump__write_key_term(ModuleInfo, VarSet)),
|
|
io__write_string(")"),
|
|
{ set__to_sorted_list(Vars0, Vars) },
|
|
rl_dump__write_var_list(VarSet, Vars).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred rl_dump__write_var_list(prog_varset::in, list(prog_var)::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
rl_dump__write_var_list(VarSet, Vars) -->
|
|
{ PrintVar = (pred(Var::in, IO0::di, IO::uo) is det :-
|
|
mercury_output_var(Var, VarSet, yes, IO0, IO)
|
|
) },
|
|
rl_dump__write_list(PrintVar, Vars).
|
|
|
|
:- pred rl_dump__write_list(pred(T, io__state, io__state), list(T),
|
|
io__state, io__state).
|
|
:- mode rl_dump__write_list(pred(in, di, uo) is det, in, di, uo) is det.
|
|
|
|
rl_dump__write_list(Writer, List) -->
|
|
rl_dump__write_list(Writer, ", ", List).
|
|
|
|
:- pred rl_dump__write_list(pred(T, io__state, io__state), string, list(T),
|
|
io__state, io__state).
|
|
:- mode rl_dump__write_list(pred(in, di, uo) is det, in, in, di, uo) is det.
|
|
|
|
rl_dump__write_list(Writer, Sep, List) -->
|
|
io__write_string("["),
|
|
io__write_list(List, Sep, Writer),
|
|
io__write_string("]").
|
|
|
|
:- pred comma(io__state::di, io__state::uo) is det.
|
|
|
|
comma --> io__write_string(", ").
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|