summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-12-31 09:52:51 -0800
committerGitHub <noreply@github.com>2024-12-31 09:52:51 -0800
commita8471a1d9a5591202bf4a552aa7d1bf11088fdce (patch)
treebd8c9fe1c761c5328f0c6485fc9d31d8e3ec69c2 /source
parentb7eb585241b3f3519ff494004efedae680cb44b9 (diff)
Fix `getInheritanceInfo` for `ExtractExistentialType`. (#5971)
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-impl.h4
-rw-r--r--source/slang/slang-check-inheritance.cpp21
-rw-r--r--source/slang/slang-ir-legalize-types.cpp4
-rw-r--r--source/slang/slang-syntax.cpp20
4 files changed, 26 insertions, 23 deletions
diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h
index f464f9298..300596caa 100644
--- a/source/slang/slang-check-impl.h
+++ b/source/slang/slang-check-impl.h
@@ -789,12 +789,12 @@ private:
InheritanceInfo _getInheritanceInfo(
DeclRef<Decl> declRef,
- DeclRefType* correspondingType,
+ Type* selfType,
InheritanceCircularityInfo* circularityInfo);
InheritanceInfo _calcInheritanceInfo(Type* type, InheritanceCircularityInfo* circularityInfo);
InheritanceInfo _calcInheritanceInfo(
DeclRef<Decl> declRef,
- DeclRefType* correspondingType,
+ Type* selfType,
InheritanceCircularityInfo* circularityInfo);
void getDependentGenericParentImpl(DeclRef<GenericDecl>& genericParent, DeclRef<Decl> declRef);
diff --git a/source/slang/slang-check-inheritance.cpp b/source/slang/slang-check-inheritance.cpp
index 4b0ec0f55..f774aae38 100644
--- a/source/slang/slang-check-inheritance.cpp
+++ b/source/slang/slang-check-inheritance.cpp
@@ -76,7 +76,7 @@ bool SharedSemanticsContext::_checkForCircularityInExtensionTargetType(
InheritanceInfo SharedSemanticsContext::_getInheritanceInfo(
DeclRef<Decl> declRef,
- DeclRefType* declRefType,
+ Type* selfType,
InheritanceCircularityInfo* circularityInfo)
{
// Just as with `Type`s, we cache and re-use the inheritance
@@ -95,7 +95,7 @@ InheritanceInfo SharedSemanticsContext::_getInheritanceInfo(
//
m_mapDeclRefToInheritanceInfo[declRef] = InheritanceInfo();
- auto info = _calcInheritanceInfo(declRef, declRefType, circularityInfo);
+ auto info = _calcInheritanceInfo(declRef, selfType, circularityInfo);
m_mapDeclRefToInheritanceInfo[declRef] = info;
getSession()->m_typeDictionarySize = Math::Max(
@@ -154,7 +154,7 @@ DeclRef<GenericDecl> SharedSemanticsContext::getDependentGenericParent(DeclRef<D
InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo(
DeclRef<Decl> declRef,
- DeclRefType* declRefType,
+ Type* selfType,
InheritanceCircularityInfo* circularityInfo)
{
// This method is the main engine for computing linearized inheritance
@@ -200,14 +200,6 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo(
//
FacetList::Builder allFacets;
- // It is possible that `declRef` is itself a type declaration,
- // in which case `declRefType` will be the coresponding type.
- // However, if `declRef` is an `extension` declaration, we
- // will extract the type that the extension applies to, so
- // that we can have a consistent "self type" to represent
- // the type that is at the root of the inheritance list.
- //
- Type* selfType = declRefType;
Facet::Kind selfFacetKind = Facet::Kind::Type;
auto astBuilder = _getASTBuilder();
@@ -1043,6 +1035,13 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo(
//
return _getInheritanceInfo(declRefType->getDeclRef(), declRefType, circularityInfo);
}
+ else if (auto extractExistentialType = as<ExtractExistentialType>(type))
+ {
+ return _getInheritanceInfo(
+ extractExistentialType->getThisTypeDeclRef(),
+ extractExistentialType,
+ circularityInfo);
+ }
else if (auto conjunctionType = as<AndType>(type))
{
// In this case, we have a type of the form `L & R`,
diff --git a/source/slang/slang-ir-legalize-types.cpp b/source/slang/slang-ir-legalize-types.cpp
index 9154277f5..962514b08 100644
--- a/source/slang/slang-ir-legalize-types.cpp
+++ b/source/slang/slang-ir-legalize-types.cpp
@@ -837,7 +837,7 @@ static LegalVal legalizeDebugVar(
case LegalType::Flavor::simple:
{
auto legalVal = context->builder->emitDebugVar(
- type.getSimple(),
+ tryGetPointedToType(context->builder, type.getSimple()),
originalInst->getSource(),
originalInst->getLine(),
originalInst->getCol(),
@@ -887,7 +887,7 @@ static LegalVal legalizeDebugValue(
{
auto ordinaryVal = legalizeDebugValue(
context,
- debugVar,
+ debugVar.getPair()->ordinaryVal,
debugValue.getPair()->ordinaryVal,
originalInst);
return ordinaryVal;
diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp
index 5dc6ca695..6fdd5088a 100644
--- a/source/slang/slang-syntax.cpp
+++ b/source/slang/slang-syntax.cpp
@@ -701,11 +701,18 @@ Type* DeclRefType::create(ASTBuilder* astBuilder, DeclRef<Decl> declRef)
}
return declRefType;
}
- else if (as<ThisTypeDecl>(declRef.getDecl()) && as<DirectDeclRef>(declRef.declRefBase))
+ else if (as<ThisTypeDecl>(declRef.getDecl()))
{
- declRef = createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, declRef);
+ if (as<DirectDeclRef>(declRef.declRefBase))
+ {
+ declRef = createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, declRef);
- return astBuilder->getOrCreate<ThisType>(declRef.declRefBase);
+ return astBuilder->getOrCreate<ThisType>(declRef.declRefBase);
+ }
+ else if (auto lookupDeclRef = as<LookupDeclRef>(declRef.declRefBase))
+ {
+ return lookupDeclRef->getWitness()->getSub();
+ }
}
else if (auto typedefDecl = as<TypeDefDecl>(declRef.getDecl()))
{
@@ -714,12 +721,9 @@ Type* DeclRefType::create(ASTBuilder* astBuilder, DeclRef<Decl> declRef)
typedefDecl->type.type->substitute(astBuilder, SubstitutionSet(declRef)));
return astBuilder->getErrorType();
}
- else
- {
- declRef = createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, declRef);
- return astBuilder->getOrCreate<DeclRefType>(declRef.declRefBase);
- }
+ declRef = createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, declRef);
+ return astBuilder->getOrCreate<DeclRefType>(declRef.declRefBase);
}
//