mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-11 17:16:30 +03:00
Merge remote-tracking branch 'origin/trunk' into wip/codebase2-cleanup
# Conflicts: # parser-typechecker/unison-parser-typechecker.cabal
This commit is contained in:
commit
509cc78a1a
@ -1077,9 +1077,13 @@ loop = do
|
||||
|
||||
fileByName = do
|
||||
ns <- maybe mempty UF.typecheckedToNames0 <$> use latestTypecheckedFile
|
||||
fnames <- pure $ Names3.Names ns mempty
|
||||
fnames <- pure $ Names3.suffixify (Names3.Names ns mempty)
|
||||
case Names3.lookupHQTerm dotDoc fnames of
|
||||
s | Set.size s == 1 -> displayI ConsoleLocation dotDoc
|
||||
s | Set.size s == 1 -> do
|
||||
-- the displayI command expects full term names, so we resolve
|
||||
-- the hash back to its full name in the file
|
||||
fname' <- pure $ Names3.longestTermName 10 (Set.findMin s) fnames
|
||||
displayI ConsoleLocation fname'
|
||||
_ -> codebaseByMetadata
|
||||
|
||||
codebaseByMetadata = unlessError do
|
||||
|
@ -301,7 +301,7 @@ lexemes' eof = P.optional space >> do
|
||||
-- ability Foo where => ability Foo where
|
||||
tn <- subsequentTypeName
|
||||
pure $ case (tn, docToks) of
|
||||
(Just tname, ht:_) | isTopLevel ->
|
||||
(Just (WordyId tname _), ht:_) | isTopLevel ->
|
||||
startToks
|
||||
<> [WordyId (tname <> ".doc") Nothing <$ ht, Open "=" <$ ht]
|
||||
<> docToks0
|
||||
@ -314,8 +314,7 @@ lexemes' eof = P.optional space >> do
|
||||
subsequentTypeName = P.lookAhead . P.optional $ do
|
||||
let lit' s = lit s <* sp
|
||||
_ <- P.optional (lit' "unique") *> (lit' "type" <|> lit' "ability")
|
||||
name <- P.takeWhile1P Nothing wordyIdChar
|
||||
pure name
|
||||
wordyId
|
||||
ignore _ _ _ = []
|
||||
body = join <$> P.many (sectionElem <* CP.space)
|
||||
sectionElem = section <|> fencedBlock <|> list <|> paragraph
|
||||
|
@ -1289,7 +1289,7 @@ bprim2 !ustk !bstk IDXB i j = do
|
||||
Just x -> do
|
||||
poke ustk $ fromIntegral x
|
||||
ustk <- bump ustk
|
||||
ustk <$ poke ustk 0
|
||||
ustk <$ poke ustk 1
|
||||
pure (ustk, bstk)
|
||||
bprim2 !ustk !bstk CATB i j = do
|
||||
l <- peekOffBi bstk i
|
||||
|
@ -17,6 +17,17 @@ test = scope "util.bytes" . tests $ [
|
||||
==
|
||||
Bytes.fromWord8s [0,1,2,3,4,5,6,7,8,9],
|
||||
|
||||
scope "at" $ do
|
||||
expect' (Bytes.at 0 (Bytes.fromWord8s [77,13,12]) == Just 77)
|
||||
expect' (Bytes.at 0 (Bytes.fromWord8s []) == Nothing)
|
||||
ok,
|
||||
|
||||
scope "at.cornerCases" $ do
|
||||
let b = Bytes.drop 3 $ Bytes.fromWord8s [77,13,12] <> Bytes.fromWord8s [9,10,11]
|
||||
expect' (Bytes.at 0 b == Just 9)
|
||||
expect' (Bytes.at 0 (mempty <> Bytes.fromWord8s [1,2,3]) == Just 1)
|
||||
ok,
|
||||
|
||||
scope "consistency with ByteString" $ do
|
||||
forM_ [(1::Int)..100] $ \_ -> do
|
||||
n <- int' 0 50
|
||||
|
@ -108,7 +108,7 @@ test config = do
|
||||
buildTests config testBuilder
|
||||
$ "unison-src" </> "transcripts"
|
||||
buildTests config testBuilder
|
||||
$ "unison-src" </> "new-runtime-transcripts"
|
||||
$ "unison-src" </> "transcripts-using-base"
|
||||
buildTests config testBuilder'
|
||||
$ "unison-src" </> "transcripts" </> "errors"
|
||||
cleanup
|
||||
|
@ -21,6 +21,7 @@ module Unison.Name
|
||||
, stripNamePrefix
|
||||
, stripPrefixes
|
||||
, segments
|
||||
, countSegments
|
||||
, segments'
|
||||
, suffixes
|
||||
, toString
|
||||
@ -177,6 +178,9 @@ fromSegment = unsafeFromText . NameSegment.toText
|
||||
segments :: Name -> [NameSegment]
|
||||
segments (Name n) = NameSegment <$> segments' n
|
||||
|
||||
countSegments :: Name -> Int
|
||||
countSegments n = length (segments n)
|
||||
|
||||
class Convert a b where
|
||||
convert :: a -> b
|
||||
|
||||
|
@ -169,6 +169,20 @@ typeName length r Names{..} =
|
||||
where hq n = HQ'.take length (HQ'.fromNamedReference n r)
|
||||
isConflicted n = R.manyDom n (Names.types currentNames)
|
||||
|
||||
-- List of names for a referent, longer names (by number of segments) first.
|
||||
termNamesByLength :: Int -> Referent -> Names -> [HQ'.HashQualified Name]
|
||||
termNamesByLength length r ns =
|
||||
sortOn len (toList $ termName length r ns)
|
||||
where len (HQ'.NameOnly n) = Name.countSegments n
|
||||
len (HQ'.HashQualified n _) = Name.countSegments n
|
||||
|
||||
-- The longest term name (by segment count) for a `Referent`.
|
||||
longestTermName :: Int -> Referent -> Names -> HQ.HashQualified Name
|
||||
longestTermName length r ns =
|
||||
case reverse (termNamesByLength length r ns) of
|
||||
[] -> HQ.take length (HQ.fromReferent r)
|
||||
(h : _) -> Name.convert h
|
||||
|
||||
termName :: Int -> Referent -> Names -> Set (HQ'.HashQualified Name)
|
||||
termName length r Names{..} =
|
||||
if R.memberRan r . Names.terms $ currentNames
|
||||
|
@ -13,7 +13,7 @@ transcripts which contain less boilerplate.
|
||||
.> builtins.merge
|
||||
.> builtins.mergeio
|
||||
.> cd builtin
|
||||
.> load unison-src/new-runtime-transcripts/base.u
|
||||
.> load unison-src/transcripts-using-base/base.u
|
||||
.> add
|
||||
```
|
||||
|
@ -177,6 +177,22 @@ test> Text.tests.alignment =
|
||||
.> add
|
||||
```
|
||||
|
||||
## `Bytes` functions
|
||||
|
||||
```unison:hide
|
||||
test> Bytes.tests.at =
|
||||
bs = Bytes.fromList [77, 13, 12]
|
||||
checks [
|
||||
Bytes.at 1 bs == Some 13,
|
||||
Bytes.at 0 bs == Some 77,
|
||||
Bytes.at 99 bs == None
|
||||
]
|
||||
```
|
||||
|
||||
```ucm:hide
|
||||
.> add
|
||||
```
|
||||
|
||||
## `Any` functions
|
||||
|
||||
```unison
|
@ -165,6 +165,18 @@ test> Text.tests.alignment =
|
||||
]
|
||||
```
|
||||
|
||||
## `Bytes` functions
|
||||
|
||||
```unison
|
||||
test> Bytes.tests.at =
|
||||
bs = Bytes.fromList [77, 13, 12]
|
||||
checks [
|
||||
Bytes.at 1 bs == Some 13,
|
||||
Bytes.at 0 bs == Some 77,
|
||||
Bytes.at 99 bs == None
|
||||
]
|
||||
```
|
||||
|
||||
## `Any` functions
|
||||
|
||||
```unison
|
||||
@ -212,6 +224,7 @@ Now that all the tests have been added to the codebase, let's view the test repo
|
||||
|
||||
◉ Any.test1 Passed
|
||||
◉ Any.test2 Passed
|
||||
◉ Bytes.tests.at Passed
|
||||
◉ Int.tests.arithmetic Passed
|
||||
◉ Int.tests.bitTwiddling Passed
|
||||
◉ Int.tests.conversions Passed
|
||||
@ -222,7 +235,7 @@ Now that all the tests have been added to the codebase, let's view the test repo
|
||||
◉ Text.tests.repeat Passed
|
||||
◉ Text.tests.takeDropAppend Passed
|
||||
|
||||
✅ 11 test(s) passing
|
||||
✅ 12 test(s) passing
|
||||
|
||||
Tip: Use view Any.test1 to view the source of a test.
|
||||
|
@ -29,7 +29,7 @@ The 7 days of the week, defined as:
|
||||
|
||||
@source{type DayOfWeek}
|
||||
}}
|
||||
unique type DayOfWeek = Sun | Mon | Tue | Wed | Thu | Fri | Sat
|
||||
unique type time.DayOfWeek = Sun | Mon | Tue | Wed | Thu | Fri | Sat
|
||||
```
|
||||
|
||||
Notice that an anonymous documentation block `{{ ... }}` before a definition `ImportantConstant` is just syntax sugar for `ImportantConstant.doc = {{ ... }}`.
|
||||
@ -49,7 +49,7 @@ The `docs ImportantConstant` command will look for `ImportantConstant.doc` in th
|
||||
First, we'll load the `syntax.u` file which has examples of all the syntax:
|
||||
|
||||
```ucm
|
||||
.> load ./unison-src/new-runtime-transcripts/doc.md.files/syntax.u
|
||||
.> load ./unison-src/transcripts-using-base/doc.md.files/syntax.u
|
||||
```
|
||||
|
||||
```ucm:hide
|
@ -25,7 +25,7 @@ The 7 days of the week, defined as:
|
||||
|
||||
@source{type DayOfWeek}
|
||||
}}
|
||||
unique type DayOfWeek = Sun | Mon | Tue | Wed | Thu | Fri | Sat
|
||||
unique type time.DayOfWeek = Sun | Mon | Tue | Wed | Thu | Fri | Sat
|
||||
```
|
||||
|
||||
```ucm
|
||||
@ -36,12 +36,12 @@ unique type DayOfWeek = Sun | Mon | Tue | Wed | Thu | Fri | Sat
|
||||
|
||||
⍟ These new definitions are ok to `add`:
|
||||
|
||||
unique type DayOfWeek
|
||||
DayOfWeek.doc : Doc2
|
||||
unique type time.DayOfWeek
|
||||
ImportantConstant : Nat
|
||||
ImportantConstant.doc : Doc2
|
||||
d1 : Doc2
|
||||
name : Doc2
|
||||
time.DayOfWeek.doc : Doc2
|
||||
|
||||
```
|
||||
Notice that an anonymous documentation block `{{ ... }}` before a definition `ImportantConstant` is just syntax sugar for `ImportantConstant.doc = {{ ... }}`.
|
||||
@ -78,10 +78,10 @@ The `docs ImportantConstant` command will look for `ImportantConstant.doc` in th
|
||||
First, we'll load the `syntax.u` file which has examples of all the syntax:
|
||||
|
||||
```ucm
|
||||
.> load ./unison-src/new-runtime-transcripts/doc.md.files/syntax.u
|
||||
.> load ./unison-src/transcripts-using-base/doc.md.files/syntax.u
|
||||
|
||||
I found and typechecked these definitions in
|
||||
./unison-src/new-runtime-transcripts/doc.md.files/syntax.u. If
|
||||
./unison-src/transcripts-using-base/doc.md.files/syntax.u. If
|
||||
you do an `add` or `update`, here's how your codebase would
|
||||
change:
|
||||
|
Loading…
Reference in New Issue
Block a user