mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-17 13:27:30 +03:00
fleshed out transcript some more, fixed a number of bugs
This commit is contained in:
parent
720ba7a8c4
commit
4bcd58ecef
@ -20,13 +20,13 @@ import Unison.Util.Relation (Relation)
|
||||
import Unison.Util.Relation3 (Relation3)
|
||||
import Unison.Runtime.IOSource (isPropagatedValue)
|
||||
|
||||
data DiffType a = Create a | Delete a | Modify a
|
||||
data DiffType a = Create a | Delete a | Modify a deriving Show
|
||||
|
||||
-- todo: maybe simplify this file using Relation3?
|
||||
data NamespaceSlice r = NamespaceSlice {
|
||||
names :: Relation r Name,
|
||||
metadata :: Relation3 r Name Metadata.Value
|
||||
}
|
||||
} deriving Show
|
||||
|
||||
data DiffSlice r = DiffSlice {
|
||||
-- tpatchUpdates :: Relation r r, -- old new
|
||||
@ -37,13 +37,13 @@ data DiffSlice r = DiffSlice {
|
||||
tmoves :: Map r (Set Name, Set Name), -- ref (old, new)
|
||||
taddedMetadata :: Relation3 r Name Metadata.Value,
|
||||
tremovedMetadata :: Relation3 r Name Metadata.Value
|
||||
}
|
||||
} deriving Show
|
||||
|
||||
data BranchDiff = BranchDiff
|
||||
{ termsDiff :: DiffSlice Referent
|
||||
, typesDiff :: DiffSlice Reference
|
||||
, patchesDiff :: Map Name (DiffType PatchDiff)
|
||||
}
|
||||
} deriving Show
|
||||
|
||||
diff0 :: forall m. Monad m => Branch0 m -> Branch0 m -> m BranchDiff
|
||||
diff0 old new = BranchDiff terms types <$> patchDiff old new where
|
||||
|
@ -102,6 +102,8 @@ toOutput :: forall m v a
|
||||
-> m (BranchDiffOutput v a)
|
||||
toOutput typeOf declOrBuiltin hqLen names1 names2 ppe
|
||||
(BranchDiff termsDiff typesDiff patchesDiff) = do
|
||||
traceM "termsDiff"
|
||||
traceShowM termsDiff
|
||||
let
|
||||
-- | This calculates the new reference's metadata as:
|
||||
-- adds: now-attached metadata that was missing from
|
||||
@ -123,10 +125,13 @@ toOutput typeOf declOrBuiltin hqLen names1 names2 ppe
|
||||
{ addedMetadata = toList $ new_metadata `Set.difference` old_intersection
|
||||
, removedMetadata = toList $ old_union `Set.difference` new_metadata
|
||||
}
|
||||
getMetadataUpdates s =
|
||||
[ (n, (Set.singleton r, Set.singleton r))
|
||||
-- For the metadata on a definition to have changed, the name
|
||||
-- and the reference must have existed before
|
||||
getMetadataUpdates s = traceShowId $
|
||||
[ (n, (Set.singleton r, Set.singleton r)) -- the reference is unchanged
|
||||
| (r,n,v) <- R3.toList $ BranchDiff.taddedMetadata s <>
|
||||
BranchDiff.tremovedMetadata s
|
||||
, R.notMember r n (BranchDiff.talladds s)
|
||||
, v /= isPropagatedValue ]
|
||||
|
||||
updatedTypes :: [UpdateTypeDisplay v a] <- let
|
||||
@ -148,6 +153,8 @@ toOutput typeOf declOrBuiltin hqLen names1 names2 ppe
|
||||
<*> declOrBuiltin r_new
|
||||
<*> fillMetadata ppe (getNewMetadataDiff typesDiff n rs_old r_new)
|
||||
loadEntry :: (Name, (Set Reference, Set Reference)) -> m (UpdateTypeDisplay v a)
|
||||
loadEntry (n, (Set.toList -> [rold], Set.toList -> [rnew])) | rold == rnew =
|
||||
(Nothing,) <$> for [rnew] (loadNew n (Set.singleton rold))
|
||||
loadEntry (n, (rs_old, rs_new)) =
|
||||
(,) <$> (Just <$> for (toList rs_old) (loadOld n))
|
||||
<*> for (toList rs_new) (loadNew n rs_old)
|
||||
@ -169,10 +176,13 @@ toOutput typeOf declOrBuiltin hqLen names1 names2 ppe
|
||||
<*> pure r_new
|
||||
<*> typeOf r_new
|
||||
<*> fillMetadata ppe (getNewMetadataDiff termsDiff n rs_old r_new)
|
||||
loadEntry (n, (Set.toList -> [rold], Set.toList -> [rnew])) | rold == rnew =
|
||||
(Nothing,) <$> for [rnew] (loadNew n (Set.singleton rold))
|
||||
loadEntry (n, (rs_old, rs_new)) =
|
||||
(,) <$> (Just <$> for (toList rs_old) (loadOld n))
|
||||
<*> for (toList rs_new) (loadNew n rs_old)
|
||||
in for (sortOn fst . uniqueBy fst $ nsUpdates <> metadataUpdates) loadEntry
|
||||
-- in for (sortOn fst . uniqueBy fst $ nsUpdates <> metadataUpdates) loadEntry
|
||||
|
||||
let propagatedUpdates :: Int =
|
||||
(Set.size . R3.d2s . BranchDiff.propagatedNamespaceUpdates) typesDiff +
|
||||
|
@ -1218,7 +1218,7 @@ showDiffNamespace _ _ _ diffOutput | OBD.isEmpty diffOutput =
|
||||
showDiffNamespace ppe oldPath newPath OBD.BranchDiffOutput{..} =
|
||||
(P.sepNonEmpty "\n\n" p, toList args)
|
||||
where
|
||||
(p, (menuSize, args)) = (`State.runState` (1::Int, Seq.empty)) $ sequence [
|
||||
(p, (menuSize, args)) = (`State.runState` (0::Int, Seq.empty)) $ sequence [
|
||||
if (not . null) updatedTypes
|
||||
|| (not . null) updatedTerms
|
||||
|| propagatedUpdates > 0
|
||||
@ -1235,7 +1235,7 @@ showDiffNamespace ppe oldPath newPath OBD.BranchDiffOutput{..} =
|
||||
$ P.wrap ("& " <> P.shown propagatedUpdates
|
||||
<> "auto-propagated updates")
|
||||
else mempty
|
||||
, P.indentN 2 . P.linesNonEmpty $ prettyUpdatedPatches
|
||||
, P.indentNonEmptyN 2 . P.linesNonEmpty $ prettyUpdatedPatches
|
||||
]
|
||||
else pure mempty
|
||||
,if (not . null) addedTypes
|
||||
@ -1312,7 +1312,7 @@ showDiffNamespace ppe oldPath newPath OBD.BranchDiffOutput{..} =
|
||||
-- [ "peach ┐"
|
||||
-- , "peach' ┘"]
|
||||
olds' :: [Numbered Pretty] =
|
||||
map (\(oldhq, oldp) -> numHQ oldPath oldhq r <&> (\n -> n <> oldp))
|
||||
map (\(oldhq, oldp) -> numHQ oldPath oldhq r <&> (\n -> n <> " " <> oldp))
|
||||
. (zip (toList olds))
|
||||
. (P.boxRight' P.rBoxStyle2)
|
||||
. map (P.rightPad leftNamePad . phq')
|
||||
@ -1322,7 +1322,7 @@ showDiffNamespace ppe oldPath newPath OBD.BranchDiffOutput{..} =
|
||||
-- , "└ 17. ooga.booga2" ]
|
||||
news' :: [Numbered Pretty] =
|
||||
P.boxLeftM' P.lBoxStyle2
|
||||
. map (\new -> numHQ newPath new r <&> (\n -> n <> phq' new))
|
||||
. map (\new -> numHQ newPath new r <&> (\n -> n <> " " <> phq' new))
|
||||
$ toList news
|
||||
buildTable lefts rights = go arrow lefts rights where
|
||||
go :: Monad m => String -> [m Pretty] -> [m Pretty] -> m [Pretty]
|
||||
@ -1406,7 +1406,7 @@ showDiffNamespace ppe oldPath newPath OBD.BranchDiffOutput{..} =
|
||||
pure $ zip3 nums (boxLeft names) decls
|
||||
prettyLine r otype (hq, mds) = do
|
||||
n <- numHQ newPath hq r
|
||||
pure . (n, phq' hq, ) $ " : " <> prettyType otype <> case length mds of
|
||||
pure . (n, phq' hq, ) $ ": " <> prettyType otype <> case length mds of
|
||||
0 -> mempty
|
||||
c -> " (+" <> P.shown c <> " metadata)"
|
||||
|
||||
@ -1455,12 +1455,16 @@ showDiffNamespace ppe oldPath newPath OBD.BranchDiffOutput{..} =
|
||||
fmap ((n,) . P.linesNonEmpty) . sequence $
|
||||
[ pure $ prettyDecl hq odecl
|
||||
, P.indentN leftNumsWidth <$> prettyMetadataDiff mddiff ]
|
||||
|
||||
-- + 2. MIT : License
|
||||
-- - 3. AllRightsReserved : License
|
||||
mdTermLine :: Path.Absolute -> Int -> OBD.TermDisplay v a -> Numbered (Pretty, Pretty)
|
||||
mdTermLine p namesWidth (hq, r, otype, mddiff) = do
|
||||
n <- numHQ p hq r
|
||||
fmap ((n,) . P.linesNonEmpty) . sequence $
|
||||
[ pure $ P.rightPad namesWidth (phq' hq) <> " : " <> prettyType otype
|
||||
, P.indentN leftNumsWidth <$> prettyMetadataDiff mddiff ]
|
||||
, prettyMetadataDiff mddiff ]
|
||||
-- , P.indentN 2 <$> prettyMetadataDiff mddiff ]
|
||||
|
||||
prettyUpdateTerm :: OBD.UpdateTermDisplay v a -> Numbered Pretty
|
||||
prettyUpdateTerm (Nothing, newTerms) =
|
||||
@ -1480,12 +1484,12 @@ showDiffNamespace ppe oldPath newPath OBD.BranchDiffOutput{..} =
|
||||
|
||||
prettyMetadataDiff :: OBD.MetadataDiff (OBD.MetadataDisplay v a) -> Numbered Pretty
|
||||
prettyMetadataDiff OBD.MetadataDiff{..} = P.column2M $
|
||||
map (elem oldPath " - ") removedMetadata <>
|
||||
map (elem newPath " + ") addedMetadata
|
||||
map (elem oldPath "- ") removedMetadata <>
|
||||
map (elem newPath "+ ") addedMetadata
|
||||
where
|
||||
elem p x (hq, r, otype) = do
|
||||
num <- numHQ p hq r
|
||||
pure (x <> num <> phq' hq, " : " <> prettyType otype)
|
||||
pure (x <> num <> phq' hq, ": " <> prettyType otype)
|
||||
|
||||
prettyType = maybe (P.red "type not found") (TypePrinter.pretty ppe)
|
||||
prettyDecl hq =
|
||||
@ -1510,9 +1514,9 @@ showDiffNamespace ppe oldPath newPath OBD.BranchDiffOutput{..} =
|
||||
pure $ padNumber (n+1)
|
||||
|
||||
padNumber :: Int -> Pretty
|
||||
padNumber n = P.hiBlack . P.rightPad leftNumsWidth $ P.shown n <> ". "
|
||||
padNumber n = P.hiBlack . P.rightPad leftNumsWidth $ P.shown n <> "."
|
||||
|
||||
leftNumsWidth = traceShowId $ length (show menuSize) + length (". " :: String)
|
||||
leftNumsWidth = traceShowId $ length (show menuSize) + length ("." :: String)
|
||||
|
||||
noResults :: Pretty
|
||||
noResults = P.callout "😶" $
|
||||
|
@ -11,14 +11,15 @@ import qualified Unison.Util.Relation as R
|
||||
import Data.Semigroup (Sum(Sum, getSum))
|
||||
import Data.Tuple.Extra (uncurry3)
|
||||
|
||||
-- Represents a set of (fact, d1, d2, d3), but indexed using a star schema so
|
||||
-- it can be efficiently quried from any of the dimensions.
|
||||
data Relation3 a b c
|
||||
= Relation3
|
||||
{ d1 :: Map a (Relation b c)
|
||||
, d2 :: Map b (Relation a c)
|
||||
, d3 :: Map c (Relation a b)
|
||||
} deriving (Eq,Ord,Show)
|
||||
} deriving (Eq,Ord)
|
||||
|
||||
instance (Show a, Show b, Show c) => Show (Relation3 a b c) where
|
||||
show = show . toList
|
||||
|
||||
d1s :: Relation3 a b c -> Set a
|
||||
d1s = Map.keysSet . d1
|
||||
|
@ -22,27 +22,58 @@ ability X a1 a2 where x : Nat
|
||||
|
||||
```ucm
|
||||
.ns1> add
|
||||
.ns1> link a b
|
||||
.ns1> fork .ns1 .ns2
|
||||
.ns1> cd .
|
||||
.> diff.namespace ns1 ns2
|
||||
```
|
||||
|
||||
```unison
|
||||
a = 99
|
||||
d = 4
|
||||
e = 5
|
||||
f = 6
|
||||
unique type Y a b = Y a b
|
||||
```
|
||||
|
||||
```ucm
|
||||
.ns2> add
|
||||
.ns2> update
|
||||
.> diff.namespace ns1 ns2
|
||||
.> alias.term ns2.d ns2.d'
|
||||
.> alias.type ns2.A ns2.A'
|
||||
.> alias.type ns2.X ns2.X'
|
||||
.> diff.namespace ns1 ns2
|
||||
.> view 2
|
||||
.> link ns2.f ns1.a
|
||||
.> diff.namespace ns1 ns2
|
||||
.> unlink ns2.a ns2.b
|
||||
.> diff.namespace ns1 ns2
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Display issues to fixup
|
||||
|
||||
- [x] An add with new metadata is getting characterized as an update
|
||||
- [ ] 12.patch patch needs a space
|
||||
- [ ] This looks like garbage
|
||||
Updates:
|
||||
|
||||
1. [f : Nat
|
||||
|
||||
⧩ replaced with
|
||||
2. [f : Nat
|
||||
+ 3.a : Nat
|
||||
|
||||
|
||||
Things busted:
|
||||
[x] Get rid of blank line before replaced with
|
||||
[x] Missing a space after the metadata 3. number
|
||||
3. Square brackets look bad, that was a bad idea and we
|
||||
should feel bad.
|
||||
[x] Metadata is indented waaay too far. Just be 1 level.
|
||||
|
||||
- [ ] Try deleting blank line in between copies / renames entries
|
||||
- [x] Extra 2 blank lines at the end of the add section
|
||||
|
Loading…
Reference in New Issue
Block a user