Skip to content

Commit

Permalink
Merge pull request #4784 from unisonweb/format/aryairani-patch-4
Browse files Browse the repository at this point in the history
autoformat aryairani-patch-4
  • Loading branch information
aryairani authored Mar 13, 2024
2 parents 75fabc4 + f88d652 commit 7d95ed5
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import Unison.Codebase.Path (Path)
import Unison.Codebase.Path qualified as Path
import Unison.Codebase.ShortCausalHash (ShortCausalHash)
import Unison.Codebase.ShortCausalHash qualified as SCH
import Unison.NameSegment qualified as NameSegment
import Unison.Prelude
import Unison.Project (ProjectAndBranch (..), ProjectBranchName, ProjectName)
import Unison.Share.Types
import Unison.Util.Monoid qualified as Monoid
import qualified Unison.NameSegment as NameSegment

data ReadRepo
= ReadRepoGit ReadGitRepo
Expand Down
34 changes: 19 additions & 15 deletions parser-typechecker/src/Unison/Runtime/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Control.Monad.Catch (MonadCatch)
import Control.Monad.Primitive qualified as PA
import Control.Monad.Reader (ReaderT (..), ask, runReaderT)
import Control.Monad.State.Strict (State, execState, modify)
import Crypto.Error (CryptoError(..), CryptoFailable(..))
import Crypto.Error (CryptoError (..), CryptoFailable (..))
import Crypto.Hash qualified as Hash
import Crypto.MAC.HMAC qualified as HMAC
import Crypto.PubKey.Ed25519 qualified as Ed25519
Expand Down Expand Up @@ -2823,10 +2823,12 @@ declareForeigns = do
in pure . Bytes.fromArray . hmac alg $ serializeValueLazy x

declareForeign Untracked "crypto.Ed25519.sign.impl" boxBoxBoxToEFBox
. mkForeign $ pure . signEd25519Wrapper
. mkForeign
$ pure . signEd25519Wrapper

declareForeign Untracked "crypto.Ed25519.verify.impl" boxBoxBoxToEFBool
. mkForeign $ pure . verifyEd25519Wrapper
. mkForeign
$ pure . verifyEd25519Wrapper

let catchAll :: (MonadCatch m, MonadIO m, NFData a) => m a -> m (Either Util.Text.Text a)
catchAll e = do
Expand Down Expand Up @@ -3426,15 +3428,16 @@ hostPreference (Just host) = SYS.Host $ Util.Text.unpack host
signEd25519Wrapper ::
(Bytes.Bytes, Bytes.Bytes, Bytes.Bytes) -> Either Failure Bytes.Bytes
signEd25519Wrapper (secret0, public0, msg0) = case validated of
CryptoFailed err ->
Left (Failure Ty.cryptoFailureRef (errMsg err) unitValue)
CryptoPassed (secret, public) ->
Right . Bytes.fromArray $ Ed25519.sign secret public msg
CryptoFailed err ->
Left (Failure Ty.cryptoFailureRef (errMsg err) unitValue)
CryptoPassed (secret, public) ->
Right . Bytes.fromArray $ Ed25519.sign secret public msg
where
msg = Bytes.toArray msg0 :: ByteString
validated =
(,) <$> Ed25519.secretKey (Bytes.toArray secret0 :: ByteString)
<*> Ed25519.publicKey (Bytes.toArray public0 :: ByteString)
(,)
<$> Ed25519.secretKey (Bytes.toArray secret0 :: ByteString)
<*> Ed25519.publicKey (Bytes.toArray public0 :: ByteString)

errMsg CryptoError_PublicKeySizeInvalid =
"ed25519: Public key size invalid"
Expand All @@ -3447,15 +3450,16 @@ signEd25519Wrapper (secret0, public0, msg0) = case validated of
verifyEd25519Wrapper ::
(Bytes.Bytes, Bytes.Bytes, Bytes.Bytes) -> Either Failure Bool
verifyEd25519Wrapper (public0, msg0, sig0) = case validated of
CryptoFailed err ->
Left $ Failure Ty.cryptoFailureRef (errMsg err) unitValue
CryptoPassed (public, sig) ->
Right $ Ed25519.verify public msg sig
CryptoFailed err ->
Left $ Failure Ty.cryptoFailureRef (errMsg err) unitValue
CryptoPassed (public, sig) ->
Right $ Ed25519.verify public msg sig
where
msg = Bytes.toArray msg0 :: ByteString
validated =
(,) <$> Ed25519.publicKey (Bytes.toArray public0 :: ByteString)
<*> Ed25519.signature (Bytes.toArray sig0 :: ByteString)
(,)
<$> Ed25519.publicKey (Bytes.toArray public0 :: ByteString)
<*> Ed25519.signature (Bytes.toArray sig0 :: ByteString)

