From d9d1d4b91cf276b0acace0687468b8ac4d1a650c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAnar?= Date: Wed, 8 Sep 2021 21:59:01 -0400 Subject: [PATCH 1/2] Add parens to destructuring binds --- parser-typechecker/src/Unison/TermPrinter.hs | 2 +- unison-src/transcripts-round-trip/main.md | 25 +++++- .../transcripts-round-trip/main.output.md | 88 +++++++++++++++++-- 3 files changed, 107 insertions(+), 8 deletions(-) diff --git a/parser-typechecker/src/Unison/TermPrinter.hs b/parser-typechecker/src/Unison/TermPrinter.hs index 72bda10f9..172dfa728 100644 --- a/parser-typechecker/src/Unison/TermPrinter.hs +++ b/parser-typechecker/src/Unison/TermPrinter.hs @@ -298,7 +298,7 @@ pretty0 -- know bc.) So we'll fail to take advantage of any opportunity -- this let block provides to add a use statement. Not so bad. (fmt S.ControlKeyword "let") `PP.hang` x - lhs = PP.group (fst (prettyPattern n (ac 0 Block im doc) (-1) vs pat)) + lhs = PP.group (fst (prettyPattern n (ac 0 Block im doc) 10 vs pat)) <> printGuard guard printGuard Nothing = mempty printGuard (Just g') = let (_,g) = ABT.unabs g' in diff --git a/unison-src/transcripts-round-trip/main.md b/unison-src/transcripts-round-trip/main.md index 7ff7039ca..42930a80c 100644 --- a/unison-src/transcripts-round-trip/main.md +++ b/unison-src/transcripts-round-trip/main.md @@ -55,6 +55,27 @@ Without the above stanza, the `edit` will send the definition to the most recent No reason you can't load a bunch of definitions from a single `.u` file in one go, the only thing that's annoying is you'll have to `find` and then `edit 1-11` in the transcript to load all the definitions into the file. -## Example 1 +## Destructuring binds + +Regression test for https://github.com/unisonweb/unison/issues/2337 + +```unison:hide +unique type Blah = Blah Boolean Boolean + +f : Blah -> Boolean +f x = let + (Blah.Blah a b) = x + a +``` + +```ucm +.> add +.> edit Blah f +.> reflog +.> reset-root 2 +``` + +``` ucm +.> load scratch.u +``` -Add tests here diff --git a/unison-src/transcripts-round-trip/main.output.md b/unison-src/transcripts-round-trip/main.output.md index 7708035cb..53e313284 100644 --- a/unison-src/transcripts-round-trip/main.output.md +++ b/unison-src/transcripts-round-trip/main.output.md @@ -18,7 +18,7 @@ x = 1 + 1 ☝️ I added these definitions to the top of - /Users/pchiusano/unison/scratch.u + /Users/runar/work/unison/scratch.u x : Nat x = @@ -102,7 +102,7 @@ Without the above stanza, the `edit` will send the definition to the most recent ☝️ I added these definitions to the top of - /Users/pchiusano/unison/scratch.u + /Users/runar/work/unison/scratch.u b : Nat b = 92384 @@ -146,8 +146,86 @@ Without the above stanza, the `edit` will send the definition to the most recent b : Nat ``` -No reason you can't load a bunch of definitions from a single `.u` file in one go, the only thing that's annoying is you'll have to `find` and then `edit 1-11 in the transcript to load all the definitions into the file. +No reason you can't load a bunch of definitions from a single `.u` file in one go, the only thing that's annoying is you'll have to `find` and then `edit 1-11` in the transcript to load all the definitions into the file. -## Example 1 +## Destructuring binds -Add tests here +Regression test for https://github.com/unisonweb/unison/issues/2337 + +```unison +unique type Blah = Blah Boolean Boolean + +f : Blah -> Boolean +f x = let + 0 + (Blah.Blah a b) = x + a +``` + +```ucm +.> add + + ⍟ I've added these definitions: + + unique type Blah + f : Blah -> Boolean + +.> edit Blah f + + ☝️ + + I added these definitions to the top of + /Users/runar/work/unison/scratch.u + + unique type Blah + = Blah Boolean Boolean + + f : Blah -> Boolean + f x = + 0 + let + (Blah a b) = x + a + + You can edit them there, then do `update` to replace the + definitions currently in this namespace. + +.> reflog + + Here is a log of the root namespace hashes, starting with the + most recent, along with the command that got us there. Try: + + `fork 2 .old` + `fork #pqvd5behc2 .old` to make an old namespace + accessible again, + + `reset-root #pqvd5behc2` to reset the root namespace and + its history to that of the + specified namespace. + + 1. #53gruvtk78 : add + 2. #pqvd5behc2 : reset-root #pqvd5behc2 + 3. #dbvse9969b : add + 4. #pqvd5behc2 : reset-root #pqvd5behc2 + 5. #8rn1an5gj8 : add + 6. #pqvd5behc2 : builtins.mergeio + 7. #sjg2v58vn2 : (initial reflogged namespace) + +.> reset-root 2 + + Done. + +``` +```ucm +.> load scratch.u + + I found and typechecked these definitions in scratch.u. If you + do an `add` or `update`, here's how your codebase would + change: + + ⍟ These new definitions are ok to `add`: + + unique type Blah + f : Blah -> Boolean + +``` From 935c4ed1a011692f9e1981a5c635a848f802f713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAnar?= Date: Wed, 8 Sep 2021 23:00:48 -0400 Subject: [PATCH 2/2] update test --- parser-typechecker/tests/Unison/Test/TermPrinter.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser-typechecker/tests/Unison/Test/TermPrinter.hs b/parser-typechecker/tests/Unison/Test/TermPrinter.hs index d190ab512..66f21a5b8 100644 --- a/parser-typechecker/tests/Unison/Test/TermPrinter.hs +++ b/parser-typechecker/tests/Unison/Test/TermPrinter.hs @@ -370,7 +370,7 @@ test = scope "termprinter" $ tests , pending $ tc "match x with [a] -> a" -- ditto , pending $ tc "match x with [] -> a" -- ditto , tcDiff "match x with Optional.Some (Optional.Some _) -> ()" - "let\n Optional.Some (Optional.Some _) = x\n ()" + "let\n (Optional.Some (Optional.Some _)) = x\n ()" -- need an actual effect constructor to test the following , pending $ tc "match x with { SomeRequest (Optional.Some _) -> k } -> ()" , tcBinding 50 "foo" (Just "Int") "3" "foo : Int\n\