-
Notifications
You must be signed in to change notification settings - Fork 4
feat(rt): handle zero-sized locals #809
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
Conversation
|
Related: #675 |
| // Fallback for zero-sized constants whose type metadata was not emitted. | ||
| rule <k> operandConstant(constOperand(_, _, mirConst(constantKindZeroSized, TY, _))) | ||
| => Aggregate(variantIdx(0), .List) | ||
| ... | ||
| </k> | ||
| requires typeInfoVoidType ==K lookupTy(TY) |
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.
Do we actually see this case? (no metadata available)
We have rules for ZeroSized constants with known metadata so if we find this necessary we should investigate it more.
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.
- This is needed by passing the
interior-mut*functions in feat: model interior borrows for refcell #786 - But yes, I can move this rule to another pr to investigate more.
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.
| // Borrowing a zero-sized local that is still `NewLocal`: initialise it, then reuse the regular rule. | ||
| rule <k> rvalueRef(REGION, KIND, place(local(I), PROJS)) | ||
| => #forceSetLocal(local(I), Aggregate(variantIdx(0), .List)) | ||
| ~> rvalueRef(REGION, KIND, place(local(I), PROJS)) | ||
| ... | ||
| </k> | ||
| <locals> LOCALS </locals> | ||
| requires 0 <=Int I andBool I <Int size(LOCALS) | ||
| andBool isNewLocal(LOCALS[I]) | ||
| andBool #zeroSizedType(lookupTy(tyOfLocal(getLocal(LOCALS, I)))) | ||
| [preserves-definedness] // valid list indexing checked, zero-sized locals materialise trivially | ||
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.
These are very useful rules to handle the cases described in #675 .
Maybe we could call #decodeConstant instead of assuming an Aggregate and inserting it directly?
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.
Solved
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.
LGTM
Actually, could you add tests from issue #675 ?
| if not component_tys: | ||
| if data: | ||
| raise ValueError(f'Zero-sized tuple expected empty data, got: {data!r}') | ||
| return AggregateValue(0, []) | ||
|
|
||
| raise ValueError('Tuple decoding with components is not implemented yet') |
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.
Can you please create an issue to add tuple decoding?
It depends on how the layout is, maybe we can just decode the components in sequence? Or can the fields be out of order for tuples?
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.
Here are the issues:
No description provided.