Skip to content

Commit 33be5c8

Browse files
committed
Restore a fix to handle_inst_var_subs_2.
A previous change improved the precision of inst matching by making handle_inst_var_subs_2 recurse on the abstract unification of InstA and SubInstB, Recurse(InstA, abstractly_unify_inst(InstA, SubInstB)) The change was temporarily reverted because it is susceptible to infinite recursion when abstractly_unify_inst returns an inst containing larger and larger "unify_insts" in each successive call. compiler/inst_match.m: Restore the fix but avoid infinite recursion. tests/EXPECT_FAIL_TESTS.all_grades: Enable invalid/constrained_poly_insts2 again.
1 parent a2879c6 commit 33be5c8

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

compiler/inst_match.m

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -495,35 +495,25 @@
495495

496496
handle_inst_var_subs_2(Recurse, Continue, InstA, InstB, Type, !Info) :-
497497
( InstB = constrained_inst_vars(InstVarsB, SubInstB) ->
498-
% InstB is a constrained_inst_var with upper bound SubInstB.
499-
% We need to check that InstA matches_initial SubInstB and add the
500-
% appropriate inst_var substitution.
501-
Recurse(InstA, SubInstB, Type, !Info),
502-
503-
% Call abstractly_unify_inst to calculate the uniqueness of the
504-
% inst represented by the constrained_inst_var.
505-
% We pass `Live = is_dead' because we want
506-
% abstractly_unify(unique, unique) = unique, not shared.
507-
Live = is_dead,
508-
ModuleInfo0 = !.Info ^ imi_module_info,
509-
abstractly_unify_inst(Live, InstA, SubInstB, fake_unify,
510-
Inst, _Det, ModuleInfo0, ModuleInfo),
511-
!Info ^ imi_module_info := ModuleInfo,
512-
update_inst_var_sub(InstVarsB, Inst, Type, !Info)
513-
514-
% This accepts more code but some cases cause infinite recursion.
515-
/*
516498
% Add the substitution InstVarsB => InstA `glb` SubInstB
517499
% (see get_subst_inst in dmo's thesis, page 78).
500+
%
501+
% We pass `Live = is_dead' because we want
502+
% abstractly_unify(unique, unique) = unique, not shared.
518503
ModuleInfo0 = !.Info ^ imi_module_info,
519504
abstractly_unify_inst(is_dead, InstA, SubInstB, fake_unify,
520-
Inst, _Det, ModuleInfo0, ModuleInfo),
505+
UnifyInst, _Det, ModuleInfo0, ModuleInfo),
521506
!Info ^ imi_module_info := ModuleInfo,
522-
update_inst_var_sub(InstVarsB, Inst, Type, !Info),
507+
update_inst_var_sub(InstVarsB, UnifyInst, Type, !Info),
508+
523509
% Check that InstA matches InstB after applying the substitution
524510
% to InstB.
525-
Recurse(InstA, Inst, Type, !Info)
526-
*/
511+
( UnifyInst = constrained_inst_vars(InstVarsB, UnifySubInst) ->
512+
% Avoid infinite regress.
513+
Recurse(InstA, UnifySubInst, Type, !Info)
514+
;
515+
Recurse(InstA, UnifyInst, Type, !Info)
516+
)
527517
; InstA = constrained_inst_vars(_InstVarsA, SubInstA) ->
528518
Recurse(SubInstA, InstB, Type, !Info)
529519
;

tests/EXPECT_FAIL_TESTS.all_grades

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ valid/bug85
44
valid/constraint_prop_bug
55
valid/csharp_hello
66
valid/ho_and_type_spec_bug2
7-
invalid/constrained_poly_insts2

0 commit comments

Comments
 (0)