errMsg CryptoError_PublicKeySizeInvalid =
"ed25519: Public key size invalid"
Expand Down
5 changes: 3 additions & 2 deletions parser-typechecker/src/Unison/Syntax/FileParser.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Unison.Syntax.FileParser
( file
) where
( file,
)
where

import Control.Lens
import Control.Monad.Reader (asks, local)
Expand Down
9 changes: 5 additions & 4 deletions parser-typechecker/src/Unison/Syntax/TypeParser.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{-# LANGUAGE OverloadedStrings #-}

module Unison.Syntax.TypeParser
( computationType
, valueType
, valueTypeLeaf
) where
( computationType,
valueType,
valueTypeLeaf,
)
where

import Control.Monad.Reader (asks)
import Data.Set qualified as Set
Expand Down
18 changes: 9 additions & 9 deletions unison-cli/src/Unison/Cli/ProjectUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ import Unison.Sqlite qualified as Sqlite
import Witch (unsafeFrom)

branchRelativePathToAbsolute :: BranchRelativePath -> Cli Path.Absolute
branchRelativePathToAbsolute brp = resolveBranchRelativePath brp <&> \case
BranchRelativePath.ResolvedLoosePath p -> p
BranchRelativePath.ResolvedBranchRelative projectBranch mRel ->
let projectBranchIds = getIds projectBranch
handleRel = case mRel of
Nothing -> id
Just rel -> flip Path.resolve rel
in handleRel (projectBranchPath projectBranchIds)
branchRelativePathToAbsolute brp =
resolveBranchRelativePath brp <&> \case
BranchRelativePath.ResolvedLoosePath p -> p
BranchRelativePath.ResolvedBranchRelative projectBranch mRel ->
let projectBranchIds = getIds projectBranch
handleRel = case mRel of
Nothing -> id
Just rel -> flip Path.resolve rel
in handleRel (projectBranchPath projectBranchIds)
where
getIds = \case
ProjectAndBranch project branch -> ProjectAndBranch (view #projectId project) (view #branchId branch)
Expand All @@ -91,7 +92,6 @@ resolveBranchRelativePath = \case
toThese = \case
Left branchName -> That branchName
Right (projectName, branchName) -> These projectName branchName


-- | Get the current project that a user is on.
getCurrentProject :: Cli (Maybe Sqlite.Project)
Expand Down
4 changes: 2 additions & 2 deletions unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,7 @@ renderEditConflicts ppe Patch {..} = do
then "deprecated and also replaced with"
else "replaced with"
)
`P.hang` P.lines replacements
`P.hang` P.lines replacements
formatTermEdits ::
(Reference.TermReference, Set TermEdit.TermEdit) ->
Numbered Pretty
Expand All @@ -2772,7 +2772,7 @@ renderEditConflicts ppe Patch {..} = do
then "deprecated and also replaced with"
else "replaced with"
)
`P.hang` P.lines replacements
`P.hang` P.lines replacements
formatConflict ::
Either
(Reference, Set TypeEdit.TypeEdit)
Expand Down
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/LSP/Completion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Unison.Referent qualified as Referent
import Unison.Runtime.IOSource qualified as IOSource
import Unison.Syntax.DeclPrinter qualified as DeclPrinter
import Unison.Syntax.HashQualified' qualified as HQ' (toText)
import Unison.Syntax.Name qualified as Name (parseText, nameP, toText)
import Unison.Syntax.Name qualified as Name (nameP, parseText, toText)
import Unison.Syntax.TypePrinter qualified as TypePrinter
import Unison.Util.Monoid qualified as Monoid
import Unison.Util.Pretty qualified as Pretty
Expand Down
13 changes: 7 additions & 6 deletions unison-cli/transcripts/Transcripts.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

