Mercury Bugs - mercury
View Issue Details
0000047mercuryBugpublic2008-02-25 11:432008-02-25 13:29
Assigned To 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000047: mutable dependency problem
DescriptionThe program (attached) contains two mutables `a' and `b' whose initialisation mutually depends on each other. Thus to initialise `a' we need the value of `b' and vice versa. Mercury does not detect this problem, and happily compiles the program, which (unsurprisingly) seg. faults when you try and run it.

Note that non-mutual dependencies may also be a problem, depending on the order the mutables are initialised. This is how the bug was discovered.
TagsNo tags attached.
Attached Files? crash.m (485) 2008-02-25 11:43

2008-02-25 13:29   
In *this* case it could be detected, but in general it is not possible to detect this at compile-time.

The order in which mutables are initialised is specified in the reference manual, for initialisations
within a module it is:

    For the purposes of determining when mutables are assigned their initial values, the expression `initial_value' behaves as though it were a predicate specified in an `initialise' directive.

There is no initialisation order assumed beteween (sub-)modules.

As a matter of practice I recommend that mutable initialisation expressions should not call mutable
access predicates (I will add this to the reference manual).

Issue History
2008-02-25 11:43user57New Issue
2008-02-25 11:43user57File Added: crash.m
2008-02-25 13:29juliensfNote Added: 0000079