Skip to content

Commit

Permalink
Ormolu-ify the codebase and update development.markdown docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pchiusano committed Feb 13, 2023
1 parent 76c0f0b commit 88ef0a8
Show file tree
Hide file tree
Showing 222 changed files with 2,862 additions and 2,485 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ where
import qualified Data.Set as Set
import U.Codebase.Sqlite.HashHandle
import U.Util.Type (removeAllEffectVars)
import Unison.Hashing.V2.Convert2 (h2ToV2Reference, v2ToH2Type, v2ToH2TypeD)
import qualified Unison.Hashing.V2 as H2
import Unison.Hashing.V2.Convert2 (h2ToV2Reference, v2ToH2Type, v2ToH2TypeD)

v2HashHandle :: HashHandle
v2HashHandle =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ convertReference' idConv = \case
V2.ReferenceBuiltin x -> H2.ReferenceBuiltin x
V2.ReferenceDerived x -> H2.ReferenceDerivedId (idConv x)

v2ToH2Type :: forall v. Ord v => V2.Type.TypeR V2.TypeRef v -> H2.Type v ()
v2ToH2Type :: forall v. (Ord v) => V2.Type.TypeR V2.TypeRef v -> H2.Type v ()
v2ToH2Type = v2ToH2Type' convertReference

v2ToH2TypeD :: forall v. Ord v => Hash -> V2.Type.TypeD v -> H2.Type v ()
v2ToH2TypeD :: forall v. (Ord v) => Hash -> V2.Type.TypeD v -> H2.Type v ()
v2ToH2TypeD defaultHash = v2ToH2Type' (convertReference' (convertId defaultHash))

v2ToH2Type' :: forall r v. Ord v => (r -> H2.Reference) -> V2.Type.TypeR r v -> H2.Type v ()
v2ToH2Type' :: forall r v. (Ord v) => (r -> H2.Reference) -> V2.Type.TypeR r v -> H2.Type v ()
v2ToH2Type' mkReference = ABT.transform convertF
where
convertF :: forall a. V2.Type.F' r a -> H2.TypeF a
Expand Down
4 changes: 2 additions & 2 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/LocalizeObject.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type LocalizeBranchState =
)

-- Run a computation that localizes a branch object, returning the local ids recorded within.
runLocalizeBranch :: Monad m => StateT LocalizeBranchState m a -> m (BranchLocalIds, a)
runLocalizeBranch :: (Monad m) => StateT LocalizeBranchState m a -> m (BranchLocalIds, a)
runLocalizeBranch action = do
(result, (localTexts, localDefns, localPatches, localChildren)) <- State.runStateT action (mempty @LocalizeBranchState)
let branchLocalIds :: BranchLocalIds
Expand All @@ -143,7 +143,7 @@ type LocalizePatchState =
)

-- Run a computation that localizes a patch object, returning the local ids recorded within.
runLocalizePatch :: Monad m => StateT LocalizePatchState m a -> m (PatchLocalIds, a)
runLocalizePatch :: (Monad m) => StateT LocalizePatchState m a -> m (PatchLocalIds, a)
runLocalizePatch action = do
(result, (localTexts, localHashes, localDefns)) <- State.runStateT action (mempty @LocalizePatchState)
let patchLocalIds :: PatchLocalIds
Expand Down
6 changes: 3 additions & 3 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/NamedRef.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ instance FromField (ConstructorType) where
data NamedRef ref = NamedRef {reversedSegments :: ReversedSegments, ref :: ref}
deriving stock (Show, Functor, Foldable, Traversable)

instance ToRow ref => ToRow (NamedRef ref) where
instance (ToRow ref) => ToRow (NamedRef ref) where
toRow (NamedRef {reversedSegments = segments, ref}) =
[toField reversedName] <> toRow ref
where
reversedName = Text.intercalate "." . toList $ segments

instance FromRow ref => FromRow (NamedRef ref) where
instance (FromRow ref) => FromRow (NamedRef ref) where
fromRow = do
reversedSegments <- NonEmpty.fromList . Text.splitOn "." <$> field
ref <- fromRow
pure (NamedRef {reversedSegments, ref})

