From c68ecfc82b7dddeac6d52c856bb4f743b20027e9 Mon Sep 17 00:00:00 2001 From: Iavor Diatchki Date: Wed, 31 Jan 2024 10:57:15 -0800 Subject: [PATCH] Make the `cryptol-remote-api` build again. It looks like the code previously just a had a placeholder for `newtypes`. Now it sends a bit more info for nominal types, but I am not sure that the rest of the code would handle these correctly. --- .../src/CryptolServer/Data/Expression.hs | 2 +- cryptol-remote-api/src/CryptolServer/Data/Type.hs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cryptol-remote-api/src/CryptolServer/Data/Expression.hs b/cryptol-remote-api/src/CryptolServer/Data/Expression.hs index 623775513..97797d976 100644 --- a/cryptol-remote-api/src/CryptolServer/Data/Expression.hs +++ b/cryptol-remote-api/src/CryptolServer/Data/Expression.hs @@ -617,7 +617,7 @@ readBack ty val = TVTuple{} -> "tuple" TVRec{} -> "record" TVFun{} -> "fun" - TVNewtype nt _ _ -> identText $ nameIdent $ TC.ntName nt + TVNominal nt _ _ -> identText $ nameIdent $ TC.ntName nt TVAbstract{} -> "abstract" diff --git a/cryptol-remote-api/src/CryptolServer/Data/Type.hs b/cryptol-remote-api/src/CryptolServer/Data/Type.hs index 1cbb9f355..f62e8cf34 100644 --- a/cryptol-remote-api/src/CryptolServer/Data/Type.hs +++ b/cryptol-remote-api/src/CryptolServer/Data/Type.hs @@ -20,7 +20,10 @@ import Cryptol.Parser.Position (emptyRange) import Cryptol.Parser.Selector (ppSelector) import Cryptol.Utils.RecordMap (recordFromFields) import Cryptol.TypeCheck.PP (NameMap, emptyNameMap, ppWithNames) -import Cryptol.TypeCheck.Type (Kind(..), PC(..), TC(..), TCon(..), TFun(..), TParam(..), Type(..), Schema(..), addTNames, kindOf) +import Cryptol.TypeCheck.Type (Kind(..), PC(..), TC(..), TCon(..), + TFun(..), TParam(..), Type(..), Schema(..), addTNames, kindOf, + NominalType(..), NominalTypeDef(..) + ) import Cryptol.Utils.Ident (mkIdent) import Cryptol.Utils.PP (pp) import Cryptol.Utils.RecordMap (canonicalFields) @@ -213,8 +216,13 @@ instance JSON.ToJSON JSONType where , "name" .= show (ppWithNames ns v) ] convert (TUser _n _args def) = convert def - convert (TNewtype _nt _ts) = - JSON.object [ "type" .= T.pack "newtype" ] + convert (TNominal nt ts) = + JSON.object [ "type" .= case ntDef nt of + Struct {} -> T.pack "newtype" + Enum {} -> T.pack "enum" + , "name" .= show (pp (ntName nt)) + , "arguments" .= map (JSONType ns) ts + ] convert (TRec fields) = JSON.object [ "type" .= T.pack "record"