[m-rev.] for review: Prevent float_regs abort on constrained polymorphic inst.
Peter Wang
novalazy at gmail.com
Tue Mar 6 16:57:04 AEDT 2018
The float_regs pass made a call to inst_expand (which does not touch an
inst with constrained_inst_vars at the top level) was followed by
get_arg_insts (which expects the inst to be expanded), leading to a
compiler abort.
This fixes compilation of tests/valid/constrained_poly_insts.m
when floating point registers are used.
compiler/float_regs.m:
Replace a call to inst_expand with
inst_expand_and_remove_constrained_inst_vars.
Add require_complete_switch scope to a switch.
compiler/inst_util.m:
compiler/prog_mode.m:
Add comments for would-be callers of inst_expand and get_arg_insts.
---
compiler/float_regs.m | 19 ++++++++++++++++++-
compiler/inst_util.m | 2 ++
compiler/prog_mode.m | 3 +++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/compiler/float_regs.m b/compiler/float_regs.m
index 4f55da795..c4a68f20f 100644
--- a/compiler/float_regs.m
+++ b/compiler/float_regs.m
@@ -834,7 +834,8 @@ insert_reg_wrappers_unify_goal(GoalExpr0, GoalInfo0, Goal, !InstMap, !Info,
lambda_info_get_module_info(!.Info, ModuleInfo),
list.length(Args, Arity),
instmap_lookup_var(!.InstMap, CellVar, CellVarInst0),
- inst_expand(ModuleInfo, CellVarInst0, CellVarInst),
+ inst_expand_and_remove_constrained_inst_vars(ModuleInfo,
+ CellVarInst0, CellVarInst),
( if
get_arg_insts(CellVarInst, ConsId, Arity, ArgInsts),
list.map_corresponding(unify_mode_set_rhs_final_inst(ModuleInfo),
@@ -1419,6 +1420,7 @@ search_pred_inst_info(ModuleInfo, Inst, PredOrFunc, Arity, PredInstInfo) :-
pred_inst_info::out) is semidet.
search_pred_inst_info_2(ModuleInfo, Inst, PredInstInfo) :-
+ require_complete_switch [Inst]
(
Inst = any(_, higher_order(PredInstInfo))
;
@@ -1427,6 +1429,21 @@ search_pred_inst_info_2(ModuleInfo, Inst, PredInstInfo) :-
Inst = defined_inst(InstName),
inst_lookup(ModuleInfo, InstName, InstB),
search_pred_inst_info_2(ModuleInfo, InstB, PredInstInfo)
+ ;
+ Inst = constrained_inst_vars(_Vars, _SubInst),
+ % This might be necessary if modecheck_higher_order_call is changed
+ % to accept an inst with constrained_inst_vars at the top level:
+ % search_pred_inst_info_2(ModuleInfo, SubInst, PredInstInfo)
+ fail
+ ;
+ ( Inst = free
+ ; Inst = free(_)
+ ; Inst = bound(_, _, _)
+ ; Inst = not_reached
+ ; Inst = inst_var(_)
+ ; Inst = abstract_inst(_, _)
+ ),
+ fail
).
:- pred get_ho_arg_regs(pred_inst_info::in, list(mer_type)::in,
diff --git a/compiler/inst_util.m b/compiler/inst_util.m
index 9d4355890..1ddfb6b9b 100644
--- a/compiler/inst_util.m
+++ b/compiler/inst_util.m
@@ -43,6 +43,8 @@
% inst_expand(ModuleInfo, Inst0, Inst) checks if the top-level part
% of the inst is a defined inst, and if so replaces it with the definition.
%
+ % This leaves insts with constrained_inst_vars at the top level unchanged.
+ %
:- pred inst_expand(module_info::in, mer_inst::in, mer_inst::out) is det.
% inst_expand_and_remove_constrained_inst_vars is the same as inst_expand
diff --git a/compiler/prog_mode.m b/compiler/prog_mode.m
index 224d20b4c..6c9caa4bc 100644
--- a/compiler/prog_mode.m
+++ b/compiler/prog_mode.m
@@ -136,6 +136,9 @@
% insts of the arguments of the top level functor, failing if the
% inst could not be bound to the functor.
%
+ % Note that inst_expand does not expand insts with constrained_inst_vars
+ % at the top level.
+ %
:- pred get_arg_insts(mer_inst::in, cons_id::in, arity::in,
list(mer_inst)::out) is semidet.
--
2.16.2
More information about the reviews
mailing list