Skip to content

Commit 89eb6da

Browse files
committed
Add shutDown method to PluginMessageHandler
This method deterministically and synchronously cleans 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. This method is required for `swift-plugin-server` to properly clean up file handles there were opened for communication with Wasm macros, as prototyped in swiftlang/swift#73031.
1 parent 6be29a5 commit 89eb6da

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift

+10
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ public class CompilerPluginMessageListener<Connection: MessageConnection, Handle
133133
public protocol PluginMessageHandler {
134134
/// Handles a single message received from the plugin host.
135135
func handleMessage(_ message: HostToPluginMessage) -> PluginToHostMessage
136+
137+
/// Deterministically and synchronously cleans up resources that cannot be dealt with in
138+
/// a deinitializer due to possible errors thrown during the clean up. Usually this
139+
/// includes closure of file handles, sockets, shutting down external processes and IPC
140+
/// resources set up for these processes, etc.
141+
func shutDown() throws
136142
}
137143

138144
/// A `PluginMessageHandler` that uses a `PluginProvider`.
@@ -226,6 +232,10 @@ public class PluginProviderMessageHandler<Provider: PluginProvider>: PluginMessa
226232
return .loadPluginLibraryResult(loaded: diags.isEmpty, diagnostics: diags)
227233
}
228234
}
235+
236+
/// Empty implementation for the default message handler, since all resources are automatically
237+
/// cleaned up in the synthesized initializer.
238+
public func shutDown() throws {}
229239
}
230240

231241
@_spi(PluginMessage)

0 commit comments

Comments
 (0)