From 071f1b6062b459928ebfd6f2f60a8d6ad021112b Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 14 Aug 2024 18:41:48 -0700 Subject: Variadic Generics Part 1: parsing and type checking. (#4833) --- source/slang/slang-check-inheritance.cpp | 40 ++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-check-inheritance.cpp') diff --git a/source/slang/slang-check-inheritance.cpp b/source/slang/slang-check-inheritance.cpp index 7320d0463..3e59c5e8d 100644 --- a/source/slang/slang-check-inheritance.cpp +++ b/source/slang/slang-check-inheritance.cpp @@ -266,7 +266,7 @@ namespace Slang addDirectBaseType(baseType, satisfyingWitness); } } - else if (auto genericTypeParamDeclRef = declRef.as()) + else if (auto genericTypeParamDeclRef = declRef.as()) { // The constraints placed on a generic type parameter are siblings of that // parameter in its parent `GenericDecl`, so we need to enumerate all of @@ -298,7 +298,14 @@ namespace Slang // auto subDeclRefType = as(subType); if (!subDeclRefType) - continue; + { + if (auto subEachType = as(subType)) + { + subDeclRefType = as(subEachType->getElementType()); + } + if (!subDeclRefType) + continue; + } if (subDeclRefType->getDeclRef() != genericTypeParamDeclRef) continue; @@ -922,6 +929,35 @@ namespace Slang info.facets = mergedFacets; return info; } + else if (auto eachType = as(type)) + { + auto elementInheritanceInfo = getInheritanceInfo(eachType->getElementType()); + SemanticsVisitor visitor(this); + auto directFacet = new(arena) Facet::Impl( + Facet::Kind::Type, + Facet::Directness::Self, + DeclRef(), + type, + visitor.createTypeEqualityWitness(type)); + Facet tail = directFacet; + for (auto facet : elementInheritanceInfo.facets) + { + if (facet->directness == Facet::Directness::Direct) + { + auto eachFacet = new(arena) Facet::Impl( + Facet::Kind::Type, + Facet::Directness::Direct, + facet->origin.declRef, + facet->origin.type, + astBuilder->getEachSubtypeWitness(type, facet->subtypeWitness->getSup(), facet->subtypeWitness)); + tail->next = eachFacet; + tail = eachFacet; + } + } + InheritanceInfo info; + info.facets = FacetList(directFacet); + return info; + } else { // As a fallback, any type not covered by the above cases will -- cgit v1.2.3