Skip to content

Commit b08cbb0

Browse files
authored
Merge pull request #5324 from unisonweb/fix-5323
bugfix: fix suffixification logic in upgrade
2 parents e812c30 + e6b8ccd commit b08cbb0

File tree

6 files changed

+104
-35
lines changed

6 files changed

+104
-35
lines changed
Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
module Unison.PrettyPrintEnvDecl.Names
22
( makePPED,
3-
makeFilePPED,
4-
makeCodebasePPED,
53
)
64
where
75

8-
import Unison.Names (Names)
96
import Unison.PrettyPrintEnv.Names qualified as PPE
107
import Unison.PrettyPrintEnvDecl (PrettyPrintEnvDecl (PrettyPrintEnvDecl))
118

@@ -14,23 +11,3 @@ makePPED namer suffixifier =
1411
PrettyPrintEnvDecl
1512
(PPE.makePPE namer PPE.dontSuffixify)
1613
(PPE.makePPE namer suffixifier)
17-
18-
-- | Make a PPED suitable for names in a Unison file.
19-
--
20-
-- Such names have special suffixification rules: aliases may *not* be referred to by a common suffix. For example, if
21-
-- a file contains
22-
--
23-
-- one.foo = 6
24-
-- two.foo = 6
25-
--
26-
-- then the suffix `foo` will *not* be accepted (currently). So, this PPE uses the "suffixify by name" strategy.
27-
makeFilePPED :: Names -> PrettyPrintEnvDecl
28-
makeFilePPED names =
29-
makePPED (PPE.namer names) (PPE.suffixifyByName names)
30-
31-
-- | Make a PPED suitable for names in the codebase. These names are hash qualified and suffixified by hash.
32-
makeCodebasePPED :: Names -> PrettyPrintEnvDecl
33-
makeCodebasePPED names =
34-
makePPED
35-
(PPE.hqNamer 10 names)
36-
(PPE.suffixifyByHash names)

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import Unison.PrettyPrintEnv qualified as PPE
5959
import Unison.PrettyPrintEnv.Names qualified as PPE
6060
import Unison.PrettyPrintEnvDecl (PrettyPrintEnvDecl (..))
6161
import Unison.PrettyPrintEnvDecl qualified as PPED (addFallback)
62-
import Unison.PrettyPrintEnvDecl.Names qualified as PPED (makeCodebasePPED, makeFilePPED)
62+
import Unison.PrettyPrintEnvDecl.Names qualified as PPED (makePPED)
6363
import Unison.Project (ProjectBranchName)
6464
import Unison.Reference (TermReference, TermReferenceId, TypeReference, TypeReferenceId)
6565
import Unison.Reference qualified as Reference
@@ -162,15 +162,23 @@ handleUpgrade oldName newName = do
162162
UnisonFile.emptyUnisonFile
163163
pure
164164
( unisonFile,
165-
makeOldDepPPE
166-
oldName
167-
newName
168-
currentDeepNamesSansOld
169-
(Branch.toNames oldNamespace)
170-
(Branch.toNames oldLocalNamespace)
171-
(Branch.toNames newLocalNamespace)
172-
`PPED.addFallback` PPED.makeFilePPED (Names.fromReferenceIds dependents)
173-
`PPED.addFallback` PPED.makeCodebasePPED currentDeepNamesSansOld
165+
let ppe1 =
166+
makeOldDepPPE
167+
oldName
168+
newName
169+
currentDeepNamesSansOld
170+
(Branch.toNames oldNamespace)
171+
(Branch.toNames oldLocalNamespace)
172+
(Branch.toNames newLocalNamespace)
173+
ppe2 =
174+
PPED.makePPED
175+
(PPE.namer (Names.fromReferenceIds dependents))
176+
(PPE.suffixifyByName currentDeepNamesSansOld)
177+
ppe3 =
178+
PPED.makePPED
179+
(PPE.hqNamer 10 currentDeepNamesSansOld)
180+
(PPE.suffixifyByHash currentDeepNamesSansOld)
181+
in ppe1 `PPED.addFallback` ppe2 `PPED.addFallback` ppe3
174182
)
175183

