Mercury Bugs - mercury
View Issue Details
0000239mercuryBugpublic2011-11-30 08:442011-12-05 14:18
Reportercolanderman 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusnewResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000239: Aliasing of partially instantiated structures in solutions.* predicates
DescriptionIf a partially instantiated structure is fully instantiated and output from the generator predicate of one of the solutions.* predicates, then each result generated will point at the same physical structure (see attached example).

This is because multi/nondet predicates do not deep copy partially instantiated structures when filling them in, and solutions.builtin_aggregate does not deep copy while generating results (except in the case of accurate garbage collection).

Since changing the former would result in pervasive ABI changes, I believe that changing solutions.builtin_aggregate to always copy generated results is the correct solution (albeit at a performance hit).
TagsNo tags attached.
Attached Files? agg_bug.m (416) 2011-11-30 08:44
https://bugs.mercurylang.org/file_download.php?file_id=142&type=bug
patch solutions_copy.patch (3,685) 2011-11-30 08:45
https://bugs.mercurylang.org/file_download.php?file_id=143&type=bug

Notes
(0000419)
colanderman   
2011-11-30 08:49   
Attached is a proof-of-concept patch against a 11.07 beta (not CVS, sorry) which fixes the bug in asm_fast.gc, hlc.gc, and java. I believe it also fixes the bug in C# grades, but I cannot test this. I am not sure that the bug exists in Erlang grades.

The attached patch is suboptimal in that it will unnecessarily copy the aggregation result as well. I suppose the changes in the patch should instead create a new predicate similar to partial_deep_copy, but perhaps there is a cleaner method.
(0000431)
mark   
2011-12-05 14:18   
The "bug" here is just that the current implementation does not support partially instantiated data structures, so if you want to use them you should expect to need some workarounds. I don't want to pay the cost of unnecessary copying to partly support a feature that won't be fully supported anyway.

In this case a workaround is to perform the necessary copying yourself in the closure that is passed to solutions.*.

Issue History
2011-11-30 08:44colandermanNew Issue
2011-11-30 08:44colandermanFile Added: agg_bug.m
2011-11-30 08:45colandermanFile Added: solutions_copy.patch
2011-11-30 08:49colandermanNote Added: 0000419
2011-12-05 14:18markNote Added: 0000431