replace CryptolEnvStack with scopes within CryptolEnv#3242
replace CryptolEnvStack with scopes within CryptolEnv#3242danmatichuk wants to merge 10 commits into
Conversation
e1bde62 to
45e96ed
Compare
dbf2a17 to
dfc303c
Compare
8beef55 to
4c575af
Compare
fixes issue where restoring a checkpoint to before initialization would throw away data that would otherwise have been preserved
350fb67 to
9e1653d
Compare
sauclovian-g
left a comment
There was a problem hiding this comment.
Some comments from a first run, mostly cosmetic stuff.
The basic approach seems sound.
| -- This is intended to be a write-once record of any work done | ||
| -- during translation, analagous to the 'SharedContext' from | ||
| --- SAWCore. Rather than directly accessing this environment, |
There was a problem hiding this comment.
| -- This is intended to be a write-once record of any work done | |
| -- during translation, analagous to the 'SharedContext' from | |
| --- SAWCore. Rather than directly accessing this environment, | |
| -- | |
| -- This is intended to be a write-once record of any work done | |
| -- during translation, analogous to the 'SharedContext' from | |
| -- SAWCore. Rather than directly accessing this environment, |
There was a problem hiding this comment.
(and similarly below and elsewhere, please put empty lines between comment paragraphs and include the initial -- in them so it's all one big comment (I'm not sure offhand if Haddock will collect or ignore following comment fragments, but I think it will probably ignore them and that's not what we want...))
| -- includes a scoped naming environment via 'CryptolScope'. | ||
|
|
||
|
|
||
| -- |
There was a problem hiding this comment.
Did you mean to keep the rest of this? Hopefully it's now out of date
(also some of it, like "There is now one environment type", is now wrong)
| } | ||
|
|
||
| -- | Initialize the global environment with the given 'ME.ModuleEnv', | ||
| -- and populate the 'geAllVars' accordingly. |
There was a problem hiding this comment.
| -- and populate the 'geAllVars' accordingly. | |
| -- and populate the 'geAllVars' field accordingly. |
| let newMEnv = geModuleEnv chk | ||
| chkMEnv = geModuleEnv now |
There was a problem hiding this comment.
These names seem backwards...?
| let env1 = pushScope env0 | ||
| (a, env2) <- f env1 | ||
| unless (sameHeight env1 env2) $ | ||
| fail "withFreshScope: mismatched push/pops" |
There was a problem hiding this comment.
This should probably be a panic. There seems to be only one user, that doesn't abuse it.
| let _cryenv = cc ^. jccCryptolEnv | ||
| ety_tm <- liftIO $ Cryptol.translateType sc ety |
There was a problem hiding this comment.
| let _cryenv = cc ^. jccCryptolEnv | |
| ety_tm <- liftIO $ Cryptol.translateType sc ety | |
| ety_tm <- liftIO $ Cryptol.translateType sc ety |
| -- NOTE: implementation of loadCryptolModule, now uses this default: | ||
| -- defaultPrimitiveOptions = ImportPrimitiveOptions{allowUnknownPrimitives=True} | ||
| import_env <- refreshCryptolEnv env | ||
| let import_env = env |
There was a problem hiding this comment.
Can you remove this? The only thing that uses it downstream doesn't need it.
| CryptolModule -> | ||
| IO (Either TranslationError [Rocq.Decl]) | ||
| translateCryptolModule sc env configuration globalDecls (CryptolModule _ tm) = | ||
| translateCryptolModule sc _env configuration globalDecls (CryptolModule _ tm) = |
There was a problem hiding this comment.
Can you remove this one? It only has the one call site
| primEnviron :: Options -> BuiltinContext -> CryptolEnvStack -> Environ | ||
| primEnviron opts bic cryenvs = | ||
| primEnviron :: Options -> BuiltinContext -> CEnv.CryptolEnv -> Environ | ||
| primEnviron opts bic env = |
There was a problem hiding this comment.
| primEnviron opts bic env = | |
| primEnviron opts bic cenv = |
| varenv = ScopedMap.push $ ScopedMap.seed $ primValueEnv opts bic | ||
| in | ||
| Environ varenv tyenv cryenvs | ||
| Environ varenv tyenv env |
There was a problem hiding this comment.
| Environ varenv tyenv env | |
| Environ varenv tyenv cenv |
There are too many things just "env" could be...
fixes #3167 and #2860
splits up the
CryptolEnvdatatype intoGlobalCryptolEnvfor globally-tracked Cryptol translation data, andCryptolEnvfor data that's only relevant for scoping "extra" names (i.e. injected SAWScript values) needed for parsing Cryptol.The
GlobalCryptolEnvis stored as global metadata in theSharedContext, and only accessible indirectly via the functions inCryptolSAWCore.GlobalCryptolEnv. In the majority of cases, functions with the shapeSharedContext -> CryptolEnv -> a -> IO (b, CryptolEnv)have been rewritten intoSharedContext -> a -> IO b.The previous
CryptolEnvStackhas been replaced by havingCryptolEnvitself provide push/pop scope functions. Importantly, the data fromGlobalCryptolEnvthat was previously part of this stack is now unscoped. This is internally consistent because the names in the global environment are globally-unique (generated with unique nonces from the Cryptol module environment).Although this reworks a large chunk of the Cryptol environment code, this change shouldn't affect any currently-working SAW scripts, but should resolve issues with SAWScript scopes capturing stale Cryptol environments.