Skip to content
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

Fix redundant reexports of IReference bindings #481

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions Generator/Sources/SwiftWinRT/Writing/ABIBinding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ import struct Foundation.UUID

/// Writes a type or extension providing the ABIBinding conformance for a given projected WinRT type.
internal func writeABIBindingConformance(_ typeDefinition: TypeDefinition, genericArgs: [TypeNode]?, projection: Projection, to writer: SwiftSourceFileWriter) throws {
if SupportModules.WinRT.getBuiltInTypeKind(typeDefinition) == .definitionAndBinding {
// The support module already defines a projection, just reexport it.
if typeDefinition.isReferenceType {
writer.writeImport(exported: true, kind: .enum,
module: SupportModules.WinRT.moduleName,
symbolName: try projection.toBindingTypeName(typeDefinition))
}
else {
// The struct conforms to ABIBinding itself, and we already imported it.
}
return
}

if let structDefinition = typeDefinition as? StructDefinition {
assert(genericArgs == nil)
try writeStructBindingExtension(structDefinition, projection: projection, to: writer)
Expand Down
25 changes: 25 additions & 0 deletions Generator/Sources/SwiftWinRT/writeProjectionFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,36 @@ fileprivate func writeTypeDefinitionFile(
}

fileprivate func writeABIBindingConformanceFile(_ typeDefinition: TypeDefinition, module: Module, toPath path: String) throws {
let bindingDefinedInSupportModule = SupportModules.WinRT.getBuiltInTypeKind(typeDefinition) == .definitionAndBinding
if bindingDefinedInSupportModule {
if !module.hasTypeDefinition(typeDefinition) {
// This is a generic instantiation of a type that is defined in the support module.
// Since the support module defines the binding, it must be defined in a way that
// covers all generic instantiations, e.g. WindowsFoundation_IReferenceBinding.
return
}
if typeDefinition.isValueType {
// We're generating the module for WindowsFoundation and this type is a value type,
// like WindowsFoundation_Point. We're reexporting the type from the support module
// elsewhere, and it implements ABIBinding itself, so we don't need to generate it again.
return
}
}

let writer = SwiftSourceFileWriter(output: FileTextOutputStream(path: path, directoryCreation: .ancestors))
writeGeneratedCodePreamble(to: writer)
writeModulePreamble(module, to: writer)

if module.hasTypeDefinition(typeDefinition) {
if bindingDefinedInSupportModule {
// We're generating the module for WindowsFoundation and this type's binding is defined in the support module,
// like WindowsFoundation_IStringableBinding. Just reexport the binding here.
writer.writeImport(exported: true, kind: .enum,
module: SupportModules.WinRT.moduleName,
symbolName: try module.projection.toBindingTypeName(typeDefinition))
return
}

try writeABIBindingConformance(typeDefinition, genericArgs: nil, projection: module.projection, to: writer)
}

Expand Down
Loading