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 qualified Unison.Name as Name
import Unison.NamesWithHistory (NamesWithHistory(..))
import Unison.Names (UnqualifiedNames)
import Unison.Names (Names)
import qualified Unison.NamesWithHistory as NamesWithHistory
import qualified Unison.Typechecker.TypeLookup as TL
import qualified Unison.Util.Relation as Rel
@ -56,7 +56,7 @@ type Type v = Type.Type v ()
names :: NamesWithHistory
names = NamesWithHistory names0 mempty
names0 :: UnqualifiedNames
names0 :: Names
names0 = NamesWithHistory.names0 terms types where
terms = Rel.mapRan Referent.Ref (Rel.fromMap termNameRefs) <>
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',
namesDiff,
toUnqualifiedNames,
toNames,
)
where
@ -21,7 +21,7 @@ import qualified Unison.HashQualified as HQ
import Unison.LabeledDependency (LabeledDependency)
import qualified Unison.LabeledDependency as LD
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.NamesWithHistory as Names
import Unison.Prelude hiding (empty)
@ -31,8 +31,8 @@ import qualified Unison.Referent as Referent
import qualified Unison.Util.Relation as R
import Prelude hiding (head, read, subtract)
toUnqualifiedNames :: Branch0 m -> UnqualifiedNames
toUnqualifiedNames b = Names (R.swap . deepTerms $ b)
toNames :: Branch0 m -> Names
toNames b = Names (R.swap . deepTerms $ b)
(R.swap . deepTypes $ b)
-- This stops searching for a given HashQualified once it encounters
@ -40,19 +40,19 @@ toUnqualifiedNames b = Names (R.swap . deepTerms $ b)
findHistoricalHQs :: Monad m
=> Set (HashQualified Name)
-> Branch m
-> m (Set (HashQualified Name), UnqualifiedNames)
-> m (Set (HashQualified Name), Names)
findHistoricalHQs = findInHistory
(\hq r n -> HQ.matchesNamedReferent n r hq)
(\hq r n -> HQ.matchesNamedReference n r hq)
findHistoricalRefs :: Monad m => Set LabeledDependency -> Branch m
-> m (Set LabeledDependency, UnqualifiedNames)
-> m (Set LabeledDependency, Names)
findHistoricalRefs = findInHistory
(\query r _n -> LD.fold (const False) (==r) query)
(\query r _n -> LD.fold (==r) (const False) query)
findHistoricalRefs' :: Monad m => Set Reference -> Branch m
-> m (Set Reference, UnqualifiedNames)
-> m (Set Reference, Names)
findHistoricalRefs' = findInHistory
(\queryRef r _n -> r == Referent.Ref queryRef)
(\queryRef r _n -> r == queryRef)
@ -60,7 +60,7 @@ findHistoricalRefs' = findInHistory
findInHistory :: forall m q. (Monad m, Ord q)
=> (q -> Referent -> 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 =
(Causal.foldHistoryUntil f (queries, mempty) . _history) b <&> \case
-- 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')
where
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 =
foldl' (doType sh) (foldl' (doTerm sh) acc
(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
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 Unison.Codebase.Branch (Branch, Branch0)
import qualified Unison.Names as Names
import Unison.Names (UnqualifiedNames)
import Unison.Names (Names)
import qualified Unison.Referent as Referent
import qualified Unison.Reference as Reference
import Unison.Referent (Referent)
@ -27,18 +27,18 @@ import Unison.Codebase.Patch (Patch)
import Unison.NameSegment (NameSegment)
import Control.Lens (view)
fromUnqualifiedNames :: Monad m => UnqualifiedNames -> Branch m
fromUnqualifiedNames names0 = Branch.one $ addFromUnqualifiedNames names0 Branch.empty0
fromNames :: Monad m => Names -> Branch m
fromNames names0 = Branch.one $ addFromNames names0 Branch.empty0
-- can produce a pure value because there's no history to traverse
hashesFromUnqualifiedNames :: Monad m => UnqualifiedNames -> Map Branch.Hash (Branch m)
hashesFromUnqualifiedNames = deepHashes . fromUnqualifiedNames where
hashesFromNames :: Monad m => Names -> Map Branch.Hash (Branch m)
hashesFromNames = deepHashes . fromNames where
deepHashes :: Branch m -> Map Branch.Hash (Branch m)
deepHashes b = Map.singleton (Branch.headHash b) b
<> (foldMap deepHashes . view Branch.children . Branch.head) b
addFromUnqualifiedNames :: Monad m => UnqualifiedNames -> Branch0 m -> Branch0 m
addFromUnqualifiedNames names0 = Branch.stepManyAt0 (typeActions <> termActions)
addFromNames :: Monad m => Names -> Branch0 m -> Branch0 m
addFromNames names0 = Branch.stepManyAt0 (typeActions <> termActions)
where
typeActions = map doType . R.toList $ Names.types 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 Unison.Codebase.SyncMode ( SyncMode )
import Unison.NamesWithHistory ( NamesWithHistory )
import Unison.Names ( UnqualifiedNames )
import Unison.Names ( Names )
import Unison.Parser.Ann (Ann)
import Unison.Referent ( Referent )
import Unison.Reference ( Reference )
@ -75,7 +75,7 @@ data LoadSourceResult = InvalidSourceNameError
type TypecheckingResult v =
Result (Seq (Note v Ann))
(Either UnqualifiedNames (UF.TypecheckedUnisonFile v Ann))
(Either Names (UF.TypecheckedUnisonFile v Ann))
data Command m i v a where
-- Escape hatch.

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@ import qualified Unison.Codebase.Patch as Patch
import Unison.DataDeclaration ( Decl )
import qualified Unison.DataDeclaration as Decl
import qualified Unison.Name as Name
import Unison.Names ( UnqualifiedNames )
import Unison.Names ( Names )
import qualified Unison.Names as Names
import Unison.Parser.Ann (Ann(..))
import Unison.Reference ( Reference(..) )
@ -74,7 +74,7 @@ noEdits = Edits mempty mempty mempty mempty mempty mempty mempty
propagateAndApply
:: forall m i v
. (Applicative m, Var v)
=> UnqualifiedNames
=> Names
-> Patch
-> 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
-- be the same.
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
let mappings :: (Reference,Reference) -> _ (Map Referent Referent)
mappings (old,new) = do
@ -226,7 +226,7 @@ debugMode = False
propagate
:: forall m i 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`
-> Patch
-> Branch0 m
@ -252,7 +252,7 @@ propagate rootNames patch b = case validatePatch patch of
in case toList rns of
[] -> show r
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
[] -> Referent.toString r
n : _ -> show n
@ -455,7 +455,7 @@ propagate rootNames patch b = case validatePatch patch of
(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 when j is a dependent of i.
names0 = Branch.toUnqualifiedNames b
names0 = Branch.toNames b
validatePatch
:: Patch -> Maybe (Map Reference TermEdit, Map Reference TypeEdit)
validatePatch p =
@ -634,7 +634,7 @@ computeFrontier
. Monad m
=> (Reference -> m (Set Reference)) -- eg Codebase.dependents codebase
-> Patch
-> UnqualifiedNames
-> Names
-> m (R.Relation Reference Reference)
computeFrontier getDependents patch names = do
-- (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`.
constructorsFor :: Var v => Set v -> UF.TypecheckedUnisonFile v Ann -> Set v
constructorsFor types uf = let
names = UF.typecheckedToUnqualifiedNames uf
names = UF.typecheckedToNames uf
typesRefs = Set.unions $ Names.typesNamed names . Name.fromVar <$> toList types
ctorNames = R.filterRan isOkCtor (Names.terms names)
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 Unison.DataDeclaration as DD
import Unison.Reference (Reference)
import Unison.Names (UnqualifiedNames)
import Unison.Names (Names)
import Unison.Codebase.Patch (Patch)
import Unison.Codebase.Editor.DisplayObject (DisplayObject(UserObject))
import Unison.Type (Type)
@ -28,7 +28,7 @@ data TodoOutput v a = TodoOutput
, todoFrontierDependents ::
( [(Score, Reference, Maybe (Type v a))]
, [(Score, Reference, DisplayObject () (Decl v a))])
, nameConflicts :: UnqualifiedNames
, nameConflicts :: Names
, editConflicts :: Patch
} deriving (Show)

View File

@ -42,10 +42,10 @@ execute codebase runtime mainName =
die ("Couldn't load root branch " ++ show h)
Left (Codebase.CouldntParseRootBranch 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
let mainType = Runtime.mainType runtime
mt <- getMainTerm loadTypeOfTerm parseUnqualifiedNames mainName mainType
mt <- getMainTerm loadTypeOfTerm parseNames mainName mainType
case mt of
MainTerm.NotAFunctionName s -> die ("Not a function name: " ++ s)
MainTerm.NotFound s -> die ("Not found: " ++ s)

View File

@ -33,15 +33,15 @@ data MainTerm v
getMainTerm
:: (Monad m, Var v)
=> (Reference -> m (Maybe (Type v Ann)))
-> Names.UnqualifiedNames
-> Names.Names
-> String
-> Type.Type v Ann
-> m (MainTerm v)
getMainTerm loadTypeOfTerm parseUnqualifiedNames mainName mainType =
getMainTerm loadTypeOfTerm parseNames mainName mainType =
case HQ.fromString mainName of
Nothing -> pure (NotAFunctionName mainName)
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
case toList refs of
[Referent.Ref ref] -> do

View File

@ -33,7 +33,7 @@ import qualified Unison.Codebase.Watch as Watch
import Unison.CommandLine.InputPattern (InputPattern (parse))
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.Find as Find
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'' 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
Nothing -> []
Just query ->

View File

@ -1533,7 +1533,7 @@ typeCompletor :: Applicative m
-> Path.Absolute
-> m [Completion]
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
=> (String -> [String] -> [Completion])
@ -1543,7 +1543,7 @@ termCompletor :: Applicative m
-> Path.Absolute
-> m [Completion]
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 "patch" $ pathCompletor

View File

@ -71,7 +71,7 @@ import Unison.NamePrinter (prettyHashQualified,
prettyName, prettyShortHash,
styleHashQualified,
styleHashQualified', prettyHashQualified')
import Unison.Names (Names'(..), UnqualifiedNames)
import Unison.Names (Names'(..), Names)
import qualified Unison.Names as Names
import qualified Unison.NamesWithHistory as Names
import Unison.Parser.Ann (Ann, startingLine)
@ -1382,7 +1382,7 @@ todoOutput ppe todo =
where
-- If a conflict is both an edit and a name conflict, we show it in the edit
-- conflicts section
c :: UnqualifiedNames
c :: Names
c = removeEditConflicts (TO.editConflicts todo) (TO.nameConflicts todo)
conflictedTypeNames = (R.dom . Names.types) 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 Unison.Var (Var)
import qualified Unison.Var as Var
import Unison.Names(UnqualifiedNames)
import Unison.Names(Names)
import qualified Unison.Names as Names
type Term v = Term.Term v Ann
@ -69,7 +69,7 @@ parseAndSynthesizeFile
-> ResultT
(Seq (Note v Ann))
m
(Either UnqualifiedNames (UF.TypecheckedUnisonFile v Ann))
(Either Names (UF.TypecheckedUnisonFile v Ann))
parseAndSynthesizeFile ambient typeLookupf env filePath src = do
when debug $ traceM "parseAndSynthesizeFile"
uf <- Result.fromParsing $ Parsers.parseFile filePath (unpack src) env
@ -83,7 +83,7 @@ type TDNRMap v = Map Typechecker.Name [Typechecker.NamedReference v Ann]
resolveNames
:: (Var v, Monad m)
=> (Set Reference -> m (TL.TypeLookup v Ann))
-> Names.UnqualifiedNames
-> Names.Names
-> UnisonFile v
-> ResultT
(Seq (Note v Ann))

View File

@ -1467,16 +1467,16 @@ prettyResolutionFailures s allFailures =
toAmbiguityPair :: Names.ResolutionFailure v annotation -> (v, Maybe (NESet String))
toAmbiguityPair = \case
(Names.TermResolutionFailure v _ (Names.Ambiguous names refs)) -> do
let ppe = ppeFromUnqualifiedNames names
let ppe = ppeFromNames names
in (v, Just $ NES.map (showTermRef ppe) refs)
(Names.TypeResolutionFailure v _ (Names.Ambiguous names refs)) -> do
let ppe = ppeFromUnqualifiedNames names
let ppe = ppeFromNames names
in (v, Just $ NES.map (showTypeRef ppe) refs)
(Names.TermResolutionFailure v _ Names.NotFound) -> (v, Nothing)
(Names.TypeResolutionFailure v _ Names.NotFound) -> (v, Nothing)
ppeFromUnqualifiedNames :: Names.UnqualifiedNames -> PPE.PrettyPrintEnv
ppeFromUnqualifiedNames names0 =
ppeFromNames :: Names.Names -> PPE.PrettyPrintEnv
ppeFromNames names0 =
PPE.fromNames PPE.todoHashLength (NamesWithHistory.NamesWithHistory {currentNames = names0, oldNames = mempty})
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 Unison.NamesWithHistory ( NamesWithHistory (..) )
import qualified Unison.NamesWithHistory as NamesWithHistory
import Unison.Names (UnqualifiedNames)
import Unison.Names (Names)
import Unison.Parser.Ann (Ann)
import Unison.Prelude
import qualified Unison.PrettyPrintEnv as PPE
@ -121,42 +121,42 @@ data BackendError
type Backend m a = ExceptT BackendError m a
-- implementation detail of basicParseUnqualifiedNames and basicPrettyPrintUnqualifiedNames
basicUnqualifiedNames' :: Branch m -> Path -> (UnqualifiedNames, UnqualifiedNames)
basicUnqualifiedNames' root path = (parseUnqualifiedNames0, prettyPrintUnqualifiedNames0)
-- implementation detail of basicParseNames and basicPrettyPrintNames
basicNames' :: Branch m -> Path -> (Names, Names)
basicNames' root path = (parseNames0, prettyPrintNames0)
where
root0 = Branch.head 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
currentPathUnqualifiedNames = Branch.toUnqualifiedNames currentBranch0
currentPathNames = Branch.toNames currentBranch0
-- all names, but with local names in their relative form only, rather
-- than absolute; external names appear as absolute
currentAndExternalUnqualifiedNames =
currentPathUnqualifiedNames
currentAndExternalNames =
currentPathNames
`NamesWithHistory.unionLeft0` absDot externalNames
where
absDot = Names.prefix0 (Name.unsafeFromText "")
externalNames = rootNames `Names.difference` pathPrefixed currentPathUnqualifiedNames
rootNames = Branch.toUnqualifiedNames root0
externalNames = rootNames `Names.difference` pathPrefixed currentPathNames
rootNames = Branch.toNames root0
pathPrefixed = case path of
Path.Path (toList -> []) -> const mempty
p -> Names.prefix0 (Path.toName p)
-- parsing should respond to local and absolute names
parseUnqualifiedNames0 = currentPathUnqualifiedNames <> absoluteRootUnqualifiedNames
parseNames0 = currentPathNames <> absoluteRootNames
-- pretty-printing should use local names where available
prettyPrintUnqualifiedNames0 = currentAndExternalUnqualifiedNames
prettyPrintNames0 = currentAndExternalNames
basicSuffixifiedNames :: Int -> Branch m -> Path -> PPE.PrettyPrintEnv
basicSuffixifiedNames hashLength root path =
let names0 = basicPrettyPrintUnqualifiedNames root path
let names0 = basicPrettyPrintNames root path
in PPE.suffixifiedPPE . PPE.fromNamesDecl hashLength $ NamesWithHistory names0 mempty
basicPrettyPrintUnqualifiedNames :: Branch m -> Path -> UnqualifiedNames
basicPrettyPrintUnqualifiedNames root = snd . basicUnqualifiedNames' root
basicPrettyPrintNames :: Branch m -> Path -> Names
basicPrettyPrintNames root = snd . basicNames' root
basicParseUnqualifiedNames :: Branch m -> Path -> UnqualifiedNames
basicParseUnqualifiedNames root = fst . basicUnqualifiedNames' root
basicParseNames :: Branch m -> Path -> Names
basicParseNames root = fst . basicNames' root
loadReferentType ::
(Applicative m, Var v) =>
@ -220,7 +220,7 @@ fuzzyFind
fuzzyFind path branch query =
let
printNames =
basicPrettyPrintUnqualifiedNames branch path
basicPrettyPrintNames branch path
fzfNames =
Names.fuzzyFind (words query) printNames
@ -440,15 +440,15 @@ termReferentsByShortHash codebase sh = do
B.intrinsicTermReferences
pure (fromBuiltins <> Set.map (fmap Reference.DerivedId) fromCodebase)
-- currentPathUnqualifiedNames :: Path -> UnqualifiedNames
-- currentPathUnqualifiedNames = Branch.toUnqualifiedNames . Branch.head . Branch.getAt
-- currentPathNames :: Path -> Names
-- currentPathNames = Branch.toNames . Branch.head . Branch.getAt
getCurrentPrettyNames :: Path -> Branch m -> NamesWithHistory
getCurrentPrettyNames path root =
NamesWithHistory (basicPrettyPrintUnqualifiedNames root path) mempty
NamesWithHistory (basicPrettyPrintNames root path) mempty
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
-- 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
-- then name foo.bar.baz becomes baz
-- name cat.dog becomes .cat.dog
fixupNamesRelative :: Path.Absolute -> UnqualifiedNames -> UnqualifiedNames
fixupNamesRelative :: Path.Absolute -> Names -> Names
fixupNamesRelative root = NamesWithHistory.map0 fixName where
prefix = Path.toName $ Path.unabsolute root
fixName n = if root == Path.absoluteEmpty

View File

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

View File

@ -12,7 +12,7 @@ import Unison.DataDeclaration (DataDeclaration)
import Unison.DataDeclaration (EffectDeclaration(..))
import Unison.Reference (Reference)
import qualified Unison.Reference as Reference
import Unison.Names (UnqualifiedNames)
import Unison.Names (Names)
data Env v a = Env
-- 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
, effectsId :: Map v (Reference.Id, EffectDeclaration v a)
-- Naming environment
, names :: UnqualifiedNames
, names :: Names
}
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.Name as Name
import qualified Unison.Names.ResolutionResult as Names
import Unison.Names (UnqualifiedNames)
import Unison.Names (Names)
import qualified Unison.NamesWithHistory as Names
import Unison.Prelude
import qualified Unison.Reference as Reference
@ -29,14 +29,14 @@ import qualified Unison.Util.Relation as Relation
import Unison.Var (Var)
import qualified Unison.WatchKind as WK
toNames :: Var v => UnisonFile v a -> UnqualifiedNames
toNames :: Var v => UnisonFile v a -> Names
toNames uf = datas <> effects
where
datas = foldMap DD.Names.dataDeclToNames' (Map.toList (UF.dataDeclarationsId uf))
effects = foldMap DD.Names.effectDeclToNames' (Map.toList (UF.effectDeclarationsId uf))
typecheckedToUnqualifiedNames :: Var v => TypecheckedUnisonFile v a -> UnqualifiedNames
typecheckedToUnqualifiedNames uf = Names.names0 (terms <> ctors) types where
typecheckedToNames :: Var v => TypecheckedUnisonFile v a -> Names
typecheckedToNames uf = Names.names0 (terms <> ctors) types where
terms = Relation.fromList
[ (Name.fromVar v, Referent.Ref r)
| (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
-- as it can't refer to a local definition.
bindNames :: Var v
=> UnqualifiedNames
=> Names
-> UnisonFile v a
-> Names.ResolutionResult v a (UnisonFile v a)
bindNames names (UnisonFileId d e ts ws) = do
@ -85,7 +85,7 @@ bindNames names (UnisonFileId d e ts ws) = do
-- left.
environmentFor
:: forall v a . Var v
=> UnqualifiedNames
=> Names
-> Map v (DataDeclaration v a)
-> Map v (EffectDeclaration 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 Unison.Name ( Name )
import qualified Unison.Names as Names
import Unison.Names ( UnqualifiedNames )
import Unison.Names ( Names )
import Unison.NamePrinter (prettyHashQualified)
import qualified Unison.Reference as Reference
import qualified Unison.Referent as Referent
@ -114,7 +114,7 @@ fuzzyFindMatchArray query items render =
-- Ord MatchArray already provides a. and b. todo: c.
prefixFindInBranch ::
UnqualifiedNames -> HQ'.HashQualified Name -> [(SearchResult, P.Pretty P.ColorText)]
Names -> HQ'.HashQualified Name -> [(SearchResult, P.Pretty P.ColorText)]
prefixFindInBranch b hq = fmap getName $
-- query string includes a name component, so do a prefix find on that
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 #
fuzzyFindInBranch :: HasCallStack
=> UnqualifiedNames
=> Names
-> HQ'.HashQualified Name
-> [(SearchResult, P.Pretty P.ColorText)]
fuzzyFindInBranch b hq =

View File

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

View File

@ -33,14 +33,14 @@ import Unison.Util.Monoid (intercalateMap)
import Unison.Util.Pretty (toPlain)
import qualified Unison.Test.Common as Common
import qualified Unison.NamesWithHistory as NamesWithHistory
import Unison.Names (UnqualifiedNames)
import Unison.Names (Names)
type Note = Result.Note Symbol Ann
type TFile = UF.TypecheckedUnisonFile Symbol Ann
type SynthResult =
Result (Seq Note)
(Either UnqualifiedNames TFile)
(Either Names 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.Type.Names as Type.Names
import Unison.Var ( Var )
import Unison.Names (UnqualifiedNames)
import Unison.Names (Names)
import qualified Unison.NamesWithHistory as Names
import qualified Unison.Names.ResolutionResult as Names
import qualified Unison.ConstructorType as CT
-- implementation of dataDeclToNames and effectDeclToNames
toUnqualifiedNames :: Var v => CT.ConstructorType -> v -> Reference.Id -> DataDeclaration v a -> UnqualifiedNames
toUnqualifiedNames ct typeSymbol (Reference.DerivedId -> r) dd =
toNames :: Var v => CT.ConstructorType -> v -> Reference.Id -> DataDeclaration v a -> Names
toNames ct typeSymbol (Reference.DerivedId -> r) dd =
-- constructor names
foldMap names (DD.constructorVars dd `zip` [0 ..])
-- name of the type itself
@ -37,21 +37,21 @@ toUnqualifiedNames ct typeSymbol (Reference.DerivedId -> r) dd =
names (ctor, i) =
Names.names0 (Rel.singleton (Name.fromVar ctor) (Referent.Con r i ct)) mempty
dataDeclToNames :: Var v => v -> Reference.Id -> DataDeclaration v a -> UnqualifiedNames
dataDeclToNames = toUnqualifiedNames CT.Data
dataDeclToNames :: Var v => v -> Reference.Id -> DataDeclaration v a -> Names
dataDeclToNames = toNames CT.Data
effectDeclToNames :: Var v => v -> Reference.Id -> EffectDeclaration v a -> UnqualifiedNames
effectDeclToNames typeSymbol r ed = toUnqualifiedNames CT.Effect typeSymbol r $ DD.toDataDecl ed
effectDeclToNames :: Var v => v -> Reference.Id -> EffectDeclaration v a -> Names
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
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
bindNames :: Var v
=> Set v
-> UnqualifiedNames
-> Names
-> DataDeclaration v a
-> Names.ResolutionResult v a (DataDeclaration v a)
bindNames keepFree names (DataDeclaration m a bound constructors) = do

View File

@ -5,9 +5,8 @@
{-# LANGUAGE ViewPatterns #-}
module Unison.Names
( UnqualifiedNames
( Names
, Names'(Names)
, pattern UnqualifiedNames
, addTerm
, addType
, allReferences
@ -75,18 +74,13 @@ data Names' n = Names
, types :: Relation n Reference
} deriving (Eq,Ord)
type UnqualifiedNames = Names' Name
pattern UnqualifiedNames :: Relation Name Referent
-> Relation Name Reference
-> UnqualifiedNames
pattern UnqualifiedNames terms types = Names terms types
type Names = Names' Name
-- Finds names that are supersequences of all the given strings, ordered by
-- score and grouped by name.
fuzzyFind
:: [String]
-> UnqualifiedNames
-> Names
-> [(FZF.Alignment, Name, Set (Either Referent Reference))]
fuzzyFind query names =
fmap flatten
@ -262,7 +256,7 @@ hqName b n = \case
ambiguous = Set.size (termsNamed b n) + Set.size (typesNamed b n) > 1
-- 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 hqLen b n r = if Set.size (termsNamed b n) > 1
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)
-- 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' hqLen 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 ts = Names mempty (R.fromList ts)
prefix0 :: Name -> UnqualifiedNames -> UnqualifiedNames
prefix0 :: Name -> Names -> Names
prefix0 n (Names terms types) = Names terms' types' where
terms' = R.mapDom (Name.joinDot n) terms
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)
-- 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
terms' = R.filter f terms
types' = R.filter g types
f (n, r) = any (HQ.matchesNamedReferent 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
terms' = R.filter f terms
types' = R.filter g types

View File

@ -7,14 +7,14 @@ module Unison.Names.ResolutionResult where
import Unison.Prelude
import Unison.Reference as Reference ( Reference )
import Unison.Referent as Referent ( Referent )
import Unison.Names (UnqualifiedNames)
import Unison.Names (Names)
import Data.Set.NonEmpty
data ResolutionError ref
= NotFound
-- 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?).
| Ambiguous UnqualifiedNames (NESet ref)
| Ambiguous Names (NESet ref)
deriving (Eq, Ord, Show)
-- | 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.Relation as R
import qualified Unison.ConstructorType as CT
import Unison.Names (UnqualifiedNames, pattern UnqualifiedNames)
import Unison.Names (Names, pattern Names)
data NamesWithHistory = NamesWithHistory
{ -- | 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
-- codebase, but which may have previously had names. This may allow us to show more helpful
-- context to users rather than just a hash.
oldNames :: Names.UnqualifiedNames
oldNames :: Names.Names
}
deriving (Show)
filterTypes :: (Name -> Bool) -> UnqualifiedNames -> UnqualifiedNames
filterTypes :: (Name -> Bool) -> Names -> Names
filterTypes = Names.filterTypes
-- Simple 2 way diff, has the property that:
@ -41,36 +41,36 @@ filterTypes = Names.filterTypes
--
-- `addedNames` are names in `n2` but not `n1`
-- `removedNames` are names in `n1` but not `n2`
diff0 :: UnqualifiedNames -> UnqualifiedNames -> Diff
diff0 :: Names -> Names -> Diff
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)
removed = UnqualifiedNames (terms0 n1 `R.difference` terms0 n2)
removed = Names (terms0 n1 `R.difference` terms0 n2)
(types0 n1 `R.difference` types0 n2)
data Diff =
Diff { originalNames :: UnqualifiedNames
, addedNames :: UnqualifiedNames
, removedNames :: UnqualifiedNames
Diff { originalNames :: Names
, addedNames :: Names
, removedNames :: Names
} deriving Show
isEmptyDiff :: Diff -> Bool
isEmptyDiff d = isEmpty0 (addedNames d) && isEmpty0 (removedNames d)
isEmpty0 :: UnqualifiedNames -> Bool
isEmpty0 :: Names -> Bool
isEmpty0 n = R.null (terms0 n) && R.null (types0 n)
-- Add `n1` to `currentNames`, shadowing anything with the same name and
-- moving shadowed definitions into `oldNames` so they can can still be
-- referenced hash qualified.
push :: UnqualifiedNames -> NamesWithHistory -> NamesWithHistory
push :: Names -> NamesWithHistory -> NamesWithHistory
push n0 ns = NamesWithHistory (unionLeft0 n1 cur) (oldNames ns <> shadowed) where
n1 = suffixify0 n0
cur = currentNames ns
shadowed = names0 terms' types' where
terms' = R.dom (terms0 n1) R.<| (terms0 cur `R.difference` terms0 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
terms' = terms0 n1 <> R.subtractDom (R.dom $ terms0 n1) (terms0 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
-- 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
-- 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
-- is whether names are hash qualified or not.
suffixify0 :: UnqualifiedNames -> UnqualifiedNames
suffixify0 :: Names -> Names
suffixify0 ns = ns <> suffixNs
where
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 ]
uniqueTypes = [ (n,ref) | (n, nubOrd -> [ref]) <- Map.toList types ]
unionLeft0 :: UnqualifiedNames -> UnqualifiedNames -> UnqualifiedNames
unionLeft0 :: Names -> Names -> Names
unionLeft0 = Names.unionLeft
unionLeftName0 :: UnqualifiedNames -> UnqualifiedNames -> UnqualifiedNames
unionLeftName0 :: Names -> Names -> Names
unionLeftName0 = Names.unionLeftName
map0 :: (Name -> Name) -> UnqualifiedNames -> UnqualifiedNames
map0 :: (Name -> Name) -> Names -> Names
map0 f (Names.Names terms types) = Names.Names terms' types' where
terms' = R.mapDom f terms
types' = R.mapDom f types
names0 :: Relation Name Referent -> Relation Name Reference -> UnqualifiedNames
names0 :: Relation Name Referent -> Relation Name Reference -> Names
names0 = Names.Names
types0 :: UnqualifiedNames -> Relation Name Reference
types0 :: Names -> Relation Name Reference
types0 = Names.types
terms0 :: UnqualifiedNames -> Relation Name Referent
terms0 :: Names -> Relation Name Referent
terms0 = Names.terms
-- 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
-- thus, `unionLeftName0`.
shadowing :: UnqualifiedNames -> NamesWithHistory -> NamesWithHistory
shadowing :: Names -> NamesWithHistory -> NamesWithHistory
shadowing prio (NamesWithHistory current old) =
NamesWithHistory (prio `unionLeftName0` current) (current <> old)
makeAbsolute0 :: UnqualifiedNames -> UnqualifiedNames
makeAbsolute0 :: Names -> Names
makeAbsolute0 = map0 Name.makeAbsolute
-- Find all types whose name has a suffix matching the provided `HashQualified`,
@ -191,8 +191,8 @@ lookupHQTerm' =
lookupHQRef ::
forall r.
Ord r =>
-- | A projection of types or terms from a UnqualifiedNames.
(UnqualifiedNames -> Relation Name r) ->
-- | A projection of types or terms from a Names.
(Names -> Relation Name r) ->
-- | isPrefixOf, for references or referents
(ShortHash -> r -> Bool) ->
-- | The name to look up
@ -295,8 +295,8 @@ lookupHQPattern hq ctt names = Set.fromList
, ct == ctt
]
-- Finds all the constructors for the given type in the `UnqualifiedNames`
constructorsForType0 :: Reference -> UnqualifiedNames -> [(Name,Referent)]
-- Finds all the constructors for the given type in the `Names`
constructorsForType0 :: Reference -> Names -> [(Name,Referent)]
constructorsForType0 r ns = let
-- rather than searching all of names, we use the known possible forms
-- that the constructors can take
@ -319,7 +319,7 @@ importing :: [(Name, Name)] -> NamesWithHistory -> NamesWithHistory
importing shortToLongName ns =
ns { currentNames = importing0 shortToLongName (currentNames ns) }
importing0 :: [(Name, Name)] -> UnqualifiedNames -> UnqualifiedNames
importing0 :: [(Name, Name)] -> Names -> Names
importing0 shortToLongName ns =
Names.Names
(foldl' go (terms0 ns) shortToLongName)
@ -334,7 +334,7 @@ importing0 shortToLongName ns =
-- [(suffix, full)]. Example: if `io` contains two functions, `foo` and
-- `bar`, then `expandWildcardImport io` will produce
-- `[(foo, io.foo), (bar, io.bar)]`.
expandWildcardImport :: Name -> UnqualifiedNames -> [(Name,Name)]
expandWildcardImport :: Name -> Names -> [(Name,Name)]
expandWildcardImport prefix ns =
[ (suffix, full) | Just (suffix,full) <- go <$> R.toList (terms0 ns) ] <>
[ (suffix, full) | Just (suffix,full) <- go <$> R.toList (types0 ns) ]
@ -349,13 +349,13 @@ expandWildcardImport prefix ns =
-- suffix = negate
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,
-- traversing only `ns`.
--
-- See usage in `FileParser` for handling precendence of symbol
-- resolution where local names are preferred to codebase names.
shadowTerms0 :: [Name] -> UnqualifiedNames -> UnqualifiedNames
shadowTerms0 :: [Name] -> Names -> Names
shadowTerms0 ns n0 = names0 terms' (types0 n0)
where
terms' = foldl' go (terms0 n0) ns

View File

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

View File

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