Skip to content

Commit

Permalink
Merge pull request #5239 from sellout/reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
aryairani authored Jul 19, 2024
2 parents 42ebc76 + 9ac6a04 commit 01b475c
Show file tree
Hide file tree
Showing 95 changed files with 315 additions and 331 deletions.
4 changes: 4 additions & 0 deletions .ormolu
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
infixl 8 ^?
infixr 4 %%~, %~
infixl 3 <|>
infixl 1 &, <&>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import U.Codebase.HashTags
import Unison.Hashing.V2 qualified as Hashing
import Unison.Hashing.V2.Convert2 (convertBranchV3, v2ToH2Branch)

hashBranch :: forall m. Monad m => Branch m -> m BranchHash
hashBranch :: forall m. (Monad m) => Branch m -> m BranchHash
hashBranch branch =
BranchHash . Hashing.contentHash <$> v2ToH2Branch branch

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ v2ToH2Referent = \case
V2Referent.Ref r -> H2.ReferentRef (v2ToH2Reference r)
V2Referent.Con r cid -> H2.ReferentCon (v2ToH2Reference r) cid

v2ToH2Branch :: Monad m => V2.Branch m -> m H2.Branch
v2ToH2Branch :: (Monad m) => V2.Branch m -> m H2.Branch
v2ToH2Branch V2.Branch {terms, types, patches, children} = do
hterms <-
traverse sequenceA terms
Expand Down Expand Up @@ -166,7 +166,7 @@ hashPatchFormatToH2Patch Memory.PatchFull.Patch {termEdits, typeEdits} =
V2Referent.Con typeRef conId -> do
(H2.ReferentCon (v2ToH2Reference $ second unComponentHash typeRef) conId)

v2ToH2Term :: forall v. Ord v => V2.Term.HashableTerm v -> H2.Term v ()
v2ToH2Term :: forall v. (Ord v) => V2.Term.HashableTerm v -> H2.Term v ()
v2ToH2Term = ABT.transform convertF
where
convertF :: V2.Term.F' Text V2.Term.HashableTermRef V2.Term.TypeRef V2.Term.HashableTermLink V2.Term.TypeLink v a1 -> H2.TermF v () () a1
Expand Down
2 changes: 1 addition & 1 deletion codebase2/codebase-sqlite/U/Codebase/Sqlite/Decode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ decodeWatchResultFormat =
------------------------------------------------------------------------------------------------------------------------
-- unsyncs

unsyncTermComponent :: HasCallStack => TermFormat.SyncLocallyIndexedComponent' t d -> Either DecodeError (TermFormat.LocallyIndexedComponent' t d)
unsyncTermComponent :: (HasCallStack) => TermFormat.SyncLocallyIndexedComponent' t d -> Either DecodeError (TermFormat.LocallyIndexedComponent' t d)
unsyncTermComponent (TermFormat.SyncLocallyIndexedComponent terms) = do
let phi (localIds, bs) = do
(a, b) <- decodeSyncTermAndType bs
Expand Down
2 changes: 1 addition & 1 deletion codebase2/codebase-sqlite/U/Codebase/Sqlite/HashHandle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data HashHandle = HashHandle
toReferenceDecl :: Hash -> C.Type.TypeD Symbol -> C.Reference,
-- | Hash decl's mentions
toReferenceDeclMentions :: Hash -> C.Type.TypeD Symbol -> Set C.Reference,
hashBranch :: forall m. Monad m => Branch m -> m BranchHash,
hashBranch :: forall m. (Monad m) => Branch m -> m BranchHash,
hashBranchV3 :: forall m. BranchV3 m -> BranchHash,
hashCausal ::
-- The causal's namespace hash
Expand Down
24 changes: 12 additions & 12 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/LocalizeObject.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ localizePatchG (Patch termEdits typeEdits) =
-- General-purpose localization

-- Contains references to branch objects.
class Ord c => ContainsBranches c s where
class (Ord c) => ContainsBranches c s where
branches_ :: Lens' s (Map c LocalBranchChildId)

-- Contains references to definition objects i.e. term/decl component objects.
class Ord d => ContainsDefns d s where
class (Ord d) => ContainsDefns d s where
defns_ :: Lens' s (Map d LocalDefnId)

