summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2025-09-23 10:12:09 -0500
committerGitHub <noreply@github.com>2025-09-23 15:12:09 +0000
commit7740f7905fdebebdbe22011787d432b385f4cd9d (patch)
treedeadd3796624ae30dac3770b25098e21a222e31a /source/slang
parent9e34c6d949e97fc87a0a7be4ab37092b586aee9d (diff)
fix a crash when using type equality constaint (#8515)
Close #8193. When constructing `TransitiveTypeWitness` node, we should check if there is operand that represents two equal times. Currently, we only check whether the operand is `TypeEqualityWitness`, which is not good enough, because a `DeclaredSubtypeWitness` could also be representing two same types, in that case, we should also const fold this kind of witness. Fails to do so, we could finally ends up with a generating a lookup witness IR on a generic parameter that is not supposed to be looked up.
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-ast-base.h7
-rw-r--r--source/slang/slang-ast-builder.cpp10
-rw-r--r--source/slang/slang-ast-decl-ref.cpp8
3 files changed, 19 insertions, 6 deletions
diff --git a/source/slang/slang-ast-base.h b/source/slang/slang-ast-base.h
index 828bbdb5c..fe3554f84 100644
--- a/source/slang/slang-ast-base.h
+++ b/source/slang/slang-ast-base.h
@@ -673,12 +673,7 @@ class DeclRefBase : public Val
SourceLoc getNameLoc() const;
SourceLoc getLoc() const;
DeclRefBase* getParent();
- String toString() const
- {
- StringBuilder sb;
- const_cast<DeclRefBase*>(this)->toText(sb);
- return sb.produceString();
- }
+ String toString() const;
DeclRefBase* getBase();
void toText(StringBuilder& out);
};
diff --git a/source/slang/slang-ast-builder.cpp b/source/slang/slang-ast-builder.cpp
index f7304f308..be71fc334 100644
--- a/source/slang/slang-ast-builder.cpp
+++ b/source/slang/slang-ast-builder.cpp
@@ -936,6 +936,11 @@ top:
{
return bIsSubtypeOfCWitness;
}
+ else if (auto declAIsSubtypeOfBWitness = as<DeclaredSubtypeWitness>(aIsSubtypeOfBWitness))
+ {
+ if (declAIsSubtypeOfBWitness->isEquality())
+ return bIsSubtypeOfCWitness;
+ }
// Similarly, if `b == c`, then the `a <: b` witness is a witness for `a <: c`
//
@@ -943,6 +948,11 @@ top:
{
return aIsSubtypeOfBWitness;
}
+ else if (auto declBIsSubtypeOfCWitness = as<DeclaredSubtypeWitness>(bIsSubtypeOfCWitness))
+ {
+ if (declBIsSubtypeOfCWitness->isEquality())
+ return declBIsSubtypeOfCWitness;
+ }
// HACK: There is downstream code generation logic that assumes that
// a `TransitiveSubtypeWitness` will never have a transitive witness
diff --git a/source/slang/slang-ast-decl-ref.cpp b/source/slang/slang-ast-decl-ref.cpp
index 7eec32a3a..c054ef994 100644
--- a/source/slang/slang-ast-decl-ref.cpp
+++ b/source/slang/slang-ast-decl-ref.cpp
@@ -426,6 +426,14 @@ SourceLoc DeclRefBase::getLoc() const
return getDecl()->loc;
}
+// Keep this function here for better debuggin purpose
+String DeclRefBase::toString() const
+{
+ StringBuilder sb;
+ const_cast<DeclRefBase*>(this)->toText(sb);
+ return sb.produceString();
+}
+
DeclRefBase* DeclRefBase::getParent()
{
auto astBuilder = getCurrentASTBuilder();