|
36 | 36 | #include "swift/AST/ProtocolConformance.h"
|
37 | 37 | #include "swift/AST/SourceFile.h"
|
38 | 38 | #include "swift/AST/SubstitutionMap.h"
|
| 39 | +#include "swift/AST/TypeCheckRequests.h" |
39 | 40 | #include "swift/Basic/Defer.h"
|
40 | 41 | #include "swift/Basic/StringExtras.h"
|
41 | 42 | #include "swift/Sema/ConstraintSystem.h"
|
@@ -5394,27 +5395,20 @@ namespace {
|
5394 | 5395 | }
|
5395 | 5396 | // For a non-expression macro, expand it as a declaration.
|
5396 | 5397 | else if (macro->getMacroRoles().contains(MacroRole::Declaration)) {
|
| 5398 | + auto &ctx = cs.getASTContext(); |
5397 | 5399 | if (!E->getSubstituteDecl()) {
|
5398 | 5400 | auto *med = E->createSubstituteDecl();
|
| 5401 | + |
| 5402 | + // Cache the result of ResolveMacroRequest for this new declaration; |
| 5403 | + // we don't want to compute it again. |
| 5404 | + ctx.evaluator.cacheOutput( |
| 5405 | + ResolveMacroRequest{UnresolvedMacroReference{med}, |
| 5406 | + med->getDeclContext()}, |
| 5407 | + ConcreteDeclRef(macroRef)); |
| 5408 | + |
5399 | 5409 | E->setSubstituteDecl(med);
|
5400 | 5410 | TypeChecker::typeCheckDecl(med);
|
5401 | 5411 | }
|
5402 |
| - // To prevent AST nodes from being visited twice, we've sunk the |
5403 |
| - // original argument list down to the substitute macro expansion decl, |
5404 |
| - // and we'll replace the expr's arguments with opaque values. |
5405 |
| - SmallVector<Argument, 4> newArguments; |
5406 |
| - for (auto arg : *E->getArgs()) { |
5407 |
| - arg.setExpr(new (cs.getASTContext()) OpaqueValueExpr( |
5408 |
| - arg.getSourceRange(), cs.getType(arg.getExpr()))); |
5409 |
| - newArguments.push_back(arg); |
5410 |
| - } |
5411 |
| - auto newArgList = ArgumentList::create( |
5412 |
| - cs.getASTContext(), E->getArgs()->getLParenLoc(), newArguments, |
5413 |
| - E->getArgs()->getRParenLoc(), |
5414 |
| - E->getArgs()->getFirstTrailingClosureIndex(), |
5415 |
| - E->getArgs()->isImplicit()); |
5416 |
| - E->setArgs(newArgList); |
5417 |
| - cs.setType(E, cs.getASTContext().getVoidType()); |
5418 | 5412 | }
|
5419 | 5413 | // Other macro roles may also be encountered here, as they use
|
5420 | 5414 | // `MacroExpansionExpr` for resolution. In those cases, do not expand.
|
|
0 commit comments