-- Contains references to objects by their hash.
class Ord h => ContainsHashes h s where
class (Ord h) => ContainsHashes h s where
hashes_ :: Lens' s (Map h LocalHashId)

-- Contains references to patch objects.
class Ord p => ContainsPatches p s where
class (Ord p) => ContainsPatches p s where
patches_ :: Lens' s (Map p LocalPatchObjectId)

-- Contains text.
class Ord t => ContainsText t s where
class (Ord t) => ContainsText t s where
texts_ :: Lens' s (Map t LocalTextId)

-- The inner state of the localization of a branch object.
Expand All @@ -137,16 +137,16 @@ data LocalizeBranchState t d p c = LocalizeBranchState
}
deriving (Show, Generic)

instance Ord t => ContainsText t (LocalizeBranchState t d p c) where
instance (Ord t) => ContainsText t (LocalizeBranchState t d p c) where
texts_ = field @"texts"

instance Ord d => ContainsDefns d (LocalizeBranchState t d p c) where
instance (Ord d) => ContainsDefns d (LocalizeBranchState t d p c) where
defns_ = field @"defns"

instance Ord p => ContainsPatches p (LocalizeBranchState t d p c) where
instance (Ord p) => ContainsPatches p (LocalizeBranchState t d p c) where
patches_ = field @"patches"

instance Ord c => ContainsBranches c (LocalizeBranchState t d p c) where
instance (Ord c) => ContainsBranches c (LocalizeBranchState t d p c) where
branches_ = field @"branches"

-- | Run a computation that localizes a branch object, returning the local ids recorded within.
Expand All @@ -171,13 +171,13 @@ data LocalizePatchState t h d = LocalizePatchState
}
deriving (Show, Generic)

instance Ord t => ContainsText t (LocalizePatchState t h d) where
instance (Ord t) => ContainsText t (LocalizePatchState t h d) where
texts_ = field @"texts"

instance Ord h => ContainsHashes h (LocalizePatchState t h d) where
instance (Ord h) => ContainsHashes h (LocalizePatchState t h d) where
hashes_ = field @"hashes"

instance Ord d => ContainsDefns d (LocalizePatchState t h d) where
instance (Ord d) => ContainsDefns d (LocalizePatchState t h d) where
defns_ = field @"defns"

-- Run a computation that localizes a patch object, returning the local ids recorded within.
Expand Down
2 changes: 1 addition & 1 deletion codebase2/codebase-sqlite/U/Codebase/Sqlite/NamedRef.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ instance (FromRow ref) => FromRow (NamedRef ref) where
newtype ScopedRow ref
= ScopedRow (NamedRef ref)