176184
pp@(PP.ProjectPath project projectBranch _path) <- Cli.getCurrentProjectPath
@@ -300,12 +308,12 @@ makeUnisonFile abort codebase doFindCtorNames defns = do
300308
overwriteConstructorNames name ed.toDataDecl <&> \ed' ->
301309
uf
302310
& #effectDeclarationsId
303-
%~ Map.insertWith (\_new old -> old) (Name.toVar name) (Reference.Id h i, Decl.EffectDeclaration ed')
311+
%~ Map.insertWith (\_new old -> old) (Name.toVar name) (Reference.Id h i, Decl.EffectDeclaration ed')
304312
Right dd ->
305313
overwriteConstructorNames name dd <&> \dd' ->
306314
uf
307315
& #dataDeclarationsId
308-
%~ Map.insertWith (\_new old -> old) (Name.toVar name) (Reference.Id h i, dd')
316+
%~ Map.insertWith (\_new old -> old) (Name.toVar name) (Reference.Id h i, dd')
309317

310318
-- Constructor names are bogus when pulled from the database, so we set them to what they should be here
311319
overwriteConstructorNames :: Name -> DataDeclaration Symbol Ann -> Transaction (DataDeclaration Symbol Ann)

unison-src/transcripts/fix-5276.md renamed to unison-src/transcripts/fix-5312.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
This transcript demonstrates that dependents of an update are suffixified properly. Previously, `c = b.y + 1` would
2+
render as `c = y + 1` (ambiguous).
3+
14
```ucm
25
scratch/main> builtins.merge lib.builtin
36
```

unison-src/transcripts/fix-5276.output.md renamed to unison-src/transcripts/fix-5312.output.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
This transcript demonstrates that dependents of an update are suffixified properly. Previously, `c = b.y + 1` would
2+
render as `c = y + 1` (ambiguous).
3+
14
``` ucm
25
scratch/main> builtins.merge lib.builtin
36

unison-src/transcripts/fix-5323.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This transcript demonstrates that dependents of an upgrade are suffixified properly. Previously, `c = b.y + 1` would
2+
render as `c = y + 1` (ambiguous).
3+
4+
```ucm
5+
scratch/main> builtins.merge lib.builtin
6+
```
7+
8+
```unison
9+
lib.old.x = 17
10+
lib.new.x = 100
11+
12+
a.y = 18
13+
b.y = lib.old.x + 1
14+
15+
c = b.y + 1
16+
```
17+
18+
```ucm
19+
scratch/main> add
20+
```
21+
22+
```ucm
23+
scratch/main> upgrade old new
24+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
This transcript demonstrates that dependents of an upgrade are suffixified properly. Previously, `c = b.y + 1` would
2+
render as `c = y + 1` (ambiguous).
3+
4+
``` ucm
5+
scratch/main> builtins.merge lib.builtin
6+
7+
Done.
8+
9+
```
10+
``` unison
11+
lib.old.x = 17
12+
lib.new.x = 100
13+
14+
a.y = 18
15+
b.y = lib.old.x + 1
16+
17+
c = b.y + 1
18+
```
19+
20+
``` ucm
21+
22+
Loading changes detected in scratch.u.
23+
24+
I found and typechecked these definitions in scratch.u. If you
25+
do an `add` or `update`, here's how your codebase would
26+
change:
27+
28+
⍟ These new definitions are ok to `add`:
29+
30+
a.y : Nat
31+
b.y : Nat
32+
c : Nat
33+
lib.new.x : Nat
34+
lib.old.x : Nat
35+
36+
```
37+
``` ucm
38+
scratch/main> add
39+
40+
⍟ I've added these definitions:
41+
42+
a.y : Nat
43+
b.y : Nat
44+
c : Nat
45+
lib.new.x : Nat
46+
lib.old.x : Nat
47+
48+
```
49+
``` ucm
50+
scratch/main> upgrade old new
51+
52+
I upgraded old to new, and removed old.
53+
54+
```

0 commit comments

Comments
 (0)