GaloisInc / saw-script

The SAW scripting language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `mir_lifetime` combinator for looking up types with lifetime substitutions

RyanGlScott opened this issue · comments

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