From 7cee8ba40d91923b1771c998f719cb3020100129 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Fri, 10 Oct 2025 14:48:50 -0700 Subject: [PATCH] [Macros] Termination signal for executable plugin Exit the plugin when it receives an empty message. rdar://160820381 --- .../StandardIOMessageConnection.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/SwiftCompilerPluginMessageHandling/StandardIOMessageConnection.swift b/Sources/SwiftCompilerPluginMessageHandling/StandardIOMessageConnection.swift index 9ad7cc46542..74bb6768d38 100644 --- a/Sources/SwiftCompilerPluginMessageHandling/StandardIOMessageConnection.swift +++ b/Sources/SwiftCompilerPluginMessageHandling/StandardIOMessageConnection.swift @@ -152,6 +152,10 @@ public struct StandardIOMessageConnection: MessageConnection { // Read the JSON payload. let count = Int(UInt64(littleEndian: header)) + // Empty message is a termination signal. + if count == 0 { + return nil + } let data = UnsafeMutableRawBufferPointer.allocate(byteCount: count, alignment: 1) defer { data.deallocate() } try _read(into: data)