toRowWithNamespace :: ToRow ref => NamedRef ref -> [SQLData]
toRowWithNamespace :: (ToRow ref) => NamedRef ref -> [SQLData]
toRowWithNamespace nr = toRow nr <> [SQLText namespace]
where
namespace = Text.intercalate "." . reverse . NEL.tail . reversedSegments $ nr
17 changes: 11 additions & 6 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/Operations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ s2cBranch (S.Branch.Full.Branch tms tps patches children) =
Map Db.TextId (Db.BranchObjectId, Db.CausalHashId) ->
Transaction (Map NameSegment (C.Causal Transaction CausalHash BranchHash (C.Branch.Branch Transaction)))
doChildren = Map.bitraverse (fmap NameSegment . Q.expectText) \(boId, chId) ->
C.Causal <$> Q.expectCausalHash chId
C.Causal
<$> Q.expectCausalHash chId
<*> expectValueHashByCausalHashId chId
<*> headParents chId
<*> pure (expectBranch boId)
Expand Down Expand Up @@ -572,7 +573,8 @@ s2cBranch (S.Branch.Full.Branch tms tps patches children) =
Db.CausalHashId ->
Transaction (C.Causal Transaction CausalHash BranchHash (C.Branch.Branch Transaction))
loadCausal chId = do
C.Causal <$> Q.expectCausalHash chId
C.Causal
<$> Q.expectCausalHash chId
<*> expectValueHashByCausalHashId chId
<*> headParents chId
<*> pure (loadValue chId)
Expand Down Expand Up @@ -771,7 +773,7 @@ expectDbBranch id =
(mergePatches patches patches')
(mergeChildren children children')
mergeChildren ::
Ord ns =>
(Ord ns) =>
Map ns (Db.BranchObjectId, Db.CausalHashId) ->
Map ns S.BranchDiff.ChildOp ->
Map ns (Db.BranchObjectId, Db.CausalHashId)
Expand All @@ -794,7 +796,7 @@ expectDbBranch id =
S.BranchDiff.ChildAddReplace id -> id
S.BranchDiff.ChildRemove -> error "diff tries to remove a nonexistent child"
mergePatches ::
Ord ns =>
(Ord ns) =>
Map ns Db.PatchObjectId ->
Map ns S.BranchDiff.PatchOp ->
Map ns Db.PatchObjectId
Expand Down Expand Up @@ -826,7 +828,7 @@ expectDbBranch id =
S.Branch.Diff.RemoveDef -> error "diff tries to remove a nonexistent definition"
S.Branch.Diff.AlterDefMetadata _md -> error "diff tries to change metadata for a nonexistent definition"
mergeDefnOp ::
Ord r =>
(Ord r) =>
Map r S.MetadataSet.DbMetadataSet ->
Map r S.BranchDiff.DefinitionOp ->
Map r S.MetadataSet.DbMetadataSet
Expand Down Expand Up @@ -872,7 +874,10 @@ saveDbBranchUnderHashId hh bhId@(Db.unBranchHashId -> hashId) stats branch = do
let (localBranchIds, localBranch) = LocalizeObject.localizeBranch branch
when debug $
traceM $
"saveBranchObject\n\tid = " ++ show bhId ++ "\n\tli = " ++ show localBranchIds
"saveBranchObject\n\tid = "
++ show bhId
++ "\n\tli = "
++ show localBranchIds
++ "\n\tlBranch = "
++ show localBranch
let bytes = S.putBytes S.putBranchFormat $ S.BranchFormat.Full localBranchIds localBranch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ applyPatchDiffs =
addRemove add del src =
Map.unionWith (<>) add (Map.differenceWith remove src del)

remove :: Ord b => Set b -> Set b -> Maybe (Set b)
remove :: (Ord b) => Set b -> Set b -> Maybe (Set b)
remove src del =
let diff = Set.difference src del
in if Set.null diff then Nothing else Just diff
Expand Down
6 changes: 3 additions & 3 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ saveDeclComponent hh@HashHandle {toReferenceDecl, toReferenceDeclMentions} maybe
pure oId

-- | implementation detail of {s,w}2c*Term* & s2cDecl
localIdsToLookups :: Monad m => (t -> m Text) -> (d -> m Hash) -> LocalIds' t d -> m (LocalTextId -> Text, LocalDefnId -> Hash)
localIdsToLookups :: (Monad m) => (t -> m Text) -> (d -> m Hash) -> LocalIds' t d -> m (LocalTextId -> Text, LocalDefnId -> Hash)
localIdsToLookups loadText loadHash localIds = do
texts <- traverse loadText $ LocalIds.textLookup localIds
hashes <- traverse loadHash $ LocalIds.defnLookup localIds
Expand Down Expand Up @@ -2174,7 +2174,7 @@ localIdsToTypeRefLookup localIds = do

c2sDecl ::
forall m t d.
Monad m =>
(Monad m) =>
(Text -> m t) ->
(Hash -> m d) ->
C.Decl Symbol ->
Expand Down Expand Up @@ -2210,7 +2210,7 @@ c2sDecl saveText saveDefn (C.Decl.DataDeclaration dt m b cts) = do

-- | implementation detail of c2{s,w}Term
-- The Type is optional, because we don't store them for watch expression results.
c2xTerm :: forall m t d. Monad m => (Text -> m t) -> (Hash -> m d) -> C.Term Symbol -> Maybe (C.Term.Type Symbol) -> m (LocalIds' t d, S.Term.Term, Maybe (S.Term.Type))
c2xTerm :: forall m t d. (Monad m) => (Text -> m t) -> (Hash -> m d) -> C.Term Symbol -> Maybe (C.Term.Type Symbol) -> m (LocalIds' t d, S.Term.Term, Maybe (S.Term.Type))
c2xTerm saveText saveDefn tm tp =
done =<< (runWriterT . flip evalStateT mempty) do
sterm <- ABT.transformM go tm
Expand Down
4 changes: 2 additions & 2 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/Reference.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ referenceFromRow' = liftA3 mkRef field field field
where
str = "(" ++ show t ++ ", " ++ show h ++ ", " ++ show i ++ ")"

instance ToField h => ToRow (Id' h) where
instance (ToField h) => ToRow (Id' h) where
toRow = \case
Id h i -> toRow (Only h) ++ toRow (Only i)

instance FromField h => FromRow (Id' h) where
instance (FromField h) => FromRow (Id' h) where
fromRow = Id <$> field <*> field
Loading

0 comments on commit 88ef0a8

Please sign in to comment.