Skip to content

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

Merged
merged 9 commits into from
Oct 22, 2019

Conversation

ecstatic-morse
Copy link
Contributor

@ecstatic-morse ecstatic-morse commented Oct 11, 2019

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 in qualify_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 and static". 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

@RalfJung
Copy link
Member

This needs rebasing now that my PR landed.

@ecstatic-morse
Copy link
Contributor Author

Rebased. There's now two sections about & in consts and statics. I will resolve this once the terminology is decided, since the section I added might go away.

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
Copy link
Contributor

@oli-obk oli-obk Oct 19, 2019

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 Cells

@oli-obk
Copy link
Contributor

oli-obk commented Oct 19, 2019

lgtm other than the clarification about which constants get promoted

@oli-obk oli-obk merged commit 220938f into rust-lang:master Oct 22, 2019
@@ -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
Copy link
Member

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants