-
Notifications
You must be signed in to change notification settings - Fork 17
Define promotion contexts and promotability #28
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
Define promotion contexts and promotability #28
Conversation
This needs rebasing now that my PR landed. |
e6d1254
to
10543e9
Compare
Rebased. There's now two sections about |
This is useful inside a const-context as well.
promotion.md
Outdated
|
||
### Access to a `const` or `static` | ||
|
||
Accesses to `const`s are always promotable, regardless of the body of the |
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.
well, not quite "regardless". You still can't promote Cell
s
lgtm other than the clarification about which constants get promoted |
4436f9c
to
3ccf570
Compare
@@ -1,6 +1,16 @@ | |||
# Const promotion | |||
|
|||
["(Implicit) Promotion"][promotion-rfc] is a mechanism that affects code like `&3`: | |||
"Promotion" is the act of guaranteeing that code not written in a const context | |||
(e.g. initalizer of a `const` or `static`, or an array length expression) will |
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 examples for code in const-context, right? Because to me this reads like examples for "code not written in a const context".
This adds an introduction to
promotion.md
that explains promotion in terms of "promotion contexts" (e.g.&expr
,[expr; 32]
) and "promotability" (the rules for which expressions can be promoted in a given context). This is a variation on the terminology described in this comment, which I was using to reason about the code inqualify_consts.rs
while working on dataflow-based const qualification.I'm not asserting that this mental model is the correct one. In particular, you can see some inconsistencies in the section called "Lifetime extension in
const
andstatic
". Hopefully it can serve as a starting point.This also adds some requirements that were missing from the "Rules" section (now renamed to "Promotability"). These requirements are mostly structural ones (single assignment, no named variables), so maybe they should go in a different section?
cc @RalfJung @oli-obk