From 020a16072923a66ae0985be618fd32310aa87242 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 16 Jul 2025 23:43:06 -0700 Subject: Improve lookup performance. (#7798) * Improve lookup performance. * Cleanup. * Improve autocompletion latency. --- source/slang/slang-lookup.cpp | 46 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'source/slang/slang-lookup.cpp') diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index a9b472776..0fd66abc3 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -357,6 +357,32 @@ static Type* _maybeSpecializeSuperType( return superType; } +void FacetImpl::init(ASTBuilder* astBuilder) +{ + if (directness != Facet::Directness::Self) + { + // Depending on the type of the facet, we may want to specialize the + // declRef that we are going to lookup in. If the facet represents + // an extension, we should just lookup in the extension decl. + // + // If the facet is an extension to an interface type, we should + // specialize the interface declRef to the concrete type that this + // extension applied to. + // + // If the facet represents an implementation of interface type, + // we should also specialize the interface declRef with the concrete + // type info. + // + declRefForMemberLookup = + _maybeSpecializeSuperTypeDeclRef(astBuilder, origin.declRef, getType(), subtypeWitness) + .as(); + } + else + { + declRefForMemberLookup = origin.declRef.as(); + } +} + static void _lookUpMembersInType( ASTBuilder* astBuilder, Name* name, @@ -490,27 +516,9 @@ static void _lookupMembersInSuperTypeFacets( BreadcrumbInfo* newBreadcrumbs = inBreadcrumbs; BreadcrumbInfo subtypeInfo; - auto parentDeclRef = containerDeclRef; + auto parentDeclRef = facet->declRefForMemberLookup; if (facet->directness != Facet::Directness::Self) { - // Depending on the type of the facet, we may want to specialize the - // declRef that we are going to lookup in. If the facet represents - // an extension, we should just lookup in the extension decl. - // - // If the facet is an extension to an interface type, we should - // specialize the interface declRef to the concrete type that this - // extension applied to. - // - // If the facet represents an implementation of interface type, - // we should also specialize the interface declRef with the concrete - // type info. - // - parentDeclRef = _maybeSpecializeSuperTypeDeclRef( - astBuilder, - containerDeclRef, - facet->getType(), - facet->subtypeWitness) - .as(); if (as(parentDeclRef.getDecl()) && getText(name) == "This") { // If we are going looking for `This` in a `ThisType`, we just need to return the -- cgit v1.2.3