-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Macros] In-process plugin server #73725
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
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
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.
e64de00
to
9be379a
Compare
👋 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
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! |
d7a0d58
to
db933a8
Compare
bd5a47d
to
c0449ed
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`
9769e8f
to
2f7aa42
Compare
swiftlang/llvm-project#8855 |
e9254dc
to
4d42b59
Compare
swiftlang/llvm-project#8855 |
Not all driver can send '-in-process-plugin-server-path'. To keep existing '-plugin-path' working, infer default server path in the frontend.
4d42b59
to
f08d69c
Compare
1 similar comment
swiftlang/llvm-project#8855 |
…target PR swiftlang#73725 introduced the in-process plugin server library, but the selection of the library depends on the selected toolchain, which depends on the compiler target, not the host. When cross-compiling (for example from macOS to a embedded Unix target), the compiler will incorrectly chose the `.so` file, not find it, and fail to compile things like the `@debugDescription` macro. Move the in-process plugin server library code from the platform toolchains into the parent type, and code it so it uses the right name depending on the compiler host at compilation time. This discards the target and only relies on the compiler host for selecting the right library.
…target PR swiftlang#73725 introduced the in-process plugin server library, but the selection of the library depends on the selected toolchain, which depends on the compiler target, not the host. When cross-compiling (for example from macOS to a embedded Unix target), the compiler will incorrectly chose the `.so` file, not find it, and fail to compile things like the `@debugDescription` macro. Move the in-process plugin server library code from the platform toolchains into the parent type, and code it so it uses the right name depending on the compiler host at compilation time. This discards the target and only relies on the compiler host for selecting the right library.
…target PR swiftlang#73725 introduced the in-process plugin server library, but the selection of the library depends on the selected toolchain, which depends on the compiler target, not the host. When cross-compiling (for example from macOS to a embedded Unix target), the compiler will incorrectly chose the `.so` file, not find it, and fail to compile things like the `@debugDescription` macro. Move the in-process plugin server library code from the platform toolchains into the parent type, and code it so it uses the right name depending on the compiler host at compilation time. This discards the target and only relies on the compiler host for selecting the right library.
…target PR swiftlang#73725 introduced the in-process plugin server library, but the selection of the library depends on the selected toolchain, which depends on the compiler target, not the host. When cross-compiling (for example from macOS to a embedded Unix target), the compiler will incorrectly chose the `.so` file, not find it, and fail to compile things like the `@debugDescription` macro. Move the in-process plugin server library code from the platform toolchains into the parent type, and code it so it uses the right name depending on the compiler host at compilation time. This discards the target and only relies on the compiler host for selecting the right library.
…target PR swiftlang#73725 introduced the in-process plugin server library, but the selection of the library depends on the selected toolchain, which depends on the compiler target, not the host. When cross-compiling (for example from macOS to a embedded Unix target), the compiler will incorrectly chose the `.so` file, not find it, and fail to compile things like the `@debugDescription` macro. Move the in-process plugin server library code from the platform toolchains into the parent type, and code it so it uses the right name depending on the compiler host at compilation time. This discards the target and only relies on the compiler host for selecting the right library.
…target PR swiftlang#73725 introduced the in-process plugin server library, but the selection of the library depends on the selected toolchain, which depends on the compiler target, not the host. When cross-compiling (for example from macOS to a embedded Unix target), the compiler will incorrectly chose the `.so` file, not find it, and fail to compile things like the `@debugDescription` macro. Move the in-process plugin server library code from the platform toolchains into the parent type, and code it so it uses the right name depending on the compiler host at compilation time. This discards the target and only relies on the compiler host for selecting the right library.
…target PR swiftlang#73725 introduced the in-process plugin server library, but the selection of the library depends on the selected toolchain, which depends on the compiler target, not the host. When cross-compiling (for example from macOS to a embedded Unix target), the compiler will incorrectly chose the `.so` file, not find it, and fail to compile things like the `@debugDescription` macro. Move the in-process plugin server library code from the platform toolchains into the parent type, and code it so it uses the right name depending on the compiler host at compilation time. This discards the target and only relies on the compiler host for selecting the right library.
…target (#74785) PR #73725 introduced the in-process plugin server library, but the selection of the library depends on the selected toolchain, which depends on the compiler target, not the host. When cross-compiling (for example from macOS to a embedded Unix target), the compiler will incorrectly chose the `.so` file, not find it, and fail to compile things like the `@debugDescription` macro. Move the in-process plugin server library code from the platform toolchains into the parent type, and code it so it uses the right name depending on the compiler host at compilation time. This discards the target and only relies on the compiler host for selecting the right library.
…target PR swiftlang#73725 introduced the in-process plugin server library, but the selection of the library depends on the selected toolchain, which depends on the compiler target, not the host. When cross-compiling (for example from macOS to a embedded Unix target), the compiler will incorrectly chose the `.so` file, not find it, and fail to compile things like the `@debugDescription` macro. Move the in-process plugin server library code from the platform toolchains into the parent type, and code it so it uses the right name depending on the compiler host at compilation time. This discards the target and only relies on the compiler host for selecting the right library. (cherry picked from commit 55d9e74)
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