mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 10:35:57 +03:00
add uniqueTypeGuid stub to parsing env
This commit is contained in:
parent
5ae45600c2
commit
607e152aa3
@ -77,8 +77,10 @@ unsafeParseFileBuiltinsOnly ::
|
||||
unsafeParseFileBuiltinsOnly =
|
||||
unsafeReadAndParseFile $
|
||||
Parser.ParsingEnv
|
||||
mempty
|
||||
(Names.NamesWithHistory Builtin.names0 mempty)
|
||||
{ uniqueNames = mempty,
|
||||
uniqueTypeGuid = \_ -> pure Nothing,
|
||||
names = Names.NamesWithHistory Builtin.names0 mempty
|
||||
}
|
||||
|
||||
unsafeParseFile :: Monad m => String -> Parser.ParsingEnv m -> m (UnisonFile Symbol Ann)
|
||||
unsafeParseFile s pEnv = unsafeGetRightFrom s <$> parseFile "" s pEnv
|
||||
|
@ -40,7 +40,11 @@ debug = False
|
||||
|
||||
parsingEnv :: Parser.ParsingEnv Identity
|
||||
parsingEnv =
|
||||
Parser.ParsingEnv mempty (Names.NamesWithHistory Builtin.names0 mempty)
|
||||
Parser.ParsingEnv
|
||||
{ uniqueNames = mempty,
|
||||
uniqueTypeGuid = \_ -> pure Nothing,
|
||||
names = Names.NamesWithHistory Builtin.names0 mempty
|
||||
}
|
||||
|
||||
typecheckingEnv :: Typechecker.Env Symbol Ann
|
||||
typecheckingEnv =
|
||||
|
@ -83,4 +83,9 @@ parseAndSynthesizeAsFile ambient filename s = do
|
||||
Result.Result _ (Just typecheckedFile) -> pure (Right typecheckedFile)
|
||||
|
||||
parsingEnv :: Parser.ParsingEnv Identity
|
||||
parsingEnv = Parser.ParsingEnv mempty B.names
|
||||
parsingEnv =
|
||||
Parser.ParsingEnv
|
||||
{ uniqueNames = mempty,
|
||||
uniqueTypeGuid = \_ -> pure Nothing,
|
||||
names = B.names
|
||||
}
|
||||
|
@ -1455,7 +1455,12 @@ loadUnisonFile sourceName text = do
|
||||
& #latestTypecheckedFile .~ Nothing
|
||||
Cli.Env {codebase, generateUniqueName} <- ask
|
||||
uniqueName <- liftIO generateUniqueName
|
||||
let parsingEnv = Parser.ParsingEnv uniqueName parseNames
|
||||
let parsingEnv =
|
||||
Parser.ParsingEnv
|
||||
{ uniqueNames = uniqueName,
|
||||
uniqueTypeGuid = wundefined,
|
||||
names = parseNames
|
||||
}
|
||||
unisonFile <-
|
||||
Cli.runTransaction (Parsers.parseFile (Text.unpack sourceName) (Text.unpack text) parsingEnv)
|
||||
& onLeftM \err -> Cli.returnEarly (ParseErrors text [err])
|
||||
@ -2982,8 +2987,14 @@ parseType input src = do
|
||||
NamesWithHistory.push
|
||||
(NamesWithHistory.currentNames names0)
|
||||
(NamesWithHistory.NamesWithHistory parseNames (NamesWithHistory.oldNames names0))
|
||||
let parsingEnv =
|
||||
Parser.ParsingEnv
|
||||
{ uniqueNames = mempty,
|
||||
uniqueTypeGuid = wundefined,
|
||||
names
|
||||
}
|
||||
typ <-
|
||||
Parsers.parseType (Text.unpack (fst lexed)) (Parser.ParsingEnv mempty names) & onLeftM \err ->
|
||||
Parsers.parseType (Text.unpack (fst lexed)) parsingEnv & onLeftM \err ->
|
||||
Cli.returnEarly (TypeParseError src err)
|
||||
|
||||
Type.bindNames Name.unsafeFromVar mempty (NamesWithHistory.currentNames names) (Type.generalizeLowercase mempty typ) & onLeft \errs ->
|
||||
|
@ -77,7 +77,12 @@ checkFile doc = runMaybeT $ do
|
||||
cb <- asks codebase
|
||||
let generateUniqueName = Parser.uniqueBase32Namegen <$> Random.getSystemDRG
|
||||
uniqueName <- liftIO generateUniqueName
|
||||
let parsingEnv = Parser.ParsingEnv uniqueName parseNames
|
||||
let parsingEnv =
|
||||
Parser.ParsingEnv
|
||||
{ uniqueNames = uniqueName,
|
||||
uniqueTypeGuid = wundefined,
|
||||
names = parseNames
|
||||
}
|
||||
(notes, parsedFile, typecheckedFile) <- do
|
||||
liftIO do
|
||||
Codebase.runTransaction cb do
|
||||
|
@ -330,7 +330,12 @@ typecheckSrc name src = do
|
||||
uniqueName <- Parser.uniqueBase32Namegen <$> Random.getSystemDRG
|
||||
let ambientAbilities = []
|
||||
let parseNames = mempty
|
||||
let parsingEnv = Parser.ParsingEnv uniqueName parseNames
|
||||
let parsingEnv =
|
||||
Parser.ParsingEnv
|
||||
{ uniqueNames = uniqueName,
|
||||
uniqueTypeGuid = wundefined,
|
||||
names = parseNames
|
||||
}
|
||||
Codebase.runTransaction codebase do
|
||||
Parsers.parseFile name (Text.unpack src) parsingEnv >>= \case
|
||||
Left err -> pure (Left (crash ("Failed to parse: " ++ show err)))
|
||||
|
@ -62,6 +62,7 @@ import Data.Bytes.Put (runPutS)
|
||||
import Data.Bytes.Serial (serialize)
|
||||
import Data.Bytes.VarInt (VarInt (..))
|
||||
import Data.Char qualified as Char
|
||||
import Data.Kind (Type)
|
||||
import Data.List.NonEmpty qualified as Nel
|
||||
import Data.Set qualified as Set
|
||||
import Data.Text qualified as Text
|
||||
@ -89,7 +90,6 @@ import Unison.UnisonFile.Error qualified as UF
|
||||
import Unison.Util.Bytes (Bytes)
|
||||
import Unison.Var (Var)
|
||||
import Unison.Var qualified as Var
|
||||
import Data.Kind (Type)
|
||||
|
||||
debug :: Bool
|
||||
debug = False
|
||||
@ -100,6 +100,13 @@ type Err v = P.ParseError Input (Error v)
|
||||
|
||||
data ParsingEnv (m :: Type -> Type) = ParsingEnv
|
||||
{ uniqueNames :: UniqueName,
|
||||
-- | Return a GUID to reuse for a unique type of the given name, if any.
|
||||
--
|
||||
-- This callback is called for every `unique type` declaration that does not explicitly specify a GUID.
|
||||
--
|
||||
-- The name (e.g. `Foo` in `unique type Foo`) is passed in, and if the function returns a Just, that GUID is used;
|
||||
-- otherwise, a random one is generated from `uniqueNames`.
|
||||
uniqueTypeGuid :: Name -> m (Maybe Text),
|
||||
names :: NamesWithHistory
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user