summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-expr.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-10-27 11:06:14 -0700
committerGitHub <noreply@github.com>2022-10-27 11:06:14 -0700
commit8e11063bfcec528e70f5e80e5db9fca7d4016737 (patch)
tree60a4a492e732479bb1f72e76675b2b494c140b6b /source/slang/slang-check-expr.cpp
parentf7f0dcadd3b2aca4c0bcd03a96e11c617cf69fc2 (diff)
Auto synthesis of IDifferntial interface methods. (#2469)
* Auto synthesis of IDifferntial interface methods. * Add comments. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
-rw-r--r--source/slang/slang-check-expr.cpp41
1 files changed, 27 insertions, 14 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp
index d69cd39ed..d1e737720 100644
--- a/source/slang/slang-check-expr.cpp
+++ b/source/slang/slang-check-expr.cpp
@@ -405,14 +405,17 @@ namespace Slang
switch (item.declRef.getDecl()->astNodeType)
{
case ASTNodeType::AssocTypeDecl:
- return maybeUseSynthesizedTypeDeclForLookupResult(item, originalExpr);
+ break;
+ case ASTNodeType::FuncDecl:
+ // We don't need to intercept lookup results with synthesized decls for methods,
+ // because function lookups will only take place when we are checking the decl bodies.
+ // At that point conformance check and synthesis is already done so they will always resolve
+ // to the synthesized method.
+ return nullptr;
default:
return nullptr;
}
- }
- Expr* SemanticsVisitor::maybeUseSynthesizedTypeDeclForLookupResult(LookupResultItem const& item, Expr* originalExpr)
- {
// We need to check if the lookup should resolve to a definition in an implementation type
// if it existed.
// This will be the case when the lookup is initiated from the concrete implementation type instead of
@@ -425,7 +428,7 @@ namespace Slang
// We will only ever need to synthesis a type to satisfy an associatedtype requirement.
// In this case the lookup should have resolved to a known associatedtype decl.
- auto builtinAssocTypeAttr = item.declRef.getDecl()->findModifier<BuiltinAssociatedTypeRequirementAttribute>();
+ auto builtinAssocTypeAttr = item.declRef.getDecl()->findModifier<BuiltinRequirementAttribute>();
if (!builtinAssocTypeAttr)
return nullptr;
@@ -465,22 +468,32 @@ namespace Slang
if (!parent)
return nullptr;
- // If we reach here, we are expecting a synthesized associated type defined in `subType`.
- // Instead of returning a DeclRefExpr to the requirement decl, we synthesize a placeholder type
+ // If we reach here, we are expecting a synthesized decl defined in `subType`.
+ // Instead of returning a DeclRefExpr to the requirement decl, we synthesize a placeholder decl
// in `subType` and return a DeclRefExpr to the synthesized decl.
- auto assocType = m_astBuilder->create<StructDecl>();
- assocType->parentDecl = parent;
- assocType->nameAndLoc.name = item.declRef.getName();
- assocType->loc = parent->loc;
- parent->members.add(assocType);
+
+ Decl* synthesizedDecl = nullptr;
+ switch (builtinAssocTypeAttr->kind)
+ {
+ case BuiltinRequirementKind::DifferentialType:
+ synthesizedDecl = m_astBuilder->create<StructDecl>();
+ break;
+ default:
+ break;
+ }
+ synthesizedDecl = m_astBuilder->create<StructDecl>();
+ synthesizedDecl->parentDecl = parent;
+ synthesizedDecl->nameAndLoc.name = item.declRef.getName();
+ synthesizedDecl->loc = parent->loc;
+ parent->members.add(synthesizedDecl);
parent->invalidateMemberDictionary();
// Mark the newly synthesized decl as `ToBeSynthesized` so future checking can differentiate it
// from user-provided definitions, and proceed to fill in its definition.
auto toBeSynthesized = m_astBuilder->create<ToBeSynthesizedModifier>();
- addModifier(assocType, toBeSynthesized);
+ addModifier(synthesizedDecl, toBeSynthesized);
- return ConstructDeclRefExpr(makeDeclRef(assocType), nullptr, originalExpr->loc, originalExpr);
+ return ConstructDeclRefExpr(makeDeclRef(synthesizedDecl), nullptr, originalExpr->loc, originalExpr);
}
Expr* SemanticsVisitor::ConstructLookupResultExpr(