Skip to content

Commit 3aea4e4

Browse files
authored
Merge pull request #6151 from unisonweb/load-merge
On merge branches, classify adds/updates/deletes relative to target of merge
2 parents a0ef647 + 0a01fe8 commit 3aea4e4

File tree

6 files changed

+107
-85
lines changed

6 files changed

+107
-85
lines changed

.github/workflows/proofs/tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4dd90696a22935e9a1db32ab7f7ec9e2b5847c7af2e21dcc6b762f18f077b24e bb475eb1950a60d5a3b214802e10b997d5b6d7fa47df5a1ed69c56b37f94fd85 pass
1+
2d4c8ab2cf9b38815ad8f3192a94a814e81a79fcd17550a8f53dd79803c9405e bb475eb1950a60d5a3b214802e10b997d5b6d7fa47df5a1ed69c56b37f94fd85 pass
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1a21a3053f57a1d0dd9d2e925e4562f13745c0f558f4fcac8e5b7fc36b84d3f1 d87764682d1e2b3d3a479e600c6acddb5dbd9795c7b64747a67f6807d438dcc2 pass
1+
458f8dd38aa87af2c2fda3bf3c919139a210aa1e5f3e9bb077ef86b92f8cc47f d87764682d1e2b3d3a479e600c6acddb5dbd9795c7b64747a67f6807d438dcc2 pass

unison-cli/src/Unison/Codebase/Editor/HandleInput/Load.hs

Lines changed: 68 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -103,79 +103,85 @@ loadUnisonFile sourceName text = do
103103
let newPpe = PPED.suffixifiedPPE (PPED.makePPED (PPE.hqNamer 10 newNames) (PPE.suffixifyByHash newNames))
104104
pp <- Cli.getCurrentProjectPath
105105

106-
maybeUpdateOrUpgradeBranchParentCausalHash <-
107-
if pp.branch.isUpdate || pp.branch.isUpgrade
106+
-- If we're on an update, upgrade, or merge branch, we have special logic to render changes relative to the parent
107+
-- branch (in a merge branch, that's the branch we're merging into). This is because, on these branches, dependents
108+
-- have been pulled out of the underlying namespace and put into the scratch file (so that we can support deleting
109+
-- things). Without this special logic, all of these things would be classified as new definitions.
110+
111+
maybeSpecialBranchParentCausalHash <-
112+
if pp.branch.isUpdate || pp.branch.isUpgrade || pp.branch.isMerge
108113
then case pp.branch.parentBranchId of
109114
Nothing -> pure Nothing
110115
Just parentBranchId ->
111116
Just <$> Cli.runTransaction (Queries.expectProjectBranchHeadHash pp.project.projectId parentBranchId)
112117
else pure Nothing
113118

114-
case maybeUpdateOrUpgradeBranchParentCausalHash of
115-
Nothing -> do
116-
slurpEntries <-
117-
Cli.runTransaction do
118-
terms <-
119-
slurpTerms
120-
env.codebase
121-
unisonFile
122-
False
123-
(Relation.domain oldNames.terms)
124-
(Relation.domain unisonFileNames.terms)
125-
types <-
126-
slurpTypes
127-
env.codebase
128-
unisonFile
129-
False
130-
(Relation.domain oldNames.types)
131-
(Relation.domain unisonFileNames.types)
132-
pure Defns {terms, types}
133-
134-
let aliases :: Map Referent (NESet Name)
135-
aliases =
136-
getTermAliases oldNames.terms slurpEntries.terms
137-
138-
let oldPpe =
139-
PPED.suffixifiedPPE (PPED.makePPED (PPE.hqNamer 10 oldNames) (PPE.suffixifyByHash oldNames))
140-
141-
Cli.respond (Output.Typechecked oldPpe newPpe slurpEntries aliases)
142-
Just updateOrUpgradeBranchParentCausalHash -> do
143-
updateOrUpgradeBranchParent <- liftIO (Codebase.expectBranchForHash env.codebase updateOrUpgradeBranchParentCausalHash)
144-
let updateOrUpgradeBranchParent0 = Branch.head updateOrUpgradeBranchParent
145-
let updateOrUpgradeBranchParentNames = Branch.toNames updateOrUpgradeBranchParent0
146-
let updateOrUpgradeBranchParentLocalNames = Branch.toNames (Branch.deleteLibdeps updateOrUpgradeBranchParent0)
147-
let updateOrUpgradeBranchLocalNames =
148-
Names.shadowing unisonFileNames (Branch.toNames (Branch.deleteLibdeps oldBranch0))
119+
(oldPpe, slurpEntries, existingTerms) <-
120+
case maybeSpecialBranchParentCausalHash of
121+
Nothing -> do
122+
slurpEntries <-
123+
Cli.runTransaction do
124+
terms <-
125+
slurpTerms
126+
env.codebase
127+
unisonFile
128+
False
129+
(Relation.domain oldNames.terms)
130+
(Relation.domain unisonFileNames.terms)
131+
types <-
132+
slurpTypes
133+
env.codebase
134+
unisonFile
135+
False
136+
(Relation.domain oldNames.types)
137+
(Relation.domain unisonFileNames.types)
138+
pure Defns {terms, types}
149139

