Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ dist-newstyle

# Nix
result
result-transcripts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ handleDiffUpdate = do
| (var, (refId, decl)) <- Map.toList (UF.effectDeclarationsId' tuf)
]

let newTypes :: Map Name (DeclOrBuiltin Symbol Ann)
newTypes = Map.restrictKeys fileTypeDecls newTypeNames
let newTypes :: Map Name (TypeReferenceId, Decl Symbol Ann)
newTypes = Map.restrictKeys fileTypeDeclsWithRefIds newTypeNames

-- Types from the file that are updates to existing codebase definitions
let updatedFileTypes :: Map Name (TypeReferenceId, Decl Symbol Ann)
Expand Down
4 changes: 2 additions & 2 deletions unison-cli/src/Unison/Codebase/Editor/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ data Output
!PPE.PrettyPrintEnvDecl
-- PPE for old definitions (namespace names without file shadowing)
!PPE.PrettyPrintEnvDecl
-- New definitions (terms with body and type, types with decl)
!(Defns (Map Name (Term Symbol Ann, Type Symbol Ann)) (Map Name (DeclOrBuiltin Symbol Ann)))
-- New definitions (terms with body and type, types with refId and decl)
!(Defns (Map Name (Term Symbol Ann, Type Symbol Ann)) (Map Name (TypeReferenceId, DD.Decl Symbol Ann)))
-- Updated definitions: ((old term, old type), (new term, new type)) for terms,
-- ((old refId, old decl), (new refId, new decl)) for types
!(Defns (Map Name ((Term Symbol Ann, Type Symbol Ann), (Term Symbol Ann, Type Symbol Ann))) (Map Name ((TypeReferenceId, DD.Decl Symbol Ann), (TypeReferenceId, DD.Decl Symbol Ann))))
Expand Down
25 changes: 14 additions & 11 deletions unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2654,21 +2654,24 @@ notifyUser dir issueFn = \case
let ppe = PPED.suffixifiedPPE ppedNew
let colorAdd = P.green . ("+ " <>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this definition is no longer used, was that intentional? Or maybe it got copied somewhere else?

It's hitting "warnings as errors" in CI.


let renderTypes :: (Pretty -> Pretty) -> Map Name (DeclOrBuiltin Symbol Ann) -> Pretty
renderTypes colored types =
-- Render new types with "+ " prefix on each line
-- Similar to renderTerms, we render multiline text for full type definitions
let renderNewTypes :: Map Name (TypeReferenceId, DD.Decl Symbol Ann) -> Pretty
renderNewTypes types =
types
& Map.toList
& sortAlphabeticallyOn (view _1)
& map
( \(name, decl) ->
colored $
P.syntaxToColor $
DeclPrinter.prettyDeclOrBuiltinHeader
DeclPrinter.RenderUniqueTypeGuids'No
(HQ.fromName name)
decl
( \(name, (refId, decl)) ->
let ref = Reference.fromId refId
typeText =
P.toPlain 80 $
P.syntaxToColor $
DeclPrinter.prettyDecl ppedNew DeclPrinter.RenderUniqueTypeGuids'No ref (HQ.fromName name) decl
typeLines = Text.lines typeText
in P.lines $ map (\line -> P.green $ P.text $ "+ " <> line) typeLines
)
& P.lines
& P.sepNonEmpty "\n"

-- Render new terms with "+ " prefix on each line
-- Note: We use prettyBindingForDiff which renders multiline text with actual newlines
Expand Down Expand Up @@ -2769,7 +2772,7 @@ notifyUser dir issueFn = \case
then
P.linesNonEmpty
[ P.wrap "New definitions:",
if Map.null newDefns.types then mempty else P.indentN 2 $ renderTypes colorAdd newDefns.types,
if Map.null newDefns.types then mempty else P.indentN 2 $ renderNewTypes newDefns.types,
if Map.null newDefns.terms then mempty else P.indentN 2 $ renderTerms newDefns.terms
]
else mempty,
Expand Down
68 changes: 68 additions & 0 deletions unison-src/transcripts/idempotent/diff-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,74 @@ scratch/main> update
Done.
```

## Test diff.update with a new type

Let's test adding a brand new type (not modifying an existing one) to see if diff.update
shows the full type structure or just the type name:

``` unison
structural type Person = { name : Text, age : Nat }

unique ability Counter where
increment : Nat
getCount : Nat
```

``` ucm :added-by-ucm
Loading changes detected in scratch.u.

+ ability Counter
+ structural type Person

+ Person.age : Person -> Nat
+ Person.age.modify : (Nat ->{g} Nat) -> Person ->{g} Person
+ Person.age.set : Nat -> Person -> Person
+ Person.name : Person -> Text
+ Person.name.modify : (Text ->{g} Text)
-> Person
->{g} Person
+ Person.name.set : Text -> Person -> Person

Run `update` to apply these changes to your codebase.
```

Running `diff.update` should show the new type with its full structure:

``` ucm
scratch/main> diff.update

Preview of changes that would be made by `update`:

New definitions:
+ ability Counter where
+ increment : {Counter} Nat
+ getCount : {Counter} Nat
+ structural type Person = { name : Text, age : Nat }
+ Person.age : Person -> Nat
+ Person.age = cases Person _ age -> age
+ Person.age.modify : (Nat ->{g} Nat) -> Person ->{g} Person
+ Person.age.modify f = cases Person name age -> Person name (f age)
+ Person.age.set : Nat -> Person -> Person
+ Person.age.set age1 = cases Person name _ -> Person name age1
+ Person.name : Person -> Text
+ Person.name = cases Person name _ -> name
+ Person.name.modify : (Text ->{g} Text) -> Person ->{g} Person
+ Person.name.modify f = cases Person name age -> Person (f name) age
+ Person.name.set : Text -> Person -> Person
+ Person.name.set name1 = cases Person _ age -> Person name1 age

Run `update` to apply these changes.
```

``` ucm
scratch/main> update

Okay, I'm searching the branch for code that needs to be
updated...

Done.
```

## Test diff.update with a modified type

Let's add a type to the codebase:
Expand Down
Loading