-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Macros] Improve macro plugin loading macro definition resolution diagnostics #69027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Macros] Improve macro plugin loading macro definition resolution diagnostics #69027
Conversation
669521c
to
bc0dfb8
Compare
@swift-ci Please smoke test |
swiftlang/swift-syntax#2268 |
bc0dfb8
to
ea4efca
Compare
swiftlang/swift-syntax#2268 |
@swift-ci Please test Windows |
lib/AST/PluginLoader.cpp
Outdated
plugin.takeError(), [&](const llvm::ErrorInfoBase &err) { | ||
return llvm::createStringError( | ||
err.convertToErrorCode(), | ||
"compiler plugin not loaded: %s; loader error: %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compiler plugin '%s' could not be loaded: %s
. Same below as well
lib/Sema/TypeCheckDeclPrimary.cpp
Outdated
).limitBehavior(DiagnosticBehavior::Warning); | ||
auto externalDef = | ||
evaluateOrDefault(Ctx.evaluator, request, | ||
ExternalMacroDefinition::error("failed request")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just "unknown error"? failed request
wouldn't make much sense to a user, at least unknown error
sort of implies there's not much they can do about it 😅
lib/Sema/TypeCheckMacros.cpp
Outdated
return nullptr; | ||
return llvm::createStringError( | ||
llvm::inconvertibleErrorCode(), | ||
"failed to initialize executable plugin '" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice for this to be a little more actionable, though I know it's unlikely anyone would hit this (without implementing their own plugin). No great ideas here, maybe something like "'%s' produced malformed response"
?
lib/Sema/TypeCheckMacros.cpp
Outdated
"failed to load library plugin '" + resolvedLibraryPathStr + | ||
"' in plugin server '" + | ||
StringRef(executablePlugin->getExecutablePath()) + "'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have the error returned by swift_ASTGen_pluginServerLoadLibraryPlugin
instead of having it added as a diagnostic, similar to the rest of the changes here. Just more of a pain since it's across the language boundary.
lib/Sema/TypeCheckMacros.cpp
Outdated
return executablePlugin.get(); | ||
llvm::handleAllErrors( | ||
executablePlugin.takeError(), | ||
[&](const llvm::ErrorInfoBase &err) { errorMessage += err.message(); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is any separation needed here? Newline/space/etc? Could use SmallString instead too
lib/Sema/TypeCheckMacros.cpp
Outdated
NullTerminatedStringRef errMsg("plugin that can handle module '" + | ||
moduleName.str() + "' not found", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"plugin for module '...' not found"
reads a little nicer IMO
lib/Sema/TypeCheckMacros.cpp
Outdated
"type '" + moduleName.str() + "." + typeName.str() + | ||
"' is not a valid macro implementation type in library plugin '" + | ||
StringRef(plugin->getLibraryPath()) + "'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO you can skip type
here
lib/Sema/TypeCheckMacros.cpp
Outdated
NullTerminatedStringRef err("macro implementation type '" + moduleName.str() + | ||
"." + typeName.str() + | ||
"' could not be found in library plugin '" + | ||
StringRef(plugin->getLibraryPath()) + "'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And as with the previous, macro implementation type
could also be skipped here
lib/Sema/TypeCheckMacros.cpp
Outdated
#endif | ||
return llvm::None; | ||
return ExternalMacroDefinition::error("macro is not supported"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be hit, but the current compiler was not built with macro support
?
Return the failure reason as the result.
Instead of emitting an warning to the diagnostic engine, return the plugin loading error as the result of the request. So that the user can decide to emit it as a warning or an error.
ea4efca
to
648b95e
Compare
swiftlang/swift-syntax#2268 |
648b95e
to
444fcfa
Compare
swiftlang/swift-syntax#2268 |
swiftlang/swift-syntax#2268 |
1 similar comment
swiftlang/swift-syntax#2268 |
swiftlang/swift-syntax#2268 |
swiftlang/swift-syntax#2268 |
rdar://115571427