-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Possible disagreement on categorisation of value during MIR build and PromoteTemps pass #147021
Copy link
Copy link
Open
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-arrayArea: `[T; N]`Area: `[T; N]`A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-arrayArea: `[T; N]`Area: `[T; N]`A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I tried this code, before #145277, courtesy of @traviscross in a comment:
I expected to see this happen: every
assert_eq!should triggerInstead, this happened: execution passes
The reason I am opening this issue is to discuss a comprehensive plan to resolve the remaining concern over #145277. We would discover more corner cases and it would become unmanagable if we have to fix these cases one at a time.
Problem statement
Current MIR building from THIR, when repeat expression
[$expr; $const]is concerned, needs to know the following information to decide how this kind of expression would be lowered:$consttakes a value of0,1or anything else$exprhas aCopytype$expris a const-promotableThe prominent feature of the lowering is whether
$exprshall be "built" for evaluation. If$expris materialised, it has significance such that adropis mandatory. However, the materialisation can be superfluous if the value would not end up used in the repeat expression because$constcould be statically evaluated to0; or thedropis unnecessary because$constcould be statically evaluated to1.$expr\ compile-time value of$constCopyHowever, determine whether
$expris const-promotable happens after the MIR building. The MIR builder has to apply a simple, but not satisfyingly comprehensive, check to decide which case in the table above shall be applicable.