Skip to content

Commit

Permalink
Use @retroactive only with Swift language versions which require it
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Feb 19, 2024
1 parent 6b9b1b5 commit a672dc0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions Generator/Sources/ProjectionGenerator/SupportModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum SupportModule {
extension SupportModule {
public static var winrtModuleName: String { "WindowsRuntime" }

public static var comIInspectableStruct: SwiftType { .chain(winrtModuleName, "COMIInspectableStruct") }
public static var eventRegistration: SwiftType { .chain(winrtModuleName, "EventRegistration") }
public static var eventRegistrationToken: SwiftType { .chain(winrtModuleName, "EventRegistrationToken") }
public static var hstringProjection: SwiftType { .chain(winrtModuleName, "HStringProjection") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ fileprivate func writeCOMInteropExtension(abiType: BoundType, abiName: String, m

if abiType.definition is InterfaceDefinition {
// COM interfaces for WinRT interfaces are IInspectable-compatible. This is not true for delegates.
writer.output.writeFullLine(grouping: .never, "extension \(qualifiedAbiName): @retroactive WindowsRuntime.COMIInspectableStruct {}")
// @retroactive is only supported in Swift 5.10 and above.
let group = writer.output.allocateVerticalGrouping()
writer.output.writeFullLine(grouping: group, "#if swift(>=5.10)")
writer.output.writeFullLine(grouping: group, "extension \(qualifiedAbiName): @retroactive \(SupportModule.comIInspectableStruct) {}")
writer.output.writeFullLine(grouping: group, "#else")
writer.output.writeFullLine(grouping: group, "extension \(qualifiedAbiName): \(SupportModule.comIInspectableStruct) {}")
writer.output.writeFullLine(grouping: group, "#endif")
}

try writer.writeExtension(name: "COMInterop", whereClauses: [ "Interface == \(qualifiedAbiName)" ]) { writer in
Expand Down
1 change: 1 addition & 0 deletions Generator/Sources/SwiftWinRT/Writing/ClassDefinition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ fileprivate func writeActivationFactoryInitializers(
for method in activationFactory.methods {
let (params, returnParam) = try projection.getParamProjections(method: method, genericTypeArgs: [])
try writer.writeInit(
documentation: try projection.getDocumentationComment(method),
visibility: .public,
convenience: true,
params: params.map { $0.toSwiftParam() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fileprivate func writeInterfacePropertyImplementation(
if let getter = try property.getter, try getter.hasReturnValue {
let returnParamProjection = try projection.getParamProjection(getter.returnParam, genericTypeArgs: typeGenericArgs)
try writer.writeComputedProperty(
documentation: try projection.getDocumentationComment(property),
visibility: .public,
static: `static`,
name: SwiftProjection.toMemberName(property),
Expand All @@ -61,6 +62,7 @@ fileprivate func writeInterfacePropertyImplementation(
guard let newValueParam = try setter.params.first else { fatalError() }
let newValueParamProjection = try projection.getParamProjection(newValueParam, genericTypeArgs: typeGenericArgs)
try writer.writeFunc(
documentation: try projection.getDocumentationComment(property),
visibility: .public,
static: `static`,
name: SwiftProjection.toMemberName(property),
Expand All @@ -84,6 +86,7 @@ fileprivate func writeInterfaceEventImplementation(
let handlerParamProjection = try projection.getParamProjection(handlerParameter, genericTypeArgs: typeGenericArgs)
let eventRegistrationType = SupportModule.eventRegistration
try writer.writeFunc(
documentation: try projection.getDocumentationComment(event),
visibility: .public, static: `static`, name: name,
params: [ handlerParamProjection.toSwiftParam(label: "adding") ], throws: true,
returnType: eventRegistrationType) { writer throws in
Expand All @@ -104,6 +107,7 @@ fileprivate func writeInterfaceEventImplementation(
if let removeAccessor = try event.removeAccessor, let tokenParameter = try removeAccessor.params.first {
let tokenParamProjection = try projection.getParamProjection(tokenParameter, genericTypeArgs: typeGenericArgs)
try writer.writeFunc(
documentation: try projection.getDocumentationComment(event),
visibility: .public,
static: `static`,
name: name,
Expand All @@ -122,6 +126,7 @@ fileprivate func writeInterfaceMethodImplementation(
projection: SwiftProjection, to writer: SwiftTypeDefinitionWriter) throws {
let (params, returnParam) = try projection.getParamProjections(method: method, genericTypeArgs: typeGenericArgs)
try writer.writeFunc(
documentation: try projection.getDocumentationComment(method),
visibility: .public,
static: `static`,
name: SwiftProjection.toMemberName(method),
Expand Down

0 comments on commit a672dc0

Please sign in to comment.