Define promotion contexts and promotability#28
Merged
oli-obk merged 9 commits intorust-lang:masterfrom Oct 22, 2019
Merged
Conversation
Member
|
This needs rebasing now that my PR landed. |
e6d1254 to
10543e9
Compare
Contributor
Author
|
Rebased. There's now two sections about |
This is useful inside a const-context as well.
ecstatic-morse
commented
Oct 11, 2019
ecstatic-morse
commented
Oct 11, 2019
oli-obk
reviewed
Oct 19, 2019
promotion.md
Outdated
|
|
||
| ### Access to a `const` or `static` | ||
|
|
||
| Accesses to `const`s are always promotable, regardless of the body of the |
Contributor
There was a problem hiding this comment.
well, not quite "regardless". You still can't promote Cells
Contributor
|
lgtm other than the clarification about which constants get promoted |
4436f9c to
3ccf570
Compare
RalfJung
reviewed
Nov 16, 2019
|
|
||
| ["(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 |
Member
There was a problem hiding this comment.
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds an introduction to
promotion.mdthat 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.rswhile 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
constandstatic". 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