UnqualifiedNames -> Names

This commit is contained in:
Chris Penner 2021-10-16 22:19:33 -06:00
parent 0f082fbd22
commit 14f2c1a02e
30 changed files with 259 additions and 265 deletions

View File

@ -43,7 +43,7 @@ import qualified Unison.Var as Var
import Unison.Name ( Name ) import Unison.Name ( Name )
import qualified Unison.Name as Name import qualified Unison.Name as Name
import Unison.NamesWithHistory (NamesWithHistory(..)) import Unison.NamesWithHistory (NamesWithHistory(..))
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
import qualified Unison.NamesWithHistory as NamesWithHistory import qualified Unison.NamesWithHistory as NamesWithHistory
import qualified Unison.Typechecker.TypeLookup as TL import qualified Unison.Typechecker.TypeLookup as TL
import qualified Unison.Util.Relation as Rel import qualified Unison.Util.Relation as Rel
@ -56,7 +56,7 @@ type Type v = Type.Type v ()
names :: NamesWithHistory names :: NamesWithHistory
names = NamesWithHistory names0 mempty names = NamesWithHistory names0 mempty
names0 :: UnqualifiedNames names0 :: Names
names0 = NamesWithHistory.names0 terms types where names0 = NamesWithHistory.names0 terms types where
terms = Rel.mapRan Referent.Ref (Rel.fromMap termNameRefs) <> terms = Rel.mapRan Referent.Ref (Rel.fromMap termNameRefs) <>
Rel.fromList [ (Name.fromVar vc, Referent.Con (R.DerivedId r) cid ct) Rel.fromList [ (Name.fromVar vc, Referent.Con (R.DerivedId r) cid ct)

View File

@ -9,7 +9,7 @@ module Unison.Codebase.Branch.Names
findHistoricalRefs, findHistoricalRefs,
findHistoricalRefs', findHistoricalRefs',
namesDiff, namesDiff,
toUnqualifiedNames, toNames,
) )
where where
@ -21,7 +21,7 @@ import qualified Unison.HashQualified as HQ
import Unison.LabeledDependency (LabeledDependency) import Unison.LabeledDependency (LabeledDependency)
import qualified Unison.LabeledDependency as LD import qualified Unison.LabeledDependency as LD
import Unison.Name (Name (..)) import Unison.Name (Name (..))
import Unison.Names (Names' (Names), UnqualifiedNames) import Unison.Names (Names' (Names), Names)
import qualified Unison.Names as Names import qualified Unison.Names as Names
import qualified Unison.NamesWithHistory as Names import qualified Unison.NamesWithHistory as Names
import Unison.Prelude hiding (empty) import Unison.Prelude hiding (empty)
@ -31,8 +31,8 @@ import qualified Unison.Referent as Referent
import qualified Unison.Util.Relation as R import qualified Unison.Util.Relation as R
import Prelude hiding (head, read, subtract) import Prelude hiding (head, read, subtract)
toUnqualifiedNames :: Branch0 m -> UnqualifiedNames toNames :: Branch0 m -> Names
toUnqualifiedNames b = Names (R.swap . deepTerms $ b) toNames b = Names (R.swap . deepTerms $ b)
(R.swap . deepTypes $ b) (R.swap . deepTypes $ b)
-- This stops searching for a given HashQualified once it encounters -- This stops searching for a given HashQualified once it encounters
@ -40,19 +40,19 @@ toUnqualifiedNames b = Names (R.swap . deepTerms $ b)
findHistoricalHQs :: Monad m findHistoricalHQs :: Monad m
=> Set (HashQualified Name) => Set (HashQualified Name)
-> Branch m -> Branch m
-> m (Set (HashQualified Name), UnqualifiedNames) -> m (Set (HashQualified Name), Names)
findHistoricalHQs = findInHistory findHistoricalHQs = findInHistory
(\hq r n -> HQ.matchesNamedReferent n r hq) (\hq r n -> HQ.matchesNamedReferent n r hq)
(\hq r n -> HQ.matchesNamedReference n r hq) (\hq r n -> HQ.matchesNamedReference n r hq)
findHistoricalRefs :: Monad m => Set LabeledDependency -> Branch m findHistoricalRefs :: Monad m => Set LabeledDependency -> Branch m
-> m (Set LabeledDependency, UnqualifiedNames) -> m (Set LabeledDependency, Names)
findHistoricalRefs = findInHistory findHistoricalRefs = findInHistory
(\query r _n -> LD.fold (const False) (==r) query) (\query r _n -> LD.fold (const False) (==r) query)
(\query r _n -> LD.fold (==r) (const False) query) (\query r _n -> LD.fold (==r) (const False) query)
findHistoricalRefs' :: Monad m => Set Reference -> Branch m findHistoricalRefs' :: Monad m => Set Reference -> Branch m
-> m (Set Reference, UnqualifiedNames) -> m (Set Reference, Names)
findHistoricalRefs' = findInHistory findHistoricalRefs' = findInHistory
(\queryRef r _n -> r == Referent.Ref queryRef) (\queryRef r _n -> r == Referent.Ref queryRef)
(\queryRef r _n -> r == queryRef) (\queryRef r _n -> r == queryRef)
@ -60,7 +60,7 @@ findHistoricalRefs' = findInHistory
findInHistory :: forall m q. (Monad m, Ord q) findInHistory :: forall m q. (Monad m, Ord q)
=> (q -> Referent -> Name -> Bool) => (q -> Referent -> Name -> Bool)
-> (q -> Reference -> Name -> Bool) -> (q -> Reference -> Name -> Bool)
-> Set q -> Branch m -> m (Set q, UnqualifiedNames) -> Set q -> Branch m -> m (Set q, Names)
findInHistory termMatches typeMatches queries b = findInHistory termMatches typeMatches queries b =
(Causal.foldHistoryUntil f (queries, mempty) . _history) b <&> \case (Causal.foldHistoryUntil f (queries, mempty) . _history) b <&> \case
-- could do something more sophisticated here later to report that some SH -- could do something more sophisticated here later to report that some SH
@ -76,7 +76,7 @@ findInHistory termMatches typeMatches queries b =
f acc@(remainingQueries, _) b0 = (acc', null remainingQueries') f acc@(remainingQueries, _) b0 = (acc', null remainingQueries')
where where
acc'@(remainingQueries', _) = foldl' findQ acc remainingQueries acc'@(remainingQueries', _) = foldl' findQ acc remainingQueries
findQ :: (Set q, UnqualifiedNames) -> q -> (Set q, UnqualifiedNames) findQ :: (Set q, Names) -> q -> (Set q, Names)
findQ acc sh = findQ acc sh =
foldl' (doType sh) (foldl' (doTerm sh) acc foldl' (doType sh) (foldl' (doTerm sh) acc
(R.toList $ deepTerms b0)) (R.toList $ deepTerms b0))
@ -87,4 +87,4 @@ findInHistory termMatches typeMatches queries b =
then (Set.delete q remainingSHs, Names.addType n r names0) else acc then (Set.delete q remainingSHs, Names.addType n r names0) else acc
namesDiff :: Branch m -> Branch m -> Names.Diff namesDiff :: Branch m -> Branch m -> Names.Diff
namesDiff b1 b2 = Names.diff0 (toUnqualifiedNames (head b1)) (toUnqualifiedNames (head b2)) namesDiff b1 b2 = Names.diff0 (toNames (head b1)) (toNames (head b2))

View File

@ -9,7 +9,7 @@ import qualified Unison.Codebase.Path as Path
import qualified Unison.Codebase.Branch as Branch import qualified Unison.Codebase.Branch as Branch
import Unison.Codebase.Branch (Branch, Branch0) import Unison.Codebase.Branch (Branch, Branch0)
import qualified Unison.Names as Names import qualified Unison.Names as Names
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
import qualified Unison.Referent as Referent import qualified Unison.Referent as Referent
import qualified Unison.Reference as Reference import qualified Unison.Reference as Reference
import Unison.Referent (Referent) import Unison.Referent (Referent)
@ -27,18 +27,18 @@ import Unison.Codebase.Patch (Patch)
import Unison.NameSegment (NameSegment) import Unison.NameSegment (NameSegment)
import Control.Lens (view) import Control.Lens (view)
fromUnqualifiedNames :: Monad m => UnqualifiedNames -> Branch m fromNames :: Monad m => Names -> Branch m
fromUnqualifiedNames names0 = Branch.one $ addFromUnqualifiedNames names0 Branch.empty0 fromNames names0 = Branch.one $ addFromNames names0 Branch.empty0
-- can produce a pure value because there's no history to traverse -- can produce a pure value because there's no history to traverse
hashesFromUnqualifiedNames :: Monad m => UnqualifiedNames -> Map Branch.Hash (Branch m) hashesFromNames :: Monad m => Names -> Map Branch.Hash (Branch m)
hashesFromUnqualifiedNames = deepHashes . fromUnqualifiedNames where hashesFromNames = deepHashes . fromNames where
deepHashes :: Branch m -> Map Branch.Hash (Branch m) deepHashes :: Branch m -> Map Branch.Hash (Branch m)
deepHashes b = Map.singleton (Branch.headHash b) b deepHashes b = Map.singleton (Branch.headHash b) b
<> (foldMap deepHashes . view Branch.children . Branch.head) b <> (foldMap deepHashes . view Branch.children . Branch.head) b
addFromUnqualifiedNames :: Monad m => UnqualifiedNames -> Branch0 m -> Branch0 m addFromNames :: Monad m => Names -> Branch0 m -> Branch0 m
addFromUnqualifiedNames names0 = Branch.stepManyAt0 (typeActions <> termActions) addFromNames names0 = Branch.stepManyAt0 (typeActions <> termActions)
where where
typeActions = map doType . R.toList $ Names.types names0 typeActions = map doType . R.toList $ Names.types names0
termActions = map doTerm . R.toList $ Names.terms names0 termActions = map doTerm . R.toList $ Names.terms names0

View File

@ -35,7 +35,7 @@ import qualified Unison.Codebase.Branch.Merge as Branch
import qualified Unison.Codebase.Reflog as Reflog import qualified Unison.Codebase.Reflog as Reflog
import Unison.Codebase.SyncMode ( SyncMode ) import Unison.Codebase.SyncMode ( SyncMode )
import Unison.NamesWithHistory ( NamesWithHistory ) import Unison.NamesWithHistory ( NamesWithHistory )
import Unison.Names ( UnqualifiedNames ) import Unison.Names ( Names )
import Unison.Parser.Ann (Ann) import Unison.Parser.Ann (Ann)
import Unison.Referent ( Referent ) import Unison.Referent ( Referent )
import Unison.Reference ( Reference ) import Unison.Reference ( Reference )
@ -75,7 +75,7 @@ data LoadSourceResult = InvalidSourceNameError
type TypecheckingResult v = type TypecheckingResult v =
Result (Seq (Note v Ann)) Result (Seq (Note v Ann))
(Either UnqualifiedNames (UF.TypecheckedUnisonFile v Ann)) (Either Names (UF.TypecheckedUnisonFile v Ann))
data Command m i v a where data Command m i v a where
-- Escape hatch. -- Escape hatch.

View File

