[m-rev.] diff: Make --allow-ho-insts-as-modes also apply to higher-order function insts.

Peter Wang novalazy at gmail.com
Thu Jul 27 13:56:59 AEST 2023


compiler/parse_inst_mode_name.m:
    When --no-allow-ho-insts-as-modes is used, report an error if a
    higher-order function inst is used as a mode, in addition to
    higher-order predicate insts.
---
 compiler/parse_inst_mode_name.m | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/compiler/parse_inst_mode_name.m b/compiler/parse_inst_mode_name.m
index ae6dca3f9..08244f4dc 100644
--- a/compiler/parse_inst_mode_name.m
+++ b/compiler/parse_inst_mode_name.m
@@ -288,6 +288,17 @@ parse_higher_order_mode(AllowConstrainedInstVar, VarSet, ContextPieces,
             IsAny = yes
         )
     then
+        AllowInstsAsModes = globals.get_allow_ho_insts_as_modes,
+        (
+            AllowInstsAsModes = no,
+            Pieces = cord.list(ContextPieces) ++ [lower_case_next_if_not_first,
+                words("Error: higher order inst is used as a mode."), nl],
+            Spec = simplest_spec($pred, severity_error,
+                phase_term_to_parse_tree, get_term_context(BeforeIsTerm),
+                Pieces),
+            MaybeMode = error1([Spec])
+        ;
+            AllowInstsAsModes = yes,
             % XXX Should update ContextPieces.
             parse_modes(AllowConstrainedInstVar, VarSet, ContextPieces,
                 ArgModesTerms, MaybeArgModes0),
@@ -317,6 +328,7 @@ parse_higher_order_mode(AllowConstrainedInstVar, VarSet, ContextPieces,
                     ++ get_any_errors1(MaybeDetism),
                 MaybeMode = error1(Specs)
             )
+        )
     else
         Pieces = cord.list(ContextPieces) ++ [lower_case_next_if_not_first,
             words("Error: a higher-order mode should have"),
-- 
2.39.0



More information about the reviews mailing list