Skip to content

Do NRVO when type of returned local does not match return type #72428

Closed
@ecstatic-morse

Description

@ecstatic-morse
Contributor

#72205 will fail to fire for code such as the following:

fn foo(x: &mut i32) -> &i32 { x }

This is because, by the time we get to the RenameReturnPlace pass, the reborrow has been optimized away and we have MIR like:

_0: &i32 = _1: &mut i32

To merge these locals, we need to pick a type for the unified LocalDecl. However, I wasn't sure how or if codegen makes use of the types of locals, so for now #72205 just doesn't run if the locals have different type. We should come up with a solution here.

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-mir-optArea: MIR optimizations
A-mir-opt-nrvoFixed by the Named Return Value Opt. (NRVO)
on May 21, 2020
ecstatic-morse

ecstatic-morse commented on May 21, 2020

@ecstatic-morse
ContributorAuthor

Worth noting that an initial perf run of #72205 was a bit faster than the one for the version that was merged. This issue is one plausible explanation, although there was also an LLVM upgrade in between.

added 2 commits that reference this issue on May 25, 2020

Rollup merge of rust-lang#72451 - ecstatic-morse:nrvo-type-mismatch, …

123d918

Rollup merge of rust-lang#72451 - ecstatic-morse:nrvo-type-mismatch, …

036688f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsA-mir-opt-nrvoFixed by the Named Return Value Opt. (NRVO)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jonas-schievink@ecstatic-morse

      Issue actions

        Do NRVO when type of returned local does not match return type · Issue #72428 · rust-lang/rust