[m-rev.] for review: fix regression after cons_id type_ctor field
Peter Wang
novalazy at gmail.com
Thu Aug 12 17:06:40 AEST 2010
For review by Zoltan.
Branches: main, 10.04
Fix a regression introduced on 2009-06-11 in the change
"Include the type_ctor in cons_ids for user-defined types."
The symptom was an abort in the low-level C code generator when compiling
a call to an implied mode, where the implied argument is of a no-tag type.
The bug below messed up the liveness computation.
compiler/mode_util.m:
Use `equivalent_cons_ids' to compare a cons_id-for-a-type with a
cons_id-for-an-inst as the latter may have a dummy type_ctor field.
tests/valid/Mmakefile:
tests/valid/implied_mode_no_tag.m:
Add test case.
diff --git a/compiler/mode_util.m b/compiler/mode_util.m
index 104a02b..a25ddaa 100644
--- a/compiler/mode_util.m
+++ b/compiler/mode_util.m
@@ -417,7 +417,12 @@ get_single_arg_inst(ModuleInfo, Inst, ConsId, ArgInst) :-
is semidet.
get_single_arg_inst_2([BoundInst | BoundInsts], ConsId, ArgInst) :-
- ( BoundInst = bound_functor(ConsId, [ArgInst0]) ->
+ (
+ BoundInst = bound_functor(InstConsId, [ArgInst0]),
+ % The cons_ids for types and insts can differ in the type_ctor field
+ % so we must ignore them.
+ equivalent_cons_ids(ConsId, InstConsId)
+ ->
ArgInst = ArgInst0
;
get_single_arg_inst_2(BoundInsts, ConsId, ArgInst)
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index 3871fe2..d2c7679 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -122,6 +122,7 @@ OTHER_PROGS= \
ho_unify \
id_type_bug \
implied_mode \
+ implied_mode_no_tag \
impure_lambda_bug \
indexing \
inhibit_warn_test \
diff --git a/tests/valid/implied_mode_no_tag.m b/tests/valid/implied_mode_no_tag.m
new file mode 100644
index 0000000..50deaa5
--- /dev/null
+++ b/tests/valid/implied_mode_no_tag.m
@@ -0,0 +1,18 @@
+% The compiler of 11/06/2009 aborted on this test case.
+
+:- module implied_mode_no_tag.
+:- interface.
+
+:- pred p(string::in) is semidet.
+
+:- implementation.
+
+:- type nt ---> nt(string).
+
+p(S) :-
+ q(S, nt(_)).
+
+:- pred q(string::in, nt::out) is det.
+:- pragma no_inline(q/2).
+
+q(S, nt(S)).
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list