mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Macros] Be deliberate about walking macro arguments vs. expansions
Provide ASTWalker with a customization point to specify whether to check macro arguments (which are type checked but never emitted), the macro expansion (which is the result of applying the macro and is actually emitted into the source), or both. Provide answers for the ~115 different ASTWalker visitors throughout the code base. Fixes rdar://104042945, which concerns checking of effects in macro arguments---which we shouldn't do.
This commit is contained in:
@@ -3376,6 +3376,11 @@ private:
|
||||
CacheExprTypes(Expr *expr, ConstraintSystem &cs, bool excludeRoot)
|
||||
: RootExpr(expr), CS(cs), ExcludeRoot(excludeRoot) {}
|
||||
|
||||
/// Walk everything in a macro
|
||||
MacroWalking getMacroWalkingBehavior() const override {
|
||||
return MacroWalking::ArgumentsAndExpansion;
|
||||
}
|
||||
|
||||
PostWalkResult<Expr *> walkToExprPost(Expr *expr) override {
|
||||
if (ExcludeRoot && expr == RootExpr) {
|
||||
assert(!expr->getType() && "Unexpected type in root of expression!");
|
||||
@@ -6954,6 +6959,10 @@ public:
|
||||
: NumOverloads(overloads)
|
||||
{}
|
||||
|
||||
MacroWalking getMacroWalkingBehavior() const override {
|
||||
return MacroWalking::Arguments;
|
||||
}
|
||||
|
||||
PreWalkResult<Expr *> walkToExprPre(Expr *expr) override {
|
||||
if (auto applyExpr = dyn_cast<ApplyExpr>(expr)) {
|
||||
// If we've found function application and it's
|
||||
|
||||
Reference in New Issue
Block a user