instance ToRow ref => ToRow (ScopedRow ref) where
instance (ToRow ref) => ToRow (ScopedRow ref) where
toRow (ScopedRow (NamedRef {reversedSegments = revSegments, ref})) =
SQLText reversedName : SQLText namespace : SQLText lastNameSegment : toRow ref
where
Expand Down
2 changes: 1 addition & 1 deletion codebase2/codebase-sqlite/U/Codebase/Sqlite/Patch/Full.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ patchT_ f Patch {termEdits, typeEdits} = do
newTypeEdits <- traverseOf (Map.bitraversed (Reference.t_) (Set.traverse . traverseFirst)) f typeEdits
pure Patch {termEdits = newTermEdits, typeEdits = newTypeEdits}
where
traverseFirst :: Bitraversable b => Traversal (b a c) (b a' c) a a'
traverseFirst :: (Bitraversable b) => Traversal (b a c) (b a' c) a a'
traverseFirst f = bitraverse f pure

patchH_ :: (Ord t, Ord h') => Traversal (Patch' t h o) (Patch' t h' o) h h'
Expand Down
2 changes: 1 addition & 1 deletion codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ module U.Codebase.Sqlite.Queries
-- * Types
NamespaceText,
TextPathSegments,
JsonParseFailure(..),
JsonParseFailure (..),
)
where

Expand Down
6 changes: 3 additions & 3 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/Serialization.hs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ putDeclFormat = \case
putDeclComponent (DeclFormat.LocallyIndexedComponent v) =
putFramedArray (putPair putLocalIds putDeclElement) v

putDeclElement :: MonadPut m => Decl.DeclR DeclFormat.TypeRef Symbol -> m ()
putDeclElement :: (MonadPut m) => Decl.DeclR DeclFormat.TypeRef Symbol -> m ()
putDeclElement Decl.DataDeclaration {..} = do
putDeclType declType
putModifier modifier
Expand Down Expand Up @@ -499,7 +499,7 @@ getDeclElement =
1 -> pure Decl.Effect
other -> unknownTag "DeclType" other

getModifier :: MonadGet m => m Modifier
getModifier :: (MonadGet m) => m Modifier
getModifier =
getWord8 >>= \case
0 -> pure Decl.Structural
Expand Down Expand Up @@ -720,7 +720,7 @@ getLocalBranch =
x -> unknownTag "getMetadataSetFormat" x

getBranchDiff' ::
MonadGet m =>
(MonadGet m) =>
m branchRef ->
m (BranchFormat.BranchLocalIds' text defRef patchRef childRef) ->
m (BranchFormat.BranchFormat' text defRef patchRef childRef branchRef)
Expand Down
4 changes: 2 additions & 2 deletions codebase2/codebase/U/Codebase/Causal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ data Causal m hc he pe e = Causal
}
deriving stock (Functor, Generic)

instance Eq hc => Eq (Causal m hc he pe e) where
instance (Eq hc) => Eq (Causal m hc he pe e) where
(==) = (==) `on` causalHash

-- | @emap f g@ maps over the values and parents' values with @f@ and @g@.
emap :: Functor m => (e -> e') -> (pe -> pe') -> Causal m hc he pe e -> Causal m hc he pe' e'
emap :: (Functor m) => (e -> e') -> (pe -> pe') -> Causal m hc he pe e -> Causal m hc he pe' e'
emap f g causal@Causal {parents, value} =
causal
{ parents = Map.map (fmap (emap g g)) parents,
Expand Down
6 changes: 3 additions & 3 deletions codebase2/codebase/U/Codebase/Decl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ data DeclR r v = DataDeclaration
}
deriving (Show)

allVars :: Ord v => DeclR r v -> Set v
allVars :: (Ord v) => DeclR r v -> Set v
allVars (DataDeclaration _ _ bound constructorTypes) =
(Set.fromList $ foldMap ABT.allVars constructorTypes) <> Set.fromList bound

vmap :: Ord v' => (v -> v') -> DeclR r v -> DeclR r v'
vmap :: (Ord v') => (v -> v') -> DeclR r v -> DeclR r v'
vmap f (DataDeclaration {declType, modifier, bound, constructorTypes}) =
DataDeclaration
{ declType,
Expand Down Expand Up @@ -82,7 +82,7 @@ data F a
-- to the relevant piece of the component in the component map.
unhashComponent ::
forall v extra.
ABT.Var v =>
(ABT.Var v) =>
Hash ->
-- | A function to convert a reference to a variable. The actual var names aren't important.
(Reference.Id -> v) ->
Expand Down
4 changes: 2 additions & 2 deletions codebase2/codebase/U/Codebase/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ extraMapM ftext ftermRef ftypeRef ftermLink ftypeLink fvt = go'
rmapPattern :: (t -> t') -> (r -> r') -> Pattern t r -> Pattern t' r'
rmapPattern ft fr p = runIdentity . rmapPatternM (pure . ft) (pure . fr) $ p

rmapPatternM :: Applicative m => (t -> m t') -> (r -> m r') -> Pattern t r -> m (Pattern t' r')
rmapPatternM :: (Applicative m) => (t -> m t') -> (r -> m r') -> Pattern t r -> m (Pattern t' r')
rmapPatternM ft fr = go
where
go = \case
Expand Down Expand Up @@ -260,7 +260,7 @@ dependencies =
-- to the relevant piece of the component in the component map.
unhashComponent ::
forall v extra.
ABT.Var v =>
(ABT.Var v) =>
-- | The hash of the component, this is used to fill in self-references.
Hash ->
-- | A function to convert a reference to a variable. The actual var names aren't important.
Expand Down
13 changes: 7 additions & 6 deletions codebase2/core/Unison/NameSegment/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ newtype NameSegment = NameSegment
deriving newtype (Alphabetical)

instance
TypeError
( 'TypeError.Text "You cannot implicitly convert a ‘String’ to a ‘NameSegment’. If you need a"
':$$: 'TypeError.Text "special-cased segment it should exist as a constant in"
':$$: 'TypeError.Text "“Unison.NameSegment”, otherwise it should be parsed via"
':$$: 'TypeError.Text "“Unison.Syntax.NameSegment”."
) =>
( TypeError
( 'TypeError.Text "You cannot implicitly convert a ‘String’ to a ‘NameSegment’. If you need a"
':$$: 'TypeError.Text "special-cased segment it should exist as a constant in"
':$$: 'TypeError.Text "“Unison.NameSegment”, otherwise it should be parsed via"
':$$: 'TypeError.Text "“Unison.Syntax.NameSegment”."
)
) =>
IsString NameSegment
where
fromString = undefined
4 changes: 2 additions & 2 deletions codebase2/core/Unison/Util/Alphabetical.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import Data.Text (Text)
class (Eq n) => Alphabetical n where
compareAlphabetical :: n -> n -> Ordering

sortAlphabetically :: Alphabetical a => [a] -> [a]
sortAlphabetically :: (Alphabetical a) => [a] -> [a]
sortAlphabetically as = (\(OrderAlphabetically a) -> a) <$> List.sort (map OrderAlphabetically as)

sortAlphabeticallyOn :: Alphabetical a => (b -> a) -> [b] -> [b]
sortAlphabeticallyOn :: (Alphabetical a) => (b -> a) -> [b] -> [b]
sortAlphabeticallyOn f = List.sortOn (OrderAlphabetically . f)

instance Alphabetical Text where
Expand Down
2 changes: 1 addition & 1 deletion codebase2/util-serialization/U/Util/Serialization.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ getVector getA = do
length <- getVarInt
Vector.replicateM length getA

skipVector :: MonadGet m => m a -> m ()
skipVector :: (MonadGet m) => m a -> m ()
skipVector getA = do
length <- getVarInt
replicateM_ length getA
Expand Down
2 changes: 1 addition & 1 deletion lib/unison-prelude/src/Unison/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ import Witch as X (From (from), TryFrom (tryFrom), TryFromException (TryFromExce
import Witherable as X (filterA, forMaybe, mapMaybe, wither, witherMap)

-- | Can be removed when we upgrade transformers to a more recent version.
hoistMaybe :: Applicative m => Maybe a -> MaybeT m a
hoistMaybe :: (Applicative m) => Maybe a -> MaybeT m a
hoistMaybe = MaybeT . pure

-- | Like 'fold' but for Alternative.
Expand Down
16 changes: 8 additions & 8 deletions lib/unison-prelude/src/Unison/Util/Map.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Data.Vector qualified as Vector
import Unison.Prelude hiding (bimap, foldM, for_)

-- | A common case of @Map.merge@. Like @alignWith@, but includes the key.
alignWithKey :: Ord k => (k -> These a b -> c) -> Map k a -> Map k b -> Map k c
alignWithKey :: (Ord k) => (k -> These a b -> c) -> Map k a -> Map k b -> Map k c
alignWithKey f =
Map.merge
(Map.mapMissing \k x -> f k (This x))
Expand All @@ -60,7 +60,7 @@ bitraversed keyT valT f m =

-- | Traverse a map as a list of key-value pairs.
-- Note: This can have unexpected results if the result contains duplicate keys.
asList_ :: Ord k' => Traversal (Map k v) (Map k' v') [(k, v)] [(k', v')]
asList_ :: (Ord k') => Traversal (Map k v) (Map k' v') [(k, v)] [(k', v')]
asList_ f s =
s
& Map.toList
Expand All @@ -73,13 +73,13 @@ swap =
Map.foldlWithKey' (\z a b -> Map.insert b a z) mempty

-- | Like 'Map.insert', but returns the old value as well.
insertLookup :: Ord k => k -> v -> Map k v -> (Maybe v, Map k v)
insertLookup :: (Ord k) => k -> v -> Map k v -> (Maybe v, Map k v)
insertLookup k v =
upsertLookup (const v) k

-- | Invert a map's keys and values. This probably only makes sense with injective maps, but otherwise, later key/value
-- pairs (ordered by the original map's keys) overwrite earlier ones.
invert :: Ord v => Map k v -> Map v k
invert :: (Ord v) => Map k v -> Map v k
invert =
Map.foldlWithKey' (\m k v -> Map.insert v k m) Map.empty

Expand All @@ -94,7 +94,7 @@ upsertF f =
Map.alterF (fmap Just . f)

-- | Like 'upsert', but returns the old value as well.
upsertLookup :: Ord k => (Maybe v -> v) -> k -> Map k v -> (Maybe v, Map k v)
upsertLookup :: (Ord k) => (Maybe v -> v) -> k -> Map k v -> (Maybe v, Map k v)
upsertLookup f =
upsertF (\v -> (v, f v))

Expand All @@ -113,12 +113,12 @@ deleteLookupJust =
Map.alterF (maybe (error (reportBug "E525283" "deleteLookupJust: element not found")) (,Nothing))

-- | Like 'Map.elems', but return the values as a set.
elemsSet :: Ord v => Map k v -> Set v
elemsSet :: (Ord v) => Map k v -> Set v
elemsSet =
Set.fromList . Map.elems

-- | Like 'Map.foldlWithKey'', but with a monadic accumulator.
foldM :: Monad m => (acc -> k -> v -> m acc) -> acc -> Map k v -> m acc
foldM :: (Monad m) => (acc -> k -> v -> m acc) -> acc -> Map k v -> m acc
foldM f acc0 =
go acc0
where
Expand All @@ -141,7 +141,7 @@ foldMapM f =
pure $! Map.insert k v acc

-- | Run a monadic action for each key/value pair in a map.
for_ :: Monad m => Map k v -> (k -> v -> m ()) -> m ()
for_ :: (Monad m) => Map k v -> (k -> v -> m ()) -> m ()
for_ m f =
go m
where
Expand Down
2 changes: 1 addition & 1 deletion lib/unison-prelude/src/Unison/Util/Tuple.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

-- | Tuple utils.
module Unison.Util.Tuple
Expand Down
4 changes: 2 additions & 2 deletions lib/unison-sqlite/src/Unison/Sqlite/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ logQuery (Sql sql params) result =

-- Without results

execute :: HasCallStack => Connection -> Sql -> IO ()
execute :: (HasCallStack) => Connection -> Sql -> IO ()
execute conn@(Connection _ _ conn0) sql@(Sql s params) = do
logQuery sql Nothing
doExecute `catch` \(exception :: Sqlite.SQLError) ->
Expand All @@ -171,7 +171,7 @@ execute conn@(Connection _ _ conn0) sql@(Sql s params) = do
-- | Execute one or more semicolon-delimited statements.
--
-- This function does not support parameters, and is mostly useful for executing DDL and migrations.
executeStatements :: HasCallStack => Connection -> Text -> IO ()
executeStatements :: (HasCallStack) => Connection -> Text -> IO ()
executeStatements conn@(Connection _ _ (Sqlite.Connection database _tempNameCounter)) sql = do
logQuery (Sql sql []) Nothing
Direct.Sqlite.exec database sql `catch` \(exception :: Sqlite.SQLError) ->
Expand Down
2 changes: 1 addition & 1 deletion lib/unison-sqlite/src/Unison/Sqlite/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ data SqliteQueryExceptionInfo = SqliteQueryExceptionInfo
exception :: SomeSqliteExceptionReason
}

throwSqliteQueryException :: HasCallStack => SqliteQueryExceptionInfo -> IO a
throwSqliteQueryException :: (HasCallStack) => SqliteQueryExceptionInfo -> IO a
throwSqliteQueryException SqliteQueryExceptionInfo {connection, exception, sql = Sql sql params} = do
threadId <- myThreadId
throwIO
Expand Down
2 changes: 1 addition & 1 deletion lib/unison-sqlite/src/Unison/Sqlite/Sql.hs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ sqlQQ input =
Nothing -> fail ("Not in scope: " ++ Text.unpack var)
Just name -> (,) <$> [|valuesSql $(TH.varE name)|] <*> [|foldMap Sqlite.Simple.toRow $(TH.varE name)|]

inSql :: Sqlite.Simple.ToField a => [a] -> Text
inSql :: (Sqlite.Simple.ToField a) => [a] -> Text
inSql scalars =
Text.Builder.run ("IN (" <> b_commaSep (map (\_ -> b_qmark) scalars) <> b_rparen)

Expand Down
Loading

0 comments on commit 01b475c

Please sign in to comment.