Skip to content

Commit

Permalink
Merge pull request #5078 from unisonweb/cp/use-projects-in-transcripts
Browse files Browse the repository at this point in the history
Use projects in transcripts
  • Loading branch information
mergify[bot] authored Jun 27, 2024
2 parents f824743 + 937ac50 commit c206059
Show file tree
Hide file tree
Showing 408 changed files with 2,149 additions and 2,473 deletions.
12 changes: 5 additions & 7 deletions lib/unison-prelude/src/Unison/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ module Unison.Debug
)
where

import Control.Applicative (empty)
import Control.Monad (when)
import Data.Set (Set)
import Data.Set qualified as Set
import Data.Text qualified as Text
import Debug.Pretty.Simple (pTrace, pTraceM, pTraceShowId, pTraceShowM)
import Debug.Pretty.Simple (pTrace, pTraceM)
import System.IO.Unsafe (unsafePerformIO)
import Text.Pretty.Simple (pShow)
import Unison.Prelude
import UnliftIO.Environment (lookupEnv)

data DebugFlag
Expand Down Expand Up @@ -148,7 +147,7 @@ debugPatternCoverageConstraintSolver = PatternCoverageConstraintSolver `Set.memb
debug :: (Show a) => DebugFlag -> String -> a -> a
debug flag msg a =
if shouldDebug flag
then pTraceShowId (pTrace (msg <> ":\n") a)
then (pTrace (msg <> ":\n" <> into @String (pShow a)) a)
else a

-- | Use for selective debug logging in monadic contexts.
Expand All @@ -159,8 +158,7 @@ debug flag msg a =
debugM :: (Show a, Monad m) => DebugFlag -> String -> a -> m ()
debugM flag msg a =
whenDebug flag do
pTraceM (msg <> ":\n")
pTraceShowM a
traceM (msg <> ":\n" <> into @String (pShow a))

debugLog :: DebugFlag -> String -> a -> a
debugLog flag msg =
Expand Down
4 changes: 2 additions & 2 deletions unison-share-api/src/Unison/Server/Local.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ relocateToNameRoot perspective query rootBranch = do
-- Since the project root is lower down we need to strip the part of the prefix
-- which is now redundant.
pure . Right $ (projectRoot, query <&> \n -> fromMaybe n $ Path.unprefixName (Path.Absolute remainder) n)
-- The namesRoot is _inside_ of the project containing the query
-- The namesRoot is _inside (or equal to)_ the project containing the query
(_sharedPrefix, remainder, Path.Empty) -> do
-- Since the project is higher up, we need to prefix the query
-- with the remainder of the path
pure $ Right (projectRoot, query <&> Path.prefixNameIfRel (Path.AbsolutePath' $ Path.Absolute remainder))
pure $ Right (projectRoot, query <&> Path.prefixNameIfRel (Path.RelativePath' $ Path.Relative remainder))
-- The namesRoot and project root are disjoint, this shouldn't ever happen.
(_, _, _) -> pure $ Left (DisjointProjectAndPerspective perspective projectRoot)

Expand Down
6 changes: 3 additions & 3 deletions unison-src/builtin-tests/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Thus, make sure the contents of this file define the contents of the cache
(e.g. don't pull `latest`.)

```ucm
.> pull @unison/base/releases/2.5.0 .base
.> builtins.mergeio
.> undo
scratch/main> pull @unison/base/releases/2.5.0 .base
scratch/main> builtins.mergeio
scratch/main> undo
```
8 changes: 4 additions & 4 deletions unison-src/builtin-tests/interpreter-tests.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ If you want to add or update tests, you can create a branch of that project, and
Before merging the PR on Github, we'll merge your branch on Share and restore `runtime_tests_version` to /main or maybe a release.

```ucm:hide:error
.> this is a hack to trigger an error, in order to swallow any error on the next line.
.> we delete the project to avoid any merge conflicts or complaints from ucm.
.> delete.project runtime-tests
scratch/main> this is a hack to trigger an error, in order to swallow any error on the next line.
scratch/main> we delete the project to avoid any merge conflicts or complaints from ucm.
scratch/main> delete.project runtime-tests
```
```ucm:hide
.> clone ${runtime_tests_version} runtime-tests/selected
scratch/main> clone ${runtime_tests_version} runtime-tests/selected
```

```ucm
Expand Down
12 changes: 6 additions & 6 deletions unison-src/builtin-tests/jit-tests.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ If you want to add or update tests, you can create a branch of that project, and
Before merging the PR on Github, we'll merge your branch on Share and restore `runtime_tests_version` to /main or maybe a release.

```ucm:hide:error
.> this is a hack to trigger an error, in order to swallow any error on the next line.
.> we delete the project to avoid any merge conflicts or complaints from ucm.
.> delete.project runtime-tests
scratch/main> this is a hack to trigger an error, in order to swallow any error on the next line.
scratch/main> we delete the project to avoid any merge conflicts or complaints from ucm.
scratch/main> delete.project runtime-tests
```
```ucm:hide
.> clone ${runtime_tests_version} runtime-tests/selected
scratch/main> clone ${runtime_tests_version} runtime-tests/selected
```

