Skip to content

[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

Merged
merged 4 commits into from
Oct 17, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Oct 6, 2023

rdar://115571427

@rintaro rintaro marked this pull request as draft October 6, 2023 22:38
@rintaro rintaro force-pushed the macro-resolveerror-rdar115571427 branch 2 times, most recently from 669521c to bc0dfb8 Compare October 10, 2023 23:22
@rintaro
Copy link
Member Author

rintaro commented Oct 10, 2023

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Oct 11, 2023

swiftlang/swift-syntax#2268
@swift-ci Please smoke test

@rintaro rintaro force-pushed the macro-resolveerror-rdar115571427 branch from bc0dfb8 to ea4efca Compare October 11, 2023 17:19
@rintaro
Copy link
Member Author

rintaro commented Oct 11, 2023

swiftlang/swift-syntax#2268
@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Oct 11, 2023

@swift-ci Please test Windows

@rintaro rintaro marked this pull request as ready for review October 11, 2023 18:30
@rintaro rintaro requested a review from bnbarham October 11, 2023 18:30
plugin.takeError(), [&](const llvm::ErrorInfoBase &err) {
return llvm::createStringError(
err.convertToErrorCode(),
"compiler plugin not loaded: %s; loader error: %s",
Copy link
Contributor

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

).limitBehavior(DiagnosticBehavior::Warning);
auto externalDef =
evaluateOrDefault(Ctx.evaluator, request,
ExternalMacroDefinition::error("failed request"));
Copy link
Contributor

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 😅

return nullptr;
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"failed to initialize executable plugin '" +
Copy link
Contributor

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"?

Comment on lines 338 to 340
"failed to load library plugin '" + resolvedLibraryPathStr +
"' in plugin server '" +
StringRef(executablePlugin->getExecutablePath()) + "'");
Copy link
Contributor

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.

return executablePlugin.get();
llvm::handleAllErrors(
executablePlugin.takeError(),
[&](const llvm::ErrorInfoBase &err) { errorMessage += err.message(); });
Copy link
Contributor

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

Comment on lines 411 to 412
NullTerminatedStringRef errMsg("plugin that can handle module '" +
moduleName.str() + "' not found",
Copy link
Contributor

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

Comment on lines 437 to 440
"type '" + moduleName.str() + "." + typeName.str() +
"' is not a valid macro implementation type in library plugin '" +
StringRef(plugin->getLibraryPath()) + "'",
Copy link
Contributor

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

Comment on lines 445 to 448
NullTerminatedStringRef err("macro implementation type '" + moduleName.str() +
"." + typeName.str() +
"' could not be found in library plugin '" +
StringRef(plugin->getLibraryPath()) + "'",
Copy link
Contributor

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

#endif
return llvm::None;
return ExternalMacroDefinition::error("macro is not supported");
Copy link
Contributor

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?

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.
@rintaro rintaro force-pushed the macro-resolveerror-rdar115571427 branch from ea4efca to 648b95e Compare October 13, 2023 00:13
@rintaro
Copy link
Member Author

rintaro commented Oct 13, 2023

swiftlang/swift-syntax#2268
@swift-ci Please smoke test

@rintaro rintaro force-pushed the macro-resolveerror-rdar115571427 branch from 648b95e to 444fcfa Compare October 13, 2023 17:38
@rintaro
Copy link
Member Author

rintaro commented Oct 13, 2023

swiftlang/swift-syntax#2268
@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Oct 13, 2023

swiftlang/swift-syntax#2268
@swift-ci Please smoke test Linux

1 similar comment
@rintaro
Copy link
Member Author

rintaro commented Oct 13, 2023

swiftlang/swift-syntax#2268
@swift-ci Please smoke test Linux

@rintaro
Copy link
Member Author

rintaro commented Oct 13, 2023

swiftlang/swift-syntax#2268
@swift-ci Please smoke test Linux

@rintaro
Copy link
Member Author

rintaro commented Oct 13, 2023

swiftlang/swift-syntax#2268
@swift-ci Please smoke test

@rintaro rintaro merged commit 37a6374 into swiftlang:main Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants