Mercury Bugs - mercury
View Issue Details
0000207mercuryBugpublic2011-07-28 10:492011-09-06 10:23
Reporterwangp 
Assigned Tozs 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000207: tree_bitset.difference bug
DescriptionIn the following test case tree_bitset.difference produces the wrong result on 32-bit platforms.

% ./tree_bitset_difference
set: [532, 32431]
tree_bitset: []

This affects the compiler since the recent representation change.
TagsNo tags attached.
Attached Files? tree_bitset_difference.m (1,212) 2011-07-28 10:49
https://bugs.mercurylang.org/file_download.php?file_id=125&type=bug

Notes
(0000342)
zs   
2011-07-28 14:53   
Fix committed 28 July.
(0000343)
wangp   
2011-07-29 10:13   
Unfortunately it was only a partial fix. Here are a few more cases. I don't know if there are significant differences between them.


    test([1, 29424], [1, 2, 3, 35701], !IO),
    test([1], [2, 35701], !IO),
    test([101, 102], [1, 2, 3, 35699, 35700, 35701], !IO),
    test([35696, 35702, 35703, 35704, 35705], [1, 2, 3, 33416, 334283], !IO),
(0000346)
wangp   
2011-08-03 12:07   
(Last edited: 2011-08-03 12:17)
Is this the fix? edit: no.

diff --git a/library/tree_bitset.m b/library/tree_bitset.m
index e01831c..716416f 100644
--- a/library/tree_bitset.m
+++ b/library/tree_bitset.m
@@ -2130,7 +2130,7 @@ difference(SetA, SetB) = Set :-
 interiornode_difference(LevelA, HeadA, TailA, LevelB, HeadB, TailB,
         Level, List) :-
     ( LevelA < LevelB ->
- range_of_parent_node(HeadA ^ init_offset, LevelA + 1,
+ range_of_parent_node(HeadA ^ init_offset, LevelA,
             ParentInitOffsetA, ParentLimitOffsetA),
         (
             find_containing_node(ParentInitOffsetA, ParentLimitOffsetA,

(0000347)
zs   
2011-08-03 19:16   
That fixes one bug, but there are others. I have tentative fixes for another two, but I am reconsidering the wisdom of just fixing bugs in the existing code. The code was designed the way it is because it was supposed to be slow but simple, and the bugs show it isn't simple. It looks like getting a faster design correct may not be that much more work than fixing the slow design.

In the meantime, one possible workaround for the problem is to make set_of_var use sparse_bitset instead of tree_bitset.
(0000359)
zs   
2011-09-06 10:23   
Fix committed a while ago.

Issue History
2011-07-28 10:49wangpNew Issue
2011-07-28 10:49wangpFile Added: tree_bitset_difference.m
2011-07-28 10:50wangpStatusnew => assigned
2011-07-28 10:50wangpAssigned To => zs
2011-07-28 14:53zsNote Added: 0000342
2011-07-28 14:53zsStatusassigned => resolved
2011-07-28 14:53zsResolutionopen => fixed
2011-07-29 10:13wangpNote Added: 0000343
2011-07-29 10:13wangpStatusresolved => feedback
2011-07-29 10:13wangpResolutionfixed => reopened
2011-08-02 14:52wangpNote Added: 0000345
2011-08-02 15:38wangpNote Deleted: 0000345
2011-08-03 12:07wangpNote Added: 0000346
2011-08-03 12:07wangpStatusfeedback => assigned
2011-08-03 12:17wangpNote Edited: 0000346
2011-08-03 19:16zsNote Added: 0000347
2011-09-06 10:23zsNote Added: 0000359
2011-09-06 10:23zsStatusassigned => resolved
2011-09-06 10:23zsResolutionreopened => fixed