Skip to content

Commit 3ecfb53

Browse files
committed
[Macros] Type-check macro-generated extensions via the top-level decls of
the synthesized source file instead of a separate API to gather the extensions. This is how macro-generated extensions are visited everywhere else.
1 parent 83030a9 commit 3ecfb53

File tree

4 files changed

+10
-34
lines changed

4 files changed

+10
-34
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -924,12 +924,6 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
924924
bool visitFreestandingExpanded = true
925925
) const;
926926

927-
using ExtensionCallback = llvm::function_ref<void(ExtensionDecl *)>;
928-
929-
/// Iterate over each macro-expanded extension for this declaration,
930-
/// invoking the given callback with each extension.
931-
void forEachExpandedExtension(ExtensionCallback callback) const;
932-
933927
using MacroCallback = llvm::function_ref<void(CustomAttr *, MacroDecl *)>;
934928

935929
/// Iterate over each attached macro with the given role, invoking the

lib/AST/Decl.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -422,29 +422,6 @@ void Decl::visitAuxiliaryDecls(
422422
// FIXME: fold VarDecl::visitAuxiliaryDecls into this.
423423
}
424424

425-
void
426-
Decl::forEachExpandedExtension(ExtensionCallback callback) const {
427-
auto &ctx = getASTContext();
428-
auto *mutableThis = const_cast<Decl *>(this);
429-
auto *nominal = dyn_cast<NominalTypeDecl>(mutableThis);
430-
if (!nominal)
431-
return;
432-
433-
SourceManager &sourceMgr = ctx.SourceMgr;
434-
auto *moduleDecl = getModuleContext();
435-
auto conformanceBuffers =
436-
evaluateOrDefault(ctx.evaluator,
437-
ExpandConformanceMacros{nominal},
438-
{});
439-
for (auto bufferID : conformanceBuffers) {
440-
auto startLoc = sourceMgr.getLocForBufferStart(bufferID);
441-
auto *sourceFile = moduleDecl->getSourceFileContainingLocation(startLoc);
442-
for (auto *extension : sourceFile->getTopLevelDecls()) {
443-
callback(cast<ExtensionDecl>(extension));
444-
}
445-
}
446-
}
447-
448425
void Decl::forEachAttachedMacro(MacroRole role,
449426
MacroCallback macroCallback) const {
450427
for (auto customAttrConst : getSemanticAttrs().getAttributes<CustomAttr>()) {

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,11 +1936,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
19361936
"`" + VD->getBaseName().userFacingName().str() + "`");
19371937
}
19381938
}
1939-
1940-
// Visit macro-generated extensions.
1941-
decl->forEachExpandedExtension([&](ExtensionDecl *extension) {
1942-
DeclVisitor<DeclChecker>::visit(extension);
1943-
});
19441939
}
19451940

19461941

lib/Sema/TypeChecker.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,16 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, SourceFile *SF) const {
297297
}
298298
}
299299

300+
// Type-check macro-generated extensions.
301+
if (auto *synthesizedSF = SF->getSynthesizedFile()) {
302+
for (auto *decl : synthesizedSF->getTopLevelDecls()) {
303+
if (!decl->isImplicit()) {
304+
assert(isa<ExtensionDecl>(decl));
305+
TypeChecker::typeCheckDecl(decl);
306+
}
307+
}
308+
}
309+
300310
typeCheckDelayedFunctions(*SF);
301311
}
302312

0 commit comments

Comments
 (0)