Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Nov 12, 2021
1 parent faf3346 commit ceee270
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 74 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,3 +13,4 @@ dist-newstyle

# GHC
*.hie
*.prof
8 changes: 4 additions & 4 deletions parser-typechecker/src/Unison/Codebase/Type.hs
Expand Up @@ -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
Expand Down
114 changes: 57 additions & 57 deletions unison-cli/src/Unison/Codebase/Editor/Command.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/Codebase/Editor/HandleCommand.hs
Expand Up @@ -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
Expand Down
Expand Up @@ -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))
)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
14 changes: 7 additions & 7 deletions unison-core/src/Unison/Referent.hs
Expand Up @@ -11,8 +11,8 @@ module Unison.Referent
pattern ConId,
fold,
toReference,
fromReference,
fromReferenceId,
fromTermReference,
fromTermReferenceId,
fromText,

-- * Lenses
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ceee270

Please sign in to comment.