Skip to content

Commit e8838bc

Browse files
authored
Merge pull request #62123 from DougGregor/pretty-stack-trace-macros
2 parents 153b1ac + 9b10b0b commit e8838bc

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

lib/AST/Expr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,8 @@ ArgumentList *Expr::getArgs() const {
832832
return DSE->getArgs();
833833
if (auto *OLE = dyn_cast<ObjectLiteralExpr>(this))
834834
return OLE->getArgs();
835+
if (auto *ME = dyn_cast<MacroExpansionExpr>(this))
836+
return ME->getArgs();
835837
return nullptr;
836838
}
837839

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5541,10 +5541,12 @@ bool ConstraintSystem::repairFailures(
55415541

55425542
if (auto overload = findSelectedOverloadFor(calleeLocator)) {
55435543
if (auto *decl = overload->choice.getDeclOrNull()) {
5544-
if (getParameterList(decl)->get(paramIdx)->getTypeOfDefaultExpr()) {
5545-
conversionsOrFixes.push_back(
5546-
IgnoreDefaultExprTypeMismatch::create(*this, lhs, rhs, loc));
5547-
break;
5544+
if (auto paramList = getParameterList(decl)) {
5545+
if (paramList->get(paramIdx)->getTypeOfDefaultExpr()) {
5546+
conversionsOrFixes.push_back(
5547+
IgnoreDefaultExprTypeMismatch::create(*this, lhs, rhs, loc));
5548+
break;
5549+
}
55485550
}
55495551
}
55505552
}

lib/Sema/TypeCheckMacros.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/AST/ASTContext.h"
2020
#include "swift/AST/CompilerPlugin.h"
2121
#include "swift/AST/Expr.h"
22+
#include "swift/AST/PrettyStackTrace.h"
2223
#include "swift/AST/SourceFile.h"
2324
#include "swift/AST/TypeCheckRequests.h"
2425
#include "swift/Basic/Defer.h"
@@ -163,8 +164,6 @@ getMacroSignature(
163164
typealias->getGenericSignature(), typealias->getUnderlyingType());
164165
}
165166

166-
167-
168167
/// Create a macro.
169168
static MacroDecl *createMacro(
170169
ModuleDecl *mod, Identifier macroName,
@@ -368,8 +367,10 @@ Expr *swift::expandMacroExpr(
368367
NullTerminatedStringRef evaluatedSource;
369368

370369
MacroDecl *macro = cast<MacroDecl>(macroRef.getDecl());
370+
{
371+
PrettyStackTraceExpr debugStack(ctx, "expanding macro", expr);
371372

372-
switch (macro->implementationKind) {
373+
switch (macro->implementationKind) {
373374
case MacroDecl::ImplementationKind::Builtin: {
374375
// Builtin macros are handled via ASTGen.
375376
auto astGenSourceFile = sourceFile->exportedSourceFile;
@@ -380,8 +381,8 @@ Expr *swift::expandMacroExpr(
380381
const char *evaluatedSourceAddress;
381382
ptrdiff_t evaluatedSourceLength;
382383
swift_ASTGen_evaluateMacro(
383-
astGenSourceFile, expr->getStartLoc().getOpaquePointerValue(),
384-
&evaluatedSourceAddress, &evaluatedSourceLength);
384+
astGenSourceFile, expr->getStartLoc().getOpaquePointerValue(),
385+
&evaluatedSourceAddress, &evaluatedSourceLength);
385386
if (!evaluatedSourceAddress)
386387
return nullptr;
387388
evaluatedSource = NullTerminatedStringRef(evaluatedSourceAddress,
@@ -394,18 +395,19 @@ Expr *swift::expandMacroExpr(
394395
auto bufferID = sourceFile->getBufferID();
395396
auto sourceFileText = sourceMgr.getEntireTextForBuffer(*bufferID);
396397
auto evaluated = plugin->invokeRewrite(
397-
/*targetModuleName*/ dc->getParentModule()->getName().str(),
398-
/*filePath*/ sourceFile->getFilename(),
399-
/*sourceFileText*/ sourceFileText,
400-
/*range*/ Lexer::getCharSourceRangeFromSourceRange(
401-
sourceMgr, expr->getSourceRange()),
402-
ctx);
398+
/*targetModuleName*/ dc->getParentModule()->getName().str(),
399+
/*filePath*/ sourceFile->getFilename(),
400+
/*sourceFileText*/ sourceFileText,
401+
/*range*/ Lexer::getCharSourceRangeFromSourceRange(
402+
sourceMgr, expr->getSourceRange()),
403+
ctx);
403404
if (evaluated)
404405
evaluatedSource = *evaluated;
405406
else
406407
return nullptr;
407408
break;
408409
}
410+
}
409411
}
410412

411413
// Figure out a reasonable name for the macro expansion buffer.
@@ -481,6 +483,8 @@ Expr *swift::expandMacroExpr(
481483
ContextualTypePurpose::CTP_CoerceOperand
482484
};
483485

486+
PrettyStackTraceExpr debugStack(
487+
ctx, "type checking expanded macro", expandedExpr);
484488
Type realExpandedType = TypeChecker::typeCheckExpression(
485489
expandedExpr, dc, contextualType);
486490
if (!realExpandedType)

0 commit comments

Comments
 (0)