150-
slurpEntries <-
151-
Cli.runTransaction do
152-
terms <-
153-
slurpTerms
154-
env.codebase
155-
unisonFile
156-
True
157-
(Relation.domain updateOrUpgradeBranchParentLocalNames.terms)
158-
(Relation.domain updateOrUpgradeBranchLocalNames.terms)
159-
types <-
160-
slurpTypes
161-
env.codebase
162-
unisonFile
163-
False
164-
(Relation.domain updateOrUpgradeBranchParentLocalNames.types)
165-
(Relation.domain updateOrUpgradeBranchLocalNames.types)
166-
pure Defns {terms, types}
140+
pure
141+
( PPED.suffixifiedPPE (PPED.makePPED (PPE.hqNamer 10 oldNames) (PPE.suffixifyByHash oldNames)),
142+
slurpEntries,
143+
oldNames.terms
144+
)
145+
Just specialBranchParentCausalHash -> do
146+
specialBranchParent <- liftIO (Codebase.expectBranchForHash env.codebase specialBranchParentCausalHash)
147+
let specialBranchParent0 = Branch.head specialBranchParent
148+
let specialBranchParentNames = Branch.toNames specialBranchParent0
149+
let specialBranchParentLocalNames = Branch.toNames (Branch.deleteLibdeps specialBranchParent0)
150+
let specialBranchLocalNames =
151+
Names.shadowing unisonFileNames (Branch.toNames (Branch.deleteLibdeps oldBranch0))
167152

168-
let aliases :: Map Referent (NESet Name)
169-
aliases =
170-
getTermAliases updateOrUpgradeBranchParentNames.terms slurpEntries.terms
153+
slurpEntries <-
154+
Cli.runTransaction do
155+
terms <-
156+
slurpTerms
157+
env.codebase
158+
unisonFile
159+
True
160+
(Relation.domain specialBranchParentLocalNames.terms)
161+
(Relation.domain specialBranchLocalNames.terms)
162+
types <-
163+
slurpTypes
164+
env.codebase
165+
unisonFile
166+
False
167+
(Relation.domain specialBranchParentLocalNames.types)
168+
(Relation.domain specialBranchLocalNames.types)
169+
pure Defns {terms, types}
171170

172-
let oldPpe =
173-
PPED.suffixifiedPPE $
171+
pure
172+
( PPED.suffixifiedPPE $
174173
PPED.makePPED
175-
(PPE.hqNamer 10 updateOrUpgradeBranchParentNames)
176-
(PPE.suffixifyByHash updateOrUpgradeBranchParentNames)
174+
(PPE.hqNamer 10 specialBranchParentNames)
175+
(PPE.suffixifyByHash specialBranchParentNames),
176+
slurpEntries,
177+
specialBranchParentNames.terms
178+
)
179+
180+
let aliases :: Map Referent (NESet Name)
181+
aliases =
182+
getTermAliases existingTerms slurpEntries.terms
177183

178-
Cli.respond (Output.Typechecked oldPpe newPpe slurpEntries aliases)
184+
Cli.respond (Output.Typechecked oldPpe newPpe slurpEntries aliases pp.branch.isMerge)
179185

180186
when (not . null $ UF.watchComponents unisonFile) do
181187
Timing.time "evaluating watches" do

unison-cli/src/Unison/Codebase/Editor/Output.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ data Output
304304
!PPE.PrettyPrintEnv
305305
!(DefnsF (Map Name) SR.TermSlurp SR.TypeSlurp)
306306
!(Map Referent (NESet Name))
307+
!Bool -- merging? (can expand later to include: upgrading?)
307308
| DisplayRendered (Maybe FilePath) (P.Pretty P.ColorText)
308309
| -- "display" the provided code to the console.
309310
DisplayDefinitions (P.Pretty P.ColorText)

