Stream: t-compiler/help

Topic: What is promotion?


Xavier Denis (Jul 31 2020 at 14:41, on Zulip):

What exactly is promotion in rustc? is it like lambda lifting in functional compilers? just lifting closures / constants to the top level? Also, where can I find the rules governing what can and cannot be promoted?

lcnr (Jul 31 2020 at 14:44, on Zulip):

See https://github.com/rust-lang/const-eval/blob/master/promotion.md,

const promotion allows for things like let x: &'static str = &(3 + 4); by promoting the result of 3 + 4 to a constant

davidtwco (Jul 31 2020 at 14:44, on Zulip):

(someone should write https://rustc-dev-guide.rust-lang.org/mir/index.html?highlight=promotion#promoted-constants)

oli (Jul 31 2020 at 14:45, on Zulip):

Someone wrote https://doc.rust-lang.org/stable/reference/destructors.html?highlight=promotion#constant-promotion :wink:

oli (Jul 31 2020 at 14:46, on Zulip):

but yes, the rustc internals should be documented

davidtwco (Jul 31 2020 at 14:46, on Zulip):

I never think to check the reference.

Edd Barrett (Sep 03 2020 at 10:16, on Zulip):

I didn't understand the first sentence of the link @oli posted:

Promotion of a value expression to a 'static slot occurs when the expression could be written in a constant, borrowed, and dereferencing that borrow where the expression was originally written, without changing the runtime behavior.

Edd Barrett (Sep 03 2020 at 10:16, on Zulip):

Could use a re-wording?

Last update: Jan 22 2021 at 13:15UTC