@ -86,7 +86,7 @@ import qualified Unison.HashQualified' as HQ'
import qualified Unison.Name as Name import qualified Unison.Name as Name
import Unison.Name ( Name ) import Unison.Name ( Name )
import Unison.NamesWithHistory ( NamesWithHistory(..) ) import Unison.NamesWithHistory ( NamesWithHistory(..) )
import Unison.Names (UnqualifiedNames, pattern UnqualifiedNames ) import Unison.Names (Names, pattern Names )
import qualified Unison.Names as Names import qualified Unison.Names as Names
import qualified Unison.NamesWithHistory as NamesWithHistory import qualified Unison.NamesWithHistory as NamesWithHistory
import Unison.Parser.Ann (Ann(..)) import Unison.Parser.Ann (Ann(..))
@ -242,8 +242,8 @@ loop = do
getHQ'Types :: Path.HQSplit' -> Set Reference getHQ'Types :: Path.HQSplit' -> Set Reference
getHQ'Types p = BranchUtil.getType (resolveSplit' p) root0 getHQ'Types p = BranchUtil.getType (resolveSplit' p) root0
basicPrettyPrintUnqualifiedNames = basicPrettyPrintNames =
Backend.basicPrettyPrintUnqualifiedNames root' (Path.unabsolute currentPath') Backend.basicPrettyPrintNames root' (Path.unabsolute currentPath')
resolveHHQS'Types :: HashOrHQSplit' -> Action' m v (Set Reference) resolveHHQS'Types :: HashOrHQSplit' -> Action' m v (Set Reference)
resolveHHQS'Types = either resolveHHQS'Types = either
@ -296,7 +296,7 @@ loop = do
loadUnisonFile sourceName text = do loadUnisonFile sourceName text = do
let lexed = L.lexer (Text.unpack sourceName) (Text.unpack text) let lexed = L.lexer (Text.unpack sourceName) (Text.unpack text)
withFile [] sourceName (text, lexed) $ \unisonFile -> do withFile [] sourceName (text, lexed) $ \unisonFile -> do
sr <- toSlurpResult currentPath' unisonFile <$> slurpResultUnqualifiedNames sr <- toSlurpResult currentPath' unisonFile <$> slurpResultNames
names <- displayNames unisonFile names <- displayNames unisonFile
pped <- prettyPrintEnvDecl names pped <- prettyPrintEnvDecl names
let ppe = PPE.suffixifiedPPE pped let ppe = PPE.suffixifiedPPE pped
@ -616,12 +616,12 @@ loop = do
where where
resolvedPath = resolveSplit' (HQ'.toName <$> hq) resolvedPath = resolveSplit' (HQ'.toName <$> hq)
goMany tms tys = do goMany tms tys = do
let rootNames = Branch.toUnqualifiedNames root0 let rootNames = Branch.toNames root0
name = Path.toName (Path.unsplit resolvedPath) name = Path.toName (Path.unsplit resolvedPath)
toRel :: Ord ref => Set ref -> R.Relation Name ref toRel :: Ord ref => Set ref -> R.Relation Name ref
toRel = R.fromList . fmap (name,) . toList toRel = R.fromList . fmap (name,) . toList
-- these names are relative to the root -- these names are relative to the root
toDelete = UnqualifiedNames (toRel tms) (toRel tys) toDelete = Names (toRel tms) (toRel tys)
(failed, failedDependents) <- (failed, failedDependents) <-
getEndangeredDependents (eval . GetDependents) toDelete rootNames getEndangeredDependents (eval . GetDependents) toDelete rootNames
if failed == mempty then do if failed == mempty then do
@ -637,8 +637,8 @@ loop = do
uf <- use latestTypecheckedFile >>= addWatch (HQ.toString hq) uf <- use latestTypecheckedFile >>= addWatch (HQ.toString hq)
case uf of case uf of
Nothing -> do Nothing -> do
let parseUnqualifiedNames = (`NamesWithHistory.NamesWithHistory` mempty) basicPrettyPrintUnqualifiedNames let parseNames = (`NamesWithHistory.NamesWithHistory` mempty) basicPrettyPrintNames
results = NamesWithHistory.lookupHQTerm hq parseUnqualifiedNames results = NamesWithHistory.lookupHQTerm hq parseNames
if Set.null results then if Set.null results then
respond $ SearchTermsNotFound [hq] respond $ SearchTermsNotFound [hq]
else if Set.size results > 1 then else if Set.size results > 1 then
@ -646,11 +646,11 @@ loop = do
-- ... but use the unsuffixed names for display -- ... but use the unsuffixed names for display
else do else do
let tm = Term.fromReferent External $ Set.findMin results let tm = Term.fromReferent External $ Set.findMin results
pped <- prettyPrintEnvDecl parseUnqualifiedNames pped <- prettyPrintEnvDecl parseNames
tm <- eval $ Evaluate1 (PPE.suffixifiedPPE pped) True tm tm <- eval $ Evaluate1 (PPE.suffixifiedPPE pped) True tm
case tm of case tm of
Left e -> respond (EvaluationFailure e) Left e -> respond (EvaluationFailure e)
Right tm -> doDisplay outputLoc parseUnqualifiedNames (Term.unannotate tm) Right tm -> doDisplay outputLoc parseNames (Term.unannotate tm)
Just (toDisplay, unisonFile) -> do Just (toDisplay, unisonFile) -> do
ppe <- executePPE unisonFile ppe <- executePPE unisonFile
unlessError' EvaluationFailure do unlessError' EvaluationFailure do
@ -853,10 +853,10 @@ loop = do
where where
go (Branch.head -> b) = do go (Branch.head -> b) = do
(failed, failedDependents) <- (failed, failedDependents) <-
let rootNames = Branch.toUnqualifiedNames root0 let rootNames = Branch.toNames root0
toDelete = Names.prefix0 toDelete = Names.prefix0
(Path.toName . Path.unsplit . resolveSplit' $ p) -- resolveSplit' incorporates currentPath (Path.toName . Path.unsplit . resolveSplit' $ p) -- resolveSplit' incorporates currentPath
(Branch.toUnqualifiedNames b) (Branch.toNames b)
in getEndangeredDependents (eval . GetDependents) toDelete rootNames in getEndangeredDependents (eval . GetDependents) toDelete rootNames
if failed == mempty then do if failed == mempty then do
stepAt $ BranchUtil.makeSetBranch (resolveSplit' p) Branch.empty stepAt $ BranchUtil.makeSetBranch (resolveSplit' p) Branch.empty
@ -1014,11 +1014,11 @@ loop = do
fixupOutput = fmap Path.toName . HQ'.toHQ . Path.unsplitHQ fixupOutput = fmap Path.toName . HQ'.toHQ . Path.unsplitHQ
NamesI thing -> do NamesI thing -> do
ns0 <- basicParseUnqualifiedNames ns0 <- basicParseNames
let ns = NamesWithHistory ns0 mempty let ns = NamesWithHistory ns0 mempty
terms = NamesWithHistory.lookupHQTerm thing ns terms = NamesWithHistory.lookupHQTerm thing ns
types = NamesWithHistory.lookupHQType thing ns types = NamesWithHistory.lookupHQType thing ns
printNames = NamesWithHistory basicPrettyPrintUnqualifiedNames mempty printNames = NamesWithHistory basicPrettyPrintNames mempty
terms' :: Set (Referent, Set (HQ'.HashQualified Name)) terms' :: Set (Referent, Set (HQ'.HashQualified Name))
terms' = Set.map go terms where terms' = Set.map go terms where
go r = (r, NamesWithHistory.termName hqLength r printNames) go r = (r, NamesWithHistory.termName hqLength r printNames)
@ -1060,7 +1060,7 @@ loop = do
dotDoc = hq <&> \n -> Name.joinDot n "doc" dotDoc = hq <&> \n -> Name.joinDot n "doc"
fileByName = do fileByName = do
ns <- maybe mempty UF.typecheckedToUnqualifiedNames <$> use latestTypecheckedFile ns <- maybe mempty UF.typecheckedToNames <$> use latestTypecheckedFile
fnames <- pure $ NamesWithHistory.NamesWithHistory ns mempty fnames <- pure $ NamesWithHistory.NamesWithHistory ns mempty
case NamesWithHistory.lookupHQTerm dotDoc fnames of case NamesWithHistory.lookupHQTerm dotDoc fnames of
s | Set.size s == 1 -> do s | Set.size s == 1 -> do
@ -1076,7 +1076,7 @@ loop = do
[] -> codebaseByName [] -> codebaseByName
[(_name, ref, _tm)] -> do [(_name, ref, _tm)] -> do
len <- eval BranchHashLength len <- eval BranchHashLength
let names = NamesWithHistory.NamesWithHistory basicPrettyPrintUnqualifiedNames mempty let names = NamesWithHistory.NamesWithHistory basicPrettyPrintNames mempty
let tm = Term.ref External ref let tm = Term.ref External ref
tm <- eval $ Evaluate1 (PPE.fromNames len names) True tm tm <- eval $ Evaluate1 (PPE.fromNames len names) True tm
case tm of case tm of
@ -1087,7 +1087,7 @@ loop = do
respond $ ListOfLinks ppe out respond $ ListOfLinks ppe out
codebaseByName = do codebaseByName = do
parseNames <- basicParseUnqualifiedNames parseNames <- basicParseNames
case NamesWithHistory.lookupHQTerm dotDoc (NamesWithHistory.NamesWithHistory parseNames mempty) of case NamesWithHistory.lookupHQTerm dotDoc (NamesWithHistory.NamesWithHistory parseNames mempty) of
s | Set.size s == 1 -> displayI ConsoleLocation dotDoc s | Set.size s == 1 -> displayI ConsoleLocation dotDoc
| Set.size s == 0 -> respond $ ListOfLinks mempty [] | Set.size s == 0 -> respond $ ListOfLinks mempty []
@ -1216,7 +1216,7 @@ loop = do
pathArgStr = show pathArg pathArgStr = show pathArg
SearchByNameI isVerbose _showAll ws -> do SearchByNameI isVerbose _showAll ws -> do
let prettyPrintUnqualifiedNames = basicPrettyPrintUnqualifiedNames let prettyPrintNames = basicPrettyPrintNames
unlessError do unlessError do
results <- case ws of results <- case ws of
-- no query, list everything -- no query, list everything
@ -1241,12 +1241,12 @@ loop = do
-- aliases to a single search result; in non-verbose mode, -- aliases to a single search result; in non-verbose mode,
-- a separate result may be shown for each alias -- a separate result may be shown for each alias
(if isVerbose then uniqueBy SR.toReferent else id) $ (if isVerbose then uniqueBy SR.toReferent else id) $
searchResultsFor prettyPrintUnqualifiedNames matches [] searchResultsFor prettyPrintNames matches []
pure . pure $ results pure . pure $ results
-- name query -- name query
(map HQ.unsafeFromString -> qs) -> do (map HQ.unsafeFromString -> qs) -> do
let ns = basicPrettyPrintUnqualifiedNames let ns = basicPrettyPrintNames
let srs = searchBranchScored ns fuzzyNameDistance qs let srs = searchBranchScored ns fuzzyNameDistance qs
pure $ uniqueBy SR.toReferent srs pure $ uniqueBy SR.toReferent srs
lift do lift do
@ -1383,7 +1383,7 @@ loop = do
sr <- Slurp.disallowUpdates sr <- Slurp.disallowUpdates
. applySelection hqs uf . applySelection hqs uf
. toSlurpResult currentPath' uf . toSlurpResult currentPath' uf
<$> slurpResultUnqualifiedNames <$> slurpResultNames
let adds = Slurp.adds sr let adds = Slurp.adds sr
when (Slurp.isNonempty sr) $ do when (Slurp.isNonempty sr) $ do
stepAtNoSync ( Path.unabsolute currentPath' stepAtNoSync ( Path.unabsolute currentPath'
@ -1399,7 +1399,7 @@ loop = do
sr <- Slurp.disallowUpdates sr <- Slurp.disallowUpdates
. applySelection hqs uf . applySelection hqs uf
. toSlurpResult currentPath' uf . toSlurpResult currentPath' uf
<$> slurpResultUnqualifiedNames <$> slurpResultNames
previewResponse sourceName sr uf previewResponse sourceName sr uf
_ -> respond NoUnisonFile _ -> respond NoUnisonFile
@ -1407,18 +1407,18 @@ loop = do
Nothing -> respond NoUnisonFile Nothing -> respond NoUnisonFile
Just uf -> do Just uf -> do
let patchPath = fromMaybe defaultPatchPath maybePatchPath let patchPath = fromMaybe defaultPatchPath maybePatchPath
slurpCheckUnqualifiedNames <- slurpResultUnqualifiedNames slurpCheckNames <- slurpResultNames
currentPathUnqualifiedNames <- currentPathUnqualifiedNames currentPathNames <- currentPathNames
let sr = applySelection hqs uf let sr = applySelection hqs uf
. toSlurpResult currentPath' uf . toSlurpResult currentPath' uf
$ slurpCheckUnqualifiedNames $ slurpCheckNames
addsAndUpdates = Slurp.updates sr <> Slurp.adds sr addsAndUpdates = Slurp.updates sr <> Slurp.adds sr
fileUnqualifiedNames = UF.typecheckedToUnqualifiedNames uf fileNames = UF.typecheckedToNames uf
-- todo: display some error if typeEdits or termEdits itself contains a loop -- todo: display some error if typeEdits or termEdits itself contains a loop
typeEdits :: Map Name (Reference, Reference) typeEdits :: Map Name (Reference, Reference)
typeEdits = Map.fromList $ map f (toList $ SC.types (updates sr)) where typeEdits = Map.fromList $ map f (toList $ SC.types (updates sr)) where
f v = case (toList (Names.typesNamed slurpCheckUnqualifiedNames n) f v = case (toList (Names.typesNamed slurpCheckNames n)
,toList (Names.typesNamed fileUnqualifiedNames n)) of ,toList (Names.typesNamed fileNames n)) of
([old],[new]) -> (n, (old, new)) ([old],[new]) -> (n, (old, new))
_ -> error $ "Expected unique matches for " _ -> error $ "Expected unique matches for "
++ Var.nameStr v ++ " but got: " ++ Var.nameStr v ++ " but got: "
@ -1429,8 +1429,8 @@ loop = do
hashTerms0 = (\(r, _wk, _tm, typ) -> (r, typ)) <$> UF.hashTerms uf hashTerms0 = (\(r, _wk, _tm, typ) -> (r, typ)) <$> UF.hashTerms uf
termEdits :: Map Name (Reference, Reference) termEdits :: Map Name (Reference, Reference)
termEdits = Map.fromList $ map g (toList $ SC.terms (updates sr)) where termEdits = Map.fromList $ map g (toList $ SC.terms (updates sr)) where
g v = case ( toList (Names.refTermsNamed slurpCheckUnqualifiedNames n) g v = case ( toList (Names.refTermsNamed slurpCheckNames n)
, toList (Names.refTermsNamed fileUnqualifiedNames n)) of , toList (Names.refTermsNamed fileNames n)) of
([old], [new]) -> (n, (old, new)) ([old], [new]) -> (n, (old, new))
_ -> error $ "Expected unique matches for " _ -> error $ "Expected unique matches for "
++ Var.nameStr v ++ " but got: " ++ Var.nameStr v ++ " but got: "
@ -1439,7 +1439,7 @@ loop = do
termDeprecations :: [(Name, Referent)] termDeprecations :: [(Name, Referent)]
termDeprecations = termDeprecations =
[ (n, r) | (oldTypeRef,_) <- Map.elems typeEdits [ (n, r) | (oldTypeRef,_) <- Map.elems typeEdits
, (n, r) <- NamesWithHistory.constructorsForType0 oldTypeRef currentPathUnqualifiedNames ] , (n, r) <- NamesWithHistory.constructorsForType0 oldTypeRef currentPathNames ]
ye'ol'Patch <- getPatchAt patchPath ye'ol'Patch <- getPatchAt patchPath
-- If `uf` updates a -> a', we want to replace all (a0 -> a) in patch -- If `uf` updates a -> a', we want to replace all (a0 -> a) in patch
@ -1503,7 +1503,7 @@ loop = do
(Just (sourceName, _), Just uf) -> do (Just (sourceName, _), Just uf) -> do
sr <- applySelection hqs uf sr <- applySelection hqs uf
. toSlurpResult currentPath' uf . toSlurpResult currentPath' uf
<$> slurpResultUnqualifiedNames <$> slurpResultNames
previewResponse sourceName sr uf previewResponse sourceName sr uf
_ -> respond NoUnisonFile _ -> respond NoUnisonFile
@ -1580,11 +1580,11 @@ loop = do
ExecuteI main -> addRunMain main uf >>= \case ExecuteI main -> addRunMain main uf >>= \case
NoTermWithThatName -> do NoTermWithThatName -> do
ppe <- suffixifiedPPE (NamesWithHistory.NamesWithHistory basicPrettyPrintUnqualifiedNames mempty) ppe <- suffixifiedPPE (NamesWithHistory.NamesWithHistory basicPrettyPrintNames mempty)
mainType <- eval RuntimeMain mainType <- eval RuntimeMain
respond $ NoMainFunction main ppe [mainType] respond $ NoMainFunction main ppe [mainType]
TermHasBadType ty -> do TermHasBadType ty -> do
ppe <- suffixifiedPPE (NamesWithHistory.NamesWithHistory basicPrettyPrintUnqualifiedNames mempty) ppe <- suffixifiedPPE (NamesWithHistory.NamesWithHistory basicPrettyPrintNames mempty)
mainType <- eval RuntimeMain mainType <- eval RuntimeMain
respond $ BadMainFunction main ty ppe [mainType] respond $ BadMainFunction main ty ppe [mainType]
RunMainSuccess unisonFile -> do RunMainSuccess unisonFile -> do
@ -1598,7 +1598,7 @@ loop = do
MakeStandaloneI output main -> do MakeStandaloneI output main -> do
mainType <- eval RuntimeMain mainType <- eval RuntimeMain
parseNames <- parseNames <-
flip NamesWithHistory.NamesWithHistory mempty <$> basicPrettyPrintUnqualifiedNamesA flip NamesWithHistory.NamesWithHistory mempty <$> basicPrettyPrintNamesA
ppe <- suffixifiedPPE parseNames ppe <- suffixifiedPPE parseNames
let resolved = toList $ NamesWithHistory.lookupHQTerm main parseNames let resolved = toList $ NamesWithHistory.lookupHQTerm main parseNames
smain = HQ.toString main smain = HQ.toString main
@ -1617,7 +1617,7 @@ loop = do
IOTestI main -> do IOTestI main -> do
-- todo - allow this to run tests from scratch file, using addRunMain -- todo - allow this to run tests from scratch file, using addRunMain
testType <- eval RuntimeTest testType <- eval RuntimeTest
parseNames <- (`NamesWithHistory.NamesWithHistory` mempty) <$> basicPrettyPrintUnqualifiedNamesA parseNames <- (`NamesWithHistory.NamesWithHistory` mempty) <$> basicPrettyPrintNamesA
ppe <- suffixifiedPPE parseNames ppe <- suffixifiedPPE parseNames
-- use suffixed names for resolving the argument to display -- use suffixed names for resolving the argument to display
let let
@ -1663,7 +1663,7 @@ loop = do
eval $ AddDefsToCodebase uf eval $ AddDefsToCodebase uf
-- add the names; note, there are more names than definitions -- add the names; note, there are more names than definitions
-- due to builtin terms; so we don't just reuse `uf` above. -- due to builtin terms; so we don't just reuse `uf` above.
let srcb = BranchUtil.fromUnqualifiedNames Builtin.names0 let srcb = BranchUtil.fromNames Builtin.names0
_ <- updateAtM (currentPath' `snoc` "builtin") $ \destb -> _ <- updateAtM (currentPath' `snoc` "builtin") $ \destb ->
eval $ Merge Branch.RegularMerge srcb destb eval $ Merge Branch.RegularMerge srcb destb
success success
@ -1682,8 +1682,8 @@ loop = do
-- add the names; note, there are more names than definitions -- add the names; note, there are more names than definitions
-- due to builtin terms; so we don't just reuse `uf` above. -- due to builtin terms; so we don't just reuse `uf` above.
let names0 = Builtin.names0 let names0 = Builtin.names0
<> UF.typecheckedToUnqualifiedNames @v IOSource.typecheckedFile' <> UF.typecheckedToNames @v IOSource.typecheckedFile'
let srcb = BranchUtil.fromUnqualifiedNames names0 let srcb = BranchUtil.fromNames names0
_ <- updateAtM (currentPath' `snoc` "builtin") $ \destb -> _ <- updateAtM (currentPath' `snoc` "builtin") $ \destb ->
eval $ Merge Branch.RegularMerge srcb destb eval $ Merge Branch.RegularMerge srcb destb
@ -1884,7 +1884,7 @@ loop = do
resolveHQToLabeledDependencies :: Functor m => HQ.HashQualified Name -> Action' m v (Set LabeledDependency) resolveHQToLabeledDependencies :: Functor m => HQ.HashQualified Name -> Action' m v (Set LabeledDependency)
resolveHQToLabeledDependencies = \case resolveHQToLabeledDependencies = \case
HQ.NameOnly n -> do HQ.NameOnly n -> do
parseNames <- basicParseUnqualifiedNames parseNames <- basicParseNames
let terms, types :: Set LabeledDependency let terms, types :: Set LabeledDependency
terms = Set.map LD.referent . Name.searchBySuffix n $ NamesWithHistory.terms0 parseNames terms = Set.map LD.referent . Name.searchBySuffix n $ NamesWithHistory.terms0 parseNames
types = Set.map LD.typeRef . Name.searchBySuffix n $ NamesWithHistory.types0 parseNames types = Set.map LD.typeRef . Name.searchBySuffix n $ NamesWithHistory.types0 parseNames
@ -1988,7 +1988,7 @@ propagatePatchNoSync
-> Action' m v Bool -> Action' m v Bool
propagatePatchNoSync patch scopePath = do propagatePatchNoSync patch scopePath = do
r <- use root r <- use root
let nroot = Branch.toUnqualifiedNames (Branch.head r) let nroot = Branch.toNames (Branch.head r)
stepAtMNoSync' (Path.unabsolute scopePath, stepAtMNoSync' (Path.unabsolute scopePath,
lift . lift . Propagate.propagateAndApply nroot patch) lift . lift . Propagate.propagateAndApply nroot patch)
@ -1997,7 +1997,7 @@ propagatePatch :: (Monad m, Var v) =>
InputDescription -> Patch -> Path.Absolute -> Action' m v Bool InputDescription -> Patch -> Path.Absolute -> Action' m v Bool
propagatePatch inputDescription patch scopePath = do propagatePatch inputDescription patch scopePath = do
r <- use root r <- use root
let nroot = Branch.toUnqualifiedNames (Branch.head r) let nroot = Branch.toNames (Branch.head r)
stepAtM' (inputDescription <> " (applying patch)") stepAtM' (inputDescription <> " (applying patch)")
(Path.unabsolute scopePath, (Path.unabsolute scopePath,
lift . lift . Propagate.propagateAndApply nroot patch) lift . lift . Propagate.propagateAndApply nroot patch)
@ -2006,7 +2006,7 @@ propagatePatch inputDescription patch scopePath = do
doShowTodoOutput :: Monad m => Patch -> Path.Absolute -> Action' m v () doShowTodoOutput :: Monad m => Patch -> Path.Absolute -> Action' m v ()
doShowTodoOutput patch scopePath = do doShowTodoOutput patch scopePath = do
scope <- getAt scopePath scope <- getAt scopePath
let names0 = Branch.toUnqualifiedNames (Branch.head scope) let names0 = Branch.toNames (Branch.head scope)
-- only needs the local references to check for obsolete defs -- only needs the local references to check for obsolete defs
let getPpe = do let getPpe = do
names <- makePrintNamesFromLabeled' (Patch.labeledDependencies patch) names <- makePrintNamesFromLabeled' (Patch.labeledDependencies patch)
@ -2019,7 +2019,7 @@ showTodoOutput
-- ^ Action that fetches the pretty print env. It's expensive because it -- ^ Action that fetches the pretty print env. It's expensive because it
-- involves looking up historical names, so only call it if necessary. -- involves looking up historical names, so only call it if necessary.
-> Patch -> Patch
-> UnqualifiedNames -> Names
-> Action' m v () -> Action' m v ()
showTodoOutput getPpe patch names0 = do showTodoOutput getPpe patch names0 = do
todo <- checkTodo patch names0 todo <- checkTodo patch names0
@ -2032,7 +2032,7 @@ showTodoOutput getPpe patch names0 = do
ppe <- getPpe ppe <- getPpe
respond $ TodoOutput ppe todo respond $ TodoOutput ppe todo
checkTodo :: Patch -> UnqualifiedNames -> Action m i v (TO.TodoOutput v Ann) checkTodo :: Patch -> Names -> Action m i v (TO.TodoOutput v Ann)
checkTodo patch names0 = do checkTodo patch names0 = do
f <- computeFrontier (eval . GetDependents) patch names0 f <- computeFrontier (eval . GetDependents) patch names0
let dirty = R.dom f let dirty = R.dom f
@ -2057,7 +2057,7 @@ checkTodo patch names0 = do
(Patch.conflicts patch) (Patch.conflicts patch)
where where
frontierTransitiveDependents :: frontierTransitiveDependents ::
Monad m => (Reference -> m (Set Reference)) -> UnqualifiedNames -> Set Reference -> m (Set Reference) Monad m => (Reference -> m (Set Reference)) -> Names -> Set Reference -> m (Set Reference)
frontierTransitiveDependents dependents names0 rs = do frontierTransitiveDependents dependents names0 rs = do
let branchDependents r = Set.filter (Names.contains names0) <$> dependents r let branchDependents r = Set.filter (Names.contains names0) <$> dependents r
tdeps <- transitiveClosure branchDependents rs tdeps <- transitiveClosure branchDependents rs
@ -2075,7 +2075,7 @@ checkTodo patch names0 = do
computeFrontier :: forall m . Monad m computeFrontier :: forall m . Monad m
=> (Reference -> m (Set Reference)) -- eg Codebase.dependents codebase => (Reference -> m (Set Reference)) -- eg Codebase.dependents codebase
-> Patch -> Patch
-> UnqualifiedNames -> Names
-> m (R.Relation Reference Reference) -> m (R.Relation Reference Reference)
computeFrontier getDependents patch names = let computeFrontier getDependents patch names = let
edited :: Set Reference edited :: Set Reference
@ -2099,7 +2099,7 @@ confirmedCommand i = do
pure $ Just i == i0 pure $ Just i == i0
listBranch :: Branch0 m -> [SearchResult] listBranch :: Branch0 m -> [SearchResult]
listBranch (Branch.toUnqualifiedNames -> b) = listBranch (Branch.toNames -> b) =
List.sortOn (\s -> (SR.name s, s)) (SR.fromNames b) List.sortOn (\s -> (SR.name s, s)) (SR.fromNames b)
-- | restores the full hash to these search results, for _numberedArgs purposes -- | restores the full hash to these search results, for _numberedArgs purposes
@ -2123,14 +2123,14 @@ _searchBranchPrefix b n = case Path.unsnoc (Path.fromName n) of
Just b -> SR.fromNames . Names.prefix0 n $ names0 Just b -> SR.fromNames . Names.prefix0 n $ names0
where where
lastName = Path.toName (Path.singleton last) lastName = Path.toName (Path.singleton last)
subnames = Branch.toUnqualifiedNames . Branch.head $ subnames = Branch.toNames . Branch.head $
Branch.getAt' (Path.singleton last) b Branch.getAt' (Path.singleton last) b
rootnames = rootnames =
Names.filter (== lastName) . Names.filter (== lastName) .
Branch.toUnqualifiedNames . set Branch.children mempty $ Branch.head b Branch.toNames . set Branch.children mempty $ Branch.head b
names0 = rootnames <> Names.prefix0 lastName subnames names0 = rootnames <> Names.prefix0 lastName subnames
searchResultsFor :: UnqualifiedNames -> [Referent] -> [Reference] -> [SearchResult] searchResultsFor :: Names -> [Referent] -> [Reference] -> [SearchResult]
searchResultsFor ns terms types = searchResultsFor ns terms types =
[ SR.termSearchResult ns name ref [ SR.termSearchResult ns name ref
| ref <- terms | ref <- terms
@ -2142,7 +2142,7 @@ searchResultsFor ns terms types =
] ]
searchBranchScored :: forall score. (Ord score) searchBranchScored :: forall score. (Ord score)
=> UnqualifiedNames => Names
-> (Name -> Name -> Maybe score) -> (Name -> Name -> Maybe score)
-> [HQ.HashQualified Name] -> [HQ.HashQualified Name]
-> [SearchResult] -> [SearchResult]
@ -2428,9 +2428,9 @@ zeroOneOrMore f zero one more = case toList f of
-- `toBeDeleted`), then complain by returning (Y, X). -- `toBeDeleted`), then complain by returning (Y, X).
getEndangeredDependents :: forall m. Monad m getEndangeredDependents :: forall m. Monad m
=> (Reference -> m (Set Reference)) => (Reference -> m (Set Reference))
-> UnqualifiedNames -> Names
-> UnqualifiedNames -> Names
-> m (UnqualifiedNames, UnqualifiedNames) -> m (Names, Names)
getEndangeredDependents getDependents toDelete root = do getEndangeredDependents getDependents toDelete root = do
let remaining = root `Names.difference` toDelete let remaining = root `Names.difference` toDelete
toDelete', remaining', extinct :: Set Reference toDelete', remaining', extinct :: Set Reference
@ -2467,14 +2467,14 @@ applySelection hqs file = \sr@SlurpResult{..} ->
, extraDefinitions = closed `SC.difference` selection , extraDefinitions = closed `SC.difference` selection
} }
where where
selectedUnqualifiedNames = selectedNames =
Names.filterByHQs (Set.fromList hqs) (UF.typecheckedToUnqualifiedNames file) Names.filterByHQs (Set.fromList hqs) (UF.typecheckedToNames file)
selection, closed :: SlurpComponent v selection, closed :: SlurpComponent v
selection = SlurpComponent selectedTypes selectedTerms selection = SlurpComponent selectedTypes selectedTerms
closed = SC.closeWithDependencies file selection closed = SC.closeWithDependencies file selection
selectedTypes, selectedTerms :: Set v selectedTypes, selectedTerms :: Set v
selectedTypes = Set.map var $ R.dom (Names.types selectedUnqualifiedNames) selectedTypes = Set.map var $ R.dom (Names.types selectedNames)
selectedTerms = Set.map var $ R.dom (Names.terms selectedUnqualifiedNames) selectedTerms = Set.map var $ R.dom (Names.terms selectedNames)
var :: Var v => Name -> v var :: Var v => Name -> v
var name = Var.named (Name.toText name) var name = Var.named (Name.toText name)
@ -2484,7 +2484,7 @@ toSlurpResult
. Var v . Var v
=> Path.Absolute => Path.Absolute
-> UF.TypecheckedUnisonFile v Ann -> UF.TypecheckedUnisonFile v Ann
-> UnqualifiedNames -> Names
-> SlurpResult v -> SlurpResult v
toSlurpResult currentPath uf existingNames = toSlurpResult currentPath uf existingNames =
Slurp.subtractComponent (conflicts <> ctorCollisions) $ SlurpResult Slurp.subtractComponent (conflicts <> ctorCollisions) $ SlurpResult
@ -2501,7 +2501,7 @@ toSlurpResult currentPath uf existingNames =
typeAliases typeAliases
mempty mempty
where where
fileUnqualifiedNames = UF.typecheckedToUnqualifiedNames uf fileNames = UF.typecheckedToNames uf
sc :: R.Relation Name Referent -> R.Relation Name Reference -> SlurpComponent v sc :: R.Relation Name Referent -> R.Relation Name Reference -> SlurpComponent v
sc terms types = SlurpComponent { terms = Set.map var (R.dom terms) sc terms types = SlurpComponent { terms = Set.map var (R.dom terms)
@ -2511,9 +2511,9 @@ toSlurpResult currentPath uf existingNames =
conflicts :: SlurpComponent v conflicts :: SlurpComponent v
conflicts = sc terms types where conflicts = sc terms types where
terms = R.filterDom (conflicted . Names.termsNamed existingNames) terms = R.filterDom (conflicted . Names.termsNamed existingNames)
(Names.terms fileUnqualifiedNames) (Names.terms fileNames)
types = R.filterDom (conflicted . Names.typesNamed existingNames) types = R.filterDom (conflicted . Names.typesNamed existingNames)
(Names.types fileUnqualifiedNames) (Names.types fileNames)
conflicted s = Set.size s > 1 conflicted s = Set.size s > 1
ctorCollisions :: SlurpComponent v ctorCollisions :: SlurpComponent v
@ -2525,7 +2525,7 @@ toSlurpResult currentPath uf existingNames =
termCtorCollisions :: Set v termCtorCollisions :: Set v
termCtorCollisions = Set.fromList termCtorCollisions = Set.fromList
[ var n [ var n
| (n, Referent.Ref{}) <- R.toList (Names.terms fileUnqualifiedNames) | (n, Referent.Ref{}) <- R.toList (Names.terms fileNames)
, [r@Referent.Con{}] <- [toList $ Names.termsNamed existingNames n] , [r@Referent.Con{}] <- [toList $ Names.termsNamed existingNames n]
-- ignore collisions w/ ctors of types being updated -- ignore collisions w/ ctors of types being updated
, Set.notMember (Referent.toReference r) typesToUpdate , Set.notMember (Referent.toReference r) typesToUpdate
@ -2535,7 +2535,7 @@ toSlurpResult currentPath uf existingNames =
typesToUpdate :: Set Reference typesToUpdate :: Set Reference
typesToUpdate = Set.fromList typesToUpdate = Set.fromList
[ r [ r
| (n, r') <- R.toList (Names.types fileUnqualifiedNames) | (n, r') <- R.toList (Names.types fileNames)
, r <- toList (Names.typesNamed existingNames n) , r <- toList (Names.typesNamed existingNames n)
, r /= r' , r /= r'
] ]
@ -2546,7 +2546,7 @@ toSlurpResult currentPath uf existingNames =
ctorTermCollisions :: Set v ctorTermCollisions :: Set v
ctorTermCollisions = Set.fromList ctorTermCollisions = Set.fromList
[ var n [ var n
| (n, Referent.Con{}) <- R.toList (Names.terms fileUnqualifiedNames) | (n, Referent.Con{}) <- R.toList (Names.terms fileNames)
, r <- toList $ Names.termsNamed existingNames n , r <- toList $ Names.termsNamed existingNames n
-- ignore collisions w/ ctors of types being updated -- ignore collisions w/ ctors of types being updated
, Set.notMember (Referent.toReference r) typesToUpdate , Set.notMember (Referent.toReference r) typesToUpdate
@ -2556,21 +2556,21 @@ toSlurpResult currentPath uf existingNames =
-- duplicate (n,r) if (n,r) exists in names0 -- duplicate (n,r) if (n,r) exists in names0
dups :: SlurpComponent v dups :: SlurpComponent v
dups = sc terms types where dups = sc terms types where
terms = R.intersection (Names.terms existingNames) (Names.terms fileUnqualifiedNames) terms = R.intersection (Names.terms existingNames) (Names.terms fileNames)
types = R.intersection (Names.types existingNames) (Names.types fileUnqualifiedNames) types = R.intersection (Names.types existingNames) (Names.types fileNames)
-- update (n,r) if (n,r' /= r) exists in existingNames and r, r' are Ref -- update (n,r) if (n,r' /= r) exists in existingNames and r, r' are Ref
updates :: SlurpComponent v updates :: SlurpComponent v
updates = SlurpComponent (Set.fromList types) (Set.fromList terms) where updates = SlurpComponent (Set.fromList types) (Set.fromList terms) where
terms = terms =
[ var n [ var n
| (n, r'@Referent.Ref{}) <- R.toList (Names.terms fileUnqualifiedNames) | (n, r'@Referent.Ref{}) <- R.toList (Names.terms fileNames)
, [r@Referent.Ref{}] <- [toList $ Names.termsNamed existingNames n] , [r@Referent.Ref{}] <- [toList $ Names.termsNamed existingNames n]
, r' /= r , r' /= r
] ]
types = types =
[ var n [ var n
| (n, r') <- R.toList (Names.types fileUnqualifiedNames) | (n, r') <- R.toList (Names.types fileNames)
, [r] <- [toList $ Names.typesNamed existingNames n] , [r] <- [toList $ Names.typesNamed existingNames n]
, r' /= r , r' /= r
] ]
@ -2602,18 +2602,18 @@ toSlurpResult currentPath uf existingNames =
termAliases :: Map v Slurp.Aliases termAliases :: Map v Slurp.Aliases
termAliases = buildAliases (Names.terms existingNames) termAliases = buildAliases (Names.terms existingNames)
(Names.terms fileUnqualifiedNames) (Names.terms fileNames)
(SC.terms dups) (SC.terms dups)
typeAliases :: Map v Slurp.Aliases typeAliases :: Map v Slurp.Aliases
typeAliases = buildAliases (R.mapRan Referent.Ref $ Names.types existingNames) typeAliases = buildAliases (R.mapRan Referent.Ref $ Names.types existingNames)
(R.mapRan Referent.Ref $ Names.types fileUnqualifiedNames) (R.mapRan Referent.Ref $ Names.types fileNames)
(SC.types dups) (SC.types dups)
-- (n,r) is in `adds` if n isn't in existingNames -- (n,r) is in `adds` if n isn't in existingNames
adds = sc terms types where adds = sc terms types where
terms = addTerms (Names.terms existingNames) (Names.terms fileUnqualifiedNames) terms = addTerms (Names.terms existingNames) (Names.terms fileNames)
types = addTypes (Names.types existingNames) (Names.types fileUnqualifiedNames) types = addTypes (Names.types existingNames) (Names.types fileNames)
addTerms existingNames = R.filter go where addTerms existingNames = R.filter go where
go (n, Referent.Ref{}) = (not . R.memberDom n) existingNames go (n, Referent.Ref{}) = (not . R.memberDom n) existingNames
go _ = False go _ = False
@ -2653,7 +2653,7 @@ doSlurpAdds slurp uf = Branch.stepManyAt0 (typeActions <> termActions)
typeActions = map doType . toList $ SC.types slurp typeActions = map doType . toList $ SC.types slurp
termActions = map doTerm . toList $ termActions = map doTerm . toList $
SC.terms slurp <> Slurp.constructorsFor (SC.types slurp) uf SC.terms slurp <> Slurp.constructorsFor (SC.types slurp) uf
names = UF.typecheckedToUnqualifiedNames uf names = UF.typecheckedToNames uf
tests = Set.fromList $ fst <$> UF.watchesOfKind WK.TestWatch (UF.discardTypes uf) tests = Set.fromList $ fst <$> UF.watchesOfKind WK.TestWatch (UF.discardTypes uf)
(isTestType, isTestValue) = isTest (isTestType, isTestValue) = isTest
md v = md v =
@ -2731,7 +2731,7 @@ loadDisplayInfo refs = do
-- e.g. if currentPath = .foo.bar -- e.g. if currentPath = .foo.bar
-- then name foo.bar.baz becomes baz -- then name foo.bar.baz becomes baz
-- name cat.dog becomes .cat.dog -- name cat.dog becomes .cat.dog
fixupNamesRelative :: Path.Absolute -> UnqualifiedNames -> UnqualifiedNames fixupNamesRelative :: Path.Absolute -> Names -> Names
fixupNamesRelative currentPath' = NamesWithHistory.map0 fixName where fixupNamesRelative currentPath' = NamesWithHistory.map0 fixName where
prefix = Path.toName (Path.unabsolute currentPath') prefix = Path.toName (Path.unabsolute currentPath')
fixName n = if currentPath' == Path.absoluteEmpty then n else fixName n = if currentPath' == Path.absoluteEmpty then n else
@ -2741,9 +2741,9 @@ makeHistoricalParsingNames ::
Monad m => Set (HQ.HashQualified Name) -> Action' m v NamesWithHistory Monad m => Set (HQ.HashQualified Name) -> Action' m v NamesWithHistory
makeHistoricalParsingNames lexedHQs = do makeHistoricalParsingNames lexedHQs = do
rawHistoricalNames <- findHistoricalHQs lexedHQs rawHistoricalNames <- findHistoricalHQs lexedHQs
basicUnqualifiedNames <- basicParseUnqualifiedNames basicNames <- basicParseNames
currentPath <- use currentPath currentPath <- use currentPath
pure $ NamesWithHistory basicUnqualifiedNames pure $ NamesWithHistory basicNames
(NamesWithHistory.makeAbsolute0 rawHistoricalNames <> (NamesWithHistory.makeAbsolute0 rawHistoricalNames <>
fixupNamesRelative currentPath rawHistoricalNames) fixupNamesRelative currentPath rawHistoricalNames)
@ -2783,7 +2783,7 @@ parseType :: (Monad m, Var v)
parseType input src = do parseType input src = do
-- `show Input` is the name of the "file" being lexed -- `show Input` is the name of the "file" being lexed
(names0, lexed) <- lexedSource (Text.pack $ show input) (Text.pack src) (names0, lexed) <- lexedSource (Text.pack $ show input) (Text.pack src)
parseNames <- basicParseUnqualifiedNames parseNames <- basicParseNames
let names = NamesWithHistory.push (NamesWithHistory.currentNames names0) let names = NamesWithHistory.push (NamesWithHistory.currentNames names0)
(NamesWithHistory.NamesWithHistory parseNames (NamesWithHistory.oldNames names0)) (NamesWithHistory.NamesWithHistory parseNames (NamesWithHistory.oldNames names0))
e <- eval $ ParseType names lexed e <- eval $ ParseType names lexed
@ -2795,7 +2795,7 @@ parseType input src = do
Right typ -> Right typ Right typ -> Right typ
makeShadowedPrintNamesFromLabeled makeShadowedPrintNamesFromLabeled
:: Monad m => Set LabeledDependency -> UnqualifiedNames -> Action' m v NamesWithHistory :: Monad m => Set LabeledDependency -> Names -> Action' m v NamesWithHistory
makeShadowedPrintNamesFromLabeled deps shadowing = makeShadowedPrintNamesFromLabeled deps shadowing =
NamesWithHistory.shadowing shadowing <$> makePrintNamesFromLabeled' deps NamesWithHistory.shadowing shadowing <$> makePrintNamesFromLabeled' deps
@ -2807,8 +2807,8 @@ makePrintNamesFromLabeled' deps = do
(_missing, rawHistoricalNames) <- eval . Eval $ Branch.findHistoricalRefs (_missing, rawHistoricalNames) <- eval . Eval $ Branch.findHistoricalRefs
deps deps
root root
basicUnqualifiedNames <- basicPrettyPrintUnqualifiedNamesA basicNames <- basicPrettyPrintNamesA
pure $ NamesWithHistory basicUnqualifiedNames (fixupNamesRelative currentPath rawHistoricalNames) pure $ NamesWithHistory basicNames (fixupNamesRelative currentPath rawHistoricalNames)
getTermsIncludingHistorical getTermsIncludingHistorical
:: Monad m => Path.HQSplit -> Branch0 m -> Action' m v (Set Referent) :: Monad m => Path.HQSplit -> Branch0 m -> Action' m v (Set Referent)
@ -2824,7 +2824,7 @@ getTermsIncludingHistorical (p, hq) b = case Set.toList refs of
-- discards inputs that aren't hashqualified; -- discards inputs that aren't hashqualified;
-- I'd enforce it with finer-grained types if we had them. -- I'd enforce it with finer-grained types if we had them.
findHistoricalHQs :: Monad m => Set (HQ.HashQualified Name) -> Action' m v UnqualifiedNames findHistoricalHQs :: Monad m => Set (HQ.HashQualified Name) -> Action' m v Names
findHistoricalHQs lexedHQs0 = do findHistoricalHQs lexedHQs0 = do
root <- use root root <- use root
currentPath <- use currentPath currentPath <- use currentPath
@ -2846,38 +2846,38 @@ findHistoricalHQs lexedHQs0 = do
(_missing, rawHistoricalNames) <- eval . Eval $ Branch.findHistoricalHQs lexedHQs root (_missing, rawHistoricalNames) <- eval . Eval $ Branch.findHistoricalHQs lexedHQs root
pure rawHistoricalNames pure rawHistoricalNames
basicPrettyPrintUnqualifiedNamesA :: Functor m => Action' m v UnqualifiedNames basicPrettyPrintNamesA :: Functor m => Action' m v Names
basicPrettyPrintUnqualifiedNamesA = snd <$> basicUnqualifiedNames' basicPrettyPrintNamesA = snd <$> basicNames'
makeShadowedPrintNamesFromHQ :: Monad m => Set (HQ.HashQualified Name) -> UnqualifiedNames -> Action' m v NamesWithHistory makeShadowedPrintNamesFromHQ :: Monad m => Set (HQ.HashQualified Name) -> Names -> Action' m v NamesWithHistory
makeShadowedPrintNamesFromHQ lexedHQs shadowing = do makeShadowedPrintNamesFromHQ lexedHQs shadowing = do
rawHistoricalNames <- findHistoricalHQs lexedHQs rawHistoricalNames <- findHistoricalHQs lexedHQs
basicUnqualifiedNames <- basicPrettyPrintUnqualifiedNamesA basicNames <- basicPrettyPrintNamesA
currentPath <- use currentPath currentPath <- use currentPath
-- The basic names go into "current", but are shadowed by "shadowing". -- The basic names go into "current", but are shadowed by "shadowing".
-- They go again into "historical" as a hack that makes them available HQ-ed. -- They go again into "historical" as a hack that makes them available HQ-ed.
pure $ pure $
NamesWithHistory.shadowing NamesWithHistory.shadowing
shadowing shadowing
(NamesWithHistory basicUnqualifiedNames (fixupNamesRelative currentPath rawHistoricalNames)) (NamesWithHistory basicNames (fixupNamesRelative currentPath rawHistoricalNames))
basicParseUnqualifiedNames, slurpResultUnqualifiedNames :: Functor m => Action' m v UnqualifiedNames basicParseNames, slurpResultNames :: Functor m => Action' m v Names
basicParseUnqualifiedNames = fst <$> basicUnqualifiedNames' basicParseNames = fst <$> basicNames'
-- we check the file against everything in the current path -- we check the file against everything in the current path
slurpResultUnqualifiedNames = currentPathUnqualifiedNames slurpResultNames = currentPathNames
currentPathUnqualifiedNames :: Functor m => Action' m v UnqualifiedNames currentPathNames :: Functor m => Action' m v Names
currentPathUnqualifiedNames = do currentPathNames = do
currentPath' <- use currentPath currentPath' <- use currentPath
currentBranch' <- getAt currentPath' currentBranch' <- getAt currentPath'
pure $ Branch.toUnqualifiedNames (Branch.head currentBranch') pure $ Branch.toNames (Branch.head currentBranch')
-- implementation detail of basicParseUnqualifiedNames and basicPrettyPrintUnqualifiedNames -- implementation detail of basicParseNames and basicPrettyPrintNames
basicUnqualifiedNames' :: Functor m => Action' m v (UnqualifiedNames, UnqualifiedNames) basicNames' :: Functor m => Action' m v (Names, Names)
basicUnqualifiedNames' = do basicNames' = do
root' <- use root root' <- use root
currentPath' <- use currentPath currentPath' <- use currentPath
pure $ Backend.basicUnqualifiedNames' root' (Path.unabsolute currentPath') pure $ Backend.basicNames' root' (Path.unabsolute currentPath')
data AddRunMainResult v data AddRunMainResult v
= NoTermWithThatName = NoTermWithThatName
@ -2921,11 +2921,11 @@ addRunMain
-> Maybe (TypecheckedUnisonFile v Ann) -> Maybe (TypecheckedUnisonFile v Ann)
-> Action' m v (AddRunMainResult v) -> Action' m v (AddRunMainResult v)
addRunMain mainName Nothing = do addRunMain mainName Nothing = do
parseUnqualifiedNames <- basicParseUnqualifiedNames parseNames <- basicParseNames
let loadTypeOfTerm ref = eval $ LoadTypeOfTerm ref let loadTypeOfTerm ref = eval $ LoadTypeOfTerm ref
mainType <- eval RuntimeMain mainType <- eval RuntimeMain
mainToFile <$> mainToFile <$>
MainTerm.getMainTerm loadTypeOfTerm parseUnqualifiedNames mainName mainType MainTerm.getMainTerm loadTypeOfTerm parseNames mainName mainType
where where
mainToFile (MainTerm.NotAFunctionName _) = NoTermWithThatName mainToFile (MainTerm.NotAFunctionName _) = NoTermWithThatName
mainToFile (MainTerm.NotFound _) = NoTermWithThatName mainToFile (MainTerm.NotFound _) = NoTermWithThatName
@ -2967,7 +2967,7 @@ displayNames unisonFile =
-- voodoo -- voodoo
makeShadowedPrintNamesFromLabeled makeShadowedPrintNamesFromLabeled
(UF.termSignatureExternalLabeledDependencies unisonFile) (UF.termSignatureExternalLabeledDependencies unisonFile)
(UF.typecheckedToUnqualifiedNames unisonFile) (UF.typecheckedToNames unisonFile)
diffHelper :: Monad m diffHelper :: Monad m
=> Branch0 m => Branch0 m
@ -2976,15 +2976,15 @@ diffHelper :: Monad m
diffHelper before after = do diffHelper before after = do
hqLength <- eval CodebaseHashLength hqLength <- eval CodebaseHashLength
diff <- eval . Eval $ BranchDiff.diff0 before after diff <- eval . Eval $ BranchDiff.diff0 before after
names0 <- basicPrettyPrintUnqualifiedNamesA names0 <- basicPrettyPrintNamesA
ppe <- PPE.suffixifiedPPE <$> prettyPrintEnvDecl (NamesWithHistory names0 mempty) ppe <- PPE.suffixifiedPPE <$> prettyPrintEnvDecl (NamesWithHistory names0 mempty)
(ppe,) <$> (ppe,) <$>
OBranchDiff.toOutput OBranchDiff.toOutput
loadTypeOfTerm loadTypeOfTerm
declOrBuiltin declOrBuiltin
hqLength hqLength
(Branch.toUnqualifiedNames before) (Branch.toNames before)
(Branch.toUnqualifiedNames after) (Branch.toNames after)
ppe ppe
diff diff

View File

@ -25,7 +25,7 @@ import Unison.Codebase.Path (Path')
import Unison.Codebase.Patch (Patch) import Unison.Codebase.Patch (Patch)
import Unison.Codebase.Type (GitError) import Unison.Codebase.Type (GitError)
import Unison.Name ( Name ) import Unison.Name ( Name )
import Unison.Names ( UnqualifiedNames ) import Unison.Names ( Names )
import Unison.Parser.Ann (Ann) import Unison.Parser.Ann (Ann)
import qualified Unison.Reference as Reference import qualified Unison.Reference as Reference
import Unison.Reference ( Reference ) import Unison.Reference ( Reference )
@ -133,7 +133,7 @@ data Output v
-- with whatever named definitions would not have any remaining names if -- with whatever named definitions would not have any remaining names if
-- the path is deleted. -- the path is deleted.
| DeleteBranchConfirmation | DeleteBranchConfirmation
[(Path', (UnqualifiedNames, [SearchResult' v Ann]))] [(Path', (Names, [SearchResult' v Ann]))]
-- CantDelete input couldntDelete becauseTheseStillReferenceThem -- CantDelete input couldntDelete becauseTheseStillReferenceThem
| CantDelete PPE.PrettyPrintEnv [SearchResult' v Ann] [SearchResult' v Ann] | CantDelete PPE.PrettyPrintEnv [SearchResult' v Ann] [SearchResult' v Ann]
| DeleteEverythingConfirmation | DeleteEverythingConfirmation

View File

@ -26,7 +26,7 @@ import qualified Unison.HashQualified as HQ
import qualified Unison.Referent as Referent import qualified Unison.Referent as Referent
import Unison.Referent (Referent) import Unison.Referent (Referent)
import qualified Unison.Names as Names import qualified Unison.Names as Names
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
import Unison.DataDeclaration (DeclOrBuiltin) import Unison.DataDeclaration (DeclOrBuiltin)
import Unison.Runtime.IOSource (isPropagatedValue) import Unison.Runtime.IOSource (isPropagatedValue)
@ -100,8 +100,8 @@ toOutput :: forall m v a
=> (Referent -> m (Maybe (Type v a))) => (Referent -> m (Maybe (Type v a)))
-> (Reference -> m (Maybe (DeclOrBuiltin v a))) -> (Reference -> m (Maybe (DeclOrBuiltin v a)))
-> Int -> Int
-> UnqualifiedNames -> Names
-> UnqualifiedNames -> Names
-> PPE.PrettyPrintEnv -> PPE.PrettyPrintEnv
-> BranchDiff.BranchDiff -> BranchDiff.BranchDiff
-> m (BranchDiffOutput v a) -> m (BranchDiffOutput v a)

View File

@ -24,7 +24,7 @@ import qualified Unison.Codebase.Patch as Patch
import Unison.DataDeclaration ( Decl ) import Unison.DataDeclaration ( Decl )
import qualified Unison.DataDeclaration as Decl import qualified Unison.DataDeclaration as Decl
import qualified Unison.Name as Name import qualified Unison.Name as Name
import Unison.Names ( UnqualifiedNames ) import Unison.Names ( Names )
import qualified Unison.Names as Names import qualified Unison.Names as Names
import Unison.Parser.Ann (Ann(..)) import Unison.Parser.Ann (Ann(..))
import Unison.Reference ( Reference(..) ) import Unison.Reference ( Reference(..) )
@ -74,7 +74,7 @@ noEdits = Edits mempty mempty mempty mempty mempty mempty mempty
propagateAndApply propagateAndApply
:: forall m i v :: forall m i v
. (Applicative m, Var v) . (Applicative m, Var v)
=> UnqualifiedNames => Names
-> Patch -> Patch
-> Branch0 m -> Branch0 m
-> F m i v (Branch0 m) -> F m i v (Branch0 m)
@ -142,7 +142,7 @@ propagateCtorMapping oldComponent newComponent = let
-- and if the number of constructors is 1, then the constructor names need not -- and if the number of constructors is 1, then the constructor names need not
-- be the same. -- be the same.
genInitialCtorMapping :: genInitialCtorMapping ::
forall v m i . Var v => UnqualifiedNames -> Map Reference Reference -> F m i v (Map Referent Referent) forall v m i . Var v => Names -> Map Reference Reference -> F m i v (Map Referent Referent)
genInitialCtorMapping rootNames initialTypeReplacements = do genInitialCtorMapping rootNames initialTypeReplacements = do
let mappings :: (Reference,Reference) -> _ (Map Referent Referent) let mappings :: (Reference,Reference) -> _ (Map Referent Referent)
mappings (old,new) = do mappings (old,new) = do
@ -226,7 +226,7 @@ debugMode = False
propagate propagate
:: forall m i v :: forall m i v
. (Applicative m, Var v) . (Applicative m, Var v)
=> UnqualifiedNames -- TODO: this argument can be removed once patches have term replacement => Names -- TODO: this argument can be removed once patches have term replacement
-- of type `Referent -> Referent` -- of type `Referent -> Referent`
-> Patch -> Patch
-> Branch0 m -> Branch0 m
@ -252,7 +252,7 @@ propagate rootNames patch b = case validatePatch patch of
in case toList rns of in case toList rns of
[] -> show r [] -> show r
n : _ -> show n n : _ -> show n
-- this could also become show r if we're removing the dependency on UnqualifiedNames -- this could also become show r if we're removing the dependency on Names
referentName r = case toList (Names.namesForReferent rootNames r) of referentName r = case toList (Names.namesForReferent rootNames r) of
[] -> Referent.toString r [] -> Referent.toString r
n : _ -> show n n : _ -> show n
@ -455,7 +455,7 @@ propagate rootNames patch b = case validatePatch patch of
(zip (view _1 . getReference <$> Graph.topSort graph) [0 ..]) (zip (view _1 . getReference <$> Graph.topSort graph) [0 ..])
-- vertex i precedes j whenever i has an edge to j and not vice versa. -- vertex i precedes j whenever i has an edge to j and not vice versa.
-- vertex i precedes j when j is a dependent of i. -- vertex i precedes j when j is a dependent of i.
names0 = Branch.toUnqualifiedNames b names0 = Branch.toNames b
validatePatch validatePatch
:: Patch -> Maybe (Map Reference TermEdit, Map Reference TypeEdit) :: Patch -> Maybe (Map Reference TermEdit, Map Reference TypeEdit)
validatePatch p = validatePatch p =
@ -634,7 +634,7 @@ computeFrontier
. Monad m . Monad m
=> (Reference -> m (Set Reference)) -- eg Codebase.dependents codebase => (Reference -> m (Set Reference)) -- eg Codebase.dependents codebase
-> Patch -> Patch
-> UnqualifiedNames -> Names
-> m (R.Relation Reference Reference) -> m (R.Relation Reference Reference)
computeFrontier getDependents patch names = do computeFrontier getDependents patch names = do
-- (r,r2) ∈ dependsOn if r depends on r2 -- (r,r2) ∈ dependsOn if r depends on r2

View File

@ -72,7 +72,7 @@ data SlurpResult v = SlurpResult {
-- Returns the set of constructor names for type names in the given `Set`. -- Returns the set of constructor names for type names in the given `Set`.
constructorsFor :: Var v => Set v -> UF.TypecheckedUnisonFile v Ann -> Set v constructorsFor :: Var v => Set v -> UF.TypecheckedUnisonFile v Ann -> Set v
constructorsFor types uf = let constructorsFor types uf = let
names = UF.typecheckedToUnqualifiedNames uf names = UF.typecheckedToNames uf
typesRefs = Set.unions $ Names.typesNamed names . Name.fromVar <$> toList types typesRefs = Set.unions $ Names.typesNamed names . Name.fromVar <$> toList types
ctorNames = R.filterRan isOkCtor (Names.terms names) ctorNames = R.filterRan isOkCtor (Names.terms names)
isOkCtor (Referent.Con r _ _) | Set.member r typesRefs = True isOkCtor (Referent.Con r _ _) | Set.member r typesRefs = True

View File

@ -10,7 +10,7 @@ import qualified Unison.Codebase.Patch as Patch
import qualified Data.Set as Set import qualified Data.Set as Set
import qualified Unison.DataDeclaration as DD import qualified Unison.DataDeclaration as DD
import Unison.Reference (Reference) import Unison.Reference (Reference)
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
import Unison.Codebase.Patch (Patch) import Unison.Codebase.Patch (Patch)
import Unison.Codebase.Editor.DisplayObject (DisplayObject(UserObject)) import Unison.Codebase.Editor.DisplayObject (DisplayObject(UserObject))
import Unison.Type (Type) import Unison.Type (Type)
@ -28,7 +28,7 @@ data TodoOutput v a = TodoOutput
, todoFrontierDependents :: , todoFrontierDependents ::
( [(Score, Reference, Maybe (Type v a))] ( [(Score, Reference, Maybe (Type v a))]
, [(Score, Reference, DisplayObject () (Decl v a))]) , [(Score, Reference, DisplayObject () (Decl v a))])
, nameConflicts :: UnqualifiedNames , nameConflicts :: Names
, editConflicts :: Patch , editConflicts :: Patch
} deriving (Show) } deriving (Show)

View File

@ -42,10 +42,10 @@ execute codebase runtime mainName =
die ("Couldn't load root branch " ++ show h) die ("Couldn't load root branch " ++ show h)
Left (Codebase.CouldntParseRootBranch h) -> Left (Codebase.CouldntParseRootBranch h) ->
die ("Couldn't parse root branch head " ++ show h) die ("Couldn't parse root branch head " ++ show h)
let parseUnqualifiedNames = NamesWithHistory.makeAbsolute0 (Branch.toUnqualifiedNames (Branch.head root)) let parseNames = NamesWithHistory.makeAbsolute0 (Branch.toNames (Branch.head root))
loadTypeOfTerm = Codebase.getTypeOfTerm codebase loadTypeOfTerm = Codebase.getTypeOfTerm codebase
let mainType = Runtime.mainType runtime let mainType = Runtime.mainType runtime
mt <- getMainTerm loadTypeOfTerm parseUnqualifiedNames mainName mainType mt <- getMainTerm loadTypeOfTerm parseNames mainName mainType
case mt of case mt of
MainTerm.NotAFunctionName s -> die ("Not a function name: " ++ s) MainTerm.NotAFunctionName s -> die ("Not a function name: " ++ s)
MainTerm.NotFound s -> die ("Not found: " ++ s) MainTerm.NotFound s -> die ("Not found: " ++ s)

View File

@ -33,15 +33,15 @@ data MainTerm v
getMainTerm getMainTerm
:: (Monad m, Var v) :: (Monad m, Var v)
=> (Reference -> m (Maybe (Type v Ann))) => (Reference -> m (Maybe (Type v Ann)))
-> Names.UnqualifiedNames -> Names.Names
-> String -> String
-> Type.Type v Ann -> Type.Type v Ann
-> m (MainTerm v) -> m (MainTerm v)
getMainTerm loadTypeOfTerm parseUnqualifiedNames mainName mainType = getMainTerm loadTypeOfTerm parseNames mainName mainType =
case HQ.fromString mainName of case HQ.fromString mainName of
Nothing -> pure (NotAFunctionName mainName) Nothing -> pure (NotAFunctionName mainName)
Just hq -> do Just hq -> do
let refs = NamesWithHistory.lookupHQTerm hq (NamesWithHistory.NamesWithHistory parseUnqualifiedNames mempty) let refs = NamesWithHistory.lookupHQTerm hq (NamesWithHistory.NamesWithHistory parseNames mempty)
let a = Parser.Ann.External let a = Parser.Ann.External
case toList refs of case toList refs of
[Referent.Ref ref] -> do [Referent.Ref ref] -> do

View File

@ -33,7 +33,7 @@ import qualified Unison.Codebase.Watch as Watch
import Unison.CommandLine.InputPattern (InputPattern (parse)) import Unison.CommandLine.InputPattern (InputPattern (parse))
import qualified Unison.HashQualified as HQ import qualified Unison.HashQualified as HQ
import qualified Unison.HashQualified' as HQ' import qualified Unison.HashQualified' as HQ'
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
import qualified Unison.Util.ColorText as CT import qualified Unison.Util.ColorText as CT
import qualified Unison.Util.Find as Find import qualified Unison.Util.Find as Find
import qualified Unison.Util.Pretty as P import qualified Unison.Util.Pretty as P
@ -156,7 +156,7 @@ prettyCompletion' (s, p) = Line.Completion s (P.toAnsiUnbroken p) False
prettyCompletion'' :: Bool -> (String, P.Pretty P.ColorText) -> Line.Completion prettyCompletion'' :: Bool -> (String, P.Pretty P.ColorText) -> Line.Completion
prettyCompletion'' spaceAtEnd (s, p) = Line.Completion s (P.toAnsiUnbroken p) spaceAtEnd prettyCompletion'' spaceAtEnd (s, p) = Line.Completion s (P.toAnsiUnbroken p) spaceAtEnd
fuzzyCompleteHashQualified :: UnqualifiedNames -> String -> [Line.Completion] fuzzyCompleteHashQualified :: Names -> String -> [Line.Completion]
fuzzyCompleteHashQualified b q0@(HQ'.fromString -> query) = case query of fuzzyCompleteHashQualified b q0@(HQ'.fromString -> query) = case query of
Nothing -> [] Nothing -> []
Just query -> Just query ->

View File

@ -1533,7 +1533,7 @@ typeCompletor :: Applicative m
-> Path.Absolute -> Path.Absolute
-> m [Completion] -> m [Completion]
typeCompletor filterQuery = pathCompletor filterQuery go where typeCompletor filterQuery = pathCompletor filterQuery go where
go = Set.map Name.toText . R.dom . Names.types . Branch.toUnqualifiedNames go = Set.map Name.toText . R.dom . Names.types . Branch.toNames
termCompletor :: Applicative m termCompletor :: Applicative m
=> (String -> [String] -> [Completion]) => (String -> [String] -> [Completion])
@ -1543,7 +1543,7 @@ termCompletor :: Applicative m
-> Path.Absolute -> Path.Absolute
-> m [Completion] -> m [Completion]
termCompletor filterQuery = pathCompletor filterQuery go where termCompletor filterQuery = pathCompletor filterQuery go where
go = Set.map Name.toText . R.dom . Names.types . Branch.toUnqualifiedNames go = Set.map Name.toText . R.dom . Names.types . Branch.toNames
patchArg :: ArgumentType patchArg :: ArgumentType
patchArg = ArgumentType "patch" $ pathCompletor patchArg = ArgumentType "patch" $ pathCompletor

View File

@ -71,7 +71,7 @@ import Unison.NamePrinter (prettyHashQualified,
prettyName, prettyShortHash, prettyName, prettyShortHash,
styleHashQualified, styleHashQualified,
styleHashQualified', prettyHashQualified') styleHashQualified', prettyHashQualified')
import Unison.Names (Names'(..), UnqualifiedNames) import Unison.Names (Names'(..), Names)
import qualified Unison.Names as Names import qualified Unison.Names as Names
import qualified Unison.NamesWithHistory as Names import qualified Unison.NamesWithHistory as Names
import Unison.Parser.Ann (Ann, startingLine) import Unison.Parser.Ann (Ann, startingLine)
@ -1382,7 +1382,7 @@ todoOutput ppe todo =
where where
-- If a conflict is both an edit and a name conflict, we show it in the edit -- If a conflict is both an edit and a name conflict, we show it in the edit
-- conflicts section -- conflicts section
c :: UnqualifiedNames c :: Names
c = removeEditConflicts (TO.editConflicts todo) (TO.nameConflicts todo) c = removeEditConflicts (TO.editConflicts todo) (TO.nameConflicts todo)
conflictedTypeNames = (R.dom . Names.types) c conflictedTypeNames = (R.dom . Names.types) c
conflictedTermNames = (R.dom . Names.terms) c conflictedTermNames = (R.dom . Names.terms) c

View File

@ -38,7 +38,7 @@ import qualified Unison.Util.List as List
import qualified Unison.Util.Relation as Rel import qualified Unison.Util.Relation as Rel
import Unison.Var (Var) import Unison.Var (Var)
import qualified Unison.Var as Var import qualified Unison.Var as Var
import Unison.Names(UnqualifiedNames) import Unison.Names(Names)
import qualified Unison.Names as Names import qualified Unison.Names as Names
type Term v = Term.Term v Ann type Term v = Term.Term v Ann
@ -69,7 +69,7 @@ parseAndSynthesizeFile
-> ResultT -> ResultT
(Seq (Note v Ann)) (Seq (Note v Ann))
m m
(Either UnqualifiedNames (UF.TypecheckedUnisonFile v Ann)) (Either Names (UF.TypecheckedUnisonFile v Ann))
parseAndSynthesizeFile ambient typeLookupf env filePath src = do parseAndSynthesizeFile ambient typeLookupf env filePath src = do
when debug $ traceM "parseAndSynthesizeFile" when debug $ traceM "parseAndSynthesizeFile"
uf <- Result.fromParsing $ Parsers.parseFile filePath (unpack src) env uf <- Result.fromParsing $ Parsers.parseFile filePath (unpack src) env
@ -83,7 +83,7 @@ type TDNRMap v = Map Typechecker.Name [Typechecker.NamedReference v Ann]
resolveNames resolveNames
:: (Var v, Monad m) :: (Var v, Monad m)
=> (Set Reference -> m (TL.TypeLookup v Ann)) => (Set Reference -> m (TL.TypeLookup v Ann))
-> Names.UnqualifiedNames -> Names.Names
-> UnisonFile v -> UnisonFile v
-> ResultT -> ResultT
(Seq (Note v Ann)) (Seq (Note v Ann))

View File

@ -1467,16 +1467,16 @@ prettyResolutionFailures s allFailures =
toAmbiguityPair :: Names.ResolutionFailure v annotation -> (v, Maybe (NESet String)) toAmbiguityPair :: Names.ResolutionFailure v annotation -> (v, Maybe (NESet String))
toAmbiguityPair = \case toAmbiguityPair = \case
(Names.TermResolutionFailure v _ (Names.Ambiguous names refs)) -> do (Names.TermResolutionFailure v _ (Names.Ambiguous names refs)) -> do
let ppe = ppeFromUnqualifiedNames names let ppe = ppeFromNames names
in (v, Just $ NES.map (showTermRef ppe) refs) in (v, Just $ NES.map (showTermRef ppe) refs)
(Names.TypeResolutionFailure v _ (Names.Ambiguous names refs)) -> do (Names.TypeResolutionFailure v _ (Names.Ambiguous names refs)) -> do
let ppe = ppeFromUnqualifiedNames names let ppe = ppeFromNames names
in (v, Just $ NES.map (showTypeRef ppe) refs) in (v, Just $ NES.map (showTypeRef ppe) refs)
(Names.TermResolutionFailure v _ Names.NotFound) -> (v, Nothing) (Names.TermResolutionFailure v _ Names.NotFound) -> (v, Nothing)
(Names.TypeResolutionFailure v _ Names.NotFound) -> (v, Nothing) (Names.TypeResolutionFailure v _ Names.NotFound) -> (v, Nothing)
ppeFromUnqualifiedNames :: Names.UnqualifiedNames -> PPE.PrettyPrintEnv ppeFromNames :: Names.Names -> PPE.PrettyPrintEnv
ppeFromUnqualifiedNames names0 = ppeFromNames names0 =
PPE.fromNames PPE.todoHashLength (NamesWithHistory.NamesWithHistory {currentNames = names0, oldNames = mempty}) PPE.fromNames PPE.todoHashLength (NamesWithHistory.NamesWithHistory {currentNames = names0, oldNames = mempty})
prettyRow :: (v, Maybe (NESet String)) -> [(Pretty ColorText, Pretty ColorText)] prettyRow :: (v, Maybe (NESet String)) -> [(Pretty ColorText, Pretty ColorText)]

View File

@ -57,7 +57,7 @@ import qualified Unison.NameSegment as NameSegment
import qualified Unison.Names as Names import qualified Unison.Names as Names
import Unison.NamesWithHistory ( NamesWithHistory (..) ) import Unison.NamesWithHistory ( NamesWithHistory (..) )
import qualified Unison.NamesWithHistory as NamesWithHistory import qualified Unison.NamesWithHistory as NamesWithHistory
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
import Unison.Parser.Ann (Ann) import Unison.Parser.Ann (Ann)
import Unison.Prelude import Unison.Prelude
import qualified Unison.PrettyPrintEnv as PPE import qualified Unison.PrettyPrintEnv as PPE
@ -121,42 +121,42 @@ data BackendError
type Backend m a = ExceptT BackendError m a type Backend m a = ExceptT BackendError m a
-- implementation detail of basicParseUnqualifiedNames and basicPrettyPrintUnqualifiedNames -- implementation detail of basicParseNames and basicPrettyPrintNames
basicUnqualifiedNames' :: Branch m -> Path -> (UnqualifiedNames, UnqualifiedNames) basicNames' :: Branch m -> Path -> (Names, Names)
basicUnqualifiedNames' root path = (parseUnqualifiedNames0, prettyPrintUnqualifiedNames0) basicNames' root path = (parseNames0, prettyPrintNames0)
where where
root0 = Branch.head root root0 = Branch.head root
currentBranch = fromMaybe Branch.empty $ Branch.getAt path root currentBranch = fromMaybe Branch.empty $ Branch.getAt path root
absoluteRootUnqualifiedNames = NamesWithHistory.makeAbsolute0 (Branch.toUnqualifiedNames root0) absoluteRootNames = NamesWithHistory.makeAbsolute0 (Branch.toNames root0)
currentBranch0 = Branch.head currentBranch currentBranch0 = Branch.head currentBranch
currentPathUnqualifiedNames = Branch.toUnqualifiedNames currentBranch0 currentPathNames = Branch.toNames currentBranch0
-- all names, but with local names in their relative form only, rather -- all names, but with local names in their relative form only, rather
-- than absolute; external names appear as absolute -- than absolute; external names appear as absolute
currentAndExternalUnqualifiedNames = currentAndExternalNames =
currentPathUnqualifiedNames currentPathNames
`NamesWithHistory.unionLeft0` absDot externalNames `NamesWithHistory.unionLeft0` absDot externalNames
where where
absDot = Names.prefix0 (Name.unsafeFromText "") absDot = Names.prefix0 (Name.unsafeFromText "")
externalNames = rootNames `Names.difference` pathPrefixed currentPathUnqualifiedNames externalNames = rootNames `Names.difference` pathPrefixed currentPathNames
rootNames = Branch.toUnqualifiedNames root0 rootNames = Branch.toNames root0
pathPrefixed = case path of pathPrefixed = case path of
Path.Path (toList -> []) -> const mempty Path.Path (toList -> []) -> const mempty
p -> Names.prefix0 (Path.toName p) p -> Names.prefix0 (Path.toName p)
-- parsing should respond to local and absolute names -- parsing should respond to local and absolute names
parseUnqualifiedNames0 = currentPathUnqualifiedNames <> absoluteRootUnqualifiedNames parseNames0 = currentPathNames <> absoluteRootNames
-- pretty-printing should use local names where available -- pretty-printing should use local names where available
prettyPrintUnqualifiedNames0 = currentAndExternalUnqualifiedNames prettyPrintNames0 = currentAndExternalNames
basicSuffixifiedNames :: Int -> Branch m -> Path -> PPE.PrettyPrintEnv basicSuffixifiedNames :: Int -> Branch m -> Path -> PPE.PrettyPrintEnv
basicSuffixifiedNames hashLength root path = basicSuffixifiedNames hashLength root path =
let names0 = basicPrettyPrintUnqualifiedNames root path let names0 = basicPrettyPrintNames root path
in PPE.suffixifiedPPE . PPE.fromNamesDecl hashLength $ NamesWithHistory names0 mempty in PPE.suffixifiedPPE . PPE.fromNamesDecl hashLength $ NamesWithHistory names0 mempty
basicPrettyPrintUnqualifiedNames :: Branch m -> Path -> UnqualifiedNames basicPrettyPrintNames :: Branch m -> Path -> Names
basicPrettyPrintUnqualifiedNames root = snd . basicUnqualifiedNames' root basicPrettyPrintNames root = snd . basicNames' root
basicParseUnqualifiedNames :: Branch m -> Path -> UnqualifiedNames basicParseNames :: Branch m -> Path -> Names
basicParseUnqualifiedNames root = fst . basicUnqualifiedNames' root basicParseNames root = fst . basicNames' root
loadReferentType :: loadReferentType ::
(Applicative m, Var v) => (Applicative m, Var v) =>
@ -220,7 +220,7 @@ fuzzyFind
fuzzyFind path branch query = fuzzyFind path branch query =
let let
printNames = printNames =
basicPrettyPrintUnqualifiedNames branch path basicPrettyPrintNames branch path
fzfNames = fzfNames =
Names.fuzzyFind (words query) printNames Names.fuzzyFind (words query) printNames
@ -440,15 +440,15 @@ termReferentsByShortHash codebase sh = do
B.intrinsicTermReferences B.intrinsicTermReferences
pure (fromBuiltins <> Set.map (fmap Reference.DerivedId) fromCodebase) pure (fromBuiltins <> Set.map (fmap Reference.DerivedId) fromCodebase)
-- currentPathUnqualifiedNames :: Path -> UnqualifiedNames -- currentPathNames :: Path -> Names
-- currentPathUnqualifiedNames = Branch.toUnqualifiedNames . Branch.head . Branch.getAt -- currentPathNames = Branch.toNames . Branch.head . Branch.getAt
getCurrentPrettyNames :: Path -> Branch m -> NamesWithHistory getCurrentPrettyNames :: Path -> Branch m -> NamesWithHistory
getCurrentPrettyNames path root = getCurrentPrettyNames path root =
NamesWithHistory (basicPrettyPrintUnqualifiedNames root path) mempty NamesWithHistory (basicPrettyPrintNames root path) mempty
getCurrentParseNames :: Path -> Branch m -> NamesWithHistory getCurrentParseNames :: Path -> Branch m -> NamesWithHistory
getCurrentParseNames path root = NamesWithHistory (basicParseUnqualifiedNames root path) mempty getCurrentParseNames path root = NamesWithHistory (basicParseNames root path) mempty
-- Any absolute names in the input which have `root` as a prefix -- Any absolute names in the input which have `root` as a prefix
-- are converted to names relative to current path. All other names are -- are converted to names relative to current path. All other names are
@ -457,7 +457,7 @@ getCurrentParseNames path root = NamesWithHistory (basicParseUnqualifiedNames ro
-- e.g. if currentPath = .foo.bar -- e.g. if currentPath = .foo.bar
-- then name foo.bar.baz becomes baz -- then name foo.bar.baz becomes baz
-- name cat.dog becomes .cat.dog -- name cat.dog becomes .cat.dog
fixupNamesRelative :: Path.Absolute -> UnqualifiedNames -> UnqualifiedNames fixupNamesRelative :: Path.Absolute -> Names -> Names
fixupNamesRelative root = NamesWithHistory.map0 fixName where fixupNamesRelative root = NamesWithHistory.map0 fixName where
prefix = Path.toName $ Path.unabsolute root prefix = Path.toName $ Path.unabsolute root
fixName n = if root == Path.absoluteEmpty fixName n = if root == Path.absoluteEmpty

View File

@ -6,7 +6,7 @@ import qualified Data.Set as Set
import Unison.HashQualified (HashQualified) import Unison.HashQualified (HashQualified)
import qualified Unison.HashQualified' as HQ' import qualified Unison.HashQualified' as HQ'
import Unison.Name (Name) import Unison.Name (Name)
import Unison.Names (Names'(Names), UnqualifiedNames) import Unison.Names (Names'(Names), Names)
import qualified Unison.Names as Names import qualified Unison.Names as Names
import Unison.Reference (Reference) import Unison.Reference (Reference)
import Unison.Referent (Referent) import Unison.Referent (Referent)
@ -35,7 +35,7 @@ termResult
:: HashQualified Name -> Referent -> Set (HQ'.HashQualified Name) -> SearchResult :: HashQualified Name -> Referent -> Set (HQ'.HashQualified Name) -> SearchResult
termResult hq r as = Tm (TermResult hq r as) termResult hq r as = Tm (TermResult hq r as)
termSearchResult :: UnqualifiedNames -> Name -> Referent -> SearchResult termSearchResult :: Names -> Name -> Referent -> SearchResult
termSearchResult b n r = termSearchResult b n r =
termResult (HQ'.toHQ (Names._hqTermName b n r)) r (Names._hqTermAliases b n r) termResult (HQ'.toHQ (Names._hqTermName b n r)) r (Names._hqTermAliases b n r)
@ -44,7 +44,7 @@ typeResult
:: HashQualified Name -> Reference -> Set (HQ'.HashQualified Name) -> SearchResult :: HashQualified Name -> Reference -> Set (HQ'.HashQualified Name) -> SearchResult
typeResult hq r as = Tp (TypeResult hq r as) typeResult hq r as = Tp (TypeResult hq r as)
typeSearchResult :: UnqualifiedNames -> Name -> Reference -> SearchResult typeSearchResult :: Names -> Name -> Reference -> SearchResult
typeSearchResult b n r = typeSearchResult b n r =
typeResult (HQ'.toHQ (Names._hqTypeName b n r)) r (Names._hqTypeAliases b n r) typeResult (HQ'.toHQ (Names._hqTypeName b n r)) r (Names._hqTypeAliases b n r)
@ -69,12 +69,12 @@ truncateAliases n = \case
Tp (TypeResult hq r as) -> typeResult hq r (Set.map (HQ'.take n) as) Tp (TypeResult hq r as) -> typeResult hq r (Set.map (HQ'.take n) as)
-- | You may want to sort this list differently afterward. -- | You may want to sort this list differently afterward.
fromNames :: UnqualifiedNames -> [SearchResult] fromNames :: Names -> [SearchResult]
fromNames b = fromNames b =
map (uncurry (typeSearchResult b)) (R.toList . Names.types $ b) <> map (uncurry (typeSearchResult b)) (R.toList . Names.types $ b) <>
map (uncurry (termSearchResult b)) (R.toList . Names.terms $ b) map (uncurry (termSearchResult b)) (R.toList . Names.terms $ b)
_fromNames :: UnqualifiedNames -> [SearchResult] _fromNames :: Names -> [SearchResult]
_fromNames n0@(Names terms types) = typeResults <> termResults where _fromNames n0@(Names terms types) = typeResults <> termResults where
typeResults = typeResults =
[ typeSearchResult n0 name r [ typeSearchResult n0 name r

View File

@ -12,7 +12,7 @@ import Unison.DataDeclaration (DataDeclaration)
import Unison.DataDeclaration (EffectDeclaration(..)) import Unison.DataDeclaration (EffectDeclaration(..))
import Unison.Reference (Reference) import Unison.Reference (Reference)
import qualified Unison.Reference as Reference import qualified Unison.Reference as Reference
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
data Env v a = Env data Env v a = Env
-- Data declaration name to hash and its fully resolved form -- Data declaration name to hash and its fully resolved form
@ -20,7 +20,7 @@ data Env v a = Env
-- Effect declaration name to hash and its fully resolved form -- Effect declaration name to hash and its fully resolved form
, effectsId :: Map v (Reference.Id, EffectDeclaration v a) , effectsId :: Map v (Reference.Id, EffectDeclaration v a)
-- Naming environment -- Naming environment
, names :: UnqualifiedNames , names :: Names
} }
datas :: Env v a -> Map v (Reference, DataDeclaration v a) datas :: Env v a -> Map v (Reference, DataDeclaration v a)

View File

@ -15,7 +15,7 @@ import qualified Unison.DataDeclaration.Names as DD.Names
import qualified Unison.Hashing.V2.Convert as Hashing import qualified Unison.Hashing.V2.Convert as Hashing
import qualified Unison.Name as Name import qualified Unison.Name as Name
import qualified Unison.Names.ResolutionResult as Names import qualified Unison.Names.ResolutionResult as Names
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
import qualified Unison.NamesWithHistory as Names import qualified Unison.NamesWithHistory as Names
import Unison.Prelude import Unison.Prelude
import qualified Unison.Reference as Reference import qualified Unison.Reference as Reference
@ -29,14 +29,14 @@ import qualified Unison.Util.Relation as Relation
import Unison.Var (Var) import Unison.Var (Var)
import qualified Unison.WatchKind as WK import qualified Unison.WatchKind as WK
toNames :: Var v => UnisonFile v a -> UnqualifiedNames toNames :: Var v => UnisonFile v a -> Names
toNames uf = datas <> effects toNames uf = datas <> effects
where where
datas = foldMap DD.Names.dataDeclToNames' (Map.toList (UF.dataDeclarationsId uf)) datas = foldMap DD.Names.dataDeclToNames' (Map.toList (UF.dataDeclarationsId uf))
effects = foldMap DD.Names.effectDeclToNames' (Map.toList (UF.effectDeclarationsId uf)) effects = foldMap DD.Names.effectDeclToNames' (Map.toList (UF.effectDeclarationsId uf))
typecheckedToUnqualifiedNames :: Var v => TypecheckedUnisonFile v a -> UnqualifiedNames typecheckedToNames :: Var v => TypecheckedUnisonFile v a -> Names
typecheckedToUnqualifiedNames uf = Names.names0 (terms <> ctors) types where typecheckedToNames uf = Names.names0 (terms <> ctors) types where
terms = Relation.fromList terms = Relation.fromList
[ (Name.fromVar v, Referent.Ref r) [ (Name.fromVar v, Referent.Ref r)
| (v, (r, wk, _, _)) <- Map.toList $ UF.hashTerms uf, wk == Nothing || wk == Just WK.TestWatch ] | (v, (r, wk, _, _)) <- Map.toList $ UF.hashTerms uf, wk == Nothing || wk == Just WK.TestWatch ]
@ -63,7 +63,7 @@ typecheckedUnisonFile0 = TypecheckedUnisonFileId Map.empty Map.empty mempty memp
-- we are done parsing, whereas `math.sqrt#abc` can be resolved immediately -- we are done parsing, whereas `math.sqrt#abc` can be resolved immediately
-- as it can't refer to a local definition. -- as it can't refer to a local definition.
bindNames :: Var v bindNames :: Var v
=> UnqualifiedNames => Names
-> UnisonFile v a -> UnisonFile v a
-> Names.ResolutionResult v a (UnisonFile v a) -> Names.ResolutionResult v a (UnisonFile v a)
bindNames names (UnisonFileId d e ts ws) = do bindNames names (UnisonFileId d e ts ws) = do
@ -85,7 +85,7 @@ bindNames names (UnisonFileId d e ts ws) = do
-- left. -- left.
environmentFor environmentFor
:: forall v a . Var v :: forall v a . Var v
=> UnqualifiedNames => Names
-> Map v (DataDeclaration v a) -> Map v (DataDeclaration v a)
-> Map v (EffectDeclaration v a) -> Map v (EffectDeclaration v a)
-> Names.ResolutionResult v a (Either [Error v a] (Env v a)) -> Names.ResolutionResult v a (Either [Error v a] (Env v a))

View File

@ -21,7 +21,7 @@ import qualified Unison.HashQualified' as HQ'
import qualified Unison.Name as Name import qualified Unison.Name as Name
import Unison.Name ( Name ) import Unison.Name ( Name )
import qualified Unison.Names as Names import qualified Unison.Names as Names
import Unison.Names ( UnqualifiedNames ) import Unison.Names ( Names )
import Unison.NamePrinter (prettyHashQualified) import Unison.NamePrinter (prettyHashQualified)
import qualified Unison.Reference as Reference import qualified Unison.Reference as Reference
import qualified Unison.Referent as Referent import qualified Unison.Referent as Referent
@ -114,7 +114,7 @@ fuzzyFindMatchArray query items render =
-- Ord MatchArray already provides a. and b. todo: c. -- Ord MatchArray already provides a. and b. todo: c.
prefixFindInBranch :: prefixFindInBranch ::
UnqualifiedNames -> HQ'.HashQualified Name -> [(SearchResult, P.Pretty P.ColorText)] Names -> HQ'.HashQualified Name -> [(SearchResult, P.Pretty P.ColorText)]
prefixFindInBranch b hq = fmap getName $ prefixFindInBranch b hq = fmap getName $
-- query string includes a name component, so do a prefix find on that -- query string includes a name component, so do a prefix find on that
filter (filterName (HQ'.toName hq)) (candidates b hq) filter (filterName (HQ'.toName hq)) (candidates b hq)
@ -127,7 +127,7 @@ prefixFindInBranch b hq = fmap getName $
-- only search before the # before the # and after the # after the # -- only search before the # before the # and after the # after the #
fuzzyFindInBranch :: HasCallStack fuzzyFindInBranch :: HasCallStack
=> UnqualifiedNames => Names
-> HQ'.HashQualified Name -> HQ'.HashQualified Name
-> [(SearchResult, P.Pretty P.ColorText)] -> [(SearchResult, P.Pretty P.ColorText)]
fuzzyFindInBranch b hq = fuzzyFindInBranch b hq =

View File

@ -18,7 +18,7 @@ import Unison.Result (Result, Note)
import Unison.Symbol (Symbol) import Unison.Symbol (Symbol)
import Unison.Var (Var) import Unison.Var (Var)
import Unison.UnisonFile (TypecheckedUnisonFile) import Unison.UnisonFile (TypecheckedUnisonFile)
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
import qualified Unison.ABT as ABT import qualified Unison.ABT as ABT
import qualified Unison.Lexer as L import qualified Unison.Lexer as L
import qualified Unison.Parser as Parser import qualified Unison.Parser as Parser
@ -63,7 +63,7 @@ parseAndSynthesizeAsFile
-> String -> String
-> Result -> Result
(Seq (Note v Ann)) (Seq (Note v Ann))
(Either UnqualifiedNames (TypecheckedUnisonFile v Ann)) (Either Names (TypecheckedUnisonFile v Ann))
parseAndSynthesizeAsFile ambient filename s = FP.parseAndSynthesizeFile parseAndSynthesizeAsFile ambient filename s = FP.parseAndSynthesizeFile
ambient ambient
(\_deps -> pure B.typeLookup) (\_deps -> pure B.typeLookup)

View File

@ -33,14 +33,14 @@ import Unison.Util.Monoid (intercalateMap)
import Unison.Util.Pretty (toPlain) import Unison.Util.Pretty (toPlain)
import qualified Unison.Test.Common as Common import qualified Unison.Test.Common as Common
import qualified Unison.NamesWithHistory as NamesWithHistory import qualified Unison.NamesWithHistory as NamesWithHistory
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
type Note = Result.Note Symbol Ann type Note = Result.Note Symbol Ann
type TFile = UF.TypecheckedUnisonFile Symbol Ann type TFile = UF.TypecheckedUnisonFile Symbol Ann
type SynthResult = type SynthResult =
Result (Seq Note) Result (Seq Note)
(Either UnqualifiedNames TFile) (Either Names TFile)
type EitherResult = Either String TFile type EitherResult = Either String TFile

View File

@ -21,14 +21,14 @@ import qualified Unison.Reference as Reference
import qualified Unison.Referent as Referent import qualified Unison.Referent as Referent
import qualified Unison.Type.Names as Type.Names import qualified Unison.Type.Names as Type.Names
import Unison.Var ( Var ) import Unison.Var ( Var )
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
import qualified Unison.NamesWithHistory as Names import qualified Unison.NamesWithHistory as Names
import qualified Unison.Names.ResolutionResult as Names import qualified Unison.Names.ResolutionResult as Names
import qualified Unison.ConstructorType as CT import qualified Unison.ConstructorType as CT
-- implementation of dataDeclToNames and effectDeclToNames -- implementation of dataDeclToNames and effectDeclToNames
toUnqualifiedNames :: Var v => CT.ConstructorType -> v -> Reference.Id -> DataDeclaration v a -> UnqualifiedNames toNames :: Var v => CT.ConstructorType -> v -> Reference.Id -> DataDeclaration v a -> Names
toUnqualifiedNames ct typeSymbol (Reference.DerivedId -> r) dd = toNames ct typeSymbol (Reference.DerivedId -> r) dd =
-- constructor names -- constructor names
foldMap names (DD.constructorVars dd `zip` [0 ..]) foldMap names (DD.constructorVars dd `zip` [0 ..])
-- name of the type itself -- name of the type itself
@ -37,21 +37,21 @@ toUnqualifiedNames ct typeSymbol (Reference.DerivedId -> r) dd =
names (ctor, i) = names (ctor, i) =
Names.names0 (Rel.singleton (Name.fromVar ctor) (Referent.Con r i ct)) mempty Names.names0 (Rel.singleton (Name.fromVar ctor) (Referent.Con r i ct)) mempty
dataDeclToNames :: Var v => v -> Reference.Id -> DataDeclaration v a -> UnqualifiedNames dataDeclToNames :: Var v => v -> Reference.Id -> DataDeclaration v a -> Names
dataDeclToNames = toUnqualifiedNames CT.Data dataDeclToNames = toNames CT.Data
effectDeclToNames :: Var v => v -> Reference.Id -> EffectDeclaration v a -> UnqualifiedNames effectDeclToNames :: Var v => v -> Reference.Id -> EffectDeclaration v a -> Names
effectDeclToNames typeSymbol r ed = toUnqualifiedNames CT.Effect typeSymbol r $ DD.toDataDecl ed effectDeclToNames typeSymbol r ed = toNames CT.Effect typeSymbol r $ DD.toDataDecl ed
dataDeclToNames' :: Var v => (v, (Reference.Id, DataDeclaration v a)) -> UnqualifiedNames dataDeclToNames' :: Var v => (v, (Reference.Id, DataDeclaration v a)) -> Names
dataDeclToNames' (v, (r,d)) = dataDeclToNames v r d dataDeclToNames' (v, (r,d)) = dataDeclToNames v r d
effectDeclToNames' :: Var v => (v, (Reference.Id, EffectDeclaration v a)) -> UnqualifiedNames effectDeclToNames' :: Var v => (v, (Reference.Id, EffectDeclaration v a)) -> Names
effectDeclToNames' (v, (r, d)) = effectDeclToNames v r d effectDeclToNames' (v, (r, d)) = effectDeclToNames v r d
bindNames :: Var v bindNames :: Var v
=> Set v => Set v
-> UnqualifiedNames -> Names
-> DataDeclaration v a -> DataDeclaration v a
-> Names.ResolutionResult v a (DataDeclaration v a) -> Names.ResolutionResult v a (DataDeclaration v a)
bindNames keepFree names (DataDeclaration m a bound constructors) = do bindNames keepFree names (DataDeclaration m a bound constructors) = do

View File

@ -5,9 +5,8 @@
{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE ViewPatterns #-}
module Unison.Names module Unison.Names
( UnqualifiedNames ( Names
, Names'(Names) , Names'(Names)
, pattern UnqualifiedNames
, addTerm , addTerm
, addType , addType
, allReferences , allReferences
@ -75,18 +74,13 @@ data Names' n = Names
, types :: Relation n Reference , types :: Relation n Reference
} deriving (Eq,Ord) } deriving (Eq,Ord)
type UnqualifiedNames = Names' Name type Names = Names' Name
pattern UnqualifiedNames :: Relation Name Referent
-> Relation Name Reference
-> UnqualifiedNames
pattern UnqualifiedNames terms types = Names terms types
-- Finds names that are supersequences of all the given strings, ordered by -- Finds names that are supersequences of all the given strings, ordered by
-- score and grouped by name. -- score and grouped by name.
fuzzyFind fuzzyFind
:: [String] :: [String]
-> UnqualifiedNames -> Names
-> [(FZF.Alignment, Name, Set (Either Referent Reference))] -> [(FZF.Alignment, Name, Set (Either Referent Reference))]
fuzzyFind query names = fuzzyFind query names =
fmap flatten fmap flatten
@ -262,7 +256,7 @@ hqName b n = \case
ambiguous = Set.size (termsNamed b n) + Set.size (typesNamed b n) > 1 ambiguous = Set.size (termsNamed b n) + Set.size (typesNamed b n) > 1
-- Conditionally apply hash qualifier to term name. -- Conditionally apply hash qualifier to term name.
-- Should be the same as the input name if the UnqualifiedNames is unconflicted. -- Should be the same as the input name if the Names is unconflicted.
hqTermName :: (Ord n, Alphabetical n) => Int -> Names' n -> n -> Referent -> HQ.HashQualified n hqTermName :: (Ord n, Alphabetical n) => Int -> Names' n -> n -> Referent -> HQ.HashQualified n
hqTermName hqLen b n r = if Set.size (termsNamed b n) > 1 hqTermName hqLen b n r = if Set.size (termsNamed b n) > 1
then hqTermName' hqLen n r then hqTermName' hqLen n r
@ -291,7 +285,7 @@ _hqTermAliases :: (Ord n, Alphabetical n) => Names' n -> n -> Referent -> Set (H
_hqTermAliases b n r = Set.map (flip (_hqTermName b) r) (termAliases b n r) _hqTermAliases b n r = Set.map (flip (_hqTermName b) r) (termAliases b n r)
-- Unconditionally apply hash qualifier long enough to distinguish all the -- Unconditionally apply hash qualifier long enough to distinguish all the
-- References in this UnqualifiedNames. -- References in this Names.
hqTermName' :: Int -> n -> Referent -> HQ.HashQualified n hqTermName' :: Int -> n -> Referent -> HQ.HashQualified n
hqTermName' hqLen n r = hqTermName' hqLen n r =
HQ.take hqLen $ HQ.fromNamedReferent n r HQ.take hqLen $ HQ.fromNamedReferent n r
@ -314,7 +308,7 @@ fromTerms ts = Names (R.fromList ts) mempty
fromTypes :: Ord n => [(n, Reference)] -> Names' n fromTypes :: Ord n => [(n, Reference)] -> Names' n
fromTypes ts = Names mempty (R.fromList ts) fromTypes ts = Names mempty (R.fromList ts)
prefix0 :: Name -> UnqualifiedNames -> UnqualifiedNames prefix0 :: Name -> Names -> Names
prefix0 n (Names terms types) = Names terms' types' where prefix0 n (Names terms types) = Names terms' types' where
terms' = R.mapDom (Name.joinDot n) terms terms' = R.mapDom (Name.joinDot n) terms
types' = R.mapDom (Name.joinDot n) types types' = R.mapDom (Name.joinDot n) types
@ -323,14 +317,14 @@ filter :: Ord n => (n -> Bool) -> Names' n -> Names' n
filter f (Names terms types) = Names (R.filterDom f terms) (R.filterDom f types) filter f (Names terms types) = Names (R.filterDom f terms) (R.filterDom f types)
-- currently used for filtering before a conditional `add` -- currently used for filtering before a conditional `add`
filterByHQs :: Set (HashQualified Name) -> UnqualifiedNames -> UnqualifiedNames filterByHQs :: Set (HashQualified Name) -> Names -> Names
filterByHQs hqs Names{..} = Names terms' types' where filterByHQs hqs Names{..} = Names terms' types' where
terms' = R.filter f terms terms' = R.filter f terms
types' = R.filter g types types' = R.filter g types
f (n, r) = any (HQ.matchesNamedReferent n r) hqs f (n, r) = any (HQ.matchesNamedReferent n r) hqs
g (n, r) = any (HQ.matchesNamedReference n r) hqs g (n, r) = any (HQ.matchesNamedReference n r) hqs
filterBySHs :: Set ShortHash -> UnqualifiedNames -> UnqualifiedNames filterBySHs :: Set ShortHash -> Names -> Names
filterBySHs shs Names{..} = Names terms' types' where filterBySHs shs Names{..} = Names terms' types' where
terms' = R.filter f terms terms' = R.filter f terms
types' = R.filter g types types' = R.filter g types

View File

@ -7,14 +7,14 @@ module Unison.Names.ResolutionResult where
import Unison.Prelude import Unison.Prelude
import Unison.Reference as Reference ( Reference ) import Unison.Reference as Reference ( Reference )
import Unison.Referent as Referent ( Referent ) import Unison.Referent as Referent ( Referent )
import Unison.Names (UnqualifiedNames) import Unison.Names (Names)
import Data.Set.NonEmpty import Data.Set.NonEmpty
data ResolutionError ref data ResolutionError ref
= NotFound = NotFound
-- Contains the names which were in scope and which refs were possible options -- Contains the names which were in scope and which refs were possible options
-- The NonEmpty set of refs must contain 2 or more refs (otherwise what is ambiguous?). -- The NonEmpty set of refs must contain 2 or more refs (otherwise what is ambiguous?).
| Ambiguous UnqualifiedNames (NESet ref) | Ambiguous Names (NESet ref)
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)
-- | ResolutionFailure represents the failure to resolve a given variable. -- | ResolutionFailure represents the failure to resolve a given variable.

View File

@ -21,19 +21,19 @@ import qualified Unison.Names as Names
import qualified Unison.Util.List as List import qualified Unison.Util.List as List
import qualified Unison.Util.Relation as R import qualified Unison.Util.Relation as R
import qualified Unison.ConstructorType as CT import qualified Unison.ConstructorType as CT
import Unison.Names (UnqualifiedNames, pattern UnqualifiedNames) import Unison.Names (Names, pattern Names)
data NamesWithHistory = NamesWithHistory data NamesWithHistory = NamesWithHistory
{ -- | currentNames represent references which are named in the current version of the namespace. { -- | currentNames represent references which are named in the current version of the namespace.
currentNames :: Names.UnqualifiedNames, currentNames :: Names.Names,
-- | oldNames represent things which no longer have names in the current version of the -- | oldNames represent things which no longer have names in the current version of the
-- codebase, but which may have previously had names. This may allow us to show more helpful -- codebase, but which may have previously had names. This may allow us to show more helpful
-- context to users rather than just a hash. -- context to users rather than just a hash.
oldNames :: Names.UnqualifiedNames oldNames :: Names.Names
} }
deriving (Show) deriving (Show)
filterTypes :: (Name -> Bool) -> UnqualifiedNames -> UnqualifiedNames filterTypes :: (Name -> Bool) -> Names -> Names
filterTypes = Names.filterTypes filterTypes = Names.filterTypes
-- Simple 2 way diff, has the property that: -- Simple 2 way diff, has the property that:
@ -41,36 +41,36 @@ filterTypes = Names.filterTypes
-- --
-- `addedNames` are names in `n2` but not `n1` -- `addedNames` are names in `n2` but not `n1`
-- `removedNames` are names in `n1` but not `n2` -- `removedNames` are names in `n1` but not `n2`
diff0 :: UnqualifiedNames -> UnqualifiedNames -> Diff diff0 :: Names -> Names -> Diff
diff0 n1 n2 = Diff n1 added removed where diff0 n1 n2 = Diff n1 added removed where
added = UnqualifiedNames (terms0 n2 `R.difference` terms0 n1) added = Names (terms0 n2 `R.difference` terms0 n1)
(types0 n2 `R.difference` types0 n1) (types0 n2 `R.difference` types0 n1)
removed = UnqualifiedNames (terms0 n1 `R.difference` terms0 n2) removed = Names (terms0 n1 `R.difference` terms0 n2)
(types0 n1 `R.difference` types0 n2) (types0 n1 `R.difference` types0 n2)
data Diff = data Diff =
Diff { originalNames :: UnqualifiedNames Diff { originalNames :: Names
, addedNames :: UnqualifiedNames , addedNames :: Names
, removedNames :: UnqualifiedNames , removedNames :: Names
} deriving Show } deriving Show
isEmptyDiff :: Diff -> Bool isEmptyDiff :: Diff -> Bool
isEmptyDiff d = isEmpty0 (addedNames d) && isEmpty0 (removedNames d) isEmptyDiff d = isEmpty0 (addedNames d) && isEmpty0 (removedNames d)
isEmpty0 :: UnqualifiedNames -> Bool isEmpty0 :: Names -> Bool
isEmpty0 n = R.null (terms0 n) && R.null (types0 n) isEmpty0 n = R.null (terms0 n) && R.null (types0 n)
-- Add `n1` to `currentNames`, shadowing anything with the same name and -- Add `n1` to `currentNames`, shadowing anything with the same name and
-- moving shadowed definitions into `oldNames` so they can can still be -- moving shadowed definitions into `oldNames` so they can can still be
-- referenced hash qualified. -- referenced hash qualified.
push :: UnqualifiedNames -> NamesWithHistory -> NamesWithHistory push :: Names -> NamesWithHistory -> NamesWithHistory
push n0 ns = NamesWithHistory (unionLeft0 n1 cur) (oldNames ns <> shadowed) where push n0 ns = NamesWithHistory (unionLeft0 n1 cur) (oldNames ns <> shadowed) where
n1 = suffixify0 n0 n1 = suffixify0 n0
cur = currentNames ns cur = currentNames ns
shadowed = names0 terms' types' where shadowed = names0 terms' types' where
terms' = R.dom (terms0 n1) R.<| (terms0 cur `R.difference` terms0 n1) terms' = R.dom (terms0 n1) R.<| (terms0 cur `R.difference` terms0 n1)
types' = R.dom (types0 n1) R.<| (types0 cur `R.difference` types0 n1) types' = R.dom (types0 n1) R.<| (types0 cur `R.difference` types0 n1)
unionLeft0 :: UnqualifiedNames -> UnqualifiedNames -> UnqualifiedNames unionLeft0 :: Names -> Names -> Names
unionLeft0 n1 n2 = names0 terms' types' where unionLeft0 n1 n2 = names0 terms' types' where
terms' = terms0 n1 <> R.subtractDom (R.dom $ terms0 n1) (terms0 n2) terms' = terms0 n1 <> R.subtractDom (R.dom $ terms0 n1) (terms0 n2)
types' = types0 n1 <> R.subtractDom (R.dom $ types0 n1) (types0 n2) types' = types0 n1 <> R.subtractDom (R.dom $ types0 n1) (types0 n2)
@ -78,14 +78,14 @@ push n0 ns = NamesWithHistory (unionLeft0 n1 cur) (oldNames ns <> shadowed) wher
-- of that name [[foo.bar.baz], [bar.baz], [baz]]. Any suffix which uniquely -- of that name [[foo.bar.baz], [bar.baz], [baz]]. Any suffix which uniquely
-- refers to a single definition is added as an alias -- refers to a single definition is added as an alias
-- --
-- If `Names` were more like a `[UnqualifiedNames]`, then `push` could just cons -- If `Names` were more like a `[Names]`, then `push` could just cons
-- onto the list and we could get rid of all this complex logic. The -- onto the list and we could get rid of all this complex logic. The
-- complexity here is that we have to "bake the shadowing" into a single -- complexity here is that we have to "bake the shadowing" into a single
-- UnqualifiedNames, taking into account suffix-based name resolution. -- Names, taking into account suffix-based name resolution.
-- --
-- We currently have `oldNames`, but that controls an unrelated axis, which -- We currently have `oldNames`, but that controls an unrelated axis, which
-- is whether names are hash qualified or not. -- is whether names are hash qualified or not.
suffixify0 :: UnqualifiedNames -> UnqualifiedNames suffixify0 :: Names -> Names
suffixify0 ns = ns <> suffixNs suffixify0 ns = ns <> suffixNs
where where
suffixNs = names0 (R.fromList uniqueTerms) (R.fromList uniqueTypes) suffixNs = names0 (R.fromList uniqueTerms) (R.fromList uniqueTypes)
@ -94,34 +94,34 @@ push n0 ns = NamesWithHistory (unionLeft0 n1 cur) (oldNames ns <> shadowed) wher
uniqueTerms = [ (n,ref) | (n, nubOrd -> [ref]) <- Map.toList terms ] uniqueTerms = [ (n,ref) | (n, nubOrd -> [ref]) <- Map.toList terms ]
uniqueTypes = [ (n,ref) | (n, nubOrd -> [ref]) <- Map.toList types ] uniqueTypes = [ (n,ref) | (n, nubOrd -> [ref]) <- Map.toList types ]
unionLeft0 :: UnqualifiedNames -> UnqualifiedNames -> UnqualifiedNames unionLeft0 :: Names -> Names -> Names
unionLeft0 = Names.unionLeft unionLeft0 = Names.unionLeft
unionLeftName0 :: UnqualifiedNames -> UnqualifiedNames -> UnqualifiedNames unionLeftName0 :: Names -> Names -> Names
unionLeftName0 = Names.unionLeftName unionLeftName0 = Names.unionLeftName
map0 :: (Name -> Name) -> UnqualifiedNames -> UnqualifiedNames map0 :: (Name -> Name) -> Names -> Names
map0 f (Names.Names terms types) = Names.Names terms' types' where map0 f (Names.Names terms types) = Names.Names terms' types' where
terms' = R.mapDom f terms terms' = R.mapDom f terms
types' = R.mapDom f types types' = R.mapDom f types
names0 :: Relation Name Referent -> Relation Name Reference -> UnqualifiedNames names0 :: Relation Name Referent -> Relation Name Reference -> Names
names0 = Names.Names names0 = Names.Names
types0 :: UnqualifiedNames -> Relation Name Reference types0 :: Names -> Relation Name Reference
types0 = Names.types types0 = Names.types
terms0 :: UnqualifiedNames -> Relation Name Referent terms0 :: Names -> Relation Name Referent
terms0 = Names.terms terms0 = Names.terms
-- if I push an existing name, the pushed reference should be the thing -- if I push an existing name, the pushed reference should be the thing
-- if I push a different name for the same thing, i suppose they should coexist -- if I push a different name for the same thing, i suppose they should coexist
-- thus, `unionLeftName0`. -- thus, `unionLeftName0`.
shadowing :: UnqualifiedNames -> NamesWithHistory -> NamesWithHistory shadowing :: Names -> NamesWithHistory -> NamesWithHistory
shadowing prio (NamesWithHistory current old) = shadowing prio (NamesWithHistory current old) =
NamesWithHistory (prio `unionLeftName0` current) (current <> old) NamesWithHistory (prio `unionLeftName0` current) (current <> old)
makeAbsolute0 :: UnqualifiedNames -> UnqualifiedNames makeAbsolute0 :: Names -> Names
makeAbsolute0 = map0 Name.makeAbsolute makeAbsolute0 = map0 Name.makeAbsolute
-- Find all types whose name has a suffix matching the provided `HashQualified`, -- Find all types whose name has a suffix matching the provided `HashQualified`,
@ -191,8 +191,8 @@ lookupHQTerm' =
lookupHQRef :: lookupHQRef ::
forall r. forall r.
Ord r => Ord r =>
-- | A projection of types or terms from a UnqualifiedNames. -- | A projection of types or terms from a Names.
(UnqualifiedNames -> Relation Name r) -> (Names -> Relation Name r) ->
-- | isPrefixOf, for references or referents -- | isPrefixOf, for references or referents
(ShortHash -> r -> Bool) -> (ShortHash -> r -> Bool) ->
-- | The name to look up -- | The name to look up
@ -295,8 +295,8 @@ lookupHQPattern hq ctt names = Set.fromList
, ct == ctt , ct == ctt
] ]
-- Finds all the constructors for the given type in the `UnqualifiedNames` -- Finds all the constructors for the given type in the `Names`
constructorsForType0 :: Reference -> UnqualifiedNames -> [(Name,Referent)] constructorsForType0 :: Reference -> Names -> [(Name,Referent)]
constructorsForType0 r ns = let constructorsForType0 r ns = let
-- rather than searching all of names, we use the known possible forms -- rather than searching all of names, we use the known possible forms
-- that the constructors can take -- that the constructors can take
@ -319,7 +319,7 @@ importing :: [(Name, Name)] -> NamesWithHistory -> NamesWithHistory
importing shortToLongName ns = importing shortToLongName ns =
ns { currentNames = importing0 shortToLongName (currentNames ns) } ns { currentNames = importing0 shortToLongName (currentNames ns) }
importing0 :: [(Name, Name)] -> UnqualifiedNames -> UnqualifiedNames importing0 :: [(Name, Name)] -> Names -> Names
importing0 shortToLongName ns = importing0 shortToLongName ns =
Names.Names Names.Names
(foldl' go (terms0 ns) shortToLongName) (foldl' go (terms0 ns) shortToLongName)
@ -334,7 +334,7 @@ importing0 shortToLongName ns =
-- [(suffix, full)]. Example: if `io` contains two functions, `foo` and -- [(suffix, full)]. Example: if `io` contains two functions, `foo` and
-- `bar`, then `expandWildcardImport io` will produce -- `bar`, then `expandWildcardImport io` will produce
-- `[(foo, io.foo), (bar, io.bar)]`. -- `[(foo, io.foo), (bar, io.bar)]`.
expandWildcardImport :: Name -> UnqualifiedNames -> [(Name,Name)] expandWildcardImport :: Name -> Names -> [(Name,Name)]
expandWildcardImport prefix ns = expandWildcardImport prefix ns =
[ (suffix, full) | Just (suffix,full) <- go <$> R.toList (terms0 ns) ] <> [ (suffix, full) | Just (suffix,full) <- go <$> R.toList (terms0 ns) ] <>
[ (suffix, full) | Just (suffix,full) <- go <$> R.toList (types0 ns) ] [ (suffix, full) | Just (suffix,full) <- go <$> R.toList (types0 ns) ]
@ -349,13 +349,13 @@ expandWildcardImport prefix ns =
-- suffix = negate -- suffix = negate
pure (suffix, full) pure (suffix, full)
-- Deletes from the `n0 : UnqualifiedNames` any definitions whose names -- Deletes from the `n0 : Names` any definitions whose names
-- are in `ns`. Does so using logarithmic time lookups, -- are in `ns`. Does so using logarithmic time lookups,
-- traversing only `ns`. -- traversing only `ns`.
-- --
-- See usage in `FileParser` for handling precendence of symbol -- See usage in `FileParser` for handling precendence of symbol
-- resolution where local names are preferred to codebase names. -- resolution where local names are preferred to codebase names.
shadowTerms0 :: [Name] -> UnqualifiedNames -> UnqualifiedNames shadowTerms0 :: [Name] -> Names -> Names
shadowTerms0 ns n0 = names0 terms' (types0 n0) shadowTerms0 ns n0 = names0 terms' (types0 n0)
where where
terms' = foldl' go (terms0 n0) ns terms' = foldl' go (terms0 n0) ns

View File

@ -24,7 +24,7 @@ import Prelude.Extras (Eq1(..), Show1(..))
import Text.Show import Text.Show
import qualified Unison.ABT as ABT import qualified Unison.ABT as ABT
import qualified Unison.Blank as B import qualified Unison.Blank as B
import Unison.Names ( UnqualifiedNames ) import Unison.Names ( Names )
import qualified Unison.NamesWithHistory as Names import qualified Unison.NamesWithHistory as Names
import qualified Unison.Names.ResolutionResult as Names import qualified Unison.Names.ResolutionResult as Names
import Unison.Pattern (Pattern) import Unison.Pattern (Pattern)
@ -113,7 +113,7 @@ type Term0' vt v = Term' vt v ()
bindNames bindNames
:: forall v a . Var v :: forall v a . Var v
=> Set v => Set v
-> UnqualifiedNames -> Names
-> Term v a -> Term v a
-> Names.ResolutionResult v a (Term v a) -> Names.ResolutionResult v a (Term v a)
bindNames keepFreeTerms ns0 e = do bindNames keepFreeTerms ns0 e = do
@ -142,12 +142,12 @@ bindNames keepFreeTerms ns0 e = do
pure . substTypeVars typeSubsts . ABT.substsInheritAnnotation termSubsts $ e pure . substTypeVars typeSubsts . ABT.substsInheritAnnotation termSubsts $ e
-- This function replaces free term and type variables with -- This function replaces free term and type variables with
-- hashes found in the provided `UnqualifiedNames`, using suffix-based -- hashes found in the provided `Names`, using suffix-based
-- lookup. Any terms not found in the `UnqualifiedNames` are kept free. -- lookup. Any terms not found in the `Names` are kept free.
bindSomeNames bindSomeNames
:: forall v a . Var v :: forall v a . Var v
=> Set v => Set v
-> UnqualifiedNames -> Names
-> Term v a -> Term v a
-> Names.ResolutionResult v a (Term v a) -> Names.ResolutionResult v a (Term v a)
-- bindSomeNames ns e | trace "Term.bindSome" False -- bindSomeNames ns e | trace "Term.bindSome" False

View File

@ -23,7 +23,7 @@ import qualified Data.Set.NonEmpty as NES
bindNames bindNames
:: Var v :: Var v
=> Set v => Set v
-> Names.UnqualifiedNames -> Names.Names
-> Type v a -> Type v a
-> Names.ResolutionResult v a (Type v a) -> Names.ResolutionResult v a (Type v a)
bindNames keepFree ns0 t = let bindNames keepFree ns0 t = let