[m-rev.] for review: Enable coerce casts in backends.

Peter Wang novalazy at gmail.com
Thu Apr 1 12:41:17 AEDT 2021


compiler/call_gen.m:
compiler/interval.m:
compiler/ml_call_gen.m:
    As above.

tests/hard_coded/subtype_pack.m:
    Enable use of coerce in test case.

diff --git a/compiler/call_gen.m b/compiler/call_gen.m
index e28aa1fd0..f343d6e13 100644
--- a/compiler/call_gen.m
+++ b/compiler/call_gen.m
@@ -193,7 +193,9 @@ generate_generic_call(OuterCodeModel, GenericCall, Args, Modes,
         GenericCall = event_call(EventName),
         generate_event_call(EventName, Args, GoalInfo, Code, !CI, !CLD)
     ;
-        GenericCall = cast(_),
+        ( GenericCall = cast(_)
+        ; GenericCall = subtype_coerce
+        ),
         ( if Args = [InputArg, OutputArg] then
             get_module_info(!.CI, ModuleInfo),
             get_proc_info(!.CI, ProcInfo),
@@ -212,10 +214,6 @@ generate_generic_call(OuterCodeModel, GenericCall, Args, Modes,
         else
             unexpected($pred, "invalid type/inst cast call")
         )
-    ;
-        GenericCall = subtype_coerce,
-        % XXX SUBTYPE
-        sorry($pred, "coerce")
     ).
 
 :- pred generate_main_generic_call(code_model::in, generic_call::in,
@@ -441,15 +439,12 @@ generic_call_info(Globals, GenericCall, NumInputArgsR, NumInputArgsF,
         % Events and casts are generated inline.
         ( GenericCall = event_call(_)
         ; GenericCall = cast(_)
+        ; GenericCall = subtype_coerce
         ),
         CodeAddr = do_not_reached,
         SpecifierArgInfos = [],
         FirstImmediateInputReg = 1,
         HoCallVariant = ho_call_unknown     % dummy; not used
-    ;
-        GenericCall = subtype_coerce,
-        % XXX SUBTYPE
-        sorry($pred, "coerce")
     ).
 
     % Some of the values that generic call passes to the dispatch routine
diff --git a/compiler/interval.m b/compiler/interval.m
index df9f5c439..5bd296357 100644
--- a/compiler/interval.m
+++ b/compiler/interval.m
@@ -996,12 +996,10 @@ record_decisions_in_goal(Goal0, Goal, !VarInfo, !VarRename, InsertMap,
         GoalExpr0 = generic_call(GenericCall, _, _, _, _),
         % Casts are generated inline.
         (
-            GenericCall = cast(_),
+            ( GenericCall = cast(_)
+            ; GenericCall = subtype_coerce
+            ),
             MustHaveMap = no
-        ;
-            GenericCall = subtype_coerce,
-            % XXX SUBTYPE
-            sorry($pred, "coerce")
         ;
             ( GenericCall = higher_order(_, _, _, _)
             ; GenericCall = class_method(_, _, _, _)
diff --git a/compiler/ml_call_gen.m b/compiler/ml_call_gen.m
index 99b757a74..fced45a98 100644
--- a/compiler/ml_call_gen.m
+++ b/compiler/ml_call_gen.m
@@ -123,12 +123,10 @@ ml_gen_generic_call(GenericCall, ArgVars, ArgModes, Determinism, Context,
         FuncDefns = [],
         Stmts = []
     ;
-        GenericCall = cast(_),
+        ( GenericCall = cast(_)
+        ; GenericCall = subtype_coerce
+        ),
         ml_gen_cast(Context, ArgVars, LocalVarDefns, FuncDefns, Stmts, !Info)
-    ;
-        GenericCall = subtype_coerce,
-        % XXX SUBTYPE
-        sorry($pred, "coerce")
     ).
 
 :- inst main_generic_call for generic_call/0
@@ -281,8 +279,8 @@ ml_gen_main_generic_call(GenericCall, ArgVars, ArgModes, Determinism, Context,
     FuncDefns = FuncDefns0,
     Stmts = [AssignFuncVar | Stmts0].
 
-    % Generate MLDS code for a cast. The list of argument variables
-    % must have only two elements, the input and the output.
+    % Generate MLDS code for a cast (including coerce). The list of argument
+    % variables must have only two elements, the input and the output.
     %
 :- pred ml_gen_cast(prog_context::in, list(prog_var)::in,
     list(mlds_local_var_defn)::out, list(mlds_function_defn)::out,
diff --git a/tests/hard_coded/subtype_pack.m b/tests/hard_coded/subtype_pack.m
index fc98b4fbf..a2a515b5b 100644
--- a/tests/hard_coded/subtype_pack.m
+++ b/tests/hard_coded/subtype_pack.m
@@ -123,7 +123,5 @@ main(!IO) :-
             make_sub_abs_notag
         ),
     io.print_line(Sub : substruct, !IO),
-    % XXX SUBTYPE enable with coerce
-    %Base = coerce(Sub) : struct(_, _),
-    Base = Sub,
+    Base = coerce(Sub) : struct(_, _),
     io.print_line(Base, !IO).
-- 
2.30.0



More information about the reviews mailing list