Skip to content

[refactoring] MIR stores the return_ty field in two places! #46001

Closed
@nikomatsakis

Description

@nikomatsakis

Right now, the MIR has a special field, return_ty:

/// Return type of the function.
pub return_ty: Ty<'tcx>,

However, the MIR also has an array of locals, and the 0th local is the "return slot". Its type is the return type:

/// Declarations of locals.
///
/// The first local is the return value pointer, followed by `arg_count`
/// locals for the function arguments, followed by any user-declared
/// variables and temporaries.
pub local_decls: LocalDecls<'tcx>,

It would be nice to eliminate the redundancy. My preference would be to remove the return_ty field, perhaps adding an accessor to Mir<'tcx> like:

fn return_ty(&self) -> Ty<'tcx> {
    self.local_vars[RETURN_POINTER].ty
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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

    No branches or pull requests

    Issue actions