```ucm
Expand All @@ -31,8 +31,8 @@ foo = do
```

```ucm
.> run.native foo
.> run.native foo
scratch/main> run.native foo
scratch/main> run.native foo
```

This can also only be tested by separately running this test, because
Expand Down
52 changes: 26 additions & 26 deletions unison-src/transcripts-manual/benchmarks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```ucm:hide
.> pull unison.public.base.releases.M4d base
.> pull runarorama.public.sort.data sort
scratch/main> pull unison.public.base.releases.M4d base
scratch/main> pull runarorama.public.sort.data sort
```

```unison:hide
Expand Down Expand Up @@ -34,63 +34,63 @@ prepare = do
```

```ucm:hide
.> add
.> run prepare
scratch/main> add
scratch/main> run prepare
```

## Benchmarks

```ucm
.> load unison-src/transcripts-manual/benchmarks/each.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/each.u
scratch/main> run main
```

```ucm
.> load unison-src/transcripts-manual/benchmarks/listmap.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/listmap.u
scratch/main> run main
```

```ucm
.> load unison-src/transcripts-manual/benchmarks/listfilter.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/listfilter.u
scratch/main> run main
```

```ucm
.> load unison-src/transcripts-manual/benchmarks/random.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/random.u
scratch/main> run main
```

```ucm
.> load unison-src/transcripts-manual/benchmarks/simpleloop.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/simpleloop.u
scratch/main> run main
```

```ucm
.> load unison-src/transcripts-manual/benchmarks/fibonacci.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/fibonacci.u
scratch/main> run main
```

```ucm
.> load unison-src/transcripts-manual/benchmarks/map.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/map.u
scratch/main> run main
```

```ucm
.> load unison-src/transcripts-manual/benchmarks/natmap.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/natmap.u
scratch/main> run main
```

```ucm
.> load unison-src/transcripts-manual/benchmarks/stm.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/stm.u
scratch/main> run main
```

```ucm
.> load unison-src/transcripts-manual/benchmarks/tmap.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/tmap.u
scratch/main> run main
```

```ucm
.> load unison-src/transcripts-manual/benchmarks/array-sort.u
.> run main
scratch/main> load unison-src/transcripts-manual/benchmarks/array-sort.u
scratch/main> run main
```
3 changes: 1 addition & 2 deletions unison-src/transcripts-manual/docs.to-html.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
```ucm
.> project.create test-html-docs
test-html-docs/main> builtins.merge
test-html-docs/main> builtins.mergeio lib.builtins
```

```unison
Expand Down
39 changes: 7 additions & 32 deletions unison-src/transcripts-manual/docs.to-html.output.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
```ucm
.> project.create test-html-docs
🎉 I've created the project test-html-docs.
I'll now fetch the latest version of the base Unison
library...
Downloaded 14067 entities.
🎨 Type `ui` to explore this project's code in your browser.
🔭 Discover libraries at https://share.unison-lang.org
📖 Use `help-topic projects` to learn more about projects.
Write your first Unison code with UCM:
1. Open scratch.u.
2. Write some Unison code and save the file.
3. In UCM, type `add` to save it to your new project.
🎉 🥳 Happy coding!
test-html-docs/main> builtins.merge
test-html-docs/main> builtins.mergeio lib.builtins
Done.
Expand All @@ -47,13 +26,11 @@ some.outside = 3
⍟ These new definitions are ok to `add`:
some.ns.direct : Nat
some.ns.direct.doc : Doc
some.ns.direct.doc : Doc2
some.ns.pretty.deeply.nested : Nat
(also named lib.base.data.Map.internal.ratio)
some.ns.pretty.deeply.nested.doc : Doc
some.ns.pretty.deeply.nested.doc : Doc2
some.outside : Nat
(also named lib.base.data.Map.internal.delta)
some.outside.doc : Doc
some.outside.doc : Doc2
```
```ucm
Expand All @@ -62,13 +39,11 @@ test-html-docs/main> add
⍟ I've added these definitions:
some.ns.direct : Nat
some.ns.direct.doc : Doc
some.ns.direct.doc : Doc2
some.ns.pretty.deeply.nested : Nat
(also named lib.base.data.Map.internal.ratio)
some.ns.pretty.deeply.nested.doc : Doc
some.ns.pretty.deeply.nested.doc : Doc2
some.outside : Nat
(also named lib.base.data.Map.internal.delta)
some.outside.doc : Doc
some.outside.doc : Doc2
test-html-docs/main> docs.to-html some.ns unison-src/transcripts-manual/docs.to-html
Expand Down
2 changes: 1 addition & 1 deletion unison-src/transcripts-manual/remote-tab-completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Note: this makes a network call to share to get completions

```ucm
.> debug.tab-complete pull unison.pub
scratch/main> debug.tab-complete pull unison.pub
```
Loading

0 comments on commit c206059

Please sign in to comment.