{- This module kicks off the Transcript Tests.
It doesn't do the transcript parsing itself.
Expand All @@ -16,8 +17,8 @@ import System.FilePath
splitFileName,
takeDirectory,
takeExtensions,
(</>),
(<.>),
(</>),
)
import System.IO.CodePage (withCP65001)
import System.IO.Silently (silence)
Expand Down Expand Up @@ -82,7 +83,7 @@ outputFileForTranscript filePath =
replaceExtension filePath ".output.md"

buildTests :: TestConfig -> TestBuilder -> FilePath -> Test ()
buildTests TestConfig{ .. } testBuilder dir = do
buildTests TestConfig {..} testBuilder dir = do
io
. putStrLn
. unlines
Expand Down Expand Up @@ -149,9 +150,9 @@ test config = do
cleanup

handleArgs :: TestConfig -> [String] -> TestConfig
handleArgs acc ("--runtime-path":p:rest) =
handleArgs (acc { runtimePath = p }) rest
handleArgs acc [prefix] = acc { matchPrefix = Just prefix }
handleArgs acc ("--runtime-path" : p : rest) =
handleArgs (acc {runtimePath = p}) rest
handleArgs acc [prefix] = acc {matchPrefix = Just prefix}
handleArgs acc _ = acc

defaultConfig :: IO TestConfig
Expand Down
4 changes: 2 additions & 2 deletions unison-cli/unison/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ import Network.HTTP.Client.TLS qualified as HTTP
import Stats (recordRtsStats)
import System.Directory
( canonicalizePath,
exeExtension,
getCurrentDirectory,
removeDirectoryRecursive,
exeExtension
)
import System.Environment (getExecutablePath, getProgName, withArgs)
import System.Exit qualified as Exit
import System.FilePath
( replaceExtension,
takeDirectory,
takeExtension,
(</>),
(<.>),
(</>),
)
import System.IO (stderr)
import System.IO.CodePage (withCP65001)
Expand Down
1 change: 0 additions & 1 deletion unison-core/src/Unison/Kind.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ module Unison.Kind where
import Unison.Prelude

data Kind = Star | Arrow Kind Kind deriving (Eq, Ord, Read, Show, Generic)

2 changes: 1 addition & 1 deletion unison-core/src/Unison/Name/Forward.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Unison.Name qualified as Name
import Unison.Name.Internal (Name)
import Unison.NameSegment (NameSegment)

newtype ForwardName = ForwardName { toList :: NonEmpty NameSegment } deriving (Eq, Ord, Show)
newtype ForwardName = ForwardName {toList :: NonEmpty NameSegment} deriving (Eq, Ord, Show)

-- | O(d)
fromName :: Name -> ForwardName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import Unison.Server.Types
mayDefaultWidth,
)
import Unison.Symbol (Symbol)
import Unison.Syntax.Name qualified as Name
import Unison.Util.Pretty (Width)
import qualified Unison.Syntax.Name as Name

type FuzzyFindAPI =
"find"
Expand Down
17 changes: 9 additions & 8 deletions unison-share-api/src/Unison/Server/NameSearch.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
module Unison.Server.NameSearch
( Search(..)
, NameSearch(..)
, hoistSearch
, hoistNameSearch
, applySearch
, SearchType(..)
) where
( Search (..),
NameSearch (..),
hoistSearch,
hoistNameSearch,
applySearch,
SearchType (..),
)
where

import Control.Lens
import Data.List qualified as List
import Data.Set qualified as Set
import Unison.HashQualified qualified as HQ
import Unison.HashQualified' qualified as HQ'
import Unison.Name (Name)
import Unison.NamesWithHistory (SearchType(..))
import Unison.NamesWithHistory (SearchType (..))
import Unison.Prelude
import Unison.Reference (Reference)
import Unison.Referent (Referent)
Expand Down
4 changes: 2 additions & 2 deletions unison-share-api/src/Unison/Sync/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,9 @@ instance FromJSON HashMismatchForEntity where
Aeson.withObject "HashMismatchForEntity" \obj ->
HashMismatchForEntity
<$> obj
.: "supplied"
.: "supplied"
<*> obj
.: "computed"
.: "computed"

------------------------------------------------------------------------------------------------------------------------
-- Fast-forward path
Expand Down

0 comments on commit 7d95ed5

Please sign in to comment.