2024-04-20 08:54 AEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000231mercuryBugpublic2014-10-09 12:48
Reportercolanderman 
Assigned To 
PrioritynormalSeveritytrivialReproducibilityalways
StatusnewResolutionopen 
Product Version 
Target VersionFixed in Version 
Summary0000231: No way to specify instantiatedness of char type
DescriptionThere is currently no way to specify the instantiatedness of a char type, e.g.:

:- inst whitespace ---> ' '; '\t'; '\n'.

The above instantiatednesses are represented as atoms, but since instantiatednesses of character values are internally represented as type char_const(), this leads to mode errors such as:

Final instantiatedness of `HeadVar__1' was `bound('\t' ; '\n' ; ' ')',
expected final instantiatedness was `bound('\t' ; '\n' ; ' ')'.

Attached is a patch which fixes this bug.
TagsNo tags attached.
Attached Files
  • ? file icon char_inst.m (222 bytes) 2011-11-22 16:30
  • patch file icon mercury-compiler-char-inst.patch (1,974 bytes) 2011-11-22 16:31 -
    Index: compiler/inst_match.m
    ===================================================================
    RCS file: /home/mercury/mercury1/repository/mercury/compiler/inst_match.m,v
    retrieving revision 1.94
    diff -u -u -r1.94 inst_match.m
    --- compiler/inst_match.m	23 May 2011 05:08:04 -0000	1.94
    +++ compiler/inst_match.m	22 Nov 2011 05:30:28 -0000
    @@ -783,6 +783,30 @@
                 ArityA > ArityB
             )
         ;
    +        ConsIdA = char_const(CharA),
    +        ConsIdB = cons(QNameB, _, _)
    +    ->
    +        string.char_to_string(CharA, NameA),
    +        ( QNameB = unqualified(NameB)
    +        ; QNameB = qualified(_, NameB)
    +        ),
    +        compare((>), NameA, NameB)
    +    ;
    +        ConsIdA = cons(QNameA, ArityA, _),
    +        ConsIdB = char_const(CharB)
    +    ->
    +        ( QNameA = unqualified(NameA)
    +        ; QNameA = qualified(_, NameA)
    +        ),
    +        string.char_to_string(CharB, NameB),
    +        compare(O, NameA, NameB),
    +        (
    +            O = (>)
    +        ;
    +            O = (=),
    +            ArityA > 0
    +        )
    +    ;
             compare((>), ConsIdA, ConsIdB)
         ).
     
    Index: compiler/prog_data.m
    ===================================================================
    RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_data.m,v
    retrieving revision 1.235
    diff -u -u -r1.235 prog_data.m
    --- compiler/prog_data.m	6 Sep 2011 05:20:43 -0000	1.235
    +++ compiler/prog_data.m	22 Nov 2011 05:30:28 -0000
    @@ -1617,6 +1617,20 @@
             ArityA = ArityB,
             SymNameB = unqualified("{}")
         ;
    +        ConsIdA = char_const(CharA),
    +        ConsIdB = cons(SymNameB, ArityB, _)
    +    ->
    +        ArityB = 0,
    +        SymNameB = unqualified(StringB),
    +        string.char_to_string(CharA, StringB)
    +    ;
    +        ConsIdA = cons(SymNameA, ArityA, _),
    +        ConsIdB = char_const(CharB)
    +    ->
    +        ArityA = 0,
    +        SymNameA = unqualified(StringA),
    +        string.char_to_string(CharB, StringA)
    +    ;
             ConsIdA = ConsIdB
         ).
     
    
    patch file icon mercury-compiler-char-inst.patch (1,974 bytes) 2011-11-22 16:31 +

-Relationships
+Relationships

-Notes

~0000795

wangp (developer)

Applying the patch as-is would be unsafe. If you try to switch on the variable following the call to is_whitespace, e.g.

is_whitespace(C),
( C = (' '), ...
; C = ('\t'), ...
; C = ('\n'), ...
)

The inst of C is represented as a list of cons/3 functors and the cases as `char_const' functors. Switch detection does not see them as equivalent so replaces the disjunction by `fail'. I assume other parts of the compiler may have similar problems.
+Notes

-Issue History
Date Modified Username Field Change
2011-11-22 16:30 colanderman New Issue
2011-11-22 16:30 colanderman File Added: char_inst.m
2011-11-22 16:31 colanderman File Added: mercury-compiler-char-inst.patch
2014-10-09 12:48 wangp Note Added: 0000795
+Issue History