-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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] In-process plugin server #73725
base: main
Are you sure you want to change the base?
Conversation
# Make unified swift-syntax shared library. | ||
add_pure_swift_host_library(swiftSyntaxUnified SHARED) | ||
set_target_properties(swiftSyntaxUnified PROPERTIES LINKER_LANGUAGE Swift) | ||
|
||
macro(target_link_libraries_whole_archive target) | ||
foreach(lib ${ARGN}) | ||
target_compile_options(${lib} PRIVATE "SHELL:-module-link-name ${target}") | ||
target_sources(${target} PRIVATE $<TARGET_OBJECTS:${lib}>) | ||
# Workaround for CMake doesn't recognize '.o' files as sources. | ||
target_link_options(${target} PRIVATE $<TARGET_OBJECTS:${lib}>) | ||
set_property(TARGET ${target} APPEND PROPERTY | ||
INTERFACE_INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:${lib},INTERFACE_INCLUDE_DIRECTORIES>" | ||
) |
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.
Instead of making an aggregated swift-syntax libraries, can we link those static libraries with ASTGen and make libASTGen.dylib
?
edit: no because ASTGen
depends on C++ code.
@@ -319,7 +319,7 @@ class PluginDiagnosticsEngine { | |||
messageSuffix: String? = nil | |||
) { | |||
for diagnostic in diagnostics { | |||
self.emit(diagnostic) | |||
self.emit(diagnostic, messageSuffix: messageSuffix) |
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.
We had a bug in executable plugins where (from macro '\(macroName)')
suffix wasn't added in the diagnostics from executable plugins 😞
9c69aa8
to
abc1390
Compare
include/swift/AST/PluginRegistry.h
Outdated
llvm::StringMap<void *> resolvedSymbols; | ||
std::mutex mtx; | ||
|
||
/// Opaque value of the protocol capability of the pluugin. This is a |
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.
/// Opaque value of the protocol capability of the pluugin. This is a | |
/// Opaque value of the protocol capability of the plugin. This is a |
lib/AST/PluginRegistry.cpp
Outdated
// Already loaded. | ||
return storage.get(); | ||
CompilerPlugin::~CompilerPlugin() { | ||
// Let ASTGen to cleanup things. |
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.
// Let ASTGen to cleanup things. | |
// Let ASTGen do cleanup things. |
lib/AST/PluginRegistry.cpp
Outdated
auto message = receivedResponse; | ||
receivedResponse = ""; |
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.
Could get rid of the string copy here, but probably doesn't matter that much
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.
👍
SWIFT_DEFER { receivedResponse = ""; };
return std::move(receivedResponse);
lib/AST/PluginRegistry.cpp
Outdated
llvm::Expected<InProcessPlugins *> | ||
InProcessPlugins::create(const char *serverPath) { |
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.
Any reason not to have this return a unique_ptr
?
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.
No. Changed to return unique_ptr
👍
var basename: String { | ||
guard | ||
let lastSlash = lastIndex(where: { | ||
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) || os(Android) || os(Linux) |
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.
visionOS
?
tools/libSwiftScan/CMakeLists.txt
Outdated
@@ -46,20 +46,20 @@ endif() | |||
|
|||
if(SWIFT_BUILD_SWIFT_SYNTAX) | |||
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS) | |||
# Ensure that we can find the host shared libraries. | |||
# Ensure that we can find the shaered swiftsyntax libraries. |
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.
# Ensure that we can find the shaered swiftsyntax libraries. | |
# Ensure that we can find the shared swiftsyntax libraries. |
1d223b1
to
8e7b75e
Compare
Swift_MODULE_NAME ${name} | ||
Swift_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
set(module_file "${CMAKE_CURRENT_BINARY_DIR}/${name}.swiftmodule") | ||
set(module_dir "${CMAKE_CURRENT_BINARY_DIR}/modules") |
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.
Fragile modules are now created in ${CMAKE_CURRENT_BINARY_DIR}/modules
. This is to avoid PR testing failures in incremental bots. This PR changes _CompilerRegexParser
to fragile, if we create ${CMAKE_CURRENT_BINARY_DIR}/_CompilerRegexParser.swiftmodule
, subsequent PR testings will be confused because -I ${CMAKE_CURRENT_BINARY_DIR}
is added by CMake. Pre-patch #73799 can avoid that, but just in case.
@@ -629,8 +629,8 @@ struct HasNestedType { | |||
#if TEST_DIAGNOSTICS | |||
@freestanding(expression) | |||
macro missingMacro() = #externalMacro(module: "MacroDefinition", type: "BluhBlah") | |||
// expected-warning@-1 {{external macro implementation type 'MacroDefinition.BluhBlah' could not be found for macro 'missingMacro()'; 'MacroDefinition.BluhBlah' could not be found in library plugin '}} | |||
// FIXME: xpected-warning@-1 {{external macro implementation type 'MacroDefinition.BluhBlah' could not be found for macro 'missingMacro()'; 'MacroDefinition.BluhBlah' could not be found in library 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.
This is because the plugin message facilities (i.e. executable plugins) doesn't support "resolve macro type" at this point. Expansions would just fail and be diagnosed if the type is not found or not a macro type.
Maybe we can introduce case resolveMacroType(module: String, type: String)
plugin message to recover this.
8e7b75e
to
37ae72d
Compare
apple/swift-syntax#2659 |
2 similar comments
apple/swift-syntax#2659 |
apple/swift-syntax#2659 |
59d6af7
to
da3d080
Compare
apple/swift-syntax#2659 |
da3d080
to
b3c996d
Compare
apple/swift-syntax#2659 |
1 similar comment
apple/swift-syntax#2659 |
apple/swift-syntax#2659 |
e64de00
to
9be379a
Compare
apple/swift-syntax#2659 |
👋 does this PR remove support for the I should mention that I don't fully understand the implications of this PR so please do correct me if I'm mistaken. In general, in-process execution for first-party plugins during one-off swiftc invocation does seem like a nice improvement! |
I'm not 100% sure what " Since we need to keep supporting "in-process" plugins (i.e.
This PR doesn't have any intent of removing or deprecating out-of-process plugin mechanism.
Yes, reusing plugin processes across multiple I'm not sure I entirely understand your concerns. Let me know if you still have any questions! |
9be379a
to
7dd4f52
Compare
apple/swift-syntax#2659 |
1 similar comment
apple/swift-syntax#2659 |
Ah I was under the impression that this removed support for external plugin servers in favour of in-process plugins, but looks like I was confused. Thanks for the clarification! |
601d800
to
9c4a989
Compare
apple/swift-syntax#2659 |
apple/swift-syntax#2659 |
9c4a989
to
d7a0d58
Compare
apple/swift-syntax#2659 |
apple/swift-syntax#2659 |
1 similar comment
apple/swift-syntax#2659 |
d7a0d58
to
db933a8
Compare
apple/swift-syntax#2659 |
apple/llvm-project#8855 |
db933a8
to
bd5a47d
Compare
Separate swift-syntax libs for the compiler and for the library plugins. Compiler communicates with library plugins using serialized messages just like executable plugins. * `lib/swift/host/compiler/lib_Compiler*.dylib`(`lib/CompilerSwiftSyntax`): swift-syntax libraries for compiler. Library evolution is disabled. * Compiler (`ASTGen` and `swiftIDEUtilsBridging`) only depends on `lib/swift/host/compiler` libraries. * `SwiftInProcPluginServer`: In-process plugin server shared library. This has one `swift_inproc_plugins_handle_message` entry point that receives a message and return the response. * In the compiler * Add `-in-process-plugin-server-path` front-end option, which specifies the `SwiftInProcPluginServer` shared library path. * Remove `LoadedLibraryPlugin`, because all library plugins are managed by `SwiftInProcPluginServer` * Introduce abstract `CompilerPlugin` class that has 2 subclasses: * `LoadedExecutablePlugin` existing class that represents an executable plugin * `InProcessPlugins` wraps `dlopen`ed `SwiftInProcPluginServer` * Unified the code path in `TypeCheckMacros.cpp` and `ASTGen`, the difference between executable plugins and library plugins are now abstracted by `CompilerPlugin`
bd5a47d
to
c0449ed
Compare
apple/llvm-project#8855 |
apple/llvm-project#8855 |
apple/llvm-project#8855 |
apple/llvm-project#8855 |
Separate swift-syntax libs for the compiler and for the library plugins. Compiler communicates with library plugins using serialized messages just like executable plugins.
lib/swift/host/compiler/lib_Compiler*.dylib
(sourcelib/CompilerSwiftSyntax
): swift-syntax libraries for compiler. Library evolution is disabled.Compiler (
ASTGen
andswiftIDEUtilsBridging
) only depends onlib/swift/host/compiler
libraries.lib/swift/host/libSwiftInProcPluginServer.dylib
(sourcetools/swift-plugin-server/Sources/SwiftInProcPluginServer
): In-process plugin server shared library. This has oneswift_inproc_plugins_handle_message
entry point that receives a message and return the response.In the compiler:
-in-process-plugin-server-path
front-end option, which specifies theSwiftInProcPluginServer
shared library path.LoadedLibraryPlugin
, because all library plugins are managed bySwiftInProcPluginServer
CompilerPlugin
class that has 2 subclasses:LoadedExecutablePlugin
existing class that represents an executable pluginInProcessPlugins
wrapsdlopen
edSwiftInProcPluginServer
and communicate with it via theswift_inproc_plugins_handle_message
TypeCheckMacros.cpp
andASTGen
, the difference between executable plugins and library plugins are now abstracted byCompilerPlugin