Skip to content

Commit d4aaa6c

Browse files
authored
Merge pull request shader-slang#268 from csyonghe/work1
Cleanup of "support generic interface method".
2 parents e171080 + f408165 commit d4aaa6c

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

source/slang/check.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,15 @@ namespace Slang
16091609
else
16101610
return false;
16111611
}
1612+
else if (auto genValMbr = genMbr.As<GenericValueParamDecl>())
1613+
{
1614+
if (auto requiredGenValMbr = requiredGenMbr.As<GenericValueParamDecl>())
1615+
{
1616+
return genValMbr->type->Equals(requiredGenValMbr->type);
1617+
}
1618+
else
1619+
return false;
1620+
}
16121621
else if (auto genTypeConstraintMbr = genMbr.As<GenericTypeConstraintDecl>())
16131622
{
16141623
if (auto requiredTypeConstraintMbr = requiredGenMbr.As<GenericTypeConstraintDecl>())

source/slang/syntax.cpp

+32-41
Original file line numberDiff line numberDiff line change
@@ -1529,57 +1529,48 @@ void Type::accept(IValVisitor* visitor, void* extra)
15291529

15301530
RefPtr<Val> DeclaredSubtypeWitness::SubstituteImpl(Substitutions* subst, int * ioDiff)
15311531
{
1532-
DeclRef<GenericTypeParamDecl> genParamDeclRef;
1533-
if (auto subDeclRefType = this->sub.As<DeclRefType>())
1532+
if (auto genConstraintDecl = declRef.As<GenericTypeConstraintDecl>())
15341533
{
1535-
genParamDeclRef = subDeclRefType->declRef.As<GenericTypeParamDecl>();
1536-
}
1537-
if (!genParamDeclRef)
1538-
return this;
1539-
auto genParamDecl = genParamDeclRef.getDecl();
1540-
// search for a substitution that might apply to us
1541-
for (auto s = subst; s; s = s->outer.Ptr())
1542-
{
1543-
if (auto genericSubst = dynamic_cast<GenericSubstitution*>(s))
1534+
// search for a substitution that might apply to us
1535+
for (auto s = subst; s; s = s->outer.Ptr())
15441536
{
1545-
// the generic decl associated with the substitution list must be
1546-
// the generic decl that declared this parameter
1547-
auto genericDecl = genericSubst->genericDecl;
1548-
if (genericDecl != genParamDecl->ParentDecl)
1549-
continue;
1550-
bool found = false;
1551-
int index = 0;
1552-
for (auto m : genericDecl->Members)
1537+
if (auto genericSubst = dynamic_cast<GenericSubstitution*>(s))
15531538
{
1554-
if (m.Ptr() == genParamDecl)
1555-
{
1556-
// We've found it, so return the corresponding specialization argument
1557-
(*ioDiff)++;
1558-
found = true;
1559-
break;
1560-
}
1561-
else if (auto typeParam = m.As<GenericTypeParamDecl>())
1562-
{
1563-
index++;
1564-
}
1565-
else if (auto valParam = m.As<GenericValueParamDecl>())
1539+
// the generic decl associated with the substitution list must be
1540+
// the generic decl that declared this parameter
1541+
auto genericDecl = genericSubst->genericDecl;
1542+
if (genericDecl != genConstraintDecl.getDecl()->ParentDecl)
1543+
continue;
1544+
bool found = false;
1545+
UInt index = 0;
1546+
for (auto m : genericDecl->Members)
15661547
{
1567-
index++;
1548+
if (auto constraintParam = m.As<GenericTypeConstraintDecl>())
1549+
{
1550+
if (constraintParam.Ptr() == declRef.getDecl())
1551+
{
1552+
found = true;
1553+
break;
1554+
}
1555+
index++;
1556+
}
15681557
}
1569-
else
1558+
if (found)
15701559
{
1560+
(*ioDiff)++;
1561+
auto ordinaryParamCount = genericDecl->getMembersOfType<GenericTypeParamDecl>().Count() +
1562+
genericDecl->getMembersOfType<GenericValueParamDecl>().Count();
1563+
SLANG_ASSERT(index + ordinaryParamCount < genericSubst->args.Count());
1564+
return genericSubst->args[index + ordinaryParamCount];
15711565
}
15721566
}
1573-
if (found)
1574-
{
1575-
auto ordinaryParamCount = genericDecl->getMembersOfType<GenericTypeParamDecl>().Count() +
1576-
genericDecl->getMembersOfType<GenericValueParamDecl>().Count();
1577-
SLANG_ASSERT(ordinaryParamCount + index < genericSubst->args.Count());
1578-
return genericSubst->args[ordinaryParamCount + index];
1579-
}
15801567
}
15811568
}
1582-
return this;
1569+
RefPtr<DeclaredSubtypeWitness> rs = new DeclaredSubtypeWitness();
1570+
rs->sub = sub->SubstituteImpl(subst, ioDiff).As<Type>();
1571+
rs->sup = sup->SubstituteImpl(subst, ioDiff).As<Type>();
1572+
rs->declRef = declRef.SubstituteImpl(subst, ioDiff);
1573+
return rs;
15831574
}
15841575

15851576
String DeclaredSubtypeWitness::ToString()

0 commit comments

Comments
 (0)