Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Term name resolution change #5296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
24b5aa5
Added precedence rules to term parser
runarorama Aug 11, 2024
9d4e2eb
Cleanup
runarorama Aug 11, 2024
8efd8d5
Add comments
runarorama Aug 11, 2024
7012cc4
Proper algorithm for reassociation
runarorama Aug 13, 2024
8736c4a
Comments
runarorama Aug 13, 2024
b92dede
Improve comments
runarorama Aug 13, 2024
725ee3b
Modify infix printer
runarorama Aug 15, 2024
d43288a
Adapt old infix printer to new rules
runarorama Aug 16, 2024
1470085
Get rid of confusing precedence levels
runarorama Aug 17, 2024
2998137
Transcripts
runarorama Aug 18, 2024
3e89640
transcripts
runarorama Aug 18, 2024
d242ae9
Fix UI on Windows
puffnfresh Aug 20, 2024
f48880f
More parens for do blocks
runarorama Aug 20, 2024
b64ac8b
Get rid of commented-out code
runarorama Aug 20, 2024
3e40cb1
Add roundtrip tests
runarorama Aug 20, 2024
b1a4d73
Fix dev-ui-install.sh
sellout Aug 20, 2024
4c166f0
Add exponentiation operators
runarorama Aug 20, 2024
da75484
Merge branch 'trunk' of https://github.com/unisonweb/unison into prec…
runarorama Aug 20, 2024
a7a80c9
Add puffnfresh to contributors
puffnfresh Aug 21, 2024
c8414eb
Simpler infix printer
runarorama Aug 21, 2024
b868fec
Merge pull request #5288 from puffnfresh/bug/windows-ui
mergify[bot] Aug 21, 2024
4c6139a
term name resolution tweak: don't prefer names from the file over nam…
mitchellwrosen Aug 21, 2024
f911310
get ambiguous term error message properly suffixifying names
mitchellwrosen Aug 22, 2024
677e989
⅄ trunk → term-name-resolution-change
mitchellwrosen Aug 22, 2024
f03f784
show type suggestions for holes again
mitchellwrosen Aug 22, 2024
a025454
Turn a possible “impossible” into a parse failure
sellout Aug 22, 2024
a1ba98e
Add a transcript to test empty `match`
sellout Aug 23, 2024
1132a6b
Support pattern matching on empty types
sellout Aug 23, 2024
7178ec2
Merge pull request #5298 from sellout/empty-match
pchiusano Aug 23, 2024
1207653
Merge pull request #5297 from sellout/impossible-in-lexer
pchiusano Aug 23, 2024
a1e188b
Merge pull request #5291 from sellout/fix-dev-ui-install
pchiusano Aug 23, 2024
82d012f
emit a proper resolution result for constructors
mitchellwrosen Aug 23, 2024
7cb62a2
delete now-unused UnknownAbilityConstructor/UnknownDataConstructor er…
mitchellwrosen Aug 23, 2024
eefacbf
Remove comments
runarorama Aug 23, 2024
8a70414
More parens around do blocks
runarorama Aug 23, 2024
e9ca76f
Merge pull request #5273 from unisonweb/precedence
runarorama Aug 24, 2024
2e71dff
Kill Configurator and Unison Config
ChrisPenner Aug 24, 2024
bbb04d9
get the transcripts passing (but a couple are still broken)
mitchellwrosen Aug 26, 2024
6299fc3
Merge pull request #5299 from unisonweb/cp/kill-config
aryairani Aug 26, 2024
af8315e
restore better error messages from type checker, not parser, on term …
mitchellwrosen Aug 26, 2024
38c1482
fix missing record field
mitchellwrosen Aug 26, 2024
9892658
⅄ trunk → term-name-resolution-change
mitchellwrosen Aug 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bundle-ucm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ jobs:
file: ucm.cmd
content: |
@echo off
SET UCM_WEB_UI="%~dp0ui"
SET UCM_WEB_UI=%~dp0ui
"%~dp0unison\unison.exe" --runtime-path "%~dp0runtime\unison-runtime.exe" %*
- name: package everything together
run: |
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ The format for this list: name, GitHub handle
* Dan Doel (@dolio)
* Eric Torreborre (@etorreborre)
* Eduard Nicodei (@neduard)
* Brian McKenna (@puffnfresh)
1 change: 0 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ These are listed in alphabetical order.
| [comonad-5.0.6](https://hackage.haskell.org/package/comonad-5.0.6) | [BSD3](https://hackage.haskell.org/package/comonad-5.0.6/src/LICENSE) |
| [concurrent-supply-0.1.8](https://hackage.haskell.org/package/concurrent-supply-0.1.8) | [BSD3](https://hackage.haskell.org/package/concurrent-supply-0.1.8/src/LICENSE) |
| [conduit-1.3.2](https://hackage.haskell.org/package/conduit-1.3.2) | [MIT](https://hackage.haskell.org/package/conduit-1.3.2/src/LICENSE) |
| [configurator-0.3.0.0](https://hackage.haskell.org/package/configurator-0.3.0.0) | [BSD3](https://hackage.haskell.org/package/configurator-0.3.0.0/src/LICENSE) |
| [containers-0.6.2.1](https://hackage.haskell.org/package/containers-0.6.2.1) | [BSD3](https://hackage.haskell.org/package/containers-0.6.2.1/src/LICENSE) |
| [contravariant-1.5.2](https://hackage.haskell.org/package/contravariant-1.5.2) | [BSD3](https://hackage.haskell.org/package/contravariant-1.5.2/src/LICENSE) |
| [cryptohash-md5-0.11.100.1](https://hackage.haskell.org/package/cryptohash-md5-0.11.100.1) | [BSD3](https://hackage.haskell.org/package/cryptohash-md5-0.11.100.1/src/LICENSE) |
Expand Down
5 changes: 0 additions & 5 deletions contrib/cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ packages:
unison-syntax
yaks/easytest

source-repository-package
type: git
location: https://github.com/unisonweb/configurator.git
tag: e47e9e9fe1f576f8c835183b9def52d73c01327a

source-repository-package
type: git
location: https://github.com/unisonweb/haskeline.git
Expand Down
5 changes: 4 additions & 1 deletion dev-ui-install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env sh
set -eu

echo "This script downloads the latest Unison Local UI release"
echo "and puts it in the correct spot next to the unison"
echo "executable built by stack."
Expand All @@ -7,4 +10,4 @@ stack build
curl -L https://github.com/unisonweb/unison-local-ui/releases/download/latest/unisonLocal.zip --output unisonLocal.zip
parent_dir="$(dirname -- $(stack exec which unison))"
mkdir -p "$parent_dir/ui"
unzip -o unisonLocal.zip -d "$parent_dir/ui"
unzip -q -o unisonLocal.zip -d "$parent_dir/ui"
1 change: 0 additions & 1 deletion nix/unison-project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ in
}
];
branchMap = {
"https://github.com/unisonweb/configurator.git"."e47e9e9fe1f576f8c835183b9def52d73c01327a" = "unison";
"https://github.com/unisonweb/shellmet.git"."2fd348592c8f51bb4c0ca6ba4bc8e38668913746" = "topic/avoid-callCommand";
};
}
1 change: 0 additions & 1 deletion parser-typechecker/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dependencies:
- cereal
- clock
- concurrent-output
- configurator
- containers >= 0.6.3
- cryptonite
- data-default
Expand Down
4 changes: 2 additions & 2 deletions parser-typechecker/src/Unison/Hashing/V2/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ h2mReferent getCT = \case
hashDataDecls ::
(Var v) =>
Map v (Memory.DD.DataDeclaration v a) ->
ResolutionResult v a [(v, Memory.Reference.Id, Memory.DD.DataDeclaration v a)]
ResolutionResult a [(v, Memory.Reference.Id, Memory.DD.DataDeclaration v a)]
hashDataDecls memDecls = do
let hashingDecls = fmap m2hDecl memDecls
hashingResult <- Hashing.hashDecls Name.unsafeParseVar hashingDecls
Expand All @@ -239,7 +239,7 @@ hashDataDecls memDecls = do
hashDecls ::
(Var v) =>
Map v (Memory.DD.Decl v a) ->
ResolutionResult v a [(v, Memory.Reference.Id, Memory.DD.Decl v a)]
ResolutionResult a [(v, Memory.Reference.Id, Memory.DD.Decl v a)]
hashDecls memDecls = do
-- want to unwrap the decl before doing the rehashing, and then wrap it back up the same way
let howToReassemble =
Expand Down
3 changes: 2 additions & 1 deletion parser-typechecker/src/Unison/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ unsafeParseFileBuiltinsOnly =
Parser.ParsingEnv
{ uniqueNames = mempty,
uniqueTypeGuid = \_ -> pure Nothing,
names = Builtin.names
names = Builtin.names,
maybeNamespace = Nothing
}

unsafeParseFile :: (Monad m) => String -> Parser.ParsingEnv m -> m (UnisonFile Symbol Ann)
Expand Down
18 changes: 5 additions & 13 deletions parser-typechecker/src/Unison/PatternMatchCoverage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module Unison.PatternMatchCoverage
)
where

import Data.List.NonEmpty (nonEmpty)
import Data.Set qualified as Set
import Debug.Trace
import Unison.Debug
Expand Down Expand Up @@ -63,31 +62,24 @@ checkMatch ::
checkMatch scrutineeType cases = do
ppe <- getPrettyPrintEnv
v0 <- fresh
mgrdtree0 <- traverse (desugarMatch scrutineeType v0) (nonEmpty cases)
doDebug (P.hang (title "desugared:") (prettyGrdTreeMaybe (prettyPmGrd ppe) (\_ -> "<loc>") mgrdtree0)) (pure ())
grdtree0 <- desugarMatch scrutineeType v0 cases
doDebug (P.hang (title "desugared:") (prettyGrdTree (prettyPmGrd ppe) (\_ -> "<loc>") grdtree0)) (pure ())
let initialUncovered = Set.singleton (NC.markDirty v0 $ NC.declVar v0 scrutineeType id NC.emptyNormalizedConstraints)
(uncovered, grdtree1) <- case mgrdtree0 of
Nothing -> pure (initialUncovered, Nothing)
Just grdtree0 -> fmap Just <$> uncoverAnnotate initialUncovered grdtree0
(uncovered, grdtree1) <- uncoverAnnotate initialUncovered grdtree0
doDebug
( P.sep
"\n"
[ P.hang (title "annotated:") (prettyGrdTreeMaybe (NC.prettyDnf ppe) (NC.prettyDnf ppe . fst) grdtree1),
[ P.hang (title "annotated:") (prettyGrdTree (NC.prettyDnf ppe) (NC.prettyDnf ppe . fst) grdtree1),
P.hang (title "uncovered:") (NC.prettyDnf ppe uncovered)
]
)
(pure ())
uncoveredExpanded <- concat . fmap Set.toList <$> traverse (expandSolution v0) (Set.toList uncovered)
doDebug (P.hang (title "uncovered expanded:") (NC.prettyDnf ppe (Set.fromList uncoveredExpanded))) (pure ())
let sols = map (generateInhabitants v0) uncoveredExpanded
let (_accessible, inaccessible, redundant) = case grdtree1 of
Nothing -> ([], [], [])
Just x -> classify x
let (_accessible, inaccessible, redundant) = classify grdtree1
pure (redundant, inaccessible, sols)
where
prettyGrdTreeMaybe prettyNode prettyLeaf = \case
Nothing -> "<empty>"
Just x -> prettyGrdTree prettyNode prettyLeaf x
title = P.bold
doDebug out = case shouldDebug PatternCoverage of
True -> trace (P.toAnsiUnbroken out)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Unison.PatternMatchCoverage.Desugar
)
where

import Data.List.NonEmpty (NonEmpty (..))
import U.Core.ABT qualified as ABT
import Unison.Pattern
import Unison.Pattern qualified as Pattern
Expand All @@ -25,7 +24,7 @@ desugarMatch ::
-- | scrutinee variable
v ->
-- | match cases
NonEmpty (MatchCase loc (Term' vt v loc)) ->
[MatchCase loc (Term' vt v loc)] ->
m (GrdTree (PmGrd vt v loc) loc)
desugarMatch scrutineeType v0 cs0 = Fork <$> traverse desugarClause cs0
where
Expand Down
8 changes: 3 additions & 5 deletions parser-typechecker/src/Unison/PatternMatchCoverage/GrdTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ module Unison.PatternMatchCoverage.GrdTree
)
where

import Data.List.NonEmpty (NonEmpty (..))
import Data.List.NonEmpty qualified as NEL
import Data.ListLike (ListLike)
import Unison.PatternMatchCoverage.Fix
import Unison.Prelude
Expand Down Expand Up @@ -55,7 +53,7 @@ data GrdTreeF n l a
| -- | A constraint of some kind (structural pattern match, boolan guard, etc)
GrdF n a
| -- | A list of alternative matches, tried in order
ForkF (NonEmpty a)
ForkF [a]
deriving stock (Functor, Show)

prettyGrdTree :: forall n l s. (ListLike s Char, IsString s) => (n -> Pretty s) -> (l -> Pretty s) -> GrdTree n l -> Pretty s
Expand All @@ -64,7 +62,7 @@ prettyGrdTree prettyNode prettyLeaf = cata phi
phi = \case
LeafF l -> prettyLeaf l
GrdF n rest -> sep " " [prettyNode n, "──", rest]
ForkF xs -> "──" <> group (sep "\n" (makeTree $ NEL.toList xs))
ForkF xs -> "──" <> group (sep "\n" $ makeTree xs)
makeTree :: [Pretty s] -> [Pretty s]
makeTree = \case
[] -> []
Expand All @@ -82,7 +80,7 @@ pattern Leaf x = Fix (LeafF x)
pattern Grd :: n -> GrdTree n l -> GrdTree n l
pattern Grd x rest = Fix (GrdF x rest)

pattern Fork :: NonEmpty (GrdTree n l) -> GrdTree n l
pattern Fork :: [GrdTree n l] -> GrdTree n l
pattern Fork alts = Fix (ForkF alts)

{-# COMPLETE Leaf, Grd, Fork #-}
8 changes: 3 additions & 5 deletions parser-typechecker/src/Unison/PatternMatchCoverage/Solve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Data.Foldable
import Data.Function
import Data.Functor
import Data.Functor.Compose
import Data.List.NonEmpty (NonEmpty (..))
import Data.Map qualified as Map
import Data.Sequence qualified as Seq
import Data.Set qualified as Set
Expand Down Expand Up @@ -74,12 +73,11 @@ uncoverAnnotate z grdtree0 = cata phi grdtree0 z
LeafF l -> \nc -> do
nc' <- ensureInhabited' nc
pure (Set.empty, Leaf (nc', l))
ForkF (kinit :| ks) -> \nc0 -> do
ForkF ks -> \nc0 -> do
-- depth-first fold in match-case order to acculate the
-- constraints for a match failure at every case.
(nc1, t1) <- kinit nc0
(ncfinal, ts) <- foldlM (\(nc, ts) a -> a nc >>= \(nc', t) -> pure (nc', t : ts)) (nc1, []) ks
pure (ncfinal, Fork (t1 :| reverse ts))
(ncfinal, ts) <- foldlM (\(nc, ts) a -> a nc >>= \(nc', t) -> pure (nc', t : ts)) (nc0, []) ks
pure (ncfinal, Fork $ reverse ts)
GrdF grd k -> \nc0 -> case grd of
PmEffect var con convars -> handleGrd (PosEffect var (Effect con) convars) (NegEffect var (Effect con)) k nc0
PmEffectPure var resume -> handleGrd (PosEffect var NoEffect [resume]) (NegEffect var NoEffect) k nc0
Expand Down
21 changes: 21 additions & 0 deletions parser-typechecker/src/Unison/PrettyPrintEnv/Names.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Unison.PrettyPrintEnv.Names
dontSuffixify,
suffixifyByHash,
suffixifyByName,
suffixifyByHashWithUnhashedTermsInScope,

-- * Pretty-print env
makePPE,
Expand All @@ -23,11 +24,14 @@ import Unison.Name (Name)
import Unison.Name qualified as Name
import Unison.Names (Names)
import Unison.Names qualified as Names
import Unison.Names.ResolvesTo (ResolvesTo (..))
import Unison.NamesWithHistory qualified as Names
import Unison.Prelude
import Unison.PrettyPrintEnv (PrettyPrintEnv (PrettyPrintEnv))
import Unison.Reference (TypeReference)
import Unison.Referent (Referent)
import Unison.Util.Relation (Relation)
import Unison.Util.Relation qualified as Relation

------------------------------------------------------------------------------------------------------------------------
-- Namer
Expand Down Expand Up @@ -84,6 +88,23 @@ suffixifyByHash names =
suffixifyType = \name -> Name.suffixifyByHash name (Names.types names)
}

suffixifyByHashWithUnhashedTermsInScope :: Set Name -> Names -> Suffixifier
suffixifyByHashWithUnhashedTermsInScope localTermNames namespaceNames =
Suffixifier
{ suffixifyTerm = \name ->
Name.suffixifyByHash
name
terms, -- (Relation.mapRanMonotonic ResolvesToNamespace (Names.terms names)),
suffixifyType = \name -> Name.suffixifyByHash name (Names.types namespaceNames)
}
where
terms :: Relation Name (ResolvesTo Referent)
terms =
Names.terms namespaceNames
& Relation.subtractDom localTermNames
& Relation.mapRan ResolvesToNamespace
& Relation.union (Relation.fromList (map (\name -> (name, ResolvesToLocal name)) (Set.toList localTermNames)))

------------------------------------------------------------------------------------------------------------------------
-- Pretty-print env

Expand Down
Loading
Loading