Mercury Bugs - mercury
View Issue Details
0000278mercuryBugpublic2013-04-04 23:162015-10-29 14:47
Assigned Tozs 
Platformx86_64OSDebian LinuxOS Version7.0
Product Version 
Target Version15.11Fixed in Version 
Summary0000278: Compiler crash from bad state variable use.
DescriptionIf I refer to the wrong state variable in the head of a lambda expression, I can reliably crash the compiler. I have a test case.
Steps To ReproduceAttached in the testcase It crashes when I compile it with 'mmc --make' It also crashes in the Java grade.

mmc -V prints out the following just before the crash.
% Converting parse tree to hlds...
% Processing clause 1 for predicate `bug.main/2'...
% Processing clause 1 for predicate `bug.build_map/5'...

The exception thrown is:
Uncaught Mercury exception:
Software Error: hlds.make_hlds.state_var: predicate `hlds.make_hlds.state_var.svar_find_final_renames_and_copy_goals'/7: Unexpected: readonly status
Stack dump not available in this grade.
** Error making `Mercury/cs/bug.c'.

I'm using the 12.08 beta (The release MCit is using)
TagsNo tags attached.
Attached Files? bug278.m (841) 2013-04-04 23:19

2013-04-10 16:06   
In principle this is easy to fix, just replace the relevant call to unexpected/2 in compiler/state_var.m
with something that generates a proper error message. The issue is: what should that error message
be? (Probably, before zs rewrote the state var transformation this would have been picked up
later by mode checking ...)
2013-04-10 16:07   
It (hopefully) goes without saying, that this has nothing do with what backend is being used!
2013-05-29 00:43   
Actually, with Mercury 10.04.2, lots of phases picked up the error:

bug278.m:023: In clause for predicate `build_map'/5:
bug278.m:023: in argument 1 of call to predicate `list.foldl2'/6:
bug278.m:023: type error: argument has type `pred(tree234.tree234(K, V), V,
bug278.m:023: tree234.tree234(K, V), V_11, V_9)',
bug278.m:023: expected type was `pred(L, A, A, Z, Z)'.
bug278.m:023: In clause for predicate `bug278.build_map'/5:
bug278.m:023: warning: variable `STATE_VARIABLE_MemoTable' occurs only once
bug278.m:023: in this scope.
bug278.m:028: In clause for predicate `build_map'/5:
bug278.m:028: in argument 1 (i.e. the predicate term) of higher-order
bug278.m:028: predicate call:
bug278.m:028: type error: variable `KeyToValue' has type `(some [K, V]
bug278.m:028: pred(K, V))',
bug278.m:028: expected type was `pred(V_13, V_12, V_11, V_10)'.
bug278.m:030: In clause for predicate `build_map'/5:
bug278.m:030: in implicit state variable unification:
bug278.m:030: type error in unification of variable `STATE_VARIABLE_M_1'
bug278.m:030: and variable `STATE_VARIABLE_M_0'.
bug278.m:030: `STATE_VARIABLE_M_1' has type `tree234.tree234(K, V)',
bug278.m:030: `STATE_VARIABLE_M_0' has type `V'.

The issue here is: what is an appropriate error message to generate during the state var transformation?
2015-10-22 06:49   
fix committed 2015 oct 22.

Issue History
2013-04-04 23:16pboneNew Issue
2013-04-04 23:19pboneFile Added: bug278.m
2013-04-10 16:06juliensfNote Added: 0000502
2013-04-10 16:06juliensfAssigned To => juliensf
2013-04-10 16:06juliensfStatusnew => confirmed
2013-04-10 16:07juliensfNote Added: 0000503
2013-05-29 00:43juliensfNote Added: 0000532
2015-10-21 11:33zsAssigned Tojuliensf => zs
2015-10-21 11:33zsStatusconfirmed => assigned
2015-10-22 06:49zsNote Added: 0000856
2015-10-22 06:49zsStatusassigned => resolved
2015-10-22 06:49zsResolutionopen => fixed
2015-10-29 14:47pboneTarget Version => 15.11