Skip to content
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

Never emit lifetime substitutions #58

Open
RyanGlScott opened this issue Nov 13, 2023 · 0 comments
Open

Never emit lifetime substitutions #58

RyanGlScott opened this issue Nov 13, 2023 · 0 comments

Comments

@RyanGlScott
Copy link
Contributor

Currently, mir-json is rather inconsistent about when it erases Lifetime in compiled code or not. Here is an example to illustrate the problem:

pub struct S<'a> {
    pub x: &'a u32,
}

pub fn f<'a>(y: &'a u32) -> S<'a> {
    S { x: y }
}

When the compiled MIR for f is pretty-printed, it looks like this:

fn test/7ab66983::f[0](_1 : &u32) -> test/7ab66983::S[0]<lifetime> { ... }

Note the <lifetime> substitution in the occurrence of S. This is unfortunate, as lifetimes are meant to be erased during compilation, and their presence in the MIR code means that SAW users have to manually instantiate S with lifetime to get what they want. What's more, not all types carry around explicit lifetime substitutions (note that the MIR JSON contains &u32, not &'a u32).

lifetimes are currently emitted here:

// In crucible-mir, all substs entries are considered "types", and there are dummy
// TyLifetime and TyConst variants to handle non-type entries. We emit something that
// looks vaguely like an interned type's ID here, and handle it specially in MIR.JSON.
ty::subst::GenericArgKind::Lifetime(_) => json!("nonty::Lifetime"),

We should strive to avoid emitting lifetime substitutions at all to prevent users from having to care about them.

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

No branches or pull requests

1 participant