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

Add mir_lifetime combinator for looking up types with lifetime substitutions #2005

Closed
RyanGlScott opened this issue Jan 12, 2024 · 0 comments · Fixed by #2006
Closed

Add mir_lifetime combinator for looking up types with lifetime substitutions #2005

RyanGlScott opened this issue Jan 12, 2024 · 0 comments · Fixed by #2006
Assignees
Labels
subsystem: crucible-mir Issues related to Rust verification with crucible-mir and/or mir-json type: enhancement Issues describing an improvement to an existing feature or capability

Comments

@RyanGlScott
Copy link
Contributor

If you write code that looks like this:

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

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

Then the resulting MIR for the f function will be:

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

Note that the return type is S<lifetime>, but MIR currently lacks a combinator to pass to mir_find_adt in order to instantiate S with lifetime. We should add a mir_lifetime : MIRType SAWScript combinator so that users can write mir_find_adt m "example::S" [mir_lifetime].

Note that this should be considered a stopgap measure until GaloisInc/mir-json#58 is fixed. Once that issue is fixed, then mir-json will never emit types that require lifetime substitutions, at which point mir_lifetime will become moot (and should be removed). That being said, implementing mir_lifetime will likely be much easier than fixing GaloisInc/mir-json#58, so it would be worth fixing this issue first so that specs involving lifetimes will work in the meantime.

Here is a first attempt at a mir_lifetime implementation (without the accompanying SAW manual explanation, tests, etc.):

diff --git a/src/SAWScript/Interpreter.hs b/src/SAWScript/Interpreter.hs
index c8e360f3e..b9991f3d7 100644
--- a/src/SAWScript/Interpreter.hs
+++ b/src/SAWScript/Interpreter.hs
@@ -4168,6 +4168,11 @@ primitives = Map.fromList
     Experimental
     [ "The type of MIR double-precision floating-point values." ]
 
+  , prim "mir_lifetime" "MIRType"
+    (pureVal Mir.TyLifetime)
+    Experimental
+    [ "The type of MIR lifetimes." ]
+
   , prim "mir_ref" "MIRType -> MIRType"
     (pureVal mir_ref)
     Experimental
@RyanGlScott RyanGlScott added type: enhancement Issues describing an improvement to an existing feature or capability subsystem: crucible-mir Issues related to Rust verification with crucible-mir and/or mir-json labels Jan 12, 2024
@RyanGlScott RyanGlScott self-assigned this Jan 12, 2024
RyanGlScott added a commit that referenced this issue Jan 12, 2024
@mergify mergify bot closed this as completed in #2006 Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
subsystem: crucible-mir Issues related to Rust verification with crucible-mir and/or mir-json type: enhancement Issues describing an improvement to an existing feature or capability
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant