[m-rev.] for review: Allow pred or func containing coerce to be opt-exported.
Peter Wang
novalazy at gmail.com
Tue Apr 13 17:20:38 AEST 2021
compiler/intermod.m:
Make the presence of a coerce goal not disqualify a predicate or
function from being written out to a .opt file.
compiler/hlds_out_goal.m:
Write coerce goal using function call syntax "X = coerce(Y)".
instead of predicate call syntax "coerce(X, Y)".
diff --git a/compiler/hlds_out_goal.m b/compiler/hlds_out_goal.m
index 3a4c437ae..1ffc54747 100644
--- a/compiler/hlds_out_goal.m
+++ b/compiler/hlds_out_goal.m
@@ -1522,10 +1522,12 @@ write_goal_generic_call(Info, Stream, _ModuleInfo, VarSet, _TypeQual,
;
(
GenericCall = cast(CastType),
- CastTypeString = cast_type_to_string(CastType)
+ CastTypeString = cast_type_to_string(CastType),
+ PredOrFunc = pf_predicate
;
GenericCall = subtype_coerce,
- CastTypeString = "coerce"
+ CastTypeString = "coerce",
+ PredOrFunc = pf_function
),
( if string.contains_char(DumpOptions, 'l') then
write_indent(Stream, Indent, !IO),
@@ -1544,12 +1546,25 @@ write_goal_generic_call(Info, Stream, _ModuleInfo, VarSet, _TypeQual,
else
true
),
- Functor = term.atom(CastTypeString),
- term.var_list_to_term_list(ArgVars, ArgTerms),
- term.context_init(Context),
- Term = term.functor(Functor, ArgTerms, Context),
- write_indent(Stream, Indent, !IO),
- mercury_output_term(VarSet, VarNamePrint, Term, Stream, !IO),
+ (
+ PredOrFunc = pf_predicate,
+ Functor = term.atom(CastTypeString),
+ term.var_list_to_term_list(ArgVars, ArgTerms),
+ term.context_init(Context),
+ Term = term.functor(Functor, ArgTerms, Context),
+ write_indent(Stream, Indent, !IO),
+ mercury_output_term(VarSet, VarNamePrint, Term, Stream, !IO)
+ ;
+ PredOrFunc = pf_function,
+ pred_args_to_func_args(ArgVars, FuncArgVars, FuncRetVar),
+ write_indent(Stream, Indent, !IO),
+ mercury_output_var(VarSet, VarNamePrint, FuncRetVar, Stream, !IO),
+ io.write_string(Stream, " = ", !IO),
+ io.write_string(Stream,
+ functor_to_string(VarSet, VarNamePrint,
+ term.atom(CastTypeString), FuncArgVars),
+ !IO)
+ ),
io.write_string(Stream, Follow, !IO)
).
diff --git a/compiler/intermod.m b/compiler/intermod.m
index f466d94ff..1fd75855c 100644
--- a/compiler/intermod.m
+++ b/compiler/intermod.m
@@ -628,8 +628,7 @@ gather_entities_to_opt_export_in_goal_expr(GoalExpr, DoWrite,
DoWrite = no
;
CallType = subtype_coerce,
- % XXX SUBTYPE consider this later
- DoWrite = no
+ DoWrite = yes
)
;
GoalExpr = call_foreign_proc(Attrs, _, _, _, _, _, _),
--
2.30.0
More information about the reviews
mailing list