@@ -119,12 +119,8 @@ MacroDefinition MacroDefinitionRequest::evaluate(
119119 }
120120#endif
121121
122- ctx.Diags .diagnose (
123- macro, diag::external_macro_not_found, macro->externalModuleName .str (),
124- macro->externalMacroTypeName .str (), macro->getName ());
125- // FIXME: Can we give more actionable advice?
126-
127- return MacroDefinition::forInvalid ();
122+ return MacroDefinition::forMissing (
123+ ctx, macro->externalModuleName , macro->externalMacroTypeName );
128124}
129125
130126#if SWIFT_SWIFT_PARSER
@@ -150,35 +146,43 @@ Expr *swift::expandMacroExpr(
150146
151147 auto macroDef = evaluateOrDefault (
152148 ctx.evaluator , MacroDefinitionRequest{macro},
153- MacroDefinition::forInvalid ());
154- if (!macroDef) {
149+ MacroDefinition::forUndefined ());
150+ switch (macroDef.implKind ) {
151+ case MacroDefinition::ImplementationKind::Undefined:
152+ // Already diagnosed as an error elsewhere.
153+ return nullptr ;
154+
155+ case MacroDefinition::ImplementationKind::Missing: {
156+ auto missingInfo = macroDef.getMissingDefinition ();
157+ ctx.Diags .diagnose (
158+ expr->getLoc (), diag::external_macro_not_found,
159+ missingInfo->externalModuleName .str (),
160+ missingInfo->externalMacroTypeName .str (), macro->getName ());
161+ macro->diagnose (diag::decl_declared_here, macro->getName ());
155162 return nullptr ;
156163 }
157164
158- {
165+ case MacroDefinition::ImplementationKind::InProcess: {
159166 PrettyStackTraceExpr debugStack (ctx, " expanding macro" , expr);
160167
161- switch (macroDef.implKind ) {
162- case MacroDefinition::ImplementationKind::InProcess: {
163- // Builtin macros are handled via ASTGen.
164- auto astGenSourceFile = sourceFile->exportedSourceFile ;
165- if (!astGenSourceFile)
166- return nullptr ;
167-
168- const char *evaluatedSourceAddress;
169- ptrdiff_t evaluatedSourceLength;
170- swift_ASTGen_evaluateMacro (
171- &ctx.Diags ,
172- macroDef.getAsInProcess (),
173- astGenSourceFile, expr->getStartLoc ().getOpaquePointerValue (),
174- &evaluatedSourceAddress, &evaluatedSourceLength);
175- if (!evaluatedSourceAddress)
176- return nullptr ;
177- evaluatedSource = NullTerminatedStringRef (evaluatedSourceAddress,
178- (size_t )evaluatedSourceLength);
179- break ;
180- }
181- }
168+ // Builtin macros are handled via ASTGen.
169+ auto astGenSourceFile = sourceFile->exportedSourceFile ;
170+ if (!astGenSourceFile)
171+ return nullptr ;
172+
173+ const char *evaluatedSourceAddress;
174+ ptrdiff_t evaluatedSourceLength;
175+ swift_ASTGen_evaluateMacro (
176+ &ctx.Diags ,
177+ macroDef.getInProcessOpaqueHandle (),
178+ astGenSourceFile, expr->getStartLoc ().getOpaquePointerValue (),
179+ &evaluatedSourceAddress, &evaluatedSourceLength);
180+ if (!evaluatedSourceAddress)
181+ return nullptr ;
182+ evaluatedSource = NullTerminatedStringRef (evaluatedSourceAddress,
183+ (size_t )evaluatedSourceLength);
184+ break ;
185+ }
182186 }
183187
184188 // Figure out a reasonable name for the macro expansion buffer.
0 commit comments