Mercury Bugs - mercury
View Issue Details
0000187mercuryBugpublic2011-03-06 17:122015-10-31 21:00
Reportercolanderman 
Assigned Tojuliensf 
PrioritynormalSeverityminorReproducibilityalways
StatusconfirmedResolutionopen 
PlatformOSOS Version
Product Version 
Target Version15.11Fixed in Version 
Summary0000187: Strange error with disjunctive definitions returning existential typeclass instance
DescriptionI don't know how to describe this but with code. Compile it and observe the error. Now uncomment the last line, and comment out the two preceding (to use an equivalent definition of the function f). Recompile and it works as expected.
TagsNo tags attached.
related to 0000271closed pbone Polymorphism related compiler crash. 
Attached Files? test.m (265) 2011-03-06 17:12
https://bugs.mercurylang.org/file_download.php?file_id=113&type=bug

Notes
(0000546)
juliensf   
2013-06-28 14:55   
(Last edited: 2013-06-28 14:57)
The problem here is that polymorphism transforms the multi-clause version into the following:

% Clause 1.
test.f(TypeClassInfo_for_foo_3, HeadVar__1_1) = HeadVar__2_2 :-
  (
    ( HeadVar__1_1 = test.x,
      HeadVar__2_2 = test.a
    ),
    TypeClassInfo_for_foo_4 = typeclass_info_const(0),
    TypeClassInfo_for_foo_3 = TypeClassInfo_for_foo_4
  ).

% Clause 2
test.f(TypeClassInfo_for_foo_3, HeadVar__1_1) = HeadVar__2_2 :-
  (
    (
      HeadVar__1_1 = test.y,
      HeadVar__2_2 = test.b
    ),
    TypeClassInfo_for_foo_3 = TypeClassInfo_for_foo_4
  ).

In the second clause TypeClassInfo_for_foo_4 is free. It should presumably have been pointed
at typeclass_info_const(0) as in the first clause, but that hasn't happened for some reason.
(Possibly, the mapping of typeclass_infos to static data is being maintained across clauses, so it thinks
that it has already introduced the unification with the constant when it processes the second clause.)

(A workaround here is to re-write the predicate with a single clause -- as mentioned in the original bug report -- since polymorphism will process that in one go and the issue won't arise.)

(0000548)
pbone   
2013-06-28 15:45   
Possibly related to bug 0000271. When fixing this consider the fix for 0000271 and also retest 0000271.

Issue History
2011-03-06 17:12colandermanNew Issue
2011-03-06 17:12colandermanFile Added: test.m
2013-06-28 14:55juliensfNote Added: 0000546
2013-06-28 14:56juliensfAssigned To => juliensf
2013-06-28 14:56juliensfStatusnew => confirmed
2013-06-28 14:56juliensfNote Edited: 0000546bug_revision_view_page.php?bugnote_id=546#r12
2013-06-28 14:57juliensfNote Edited: 0000546bug_revision_view_page.php?bugnote_id=546#r13
2013-06-28 15:44pboneRelationship addedrelated to 0000271
2013-06-28 15:45pboneNote Added: 0000548
2015-10-31 21:00juliensfProduct Version => 15.11
2015-10-31 21:00juliensfProduct Version15.11 =>
2015-10-31 21:00juliensfTarget Version => 15.11