-
Notifications
You must be signed in to change notification settings - Fork 3
499 enum support in mir-semantics #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
499 enum support in mir-semantics #521
Conversation
syntax Int ::= #lookupDiscriminant ( TypeInfo , VariantIdx ) [function, total] | ||
| #lookupDiscrAux ( Discriminants , VariantIdx ) [function] | ||
// -------------------------------------------------------------------- | ||
rule #lookupDiscriminant(typeInfoEnumType(_, _, DISCRIMINANTS), IDX) => #lookupDiscrAux(DISCRIMINANTS, IDX) | ||
requires isInt(#lookupDiscrAux(DISCRIMINANTS, IDX)) [preserves-definedness] | ||
rule #lookupDiscriminant(_OTHER, _) => 0 [owise, preserves-definedness] // default 0. May be undefined behaviour, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this default returning 0
, we could signal undefined behaviour - if it was clear what exactly constitutes undefined behaviour here, the discussion on rust-lang/rust#91095 remains unresolved IIUC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is consistent with miri which is probably good to start with. But I think signalling UB would be good for a future version
4f57b7b
to
d8f38c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jost and I chatted through this on a call and I agree with the reasoning.
syntax Int ::= #lookupDiscriminant ( TypeInfo , VariantIdx ) [function, total] | ||
| #lookupDiscrAux ( Discriminants , VariantIdx ) [function] | ||
// -------------------------------------------------------------------- | ||
rule #lookupDiscriminant(typeInfoEnumType(_, _, DISCRIMINANTS), IDX) => #lookupDiscrAux(DISCRIMINANTS, IDX) | ||
requires isInt(#lookupDiscrAux(DISCRIMINANTS, IDX)) [preserves-definedness] | ||
rule #lookupDiscriminant(_OTHER, _) => 0 [owise, preserves-definedness] // default 0. May be undefined behaviour, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is consistent with miri which is probably good to start with. But I think signalling UB would be good for a future version
Aggregate
values, which now carry the variant indexAggregate
s forstruct
s andenum
s now have a correctTy
field (stillTyUnknown
for tuples, though)RValue::Discriminant
is implemented:enum
, it looks up the discriminant and returns it as au128
(discriminant type information unavailable)Aggregate
s, it will always return0
(see related discussion inrustc
: Decide on when MIR Discriminant() operation is UB rust-lang/rust#91095)This is a first step. The data returned by
Discriminant
is actually not consistent (bit width and signedness do not match the indicatedTy
), which will cause issues if the obtained discriminant is used in any way other than as aSwitchInt
argument.Fixes #499