diff --git a/.gitignore b/.gitignore index 434b5b4646..02aff877fd 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ dist-newstyle # GHC *.hie +*.prof diff --git a/parser-typechecker/src/Unison/Codebase/Type.hs b/parser-typechecker/src/Unison/Codebase/Type.hs index 3d33abd61e..efb25ccf91 100644 --- a/parser-typechecker/src/Unison/Codebase/Type.hs +++ b/parser-typechecker/src/Unison/Codebase/Type.hs @@ -51,12 +51,12 @@ data Codebase m v a = Codebase -- The dependents of a builtin type includes the set of builtin terms which -- mention that type. dependentsImpl :: Reference -> m (Set Reference.Id), - -- | Get non-transitive dependencies of a reference (i.e. the references contained within a given - -- reference). + -- | Get non-transitive dependencies of a reference + -- (i.e. the references contained within the term associated with the given reference id). -- Includes builtins in the result. getDependencies :: Reference.Id -> m (Set Reference), - -- | Get non-transitive dependencies of a reference (i.e. the references contained within a given - -- reference). + -- | Get non-transitive dependencies of a reference + -- (i.e. the references contained within the term associated with the given reference id). -- Does not include builtins in the result. getDerivedDependencies :: Reference.Id -> m (Set Reference.Id), -- This copies all the dependencies of `b` from the specified Codebase into this one diff --git a/unison-cli/src/Unison/Codebase/Editor/Command.hs b/unison-cli/src/Unison/Codebase/Editor/Command.hs index a1605f8918..6d80150118 100644 --- a/unison-cli/src/Unison/Codebase/Editor/Command.hs +++ b/unison-cli/src/Unison/Codebase/Editor/Command.hs @@ -134,8 +134,8 @@ data Command TermReferencesByShortHash :: ShortHash -> Command m i v (Set Reference) TermReferentsByShortHash :: ShortHash -> Command m i v (Set Referent) - -- | Get referents to all constructors for the declaration indicated by the provided reference. - ConstructorsOfType :: Reference -> Command m i v (Set Referent) + -- | Get referents to all constructors for the type declaration associated with the provided reference. + ConstructorsForTypeDeclaration :: Reference -> Command m i v (Set Referent) -- the hash length needed to disambiguate any branch in the codebase BranchHashLength :: Command m i v Int @@ -287,58 +287,58 @@ lookupEvalResult v (_, m) = view _5 <$> Map.lookup v m commandName :: Command m i v a -> String commandName = \case - Eval{} -> "Eval" - UI -> "UI" - DocsToHtml{} -> "DocsToHtml" - ConfigLookup{} -> "ConfigLookup" - Input -> "Input" - Notify{} -> "Notify" - NotifyNumbered{} -> "NotifyNumbered" - AddDefsToCodebase{} -> "AddDefsToCodebase" - CodebaseHashLength -> "CodebaseHashLength" - TypeReferencesByShortHash{} -> "TypeReferencesByShortHash" - TermReferencesByShortHash{} -> "TermReferencesByShortHash" - TermReferentsByShortHash{} -> "TermReferentsByShortHash" - BranchHashLength -> "BranchHashLength" - BranchHashesByPrefix{} -> "BranchHashesByPrefix" - ParseType{} -> "ParseType" - LoadSource{} -> "LoadSource" - Typecheck{} -> "Typecheck" - TypecheckFile{} -> "TypecheckFile" - Evaluate{} -> "Evaluate" - Evaluate1{} -> "Evaluate1" - PutWatch{} -> "PutWatch" - LoadWatches{} -> "LoadWatches" - LoadLocalRootBranch -> "LoadLocalRootBranch" - LoadLocalBranch{} -> "LoadLocalBranch" - Merge{} -> "Merge" - ViewRemoteBranch{} -> "ViewRemoteBranch" - ImportRemoteBranch{} -> "ImportRemoteBranch" - SyncLocalRootBranch{} -> "SyncLocalRootBranch" - SyncRemoteRootBranch{} -> "SyncRemoteRootBranch" - AppendToReflog{} -> "AppendToReflog" - LoadReflog -> "LoadReflog" - LoadTerm{} -> "LoadTerm" - LoadType{} -> "LoadType" - LoadTypeOfTerm{} -> "LoadTypeOfTerm" - PutTerm{} -> "PutTerm" - PutDecl{} -> "PutDecl" - IsTerm{} -> "IsTerm" - IsType{} -> "IsType" - GetDependents{} -> "GetDependents" - GetDependencies{} -> "GetDependencies" - GetDerivedDependencies{} -> "GetDerivedDependencies" - GetTermsOfType{} -> "GetTermsOfType" - GetTermsMentioningType{} -> "GetTermsMentioningType" - Execute{} -> "Execute" - CreateAuthorInfo{} -> "CreateAuthorInfo" - RuntimeMain -> "RuntimeMain" - RuntimeTest -> "RuntimeTest" - HQNameQuery{} -> "HQNameQuery" - LoadSearchResults{} -> "LoadSearchResults" - GetDefinitionsBySuffixes{} -> "GetDefinitionsBySuffixes" - FindShallow{} -> "FindShallow" - ClearWatchCache{} -> "ClearWatchCache" - MakeStandalone{} -> "MakeStandalone" - FuzzySelect{} -> "FuzzySelect" - ConstructorsOfType{} -> "ConstructorsOfType" + Eval {} -> "Eval" + UI -> "UI" + DocsToHtml {} -> "DocsToHtml" + ConfigLookup {} -> "ConfigLookup" + Input -> "Input" + Notify {} -> "Notify" + NotifyNumbered {} -> "NotifyNumbered" + AddDefsToCodebase {} -> "AddDefsToCodebase" + CodebaseHashLength -> "CodebaseHashLength" + TypeReferencesByShortHash {} -> "TypeReferencesByShortHash" + TermReferencesByShortHash {} -> "TermReferencesByShortHash" + TermReferentsByShortHash {} -> "TermReferentsByShortHash" + BranchHashLength -> "BranchHashLength" + BranchHashesByPrefix {} -> "BranchHashesByPrefix" + ParseType {} -> "ParseType" + LoadSource {} -> "LoadSource" + Typecheck {} -> "Typecheck" + TypecheckFile {} -> "TypecheckFile" + Evaluate {} -> "Evaluate" + Evaluate1 {} -> "Evaluate1" + PutWatch {} -> "PutWatch" + LoadWatches {} -> "LoadWatches" + LoadLocalRootBranch -> "LoadLocalRootBranch" + LoadLocalBranch {} -> "LoadLocalBranch" + Merge {} -> "Merge" + ViewRemoteBranch {} -> "ViewRemoteBranch" + ImportRemoteBranch {} -> "ImportRemoteBranch" + SyncLocalRootBranch {} -> "SyncLocalRootBranch" + SyncRemoteRootBranch {} -> "SyncRemoteRootBranch" + AppendToReflog {} -> "AppendToReflog" + LoadReflog -> "LoadReflog" + LoadTerm {} -> "LoadTerm" + LoadType {} -> "LoadType" + LoadTypeOfTerm {} -> "LoadTypeOfTerm" + PutTerm {} -> "PutTerm" + PutDecl {} -> "PutDecl" + IsTerm {} -> "IsTerm" + IsType {} -> "IsType" + GetDependents {} -> "GetDependents" + GetDependencies {} -> "GetDependencies" + GetDerivedDependencies {} -> "GetDerivedDependencies" + GetTermsOfType {} -> "GetTermsOfType" + GetTermsMentioningType {} -> "GetTermsMentioningType" + Execute {} -> "Execute" + CreateAuthorInfo {} -> "CreateAuthorInfo" + RuntimeMain -> "RuntimeMain" + RuntimeTest -> "RuntimeTest" + HQNameQuery {} -> "HQNameQuery" + LoadSearchResults {} -> "LoadSearchResults" + GetDefinitionsBySuffixes {} -> "GetDefinitionsBySuffixes" + FindShallow {} -> "FindShallow" + ClearWatchCache {} -> "ClearWatchCache" + MakeStandalone {} -> "MakeStandalone" + FuzzySelect {} -> "FuzzySelect" + ConstructorsForTypeDeclaration {} -> "ConstructorsForTypeDeclaration" diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleCommand.hs b/unison-cli/src/Unison/Codebase/Editor/HandleCommand.hs index 131700c143..f723ef092d 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleCommand.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleCommand.hs @@ -202,7 +202,7 @@ commandLine config awaitInput setBranchRef rt notifyUser notifyNumbered loadSour Runtime.compileTo rt (() <$ cl) ppe ref (out <> ".uc") ClearWatchCache -> lift $ Codebase.clearWatches codebase FuzzySelect opts display choices -> liftIO $ Fuzzy.fuzzySelect opts display choices - ConstructorsOfType typeRef -> do + ConstructorsForType typeRef -> do allTermsOfType <- liftIO $ Codebase.termsOfTypeByReference codebase typeRef -- Filter to only return the constructors of that type, rather than ALL terms. -- There should be a more efficient way to do this once diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/NamespaceDependencies.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/NamespaceDependencies.hs index 7c6dd0c581..4d938865cd 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/NamespaceDependencies.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/NamespaceDependencies.hs @@ -32,7 +32,7 @@ namespaceDependencies :: forall m i v. Branch0 m -> Action m i v (Map Referent ( namespaceDependencies branch = do let refToDeps :: Reference.Id -> Action m i v (Map Referent (Set Name)) refToDeps refId = do - dependencies <- fmap Referent.fromReference . Set.toList <$> eval (GetDependencies refId) + dependencies <- fmap Referent.fromTermReference . Set.toList <$> eval (GetDependencies refId) ( dependencies & fmap \dep -> Map.singleton dep (localNameByReference (Reference.fromId refId)) ) @@ -60,7 +60,7 @@ namespaceDependencies branch = do Map.unions . concat <$> ( for (Map.toList onlyExternalDeps) $ \case (ref, deps) -> do - constructors <- eval (ConstructorsOfType (Referent.toReference ref)) + constructors <- eval (ConstructorsForType (Referent.toReference ref)) let externalConstrs = constructors `Set.difference` currentBranchTermsAndConstructors pure $ [ Map.singleton ref deps, @@ -73,12 +73,12 @@ namespaceDependencies branch = do currentBranchTermsAndConstructors :: Set Referent currentBranchTermsAndConstructors = Relation.dom (Branch.deepTerms branch) localNameByReference :: Reference -> (Set Name) - localNameByReference ref = Relation.lookupDom (Referent.fromReference ref) (Branch.deepTerms branch) + localNameByReference ref = Relation.lookupDom (Referent.fromTermReference ref) (Branch.deepTerms branch) currentBranchTypes :: Set Reference currentBranchTypes = Relation.dom (Branch.deepTypes branch) typeAndTermRefsInCurrentBranch :: Set Referent typeAndTermRefsInCurrentBranch = - Set.map Referent.fromReference (Relation.dom (Branch.deepTypes branch)) + Set.map Referent.fromTermReference (Relation.dom (Branch.deepTypes branch)) <> currentBranchTermsAndConstructors -- Since metadata is only linked by reference, not by name, @@ -99,6 +99,6 @@ namespaceDependencies branch = do in Map.unionWith (<>) typeMetadataRefs termMetadataRefs externalMetadata :: Map Referent (Set Name) externalMetadata = branchMetadataReferences - & Map.mapKeys Referent.fromReference + & Map.mapKeys Referent.fromTermReference & Map.filterWithKey (\ref _ -> ref `Set.notMember` typeAndTermRefsInCurrentBranch) diff --git a/unison-core/src/Unison/Referent.hs b/unison-core/src/Unison/Referent.hs index fa7175966f..c7da3cc06e 100644 --- a/unison-core/src/Unison/Referent.hs +++ b/unison-core/src/Unison/Referent.hs @@ -11,8 +11,8 @@ module Unison.Referent pattern ConId, fold, toReference, - fromReference, - fromReferenceId, + fromTermReference, + fromTermReferenceId, fromText, -- * Lenses @@ -98,12 +98,12 @@ toString = Text.unpack . toText toReference :: Referent -> Reference toReference = toReference' --- | Inject a Reference into a Referent -fromReference :: Reference -> Referent -fromReference r = Ref r +-- | Inject a Term Reference into a Referent +fromTermReference :: Reference -> Referent +fromTermReference r = Ref r -fromReferenceId :: Reference.Id -> Referent -fromReferenceId = fromReference . Reference.fromId +fromTermReferenceId :: Reference.Id -> Referent +fromTermReferenceId = fromTermReference . Reference.fromId isPrefixOf :: ShortHash -> Referent -> Bool isPrefixOf sh r = SH.isPrefixOf sh (toShortHash r)