Skip to content

Commit

Permalink
Merge pull request #5578 from unisonweb/cp/decl-printing
Browse files Browse the repository at this point in the history
Decl printing cleanup
  • Loading branch information
aryairani authored Feb 13, 2025
2 parents bb88817 + 1146eea commit 7d74227
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 22 deletions.
7 changes: 1 addition & 6 deletions parser-typechecker/src/Unison/PrettyPrintEnv/Util.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}

module Unison.PrettyPrintEnv.Util (declarationPPE, declarationPPEDecl) where
module Unison.PrettyPrintEnv.Util (declarationPPE) where

import Unison.PrettyPrintEnv (PrettyPrintEnv (..))
import Unison.PrettyPrintEnv qualified as PPE
Expand Down Expand Up @@ -29,8 +29,3 @@ declarationPPE ppe ref = PrettyPrintEnv tm ty
ty r
| hash r == rootH = PPE.typeNames (unsuffixifiedPPE ppe) r
| otherwise = PPE.typeNames (suffixifiedPPE ppe) r

-- The suffixed names uses the fully-qualified name for `r`
declarationPPEDecl :: PrettyPrintEnvDecl -> Reference -> PrettyPrintEnvDecl
declarationPPEDecl ppe r =
ppe {suffixifiedPPE = declarationPPE ppe r}
4 changes: 2 additions & 2 deletions parser-typechecker/src/Unison/Syntax/DeclPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ prettyGADT ::
DataDeclaration v a ->
Pretty SyntaxText
prettyGADT env ctorType r name dd =
P.hang header . P.lines $
constructor <$> zip [0 ..] (DD.constructors' dd)
header <> P.newline <> P.indentN 2 constructors
where
constructors = P.lines (constructor <$> zip [0 ..] (DD.constructors' dd))
constructor (n, (_, _, t)) =
prettyPattern (PPED.unsuffixifiedPPE env) ctorType name (ConstructorReference r n)
<> fmt S.TypeAscriptionColon " :"
Expand Down
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/Cli/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ prettyType pped (n, r, dt) =
case dt of
MissingObject r -> missingDefinitionMsg n r
BuiltinObject _ -> builtin n
UserObject decl -> DeclPrinter.prettyDecl (PPED.biasTo (maybeToList $ HQ.toName n) $ PPE.declarationPPEDecl pped r) r n decl
UserObject decl -> DeclPrinter.prettyDecl (PPED.biasTo (maybeToList $ HQ.toName n) $ pped) r n decl
where
builtin n = P.wrap $ "--" <> prettyHashQualified n <> " is built-in."

Expand Down
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2634,7 +2634,7 @@ displayDefinitions' ppe0 types terms = P.syntaxToColor $ P.sep "\n\n" (prettyTyp
case dt of
MissingObject r -> missing n r
BuiltinObject _ -> builtin n
UserObject decl -> DeclPrinter.prettyDecl (PPE.declarationPPEDecl ppe0 r) r n decl
UserObject decl -> DeclPrinter.prettyDecl ppe0 r n decl
builtin n = P.wrap $ "--" <> prettyHashQualified n <> " is built-in."
missing n r =
P.wrap
Expand Down
2 changes: 1 addition & 1 deletion unison-share-api/src/Unison/Server/Backend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ typesToSyntax suff width ppe0 types =
MissingObject sh -> MissingObject sh
UserObject d ->
UserObject . Pretty.render width $
DeclPrinter.prettyDecl (PPE.declarationPPEDecl ppe0 r) r n d
DeclPrinter.prettyDecl ppe0 r n d
where
ppeDecl =
if suffixified suff
Expand Down
6 changes: 4 additions & 2 deletions unison-src/transcripts-manual/rewrites.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ scratch/main> rewrite woot1to2
-- | Rewrote using:
-- | Modified definition(s): wootEx
ability Woot1 where woot1 : '{Woot1} Nat
ability Woot1 where
woot1 : '{Woot1} Nat
ability Woot2 where woot2 : '{Woot2} Nat
ability Woot2 where
woot2 : '{Woot2} Nat
woot1to2 x =
@rewrite
Expand Down
9 changes: 6 additions & 3 deletions unison-src/transcripts-round-trip/main.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ scratch/a1> edit.new 1-1000
```

````` unison :added-by-ucm scratch.u
structural ability Abort where abort : {Abort} a
structural ability Abort where
abort : {Abort} a
structural ability Ask a where ask : {Ask a} a
structural ability Ask a where
ask : {Ask a} a
structural type Fix_2337
= Fix_2337 Boolean Boolean
structural ability Fix_2392 where zonk : {Fix_2392} Nat
structural ability Fix_2392 where
zonk : {Fix_2392} Nat
structural type Fix_2392a x y
= Oog Nat Nat (Nat, Nat)
Expand Down
2 changes: 1 addition & 1 deletion unison-src/transcripts/idempotent/doc1.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ scratch/main> view lib.builtins.Doc
| Source Link
| Signature Term
| Evaluate Term
| Join [lib.builtins.Doc]
| Join [Doc]
```

You can create these `Doc` values with ordinary code, or you can use the special syntax. A value of structural type `Doc` can be created via syntax like:
Expand Down
3 changes: 2 additions & 1 deletion unison-src/transcripts/idempotent/formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ ability Thing where
Ask.doc = {{ Ability with single constructor }}
structural ability Ask a where ask : {Ask a} a
structural ability Ask a where
ask : {Ask a} a
-- Regression test for: https://github.com/unisonweb/unison/issues/4666
provide : a -> '{Ask a} r -> r
Expand Down
5 changes: 2 additions & 3 deletions unison-src/transcripts/idempotent/top-level-exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ FYI, here are the `Exception` and `Failure` types:
scratch/main> view Exception Failure
structural ability builtin.Exception where
raise : Failure ->{builtin.Exception} x
raise : Failure ->{Exception} x
type builtin.io2.Failure
= Failure Type Text Any
type builtin.io2.Failure = Failure Type Text Any
```

Here's a sample program just to verify that the typechecker allows `run` to throw exceptions:
Expand Down
3 changes: 2 additions & 1 deletion unison-src/transcripts/merge.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,8 @@ my.cool.thing : Nat
my.cool.thing = 17
-- scratch/bob
ability my.cool where thing : Nat ->{cool} Nat
ability my.cool where
thing : Nat ->{cool} Nat
```

Expand Down

0 comments on commit 7d74227

Please sign in to comment.