From 453683bf44f2112719802eaac2b332d49eebd640 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 19 Aug 2024 15:03:56 -0700 Subject: Tuple swizzling, concat, comparison and `countof`. (#4856) * Tuple swizzling and element access. * Update proposal status. * Cleanup. * Fix merrge error. * Address review. --- source/slang/slang-lookup.cpp | 105 +++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 43 deletions(-) (limited to 'source/slang/slang-lookup.cpp') diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index c1895d754..7acaa030b 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -387,53 +387,16 @@ static void _lookUpMembersInSuperType( _lookUpMembersInSuperTypeImpl(astBuilder, name, leafType, superType, leafIsSuperWitness, request, ioResult, &breadcrumb); } -static void _lookUpMembersInSuperTypeDeclImpl( - ASTBuilder* astBuilder, +static void _lookupMembersInSuperTypeFacets(ASTBuilder* astBuilder, Name* name, - DeclRef declRef, + Type* selfType, + InheritanceInfo const& inheritanceInfo, LookupRequest const& request, LookupResult& ioResult, BreadcrumbInfo* inBreadcrumbs) { - auto semantics = request.semantics; - if (!as(declRef.getDecl()) && getText(name) == "This") - { - // If we are looking for `This` in anything other than an InterfaceDecl, - // we just need to return the declRef itself. - AddToLookupResult(ioResult, CreateLookupResultItem(declRef, inBreadcrumbs)); - return; - } - - // If the semantics context hasn't been established yet (e.g. when looking up during parsing), - // we simply do a direct lookup without considering subtypes or extensions. - // - if (!semantics) - { - // In this case we can only lookup in an aggregate type. - if (auto aggTypeDeclBaseRef = declRef.as()) - { - _lookUpDirectAndTransparentMembers(astBuilder, name, aggTypeDeclBaseRef.getDecl(), aggTypeDeclBaseRef, request, ioResult, inBreadcrumbs); - } - return; - } - - ensureDecl(semantics, declRef.getDecl(), DeclCheckState::ReadyForLookup); - - // With semantics context, we can do a comprehensive lookup by scanning through - // the linearized inheritance list. + - auto selfType = DeclRefType::create(astBuilder, declRef); - InheritanceInfo inheritanceInfo; - if (auto extDeclRef = declRef.as()) - { - inheritanceInfo = semantics->getShared()->getInheritanceInfo(extDeclRef); - } - else - { - selfType = selfType->getCanonicalType(); - inheritanceInfo = semantics->getShared()->getInheritanceInfo(selfType); - } - for (auto facet : inheritanceInfo.facets) { auto containerDeclRef = facet->getDeclRef().as(); @@ -457,12 +420,12 @@ static void _lookUpMembersInSuperTypeDeclImpl( continue; } // If we are looking up only immediate members, ignore non "Self" facets or extension to "Self" - else if (int(request.options) & int(LookupOptions::IgnoreInheritance) + else if (int(request.options) & int(LookupOptions::IgnoreInheritance) && (facet.getImpl()->directness != Facet::Directness::Self && (!extensionFacet || !extensionFacet->targetType.type->equals(selfType)) )) { - continue; + continue; } // Some things that are syntactically `InheritanceDecl`s don't actually @@ -527,6 +490,56 @@ static void _lookUpMembersInSuperTypeDeclImpl( } } +static void _lookUpMembersInSuperTypeDeclImpl( + ASTBuilder* astBuilder, + Name* name, + DeclRef declRef, + LookupRequest const& request, + LookupResult& ioResult, + BreadcrumbInfo* inBreadcrumbs) +{ + auto semantics = request.semantics; + if (!as(declRef.getDecl()) && getText(name) == "This") + { + // If we are looking for `This` in anything other than an InterfaceDecl, + // we just need to return the declRef itself. + AddToLookupResult(ioResult, CreateLookupResultItem(declRef, inBreadcrumbs)); + return; + } + + // If the semantics context hasn't been established yet (e.g. when looking up during parsing), + // we simply do a direct lookup without considering subtypes or extensions. + // + if (!semantics) + { + // In this case we can only lookup in an aggregate type. + if (auto aggTypeDeclBaseRef = declRef.as()) + { + _lookUpDirectAndTransparentMembers(astBuilder, name, aggTypeDeclBaseRef.getDecl(), aggTypeDeclBaseRef, request, ioResult, inBreadcrumbs); + } + return; + } + + ensureDecl(semantics, declRef.getDecl(), DeclCheckState::ReadyForLookup); + + // With semantics context, we can do a comprehensive lookup by scanning through + // the linearized inheritance list. + + auto selfType = DeclRefType::create(astBuilder, declRef); + InheritanceInfo inheritanceInfo; + if (auto extDeclRef = declRef.as()) + { + inheritanceInfo = semantics->getShared()->getInheritanceInfo(extDeclRef); + } + else + { + selfType = selfType->getCanonicalType(); + inheritanceInfo = semantics->getShared()->getInheritanceInfo(selfType); + } + + _lookupMembersInSuperTypeFacets(astBuilder, name, selfType, inheritanceInfo, request, ioResult, inBreadcrumbs); +} + static void _lookUpMembersInSuperTypeImpl( ASTBuilder* astBuilder, Name* name, @@ -565,6 +578,12 @@ static void _lookUpMembersInSuperTypeImpl( _lookUpMembersInSuperTypeDeclImpl(astBuilder, name, declRef, request, ioResult, inBreadcrumbs); } + else if (auto eachType = as(superType)) + { + auto canEachType = eachType->getCanonicalType(); + InheritanceInfo inheritanceInfo = request.semantics->getShared()->getInheritanceInfo(canEachType); + _lookupMembersInSuperTypeFacets(astBuilder, name, canEachType, inheritanceInfo, request, ioResult, inBreadcrumbs); + } else if (auto extractExistentialType = as(superType)) { // We want lookup to be performed on the underlying interface type of the existential, -- cgit v1.2.3