New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit definition search to provided relativeTo #3194
Changes from all commits
9623359
5ea90e7
c0efe66
783d988
715d624
b1e4558
c8a0ab2
c8a6802
2804022
de778d4
bad5acb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,8 +127,8 @@ module U.Codebase.Sqlite.Queries | |
resetNameLookupTables, | ||
insertTermNames, | ||
insertTypeNames, | ||
rootTermNames, | ||
rootTypeNames, | ||
rootTermNamesByPath, | ||
rootTypeNamesByPath, | ||
getNamespaceDefinitionCount, | ||
|
||
-- * garbage collection | ||
|
@@ -1521,26 +1521,38 @@ insertTypeNames names = | |
|] | ||
|
||
-- | Get the list of a term names in the root namespace according to the name lookup index | ||
rootTermNames :: Transaction [NamedRef (Referent.TextReferent, Maybe NamedRef.ConstructorType)] | ||
rootTermNames = do | ||
(fmap . fmap) unRow <$> queryListRow_ sql | ||
rootTermNamesByPath :: Maybe Text -> Transaction ([NamedRef (Referent.TextReferent, Maybe NamedRef.ConstructorType)], [NamedRef (Referent.TextReferent, Maybe NamedRef.ConstructorType)]) | ||
rootTermNamesByPath mayNamespace = do | ||
let (namespace, subnamespace) = case mayNamespace of | ||
Nothing -> ("", "*") | ||
Just namespace -> (namespace, globEscape namespace <> ".*") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should escape There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
results :: [Only Bool :. NamedRef (Referent.TextReferent :. Only (Maybe NamedRef.ConstructorType))] <- queryListRow sql (subnamespace, namespace, subnamespace, namespace) | ||
let (namesInNamespace, namesOutsideNamespace) = span (\(Only inNamespace :. _) -> inNamespace) results | ||
pure (fmap unRow . dropTag <$> namesInNamespace, fmap unRow . dropTag <$> namesOutsideNamespace) | ||
where | ||
dropTag (_ :. name) = name | ||
unRow (a :. Only b) = (a, b) | ||
sql = | ||
[here| | ||
SELECT reversed_name, referent_builtin, referent_component_hash, referent_component_index, referent_constructor_index, referent_constructor_type FROM term_name_lookup | ||
ORDER BY reversed_name ASC | ||
SELECT namespace GLOB ? OR namespace = ?, reversed_name, referent_builtin, referent_component_hash, referent_component_index, referent_constructor_index, referent_constructor_type FROM term_name_lookup | ||
ORDER BY (namespace GLOB ? OR namespace = ?) DESC | ||
|] | ||
|
||
-- | Get the list of a type names in the root namespace according to the name lookup index | ||
rootTypeNames :: Transaction [NamedRef Reference.TextReference] | ||
rootTypeNames = do | ||
queryListRow_ sql | ||
rootTypeNamesByPath :: Maybe Text -> Transaction ([NamedRef Reference.TextReference], [NamedRef Reference.TextReference]) | ||
rootTypeNamesByPath mayNamespace = do | ||
let (namespace, subnamespace) = case mayNamespace of | ||
Nothing -> ("", "*") | ||
Just namespace -> (namespace, globEscape namespace <> ".*") | ||
results :: [Only Bool :. NamedRef Reference.TextReference] <- queryListRow sql (subnamespace, namespace, subnamespace, namespace) | ||
let (namesInNamespace, namesOutsideNamespace) = span (\(Only inNamespace :. _) -> inNamespace) results | ||
pure (dropTag <$> namesInNamespace, dropTag <$> namesOutsideNamespace) | ||
where | ||
dropTag (_ :. name) = name | ||
sql = | ||
[here| | ||
SELECT reversed_name, reference_builtin, reference_component_hash, reference_component_index FROM type_name_lookup | ||
ORDER BY reversed_name ASC | ||
SELECT namespace GLOB ? OR namespace = ?, reversed_name, reference_builtin, reference_component_hash, reference_component_index FROM type_name_lookup | ||
ORDER BY (namespace GLOB ? OR namespace = ?) DESC | ||
|] | ||
|
||
before :: CausalHashId -> CausalHashId -> Transaction Bool | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import qualified U.Codebase.Referent as C.Referent | |
import U.Codebase.Sqlite.DbId (ObjectId) | ||
import qualified U.Codebase.Sqlite.NamedRef as S | ||
import qualified U.Codebase.Sqlite.ObjectType as OT | ||
import U.Codebase.Sqlite.Operations (NamesByPath (..)) | ||
import qualified U.Codebase.Sqlite.Operations as Ops | ||
import qualified U.Codebase.Sqlite.Queries as Q | ||
import U.Codebase.Sqlite.V2.Decl (saveDeclComponent) | ||
|
@@ -552,48 +553,52 @@ namesAtPath :: | |
Path -> | ||
Transaction ScopedNames | ||
namesAtPath path = do | ||
(termNames, typeNames) <- Ops.rootBranchNames | ||
let namespace = if path == Path.empty then Nothing else Just $ tShow path | ||
NamesByPath {termNamesInPath, termNamesExternalToPath, typeNamesInPath, typeNamesExternalToPath} <- Ops.rootNamesByPath namespace | ||
let termsInPath = convertTerms termNamesInPath | ||
let typesInPath = convertTypes typeNamesInPath | ||
let termsOutsidePath = convertTerms termNamesExternalToPath | ||
let typesOutsidePath = convertTypes typeNamesExternalToPath | ||
let allTerms :: [(Name, Referent.Referent)] | ||
allTerms = | ||
termNames <&> \(S.NamedRef {reversedSegments, ref = (ref, ct)}) -> | ||
let v1ref = runIdentity $ Cv.referent2to1 (const . pure . Cv.constructorType2to1 . fromMaybe (error "Required constructor type for constructor but it was null") $ ct) ref | ||
in (Name.fromReverseSegments (coerce reversedSegments), v1ref) | ||
allTerms = termsInPath <> termsOutsidePath | ||
let allTypes :: [(Name, Reference.Reference)] | ||
allTypes = | ||
typeNames <&> \(S.NamedRef {reversedSegments, ref}) -> | ||
(Name.fromReverseSegments (coerce reversedSegments), Cv.reference2to1 ref) | ||
allTypes = typesInPath <> typesOutsidePath | ||
let rootTerms = Rel.fromList allTerms | ||
let rootTypes = Rel.fromList allTypes | ||
let absoluteRootNames = Names {terms = rootTerms, types = rootTypes} | ||
let (relativeScopedNames, absoluteExternalNames) = | ||
let absoluteExternalNames = Names {terms = Rel.fromList termsOutsidePath, types = Rel.fromList typesOutsidePath} | ||
let relativeScopedNames = | ||
case path of | ||
Path.Empty -> (absoluteRootNames, mempty) | ||
Path.Empty -> (absoluteRootNames) | ||
p -> | ||
let reversedPathSegments = reverse . Path.toList $ p | ||
(relativeTerms, externalTerms) = foldMap (partitionByPathPrefix reversedPathSegments) allTerms | ||
(relativeTypes, externalTypes) = foldMap (partitionByPathPrefix reversedPathSegments) allTypes | ||
in ( Names {terms = Rel.fromList relativeTerms, types = Rel.fromList relativeTypes}, | ||
Names {terms = Rel.fromList externalTerms, types = Rel.fromList externalTypes} | ||
) | ||
relativeTerms = stripPathPrefix reversedPathSegments <$> termsInPath | ||
relativeTypes = stripPathPrefix reversedPathSegments <$> typesInPath | ||
in (Names {terms = Rel.fromList relativeTerms, types = Rel.fromList relativeTypes}) | ||
pure $ | ||
ScopedNames | ||
{ absoluteExternalNames, | ||
relativeScopedNames, | ||
absoluteRootNames | ||
} | ||
where | ||
convertTypes names = | ||
names <&> \(S.NamedRef {reversedSegments, ref}) -> | ||
(Name.fromReverseSegments (coerce reversedSegments), Cv.reference2to1 ref) | ||
convertTerms names = | ||
names <&> \(S.NamedRef {reversedSegments, ref = (ref, ct)}) -> | ||
let v1ref = runIdentity $ Cv.referent2to1 (const . pure . Cv.constructorType2to1 . fromMaybe (error "Required constructor type for constructor but it was null") $ ct) ref | ||
in (Name.fromReverseSegments (coerce reversedSegments), v1ref) | ||
|
||
-- If the given prefix matches the given name, the prefix is stripped and it's collected | ||
-- on the left, otherwise it's left as-is and collected on the right. | ||
-- >>> partitionByPathPrefix ["b", "a"] ("a.b.c", ()) | ||
-- ([(c,())],[]) | ||
-- | ||
-- >>> partitionByPathPrefix ["y", "x"] ("a.b.c", ()) | ||
-- ([],[(a.b.c,())]) | ||
partitionByPathPrefix :: [NameSegment] -> (Name, r) -> ([(Name, r)], [(Name, r)]) | ||
partitionByPathPrefix reversedPathSegments (n, ref) = | ||
-- >>> stripPathPrefix ["b", "a"] ("a.b.c", ()) | ||
-- ([(c,())]) | ||
stripPathPrefix :: [NameSegment] -> (Name, r) -> (Name, r) | ||
stripPathPrefix reversedPathSegments (n, ref) = | ||
case Name.stripReversedPrefix n reversedPathSegments of | ||
Nothing -> (mempty, [(n, ref)]) | ||
Just stripped -> ([(Name.makeRelative stripped, ref)], mempty) | ||
Nothing -> error $ "Expected name to be in namespace" <> show (n, reverse reversedPathSegments) | ||
Just stripped -> (Name.makeRelative stripped, ref) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest I think we have a lot of unnecessary work going on with names but it's extremely difficult to get my head around it and make too many changes at once without breaking everything and not knowing why haha. I think what I envision is that actually names objects should probably just have all absolutely qualified names, then the PPE should make them relative and/or suffixify them when it's time to display them. |
||
|
||
-- | Update the root namespace names index which is used by the share server for serving api | ||
-- requests. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I have the namespace in sqlite it's easy to partition names in sqlite which is likely faster than doing it in Haskell.