Commit Graph

23 Commits

Author SHA1 Message Date
Max Desiatov
b5e8cfb931 swift-plugin-server: update for throwing SwiftSyntax API (#78114)
Depends on https://github.com/swiftlang/swift-syntax/pull/2915

The `main` method on `CompilerPluginMessageListener` can synchronously clean up resources that cannot be dealt with in a deinitializer due to possible errors thrown during the clean up. Usually this includes closure of file handles, sockets, shutting down external processes and IPC resources set up for these processes, etc.
2024-12-12 09:24:17 +00:00
Finagolfin
3888ae338a [Macros] Add the correct RPATH flags to the in-process plugin server host library
Also, make sure it builds for Android.
2024-08-09 10:27:32 +05:30
Allan Shortlidge
5a4440787e Macros: Resolve CompilerPluginMessageHandler deprecation warnings.
NFC.
2024-07-25 11:30:10 -07:00
Rintaro Ishizaki
2f7aa428db [Macros] In-process plugin server
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`
2024-06-17 11:36:52 -07:00
Rintaro Ishizaki
be419a3428 [Macros] Use 'LibraryPluginProvider' in swift-plugin-server
Move 'PluginProvider' logic to 'SwiftLibraryPluginProvider' module
so the compiler can reuse that logic for the actual in-process plugins.
2024-05-07 09:47:04 -07:00
Rintaro Ishizaki
9a38072856 Revert "[Macros] Use 'LibraryPluginProvider' in swift-plugin-server" 2024-05-06 15:57:32 -07:00
Rintaro Ishizaki
26dbe2f8a1 [Macros] Use 'LibraryPluginProvider' in swift-plugin-server
Move 'PluginProvider' logic to 'SwiftLibraryPluginProvider' module
so the compiler can reuse that logic for the actual in-process plugins.
2024-05-01 16:41:14 -07:00
Rintaro Ishizaki
1125828f9d [swift-plugin-server] Use StandardIOMessageConnection 2024-04-25 14:43:46 -07:00
Rintaro Ishizaki
cd54cc1c31 [Macros] Use SwiftCompilerPluginMessageHandling JSON encoder/decoder
Replacing swiftLLVMSJON with SwiftCompilerPluginMessageHandling.JSON
2024-04-25 14:42:20 -07:00
Rintaro Ishizaki
ae149276ac Merge pull request #69240 from rintaro/macros-message-listener
[Macros] Update for CompilerPluginMessageListener
2024-04-25 00:20:03 -07:00
Rintaro Ishizaki
ae3a169338 [ASTGen] Update for SPI in swift-syntax
All symbols in `SwiftCompilerPluginMessageHandling` are now SPI.
2024-04-12 12:08:00 -07:00
Rintaro Ishizaki
fbef7e12fc [Macros] Update for CompilerPluginMessageListener 2023-10-17 19:03:21 -07:00
Rintaro Ishizaki
28aad9d126 [Macros] Return plugin loading error as 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.
2023-10-12 16:08:54 -07:00
Rintaro Ishizaki
d4adba20fc [Macros] Granular diagnostic when macro type is not found in a plugin
rdar://115571427
2023-10-12 16:07:33 -07:00
Rintaro Ishizaki
6f4dc22838 [plugin-server] Use standard headers in CSwiftPluginServer
For whatever reason, using standard headers in modules imported from
Swift code (depending on Darwin overlay) is no longer an issue.
2023-10-04 15:11:34 -07:00
Saleem Abdulrasool
4cb8133e4c swift-plugin-server: remove standard headers
Redefine the types rather than use the standard headers due to the
circular dependency between Darwin and Swift.
2023-09-07 10:35:01 -07:00
Saleem Abdulrasool
7f998672d7 Update swift-plugin-server.swift 2023-09-03 19:20:56 -07:00
Saleem Abdulrasool
51107c9698 Update PluginServer.h 2023-09-03 18:56:34 -07:00
Saleem Abdulrasool
a7f3e73587 Update PluginServer.h
Include `stdint.h` for non-MSVC compilers.
2023-09-03 10:39:14 -07:00
Saleem Abdulrasool
c6222bf8eb swift-plugin-server: adjust API for portability
This begins reworking the API to be less POSIX centric and more
generally usable.  The API was defined in terms of `dlopen`/`dlsym`
rather than the better suited `llvm::sys::DynamicLibrary` APIs which
would avoid most of the work that needs to be done here for platform
specifics.
2023-09-02 11:50:23 -07:00
Rintaro Ishizaki
fe1eb469e4 [ASTGen] Avoid including C standard libary headers in brigdging headers
C stdlib headers are part of "Darwin"/"Glibc" clang module.
If a Swift file imports a bridging headers and that has '#include'
C stdlib headers, Swift compiler implicitly imports "Darwin"/"Glibc"
overlay modules. That violates dependency layering. I.e. Compiler
depends on Darwin overlay, Darwin overlay is created by the compiler.

rdar://107957117
2023-04-12 17:22:32 -07:00
Rintaro Ishizaki
1851ba2d8f [Macros] swift-plugin-server cosmetic tweaks 2023-03-16 14:00:45 -07:00
Rintaro Ishizaki
c4b3edd6df [Macros] Add swift-plugin-server executable
This executable is intended to be installed in the toolchain and act as
an executable compiler plugin just like other 'macro' plugins.

This plugin server has an optional method 'loadPluginLibrary' that
dynamically loads dylib plugins.
The compiler has a newly added option '-external-plugin-path'. This
option receives a pair of the plugin library search path (just like
'-plugin-path') and the corresponding "plugin server" path, separated
by '#'. i.e.

  -external-plugin-path
    <plugin library search path>#<plugin server executable path>

For exmaple, when there's a macro decl:

  @freestanding(expression)
  macro stringify<T>(T) -> (T, String) =
      #externalMacro(module: "BasicMacro", type: "StringifyMacro")

The compiler look for 'libBasicMacro.dylib' in '-plugin-path' paths,
if not found, it falls back to '-external-plugin-path' and tries to find
'libBasicMacro.dylib' in them. If it's found, the "plugin server" path
is launched just like an executable plugin, then 'loadPluginLibrary'
method is invoked via IPC, which 'dlopen' the library path in the plugin
server. At the actual macro expansion, the mangled name for
'BasicMacro.StringifyMacro' is used to resolve the macro  just like
dylib plugins in the compiler.

This is useful for
 * Isolating the plugin process, so the plugin crashes doesn't result
   the compiler crash
 * Being able to use library plugins linked with other `swift-syntax`
   versions

rdar://105104850
2023-03-16 14:00:45 -07:00