Skip to content

Commit dbd7a1f

Browse files
authored
Merge pull request #5816 from unisonweb/25-07-14-update
Unify normal slurp output with update-branch slurp output
2 parents 3379c03 + 4fdbb76 commit dbd7a1f

File tree

259 files changed

+2801
-4552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+2801
-4552
lines changed

lib/unison-prelude/src/Unison/Util/Map.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Unison.Util.Map
1212
for_,
1313
insertLookup,
1414
invert,
15+
lookupJust,
1516
mergeMap,
1617
unionWithM,
1718
remap,
@@ -83,6 +84,11 @@ invert :: (Ord v) => Map k v -> Map v k
8384
invert =
8485
Map.foldlWithKey' (\m k v -> Map.insert v k m) Map.empty
8586

87+
-- | Like 'Map.lookup', but asserts the key is in the map.
88+
lookupJust :: (Ord k, Show k) => k -> Map k v -> v
89+
lookupJust k =
90+
Map.findWithDefault (error (reportBug "E147567" ("Missing key: " ++ show k))) k
91+
8692
-- | Upsert an element into a map.
8793
upsert :: (Ord k) => (Maybe v -> v) -> k -> Map k v -> Map k v
8894
upsert f =

parser-typechecker/src/Unison/Codebase.hs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Unison.Codebase
1414
unsafeGetTermComponent,
1515
getTypeOfTerm,
1616
expectTypeOfTerm,
17+
expectTypeOfConstructor,
1718
getDeclType,
1819
unsafeGetTypeOfTermById,
1920
isTerm,
@@ -145,6 +146,7 @@ import Unison.Codebase.SqliteCodebase.Operations qualified as SqliteCodebase.Ope
145146
import Unison.Codebase.Type (Codebase (..))
146147
import Unison.CodebasePath (CodebasePath, getCodebaseDir)
147148
import Unison.ConstructorReference (ConstructorReference, GConstructorReference (..))
149+
import Unison.ConstructorReference qualified as ConstructorReference
148150
import Unison.Core.Project (ProjectAndBranch)
149151
import Unison.DataDeclaration (Decl)
150152
import Unison.DataDeclaration qualified as DD
@@ -359,6 +361,17 @@ getTypeOfConstructor codebase (ConstructorReference r0 cid) =
359361
Just decl -> DD.typeOfConstructor (either DD.toDataDecl id decl) cid
360362
Reference.Builtin _ -> error (reportBug "924628772" "Attempt to load a type declaration which is a builtin!")
361363

364+
expectTypeOfConstructor ::
365+
(Ord v) =>
366+
Codebase m v a ->
367+
ConstructorReference ->
368+
Sqlite.Transaction (Type v a)
369+
expectTypeOfConstructor codebase ref =
370+
getTypeOfConstructor codebase ref <&> fromMaybe err
371+
where
372+
err =
373+
error (reportBug "E775974" ("constructor reference " ++ Text.unpack (ConstructorReference.toText ref) ++ " not found"))
374+
362375
-- | Like 'getWatch', but first looks up the given reference as a regular watch, then as a test watch.
363376
--
364377
-- @
@@ -435,7 +448,7 @@ typeLookupForDependencies codebase s = do
435448
getTypeOfTerm ::
436449
(BuiltinAnnotation a) =>
437450
Codebase m Symbol a ->
438-
Reference ->
451+
TermReference ->
439452
Sqlite.Transaction (Maybe (Type Symbol a))
440453
getTypeOfTerm _c r | debug && trace ("Codebase.getTypeOfTerm " ++ show r) False = undefined
441454
getTypeOfTerm c r = case r of
@@ -448,7 +461,7 @@ getTypeOfTerm c r = case r of
448461
expectTypeOfTerm ::
449462
(BuiltinAnnotation a) =>
450463
Codebase m Symbol a ->
451-
Reference ->
464+
TermReference ->
452465
Sqlite.Transaction (Type Symbol a)
453466
expectTypeOfTerm codebase ref =
454467
getTypeOfTerm codebase ref <&> fromMaybe err

parser-typechecker/src/Unison/Syntax/NamePrinter.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Unison.Referent (Referent)
1616
import Unison.ShortHash (ShortHash)
1717
import Unison.ShortHash qualified as SH
1818
import Unison.Syntax.HashQualified qualified as HQ (toText)
19-
import Unison.Syntax.Name qualified as Name (toText)
19+
import Unison.Syntax.Name qualified as Name (toText, toTextParens)
2020
import Unison.Util.Pretty (Pretty)
2121
import Unison.Util.Pretty qualified as PP
2222
import Unison.Util.SyntaxText qualified as S
@@ -26,6 +26,9 @@ type SyntaxText = S.SyntaxText' Reference
2626
prettyName :: (IsString s) => Name -> Pretty s
2727
prettyName = PP.text . Name.toText
2828

29+
prettyNameParens :: (IsString s) => Name -> Pretty s
30+
prettyNameParens = PP.text . Name.toTextParens
31+
2932
prettyHashQualified :: HQ.HashQualified Name -> Pretty SyntaxText
3033
prettyHashQualified hq = styleHashQualified' id (fmt $ S.HashQualifier hq) hq
3134

unison-cli-integration/integration-tests/IntegrationTests/transcript.output.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ main = do
3838
``` ucm :added-by-ucm
3939
Loading changes detected in scratch.u.
4040
41-
I found and typechecked these definitions in scratch.u. If you
42-
do an `update`, here's how your codebase would change:
43-
44-
⍟ New definitions:
45-
46-
structural ability Break
47-
type MyBool
48-
main : '{IO, Exception} ()
49-
resume : Request {g, Break} x -> x
41+
+ structural ability Break
42+
+ type MyBool
43+
44+
+ main : '{IO, Exception} ()
45+
+ resume : Request {g, Break} x -> x
46+
47+
Run `update` to apply these changes to your codebase.
5048
```
5149

5250
``` ucm

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ where
66
import Control.Lens (use)
77
import Control.Monad.Reader (ask)
88
import Data.Map.Strict qualified as Map
9-
import Data.Set qualified as Set
109
import Data.Text qualified as Text
1110
import Unison.Cli.Monad (Cli)
1211
import Unison.Cli.Monad qualified as Cli
@@ -47,7 +46,7 @@ handleAddRun input resultName = do
4746
(UF.watchComponents uf0)
4847
Cli.Env {codebase} <- ask
4948
currentNames <- Cli.currentNames
50-
let sr = Slurp.slurpFile uf (Set.singleton resultVar) Slurp.AddOp currentNames
49+
let sr = Slurp.slurpFile uf resultVar currentNames
5150
let adds = SlurpResult.adds sr
5251
Cli.runTransaction . Codebase.addDefsToCodebase codebase . SlurpResult.filterUnisonFile sr $ uf
5352
let description = (Text.pack (InputPattern.patternName InputPatterns.saveExecuteResult) <> " " <> Name.toText resultName)

0 commit comments

Comments
 (0)