Skip to content

Commit

Permalink
Contexts that can be serialized + deserialized while retaining and ex…
Browse files Browse the repository at this point in the history
…plicitly representing sharing (#2202)

Towards #2107.  Instead of simply storing a `Map`, contexts now also store a structured tree representing how it was built, and cache homomorphic hash values so contexts can be compared + stored by hash.  This allows us to serialize contexts into a compact form that never duplicates any context, then deserialize them in a way that restores all the sharing.

The big thing that is left is to make `FromJSONE` instances for `Value` and `Env` (and anything which contains them).  I was working on these but got bogged down, so decided to not let the perfect be the enemy of the good.  You can see some commented-out code towards a `FromJSONE Value` instance.  But we don't use any such instances yet, so I think this can be merged as is, and the rest worked out later.
  • Loading branch information
byorgey authored Nov 22, 2024
1 parent c5baa52 commit 3e05a07
Show file tree
Hide file tree
Showing 15 changed files with 454 additions and 68 deletions.
8 changes: 1 addition & 7 deletions src/swarm-engine/Swarm/Game/CESK.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ data Frame
instance ToJSON Frame where
toJSON = genericToJSON optionsMinimize

instance FromJSON Frame where
parseJSON = genericParseJSON optionsMinimize

-- | A continuation is just a stack of frames.
type Cont = [Frame]

Expand All @@ -184,7 +181,7 @@ type Addr = Int
-- | 'Store' represents a store, /i.e./ memory, indexing integer
-- locations to 'Value's.
data Store = Store {next :: Addr, mu :: IntMap Value}
deriving (Show, Eq, Generic, FromJSON, ToJSON)
deriving (Show, Eq, Generic, ToJSON)

emptyStore :: Store
emptyStore = Store 0 IM.empty
Expand Down Expand Up @@ -269,9 +266,6 @@ data CESK
instance ToJSON CESK where
toJSON = genericToJSON optionsMinimize

instance FromJSON CESK where
parseJSON = genericParseJSON optionsMinimize

-- | Is the CESK machine in a final (finished) state? If so, extract
-- the final value and store.
finalValue :: CESK -> Maybe Value
Expand Down
2 changes: 1 addition & 1 deletion src/swarm-engine/Swarm/Game/State/Substate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ data REPLStatus
-- entered. The @Maybe Value@ starts out as 'Nothing' and gets
-- filled in with a result once the command completes.
REPLWorking Polytype (Maybe Value)
deriving (Eq, Show, Generic, FromJSON, ToJSON)
deriving (Eq, Show, Generic, ToJSON)

data WinStatus
= -- | There are one or more objectives remaining that the player
Expand Down
Loading

0 comments on commit 3e05a07

Please sign in to comment.