From 49a7d176c3f1591ce208cc4b92e13af6736a1d20 Mon Sep 17 00:00:00 2001 From: Dan Doel Date: Thu, 14 Dec 2023 15:18:21 -0500 Subject: [PATCH] Formatting --- .../src/Unison/Runtime/Decompile.hs | 15 ++--- .../src/Unison/Runtime/Interface.hs | 59 ++++++++++--------- .../src/Unison/Codebase/Editor/HandleInput.hs | 23 ++++---- .../src/Unison/CommandLine/InputPatterns.hs | 18 +++--- 4 files changed, 62 insertions(+), 53 deletions(-) diff --git a/parser-typechecker/src/Unison/Runtime/Decompile.hs b/parser-typechecker/src/Unison/Runtime/Decompile.hs index fdeb4af930..9da8d47ca8 100644 --- a/parser-typechecker/src/Unison/Runtime/Decompile.hs +++ b/parser-typechecker/src/Unison/Runtime/Decompile.hs @@ -5,14 +5,14 @@ {-# LANGUAGE ViewPatterns #-} module Unison.Runtime.Decompile - ( decompile - , DecompResult - , DecompError (..) - , renderDecompError - ) where + ( decompile, + DecompResult, + DecompError (..), + renderDecompError, + ) +where import Data.Set (singleton) -import Prelude hiding (lines) import Unison.ABT (substs) import Unison.Codebase.Runtime (Error) import Unison.ConstructorReference (GConstructorReference (..)) @@ -65,10 +65,11 @@ import Unison.Type typeLinkRef, ) import Unison.Util.Bytes qualified as By -import Unison.Util.Pretty (lit, indentN, lines, wrap, syntaxToColor) +import Unison.Util.Pretty (indentN, lines, lit, syntaxToColor, wrap) import Unison.Util.Text qualified as Text import Unison.Var (Var) import Unsafe.Coerce -- for Int -> Double +import Prelude hiding (lines) con :: (Var v) => Reference -> Word64 -> Term v () con rf ct = constructor () (ConstructorReference rf $ fromIntegral ct) diff --git a/parser-typechecker/src/Unison/Runtime/Interface.hs b/parser-typechecker/src/Unison/Runtime/Interface.hs index 94250df9c0..b59eab9cac 100644 --- a/parser-typechecker/src/Unison/Runtime/Interface.hs +++ b/parser-typechecker/src/Unison/Runtime/Interface.hs @@ -30,8 +30,8 @@ import Data.Bytes.Get (MonadGet) import Data.Bytes.Put (MonadPut, putWord32be, runPutL, runPutS) import Data.Bytes.Serial import Data.Foldable -import Data.List qualified as L import Data.IORef +import Data.List qualified as L import Data.Map.Strict qualified as Map import Data.Sequence qualified as Seq (fromList) import Data.Set as Set @@ -45,11 +45,11 @@ import Data.Set as Set import Data.Set qualified as Set import Data.Text (isPrefixOf, unpack) import System.Process - ( proc, + ( CreateProcess (..), + StdStream (..), + proc, waitForProcess, withCreateProcess, - CreateProcess(..), - StdStream(..) ) import Unison.Builtin.Decls qualified as RF import Unison.Codebase.CodeLookup (CodeLookup (..)) @@ -72,7 +72,7 @@ import Unison.Runtime.ANF.Rehash as ANF (rehashGroups) import Unison.Runtime.ANF.Serialize as ANF ( getGroup, putGroup, - serializeValue + serializeValue, ) import Unison.Runtime.Builtin import Unison.Runtime.Decompile @@ -412,25 +412,25 @@ loadDeps cl ppe ctx tyrs tmrs = do out@(_, rgrp) <- loadCode cl ppe ctx tmrs out <$ cacheAdd0 tyAdd rgrp (expandSandbox sand rgrp) cc -compileValue :: Reference -> [(Reference, SuperGroup Symbol)] -> Value +compileValue :: Reference -> [(Reference, SuperGroup Symbol)] -> Value compileValue base = flip pair (rf base) . ANF.BLit . List . Seq.fromList . fmap cpair where - rf = ANF.BLit . TmLink . RF.Ref - cons x y = Data RF.pairRef 0 [] [x, y] - tt = Data RF.unitRef 0 [] [] - code sg = ANF.BLit (Code sg) - pair x y = cons x (cons y tt) - cpair (r, sg) = pair (rf r) (code sg) + rf = ANF.BLit . TmLink . RF.Ref + cons x y = Data RF.pairRef 0 [] [x, y] + tt = Data RF.unitRef 0 [] [] + code sg = ANF.BLit (Code sg) + pair x y = cons x (cons y tt) + cpair (r, sg) = pair (rf r) (code sg) decompileCtx :: EnumMap Word64 Reference -> EvalCtx -> Closure -> DecompResult Symbol decompileCtx crs ctx = decompile ib $ backReferenceTm crs fr ir dt where - ib = intermedToBase ctx - fr = floatRemap ctx - ir = intermedRemap ctx - dt = decompTm ctx + ib = intermedToBase ctx + fr = floatRemap ctx + ir = intermedRemap ctx + dt = decompTm ctx nativeEval :: IORef EvalCtx -> @@ -648,12 +648,12 @@ backReferenceTm ws frs irs dcm c i = do Map.lookup i bs schemeProc :: [String] -> CreateProcess -schemeProc args = (proc "native-compiler/bin/runner" args) - { std_in = CreatePipe - , std_out = Inherit - , std_err = Inherit - } - +schemeProc args = + (proc "native-compiler/bin/runner" args) + { std_in = CreatePipe, + std_out = Inherit, + std_err = Inherit + } -- Note: this currently does not support yielding values; instead it -- just produces a result appropriate for unitary `run` commands. The @@ -678,21 +678,22 @@ nativeEvalInContext _ ctx codes base = do let bytes = serializeValue . compileValue base $ codes decodeResult (Left msg) = pure . Left $ fromString msg - decodeResult (Right val) = reifyValue cc val >>= \case - Left _ -> pure . Left $ "missing references from result" - Right cl -> case decompileCtx crs ctx cl of - (errs, dv) -> pure $ Right (listErrors errs, dv) + decodeResult (Right val) = + reifyValue cc val >>= \case + Left _ -> pure . Left $ "missing references from result" + Right cl -> case decompileCtx crs ctx cl of + (errs, dv) -> pure $ Right (listErrors errs, dv) callout (Just pin) _ _ ph = do BS.hPut pin . runPutS . putWord32be . fromIntegral $ BS.length bytes BS.hPut pin bytes UnliftIO.hClose pin let unit = Data RF.unitRef 0 [] [] - sunit = Data RF.pairRef 0 [] [unit,unit] + sunit = Data RF.pairRef 0 [] [unit, unit] waitForProcess ph decodeResult $ Right sunit - -- TODO: actualy receive output from subprocess - -- decodeResult . deserializeValue =<< BS.hGetContents pout + -- TODO: actualy receive output from subprocess + -- decodeResult . deserializeValue =<< BS.hGetContents pout callout _ _ _ _ = pure . Left $ "withCreateProcess didn't provide handles" withCreateProcess (schemeProc []) callout diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs index 9fff1ac701..24acc05d77 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs @@ -2444,8 +2444,8 @@ getSchemeStaticLibDir = liftIO $ getXdgDirectory XdgData ("unisonlanguage" "scheme-libs") -doGenerateSchemeBoot - :: Bool -> Maybe PPE.PrettyPrintEnv -> Maybe String -> Cli () +doGenerateSchemeBoot :: + Bool -> Maybe PPE.PrettyPrintEnv -> Maybe String -> Cli () doGenerateSchemeBoot force mppe mdir = do ppe <- maybe basicPPE pure mppe dir <- maybe getSchemeGenLibDir pure mdir @@ -2585,21 +2585,24 @@ doExecute native main args = do #lastRunResult .= Just (Term.amap (\() -> External) mainRes, mainResType, unisonFile) Cli.respond (RunResult ppe mainRes) where - bonk (_, (_ann, watchKind, _id, _term0, term1, _isCacheHit)) = - (watchKind, term1) + bonk (_, (_ann, watchKind, _id, _term0, term1, _isCacheHit)) = + (watchKind, term1) doCompile :: Bool -> String -> HQ.HashQualified Name -> Cli () doCompile native output main = do Cli.Env {codebase, runtime, nativeRuntime} <- ask - let theRuntime | native = nativeRuntime - | otherwise = runtime + let theRuntime + | native = nativeRuntime + | otherwise = runtime (ref, ppe) <- resolveMainRef main let codeLookup = () <$ Codebase.toCodeLookup codebase - outf | native = output - | otherwise = output <> ".uc" + outf + | native = output + | otherwise = output <> ".uc" whenJustM - (liftIO $ - Runtime.compileTo theRuntime codeLookup ppe ref outf) + ( liftIO $ + Runtime.compileTo theRuntime codeLookup ppe ref outf + ) (Cli.returnEarly . EvaluationFailure) doRunAsScheme :: String -> [String] -> Cli () diff --git a/unison-cli/src/Unison/CommandLine/InputPatterns.hs b/unison-cli/src/Unison/CommandLine/InputPatterns.hs index be021cc689..745b0188a8 100644 --- a/unison-cli/src/Unison/CommandLine/InputPatterns.hs +++ b/unison-cli/src/Unison/CommandLine/InputPatterns.hs @@ -2495,13 +2495,17 @@ createAuthor = [] I.Visible [(Required, noCompletionsArg), (Required, noCompletionsArg)] - ( makeExample createAuthor ["alicecoder", "\"Alice McGee\""] <> " " - <> P.wrap (" creates " - <> backtick "alicecoder" - <> "values in" - <> backtick "metadata.authors" - <> "and" - <> backtick (P.group ("metadata.copyrightHolders" <> ".")))) + ( makeExample createAuthor ["alicecoder", "\"Alice McGee\""] + <> " " + <> P.wrap + ( " creates " + <> backtick "alicecoder" + <> "values in" + <> backtick "metadata.authors" + <> "and" + <> backtick (P.group ("metadata.copyrightHolders" <> ".")) + ) + ) ( \case symbolStr : authorStr@(_ : _) -> first fromString $ do symbol <- Path.definitionNameSegment symbolStr