Issue 23945 - ICE caused by std.sumtype
Summary: ICE caused by std.sumtype
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 critical
Assignee: No Owner
URL:
Keywords: ice
Depends on:
Blocks:
 
Reported: 2023-05-30 09:02 UTC by yusharora
Modified: 2023-05-30 12:29 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description yusharora 2023-05-30 09:02:06 UTC
See dlang forum thread: https://forum.dlang.org/post/yiruzleiblljendduqmu@forum.dlang.org

Source: https://gist.github.com/run-dlang/5dd783c750f04329405af1b1e4a83cde

```d
Error: unknown, please file report on issues.dlang.org
/usr/include/dlang/dmd/std/meta.d(632,42): Error: template instance `std.sumtype.matchImpl!(Flag.yes, destroyIfOwner).matchImpl!(SumType!(ConstValueIndex, EnumConstValue, ClassInfoIndex, AnnotationValue, ArrayValue)).matchImpl.valueTypes!4LU.fun!0LU` error instantiating
/usr/include/dlang/dmd/std/sumtype.d(1931,32):        instantiated from here: `Map!(getType, 0LU)`
/usr/include/dlang/dmd/std/sumtype.d(1967,51):        instantiated from here: `valueTypes!4LU`
/usr/include/dlang/dmd/std/sumtype.d(1649,52):        instantiated from here: `matchImpl!(SumType!(ConstValueIndex, EnumConstValue, ClassInfoIndex, AnnotationValue, ArrayValue))`
/usr/include/dlang/dmd/std/sumtype.d(752,17):        instantiated from here: `match!(SumType!(ConstValueIndex, EnumConstValue, ClassInfoIndex, AnnotationValue, ArrayValue))`
source/parser/definitions/attributes.d(262,22):        instantiated from here: `SumType!(ConstValueIndex, EnumConstValue, ClassInfoIndex, AnnotationValue, ArrayValue)`
/usr/include/dlang/dmd/std/sumtype.d(1985,13):        while evaluating: `static assert((__error)(hid))`
Error /usr/bin/dmd failed with exit code 1.
```
Comment 1 FeepingCreature 2023-05-30 12:12:55 UTC
Maybe reduction:

struct SumType()
{    
    ArrayValue value;

    this(ArrayValue value)
    {
        this.value = value;
    }

    static if (__traits(compiles, hashOf(ElementValuePair.init)))
    {
            size_t toHash() { return 0; }
    }
}

struct ArrayValue
{
    ElementValue[] values;
}

struct ElementValuePair
{
    ElementValue element_value;
}

alias ElementValue = SumType!();

====

Error: unknown, please file report on issues.dlang.org

I suspect something with hashOf and struct initialization order. I think this may have been a few steps minified too far, but it's still spitting out "Error: unknown", so...
Comment 2 FeepingCreature 2023-05-30 12:29:26 UTC
As a workaround, sticking this code into AnnotationValue in the original code:

    size_t toHash() const
    {
        return hashOf(annotation_value);
    }

also makes it compile. I think because the hashOf is hidden in a method body, the sema doesn't have to recurse immediately from AnnotationValue into Annotation, which breaks the loop.