Skip to content

Commit 3e229d5

Browse files
⅄ trunk → 24-06-24-todo-dependents
2 parents d8240cd + 7172bb8 commit 3e229d5

File tree

47 files changed

+835
-435
lines changed

Some content is hidden

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

47 files changed

+835
-435
lines changed

.github/workflows/ci.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ defaults:
55
shell: bash
66

77
on:
8-
# Build on every pull request (and new PR commit)
8+
# Run on the post-merge result of every PR commit
99
pull_request:
10-
# Build on new pushes to trunk (E.g. Merge commits)
11-
# Without the branch filter, each commit on a branch with a PR is triggered twice.
12-
# See: https://github.community/t/how-to-trigger-an-action-on-push-or-pull-request-but-not-both/16662
10+
# Build on the pre-merge result of every branch commit
1311
push:
14-
branches:
15-
- trunk
16-
tags:
17-
- release/*
1812
workflow_dispatch:
1913

2014
env:
@@ -270,6 +264,14 @@ jobs:
270264
${{env.transcripts}}
271265
# Fail if any transcripts cause git diffs.
272266
git diff --ignore-cr-at-eol --exit-code unison-src/transcripts
267+
- name: docs.to-html
268+
if: steps.cache-transcript-test-results.outputs.cache-hit != 'true'
269+
run: |
270+
${{env.ucm}} transcript unison-src/transcripts-manual/docs.to-html.md
271+
# Fail if the output or generated docs differ.
272+
git diff --ignore-cr-at-eol --exit-code \
273+
unison-src/transcripts-manual/docs.to-html.output.md \
274+
unison-src/transcripts-manual/docs.to-html
273275
- name: mark transcripts as passing
274276
if: steps.cache-transcript-test-results.outputs.cache-hit != 'true'
275277
run: |
@@ -417,7 +419,7 @@ jobs:
417419
build-jit-binary:
418420
name: build jit binary
419421
needs: generate-jit-source
420-
uses: ./.github/workflows/ci-build-jit-binary.yaml
422+
uses: ./.github/workflows/ci-build-jit-binary.yaml
421423

422424
test-jit:
423425
name: test jit

.github/workflows/update-transcripts.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
stack exec unison transcript unison-src/transcripts-manual/rewrites.md
3737
- name: transcripts
3838
run: stack exec transcripts
39+
- name: docs.to-html
40+
run: |
41+
stack exec unison transcript unison-src/transcripts-manual/docs.to-html.md
3942
- name: save transcript changes
4043
uses: stefanzweifel/git-auto-commit-action@v5
4144
with:

parser-typechecker/src/Unison/Codebase/Path.hs

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module Unison.Codebase.Path
4343
isRoot,
4444
isRoot',
4545

46-
-- * things that could be replaced with `Convert` instances
46+
-- * conversions
4747
absoluteToPath',
4848
fromList,
4949
fromName,
@@ -76,8 +76,6 @@ module Unison.Codebase.Path
7676
-- * things that could be replaced with `Snoc` instances
7777
snoc,
7878
unsnoc,
79-
-- This should be moved to a common util module, or we could use the 'witch' package.
80-
Convert (..),
8179
)
8280
where
8381

@@ -93,14 +91,19 @@ import Data.Sequence qualified as Seq
9391
import Data.Text qualified as Text
9492
import GHC.Exts qualified as GHC
9593
import Unison.HashQualified' qualified as HQ'
96-
import Unison.Name (Convert (..), Name)
94+
import Unison.Name (Name)
9795
import Unison.Name qualified as Name
9896
import Unison.NameSegment (NameSegment)
9997
import Unison.Prelude hiding (empty, toList)
10098
import Unison.Syntax.Name qualified as Name (toText, unsafeParseText)
10199
import Unison.Util.List qualified as List
102100

103-
-- `Foo.Bar.baz` becomes ["Foo", "Bar", "baz"]
101+
-- | A `Path` is an internal structure representing some namespace in the codebase.
102+
--
103+
-- @Foo.Bar.baz@ becomes @["Foo", "Bar", "baz"]@.
104+
--
105+
-- __NB__: This shouldn’t be exposed outside of this module (prefer`Path'`, `Absolute`, or `Relative`), but it’s
106+
-- currently used pretty widely. Such usage should be replaced when encountered.
104107
newtype Path = Path {toSeq :: Seq NameSegment}
105108
deriving stock (Eq, Ord)
106109
deriving newtype (Semigroup, Monoid)
@@ -112,10 +115,13 @@ instance GHC.IsList Path where
112115
toList (Path segs) = Foldable.toList segs
113116
fromList = Path . Seq.fromList
114117

118+
-- | A namespace path that starts from the root.
115119
newtype Absolute = Absolute {unabsolute :: Path} deriving (Eq, Ord)
116120

121+
-- | A namespace path that doesn’t necessarily start from the root.
117122
newtype Relative = Relative {unrelative :: Path} deriving (Eq, Ord)
118123

124+
-- | A namespace that may be either absolute or relative, This is the most general type that should be used.
119125
newtype Path' = Path' {unPath' :: Either Absolute Relative}
120126
deriving (Eq, Ord)
121127

@@ -534,34 +540,3 @@ instance Resolve Absolute HQSplit HQSplitAbsolute where
534540
instance Resolve Absolute Path' Absolute where
535541
resolve _ (AbsolutePath' a) = a
536542
resolve a (RelativePath' r) = resolve a r
537-
538-
instance Convert Absolute Path where convert = unabsolute
539-
540-
instance Convert Absolute Path' where convert = absoluteToPath'
541-
542-
instance Convert Absolute Text where convert = toText' . absoluteToPath'
543-
544-
instance Convert Relative Text where convert = toText . unrelative
545-
546-
instance Convert Absolute String where convert = Text.unpack . convert
547-
548-
instance Convert Relative String where convert = Text.unpack . convert
549-
550-
instance Convert [NameSegment] Path where convert = fromList
551-
552-
instance Convert Path [NameSegment] where convert = toList
553-
554-
instance Convert HQSplit (HQ'.HashQualified Path) where convert = unsplitHQ
555-
556-
instance Convert HQSplit' (HQ'.HashQualified Path') where convert = unsplitHQ'
557-
558-
instance Convert Name Split where
559-
convert = splitFromName
560-
561-
instance Convert (path, NameSegment) (path, HQ'.HQSegment) where
562-
convert (path, name) =
563-
(path, HQ'.fromName name)
564-
565-
instance (Convert path0 path1) => Convert (path0, name) (path1, name) where
566-
convert =
567-
over _1 convert

parser-typechecker/src/Unison/PrintError.hs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ styleAnnotated sty a = (,sty) <$> rangeForAnnotated a
126126
style :: s -> String -> Pretty (AnnotatedText s)
127127
style sty str = Pr.lit . AT.annotate sty $ fromString str
128128

129+
-- | Applies the color highlighting for `Code`, but also quotes the code, to separate it from the containing context.
130+
quoteCode :: String -> Pretty ColorText
131+
quoteCode = Pr.backticked . style Code
132+
129133
stylePretty :: Color -> Pretty ColorText -> Pretty ColorText
130134
stylePretty = Pr.map . AT.annotate
131135

@@ -1366,31 +1370,31 @@ renderParseErrors s = \case
13661370
<> style ErrorSite (fromString open)
13671371
<> ".\n\n"
13681372
<> excerpt
1369-
L.InvalidWordyId _id ->
1373+
L.ReservedWordyId id ->
13701374
Pr.lines
1371-
[ "This identifier isn't valid syntax: ",
1375+
[ "The identifier " <> quoteCode id <> " used here is a reserved keyword: ",
13721376
"",
13731377
excerpt,
1374-
"Here's a few examples of valid syntax: "
1375-
<> style Code "abba1', snake_case, Foo.zoink!, 🌻"
1376-
]
1377-
L.ReservedWordyId _id ->
1378-
Pr.lines
1379-
[ "The identifier used here isn't allowed to be a reserved keyword: ",
1380-
"",
1381-
excerpt
1378+
Pr.wrap $
1379+
"You can avoid this problem either by renaming the identifier or wrapping it in backticks (like "
1380+
<> style Code ("`" <> id <> "`")
1381+
<> ")."
13821382
]
1383-
L.InvalidSymbolyId _id ->
1383+
L.InvalidSymbolyId id ->
13841384
Pr.lines
1385-
[ "This infix identifier isn't valid syntax: ",
1385+
[ "The infix identifier " <> quoteCode id <> " isnt valid syntax: ",
13861386
"",
13871387
excerpt,
1388-
"Here's a few valid examples: "
1389-
<> style Code "++, Float./, `List.map`"
1388+
"Here are a few valid examples: "
1389+
<> quoteCode "++"
1390+
<> ", "
1391+
<> quoteCode "Float./"
1392+
<> ", and "
1393+
<> quoteCode "List.map"
13901394
]
1391-
L.ReservedSymbolyId _id ->
1395+
L.ReservedSymbolyId id ->
13921396
Pr.lines
1393-
[ "This identifier is reserved by Unison and can't be used as an operator: ",
1397+
[ "The identifier " <> quoteCode id <> " is reserved by Unison and can't be used as an operator: ",
13941398
"",
13951399
excerpt
13961400
]
@@ -1444,11 +1448,12 @@ renderParseErrors s = \case
14441448
"",
14451449
excerpt,
14461450
Pr.wrap $
1447-
"I was expecting some digits after the '.',"
1448-
<> "for example: "
1449-
<> style Code (n <> "0")
1451+
"I was expecting some digits after the "
1452+
<> quoteCode "."
1453+
<> ", for example: "
1454+
<> quoteCode (n <> "0")
14501455
<> "or"
1451-
<> Pr.group (style Code (n <> "1e37") <> ".")
1456+
<> Pr.group (quoteCode (n <> "1e37") <> ".")
14521457
]
14531458
L.MissingExponent n ->
14541459
Pr.lines
@@ -1458,7 +1463,7 @@ renderParseErrors s = \case
14581463
Pr.wrap $
14591464
"I was expecting some digits for the exponent,"
14601465
<> "for example: "
1461-
<> Pr.group (style Code (n <> "37") <> ".")
1466+
<> Pr.group (quoteCode (n <> "37") <> ".")
14621467
]
14631468
L.TextLiteralMissingClosingQuote _txt ->
14641469
Pr.lines
@@ -1474,7 +1479,7 @@ renderParseErrors s = \case
14741479
"",
14751480
"I only know about the following escape characters:",
14761481
"",
1477-
let s ch = style Code (fromString $ "\\" <> [ch])
1482+
let s ch = quoteCode (fromString $ "\\" <> [ch])
14781483
in Pr.indentN 2 $ intercalateMap "," s (fst <$> L.escapeChars)
14791484
]
14801485
L.LayoutError ->
@@ -1705,7 +1710,7 @@ renderParseErrors s = \case
17051710
let msg =
17061711
mconcat
17071712
[ "This looks like the start of an expression here but I was expecting a binding.",
1708-
"\nDid you mean to use a single " <> style Code ":",
1713+
"\nDid you mean to use a single " <> quoteCode ":",
17091714
" here for a type signature?",
17101715
"\n\n",
17111716
tokenAsErrorSite s t

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ pretty0
459459
go tm = goNormal 10 tm
460460
PP.hang kw <$> fmap PP.lines (traverse go rs)
461461
(Bytes' bs, _) ->
462-
pure $ fmt S.BytesLiteral "0xs" <> PP.shown (Bytes.fromWord8s (map fromIntegral bs))
462+
pure $ PP.group $ fmt S.BytesLiteral "0xs" <> PP.shown (Bytes.fromWord8s (map fromIntegral bs))
463463
BinaryAppsPred' apps lastArg -> do
464464
prettyLast <- pretty0 (ac 3 Normal im doc) lastArg
465465
prettyApps <- binaryApps apps prettyLast

scripts/check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ true \
66
&& stack exec transcripts \
77
&& stack exec unison transcript unison-src/transcripts-round-trip/main.md \
88
&& stack exec unison transcript unison-src/transcripts-manual/rewrites.md \
9+
&& stack exec unison transcript unison-src/transcripts-manual/docs.to-html.md \
910
&& stack exec cli-integration-tests

unison-cli/src/Unison/Cli/MonadUtils.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,15 @@ updateRoot new reason =
481481
getTermsAt :: (Path.Absolute, HQ'.HQSegment) -> Cli (Set Referent)
482482
getTermsAt path = do
483483
rootBranch0 <- getRootBranch0
484-
pure (BranchUtil.getTerm (Path.convert path) rootBranch0)
484+
pure (BranchUtil.getTerm (first Path.unabsolute path) rootBranch0)
485485

486486
------------------------------------------------------------------------------------------------------------------------
487487
-- Getting types
488488

489489
getTypesAt :: (Path.Absolute, HQ'.HQSegment) -> Cli (Set TypeReference)
490490
getTypesAt path = do
491491
rootBranch0 <- getRootBranch0
492-
pure (BranchUtil.getType (Path.convert path) rootBranch0)
492+
pure (BranchUtil.getType (first Path.unabsolute path) rootBranch0)
493493

494494
------------------------------------------------------------------------------------------------------------------------
495495
-- Getting patches

unison-cli/src/Unison/Cli/ProjectUtils.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ justTheIds x =
124124
ProjectAndBranch x.project.projectId x.branch.branchId
125125

126126
justTheIds' :: Sqlite.ProjectBranch -> ProjectAndBranch ProjectId ProjectBranchId
127-
justTheIds' x =
128-
ProjectAndBranch x.projectId x.branchId
127+
justTheIds' branch =
128+
ProjectAndBranch branch.projectId branch.branchId
129129

130130
justTheNames :: ProjectAndBranch Sqlite.Project Sqlite.ProjectBranch -> ProjectAndBranch ProjectName ProjectBranchName
131131
justTheNames x =

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

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import Unison.Codebase.Editor.HandleInput.FindAndReplace (handleStructuredFindI,
6666
import Unison.Codebase.Editor.HandleInput.FormatFile qualified as Format
6767
import Unison.Codebase.Editor.HandleInput.InstallLib (handleInstallLib)
6868
import Unison.Codebase.Editor.HandleInput.Load (EvalMode (Sandboxed), evalUnisonFile, handleLoad, loadUnisonFile)
69+
import Unison.Codebase.Editor.HandleInput.Ls (handleLs)
6970
import Unison.Codebase.Editor.HandleInput.Merge2 (handleMerge)
7071
import Unison.Codebase.Editor.HandleInput.MoveAll (handleMoveAll)
7172
import Unison.Codebase.Editor.HandleInput.MoveBranch (doMoveBranch)
@@ -347,7 +348,7 @@ loop e = do
347348
Left hash -> (,WhichBranchEmptyHash hash) <$> Cli.resolveShortCausalHash hash
348349
Right path' -> do
349350
absPath <- ProjectUtils.branchRelativePathToAbsolute path'
350-
let srcp = Path.convert absPath
351+
let srcp = Path.AbsolutePath' absPath
351352
srcb <- Cli.expectBranchAtPath' srcp
352353
pure (srcb, WhichBranchEmptyPath srcp)
353354
description <- inputDescription input
@@ -465,7 +466,7 @@ loop e = do
465466
Cli.respond $ Output.MarkdownOut (Text.intercalate "\n---\n" mdText)
466467
DocsToHtmlI namespacePath' sourceDirectory -> do
467468
Cli.Env {codebase, sandboxedRuntime} <- ask
468-
absPath <- Cli.resolvePath' namespacePath'
469+
absPath <- ProjectUtils.branchRelativePathToAbsolute namespacePath'
469470
branch <- liftIO $ Codebase.getBranchAtPath codebase absPath
470471
_evalErrs <- liftIO $ (Backend.docsInBranchToHtmlFiles sandboxedRuntime codebase branch sourceDirectory)
471472
pure ()
@@ -487,11 +488,11 @@ loop e = do
487488
hqLength <- Cli.runTransaction Codebase.hashLength
488489
pure (DeleteNameAmbiguous hqLength name srcTerms Set.empty)
489490
dest <- Cli.resolveSplit' dest'
490-
destTerms <- Cli.getTermsAt (Path.convert dest)
491+
destTerms <- Cli.getTermsAt (HQ'.NameOnly <$> dest)
491492
when (not (Set.null destTerms)) do
492493
Cli.returnEarly (TermAlreadyExists dest' destTerms)
493494
description <- inputDescription input
494-
Cli.stepAt description (BranchUtil.makeAddTermName (Path.convert dest) srcTerm)
495+
Cli.stepAt description (BranchUtil.makeAddTermName (first Path.unabsolute dest) srcTerm)
495496
Cli.respond Success
496497
AliasTypeI src' dest' -> do
497498
src <- traverseOf _Right Cli.resolveSplit' src'
@@ -510,11 +511,11 @@ loop e = do
510511
hqLength <- Cli.runTransaction Codebase.hashLength
511512
pure (DeleteNameAmbiguous hqLength name Set.empty srcTypes)
512513
dest <- Cli.resolveSplit' dest'
513-
destTypes <- Cli.getTypesAt (Path.convert dest)
514+
destTypes <- Cli.getTypesAt (HQ'.NameOnly <$> dest)
514515
when (not (Set.null destTypes)) do
515516
Cli.returnEarly (TypeAlreadyExists dest' destTypes)
516517
description <- inputDescription input
517-
Cli.stepAt description (BranchUtil.makeAddTypeName (Path.convert dest) srcType)
518+
Cli.stepAt description (BranchUtil.makeAddTypeName (first Path.unabsolute dest) srcType)
518519
Cli.respond Success
519520

520521
-- this implementation will happily produce name conflicts,
@@ -616,9 +617,9 @@ loop e = do
616617
guidPath <- Cli.resolveSplit' (authorPath' |> NameSegment.guidSegment)
617618
Cli.stepManyAt
618619
description
619-
[ BranchUtil.makeAddTermName (Path.convert authorPath) (d authorRef),
620-
BranchUtil.makeAddTermName (Path.convert copyrightHolderPath) (d copyrightHolderRef),
621-
BranchUtil.makeAddTermName (Path.convert guidPath) (d guidRef)
620+
[ BranchUtil.makeAddTermName (first Path.unabsolute authorPath) (d authorRef),
621+
BranchUtil.makeAddTermName (first Path.unabsolute copyrightHolderPath) (d copyrightHolderRef),
622+
BranchUtil.makeAddTermName (first Path.unabsolute guidPath) (d guidRef)
622623
]
623624
currentPath <- Cli.getCurrentPath
624625
finalBranch <- Cli.getCurrentBranch0
@@ -687,21 +688,7 @@ loop e = do
687688
traverse_ (displayI outputLoc) namesToDisplay
688689
ShowDefinitionI outputLoc showDefinitionScope query -> handleShowDefinition outputLoc showDefinitionScope query
689690
EditNamespaceI paths -> handleEditNamespace LatestFileLocation paths
690-
FindShallowI pathArg -> do
691-
Cli.Env {codebase} <- ask
692-
693-
pathArgAbs <- Cli.resolvePath' pathArg
694-
entries <- liftIO (Backend.lsAtPath codebase Nothing pathArgAbs)
695-
Cli.setNumberedArgs $ fmap (SA.ShallowListEntry pathArg) entries
696-
pped <- Cli.currentPrettyPrintEnvDecl
697-
let suffixifiedPPE = PPED.suffixifiedPPE pped
698-
-- This used to be a delayed action which only forced the loading of the root
699-
-- branch when it was necessary for printing the results, but that got wiped out
700-
-- when we ported to the new Cli monad.
701-
-- It would be nice to restore it, but it's pretty rare that it actually results
702-
-- in an improvement, so perhaps it's not worth the effort.
703-
let buildPPE = pure suffixifiedPPE
704-
Cli.respond $ ListShallow buildPPE entries
691+
FindShallowI pathArg -> handleLs pathArg
705692
FindI isVerbose fscope ws -> handleFindI isVerbose fscope ws input
706693
StructuredFindI _fscope ws -> handleStructuredFindI ws
707694
StructuredFindReplaceI ws -> handleStructuredFindReplaceI ws
@@ -1564,7 +1551,7 @@ checkDeletes typesTermsTuples doutput inputs = do
15641551
(Path.HQSplit', Set Reference, Set Referent) ->
15651552
Cli (Path.Split, Name, Set Reference, Set Referent)
15661553
toSplitName hq = do
1567-
resolvedPath <- Path.convert <$> Cli.resolveSplit' (HQ'.toName <$> hq ^. _1)
1554+
resolvedPath <- first Path.unabsolute <$> Cli.resolveSplit' (HQ'.toName <$> hq ^. _1)
15681555
return (resolvedPath, Path.unsafeToName (Path.unsplit resolvedPath), hq ^. _2, hq ^. _3)
15691556
-- get the splits and names with terms and types
15701557
splitsNames <- traverse toSplitName typesTermsTuples
@@ -1711,7 +1698,7 @@ docsI src = do
17111698
(codebaseByName) Lastly check for `foo.doc` in the codebase and if found do `display foo.doc`
17121699
-}
17131700
dotDoc :: HQ.HashQualified Name
1714-
dotDoc = Name.convert . Name.joinDot src $ Name.fromSegment NameSegment.docSegment
1701+
dotDoc = HQ.NameOnly . Name.joinDot src $ Name.fromSegment NameSegment.docSegment
17151702

17161703
findInScratchfileByName :: Cli ()
17171704
findInScratchfileByName = do

0 commit comments

Comments
 (0)