unison-cli/src/Unison/CommandLine/OutputMessages.hs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ notifyUser dir issueFn = \case
10831083
LoadingFile sourceName -> do
10841084
fileName <- renderFileName $ Text.unpack sourceName
10851085
pure $ P.wrap $ "Loading changes detected in " <> P.group (fileName <> ".")
1086-
Typechecked oldPpe newPpe slurpEntries aliases -> do
1086+
Typechecked oldPpe newPpe slurpEntries aliases isMergeBranch -> do
10871087
let newTypes0 :: [(Name, DeclOrBuiltin Symbol Ann)]
10881088
updatedTypes0 :: [(Name, DeclOrBuiltin Symbol Ann, DeclOrBuiltin Symbol Ann)]
10891089
deletedTypes0 :: [(Name, DeclOrBuiltin Symbol Ann)]
@@ -1265,16 +1265,25 @@ notifyUser dir issueFn = \case
12651265
& (\acc -> foldr (\(name, _, _) -> f name) acc newTerms)
12661266
& (\acc -> foldr (\(name, _, _, _, _) -> f name) acc updatedTerms)
12671267
in if Set.null addsAndUpdatesInLib
1268-
then
1269-
P.wrap
1270-
( "Run"
1271-
<> makeExample' IP.update
1272-
<> "to apply these changes to your codebase."
1273-
)
1268+
then runUpdateMessage
12741269
else P.warnCallout (modifyingLibNotAllowed addsAndUpdatesInLib)
12751270
)
12761271
]
1277-
else "No changes found."
1272+
else
1273+
if isMergeBranch
1274+
then runUpdateMessage
1275+
else "No changes found."
1276+
where
1277+
runUpdateMessage =
1278+
P.wrap $
1279+
"Run"
1280+
<> makeExample' IP.update
1281+
<> if isMergeBranch
1282+
then
1283+
"to apply these changes to your codebase and complete the merge, or"
1284+
<> makeExample' IP.cancelInputPattern
1285+
<> "to cancel the merge."
1286+
else "to apply these changes to your codebase."
12781287
BustedBuiltins (Set.toList -> new) (Set.toList -> old) ->
12791288
-- todo: this could be prettier! Have a nice list like `find` gives, but
12801289
-- that requires querying the codebase to determine term types. Probably

unison-src/transcripts/idempotent/merge.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,9 +1807,12 @@ foo = "alice and bobs foo"
18071807
``` ucm :added-by-ucm
18081808
Loading changes detected in scratch.u.
18091809
1810-
+ foo : Text
1810+
~ foo : Text
18111811
1812-
Run `update` to apply these changes to your codebase.
1812+
~ (modified)
1813+
1814+
Run `update` to apply these changes to your codebase and
1815+
complete the merge, or `cancel` to cancel the merge.
18131816
```
18141817

18151818
``` ucm
@@ -3241,10 +3244,8 @@ type Bar = MkBar Foo
32413244
``` ucm :added-by-ucm
32423245
Loading changes detected in scratch.u.
32433246
3244-
+ type Bar
3245-
+ type Foo
3246-
3247-
Run `update` to apply these changes to your codebase.
3247+
Run `update` to apply these changes to your codebase and
3248+
complete the merge, or `cancel` to cancel the merge.
32483249
```
32493250

32503251
``` ucm
@@ -3381,9 +3382,8 @@ type Foo = Bar
33813382
``` ucm :added-by-ucm
33823383
Loading changes detected in scratch.u.
33833384
3384-
+ type Foo
3385-
3386-
Run `update` to apply these changes to your codebase.
3385+
Run `update` to apply these changes to your codebase and
3386+
complete the merge, or `cancel` to cancel the merge.
33873387
```
33883388

33893389
``` ucm
@@ -3515,9 +3515,12 @@ type Foo = Bar
35153515
``` ucm :added-by-ucm
35163516
Loading changes detected in scratch.u.
35173517
3518-
+ type Foo
3518+
~ type Foo
35193519
3520-
Run `update` to apply these changes to your codebase.
3520+
~ (modified)
3521+
3522+
Run `update` to apply these changes to your codebase and
3523+
complete the merge, or `cancel` to cancel the merge.
35213524
```
35223525

35233526
``` ucm
@@ -3662,9 +3665,12 @@ type Foo = Bar
36623665
``` ucm :added-by-ucm
36633666
Loading changes detected in scratch.u.
36643667
3665-
+ type Foo
3668+
~ type Foo
36663669
3667-
Run `update` to apply these changes to your codebase.
3670+
~ (modified)
3671+
3672+
Run `update` to apply these changes to your codebase and
3673+
complete the merge, or `cancel` to cancel the merge.
36683674
```
36693675

36703676
``` ucm

0 commit comments

Comments
 (0)