diff --git a/hie.yaml b/hie.yaml index ce2a6418a..811a7099f 100644 --- a/hie.yaml +++ b/hie.yaml @@ -98,6 +98,11 @@ cradle: - path: "parser-typechecker/tests" component: "unison-parser-typechecker:test:parser-typechecker-tests" + - path: "unison-runtime/src" + component: "unison-runtime:lib" + + - path: "unison-runtime/tests" + component: "unison-runtime:test:runtime-tests" - path: "unison-cli/src" component: "unison-cli:lib" diff --git a/parser-typechecker/package.yaml b/parser-typechecker/package.yaml index 5cc6ba547..aef8ee985 100644 --- a/parser-typechecker/package.yaml +++ b/parser-typechecker/package.yaml @@ -8,15 +8,10 @@ flags: optimized: manual: true default: true - arraychecks: - manual: true - default: false when: - condition: flag(optimized) ghc-options: -funbox-strict-fields -O2 - - condition: flag(arraychecks) - cpp-options: -DARRAY_CHECK dependencies: - ListLike diff --git a/parser-typechecker/src/Unison/Codebase.hs b/parser-typechecker/src/Unison/Codebase.hs index 7d3fb7b8a..e29043797 100644 --- a/parser-typechecker/src/Unison/Codebase.hs +++ b/parser-typechecker/src/Unison/Codebase.hs @@ -110,7 +110,6 @@ module Unison.Codebase addDefsToCodebase, componentReferencesForReference, installUcmDependencies, - toCodeLookup, typeLookupForDependencies, unsafeGetComponentLength, SqliteCodebase.Operations.emptyCausalHash, @@ -132,7 +131,6 @@ import Unison.Builtin.Terms qualified as Builtin import Unison.Codebase.Branch (Branch) import Unison.Codebase.Branch qualified as Branch import Unison.Codebase.BuiltinAnnotation (BuiltinAnnotation (builtinAnnotation)) -import Unison.Codebase.CodeLookup qualified as CL import Unison.Codebase.Path import Unison.Codebase.Path qualified as Path import Unison.Codebase.ProjectPath qualified as PP @@ -153,7 +151,6 @@ import Unison.Project (ProjectAndBranch (ProjectAndBranch), ProjectBranchName, P import Unison.Reference (Reference, TermReference, TermReferenceId, TypeReference) import Unison.Reference qualified as Reference import Unison.Referent qualified as Referent -import Unison.Runtime.IOSource qualified as IOSource import Unison.Sqlite qualified as Sqlite import Unison.Symbol (Symbol) import Unison.Term (Term) @@ -418,12 +415,6 @@ typeLookupForDependencies codebase s = do <|> Map.lookup r (TL.effectDecls tl) $> () ) -toCodeLookup :: (MonadIO m) => Codebase m Symbol Parser.Ann -> CL.CodeLookup Symbol m Parser.Ann -toCodeLookup c = - CL.CodeLookup (runTransaction c . getTerm c) (runTransaction c . getTypeDeclaration c) - <> Builtin.codeLookup - <> IOSource.codeLookupM - -- | Get the type of a term. -- -- Note that it is possible to call 'putTerm', then 'getTypeOfTerm', and receive @Nothing@, per the semantics of diff --git a/parser-typechecker/tests/Suite.hs b/parser-typechecker/tests/Suite.hs index a3f0d89d6..4ef15dfd2 100644 --- a/parser-typechecker/tests/Suite.hs +++ b/parser-typechecker/tests/Suite.hs @@ -9,13 +9,11 @@ import System.IO import System.IO.CodePage (withCP65001) import Unison.Core.Test.Name qualified as Name import Unison.Test.ABT qualified as ABT -import Unison.Test.ANF qualified as ANF import Unison.Test.Codebase.Branch qualified as Branch import Unison.Test.Codebase.Causal qualified as Causal import Unison.Test.Codebase.Path qualified as Path import Unison.Test.CodebaseInit qualified as CodebaseInit import Unison.Test.DataDeclaration qualified as DataDeclaration -import Unison.Test.MCode qualified as MCode import Unison.Test.Referent qualified as Referent import Unison.Test.Syntax.FileParser qualified as FileParser import Unison.Test.Syntax.TermParser qualified as TermParser @@ -25,7 +23,6 @@ import Unison.Test.Type qualified as Type import Unison.Test.Typechecker qualified as Typechecker import Unison.Test.Typechecker.Context qualified as Context import Unison.Test.Typechecker.TypeError qualified as TypeError -import Unison.Test.UnisonSources qualified as UnisonSources import Unison.Test.Util.Relation qualified as Relation import Unison.Test.Util.Text qualified as Text import Unison.Test.Var qualified as Var @@ -38,7 +35,6 @@ test = Type.test, TypeError.test, TypePrinter.test, - UnisonSources.test, FileParser.test, DataDeclaration.test, Text.test, @@ -47,8 +43,6 @@ test = Causal.test, Referent.test, ABT.test, - ANF.test, - MCode.test, Var.test, Typechecker.test, Context.test, diff --git a/parser-typechecker/unison-parser-typechecker.cabal b/parser-typechecker/unison-parser-typechecker.cabal index e34a1a652..ca09ca8a9 100644 --- a/parser-typechecker/unison-parser-typechecker.cabal +++ b/parser-typechecker/unison-parser-typechecker.cabal @@ -17,10 +17,6 @@ source-repository head type: git location: https://github.com/unisonweb/unison -flag arraychecks - manual: True - default: False - flag optimized manual: True default: True @@ -48,7 +44,6 @@ library Unison.Codebase.CodeLookup.Util Unison.Codebase.Editor.DisplayObject Unison.Codebase.Editor.RemoteRepo - Unison.Codebase.Execute Unison.Codebase.FileCodebase Unison.Codebase.Init Unison.Codebase.Init.CreateCodebaseError @@ -133,27 +128,6 @@ library Unison.PrettyPrintEnvDecl.Sqlite Unison.PrintError Unison.Result - Unison.Runtime.ANF - Unison.Runtime.ANF.Rehash - Unison.Runtime.ANF.Serialize - Unison.Runtime.Array - Unison.Runtime.Builtin - Unison.Runtime.Crypto.Rsa - Unison.Runtime.Debug - Unison.Runtime.Decompile - Unison.Runtime.Exception - Unison.Runtime.Foreign - Unison.Runtime.Foreign.Function - Unison.Runtime.Interface - Unison.Runtime.IOSource - Unison.Runtime.Machine - Unison.Runtime.MCode - Unison.Runtime.MCode.Serialize - Unison.Runtime.Pattern - Unison.Runtime.Serialize - Unison.Runtime.SparseVector - Unison.Runtime.Stack - Unison.Runtime.Vector Unison.Share.Types Unison.Syntax.DeclParser Unison.Syntax.DeclPrinter @@ -350,8 +324,6 @@ library default-language: Haskell2010 if flag(optimized) ghc-options: -funbox-strict-fields -O2 - if flag(arraychecks) - cpp-options: -DARRAY_CHECK test-suite parser-typechecker-tests type: exitcode-stdio-1.0 @@ -359,16 +331,13 @@ test-suite parser-typechecker-tests other-modules: Unison.Core.Test.Name Unison.Test.ABT - Unison.Test.ANF Unison.Test.Codebase.Branch Unison.Test.Codebase.Causal Unison.Test.Codebase.Path Unison.Test.CodebaseInit Unison.Test.Common Unison.Test.DataDeclaration - Unison.Test.MCode Unison.Test.Referent - Unison.Test.Runtime.Crypto.Rsa Unison.Test.Syntax.FileParser Unison.Test.Syntax.TermParser Unison.Test.Syntax.TypePrinter @@ -378,7 +347,6 @@ test-suite parser-typechecker-tests Unison.Test.Typechecker.Components Unison.Test.Typechecker.Context Unison.Test.Typechecker.TypeError - Unison.Test.UnisonSources Unison.Test.Util.Pretty Unison.Test.Util.Relation Unison.Test.Util.Text @@ -549,5 +517,3 @@ test-suite parser-typechecker-tests default-language: Haskell2010 if flag(optimized) ghc-options: -funbox-strict-fields -O2 - if flag(arraychecks) - cpp-options: -DARRAY_CHECK diff --git a/stack.yaml b/stack.yaml index 1eb80fdd2..158938303 100644 --- a/stack.yaml +++ b/stack.yaml @@ -43,6 +43,7 @@ packages: - unison-core - unison-hashing-v2 - unison-merge + - unison-runtime - unison-share-api - unison-share-projects-api - unison-syntax diff --git a/unison-cli/package.yaml b/unison-cli/package.yaml index ac5c0053b..2251650ad 100644 --- a/unison-cli/package.yaml +++ b/unison-cli/package.yaml @@ -89,6 +89,7 @@ dependencies: - unison-parser-typechecker - unison-prelude - unison-pretty-printer + - unison-runtime - unison-share-api - unison-share-projects-api - unison-sqlite diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs index 0f13816ce..22c81c0d7 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs @@ -102,6 +102,7 @@ import Unison.Codebase.Editor.RemoteRepo qualified as RemoteRepo import Unison.Codebase.Editor.Slurp qualified as Slurp import Unison.Codebase.Editor.SlurpResult qualified as SlurpResult import Unison.Codebase.Editor.StructuredArgument qualified as SA +import Unison.Codebase.Execute qualified as Codebase import Unison.Codebase.IntegrityCheck qualified as IntegrityCheck (integrityCheckFullCodebase) import Unison.Codebase.Metadata qualified as Metadata import Unison.Codebase.Path (Path, Path' (..)) @@ -1446,7 +1447,7 @@ doCompile native output main = do | native = nativeRuntime | otherwise = runtime (ref, ppe) <- resolveMainRef main - let codeLookup = () <$ Codebase.toCodeLookup codebase + let codeLookup = () <$ Codebase.codebaseToCodeLookup codebase outf | native = output | otherwise = output <> ".uc" diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Load.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Load.hs index d969291ac..79989b65d 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Load.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Load.hs @@ -24,6 +24,7 @@ import Unison.Codebase qualified as Codebase import Unison.Codebase.Editor.HandleInput.RuntimeUtils qualified as RuntimeUtils import Unison.Codebase.Editor.Output qualified as Output import Unison.Codebase.Editor.Slurp qualified as Slurp +import Unison.Codebase.Execute qualified as Codebase import Unison.Codebase.Runtime qualified as Runtime import Unison.FileParsers qualified as FileParsers import Unison.Names (Names) @@ -192,7 +193,7 @@ evalUnisonFile mode ppe unisonFile args = do Cli.with_ (withArgs args) do (nts, errs, map) <- - Cli.ioE (Runtime.evaluateWatches (Codebase.toCodeLookup codebase) ppe watchCache theRuntime unisonFile) \err -> do + Cli.ioE (Runtime.evaluateWatches (Codebase.codebaseToCodeLookup codebase) ppe watchCache theRuntime unisonFile) \err -> do Cli.returnEarly (Output.EvaluationFailure err) when (not $ null errs) (RuntimeUtils.displayDecompileErrors errs) for_ (Map.elems map) \(_loc, kind, hash, _src, value, isHit) -> do diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/RuntimeUtils.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/RuntimeUtils.hs index df86793ff..2826d2545 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/RuntimeUtils.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/RuntimeUtils.hs @@ -13,6 +13,7 @@ import Unison.Cli.Monad (Cli) import Unison.Cli.Monad qualified as Cli import Unison.Codebase qualified as Codebase import Unison.Codebase.Editor.Output +import Unison.Codebase.Execute qualified as Codebase import Unison.Codebase.Runtime qualified as Runtime import Unison.Hashing.V2.Convert qualified as Hashing import Unison.Parser.Ann (Ann (..)) @@ -55,7 +56,7 @@ evalUnisonTermE sandbox ppe useCache tm = do pure (Term.amap (\(_ :: Ann) -> ()) <$> maybeTerm) let cache = if useCache then watchCache else Runtime.noCache - r <- liftIO (Runtime.evaluateTerm' (Codebase.toCodeLookup codebase) cache ppe theRuntime tm) + r <- liftIO (Runtime.evaluateTerm' (Codebase.codebaseToCodeLookup codebase) cache ppe theRuntime tm) when useCache do case r of Right (errs, tmr) diff --git a/unison-cli/unison-cli.cabal b/unison-cli/unison-cli.cabal index a12b03323..5b5b2f9ba 100644 --- a/unison-cli/unison-cli.cabal +++ b/unison-cli/unison-cli.cabal @@ -271,6 +271,7 @@ library , unison-parser-typechecker , unison-prelude , unison-pretty-printer + , unison-runtime , unison-share-api , unison-share-projects-api , unison-sqlite @@ -415,6 +416,7 @@ executable transcripts , unison-parser-typechecker , unison-prelude , unison-pretty-printer + , unison-runtime , unison-share-api , unison-share-projects-api , unison-sqlite @@ -563,6 +565,7 @@ test-suite cli-tests , unison-parser-typechecker , unison-prelude , unison-pretty-printer + , unison-runtime , unison-share-api , unison-share-projects-api , unison-sqlite diff --git a/unison-runtime/LICENSE b/unison-runtime/LICENSE new file mode 100644 index 000000000..c45ac9a54 --- /dev/null +++ b/unison-runtime/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2013-2021, Unison Computing, public benefit corp and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/unison-runtime/package.yaml b/unison-runtime/package.yaml new file mode 100644 index 000000000..d6de78711 --- /dev/null +++ b/unison-runtime/package.yaml @@ -0,0 +1,198 @@ +name: unison-runtime +github: unisonweb/unison +copyright: Copyright (C) 2013-2024 Unison Computing, PBC and contributors + +ghc-options: -Wall -O0 + +flags: + optimized: + manual: true + default: true + arraychecks: + manual: true + default: false + +when: + - condition: flag(optimized) + ghc-options: -funbox-strict-fields -O2 + - condition: flag(arraychecks) + cpp-options: -DARRAY_CHECK + +dependencies: + - ListLike + - aeson + - ansi-terminal + - asn1-encoding + - asn1-types + - async + - atomic-primops + - base + - base16 >= 0.2.1.0 + - base64-bytestring + - basement + - binary + - bytes + - bytestring + - bytestring-to-vector + - cereal + - clock + - concurrent-output + - containers >= 0.6.3 + - cryptonite + - data-default + - data-memocombinators + - deepseq + - directory + - either + - errors + - exceptions + - extra + - filelock + - filepath + - fingertree + - fuzzyfind + - free + - generic-lens + - hashable + - hashtables + - haskeline + - http-client + - http-media + - http-types + - IntervalMap + - iproute + - lens + - lucid + - megaparsec + - memory + - mmorph + - monad-validate + - mtl + - mutable-containers + - murmur-hash + - mwc-random + - natural-transformation + - network + - network-simple + - network-udp + - network-uri + - nonempty-containers + - open-browser + - openapi3 + - optparse-applicative + - pem + - pretty-simple + - primitive + - process + - random >= 1.2.0 + - raw-strings-qq + - recover-rtti + - regex-base + - regex-tdfa + - safe + - safe-exceptions + - semialign + - semigroups + - servant + - servant-client + - servant-docs + - servant-openapi3 + - servant-server + - shellmet + - stm + - tagged + - temporary + - terminal-size >= 0.3.3 + - text + - text-short + - these + - time + - tls + - transformers + - unicode-show + - unison-codebase + - unison-codebase-sqlite + - unison-codebase-sqlite-hashing-v2 + - unison-codebase-sync + - unison-core + - unison-core1 + - unison-hash + - unison-hashing-v2 + - unison-parser-typechecker + - unison-prelude + - unison-pretty-printer + - unison-sqlite + - unison-syntax + - unison-util-base32hex + - unison-util-bytes + - unison-util-cache + - unison-util-relation + - unison-util-rope + - unison-util-serialization + - unliftio + - uuid + - uri-encode + - utf8-string + - vector + - wai + - warp + - witch + - witherable + - crypton-x509 + - crypton-x509-store + - crypton-x509-system + - yaml + - zlib + +library: + source-dirs: src + when: + - condition: false + other-modules: Paths_unison_runtime + +tests: + runtime-tests: + source-dirs: tests + main: Suite.hs + ghc-options: -W -threaded -rtsopts "-with-rtsopts=-N -T" -v0 + dependencies: + - code-page + - easytest + - filemanip + - split + - hex-text + - unison-runtime + when: + - condition: false + other-modules: Paths_unison_parser_typechecker + +default-extensions: + - ApplicativeDo + - BangPatterns + - BlockArguments + - DeriveAnyClass + - DeriveFunctor + - DeriveGeneric + - DeriveTraversable + - DerivingStrategies + - DerivingVia + - DoAndIfThenElse + - DuplicateRecordFields + - FlexibleContexts + - FlexibleInstances + - GeneralizedNewtypeDeriving + - ImportQualifiedPost + - LambdaCase + - MultiParamTypeClasses + - NamedFieldPuns + - OverloadedLabels + - OverloadedRecordDot + - OverloadedStrings + - PatternSynonyms + - RankNTypes + - ScopedTypeVariables + - StandaloneDeriving + - TupleSections + - TypeApplications + - TypeFamilies + - ViewPatterns diff --git a/parser-typechecker/src/Unison/Codebase/Execute.hs b/unison-runtime/src/Unison/Codebase/Execute.hs similarity index 81% rename from parser-typechecker/src/Unison/Codebase/Execute.hs rename to unison-runtime/src/Unison/Codebase/Execute.hs index 788bc5abe..71f345220 100644 --- a/parser-typechecker/src/Unison/Codebase/Execute.hs +++ b/unison-runtime/src/Unison/Codebase/Execute.hs @@ -3,16 +3,22 @@ -- -- This allows one to run standalone applications implemented in the Unison -- language. -module Unison.Codebase.Execute where +module Unison.Codebase.Execute + ( execute, + codebaseToCodeLookup, + ) +where import Control.Exception (finally) import Control.Monad.Except import U.Codebase.Sqlite.Project (Project (..)) import U.Codebase.Sqlite.ProjectBranch (ProjectBranch (..)) import U.Codebase.Sqlite.Queries qualified as Q +import Unison.Builtin qualified as Builtin import Unison.Codebase qualified as Codebase import Unison.Codebase.Branch qualified as Branch import Unison.Codebase.Branch.Names qualified as Branch +import Unison.Codebase.CodeLookup qualified as CL import Unison.Codebase.MainTerm (getMainTerm) import Unison.Codebase.MainTerm qualified as MainTerm import Unison.Codebase.Path qualified as Path @@ -20,10 +26,13 @@ import Unison.Codebase.ProjectPath (ProjectPathG (..)) import Unison.Codebase.ProjectPath qualified as PP import Unison.Codebase.Runtime (Runtime) import Unison.Codebase.Runtime qualified as Runtime +import Unison.Codebase.Type (Codebase (..)) import Unison.HashQualified qualified as HQ import Unison.Parser.Ann (Ann) +import Unison.Parser.Ann qualified as Parser import Unison.Prelude import Unison.PrettyPrintEnv qualified as PPE +import Unison.Runtime.IOSource qualified as IOSource import Unison.Symbol (Symbol) import Unison.Syntax.HashQualified qualified as HQ (toText) import Unison.Util.Pretty qualified as P @@ -51,8 +60,14 @@ execute codebase runtime mainPath = MainTerm.NotFound s -> throwError ("Not found: " <> P.text (HQ.toText s)) MainTerm.BadType s _ -> throwError (P.text (HQ.toText s) <> " is not of type '{IO} ()") MainTerm.Success _ tm _ -> do - let codeLookup = Codebase.toCodeLookup codebase + let codeLookup = codebaseToCodeLookup codebase ppe = PPE.empty (liftIO $ Runtime.evaluateTerm codeLookup ppe runtime tm) >>= \case Left err -> throwError err Right _ -> pure () + +codebaseToCodeLookup :: (MonadIO m) => Codebase m Symbol Parser.Ann -> CL.CodeLookup Symbol m Parser.Ann +codebaseToCodeLookup c = + CL.CodeLookup (Codebase.runTransaction c . getTerm c) (Codebase.runTransaction c . getTypeDeclaration c) + <> Builtin.codeLookup + <> IOSource.codeLookupM diff --git a/parser-typechecker/src/Unison/Runtime/ANF.hs b/unison-runtime/src/Unison/Runtime/ANF.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/ANF.hs rename to unison-runtime/src/Unison/Runtime/ANF.hs diff --git a/parser-typechecker/src/Unison/Runtime/ANF/Rehash.hs b/unison-runtime/src/Unison/Runtime/ANF/Rehash.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/ANF/Rehash.hs rename to unison-runtime/src/Unison/Runtime/ANF/Rehash.hs diff --git a/parser-typechecker/src/Unison/Runtime/ANF/Serialize.hs b/unison-runtime/src/Unison/Runtime/ANF/Serialize.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/ANF/Serialize.hs rename to unison-runtime/src/Unison/Runtime/ANF/Serialize.hs diff --git a/parser-typechecker/src/Unison/Runtime/Array.hs b/unison-runtime/src/Unison/Runtime/Array.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Array.hs rename to unison-runtime/src/Unison/Runtime/Array.hs diff --git a/parser-typechecker/src/Unison/Runtime/Builtin.hs b/unison-runtime/src/Unison/Runtime/Builtin.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Builtin.hs rename to unison-runtime/src/Unison/Runtime/Builtin.hs diff --git a/parser-typechecker/src/Unison/Runtime/Crypto/Rsa.hs b/unison-runtime/src/Unison/Runtime/Crypto/Rsa.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Crypto/Rsa.hs rename to unison-runtime/src/Unison/Runtime/Crypto/Rsa.hs diff --git a/parser-typechecker/src/Unison/Runtime/Debug.hs b/unison-runtime/src/Unison/Runtime/Debug.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Debug.hs rename to unison-runtime/src/Unison/Runtime/Debug.hs diff --git a/parser-typechecker/src/Unison/Runtime/Decompile.hs b/unison-runtime/src/Unison/Runtime/Decompile.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Decompile.hs rename to unison-runtime/src/Unison/Runtime/Decompile.hs diff --git a/parser-typechecker/src/Unison/Runtime/Exception.hs b/unison-runtime/src/Unison/Runtime/Exception.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Exception.hs rename to unison-runtime/src/Unison/Runtime/Exception.hs diff --git a/parser-typechecker/src/Unison/Runtime/Foreign.hs b/unison-runtime/src/Unison/Runtime/Foreign.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Foreign.hs rename to unison-runtime/src/Unison/Runtime/Foreign.hs diff --git a/parser-typechecker/src/Unison/Runtime/Foreign/Function.hs b/unison-runtime/src/Unison/Runtime/Foreign/Function.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Foreign/Function.hs rename to unison-runtime/src/Unison/Runtime/Foreign/Function.hs diff --git a/parser-typechecker/src/Unison/Runtime/IOSource.hs b/unison-runtime/src/Unison/Runtime/IOSource.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/IOSource.hs rename to unison-runtime/src/Unison/Runtime/IOSource.hs diff --git a/parser-typechecker/src/Unison/Runtime/Interface.hs b/unison-runtime/src/Unison/Runtime/Interface.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Interface.hs rename to unison-runtime/src/Unison/Runtime/Interface.hs diff --git a/parser-typechecker/src/Unison/Runtime/MCode.hs b/unison-runtime/src/Unison/Runtime/MCode.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/MCode.hs rename to unison-runtime/src/Unison/Runtime/MCode.hs diff --git a/parser-typechecker/src/Unison/Runtime/MCode/Serialize.hs b/unison-runtime/src/Unison/Runtime/MCode/Serialize.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/MCode/Serialize.hs rename to unison-runtime/src/Unison/Runtime/MCode/Serialize.hs diff --git a/parser-typechecker/src/Unison/Runtime/Machine.hs b/unison-runtime/src/Unison/Runtime/Machine.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Machine.hs rename to unison-runtime/src/Unison/Runtime/Machine.hs diff --git a/parser-typechecker/src/Unison/Runtime/Pattern.hs b/unison-runtime/src/Unison/Runtime/Pattern.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Pattern.hs rename to unison-runtime/src/Unison/Runtime/Pattern.hs diff --git a/parser-typechecker/src/Unison/Runtime/Serialize.hs b/unison-runtime/src/Unison/Runtime/Serialize.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Serialize.hs rename to unison-runtime/src/Unison/Runtime/Serialize.hs diff --git a/parser-typechecker/src/Unison/Runtime/SparseVector.hs b/unison-runtime/src/Unison/Runtime/SparseVector.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/SparseVector.hs rename to unison-runtime/src/Unison/Runtime/SparseVector.hs diff --git a/parser-typechecker/src/Unison/Runtime/Stack.hs b/unison-runtime/src/Unison/Runtime/Stack.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Stack.hs rename to unison-runtime/src/Unison/Runtime/Stack.hs diff --git a/parser-typechecker/src/Unison/Runtime/Vector.hs b/unison-runtime/src/Unison/Runtime/Vector.hs similarity index 100% rename from parser-typechecker/src/Unison/Runtime/Vector.hs rename to unison-runtime/src/Unison/Runtime/Vector.hs diff --git a/parser-typechecker/src/Unison/Runtime/docs.markdown b/unison-runtime/src/Unison/Runtime/docs.markdown similarity index 100% rename from parser-typechecker/src/Unison/Runtime/docs.markdown rename to unison-runtime/src/Unison/Runtime/docs.markdown diff --git a/unison-runtime/tests/Suite.hs b/unison-runtime/tests/Suite.hs new file mode 100644 index 000000000..b17670393 --- /dev/null +++ b/unison-runtime/tests/Suite.hs @@ -0,0 +1,31 @@ +{-# OPTIONS_GHC -Wno-unused-imports #-} +{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-} + +module Main where + +import EasyTest +import System.Environment (getArgs) +import System.IO +import System.IO.CodePage (withCP65001) +import Unison.Test.Runtime.ANF qualified as ANF +import Unison.Test.Runtime.Crypto.Rsa qualified as Rsa +import Unison.Test.Runtime.MCode qualified as MCode +import Unison.Test.UnisonSources qualified as UnisonSources + +test :: Test () +test = + tests + [ ANF.test, + MCode.test, + Rsa.test, + UnisonSources.test + ] + +main :: IO () +main = withCP65001 do + args <- getArgs + mapM_ (`hSetEncoding` utf8) [stdout, stdin, stderr] + case args of + [] -> runOnly "" test + [prefix] -> runOnly prefix test + [seed, prefix] -> rerunOnly (read seed) prefix test diff --git a/unison-runtime/tests/Unison/Test/Common.hs b/unison-runtime/tests/Unison/Test/Common.hs new file mode 100644 index 000000000..e1d880002 --- /dev/null +++ b/unison-runtime/tests/Unison/Test/Common.hs @@ -0,0 +1,93 @@ +module Unison.Test.Common + ( hqLength, + t, + tm, + parseAndSynthesizeAsFile, + parsingEnv, + ) +where + +import Control.Monad.Writer (tell) +import Data.Functor.Identity (Identity (..)) +import Data.Sequence (Seq) +import Text.Megaparsec.Error qualified as MPE +import Unison.ABT qualified as ABT +import Unison.Builtin qualified as B +import Unison.FileParsers qualified as FP +import Unison.Parser.Ann (Ann (..)) +import Unison.Parsers qualified as Parsers +import Unison.PrintError (prettyParseError) +import Unison.Result (Note, Result) +import Unison.Result qualified as Result +import Unison.Symbol (Symbol) +import Unison.Syntax.Parser qualified as Parser +import Unison.Syntax.TermParser qualified as TermParser +import Unison.Syntax.TypeParser qualified as TypeParser +import Unison.Term qualified as Term +import Unison.Type qualified as Type +import Unison.UnisonFile (TypecheckedUnisonFile, UnisonFile) +import Unison.Util.Pretty qualified as Pr +import Unison.Var (Var) + +type Term v = Term.Term v Ann + +type Type v = Type.Type v Ann + +hqLength :: Int +hqLength = 10 + +t :: String -> Type Symbol +t s = + ABT.amap (const Intrinsic) + -- . either (error . show ) id + -- . Type.bindSomeNames B.names0 + . either (error . showParseError s) tweak + . runIdentity + $ Parser.run (Parser.root TypeParser.valueType) s parsingEnv + where + tweak = Type.generalizeLowercase mempty + +tm :: String -> Term Symbol +tm s = + either (error . showParseError s) id + -- . Term.bindSomeNames mempty B.names0 + -- . either (error . showParseError s) id + . runIdentity + $ Parser.run (Parser.root TermParser.term) s parsingEnv + +showParseError :: + (Var v) => + String -> + MPE.ParseError Parser.Input (Parser.Error v) -> + String +showParseError s = Pr.toANSI 60 . prettyParseError s + +parseAndSynthesizeAsFile :: + [Type Symbol] -> + FilePath -> + String -> + Result + (Seq (Note Symbol Ann)) + (Either (UnisonFile Symbol Ann) (TypecheckedUnisonFile Symbol Ann)) +parseAndSynthesizeAsFile ambient filename s = do + file <- Result.fromParsing (runIdentity (Parsers.parseFile filename s parsingEnv)) + let typecheckingEnv = + runIdentity $ + FP.computeTypecheckingEnvironment + (FP.ShouldUseTndr'Yes parsingEnv) + ambient + (\_deps -> pure B.typeLookup) + file + case FP.synthesizeFile typecheckingEnv file of + Result.Result notes Nothing -> tell notes >> pure (Left file) + Result.Result _ (Just typecheckedFile) -> pure (Right typecheckedFile) + +parsingEnv :: Parser.ParsingEnv Identity +parsingEnv = + Parser.ParsingEnv + { uniqueNames = mempty, + uniqueTypeGuid = \_ -> pure Nothing, + names = B.names, + maybeNamespace = Nothing, + localNamespacePrefixedTypesAndConstructors = mempty + } diff --git a/parser-typechecker/tests/Unison/Test/ANF.hs b/unison-runtime/tests/Unison/Test/Runtime/ANF.hs similarity index 99% rename from parser-typechecker/tests/Unison/Test/ANF.hs rename to unison-runtime/tests/Unison/Test/Runtime/ANF.hs index 9e2aa9c4b..84f97e0bf 100644 --- a/parser-typechecker/tests/Unison/Test/ANF.hs +++ b/unison-runtime/tests/Unison/Test/Runtime/ANF.hs @@ -1,7 +1,7 @@ {-# LANGUAGE BangPatterns #-} {-# LANGUAGE PatternGuards #-} -module Unison.Test.ANF where +module Unison.Test.Runtime.ANF where import Control.Monad.Reader (ReaderT (..)) import Control.Monad.State (evalState) @@ -17,7 +17,7 @@ import Unison.Reference (Reference, Reference' (Builtin)) import Unison.Runtime.ANF as ANF import Unison.Runtime.MCode (RefNums (..), emitCombs) import Unison.Term qualified as Term -import Unison.Test.Common (tm) +import Unison.Test.Common import Unison.Type as Ty import Unison.Util.EnumContainers as EC import Unison.Util.Text qualified as Util.Text diff --git a/parser-typechecker/tests/Unison/Test/Runtime/Crypto/Rsa.hs b/unison-runtime/tests/Unison/Test/Runtime/Crypto/Rsa.hs similarity index 100% rename from parser-typechecker/tests/Unison/Test/Runtime/Crypto/Rsa.hs rename to unison-runtime/tests/Unison/Test/Runtime/Crypto/Rsa.hs diff --git a/parser-typechecker/tests/Unison/Test/MCode.hs b/unison-runtime/tests/Unison/Test/Runtime/MCode.hs similarity index 98% rename from parser-typechecker/tests/Unison/Test/MCode.hs rename to unison-runtime/tests/Unison/Test/Runtime/MCode.hs index 8224914d6..0bb235f44 100644 --- a/parser-typechecker/tests/Unison/Test/MCode.hs +++ b/unison-runtime/tests/Unison/Test/Runtime/MCode.hs @@ -3,7 +3,7 @@ {-# LANGUAGE PatternGuards #-} {-# LANGUAGE TypeApplications #-} -module Unison.Test.MCode where +module Unison.Test.Runtime.MCode where import Control.Concurrent.STM import Data.Map.Strict qualified as Map diff --git a/parser-typechecker/tests/Unison/Test/UnisonSources.hs b/unison-runtime/tests/Unison/Test/UnisonSources.hs similarity index 100% rename from parser-typechecker/tests/Unison/Test/UnisonSources.hs rename to unison-runtime/tests/Unison/Test/UnisonSources.hs diff --git a/unison-runtime/unison-runtime.cabal b/unison-runtime/unison-runtime.cabal new file mode 100644 index 000000000..cdad09a8d --- /dev/null +++ b/unison-runtime/unison-runtime.cabal @@ -0,0 +1,394 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.36.0. +-- +-- see: https://github.com/sol/hpack + +name: unison-runtime +version: 0.0.0 +homepage: https://github.com/unisonweb/unison#readme +bug-reports: https://github.com/unisonweb/unison/issues +copyright: Copyright (C) 2013-2024 Unison Computing, PBC and contributors +license: MIT +license-file: LICENSE +build-type: Simple + +source-repository head + type: git + location: https://github.com/unisonweb/unison + +flag arraychecks + manual: True + default: False + +flag optimized + manual: True + default: True + +library + exposed-modules: + Unison.Codebase.Execute + Unison.Runtime.ANF + Unison.Runtime.ANF.Rehash + Unison.Runtime.ANF.Serialize + Unison.Runtime.Array + Unison.Runtime.Builtin + Unison.Runtime.Crypto.Rsa + Unison.Runtime.Debug + Unison.Runtime.Decompile + Unison.Runtime.Exception + Unison.Runtime.Foreign + Unison.Runtime.Foreign.Function + Unison.Runtime.Interface + Unison.Runtime.IOSource + Unison.Runtime.Machine + Unison.Runtime.MCode + Unison.Runtime.MCode.Serialize + Unison.Runtime.Pattern + Unison.Runtime.Serialize + Unison.Runtime.SparseVector + Unison.Runtime.Stack + Unison.Runtime.Vector + hs-source-dirs: + src + default-extensions: + ApplicativeDo + BangPatterns + BlockArguments + DeriveAnyClass + DeriveFunctor + DeriveGeneric + DeriveTraversable + DerivingStrategies + DerivingVia + DoAndIfThenElse + DuplicateRecordFields + FlexibleContexts + FlexibleInstances + GeneralizedNewtypeDeriving + ImportQualifiedPost + LambdaCase + MultiParamTypeClasses + NamedFieldPuns + OverloadedLabels + OverloadedRecordDot + OverloadedStrings + PatternSynonyms + RankNTypes + ScopedTypeVariables + StandaloneDeriving + TupleSections + TypeApplications + TypeFamilies + ViewPatterns + ghc-options: -Wall -O0 + build-depends: + IntervalMap + , ListLike + , aeson + , ansi-terminal + , asn1-encoding + , asn1-types + , async + , atomic-primops + , base + , base16 >=0.2.1.0 + , base64-bytestring + , basement + , binary + , bytes + , bytestring + , bytestring-to-vector + , cereal + , clock + , concurrent-output + , containers >=0.6.3 + , crypton-x509 + , crypton-x509-store + , crypton-x509-system + , cryptonite + , data-default + , data-memocombinators + , deepseq + , directory + , either + , errors + , exceptions + , extra + , filelock + , filepath + , fingertree + , free + , fuzzyfind + , generic-lens + , hashable + , hashtables + , haskeline + , http-client + , http-media + , http-types + , iproute + , lens + , lucid + , megaparsec + , memory + , mmorph + , monad-validate + , mtl + , murmur-hash + , mutable-containers + , mwc-random + , natural-transformation + , network + , network-simple + , network-udp + , network-uri + , nonempty-containers + , open-browser + , openapi3 + , optparse-applicative + , pem + , pretty-simple + , primitive + , process + , random >=1.2.0 + , raw-strings-qq + , recover-rtti + , regex-base + , regex-tdfa + , safe + , safe-exceptions + , semialign + , semigroups + , servant + , servant-client + , servant-docs + , servant-openapi3 + , servant-server + , shellmet + , stm + , tagged + , temporary + , terminal-size >=0.3.3 + , text + , text-short + , these + , time + , tls + , transformers + , unicode-show + , unison-codebase + , unison-codebase-sqlite + , unison-codebase-sqlite-hashing-v2 + , unison-codebase-sync + , unison-core + , unison-core1 + , unison-hash + , unison-hashing-v2 + , unison-parser-typechecker + , unison-prelude + , unison-pretty-printer + , unison-sqlite + , unison-syntax + , unison-util-base32hex + , unison-util-bytes + , unison-util-cache + , unison-util-relation + , unison-util-rope + , unison-util-serialization + , unliftio + , uri-encode + , utf8-string + , uuid + , vector + , wai + , warp + , witch + , witherable + , yaml + , zlib + default-language: Haskell2010 + if flag(optimized) + ghc-options: -funbox-strict-fields -O2 + if flag(arraychecks) + cpp-options: -DARRAY_CHECK + +test-suite runtime-tests + type: exitcode-stdio-1.0 + main-is: Suite.hs + other-modules: + Unison.Test.Common + Unison.Test.Runtime.ANF + Unison.Test.Runtime.Crypto.Rsa + Unison.Test.Runtime.MCode + Unison.Test.UnisonSources + Paths_unison_runtime + hs-source-dirs: + tests + default-extensions: + ApplicativeDo + BangPatterns + BlockArguments + DeriveAnyClass + DeriveFunctor + DeriveGeneric + DeriveTraversable + DerivingStrategies + DerivingVia + DoAndIfThenElse + DuplicateRecordFields + FlexibleContexts + FlexibleInstances + GeneralizedNewtypeDeriving + ImportQualifiedPost + LambdaCase + MultiParamTypeClasses + NamedFieldPuns + OverloadedLabels + OverloadedRecordDot + OverloadedStrings + PatternSynonyms + RankNTypes + ScopedTypeVariables + StandaloneDeriving + TupleSections + TypeApplications + TypeFamilies + ViewPatterns + ghc-options: -Wall -O0 -W -threaded -rtsopts "-with-rtsopts=-N -T" -v0 + build-depends: + IntervalMap + , ListLike + , aeson + , ansi-terminal + , asn1-encoding + , asn1-types + , async + , atomic-primops + , base + , base16 >=0.2.1.0 + , base64-bytestring + , basement + , binary + , bytes + , bytestring + , bytestring-to-vector + , cereal + , clock + , code-page + , concurrent-output + , containers >=0.6.3 + , crypton-x509 + , crypton-x509-store + , crypton-x509-system + , cryptonite + , data-default + , data-memocombinators + , deepseq + , directory + , easytest + , either + , errors + , exceptions + , extra + , filelock + , filemanip + , filepath + , fingertree + , free + , fuzzyfind + , generic-lens + , hashable + , hashtables + , haskeline + , hex-text + , http-client + , http-media + , http-types + , iproute + , lens + , lucid + , megaparsec + , memory + , mmorph + , monad-validate + , mtl + , murmur-hash + , mutable-containers + , mwc-random + , natural-transformation + , network + , network-simple + , network-udp + , network-uri + , nonempty-containers + , open-browser + , openapi3 + , optparse-applicative + , pem + , pretty-simple + , primitive + , process + , random >=1.2.0 + , raw-strings-qq + , recover-rtti + , regex-base + , regex-tdfa + , safe + , safe-exceptions + , semialign + , semigroups + , servant + , servant-client + , servant-docs + , servant-openapi3 + , servant-server + , shellmet + , split + , stm + , tagged + , temporary + , terminal-size >=0.3.3 + , text + , text-short + , these + , time + , tls + , transformers + , unicode-show + , unison-codebase + , unison-codebase-sqlite + , unison-codebase-sqlite-hashing-v2 + , unison-codebase-sync + , unison-core + , unison-core1 + , unison-hash + , unison-hashing-v2 + , unison-parser-typechecker + , unison-prelude + , unison-pretty-printer + , unison-runtime + , unison-sqlite + , unison-syntax + , unison-util-base32hex + , unison-util-bytes + , unison-util-cache + , unison-util-relation + , unison-util-rope + , unison-util-serialization + , unliftio + , uri-encode + , utf8-string + , uuid + , vector + , wai + , warp + , witch + , witherable + , yaml + , zlib + default-language: Haskell2010 + if flag(optimized) + ghc-options: -funbox-strict-fields -O2 + if flag(arraychecks) + cpp-options: -DARRAY_CHECK diff --git a/unison-share-api/package.yaml b/unison-share-api/package.yaml index 132a62304..830cd46d8 100644 --- a/unison-share-api/package.yaml +++ b/unison-share-api/package.yaml @@ -53,6 +53,7 @@ dependencies: - unison-parser-typechecker - unison-prelude - unison-pretty-printer + - unison-runtime - unison-util-base32hex - unison-util-relation - unison-share-projects-api diff --git a/unison-share-api/src/Unison/Server/Backend.hs b/unison-share-api/src/Unison/Server/Backend.hs index 6bea3c704..f40a85b24 100644 --- a/unison-share-api/src/Unison/Server/Backend.hs +++ b/unison-share-api/src/Unison/Server/Backend.hs @@ -111,6 +111,7 @@ import Unison.Codebase.Branch qualified as Branch import Unison.Codebase.Branch.Names qualified as Branch import Unison.Codebase.Editor.DisplayObject import Unison.Codebase.Editor.DisplayObject qualified as DisplayObject +import Unison.Codebase.Execute qualified as Codebase import Unison.Codebase.Path (Path) import Unison.Codebase.Path qualified as Path import Unison.Codebase.Runtime qualified as Rt @@ -801,7 +802,7 @@ evalDocRef rt codebase r = do eval errsVar (Term.amap (const mempty) -> tm) = do -- We use an empty ppe for evalutation, it's only used for adding additional context to errors. let evalPPE = PPE.empty - let codeLookup = Codebase.toCodeLookup codebase + let codeLookup = Codebase.codebaseToCodeLookup codebase let cache r = fmap Term.unannotate <$> Codebase.runTransaction codebase (Codebase.lookupWatchCache codebase r) r <- fmap hush . liftIO $ Rt.evaluateTerm' codeLookup cache evalPPE rt tm -- Only cache watches when we're not in readonly mode diff --git a/unison-share-api/unison-share-api.cabal b/unison-share-api/unison-share-api.cabal index e3878a9e7..4a257e6f2 100644 --- a/unison-share-api/unison-share-api.cabal +++ b/unison-share-api/unison-share-api.cabal @@ -127,6 +127,7 @@ library , unison-parser-typechecker , unison-prelude , unison-pretty-printer + , unison-runtime , unison-share-projects-api , unison-sqlite , unison-syntax