diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/MachOSwiftSection-Package.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/MachOSwiftSection-Package.xcscheme
index bd5a5f4d..654b2126 100644
--- a/.swiftpm/xcode/xcshareddata/xcschemes/MachOSwiftSection-Package.xcscheme
+++ b/.swiftpm/xcode/xcshareddata/xcschemes/MachOSwiftSection-Package.xcscheme
@@ -212,6 +212,20 @@
ReferencedContainer = "container:">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/swift-section.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/swift-section.xcscheme
index 000b68ef..8336ee10 100644
--- a/.swiftpm/xcode/xcshareddata/xcschemes/swift-section.xcscheme
+++ b/.swiftpm/xcode/xcshareddata/xcschemes/swift-section.xcscheme
@@ -100,6 +100,16 @@
ReferencedContainer = "container:">
+
+
+
+
` to regenerate the baseline.
+6. Re-run the affected Suite.
+
+To regenerate all baselines after fixture rebuild or toolchain upgrade:
+
+```bash
+xcodebuild -project Tests/Projects/SymbolTests/SymbolTests.xcodeproj -scheme SymbolTestsCore -configuration Release build
+swift package --allow-writing-to-package-directory regen-baselines
+git diff Tests/MachOSwiftSectionTests/Fixtures/__Baseline__/ # review drift
+```
+
+The `regen-baselines` command is provided by the `RegenerateBaselinesPlugin`
+SwiftPM command plugin (`Plugins/RegenerateBaselinesPlugin/`). It builds and
+invokes the `baseline-generator` executable target. From Xcode you can also
+right-click the package → "Regenerate MachOSwiftSection fixture-test ABI
+baselines.".
+
## Work In Progress
### GenericSpecializer (feature/generic-specializer branch)
diff --git a/Package.swift b/Package.swift
index 048d6e9a..5b2ebcac 100644
--- a/Package.swift
+++ b/Package.swift
@@ -138,7 +138,7 @@ var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/p-x9/swift-fileio.git", from: "0.9.0"),
.package(url: "https://github.com/Mx-Iris/FrameworkToolbox", from: "0.4.0"),
- .package(url: "https://github.com/MxIris-Library-Forks/swift-memberwise-init-macro", from: "0.5.3-fork"),
+ .package(url: "https://github.com/gohanlon/swift-memberwise-init-macro", from: "0.6.0"),
.package(url: "https://github.com/Mx-Iris/SourceKitD", from: "0.1.0"),
.package(url: "https://github.com/christophhagen/BinaryCodable", from: "3.1.0"),
@@ -483,6 +483,38 @@ extension Target {
]
)
+ static let baseline_generator = Target.executableTarget(
+ name: "baseline-generator",
+ dependencies: [
+ .target(.MachOFixtureSupport),
+ .product(name: "ArgumentParser", package: "swift-argument-parser"),
+ ],
+ swiftSettings: testSettings
+ )
+
+ // MARK: - Plugins
+
+ /// `swift package regen-baselines` — regenerates the auto-generated
+ /// `__Baseline__/Baseline.swift` files consumed by the fixture-based
+ /// test coverage suites. Replaces the legacy `Scripts/regen-baselines.sh`.
+ static let RegenerateBaselinesPlugin = Target.plugin(
+ name: "RegenerateBaselinesPlugin",
+ capability: .command(
+ intent: .custom(
+ verb: "regen-baselines",
+ description: "Regenerate MachOSwiftSection fixture-test ABI baselines."
+ ),
+ permissions: [
+ .writeToPackageDirectory(
+ reason: "Writes regenerated baselines under Tests/MachOSwiftSectionTests/Fixtures/__Baseline__/."
+ )
+ ]
+ ),
+ dependencies: [
+ .target(.baseline_generator),
+ ]
+ )
+
// MARK: - Macros
static let MachOMacros = Target.macro(
@@ -497,19 +529,45 @@ extension Target {
// MARK: - Testing
- static let MachOTestingSupport = Target.target(
- name: "MachOTestingSupport",
+ /// Fixture-loading helpers, baseline generators, coverage scanners, and
+ /// non-Testing-dependent code. Importable from non-test targets (e.g.
+ /// `baseline-generator`) without dragging in `Testing.framework`.
+ static let MachOFixtureSupport = Target.target(
+ name: "MachOFixtureSupport",
dependencies: [
.product(.MachOKit),
.target(.MachOExtensions),
+ .target(.MachOFoundation),
+ .target(.MachOReading),
+ .target(.MachOResolving),
+ .target(.MachOSwiftSectionC),
.target(.SwiftDump),
.target(.SwiftInterface),
.target(.MachOTestingSupportC),
- .product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
+ .product(.Demangling),
+ .product(.SwiftSyntax),
+ .product(.SwiftParser),
+ .product(.SwiftSyntaxBuilder),
],
swiftSettings: testSettings
)
-
+
+ /// `swift-testing` base classes (`MachOFileTests`, `MachOImageTests`,
+ /// `DyldCacheTests`, `XcodeMachOFileTests`, `MachOSwiftSectionFixtureTests`).
+ /// Splitting this out from `MachOFixtureSupport` keeps `Testing.framework`
+ /// out of the link line for non-test targets.
+ static let MachOTestingSupport = Target.target(
+ name: "MachOTestingSupport",
+ dependencies: [
+ .product(.MachOKit),
+ .target(.MachOFoundation),
+ .target(.MachOReading),
+ .target(.MachOResolving),
+ .target(.MachOFixtureSupport),
+ ],
+ swiftSettings: testSettings
+ )
+
static let MachOTestingSupportC = Target.target(
name: "MachOTestingSupportC",
dependencies: [
@@ -522,6 +580,7 @@ extension Target {
dependencies: [
.target(.MachOSymbols),
.target(.MachOTestingSupport),
+ .target(.MachOFixtureSupport),
],
swiftSettings: testSettings
)
@@ -531,6 +590,7 @@ extension Target {
dependencies: [
.target(.MachOSwiftSection),
.target(.MachOTestingSupport),
+ .target(.MachOFixtureSupport),
.target(.SwiftDump),
],
swiftSettings: testSettings
@@ -541,6 +601,7 @@ extension Target {
dependencies: [
.target(.MachOSwiftSection),
.target(.MachOTestingSupport),
+ .target(.MachOFixtureSupport),
.target(.SwiftInspection),
],
swiftSettings: testSettings
@@ -551,6 +612,7 @@ extension Target {
dependencies: [
.target(.SwiftDump),
.target(.MachOTestingSupport),
+ .target(.MachOFixtureSupport),
.product(.MachOObjCSection),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
@@ -562,6 +624,7 @@ extension Target {
dependencies: [
.target(.TypeIndexing),
.target(.MachOTestingSupport),
+ .target(.MachOFixtureSupport),
],
swiftSettings: testSettings
)
@@ -571,10 +634,51 @@ extension Target {
dependencies: [
.target(.SwiftInterface),
.target(.MachOTestingSupport),
+ .target(.MachOFixtureSupport),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
swiftSettings: testSettings
)
+
+ static let MachOTestingSupportTests = Target.testTarget(
+ name: "MachOTestingSupportTests",
+ dependencies: [
+ .target(.MachOTestingSupport),
+ .target(.MachOFixtureSupport),
+ ],
+ exclude: [
+ "Coverage/Fixtures/SampleSource.swift.txt",
+ "Coverage/Fixtures/SuiteSampleSource.swift.txt",
+ ],
+ swiftSettings: testSettings
+ )
+
+ static let IntegrationTests = Target.testTarget(
+ name: "IntegrationTests",
+ dependencies: [
+ .target(.MachOExtensions),
+ .target(.MachOCaches),
+ .target(.MachOReading),
+ .target(.MachOResolving),
+ .target(.MachOSymbols),
+ .target(.MachOPointers),
+ .target(.MachOSymbolPointers),
+ .target(.MachOFoundation),
+ .target(.MachOSwiftSection),
+ .target(.SwiftInspection),
+ .target(.SwiftDump),
+ .target(.SwiftInterface),
+ .target(.TypeIndexing),
+ .target(.MachOTestingSupport),
+ .target(.MachOFixtureSupport),
+ .product(.MachOKit),
+ .product(.MachOObjCSection),
+ .product(.Demangling),
+ .product(.Semantic),
+ .product(name: "Dependencies", package: "swift-dependencies"),
+ ],
+ swiftSettings: testSettings
+ )
}
let package = Package(
@@ -607,11 +711,16 @@ let package = Package(
.SwiftInterface,
.TypeIndexing,
.MachOMacros,
+ .MachOFixtureSupport,
.MachOTestingSupport,
.MachOTestingSupportC,
// Executable
.swift_section,
+ .baseline_generator,
+
+ // Plugins
+ .RegenerateBaselinesPlugin,
// Testing
.MachOSymbolsTests,
@@ -620,6 +729,8 @@ let package = Package(
.SwiftDumpTests,
.TypeIndexingTests,
.SwiftInterfaceTests,
+ .MachOTestingSupportTests,
+ .IntegrationTests,
]
)
diff --git a/Plugins/RegenerateBaselinesPlugin/RegenerateBaselinesPlugin.swift b/Plugins/RegenerateBaselinesPlugin/RegenerateBaselinesPlugin.swift
new file mode 100644
index 00000000..710d0a0b
--- /dev/null
+++ b/Plugins/RegenerateBaselinesPlugin/RegenerateBaselinesPlugin.swift
@@ -0,0 +1,81 @@
+import Foundation
+import PackagePlugin
+
+/// `swift package regen-baselines [--suite ] [--output ]`
+///
+/// Builds and invokes the `baseline-generator` executable target to regenerate
+/// the auto-generated `__Baseline__/Baseline.swift` files consumed by
+/// the fixture-based test coverage suites under
+/// `Tests/MachOSwiftSectionTests/Fixtures/`.
+///
+/// Replaces the legacy `Scripts/regen-baselines.sh` wrapper. Differences:
+/// - The default `--output` resolves against `context.package.directoryURL`,
+/// so the command works from any working directory (Xcode's plugin runner
+/// does not chdir to the package root).
+/// - Write access to the package directory is declared up-front via
+/// `permissions: [.writeToPackageDirectory(reason:)]`, so both `swift
+/// package` and Xcode prompt the user before writing baselines.
+///
+/// All command-line arguments are forwarded verbatim to `baseline-generator`,
+/// which uses `swift-argument-parser` and accepts `--suite`/`--output`.
+@main
+struct RegenerateBaselinesPlugin: CommandPlugin {
+ func performCommand(context: PluginContext, arguments: [String]) async throws {
+ let baselineGeneratorTool = try context.tool(named: "baseline-generator")
+
+ var forwardedArguments = arguments
+ if !userProvidedOutputArgument(in: forwardedArguments) {
+ let defaultOutputURL = context.package.directoryURL
+ .appending(path: "Tests/MachOSwiftSectionTests/Fixtures/__Baseline__")
+ forwardedArguments.append(contentsOf: ["--output", defaultOutputURL.path()])
+ }
+
+ // Capture stdout/stderr via pipes and re-emit through the plugin's own
+ // file handles. SwiftPM's plugin sandbox silently drops direct stdio
+ // inheritance from child processes, so the bytes have to be copied
+ // explicitly. The synchronous read after `waitUntilExit` is safe for
+ // `baseline-generator` because its output (only ArgumentParser errors
+ // and the occasional throw trace) stays well below the OS pipe
+ // buffer; if that ever changes, switch to streaming via a detached
+ // forwarding Task.
+ let standardOutputPipe = Pipe()
+ let standardErrorPipe = Pipe()
+
+ let baselineProcess = Process()
+ baselineProcess.executableURL = baselineGeneratorTool.url
+ baselineProcess.arguments = forwardedArguments
+ baselineProcess.standardOutput = standardOutputPipe
+ baselineProcess.standardError = standardErrorPipe
+
+ try baselineProcess.run()
+ baselineProcess.waitUntilExit()
+
+ let standardOutputData = standardOutputPipe.fileHandleForReading.readDataToEndOfFile()
+ let standardErrorData = standardErrorPipe.fileHandleForReading.readDataToEndOfFile()
+ if !standardOutputData.isEmpty {
+ try FileHandle.standardOutput.write(contentsOf: standardOutputData)
+ }
+ if !standardErrorData.isEmpty {
+ try FileHandle.standardError.write(contentsOf: standardErrorData)
+ }
+
+ guard baselineProcess.terminationStatus == 0 else {
+ throw RegenerateBaselinesPluginError.subprocessFailed(status: baselineProcess.terminationStatus)
+ }
+ }
+
+ private func userProvidedOutputArgument(in arguments: [String]) -> Bool {
+ arguments.contains(where: { $0 == "--output" || $0.hasPrefix("--output=") })
+ }
+}
+
+enum RegenerateBaselinesPluginError: Error, CustomStringConvertible {
+ case subprocessFailed(status: Int32)
+
+ var description: String {
+ switch self {
+ case .subprocessFailed(let status):
+ return "baseline-generator exited with status \(status)"
+ }
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/BaselineEmitter.swift b/Sources/MachOFixtureSupport/Baseline/BaselineEmitter.swift
new file mode 100644
index 00000000..eb6bf474
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/BaselineEmitter.swift
@@ -0,0 +1,24 @@
+import Foundation
+
+/// Tiny helper providing the few literal forms that SwiftSyntaxBuilder's
+/// `\(literal:)` does NOT produce in the form we want for ABI baselines.
+///
+/// Specifically: integers via `\(literal:)` come out as decimal Swift literals,
+/// but baseline files emit offsets/sizes/flags as hex (`0x...`) for parity with
+/// `otool` / Hopper output. Use these helpers with `\(raw:)` in the
+/// SwiftSyntaxBuilder source string.
+///
+/// For everything else — strings, bools, decimal ints, arrays of strings,
+/// optionals — use `\(literal:)` directly; SwiftSyntaxBuilder handles escaping.
+package enum BaselineEmitter {
+ /// Emit `0x` for any binary integer (sign-extends to UInt64).
+ package static func hex(_ value: T) -> String {
+ let unsigned = UInt64(truncatingIfNeeded: value)
+ return "0x\(String(unsigned, radix: 16))"
+ }
+
+ /// Emit `[0x..., 0x..., ...]` for an array of binary integers.
+ package static func hexArray(_ values: [T]) -> String {
+ "[\(values.map(hex).joined(separator: ", "))]"
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/BaselineFixturePicker.swift b/Sources/MachOFixtureSupport/Baseline/BaselineFixturePicker.swift
new file mode 100644
index 00000000..18453f2e
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/BaselineFixturePicker.swift
@@ -0,0 +1,734 @@
+import Foundation
+import MachOExtensions
+import MachOFoundation
+import MachOKit
+@testable import MachOSwiftSection
+
+/// Centralizes the "pick (main + variants) fixture entities for each descriptor type"
+/// logic, ensuring Suites and their corresponding BaselineGenerators look at the
+/// same set of entities.
+///
+/// Both target descriptors have unique `name(in:)` values within the
+/// `SymbolTestsCore` fixture, so a parent-chain disambiguator is unnecessary.
+package enum BaselineFixturePicker {
+ /// Picks the concrete (non-generic) struct `Structs.StructTest` from the
+ /// `SymbolTestsCore` fixture.
+ package static func struct_StructTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> StructDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "StructTest"
+ })
+ )
+ }
+
+ /// Picks the generic struct
+ /// `GenericFieldLayout.GenericStructNonRequirement` from the
+ /// `SymbolTestsCore` fixture. Exercises generic context paths.
+ package static func struct_GenericStructNonRequirement(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> StructDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "GenericStructNonRequirement"
+ })
+ )
+ }
+
+ /// Picks the generic struct
+ /// `GenericFieldLayout.GenericStructLayoutRequirement` from
+ /// the `SymbolTestsCore` fixture. Exercises a layout-class generic
+ /// requirement (`A: AnyObject`) — surfaces a single
+ /// `GenericRequirementDescriptor` whose flags carry
+ /// `GenericRequirementKind.layout` with payload `class`.
+ package static func struct_GenericStructLayoutRequirement(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> StructDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "GenericStructLayoutRequirement"
+ })
+ )
+ }
+
+ /// Picks the generic struct
+ /// `GenericFieldLayout.GenericStructSwiftProtocolRequirement`
+ /// from the `SymbolTestsCore` fixture. Exercises a Swift-protocol
+ /// generic requirement (`A: Equatable`) — surfaces
+ /// `GenericRequirementDescriptor` with kind `.protocol`, content carrying a
+ /// Swift `RelativeProtocolDescriptorPointer`.
+ package static func struct_GenericStructSwiftProtocolRequirement(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> StructDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "GenericStructSwiftProtocolRequirement"
+ })
+ )
+ }
+
+ /// Picks the generic struct
+ /// `GenericFieldLayout.GenericStructObjCProtocolRequirement`
+ /// from the `SymbolTestsCore` fixture. Exercises an ObjC-protocol
+ /// generic requirement (`A: NSCopying`) — surfaces a
+ /// `GenericRequirementDescriptor` with kind `.protocol`, content carrying
+ /// an ObjC `RelativeProtocolDescriptorPointer`.
+ package static func struct_GenericStructObjCProtocolRequirement(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> StructDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "GenericStructObjCProtocolRequirement"
+ })
+ )
+ }
+
+ /// Picks the generic struct
+ /// `GenericRequirementVariants.SameTypeRequirementTest`
+ /// (`where First == Second`) from the `SymbolTestsCore` fixture.
+ /// Exercises a `sameType` generic requirement — surfaces a
+ /// `GenericRequirementDescriptor` with kind `.sameType`, content carrying
+ /// a `RelativeDirectPointer`.
+ package static func struct_SameTypeRequirementTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> StructDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "SameTypeRequirementTest"
+ })
+ )
+ }
+
+ /// Picks the generic struct
+ /// `GenericRequirementVariants.ParameterPackRequirementTest`
+ /// from the `SymbolTestsCore` fixture. Exercises a parameter-pack
+ /// generic context — the type's generic context surfaces a non-nil
+ /// `typePackHeader` and at least one `GenericPackShapeDescriptor`.
+ package static func struct_ParameterPackRequirementTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> StructDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "ParameterPackRequirementTest"
+ })
+ )
+ }
+
+ /// Picks the generic struct
+ /// `GenericRequirementVariants.InvertibleProtocolRequirementTest: ~Copyable`
+ /// from the `SymbolTestsCore` fixture. Exercises a generic context
+ /// carrying conditional invertible-protocol requirements (the `~Copyable`
+ /// bit is encoded inline on the type's generic signature) — surfaces a
+ /// non-nil `conditionalInvertibleProtocolSet` /
+ /// `conditionalInvertibleProtocolsRequirementsCount` on the
+ /// `TargetGenericContext`.
+ package static func struct_InvertibleProtocolRequirementTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> StructDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "InvertibleProtocolRequirementTest"
+ })
+ )
+ }
+
+ /// Picks the generic struct
+ /// `GenericRequirementVariants.BaseClassRequirementTest`
+ /// from the `SymbolTestsCore` fixture. Exercises a `baseClass` generic
+ /// requirement — surfaces a `GenericRequirementDescriptor` with kind
+ /// `.baseClass`, content carrying a `RelativeDirectPointer`
+ /// to the base-class mangled name.
+ package static func struct_BaseClassRequirementTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> StructDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "BaseClassRequirementTest"
+ })
+ )
+ }
+
+ /// Picks an `AnonymousContextDescriptor` from the `SymbolTestsCore`
+ /// fixture. Anonymous contexts arise from generic parameter scopes,
+ /// closures, and other unnamed contexts; they don't appear directly in
+ /// `__swift5_types`/`__swift5_types2` records, so we discover them by
+ /// walking the parent chain of every type descriptor and returning the
+ /// first anonymous one encountered.
+ package static func anonymous_first(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> AnonymousContextDescriptor {
+ for typeDescriptor in try machO.swift.contextDescriptors {
+ var current: SymbolOrElement? = try typeDescriptor.parent(in: machO)
+ while let cursor = current {
+ if let resolved = cursor.resolved {
+ if let anonymous = resolved.anonymousContextDescriptor {
+ return anonymous
+ }
+ current = try resolved.parent(in: machO)
+ } else {
+ current = nil
+ }
+ }
+ }
+ throw RequiredError.requiredNonOptional
+ }
+
+ /// Picks the `SymbolTestsCore` module's `ModuleContextDescriptor` —
+ /// every type in the fixture chains up to it. Module contexts don't
+ /// appear directly in `__swift5_types`/`__swift5_types2` records, so we
+ /// discover them by walking the parent chain of every type descriptor
+ /// and selecting the module whose `name(in:)` is `"SymbolTestsCore"`.
+ package static func module_SymbolTestsCore(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ModuleContextDescriptor {
+ for typeDescriptor in try machO.swift.contextDescriptors {
+ var current: SymbolOrElement? = try typeDescriptor.parent(in: machO)
+ while let cursor = current {
+ if let resolved = cursor.resolved {
+ if let module = resolved.moduleContextDescriptor,
+ try module.name(in: machO) == "SymbolTestsCore" {
+ return module
+ }
+ current = try resolved.parent(in: machO)
+ } else {
+ current = nil
+ }
+ }
+ }
+ throw RequiredError.requiredNonOptional
+ }
+
+ /// Picks an `ExtensionContextDescriptor` from the `SymbolTestsCore`
+ /// fixture. Extensions don't appear directly in
+ /// `__swift5_types`/`__swift5_types2` records (only the types declared
+ /// inside an extension do), so we discover them by walking the parent
+ /// chain of every type descriptor and returning the first extension
+ /// context encountered. The fixture declares several extensions (e.g.
+ /// `Structs.StructTest: Protocols.ProtocolWitnessTableTest`).
+ package static func extension_first(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ExtensionContextDescriptor {
+ for typeDescriptor in try machO.swift.contextDescriptors {
+ var current: SymbolOrElement? = try typeDescriptor.parent(in: machO)
+ while let cursor = current {
+ if let resolved = cursor.resolved {
+ if let ext = resolved.extensionContextDescriptor {
+ return ext
+ }
+ current = try resolved.parent(in: machO)
+ } else {
+ current = nil
+ }
+ }
+ }
+ throw RequiredError.requiredNonOptional
+ }
+
+ /// Picks the concrete plain Swift class `Classes.ClassTest` from the
+ /// `SymbolTestsCore` fixture. Used as the primary class fixture: it has
+ /// instance/dynamic vars and methods (so a non-empty vtable), no
+ /// resilient superclass, no ObjC interop, and is not a generic class.
+ package static func class_ClassTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ClassDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.class).first(where: { descriptor in
+ try descriptor.name(in: machO) == "ClassTest"
+ })
+ )
+ }
+
+ /// Picks `Classes.SubclassTest: ClassTest` from the `SymbolTestsCore`
+ /// fixture. Used to exercise inheritance/superclass paths in the
+ /// `ClassDescriptor` API surface (e.g. `superclassTypeMangledName`).
+ package static func class_SubclassTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ClassDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.class).first(where: { descriptor in
+ try descriptor.name(in: machO) == "SubclassTest"
+ })
+ )
+ }
+
+ /// Picks the no-payload enum `Enums.NoPayloadEnumTest` (4 cases:
+ /// north/south/east/west) from the `SymbolTestsCore` fixture. Used as
+ /// the primary enum fixture: zero payload cases means `isMultiPayload`
+ /// is false and `payloadSizeOffset` is zero.
+ package static func enum_NoPayloadEnumTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> EnumDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.enum).first(where: { descriptor in
+ try descriptor.name(in: machO) == "NoPayloadEnumTest"
+ })
+ )
+ }
+
+ /// Picks the single-payload enum `Enums.SinglePayloadEnumTest`
+ /// (`case value(String)`, `case none`, `case error`) from the
+ /// `SymbolTestsCore` fixture. Used to exercise the `isSinglePayload`
+ /// branch of the predicate accessors on `EnumDescriptor`.
+ package static func enum_SinglePayloadEnumTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> EnumDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.enum).first(where: { descriptor in
+ try descriptor.name(in: machO) == "SinglePayloadEnumTest"
+ })
+ )
+ }
+
+ /// Picks the multi-payload enum `Enums.MultiPayloadEnumTests`
+ /// (closure / NSObject / tuple / empty) from the `SymbolTestsCore`
+ /// fixture. Used as the primary multi-payload fixture: it surfaces a
+ /// `MultiPayloadEnumDescriptor` in `__swift5_mpenum` and exercises the
+ /// `isMultiPayload` branch on `EnumDescriptor`.
+ package static func enum_MultiPayloadEnumTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> EnumDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.enum).first(where: { descriptor in
+ try descriptor.name(in: machO) == "MultiPayloadEnumTests"
+ })
+ )
+ }
+
+ /// Picks the `MultiPayloadEnumDescriptor` for `Enums.MultiPayloadEnumTests`
+ /// from the `SymbolTestsCore` fixture's `__swift5_mpenum` section. The
+ /// section emits one descriptor per multi-payload enum found.
+ ///
+ /// The mangled-name string applies Swift's identifier substitution rules
+ /// (repeat tokens become `O[A-Z]` byte references), so the literal
+ /// `MultiPayloadEnumTests` may not appear textually. Instead we resolve
+ /// the matching `EnumDescriptor` (which uses its own `name(in:)` ivar)
+ /// and pick the multi-payload descriptor whose mangled-name lookup
+ /// targets it.
+ package static func multiPayloadEnumDescriptor_MultiPayloadEnumTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> MultiPayloadEnumDescriptor {
+ let enumDescriptor = try enum_MultiPayloadEnumTest(in: machO)
+ let targetOffset = enumDescriptor.offset
+ return try required(
+ try machO.swift.multiPayloadEnumDescriptors.first(where: { descriptor in
+ let mangledName = try descriptor.mangledTypeName(in: machO)
+ for lookup in mangledName.lookupElements {
+ guard case .relative(let relative) = lookup.reference else { continue }
+ let resolvedOffset = lookup.offset + Int(relative.relativeOffset)
+ if resolvedOffset == targetOffset {
+ return true
+ }
+ }
+ return false
+ })
+ )
+ }
+
+ /// Picks the associated-type protocol `Protocols.ProtocolTest` from the
+ /// `SymbolTestsCore` fixture. Used as the primary protocol fixture: it
+ /// declares an associated type (`Body`) and the `body` requirement, and
+ /// has a default implementation extension that surfaces a non-empty
+ /// `associatedTypes(in:)` payload.
+ package static func protocol_ProtocolTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ProtocolDescriptor {
+ try required(
+ try machO.swift.protocolDescriptors.first(where: { descriptor in
+ try descriptor.name(in: machO) == "ProtocolTest"
+ })
+ )
+ }
+
+ /// Picks `Protocols.ProtocolWitnessTableTest` from the `SymbolTestsCore`
+ /// fixture. Used to exercise non-trivial witness-table layout: the
+ /// protocol declares five method requirements (`a`/`b`/`c`/`d`/`e`),
+ /// so `numRequirements` is non-zero and the trailing
+ /// `ProtocolRequirement` array is fully populated.
+ package static func protocol_ProtocolWitnessTableTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ProtocolDescriptor {
+ try required(
+ try machO.swift.protocolDescriptors.first(where: { descriptor in
+ try descriptor.name(in: machO) == "ProtocolWitnessTableTest"
+ })
+ )
+ }
+
+ /// Picks `Protocols.BaseProtocolTest` from the `SymbolTestsCore`
+ /// fixture. Used as the base side of the inheritance fixture pair
+ /// (`BaseProtocolTest` / `DerivedProtocolTest`). Has a single
+ /// `baseMethod()` requirement.
+ package static func protocol_BaseProtocolTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ProtocolDescriptor {
+ try required(
+ try machO.swift.protocolDescriptors.first(where: { descriptor in
+ try descriptor.name(in: machO) == "BaseProtocolTest"
+ })
+ )
+ }
+
+ /// Picks the first `ProtocolRecord` from the `SymbolTestsCore` fixture's
+ /// `__swift5_protos` section. Each record is a one-pointer entry that
+ /// resolves to a `ProtocolDescriptor`; we pick the first record so a
+ /// stable, deterministic offset is always available.
+ ///
+ /// The section walk requires the concrete `MachOFile` API
+ /// (`section(for:)`), so the helper is `MachOFile`-only. The companion
+ /// `MachOImage` lookup is performed by re-reading the same section
+ /// offset from the in-memory image.
+ package static func protocolRecord_first(in machO: MachOFile) throws -> ProtocolRecord {
+ let section = try machO.section(for: .__swift5_protos)
+ let sectionOffset: Int
+ if let cache = machO.cache {
+ sectionOffset = section.address - cache.mainCacheHeader.sharedRegionStart.cast()
+ } else {
+ sectionOffset = section.offset
+ }
+ let recordSize = ProtocolRecord.layoutSize
+ let count = section.size / recordSize
+ guard count > 0 else { throw RequiredError.requiredNonOptional }
+ let records: [ProtocolRecord] = try machO.readWrapperElements(
+ offset: sectionOffset,
+ numberOfElements: count
+ )
+ return try required(records.first)
+ }
+
+ /// Image-side companion to `protocolRecord_first(in:)`. Resolves the
+ /// `__swift5_protos` section from the in-memory MachOImage layout so
+ /// the Suite can compare records read via two different code paths.
+ package static func protocolRecord_first(in machO: MachOImage) throws -> ProtocolRecord {
+ let section = try machO.section(for: .__swift5_protos)
+ let sectionOffset: Int
+ if let cache = machO.cache {
+ sectionOffset = section.address - cache.mainCacheHeader.sharedRegionStart.cast()
+ } else {
+ sectionOffset = section.offset
+ }
+ let recordSize = ProtocolRecord.layoutSize
+ let count = section.size / recordSize
+ guard count > 0 else { throw RequiredError.requiredNonOptional }
+ let records: [ProtocolRecord] = try machO.readWrapperElements(
+ offset: sectionOffset,
+ numberOfElements: count
+ )
+ return try required(records.first)
+ }
+
+ /// Picks the first `ProtocolConformance` from the `SymbolTestsCore`
+ /// fixture that declares resilient witnesses. Used to surface a
+ /// non-empty `ResilientWitnessesHeader` and at least one
+ /// `ResilientWitness`. Falls back to a `RequiredError` if no
+ /// resilient-witness conformance exists.
+ package static func protocolConformance_resilientWitnessFirst(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ProtocolConformance {
+ try required(
+ try machO.swift.protocolConformances.first(where: { conformance in
+ conformance.descriptor.flags.hasResilientWitnesses
+ && !conformance.resilientWitnesses.isEmpty
+ })
+ )
+ }
+
+ /// Picks the `Structs.StructTest: Protocols.ProtocolTest` conformance
+ /// from the `SymbolTestsCore` fixture. Used as the primary
+ /// `ProtocolConformance` fixture: the conforming type is a concrete
+ /// struct, the protocol is the plain associated-type-bearing
+ /// `ProtocolTest`, and the conformance is non-retroactive with no
+ /// global-actor isolation, so the trailing-objects layout exercises
+ /// the simplest path.
+ ///
+ /// Identification scheme: walk the conformance list and match the
+ /// pair (conforming-type-descriptor name, protocol-descriptor name).
+ /// Both names are resolved via `NamedContextDescriptorProtocol.name(in:)`
+ /// and are unique within the fixture, so no parent-chain disambiguator
+ /// is needed.
+ package static func protocolConformance_StructTestProtocolTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ProtocolConformance {
+ try required(
+ try machO.swift.protocolConformances.first(where: { conformance in
+ guard try conformanceProtocolName(of: conformance, in: machO) == "ProtocolTest" else {
+ return false
+ }
+ return try conformanceTypeName(of: conformance, in: machO) == "StructTest"
+ })
+ )
+ }
+
+ /// Picks the first conditional `ProtocolConformance` from the
+ /// `SymbolTestsCore` fixture — i.e. a conformance whose
+ /// `ProtocolConformanceFlags.numConditionalRequirements > 0`. Used to
+ /// exercise the trailing `conditionalRequirements` array on
+ /// `ProtocolConformance` and the `numConditionalRequirements` accessor
+ /// on `ProtocolConformanceFlags`. The fixture's
+ /// `ConditionalConformanceVariants.ConditionalContainerTest` extensions
+ /// (e.g. `: Equatable where Element: Equatable`) emit several
+ /// such conformances.
+ package static func protocolConformance_conditionalFirst(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ProtocolConformance {
+ try required(
+ try machO.swift.protocolConformances.first(where: { conformance in
+ conformance.descriptor.flags.numConditionalRequirements > 0
+ && !conformance.conditionalRequirements.isEmpty
+ })
+ )
+ }
+
+ /// Picks the first `ProtocolConformance` from the `SymbolTestsCore`
+ /// fixture that has the `hasGlobalActorIsolation` bit set. The fixture
+ /// declares two such conformances under `Actors`:
+ /// - `Actors.GlobalActorIsolatedConformanceTest: @MainActor Actors.GlobalActorIsolatedProtocolTest`
+ /// - `Actors.GlobalActorIsolatedConformanceTest: @CustomGlobalActor Actors.CustomGlobalActorIsolatedProtocolTest`
+ /// Used to surface a non-nil `globalActorReference` so the
+ /// `GlobalActorReference` Suite has a live carrier.
+ package static func protocolConformance_globalActorFirst(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ProtocolConformance {
+ try required(
+ try machO.swift.protocolConformances.first(where: { conformance in
+ conformance.descriptor.flags.hasGlobalActorIsolation
+ && conformance.globalActorReference != nil
+ })
+ )
+ }
+
+ /// Helper: extract the protocol-descriptor name from a conformance,
+ /// returning `nil` when the protocol pointer is unresolved (a
+ /// cross-image symbol bind) or absent.
+ private static func conformanceProtocolName(
+ of conformance: ProtocolConformance,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String? {
+ guard let protocolReference = conformance.protocol else { return nil }
+ guard case .element(let descriptor) = protocolReference else { return nil }
+ return try descriptor.name(in: machO)
+ }
+
+ /// Helper: extract the conforming-type-descriptor name from a
+ /// conformance, returning `nil` for indirect / ObjC type references
+ /// (which don't carry a Swift name we can match against).
+ private static func conformanceTypeName(
+ of conformance: ProtocolConformance,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String? {
+ switch conformance.typeReference {
+ case .directTypeDescriptor(let wrapper):
+ guard let wrapper else { return nil }
+ return try wrapper.namedContextDescriptor?.name(in: machO)
+ case .indirectTypeDescriptor:
+ return nil
+ case .directObjCClassName:
+ return nil
+ case .indirectObjCClass:
+ return nil
+ }
+ }
+
+ /// Picks the first ObjC protocol prefix referenced anywhere in the
+ /// `SymbolTestsCore` fixture. The fixture's `ObjCInheritingProtocolTest`
+ /// inherits from `NSObjectProtocol`, so at least one ObjC reference is
+ /// materialized via the protocol's requirementInSignatures.
+ ///
+ /// We materialize a `Protocol` for `ObjCInheritingProtocolTest`, then
+ /// walk its requirementInSignatures looking for a `.protocol(ObjC(...))`
+ /// case, returning the resolved `ObjCProtocolPrefix`.
+ package static func objcProtocolPrefix_first(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ObjCProtocolPrefix {
+ let inheritingProtoDescriptor = try required(
+ try machO.swift.protocolDescriptors.first(where: { descriptor in
+ try descriptor.name(in: machO) == "ObjCInheritingProtocolTest"
+ })
+ )
+ let protocolType = try `Protocol`(descriptor: inheritingProtoDescriptor, in: machO)
+ for requirementInSignature in protocolType.requirementInSignatures {
+ if case .protocol(let symbolOrElement) = requirementInSignature.content,
+ case .element(let descriptorWithObjCInterop) = symbolOrElement,
+ case .objc(let objcPrefix) = descriptorWithObjCInterop {
+ return objcPrefix
+ }
+ }
+ throw RequiredError.requiredNonOptional
+ }
+
+ /// Picks the first `ClassDescriptor` from the `SymbolTestsCore` fixture
+ /// that carries the `hasSingletonMetadataInitialization` bit. Used as
+ /// the live carrier for `SingletonMetadataInitialization`. The bit
+ /// fires for resilient-superclass scenarios and certain generic-class
+ /// shapes (e.g. `Classes.ExternalSwiftSubclassTest`).
+ package static func class_singletonMetadataInitFirst(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ClassDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.class).first(where: { descriptor in
+ descriptor.hasSingletonMetadataInitialization
+ })
+ )
+ }
+
+ /// Picks the SymbolTestsCore class
+ /// `ResilientClassFixtures.ResilientChild` — a subclass of the
+ /// cross-module `SymbolTestsHelper.ResilientBase` (library-evolution
+ /// build mode), which causes the descriptor to carry a
+ /// `ResilientSuperclass` tail record (tail-objects layout) and forces
+ /// metadata bounds to be resolved at runtime via
+ /// `StoredClassMetadataBounds`.
+ package static func class_ResilientChild(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ClassDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.class).first(where: { descriptor in
+ try descriptor.name(in: machO) == "ResilientChild"
+ })
+ )
+ }
+
+ /// Picks the SymbolTestsCore class
+ /// `ObjCClassWrapperFixtures.ObjCBridge` — an NSObject-derived Swift
+ /// class. The class's metadata accessor returns
+ /// `ClassMetadataObjCInterop`, and its superclass chain reaches
+ /// NSObject's `ObjCClassWrapperMetadata` (kind 0x305). Phase B3
+ /// introduced the fixture to give the ObjC-interop metadata Suites a
+ /// fixture-owned, deterministic carrier (rather than relying on a
+ /// plain Swift class that happens to use the ObjC-interop metadata
+ /// shape on Apple platforms).
+ package static func class_ObjCBridge(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ClassDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.class).first(where: { descriptor in
+ try descriptor.name(in: machO) == "ObjCBridge"
+ })
+ )
+ }
+
+ /// Picks the SymbolTestsCore class
+ /// `ObjCClassWrapperFixtures.ObjCBridgeWithProto` — an NSObject-derived
+ /// Swift class conforming to the `@objc protocol ObjCProto`. Phase B3
+ /// reserves the picker for completeness; `@objc protocol` does not
+ /// emit a Swift-side conformance descriptor, so the conformance is
+ /// not reachable through `swift.protocolConformances`.
+ package static func class_ObjCBridgeWithProto(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ClassDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.class).first(where: { descriptor in
+ try descriptor.name(in: machO) == "ObjCBridgeWithProto"
+ })
+ )
+ }
+
+ /// Picks the SymbolTestsCore class
+ /// `ObjCResilientStubFixtures.ResilientObjCStubChild` — a non-generic
+ /// Swift class subclassing the cross-module
+ /// `SymbolTestsHelper.Object`, which forces the resilient metadata
+ /// strategy. Combined with ObjC interop being on, the Swift compiler
+ /// emits an `ObjCResilientClassStubInfo` trailing record on the
+ /// class descriptor (and a corresponding `CMt` "full ObjC
+ /// resilient class stub" symbol). Phase B4 added the fixture to give
+ /// the `ObjCResilientClassStubInfo` Suite a stably-named,
+ /// deterministic carrier independent of any other fixture's
+ /// vTable/method shape.
+ package static func class_ResilientObjCStubChild(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> ClassDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.class).first(where: { descriptor in
+ try descriptor.name(in: machO) == "ResilientObjCStubChild"
+ })
+ )
+ }
+
+ /// Picks the `AssociatedTypeDescriptor` whose conforming type is
+ /// `AssociatedTypeWitnessPatterns.ConcreteWitnessTest` and whose protocol
+ /// is `AssociatedTypeWitnessPatterns.AssociatedPatternProtocol`. The
+ /// fixture declares this conformance with five concrete witnesses
+ /// (`First = Int`, `Second = [String]`, `Third = Double`, `Fourth = Bool`,
+ /// `Fifth = Character`), so the descriptor surfaces five
+ /// `AssociatedTypeRecord`s — non-trivial test data for both
+ /// `AssociatedTypeDescriptor` (the raw payload) and `AssociatedType`
+ /// (the high-level wrapper).
+ ///
+ /// Identification scheme: `AssociatedTypeDescriptor` does not carry a
+ /// direct name. Instead its `conformingTypeName(in:)` resolves to a
+ /// `MangledName` whose lookup elements point back to the
+ /// `TypeContextDescriptor` for the conforming type. We resolve the
+ /// `StructDescriptor` for `ConcreteWitnessTest` first, then walk the
+ /// `__swift5_assocty` records and pick the one whose conformingTypeName
+ /// targets that descriptor's offset. (Mirrors
+ /// `multiPayloadEnumDescriptor_MultiPayloadEnumTest`'s strategy.)
+ package static func associatedTypeDescriptor_ConcreteWitnessTest(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> AssociatedTypeDescriptor {
+ let conformingDescriptor = try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "ConcreteWitnessTest"
+ })
+ )
+ let targetOffset = conformingDescriptor.offset
+ return try required(
+ try machO.swift.associatedTypeDescriptors.first(where: { descriptor in
+ let mangledName = try descriptor.conformingTypeName(in: machO)
+ for lookup in mangledName.lookupElements {
+ guard case .relative(let relative) = lookup.reference else { continue }
+ let resolvedOffset = lookup.offset + Int(relative.relativeOffset)
+ if resolvedOffset == targetOffset {
+ return true
+ }
+ }
+ return false
+ })
+ )
+ }
+
+ /// Picks the first `BuiltinTypeDescriptor` from the `SymbolTestsCore`
+ /// fixture's `__swift5_builtin` section. The fixture's
+ /// `BuiltinTypeFields` namespace declares structs with `Int`/`Float`/
+ /// `Bool`/`Character`/`String` fields, which causes the Swift compiler
+ /// to emit one `BuiltinTypeDescriptor` per primitive backing type used
+ /// in fields. We pick the first descriptor for stability — the order
+ /// is deterministic across builds with the same toolchain.
+ package static func builtinTypeDescriptor_first(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> BuiltinTypeDescriptor {
+ try required(try machO.swift.builtinTypeDescriptors.first)
+ }
+
+ // Note: an `opaqueTypeDescriptor_first` picker was attempted but
+ // SymbolTestsCore's opaque-type descriptors don't surface via
+ // `swift.contextDescriptors` (the `__swift5_types2` records on the
+ // current toolchain index struct/enum extras, not opaque types) nor
+ // via any context's parent chain. The OpaqueType, OpaqueTypeDescriptor,
+ // and OpaqueTypeDescriptorProtocol Suites therefore exercise their
+ // public surface against synthetic memberwise instances. Adding a
+ // fixture variant that emits an opaque type via a discoverable
+ // channel (e.g. a top-level typealias whose underlying-type
+ // relationship can be walked back) would let those Suites use a
+ // live carrier.
+
+ /// Picks the SymbolTestsCore struct
+ /// `GenericValueFixtures.FixedSizeArray` — a generic
+ /// type that declares one integer-value parameter (`N`) and one
+ /// type parameter (`T`). The Swift compiler emits an extra
+ /// `GenericValueHeader` followed by one `GenericValueDescriptor`
+ /// (with `GenericValueType.int`) on the struct's generic context
+ /// (the `GenericContextDescriptorFlags.hasValues` bit is set).
+ /// Phase B7 added the fixture so that the
+ /// `GenericValueDescriptor` and `GenericValueHeader` Suites have
+ /// live carriers for cross-reader equality assertions.
+ package static func struct_FixedSizeArray(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> StructDescriptor {
+ try required(
+ try machO.swift.typeContextDescriptors.compactMap(\.struct).first(where: { descriptor in
+ try descriptor.name(in: machO) == "FixedSizeArray"
+ })
+ )
+ }
+
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/BaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/BaselineGenerator.swift
new file mode 100644
index 00000000..c6b358a4
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/BaselineGenerator.swift
@@ -0,0 +1,850 @@
+import Foundation
+import MachOExtensions
+import MachOFoundation
+import MachOKit
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Top-level dispatcher for the per-suite baseline sub-generators.
+///
+/// Each `Models//.swift` produces a corresponding
+/// `Baseline.swift` literal under `__Baseline__/`. The dispatcher's only
+/// jobs are loading the fixture MachOFile and routing to the right
+/// sub-generator.
+///
+/// Pilot scope (Task 4): only `Type/Struct/` Suites. Tasks 5-15 each add one
+/// `case` to `dispatchSuite` and one `try dispatchSuite(...)` line to
+/// `generateAll`.
+///
+/// **Protocol-extension method attribution rule.**
+///
+/// `PublicMemberScanner` attributes a method's `MethodKey.typeName` based on the
+/// `extendedType` of its enclosing `extension`, NOT the file it lives in.
+///
+/// Example: `Extension/ExtensionContextDescriptor.swift` contains
+/// `extension ExtensionContextDescriptorProtocol { public func extendedContext(in:) ... }`.
+/// The scanner emits `MethodKey(typeName: "ExtensionContextDescriptorProtocol",
+/// memberName: "extendedContext")`. The Suite/baseline for that method must be
+/// `ExtensionContextDescriptorProtocolBaseline` / `ExtensionContextDescriptorProtocolTests`,
+/// regardless of which file the extension is declared in.
+///
+/// When adding a new sub-generator/Suite, look at the actual `extension` declarations,
+/// not just the file structure under `Models//`.
+package enum BaselineGenerator {
+ /// Regenerates every baseline file in deterministic order. Idempotent —
+ /// calling twice in a row leaves `__Baseline__/` byte-identical.
+ package static func generateAll(outputDirectory: URL) async throws {
+ try FileManager.default.createDirectory(at: outputDirectory, withIntermediateDirectories: true)
+ let machOFile = try loadFixtureMachOFile()
+ // Anonymous/
+ try dispatchSuite("AnonymousContext", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("AnonymousContextDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("AnonymousContextDescriptorFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("AnonymousContextDescriptorProtocol", in: machOFile, outputDirectory: outputDirectory)
+ // ContextDescriptor/
+ try dispatchSuite("ContextDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ContextDescriptorFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ContextDescriptorKind", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ContextDescriptorKindSpecificFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ContextDescriptorProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ContextDescriptorWrapper", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ContextProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ContextWrapper", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("NamedContextDescriptorProtocol", in: machOFile, outputDirectory: outputDirectory)
+ // Extension/
+ try dispatchSuite("ExtensionContext", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ExtensionContextDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ExtensionContextDescriptorProtocol", in: machOFile, outputDirectory: outputDirectory)
+ // Module/
+ try dispatchSuite("ModuleContext", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ModuleContextDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ // Type/Struct/
+ try dispatchSuite("StructDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("Struct", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("StructMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("StructMetadataProtocol", in: machOFile, outputDirectory: outputDirectory)
+ // Type/Class/ — sub-generators live in Generators/Class/.
+ // The Class group is large (~22 files) so the source files are
+ // grouped under Generators/Class/ for readability; flat naming is
+ // retained for the smaller groups (Tasks 4-6).
+ try dispatchSuite("AnyClassMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("AnyClassMetadataObjCInterop", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("AnyClassMetadataObjCInteropProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("AnyClassMetadataProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("Class", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ClassDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ClassFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ClassMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ClassMetadataBounds", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ClassMetadataBoundsProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ClassMetadataObjCInterop", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ExtraClassDescriptorFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("FinalClassMetadataProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MethodDefaultOverrideDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MethodDefaultOverrideTableHeader", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MethodDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MethodDescriptorFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MethodDescriptorKind", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MethodOverrideDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ObjCClassWrapperMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ObjCResilientClassStubInfo", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("OverrideTableHeader", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ResilientSuperclass", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("StoredClassMetadataBounds", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("VTableDescriptorHeader", in: machOFile, outputDirectory: outputDirectory)
+ // Type/Enum/ — sub-generators live in Generators/Enum/, mirroring
+ // the Type/Class/ layout convention from Task 7.
+ try dispatchSuite("Enum", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("EnumDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("EnumFunctions", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("EnumMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("EnumMetadataProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MultiPayloadEnumDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ // Type/ root — sub-generators live in Generators/Type/, mirroring
+ // the Type/Class/ and Type/Enum/ layout conventions from Tasks 7-8.
+ try dispatchSuite("TypeContextDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TypeContextDescriptorFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TypeContextDescriptorProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TypeContextDescriptorWrapper", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TypeContextWrapper", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TypeMetadataRecord", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TypeReference", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ValueMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ValueMetadataProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ValueTypeDescriptorWrapper", in: machOFile, outputDirectory: outputDirectory)
+ // Protocol/ — sub-generators live in Generators/Protocol/, with
+ // Invertible/ and ObjC/ subdirectories mirroring the source layout.
+ try dispatchSuite("InvertibleProtocolSet", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("InvertibleProtocolsRequirementCount", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ObjCProtocolPrefix", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("Protocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolBaseRequirement", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolContextDescriptorFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolDescriptorFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolDescriptorRef", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolRecord", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolRequirement", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolRequirementFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolRequirementKind", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolWitnessTable", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("RelativeObjCProtocolPrefix", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ResilientWitness", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ResilientWitnessesHeader", in: machOFile, outputDirectory: outputDirectory)
+ // ProtocolConformance/ — sub-generators live in
+ // Generators/ProtocolConformance/, mirroring the Type/Class/,
+ // Type/Enum/, Type/, and Protocol/ layout conventions from
+ // Tasks 7-10.
+ try dispatchSuite("GlobalActorReference", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolConformance", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolConformanceDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ProtocolConformanceFlags", in: machOFile, outputDirectory: outputDirectory)
+ // Generic/ — sub-generators live in Generators/Generic/, mirroring
+ // the Type/Class/, Type/Enum/, Type/, Protocol/, and
+ // ProtocolConformance/ layout conventions from Tasks 7-11.
+ try dispatchSuite("GenericContext", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericContextDescriptorFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericContextDescriptorHeader", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericEnvironment", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericEnvironmentFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericPackShapeDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericPackShapeHeader", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericParamDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericRequirement", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericRequirementContent", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericRequirementDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericRequirementFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericValueDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericValueHeader", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("GenericWitnessTable", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TypeGenericContextDescriptorHeader", in: machOFile, outputDirectory: outputDirectory)
+ // FieldDescriptor/ — sub-generators live in Generators/FieldDescriptor/.
+ // FieldDescriptorKind is a pure enum (only `case` declarations, no
+ // public func/var/init), so PublicMemberScanner emits no MethodKey
+ // entries for it — no Suite/baseline is needed.
+ try dispatchSuite("FieldDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ // FieldRecord/ — sub-generators live in Generators/FieldRecord/.
+ try dispatchSuite("FieldRecord", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("FieldRecordFlags", in: machOFile, outputDirectory: outputDirectory)
+ // AssociatedType/ — sub-generators live in Generators/AssociatedType/.
+ try dispatchSuite("AssociatedType", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("AssociatedTypeDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("AssociatedTypeRecord", in: machOFile, outputDirectory: outputDirectory)
+ // Metadata/ — sub-generators live in Generators/Metadata/, with
+ // Headers/ and MetadataInitialization/ subdirectories mirroring
+ // the source layout. Most metadata types are runtime-only or
+ // require a MachOImage accessor invocation; baselines emit only
+ // registered names where live data isn't reachable from the
+ // static section walks. Pure enums (`MetadataKind`, `MetadataState`)
+ // and marker protocols (`HeapMetadataProtocol`,
+ // `HeapMetadataHeaderProtocol`, `HeapMetadataHeaderPrefixProtocol`,
+ // `TypeMetadataHeaderProtocol`, `TypeMetadataHeaderBaseProtocol`,
+ // `TypeMetadataLayoutPrefixProtocol`) carry no public extension
+ // members so PublicMemberScanner emits no MethodKey entries —
+ // no Suite/baseline is needed.
+ try dispatchSuite("CanonicalSpecializedMetadataAccessorsListEntry", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("CanonicalSpecializedMetadatasCachingOnceToken", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("CanonicalSpecializedMetadatasListCount", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("CanonicalSpecializedMetadatasListEntry", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("FixedArrayTypeMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("FullMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("Metadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MetadataAccessorFunction", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MetadataBounds", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MetadataBoundsProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MetadataProtocol", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MetadataRequest", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MetadataResponse", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MetadataWrapper", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("MetatypeMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("SingletonMetadataPointer", in: machOFile, outputDirectory: outputDirectory)
+ // Metadata/Headers/
+ try dispatchSuite("HeapMetadataHeader", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("HeapMetadataHeaderPrefix", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TypeMetadataHeader", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TypeMetadataHeaderBase", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TypeMetadataLayoutPrefix", in: machOFile, outputDirectory: outputDirectory)
+ // Metadata/MetadataInitialization/
+ try dispatchSuite("ForeignMetadataInitialization", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("SingletonMetadataInitialization", in: machOFile, outputDirectory: outputDirectory)
+ // BuiltinType/
+ try dispatchSuite("BuiltinType", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("BuiltinTypeDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ // DispatchClass/
+ try dispatchSuite("DispatchClassMetadata", in: machOFile, outputDirectory: outputDirectory)
+ // ExistentialType/
+ try dispatchSuite("ExistentialMetatypeMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ExistentialTypeFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ExistentialTypeMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ExtendedExistentialTypeMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ExtendedExistentialTypeShape", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ExtendedExistentialTypeShapeFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("NonUniqueExtendedExistentialTypeShape", in: machOFile, outputDirectory: outputDirectory)
+ // ForeignType/ — registration-only; SymbolTestsCore declares no
+ // CF/ObjC foreign-class bridges or foreign-reference-type imports.
+ try dispatchSuite("ForeignClassMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ForeignReferenceTypeMetadata", in: machOFile, outputDirectory: outputDirectory)
+ // Function/ — FunctionTypeMetadata is runtime-allocated only.
+ try dispatchSuite("FunctionTypeFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("FunctionTypeMetadata", in: machOFile, outputDirectory: outputDirectory)
+ // Heap/ — both metadata types are runtime-allocated only.
+ try dispatchSuite("GenericBoxHeapMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("HeapLocalVariableMetadata", in: machOFile, outputDirectory: outputDirectory)
+ // Mangling/ — MangledNameKind is a pure enum (no public func/var/init),
+ // so only MangledName needs a Suite.
+ try dispatchSuite("MangledName", in: machOFile, outputDirectory: outputDirectory)
+ // OpaqueType/ — OpaqueMetadata is runtime-allocated only.
+ try dispatchSuite("OpaqueMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("OpaqueType", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("OpaqueTypeDescriptor", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("OpaqueTypeDescriptorProtocol", in: machOFile, outputDirectory: outputDirectory)
+ // TupleType/ — TupleTypeMetadata is runtime-allocated only;
+ // TupleTypeMetadata.Element gets its own Suite (testedTypeName ==
+ // "Element") because PublicMemberScanner keys nested types by
+ // their inner struct name.
+ try dispatchSuite("TupleTypeMetadata", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("TupleTypeMetadataElement", in: machOFile, outputDirectory: outputDirectory)
+ // ValueWitnessTable/
+ try dispatchSuite("TypeLayout", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ValueWitnessFlags", in: machOFile, outputDirectory: outputDirectory)
+ try dispatchSuite("ValueWitnessTable", in: machOFile, outputDirectory: outputDirectory)
+ // Capture/ and Misc/ are skipped:
+ // - Capture/Capture.swift / CaptureDescriptor.swift declare no
+ // public surface (both are essentially placeholder files).
+ // - Misc/SpecialPointerAuthDiscriminators.swift uses package-
+ // scoped declarations only, so PublicMemberScanner emits no
+ // entries for it.
+
+ // Index of every Suite type registered above. Consumed by
+ // MachOSwiftSectionCoverageInvariantTests (Task 16) to enumerate
+ // `[any FixtureSuite.Type]` for the static-vs-runtime guard.
+ try writeAllFixtureSuitesIndex(outputDirectory: outputDirectory)
+ }
+
+ /// Regenerates a single Suite's baseline file. Used by the polished
+ /// `--suite` CLI flag (Task 17).
+ package static func generate(suite name: String, outputDirectory: URL) async throws {
+ try FileManager.default.createDirectory(at: outputDirectory, withIntermediateDirectories: true)
+ let machOFile = try loadFixtureMachOFile()
+ try dispatchSuite(name, in: machOFile, outputDirectory: outputDirectory)
+ }
+
+ private static func dispatchSuite(_ name: String, in machOFile: MachOFile, outputDirectory: URL) throws {
+ switch name {
+ // Anonymous/
+ case "AnonymousContext":
+ try AnonymousContextBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "AnonymousContextDescriptor":
+ try AnonymousContextDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "AnonymousContextDescriptorFlags":
+ try AnonymousContextDescriptorFlagsBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "AnonymousContextDescriptorProtocol":
+ try AnonymousContextDescriptorProtocolBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // ContextDescriptor/
+ case "ContextDescriptor":
+ try ContextDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ContextDescriptorFlags":
+ try ContextDescriptorFlagsBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ContextDescriptorKind":
+ try ContextDescriptorKindBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ContextDescriptorKindSpecificFlags":
+ try ContextDescriptorKindSpecificFlagsBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ContextDescriptorProtocol":
+ try ContextDescriptorProtocolBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ContextDescriptorWrapper":
+ try ContextDescriptorWrapperBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ContextProtocol":
+ try ContextProtocolBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ContextWrapper":
+ try ContextWrapperBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "NamedContextDescriptorProtocol":
+ try NamedContextDescriptorProtocolBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // Extension/
+ case "ExtensionContext":
+ try ExtensionContextBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ExtensionContextDescriptor":
+ try ExtensionContextDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ExtensionContextDescriptorProtocol":
+ try ExtensionContextDescriptorProtocolBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // Module/
+ case "ModuleContext":
+ try ModuleContextBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ModuleContextDescriptor":
+ try ModuleContextDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // Type/Struct/
+ case "StructDescriptor":
+ try StructDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "Struct":
+ try StructBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "StructMetadata":
+ try StructMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "StructMetadataProtocol":
+ try StructMetadataProtocolBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // Type/Class/
+ case "AnyClassMetadata":
+ try AnyClassMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "AnyClassMetadataObjCInterop":
+ try AnyClassMetadataObjCInteropBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "AnyClassMetadataObjCInteropProtocol":
+ try AnyClassMetadataObjCInteropProtocolBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "AnyClassMetadataProtocol":
+ try AnyClassMetadataProtocolBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "Class":
+ try ClassBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ClassDescriptor":
+ try ClassDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ClassFlags":
+ try ClassFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ClassMetadata":
+ try ClassMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ClassMetadataBounds":
+ try ClassMetadataBoundsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ClassMetadataBoundsProtocol":
+ try ClassMetadataBoundsProtocolBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ClassMetadataObjCInterop":
+ try ClassMetadataObjCInteropBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ExtraClassDescriptorFlags":
+ try ExtraClassDescriptorFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "FinalClassMetadataProtocol":
+ try FinalClassMetadataProtocolBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MethodDefaultOverrideDescriptor":
+ try MethodDefaultOverrideDescriptorBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MethodDefaultOverrideTableHeader":
+ try MethodDefaultOverrideTableHeaderBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MethodDescriptor":
+ try MethodDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "MethodDescriptorFlags":
+ try MethodDescriptorFlagsBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "MethodDescriptorKind":
+ try MethodDescriptorKindBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MethodOverrideDescriptor":
+ try MethodOverrideDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ObjCClassWrapperMetadata":
+ try ObjCClassWrapperMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ObjCResilientClassStubInfo":
+ try ObjCResilientClassStubInfoBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "OverrideTableHeader":
+ try OverrideTableHeaderBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ResilientSuperclass":
+ try ResilientSuperclassBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "StoredClassMetadataBounds":
+ try StoredClassMetadataBoundsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "VTableDescriptorHeader":
+ try VTableDescriptorHeaderBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // Type/Enum/
+ case "Enum":
+ try EnumBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "EnumDescriptor":
+ try EnumDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "EnumFunctions":
+ try EnumFunctionsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "EnumMetadata":
+ try EnumMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "EnumMetadataProtocol":
+ try EnumMetadataProtocolBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MultiPayloadEnumDescriptor":
+ try MultiPayloadEnumDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // Type/ root
+ case "TypeContextDescriptor":
+ try TypeContextDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "TypeContextDescriptorFlags":
+ try TypeContextDescriptorFlagsBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "TypeContextDescriptorProtocol":
+ try TypeContextDescriptorProtocolBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "TypeContextDescriptorWrapper":
+ try TypeContextDescriptorWrapperBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "TypeContextWrapper":
+ try TypeContextWrapperBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "TypeMetadataRecord":
+ try TypeMetadataRecordBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "TypeReference":
+ try TypeReferenceBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ValueMetadata":
+ try ValueMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ValueMetadataProtocol":
+ try ValueMetadataProtocolBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ValueTypeDescriptorWrapper":
+ try ValueTypeDescriptorWrapperBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // Protocol/
+ case "InvertibleProtocolSet":
+ try InvertibleProtocolSetBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "InvertibleProtocolsRequirementCount":
+ try InvertibleProtocolsRequirementCountBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ObjCProtocolPrefix":
+ try ObjCProtocolPrefixBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "Protocol":
+ try ProtocolBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolBaseRequirement":
+ try ProtocolBaseRequirementBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolContextDescriptorFlags":
+ try ProtocolContextDescriptorFlagsBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolDescriptor":
+ try ProtocolDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolDescriptorFlags":
+ try ProtocolDescriptorFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ProtocolDescriptorRef":
+ try ProtocolDescriptorRefBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolRecord":
+ try ProtocolRecordBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolRequirement":
+ try ProtocolRequirementBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolRequirementFlags":
+ try ProtocolRequirementFlagsBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolRequirementKind":
+ try ProtocolRequirementKindBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ProtocolWitnessTable":
+ try ProtocolWitnessTableBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "RelativeObjCProtocolPrefix":
+ try RelativeObjCProtocolPrefixBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ResilientWitness":
+ try ResilientWitnessBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ResilientWitnessesHeader":
+ try ResilientWitnessesHeaderBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // ProtocolConformance/
+ case "GlobalActorReference":
+ try GlobalActorReferenceBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolConformance":
+ try ProtocolConformanceBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolConformanceDescriptor":
+ try ProtocolConformanceDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "ProtocolConformanceFlags":
+ try ProtocolConformanceFlagsBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // Generic/
+ case "GenericContext":
+ try GenericContextBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "GenericContextDescriptorFlags":
+ try GenericContextDescriptorFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "GenericContextDescriptorHeader":
+ try GenericContextDescriptorHeaderBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "GenericEnvironment":
+ try GenericEnvironmentBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "GenericEnvironmentFlags":
+ try GenericEnvironmentFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "GenericPackShapeDescriptor":
+ try GenericPackShapeDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "GenericPackShapeHeader":
+ try GenericPackShapeHeaderBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "GenericParamDescriptor":
+ try GenericParamDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "GenericRequirement":
+ try GenericRequirementBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "GenericRequirementContent":
+ try GenericRequirementContentBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "GenericRequirementDescriptor":
+ try GenericRequirementDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "GenericRequirementFlags":
+ try GenericRequirementFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "GenericValueDescriptor":
+ try GenericValueDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "GenericValueHeader":
+ try GenericValueHeaderBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "GenericWitnessTable":
+ try GenericWitnessTableBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "TypeGenericContextDescriptorHeader":
+ try TypeGenericContextDescriptorHeaderBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // FieldDescriptor/
+ case "FieldDescriptor":
+ try FieldDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // FieldRecord/
+ case "FieldRecord":
+ try FieldRecordBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "FieldRecordFlags":
+ try FieldRecordFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // AssociatedType/
+ case "AssociatedType":
+ try AssociatedTypeBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "AssociatedTypeDescriptor":
+ try AssociatedTypeDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "AssociatedTypeRecord":
+ try AssociatedTypeRecordBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // Metadata/
+ case "CanonicalSpecializedMetadataAccessorsListEntry":
+ try CanonicalSpecializedMetadataAccessorsListEntryBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "CanonicalSpecializedMetadatasCachingOnceToken":
+ try CanonicalSpecializedMetadatasCachingOnceTokenBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "CanonicalSpecializedMetadatasListCount":
+ try CanonicalSpecializedMetadatasListCountBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "CanonicalSpecializedMetadatasListEntry":
+ try CanonicalSpecializedMetadatasListEntryBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "FixedArrayTypeMetadata":
+ try FixedArrayTypeMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "FullMetadata":
+ try FullMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "Metadata":
+ try MetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MetadataAccessorFunction":
+ try MetadataAccessorFunctionBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MetadataBounds":
+ try MetadataBoundsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MetadataBoundsProtocol":
+ try MetadataBoundsProtocolBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MetadataProtocol":
+ try MetadataProtocolBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MetadataRequest":
+ try MetadataRequestBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MetadataResponse":
+ try MetadataResponseBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MetadataWrapper":
+ try MetadataWrapperBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "MetatypeMetadata":
+ try MetatypeMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "SingletonMetadataPointer":
+ try SingletonMetadataPointerBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // Metadata/Headers/
+ case "HeapMetadataHeader":
+ try HeapMetadataHeaderBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "HeapMetadataHeaderPrefix":
+ try HeapMetadataHeaderPrefixBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "TypeMetadataHeader":
+ try TypeMetadataHeaderBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "TypeMetadataHeaderBase":
+ try TypeMetadataHeaderBaseBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "TypeMetadataLayoutPrefix":
+ try TypeMetadataLayoutPrefixBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // Metadata/MetadataInitialization/
+ case "ForeignMetadataInitialization":
+ try ForeignMetadataInitializationBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "SingletonMetadataInitialization":
+ try SingletonMetadataInitializationBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // BuiltinType/
+ case "BuiltinType":
+ try BuiltinTypeBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ case "BuiltinTypeDescriptor":
+ try BuiltinTypeDescriptorBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // DispatchClass/
+ case "DispatchClassMetadata":
+ try DispatchClassMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // ExistentialType/
+ case "ExistentialMetatypeMetadata":
+ try ExistentialMetatypeMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ExistentialTypeFlags":
+ try ExistentialTypeFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ExistentialTypeMetadata":
+ try ExistentialTypeMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ExtendedExistentialTypeMetadata":
+ if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
+ try ExtendedExistentialTypeMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ }
+ case "ExtendedExistentialTypeShape":
+ if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
+ try ExtendedExistentialTypeShapeBaselineGenerator.generate(outputDirectory: outputDirectory)
+ }
+ case "ExtendedExistentialTypeShapeFlags":
+ if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
+ try ExtendedExistentialTypeShapeFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ }
+ case "NonUniqueExtendedExistentialTypeShape":
+ try NonUniqueExtendedExistentialTypeShapeBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // ForeignType/
+ case "ForeignClassMetadata":
+ try ForeignClassMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ForeignReferenceTypeMetadata":
+ try ForeignReferenceTypeMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // Function/
+ case "FunctionTypeFlags":
+ try FunctionTypeFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "FunctionTypeMetadata":
+ try FunctionTypeMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // Heap/
+ case "GenericBoxHeapMetadata":
+ try GenericBoxHeapMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "HeapLocalVariableMetadata":
+ try HeapLocalVariableMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // Mangling/
+ case "MangledName":
+ try MangledNameBaselineGenerator.generate(in: machOFile, outputDirectory: outputDirectory)
+ // OpaqueType/
+ case "OpaqueMetadata":
+ try OpaqueMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "OpaqueType":
+ try OpaqueTypeBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "OpaqueTypeDescriptor":
+ try OpaqueTypeDescriptorBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "OpaqueTypeDescriptorProtocol":
+ try OpaqueTypeDescriptorProtocolBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // TupleType/
+ case "TupleTypeMetadata":
+ try TupleTypeMetadataBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "TupleTypeMetadataElement":
+ try TupleTypeMetadataElementBaselineGenerator.generate(outputDirectory: outputDirectory)
+ // ValueWitnessTable/
+ case "TypeLayout":
+ try TypeLayoutBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ValueWitnessFlags":
+ try ValueWitnessFlagsBaselineGenerator.generate(outputDirectory: outputDirectory)
+ case "ValueWitnessTable":
+ try ValueWitnessTableBaselineGenerator.generate(outputDirectory: outputDirectory)
+ default:
+ throw BaselineGeneratorError.unknownSuite(name)
+ }
+ }
+
+ private static func loadFixtureMachOFile() throws -> MachOFile {
+ let file = try loadFromFile(named: .SymbolTestsCore)
+ switch file {
+ case .fat(let fat):
+ return try required(
+ fat.machOFiles().first(where: { $0.header.cpuType == .arm64 })
+ ?? fat.machOFiles().first
+ )
+ case .machO(let machO):
+ return machO
+ @unknown default:
+ fatalError()
+ }
+ }
+
+ /// Hand-maintained index of every Suite type registered in `dispatchSuite`.
+ /// Emits `__Baseline__/AllFixtureSuites.swift`, which the Coverage Invariant
+ /// Test (Task 16) reads as `[any FixtureSuite.Type]`.
+ ///
+ /// When adding a new Suite, append its type name (the class name, NOT the
+ /// `testedTypeName` String) to `suiteTypeNames`. The list is sorted at emit
+ /// time, so order here doesn't matter — keep it stable for code review.
+ ///
+ /// Note: `OpaqueTypeFixtureTests` covers `OpaqueType` (the file is named
+ /// `OpaqueTypeFixtureTests.swift` to avoid collision with the
+ /// `OpaqueTypeTests` SnapshotInterfaceTests Suite that lives in the same
+ /// target). The Coverage Invariant test keys by `testedTypeName`, so the
+ /// class-name suffix is irrelevant for coverage purposes.
+ private static func writeAllFixtureSuitesIndex(outputDirectory: URL) throws {
+ let suiteTypeNames = [
+ "AnonymousContextDescriptorFlagsTests",
+ "AnonymousContextDescriptorProtocolTests",
+ "AnonymousContextDescriptorTests",
+ "AnonymousContextTests",
+ "AnyClassMetadataObjCInteropProtocolTests",
+ "AnyClassMetadataObjCInteropTests",
+ "AnyClassMetadataProtocolTests",
+ "AnyClassMetadataTests",
+ "AssociatedTypeDescriptorTests",
+ "AssociatedTypeRecordTests",
+ "AssociatedTypeTests",
+ "BuiltinTypeDescriptorTests",
+ "BuiltinTypeTests",
+ "CanonicalSpecializedMetadataAccessorsListEntryTests",
+ "CanonicalSpecializedMetadatasCachingOnceTokenTests",
+ "CanonicalSpecializedMetadatasListCountTests",
+ "CanonicalSpecializedMetadatasListEntryTests",
+ "ClassDescriptorTests",
+ "ClassFlagsTests",
+ "ClassMetadataBoundsProtocolTests",
+ "ClassMetadataBoundsTests",
+ "ClassMetadataObjCInteropTests",
+ "ClassMetadataTests",
+ "ClassTests",
+ "ContextDescriptorFlagsTests",
+ "ContextDescriptorKindSpecificFlagsTests",
+ "ContextDescriptorKindTests",
+ "ContextDescriptorProtocolTests",
+ "ContextDescriptorTests",
+ "ContextDescriptorWrapperTests",
+ "ContextProtocolTests",
+ "ContextWrapperTests",
+ "DispatchClassMetadataTests",
+ "EnumDescriptorTests",
+ "EnumFunctionsTests",
+ "EnumMetadataProtocolTests",
+ "EnumMetadataTests",
+ "EnumTests",
+ "ExistentialMetatypeMetadataTests",
+ "ExistentialTypeFlagsTests",
+ "ExistentialTypeMetadataTests",
+ "ExtendedExistentialTypeMetadataTests",
+ "ExtendedExistentialTypeShapeFlagsTests",
+ "ExtendedExistentialTypeShapeTests",
+ "ExtensionContextDescriptorProtocolTests",
+ "ExtensionContextDescriptorTests",
+ "ExtensionContextTests",
+ "ExtraClassDescriptorFlagsTests",
+ "FieldDescriptorTests",
+ "FieldRecordFlagsTests",
+ "FieldRecordTests",
+ "FinalClassMetadataProtocolTests",
+ "FixedArrayTypeMetadataTests",
+ "ForeignClassMetadataTests",
+ "ForeignMetadataInitializationTests",
+ "ForeignReferenceTypeMetadataTests",
+ "FullMetadataTests",
+ "FunctionTypeFlagsTests",
+ "FunctionTypeMetadataTests",
+ "GenericBoxHeapMetadataTests",
+ "GenericContextDescriptorFlagsTests",
+ "GenericContextDescriptorHeaderTests",
+ "GenericContextTests",
+ "GenericEnvironmentFlagsTests",
+ "GenericEnvironmentTests",
+ "GenericPackShapeDescriptorTests",
+ "GenericPackShapeHeaderTests",
+ "GenericParamDescriptorTests",
+ "GenericRequirementContentTests",
+ "GenericRequirementDescriptorTests",
+ "GenericRequirementFlagsTests",
+ "GenericRequirementTests",
+ "GenericValueDescriptorTests",
+ "GenericValueHeaderTests",
+ "GenericWitnessTableTests",
+ "GlobalActorReferenceTests",
+ "HeapLocalVariableMetadataTests",
+ "HeapMetadataHeaderPrefixTests",
+ "HeapMetadataHeaderTests",
+ "InvertibleProtocolSetTests",
+ "InvertibleProtocolsRequirementCountTests",
+ "MangledNameTests",
+ "MetadataAccessorFunctionTests",
+ "MetadataBoundsProtocolTests",
+ "MetadataBoundsTests",
+ "MetadataProtocolTests",
+ "MetadataRequestTests",
+ "MetadataResponseTests",
+ "MetadataTests",
+ "MetadataWrapperTests",
+ "MetatypeMetadataTests",
+ "MethodDefaultOverrideDescriptorTests",
+ "MethodDefaultOverrideTableHeaderTests",
+ "MethodDescriptorFlagsTests",
+ "MethodDescriptorKindTests",
+ "MethodDescriptorTests",
+ "MethodOverrideDescriptorTests",
+ "ModuleContextDescriptorTests",
+ "ModuleContextTests",
+ "MultiPayloadEnumDescriptorTests",
+ "NamedContextDescriptorProtocolTests",
+ "NonUniqueExtendedExistentialTypeShapeTests",
+ "ObjCClassWrapperMetadataTests",
+ "ObjCProtocolPrefixTests",
+ "ObjCResilientClassStubInfoTests",
+ "OpaqueMetadataTests",
+ "OpaqueTypeDescriptorProtocolTests",
+ "OpaqueTypeDescriptorTests",
+ "OpaqueTypeFixtureTests",
+ "OverrideTableHeaderTests",
+ "ProtocolBaseRequirementTests",
+ "ProtocolConformanceDescriptorTests",
+ "ProtocolConformanceFlagsTests",
+ "ProtocolConformanceTests",
+ "ProtocolContextDescriptorFlagsTests",
+ "ProtocolDescriptorFlagsTests",
+ "ProtocolDescriptorRefTests",
+ "ProtocolDescriptorTests",
+ "ProtocolRecordTests",
+ "ProtocolRequirementFlagsTests",
+ "ProtocolRequirementKindTests",
+ "ProtocolRequirementTests",
+ "ProtocolTests",
+ "ProtocolWitnessTableTests",
+ "RelativeObjCProtocolPrefixTests",
+ "ResilientSuperclassTests",
+ "ResilientWitnessTests",
+ "ResilientWitnessesHeaderTests",
+ "SingletonMetadataInitializationTests",
+ "SingletonMetadataPointerTests",
+ "StoredClassMetadataBoundsTests",
+ "StructDescriptorTests",
+ "StructMetadataProtocolTests",
+ "StructMetadataTests",
+ "StructTests",
+ "TupleTypeMetadataElementTests",
+ "TupleTypeMetadataTests",
+ "TypeContextDescriptorFlagsTests",
+ "TypeContextDescriptorProtocolTests",
+ "TypeContextDescriptorTests",
+ "TypeContextDescriptorWrapperTests",
+ "TypeContextWrapperTests",
+ "TypeGenericContextDescriptorHeaderTests",
+ "TypeLayoutTests",
+ "TypeMetadataHeaderBaseTests",
+ "TypeMetadataHeaderTests",
+ "TypeMetadataLayoutPrefixTests",
+ "TypeMetadataRecordTests",
+ "TypeReferenceTests",
+ "VTableDescriptorHeaderTests",
+ "ValueMetadataProtocolTests",
+ "ValueMetadataTests",
+ "ValueTypeDescriptorWrapperTests",
+ "ValueWitnessFlagsTests",
+ "ValueWitnessTableTests",
+ ].sorted()
+
+ // Use `\(raw:)` because `\(literal:)` would treat each `Foo.self` as a
+ // String literal (i.e. emit `"Foo.self"`).
+ let suiteListItems = suiteTypeNames
+ .map { "\($0).self" }
+ .joined(separator: ",\n ") + ","
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ @testable import MachOTestingSupport
+ import MachOFixtureSupport
+
+ // `FixtureSuite` is `@MainActor`-isolated, so its metatype likewise inherits
+ // main-actor isolation. Annotating the constant binds access to MainActor and
+ // avoids the Sendable diagnostic on this global.
+ @MainActor
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+ let allFixtureSuites: [any FixtureSuite.Type] = [
+ \(raw: suiteListItems)
+ ]
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AllFixtureSuites.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
+
+package enum BaselineGeneratorError: Error, CustomStringConvertible {
+ case unknownSuite(String)
+
+ package var description: String {
+ switch self {
+ case .unknownSuite(let name):
+ return "Unknown suite: \(name). Use --help for the list of valid suites."
+ }
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextBaselineGenerator.swift
new file mode 100644
index 00000000..8fd04b68
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextBaselineGenerator.swift
@@ -0,0 +1,79 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/AnonymousContextBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `AnonymousContext` wraps an `AnonymousContextDescriptor` and pulls in the
+/// optional `genericContext` and `mangledName` ivars. We use the
+/// presence-flag pattern (no value embedding) for the optionals because
+/// `MangledName`/`GenericContext` are deep ABI structures that are hostile
+/// to literal embedding; cross-reader equality assertions in the companion
+/// Suite cover correctness at runtime.
+package enum AnonymousContextBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.anonymous_first(in: machO)
+ let context = try AnonymousContext(descriptor: descriptor, in: machO)
+
+ let entryExpr = emitEntryExpr(for: context)
+
+ // Public members declared directly in AnonymousContext.swift.
+ // Both `init(descriptor:in:)` overloads (MachO + ReadingContext)
+ // collapse to one MethodKey under PublicMemberScanner's name-based
+ // deduplication.
+ let registered = [
+ "descriptor",
+ "genericContext",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "mangledName",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AnonymousContextBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let hasGenericContext: Bool
+ let hasMangledName: Bool
+ }
+
+ static let firstAnonymous = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AnonymousContextBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for instance: AnonymousContext) -> String {
+ let descriptorOffset = instance.descriptor.offset
+ let hasGenericContext = instance.genericContext != nil
+ let hasMangledName = instance.mangledName != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ hasGenericContext: \(literal: hasGenericContext),
+ hasMangledName: \(literal: hasMangledName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..8bf06358
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextDescriptorBaselineGenerator.swift
@@ -0,0 +1,62 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/AnonymousContextDescriptorBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `AnonymousContextDescriptor` declares only the `offset` and `layout`
+/// ivars (the `init(layout:offset:)` is filtered as a memberwise
+/// synthesized initializer). The `Layout` is `flags + parent`; the
+/// `flags.rawValue` (a `UInt32`) is a stable scalar we can embed.
+package enum AnonymousContextDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.anonymous_first(in: machO)
+ let entryExpr = emitEntryExpr(for: descriptor)
+
+ let registered = ["layout", "offset"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AnonymousContextDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutFlagsRawValue: UInt32
+ }
+
+ static let firstAnonymous = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AnonymousContextDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for descriptor: AnonymousContextDescriptor) -> String {
+ let offset = descriptor.offset
+ let flagsRaw = descriptor.layout.flags.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextDescriptorFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextDescriptorFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..41d04307
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextDescriptorFlagsBaselineGenerator.swift
@@ -0,0 +1,69 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/AnonymousContextDescriptorFlagsBaseline.swift`.
+///
+/// `AnonymousContextDescriptorFlags` is a small `FlagSet` value type whose
+/// `rawValue` (`UInt16`) lives in the descriptor's `layout.flags`
+/// kind-specific bit-range. We extract it by interrogating the fixture's
+/// first anonymous descriptor and embed the raw value plus the derived
+/// `hasMangledName` boolean.
+package enum AnonymousContextDescriptorFlagsBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.anonymous_first(in: machO)
+ let flags = try required(descriptor.layout.flags.kindSpecificFlags?.anonymousFlags)
+
+ let entryExpr = emitEntryExpr(for: flags)
+
+ // Public members declared directly in AnonymousContextDescriptorFlags.swift.
+ let registered = [
+ "hasMangledName",
+ "init(rawValue:)",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AnonymousContextDescriptorFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt16
+ let hasMangledName: Bool
+ }
+
+ static let firstAnonymous = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AnonymousContextDescriptorFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for flags: AnonymousContextDescriptorFlags) -> String {
+ let rawValue = flags.rawValue
+ let hasMangledName = flags.hasMangledName
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ hasMangledName: \(literal: hasMangledName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextDescriptorProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextDescriptorProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..a0f16b18
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/AnonymousContextDescriptorProtocolBaselineGenerator.swift
@@ -0,0 +1,74 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/AnonymousContextDescriptorProtocolBaseline.swift`.
+///
+/// The protocol's three `mangledName(in:)` overloads (MachO / InProcess /
+/// ReadingContext) plus the `hasMangledName` derived var don't have stable
+/// literal payloads (the `MangledName` parse output is a deep tree). The
+/// companion Suite (AnonymousContextDescriptorProtocolTests) verifies the
+/// methods produce cross-reader-consistent results at runtime against the
+/// presence flag recorded here.
+///
+/// The presence flag is sourced from the same picker as the Flags Suite
+/// (`anonymous_first`), so the two Suites move together — but having the
+/// flag mirrored on this Suite's own baseline keeps the assertions
+/// self-contained.
+package enum AnonymousContextDescriptorProtocolBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.anonymous_first(in: machO)
+ let hasMangledName = descriptor.hasMangledName
+ let entryExpr = emitEntryExpr(hasMangledName: hasMangledName)
+
+ // Public members declared directly in AnonymousContextDescriptorProtocol.swift.
+ // The three `mangledName(in:)` overloads collapse to a single
+ // MethodKey via PublicMemberScanner's name-only key.
+ let registered = [
+ "hasMangledName",
+ "mangledName",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // MangledName payloads aren't embedded as literals; the companion
+ // Suite (AnonymousContextDescriptorProtocolTests) verifies the
+ // methods produce cross-reader-consistent results at runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AnonymousContextDescriptorProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let hasMangledName: Bool
+ }
+
+ static let firstAnonymous = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AnonymousContextDescriptorProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(hasMangledName: Bool) -> String {
+ let expr: ExprSyntax = """
+ Entry(
+ hasMangledName: \(literal: hasMangledName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/AssociatedType/AssociatedTypeBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/AssociatedType/AssociatedTypeBaselineGenerator.swift
new file mode 100644
index 00000000..85a889e4
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/AssociatedType/AssociatedTypeBaselineGenerator.swift
@@ -0,0 +1,97 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/AssociatedTypeBaseline.swift`.
+///
+/// `AssociatedType` is the high-level wrapper around
+/// `AssociatedTypeDescriptor`. Beyond holding the descriptor itself it
+/// pre-resolves `conformingTypeName`, `protocolTypeName`, and the
+/// trailing `[AssociatedTypeRecord]`. The two MachO-based initializers
+/// (`init(descriptor:in:)`) and the InProcess `init(descriptor:)` collapse
+/// to single MethodKey entries under PublicMemberScanner's name-based
+/// deduplication.
+///
+/// Picker: `AssociatedTypeWitnessPatterns.ConcreteWitnessTest` conforming
+/// to `AssociatedTypeWitnessPatterns.AssociatedPatternProtocol`. The
+/// fixture declares five concrete witnesses
+/// (`First = Int`, `Second = [String]`, `Third = Double`, `Fourth = Bool`,
+/// `Fifth = Character`), so the wrapper's records array has five entries.
+package enum AssociatedTypeBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machO)
+ let associatedType = try AssociatedType(descriptor: descriptor, in: machO)
+
+ let entryExpr = emitEntryExpr(for: associatedType)
+
+ // Public members declared directly in AssociatedType.swift.
+ // The two `init(descriptor:in:)` overloads (MachO + ReadingContext)
+ // collapse to one MethodKey under the scanner's name-based
+ // deduplication; `init(descriptor:)` is the InProcess form.
+ let registered = [
+ "conformingTypeName",
+ "descriptor",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "protocolTypeName",
+ "records",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live MangledName payloads aren't embedded as literals; the
+ // companion Suite (AssociatedTypeTests) verifies the methods
+ // produce cross-reader-consistent results at runtime against the
+ // counts / presence flags recorded here.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AssociatedTypeBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let recordsCount: Int
+ let hasConformingTypeName: Bool
+ let hasProtocolTypeName: Bool
+ }
+
+ static let concreteWitnessTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AssociatedTypeBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for associatedType: AssociatedType) -> String {
+ let descriptorOffset = associatedType.descriptor.offset
+ let recordsCount = associatedType.records.count
+ // The pre-resolved MangledNames are non-empty when their elements
+ // array is non-empty (the value type is not optional, but emptiness
+ // signals a missing payload).
+ let hasConformingTypeName = !associatedType.conformingTypeName.elements.isEmpty
+ let hasProtocolTypeName = !associatedType.protocolTypeName.elements.isEmpty
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ recordsCount: \(literal: recordsCount),
+ hasConformingTypeName: \(literal: hasConformingTypeName),
+ hasProtocolTypeName: \(literal: hasProtocolTypeName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/AssociatedType/AssociatedTypeDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/AssociatedType/AssociatedTypeDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..52728796
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/AssociatedType/AssociatedTypeDescriptorBaselineGenerator.swift
@@ -0,0 +1,106 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/AssociatedTypeDescriptorBaseline.swift`.
+///
+/// `AssociatedTypeDescriptor` is the raw `__swift5_assocty` payload
+/// describing a single conforming-type ↔ protocol pair plus the trailing
+/// `[AssociatedTypeRecord]`. Beyond the layout trio (`offset`, `layout`,
+/// `init(layout:offset:)` — synthesized initializer is filtered) and the
+/// `TopLevelDescriptor` conformance (`actualSize`), it carries three
+/// reader methods (`conformingTypeName(in:)`, `protocolTypeName(in:)`,
+/// `associatedTypeRecords(in:)`) plus their in-process and ReadingContext
+/// overloads.
+///
+/// Picker: `AssociatedTypeWitnessPatterns.ConcreteWitnessTest` conforming
+/// to `AssociatedTypeWitnessPatterns.AssociatedPatternProtocol` (five
+/// concrete witnesses).
+package enum AssociatedTypeDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machO)
+ let entryExpr = try emitEntryExpr(for: descriptor, in: machO)
+
+ // Public members declared directly in AssociatedTypeDescriptor.swift
+ // (across the body and three same-file extensions: MachO + InProcess +
+ // ReadingContext, plus the `TopLevelDescriptor` conformance extension).
+ // Overload triples collapse to single MethodKey entries under the
+ // scanner's name-based deduplication. `init(layout:offset:)` is
+ // filtered as memberwise-synthesized.
+ let registered = [
+ "actualSize",
+ "associatedTypeRecords",
+ "conformingTypeName",
+ "layout",
+ "offset",
+ "protocolTypeName",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live MangledName payloads aren't embedded as literals; the
+ // companion Suite (AssociatedTypeDescriptorTests) verifies the
+ // methods produce cross-reader-consistent results at runtime
+ // against the counts / presence flags recorded here.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AssociatedTypeDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumAssociatedTypes: UInt32
+ let layoutAssociatedTypeRecordSize: UInt32
+ let actualSize: Int
+ let recordsCount: Int
+ let hasConformingTypeName: Bool
+ let hasProtocolTypeName: Bool
+ }
+
+ static let concreteWitnessTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AssociatedTypeDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for descriptor: AssociatedTypeDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let offset = descriptor.offset
+ let layoutNumAssociatedTypes = descriptor.layout.numAssociatedTypes
+ let layoutAssociatedTypeRecordSize = descriptor.layout.associatedTypeRecordSize
+ let actualSize = descriptor.actualSize
+ let records = try descriptor.associatedTypeRecords(in: machO)
+ let recordsCount = records.count
+ let hasConformingTypeName = (try? descriptor.conformingTypeName(in: machO)) != nil
+ let hasProtocolTypeName = (try? descriptor.protocolTypeName(in: machO)) != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumAssociatedTypes: \(literal: layoutNumAssociatedTypes),
+ layoutAssociatedTypeRecordSize: \(literal: layoutAssociatedTypeRecordSize),
+ actualSize: \(literal: actualSize),
+ recordsCount: \(literal: recordsCount),
+ hasConformingTypeName: \(literal: hasConformingTypeName),
+ hasProtocolTypeName: \(literal: hasProtocolTypeName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/AssociatedType/AssociatedTypeRecordBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/AssociatedType/AssociatedTypeRecordBaselineGenerator.swift
new file mode 100644
index 00000000..5be1841e
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/AssociatedType/AssociatedTypeRecordBaselineGenerator.swift
@@ -0,0 +1,92 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/AssociatedTypeRecordBaseline.swift`.
+///
+/// `AssociatedTypeRecord` describes a single associated-type witness — its
+/// `RelativeDirectPointer` to the requirement name and its
+/// `RelativeDirectPointer` to the substituted type. Beyond
+/// the layout trio (`offset`, `layout`, `init(layout:offset:)` —
+/// synthesized initializer is filtered) it carries two reader methods
+/// (`name(in:)` and `substitutedTypeName(in:)`) plus their in-process
+/// and ReadingContext overloads.
+///
+/// Picker: the first record from the
+/// `AssociatedTypeWitnessPatterns.ConcreteWitnessTest` ↔
+/// `AssociatedPatternProtocol` descriptor (witnessing `First = Int`).
+package enum AssociatedTypeRecordBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machO)
+ let records = try descriptor.associatedTypeRecords(in: machO)
+ let firstRecord = try required(records.first)
+
+ let entryExpr = try emitEntryExpr(for: firstRecord, in: machO)
+
+ // Public members declared directly in AssociatedTypeRecord.swift
+ // (across the body and three same-file extensions: MachO + InProcess +
+ // ReadingContext). Overload triples collapse to single MethodKey
+ // entries under the scanner's name-based deduplication.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "name",
+ "offset",
+ "substitutedTypeName",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live MangledName payloads aren't embedded as literals; the
+ // companion Suite (AssociatedTypeRecordTests) verifies the methods
+ // produce cross-reader-consistent results at runtime against the
+ // name string / presence flags recorded here.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AssociatedTypeRecordBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let name: String
+ let hasSubstitutedTypeName: Bool
+ }
+
+ static let firstRecord = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AssociatedTypeRecordBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for record: AssociatedTypeRecord,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let offset = record.offset
+ let name = try record.name(in: machO)
+ let hasSubstitutedTypeName = (try? record.substitutedTypeName(in: machO)) != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ name: \(literal: name),
+ hasSubstitutedTypeName: \(literal: hasSubstitutedTypeName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/BuiltinType/BuiltinTypeBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/BuiltinType/BuiltinTypeBaselineGenerator.swift
new file mode 100644
index 00000000..04cfa7b5
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/BuiltinType/BuiltinTypeBaselineGenerator.swift
@@ -0,0 +1,76 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/BuiltinTypeBaseline.swift`.
+///
+/// `BuiltinType` is the high-level wrapper around `BuiltinTypeDescriptor`.
+/// It pre-resolves `typeName` from the descriptor at construction. The
+/// Suite picks the first descriptor in the `__swift5_builtin` section
+/// (matching `BuiltinTypeDescriptorBaseline`'s carrier) and wraps it.
+package enum BuiltinTypeBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.builtinTypeDescriptor_first(in: machO)
+ let builtin = try BuiltinType(descriptor: descriptor, in: machO)
+ let entryExpr = emitEntryExpr(for: builtin)
+
+ // Public members declared in BuiltinType.swift. The two MachO
+ // initializers (`init(descriptor:in:)`) and the InProcess form
+ // (`init(descriptor:)`) collapse into two MethodKey entries
+ // under the scanner.
+ let registered = [
+ "descriptor",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "typeName",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // BuiltinType wraps the first BuiltinTypeDescriptor of
+ // SymbolTestsCore. Live MangledName payload isn't embedded as a
+ // literal; the Suite verifies presence via the
+ // `hasMangledName` flag and equality of the descriptor offset.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum BuiltinTypeBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let hasTypeName: Bool
+ }
+
+ static let firstBuiltin = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("BuiltinTypeBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for builtin: BuiltinType) -> String {
+ let descriptorOffset = builtin.descriptor.offset
+ let hasTypeName = builtin.typeName != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ hasTypeName: \(literal: hasTypeName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/BuiltinType/BuiltinTypeDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/BuiltinType/BuiltinTypeDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..c9aa15ee
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/BuiltinType/BuiltinTypeDescriptorBaselineGenerator.swift
@@ -0,0 +1,102 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/BuiltinTypeDescriptorBaseline.swift`.
+///
+/// `BuiltinTypeDescriptor` is a 5-field record stored in the
+/// `__swift5_builtin` section. The fixture's `BuiltinTypeFields`
+/// declarations cause the compiler to emit one descriptor per
+/// primitive backing type used in stored fields (Int / Float /
+/// Double / Bool / Character / String etc.). The Suite picks the
+/// first descriptor for a stable carrier and asserts cross-reader
+/// equality of the layout fields.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum BuiltinTypeDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.builtinTypeDescriptor_first(in: machO)
+ let entryExpr = try emitEntryExpr(for: descriptor, in: machO)
+
+ // Public members declared in BuiltinTypeDescriptor.swift. The two
+ // `typeName` overloads (MachO + ReadingContext) collapse to one
+ // MethodKey under the scanner's name-only key.
+ let registered = [
+ "alignment",
+ "hasMangledName",
+ "isBitwiseTakable",
+ "layout",
+ "offset",
+ "typeName",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // BuiltinTypeDescriptor is the first record in the
+ // __swift5_builtin section of SymbolTestsCore. The Suite asserts
+ // cross-reader equality of the size/alignment/stride/extra-
+ // inhabitants layout fields and the typeName resolution.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum BuiltinTypeDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let size: UInt32
+ let alignmentAndFlags: UInt32
+ let stride: UInt32
+ let numExtraInhabitants: UInt32
+ let alignment: Int
+ let isBitwiseTakable: Bool
+ let hasMangledName: Bool
+ }
+
+ static let firstBuiltin = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("BuiltinTypeDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for descriptor: BuiltinTypeDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let descriptorOffset = descriptor.offset
+ let size = descriptor.layout.size
+ let alignmentAndFlags = descriptor.layout.alignmentAndFlags
+ let stride = descriptor.layout.stride
+ let numExtraInhabitants = descriptor.layout.numExtraInhabitants
+ let alignment = descriptor.alignment
+ let isBitwiseTakable = descriptor.isBitwiseTakable
+ let hasMangledName = descriptor.hasMangledName
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ size: \(raw: BaselineEmitter.hex(size)),
+ alignmentAndFlags: \(raw: BaselineEmitter.hex(alignmentAndFlags)),
+ stride: \(raw: BaselineEmitter.hex(stride)),
+ numExtraInhabitants: \(raw: BaselineEmitter.hex(numExtraInhabitants)),
+ alignment: \(raw: BaselineEmitter.hex(alignment)),
+ isBitwiseTakable: \(literal: isBitwiseTakable),
+ hasMangledName: \(literal: hasMangledName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..144886b3
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataBaselineGenerator.swift
@@ -0,0 +1,44 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/AnyClassMetadataBaseline.swift`.
+///
+/// Like the Struct counterparts, the class metadata types must be
+/// materialised at runtime via the MachOImage metadata accessor; live
+/// pointer values are not stable across runs and aren't embedded as
+/// literals. The Suite (`AnyClassMetadataTests`) exercises cross-reader
+/// consistency at runtime against this name-only baseline.
+package enum AnyClassMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in AnyClassMetadata.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // AnyClassMetadata can only be obtained by chasing superclass
+ // pointers from a loaded ClassMetadata. The Suite verifies the
+ // structural fields agree across readers; live pointer values are
+ // not embedded.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AnyClassMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AnyClassMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataObjCInteropBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataObjCInteropBaselineGenerator.swift
new file mode 100644
index 00000000..4e7aa33c
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataObjCInteropBaselineGenerator.swift
@@ -0,0 +1,41 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/AnyClassMetadataObjCInteropBaseline.swift`.
+///
+/// `AnyClassMetadataObjCInterop` is the parallel structure to
+/// `AnyClassMetadata` for ObjC-interop classes (carrying the cache /
+/// vtable / data words). Live materialisation requires a loaded
+/// MachOImage; this baseline records only the registered member names.
+package enum AnyClassMetadataObjCInteropBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in AnyClassMetadataObjCInterop.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // AnyClassMetadataObjCInterop must be materialised from a loaded
+ // MachOImage; live values are not embedded.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AnyClassMetadataObjCInteropBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AnyClassMetadataObjCInteropBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataObjCInteropProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataObjCInteropProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..c23cbf33
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataObjCInteropProtocolBaselineGenerator.swift
@@ -0,0 +1,46 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/AnyClassMetadataObjCInteropProtocolBaseline.swift`.
+///
+/// The protocol's accessors (`asFinalClassMetadata`, `superclass`,
+/// `isPureObjC`, `isTypeMetadata`) require a live class metadata
+/// instance reachable only from a loaded MachOImage. The baseline
+/// records only the registered member names; the Suite asserts
+/// cross-reader agreement at runtime.
+package enum AnyClassMetadataObjCInteropProtocolBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly across the
+ // AnyClassMetadataObjCInteropProtocol extension blocks. Overload
+ // pairs collapse via PublicMemberScanner's name-based key.
+ let registered = [
+ "asFinalClassMetadata",
+ "isPureObjC",
+ "isTypeMetadata",
+ "superclass",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live AnyClassMetadataObjCInterop cannot be embedded as a literal;
+ // the Suite verifies the methods produce cross-reader-consistent
+ // results at runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AnyClassMetadataObjCInteropProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AnyClassMetadataObjCInteropProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..2790b391
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/AnyClassMetadataProtocolBaselineGenerator.swift
@@ -0,0 +1,43 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/AnyClassMetadataProtocolBaseline.swift`.
+///
+/// The protocol's `asFinalClassMetadata(...)` overloads (MachO + InProcess
+/// + ReadingContext) require a live class metadata instance reachable
+/// only from a loaded MachOImage. This baseline records only the
+/// registered member names; the Suite asserts cross-reader agreement at
+/// runtime.
+package enum AnyClassMetadataProtocolBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in AnyClassMetadataProtocol.swift.
+ // The three `asFinalClassMetadata(...)` overloads collapse to a
+ // single MethodKey under PublicMemberScanner.
+ let registered = [
+ "asFinalClassMetadata",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live AnyClassMetadata cannot be embedded as a literal; the
+ // companion Suite (AnyClassMetadataProtocolTests) verifies the
+ // method produces cross-reader-consistent results at runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum AnyClassMetadataProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("AnyClassMetadataProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassBaselineGenerator.swift
new file mode 100644
index 00000000..0388759c
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassBaselineGenerator.swift
@@ -0,0 +1,148 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ClassBaseline.swift` from the `SymbolTestsCore`
+/// fixture via the MachOFile reader.
+///
+/// `Class` is the high-level wrapper around `ClassDescriptor`. It carries
+/// many `Optional` ivars and array-shaped trailing tables (vtable / override
+/// table / canonical specialized metadatas / etc.). We use the
+/// **presence-flag** pattern (no value embedding) for the optionals because
+/// the underlying types (`TypeGenericContext`, `MethodDescriptor`, etc.)
+/// are not cheaply Equatable; presence + cardinality catches the structural
+/// invariant we care about.
+///
+/// The `classTest` picker exercises a plain Swift class with a vtable and
+/// no resilient superclass; `subclassTest` exercises an override table.
+package enum ClassBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let classTestDescriptor = try BaselineFixturePicker.class_ClassTest(in: machO)
+ let subclassTestDescriptor = try BaselineFixturePicker.class_SubclassTest(in: machO)
+
+ let classTestClass = try Class(descriptor: classTestDescriptor, in: machO)
+ let subclassTestClass = try Class(descriptor: subclassTestDescriptor, in: machO)
+
+ let classTestExpr = emitEntryExpr(for: classTestClass)
+ let subclassTestExpr = emitEntryExpr(for: subclassTestClass)
+
+ // Public ivars + initializers declared directly in Class.swift.
+ // Two `init(descriptor:in:)` overloads (MachO + Context) collapse to
+ // a single MethodKey under PublicMemberScanner's name-based key.
+ let registered = [
+ "canonicalSpecializedMetadataAccessors",
+ "canonicalSpecializedMetadatas",
+ "canonicalSpecializedMetadatasCachingOnceToken",
+ "canonicalSpecializedMetadatasListCount",
+ "descriptor",
+ "foreignMetadataInitialization",
+ "genericContext",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "invertibleProtocolSet",
+ "methodDefaultOverrideDescriptors",
+ "methodDefaultOverrideTableHeader",
+ "methodDescriptors",
+ "methodOverrideDescriptors",
+ "objcResilientClassStubInfo",
+ "overrideTableHeader",
+ "resilientSuperclass",
+ "singletonMetadataInitialization",
+ "singletonMetadataPointer",
+ "vTableDescriptorHeader",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ClassBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let hasGenericContext: Bool
+ let hasResilientSuperclass: Bool
+ let hasForeignMetadataInitialization: Bool
+ let hasSingletonMetadataInitialization: Bool
+ let hasVTableDescriptorHeader: Bool
+ let methodDescriptorsCount: Int
+ let hasOverrideTableHeader: Bool
+ let methodOverrideDescriptorsCount: Int
+ let hasObjCResilientClassStubInfo: Bool
+ let hasCanonicalSpecializedMetadatasListCount: Bool
+ let canonicalSpecializedMetadatasCount: Int
+ let canonicalSpecializedMetadataAccessorsCount: Int
+ let hasCanonicalSpecializedMetadatasCachingOnceToken: Bool
+ let hasInvertibleProtocolSet: Bool
+ let hasSingletonMetadataPointer: Bool
+ let hasMethodDefaultOverrideTableHeader: Bool
+ let methodDefaultOverrideDescriptorsCount: Int
+ }
+
+ static let classTest = \(raw: classTestExpr)
+
+ static let subclassTest = \(raw: subclassTestExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ClassBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for instance: Class) -> String {
+ let descriptorOffset = instance.descriptor.offset
+ let hasGenericContext = instance.genericContext != nil
+ let hasResilientSuperclass = instance.resilientSuperclass != nil
+ let hasForeignMetadataInitialization = instance.foreignMetadataInitialization != nil
+ let hasSingletonMetadataInitialization = instance.singletonMetadataInitialization != nil
+ let hasVTableDescriptorHeader = instance.vTableDescriptorHeader != nil
+ let methodDescriptorsCount = instance.methodDescriptors.count
+ let hasOverrideTableHeader = instance.overrideTableHeader != nil
+ let methodOverrideDescriptorsCount = instance.methodOverrideDescriptors.count
+ let hasObjCResilientClassStubInfo = instance.objcResilientClassStubInfo != nil
+ let hasCanonicalSpecializedMetadatasListCount = instance.canonicalSpecializedMetadatasListCount != nil
+ let canonicalSpecializedMetadatasCount = instance.canonicalSpecializedMetadatas.count
+ let canonicalSpecializedMetadataAccessorsCount = instance.canonicalSpecializedMetadataAccessors.count
+ let hasCanonicalSpecializedMetadatasCachingOnceToken = instance.canonicalSpecializedMetadatasCachingOnceToken != nil
+ let hasInvertibleProtocolSet = instance.invertibleProtocolSet != nil
+ let hasSingletonMetadataPointer = instance.singletonMetadataPointer != nil
+ let hasMethodDefaultOverrideTableHeader = instance.methodDefaultOverrideTableHeader != nil
+ let methodDefaultOverrideDescriptorsCount = instance.methodDefaultOverrideDescriptors.count
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ hasGenericContext: \(literal: hasGenericContext),
+ hasResilientSuperclass: \(literal: hasResilientSuperclass),
+ hasForeignMetadataInitialization: \(literal: hasForeignMetadataInitialization),
+ hasSingletonMetadataInitialization: \(literal: hasSingletonMetadataInitialization),
+ hasVTableDescriptorHeader: \(literal: hasVTableDescriptorHeader),
+ methodDescriptorsCount: \(literal: methodDescriptorsCount),
+ hasOverrideTableHeader: \(literal: hasOverrideTableHeader),
+ methodOverrideDescriptorsCount: \(literal: methodOverrideDescriptorsCount),
+ hasObjCResilientClassStubInfo: \(literal: hasObjCResilientClassStubInfo),
+ hasCanonicalSpecializedMetadatasListCount: \(literal: hasCanonicalSpecializedMetadatasListCount),
+ canonicalSpecializedMetadatasCount: \(literal: canonicalSpecializedMetadatasCount),
+ canonicalSpecializedMetadataAccessorsCount: \(literal: canonicalSpecializedMetadataAccessorsCount),
+ hasCanonicalSpecializedMetadatasCachingOnceToken: \(literal: hasCanonicalSpecializedMetadatasCachingOnceToken),
+ hasInvertibleProtocolSet: \(literal: hasInvertibleProtocolSet),
+ hasSingletonMetadataPointer: \(literal: hasSingletonMetadataPointer),
+ hasMethodDefaultOverrideTableHeader: \(literal: hasMethodDefaultOverrideTableHeader),
+ methodDefaultOverrideDescriptorsCount: \(literal: methodDefaultOverrideDescriptorsCount)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..9952f915
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassDescriptorBaselineGenerator.swift
@@ -0,0 +1,142 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ClassDescriptorBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `ClassDescriptor` is the largest descriptor type in the Type/Class group:
+/// it carries the layout scalar fields plus a long set of derived `var`s
+/// (kind-specific flag accessors) and methods (`resilientMetadataBounds`,
+/// `superclassTypeMangledName`). Members declared elsewhere — `name(in:)`,
+/// `fields(in:)` etc. — live on `TypeContextDescriptorProtocol` and are
+/// covered by Task 9, not here.
+///
+/// Two pickers feed the baseline: the plain `Classes.ClassTest` (no
+/// superclass, no resilient stub) and `Classes.SubclassTest` (has a
+/// non-nil superclass mangled name).
+package enum ClassDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let classTest = try BaselineFixturePicker.class_ClassTest(in: machO)
+ let subclassTest = try BaselineFixturePicker.class_SubclassTest(in: machO)
+
+ let classTestExpr = try emitEntryExpr(for: classTest, in: machO)
+ let subclassTestExpr = try emitEntryExpr(for: subclassTest, in: machO)
+
+ // Members directly declared in ClassDescriptor.swift (across the main
+ // body and three same-file extensions). Overload pairs (MachO +
+ // ReadingContext) collapse to a single MethodKey under the scanner's
+ // name-based deduplication.
+ let registered = [
+ "areImmediateMembersNegative",
+ "hasDefaultOverrideTable",
+ "hasFieldOffsetVector",
+ "hasObjCResilientClassStub",
+ "hasOverrideTable",
+ "hasResilientSuperclass",
+ "hasVTable",
+ "immediateMemberSize",
+ "isActor",
+ "isDefaultActor",
+ "layout",
+ "nonResilientImmediateMembersOffset",
+ "offset",
+ "resilientMetadataBounds",
+ "resilientSuperclassReferenceKind",
+ "superclassTypeMangledName",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ClassDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumFields: Int
+ let layoutFieldOffsetVectorOffset: Int
+ let layoutNumImmediateMembers: Int
+ let layoutFlagsRawValue: UInt32
+ let hasFieldOffsetVector: Bool
+ let hasDefaultOverrideTable: Bool
+ let isActor: Bool
+ let isDefaultActor: Bool
+ let hasVTable: Bool
+ let hasOverrideTable: Bool
+ let hasResilientSuperclass: Bool
+ let areImmediateMembersNegative: Bool
+ let hasObjCResilientClassStub: Bool
+ let hasSuperclassTypeMangledName: Bool
+ let immediateMemberSize: UInt
+ let nonResilientImmediateMembersOffset: Int32
+ }
+
+ static let classTest = \(raw: classTestExpr)
+
+ static let subclassTest = \(raw: subclassTestExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ClassDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for descriptor: ClassDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let offset = descriptor.offset
+ let numFields = Int(descriptor.layout.numFields)
+ let fieldOffsetVectorOffset = Int(descriptor.layout.fieldOffsetVectorOffset)
+ let numImmediateMembers = Int(descriptor.layout.numImmediateMembers)
+ let flagsRaw = descriptor.layout.flags.rawValue
+ let hasFieldOffsetVector = descriptor.hasFieldOffsetVector
+ let hasDefaultOverrideTable = descriptor.hasDefaultOverrideTable
+ let isActor = descriptor.isActor
+ let isDefaultActor = descriptor.isDefaultActor
+ let hasVTable = descriptor.hasVTable
+ let hasOverrideTable = descriptor.hasOverrideTable
+ let hasResilientSuperclass = descriptor.hasResilientSuperclass
+ let areImmediateMembersNegative = descriptor.areImmediateMembersNegative
+ let hasObjCResilientClassStub = descriptor.hasObjCResilientClassStub
+ let hasSuperclassTypeMangledName = (try descriptor.superclassTypeMangledName(in: machO)) != nil
+ let immediateMemberSize = UInt(descriptor.immediateMemberSize)
+ let nonResilientImmediateMembersOffset = descriptor.nonResilientImmediateMembersOffset
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumFields: \(literal: numFields),
+ layoutFieldOffsetVectorOffset: \(literal: fieldOffsetVectorOffset),
+ layoutNumImmediateMembers: \(literal: numImmediateMembers),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw)),
+ hasFieldOffsetVector: \(literal: hasFieldOffsetVector),
+ hasDefaultOverrideTable: \(literal: hasDefaultOverrideTable),
+ isActor: \(literal: isActor),
+ isDefaultActor: \(literal: isDefaultActor),
+ hasVTable: \(literal: hasVTable),
+ hasOverrideTable: \(literal: hasOverrideTable),
+ hasResilientSuperclass: \(literal: hasResilientSuperclass),
+ areImmediateMembersNegative: \(literal: areImmediateMembersNegative),
+ hasObjCResilientClassStub: \(literal: hasObjCResilientClassStub),
+ hasSuperclassTypeMangledName: \(literal: hasSuperclassTypeMangledName),
+ immediateMemberSize: \(raw: BaselineEmitter.hex(immediateMemberSize)),
+ nonResilientImmediateMembersOffset: \(literal: nonResilientImmediateMembersOffset)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..2108400a
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassFlagsBaselineGenerator.swift
@@ -0,0 +1,49 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/ClassFlagsBaseline.swift`.
+///
+/// `ClassFlags` is a `UInt32` raw enum with five named cases. It does not
+/// declare additional public properties or methods. The Suite verifies the
+/// raw values stay in lockstep with the ABI; the baseline records the
+/// expected raw values per case so any rename/renumber will trip a test.
+package enum ClassFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public surface declared in ClassFlags.swift: the enum itself and its
+ // raw cases. Cases are tracked here but show up as type members on
+ // the enum (PublicMemberScanner emits no per-case keys), so the
+ // registered set is intentionally empty for this Suite — the Coverage
+ // Invariant test just expects an empty set to mean "no public
+ // members other than the cases".
+ let registered: [String] = []
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ClassFlags is a raw UInt32 enum with five named cases. The Suite
+ // (ClassFlagsTests) round-trips the raw values to catch any
+ // accidental case renumbering / renaming.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ClassFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ static let isSwiftPreStableABI: UInt32 = 0x1
+ static let usesSwiftRefcounting: UInt32 = 0x2
+ static let hasCustomObjCName: UInt32 = 0x4
+ static let isStaticSpecialization: UInt32 = 0x8
+ static let isCanonicalStaticSpecialization: UInt32 = 0x10
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ClassFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..2a90ba2e
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataBaselineGenerator.swift
@@ -0,0 +1,47 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/ClassMetadataBaseline.swift`.
+///
+/// Like `StructMetadataBaselineGenerator`, this generator does NOT consume
+/// the MachOFile fixture: `ClassMetadata` instances can only be obtained
+/// by invoking the class's metadata accessor function from a *loaded*
+/// MachOImage in the current process. Encoding live pointer values in a
+/// literal would not be stable across runs, so the Suite tests cover
+/// correctness via cross-reader equality at runtime instead.
+package enum ClassMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in ClassMetadata.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "descriptorOffset",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ClassMetadata can only be materialized via MachOImage's accessor
+ // function at runtime; live pointer values are not embedded here.
+ // The companion Suite (ClassMetadataTests) relies on cross-reader
+ // equality between (MachOImage, fileContext, imageContext,
+ // inProcess) for correctness.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ClassMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ClassMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataBoundsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataBoundsBaselineGenerator.swift
new file mode 100644
index 00000000..b419feda
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataBoundsBaselineGenerator.swift
@@ -0,0 +1,43 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/ClassMetadataBoundsBaseline.swift`.
+///
+/// `ClassMetadataBounds` is a value type holding three scalars
+/// (`negativeSizeInWords`, `positiveSizeInWords`, `immediateMembersOffset`).
+/// It's normally constructed via the static factories on
+/// `ClassMetadataBoundsProtocol`, not picked from the binary directly.
+/// The baseline records only the registered member names; the Suite
+/// exercises the type by constructing instances and checking the layout.
+package enum ClassMetadataBoundsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in ClassMetadataBounds.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ClassMetadataBounds is a derived type usually built through
+ // factory methods on ClassMetadataBoundsProtocol.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ClassMetadataBoundsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ClassMetadataBoundsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataBoundsProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataBoundsProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..a86c3663
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataBoundsProtocolBaselineGenerator.swift
@@ -0,0 +1,42 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/ClassMetadataBoundsProtocolBaseline.swift`.
+///
+/// The protocol declares one instance method (`adjustForSubclass`) and
+/// two static factory methods (`forAddressPointAndSize`,
+/// `forSwiftRootClass`). The Suite exercises them by constructing a
+/// known starting bounds value, applying a subclass adjustment, and
+/// asserting the post-adjustment scalars.
+package enum ClassMetadataBoundsProtocolBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in ClassMetadataBoundsProtocol.swift.
+ let registered = [
+ "adjustForSubclass",
+ "forAddressPointAndSize",
+ "forSwiftRootClass",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ClassMetadataBoundsProtocol's methods are pure value-type
+ // computations; the Suite exercises them with constructed inputs.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ClassMetadataBoundsProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ClassMetadataBoundsProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataObjCInteropBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataObjCInteropBaselineGenerator.swift
new file mode 100644
index 00000000..d9f3a342
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ClassMetadataObjCInteropBaselineGenerator.swift
@@ -0,0 +1,42 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/ClassMetadataObjCInteropBaseline.swift`.
+///
+/// `ClassMetadataObjCInterop` is the parallel of `ClassMetadata` for
+/// ObjC-interop classes. Same rule: only materialised at runtime via the
+/// MachOImage metadata accessor, so this baseline records only the
+/// registered member names.
+package enum ClassMetadataObjCInteropBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in ClassMetadataObjCInterop.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "descriptorOffset",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ClassMetadataObjCInterop can only be materialised via MachOImage's
+ // metadata accessor at runtime; live pointer values are not embedded.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ClassMetadataObjCInteropBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ClassMetadataObjCInteropBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ExtraClassDescriptorFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ExtraClassDescriptorFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..8577f611
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ExtraClassDescriptorFlagsBaselineGenerator.swift
@@ -0,0 +1,50 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ExtraClassDescriptorFlagsBaseline.swift`.
+///
+/// `ExtraClassDescriptorFlags` is a tiny `FlagSet` over `UInt32`. The flag
+/// is only meaningful when a class has a resilient superclass; for the
+/// plain `Classes.ClassTest` picker the raw value is zero. We exercise the
+/// `init(rawValue:)` round-trip and the derived `hasObjCResilientClassStub`
+/// boolean against a fixed raw value of `0x0` to keep the test deterministic.
+package enum ExtraClassDescriptorFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in ExtraClassDescriptorFlags.swift.
+ let registered = [
+ "hasObjCResilientClassStub",
+ "init(rawValue:)",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ExtraClassDescriptorFlags is a UInt32 FlagSet with a single bit
+ // (`hasObjCResilientClassStub`). For the plain ClassTest picker
+ // the raw value is zero; we test the flag derivation by
+ // round-tripping a known raw value through `init(rawValue:)`.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ExtraClassDescriptorFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ // Construct round-trip values: bit 0 set / unset.
+ static let zeroRawValue: UInt32 = 0x0
+ static let stubBitRawValue: UInt32 = 0x1
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ExtraClassDescriptorFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/FinalClassMetadataProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/FinalClassMetadataProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..e61d1d0f
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/FinalClassMetadataProtocolBaselineGenerator.swift
@@ -0,0 +1,44 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/FinalClassMetadataProtocolBaseline.swift`.
+///
+/// The protocol's `descriptor(...)` and `fieldOffsets(...)` overloads
+/// require a live class metadata instance. Materialising one needs a
+/// loaded MachOImage; consequently, the cross-reader assertions in the
+/// Suite are asymmetric (the metadata originates from MachOImage but its
+/// methods accept any `ReadingContext`).
+package enum FinalClassMetadataProtocolBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly across the
+ // FinalClassMetadataProtocol extension blocks. Overload pairs
+ // collapse to single MethodKey entries.
+ let registered = [
+ "descriptor",
+ "fieldOffsets",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live ClassMetadata cannot be embedded as a literal; the Suite
+ // verifies the methods produce cross-reader-consistent results
+ // at runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum FinalClassMetadataProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("FinalClassMetadataProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDefaultOverrideDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDefaultOverrideDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..4db8344d
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDefaultOverrideDescriptorBaselineGenerator.swift
@@ -0,0 +1,51 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MethodDefaultOverrideDescriptorBaseline.swift`.
+///
+/// `MethodDefaultOverrideDescriptor` represents a default implementation
+/// override entry under `MethodDefaultOverrideTableHeader`. The
+/// `SymbolTestsCore` fixture's classes don't emit a default-override
+/// table, so we cannot pick a live instance. The baseline therefore
+/// records only the registered member names; the companion Suite skips
+/// the runtime portion with a documented note. Coverage of the live
+/// behaviour will land when a fixture surfaces a default-override table
+/// (Task 16 will track this via the allowlist if needed).
+package enum MethodDefaultOverrideDescriptorBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in MethodDefaultOverrideDescriptor.swift.
+ // Overload pairs collapse to single MethodKey entries via the scanner.
+ let registered = [
+ "implementationSymbols",
+ "layout",
+ "offset",
+ "originalMethodDescriptor",
+ "replacementMethodDescriptor",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // The SymbolTestsCore fixture does not declare any class with a
+ // default-override table, so MethodDefaultOverrideDescriptor cannot
+ // be sourced from the fixture. The Suite (MethodDefaultOverrideDescriptorTests)
+ // exercises only static surface (Layout offsets) and documents the
+ // missing runtime coverage.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MethodDefaultOverrideDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MethodDefaultOverrideDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDefaultOverrideTableHeaderBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDefaultOverrideTableHeaderBaselineGenerator.swift
new file mode 100644
index 00000000..b2db676f
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDefaultOverrideTableHeaderBaselineGenerator.swift
@@ -0,0 +1,43 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MethodDefaultOverrideTableHeaderBaseline.swift`.
+///
+/// `MethodDefaultOverrideTableHeader` is the trailing-object header for the
+/// default-override table. The `SymbolTestsCore` fixture's classes don't
+/// declare a default-override table, so we cannot pick a live instance.
+/// The baseline therefore records only the registered member names; the
+/// Suite (`MethodDefaultOverrideTableHeaderTests`) skips the runtime
+/// portion with a documented note.
+package enum MethodDefaultOverrideTableHeaderBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in MethodDefaultOverrideTableHeader.swift.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // The SymbolTestsCore fixture does not declare any class with a
+ // default-override table, so MethodDefaultOverrideTableHeader cannot
+ // be sourced. The Suite documents the missing runtime coverage.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MethodDefaultOverrideTableHeaderBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MethodDefaultOverrideTableHeaderBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..3a9821af
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDescriptorBaselineGenerator.swift
@@ -0,0 +1,80 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/MethodDescriptorBaseline.swift`.
+///
+/// `MethodDescriptor` is the row type for a class's vtable. We pick the
+/// first vtable entry from the `Classes.ClassTest` picker — which has a
+/// non-empty vtable — and record the `flags.rawValue` plus the descriptor
+/// offset. Live `Symbols?` payloads aren't embedded as literals; the Suite
+/// uses cross-reader equality at runtime to assert agreement.
+package enum MethodDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.class_ClassTest(in: machO)
+ let classWrapper = try Class(descriptor: descriptor, in: machO)
+ let firstMethod = try required(classWrapper.methodDescriptors.first)
+
+ let entryExpr = emitEntryExpr(for: firstMethod)
+ let methodCount = classWrapper.methodDescriptors.count
+
+ // Public members declared directly in MethodDescriptor.swift.
+ // The two `implementationSymbols(in:)` overloads collapse to a
+ // single MethodKey under PublicMemberScanner's name-only key.
+ let registered = [
+ "implementationSymbols",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Method descriptors carry a `Symbols?` implementation pointer; live
+ // payloads aren't embedded as literals. The companion Suite
+ // (MethodDescriptorTests) verifies cross-reader agreement at
+ // runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MethodDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutFlagsRawValue: UInt32
+ }
+
+ static let firstClassTestMethod = \(raw: entryExpr)
+
+ static let classTestMethodCount = \(literal: methodCount)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MethodDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for method: MethodDescriptor) -> String {
+ let offset = method.offset
+ let flagsRaw = method.layout.flags.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDescriptorFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDescriptorFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..5bf497a6
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDescriptorFlagsBaselineGenerator.swift
@@ -0,0 +1,103 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/MethodDescriptorFlagsBaseline.swift`.
+///
+/// `MethodDescriptorFlags` is a 32-bit packed flag word stored in each
+/// `MethodDescriptor.layout.flags`. We extract the live flags from the
+/// first vtable entry of `Classes.ClassTest` and record the raw value
+/// plus all derived booleans / fields. This catches accidental changes
+/// to the bit layout.
+package enum MethodDescriptorFlagsBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.class_ClassTest(in: machO)
+ let classWrapper = try Class(descriptor: descriptor, in: machO)
+ let firstMethod = try required(classWrapper.methodDescriptors.first)
+ let flags = firstMethod.layout.flags
+
+ let entryExpr = emitEntryExpr(for: flags)
+
+ // Public members declared directly in MethodDescriptorFlags.swift.
+ let registered = [
+ "_hasAsyncBitSet",
+ "extraDiscriminator",
+ "init(rawValue:)",
+ "isAsync",
+ "isCalleeAllocatedCoroutine",
+ "isCoroutine",
+ "isData",
+ "isDynamic",
+ "isInstance",
+ "kind",
+ "rawValue",
+ ]
+
+ let headerComment = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: headerComment)
+
+ enum MethodDescriptorFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt32
+ let kindRawValue: UInt8
+ let isDynamic: Bool
+ let isInstance: Bool
+ let hasAsyncBitSet: Bool
+ let isAsync: Bool
+ let isCoroutine: Bool
+ let isCalleeAllocatedCoroutine: Bool
+ let isData: Bool
+ let extraDiscriminator: UInt16
+ }
+
+ static let firstClassTestMethod = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MethodDescriptorFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for flags: MethodDescriptorFlags) -> String {
+ let rawValue = flags.rawValue
+ let kindRawValue = flags.kind.rawValue
+ let isDynamic = flags.isDynamic
+ let isInstance = flags.isInstance
+ let hasAsyncBitSet = flags._hasAsyncBitSet
+ let isAsync = flags.isAsync
+ let isCoroutine = flags.isCoroutine
+ let isCalleeAllocatedCoroutine = flags.isCalleeAllocatedCoroutine
+ let isData = flags.isData
+ let extraDiscriminator = flags.extraDiscriminator
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRawValue)),
+ isDynamic: \(literal: isDynamic),
+ isInstance: \(literal: isInstance),
+ hasAsyncBitSet: \(literal: hasAsyncBitSet),
+ isAsync: \(literal: isAsync),
+ isCoroutine: \(literal: isCoroutine),
+ isCalleeAllocatedCoroutine: \(literal: isCalleeAllocatedCoroutine),
+ isData: \(literal: isData),
+ extraDiscriminator: \(raw: BaselineEmitter.hex(extraDiscriminator))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDescriptorKindBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDescriptorKindBaselineGenerator.swift
new file mode 100644
index 00000000..98c3fa1b
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodDescriptorKindBaselineGenerator.swift
@@ -0,0 +1,50 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MethodDescriptorKindBaseline.swift`.
+///
+/// `MethodDescriptorKind` is a `UInt8`-raw enum with six cases (`method`,
+/// `init`, `getter`, `setter`, `modifyCoroutine`, `readCoroutine`). The
+/// `description` accessor returns a fixed-width display string per case.
+/// We pin the raw values and description strings here so accidental
+/// renumbering or display tweaks fail a Suite test.
+package enum MethodDescriptorKindBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in MethodDescriptorKind.swift:
+ // only `description`. Cases are tracked statically below.
+ let registered = [
+ "description",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MethodDescriptorKindBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt8
+ let description: String
+ }
+
+ static let method = Entry(rawValue: 0x0, description: "Method")
+ static let `init` = Entry(rawValue: 0x1, description: " Init ")
+ static let getter = Entry(rawValue: 0x2, description: "Getter")
+ static let setter = Entry(rawValue: 0x3, description: "Setter")
+ static let modifyCoroutine = Entry(rawValue: 0x4, description: "Modify")
+ static let readCoroutine = Entry(rawValue: 0x5, description: " Read ")
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MethodDescriptorKindBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodOverrideDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodOverrideDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..45432a8a
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/MethodOverrideDescriptorBaselineGenerator.swift
@@ -0,0 +1,78 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/MethodOverrideDescriptorBaseline.swift`.
+///
+/// `MethodOverrideDescriptor` is the row type for a class's override table.
+/// We pick the first override entry from `Classes.SubclassTest` (which
+/// overrides several methods inherited from `ClassTest`) and record the
+/// descriptor offset. Resolved class/method/symbols pointers aren't
+/// embedded as literals; the Suite uses cross-reader equality at runtime.
+package enum MethodOverrideDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.class_SubclassTest(in: machO)
+ let classWrapper = try Class(descriptor: descriptor, in: machO)
+ let firstOverride = try required(classWrapper.methodOverrideDescriptors.first)
+
+ let entryExpr = emitEntryExpr(for: firstOverride)
+ let overrideCount = classWrapper.methodOverrideDescriptors.count
+
+ // Public members declared directly in MethodOverrideDescriptor.swift
+ // (across the main body and same-file extensions). Overload sets
+ // collapse to a single MethodKey under PublicMemberScanner.
+ let registered = [
+ "classDescriptor",
+ "implementationSymbols",
+ "layout",
+ "methodDescriptor",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // MethodOverrideDescriptor carries three relative pointers (class /
+ // method / implementation Symbols). Live payloads aren't embedded;
+ // the Suite verifies cross-reader agreement at runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MethodOverrideDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ }
+
+ static let firstSubclassOverride = \(raw: entryExpr)
+
+ static let subclassOverrideCount = \(literal: overrideCount)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MethodOverrideDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for override: MethodOverrideDescriptor) -> String {
+ let offset = override.offset
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ObjCClassWrapperMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ObjCClassWrapperMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..c66f4b07
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ObjCClassWrapperMetadataBaselineGenerator.swift
@@ -0,0 +1,60 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ObjCClassWrapperMetadataBaseline.swift`.
+///
+/// Phase B3: `ObjCClassWrapperMetadata` is exercised as a real
+/// InProcess test against `NSObject.self` — the Swift runtime allocates
+/// kind 0x305 wrapper metadata for plain ObjC classes. Phase B3 added
+/// `ObjCClassWrappers.swift` to the SymbolTestsCore fixture (so the
+/// fixture itself contains NSObject-derived classes); however the
+/// canonical `ObjCClassWrapperMetadata` carrier is NSObject's own
+/// runtime metadata, which is allocated by Swift's bridging layer on
+/// first use.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum ObjCClassWrapperMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let pointer = InProcessMetadataPicker.foundationNSObjectWrapper
+ let context = InProcessContext()
+ let metadata = try ObjCClassWrapperMetadata.resolve(at: pointer, in: context)
+ let kindRaw = metadata.layout.kind
+
+ let registered = ["layout", "offset"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess (`Foundation.NSObject.self`); no Mach-O section presence.
+ //
+ // ObjCClassWrapperMetadata is allocated by the Swift runtime on
+ // first reference to a pure ObjC class. Phase B3 introduced the
+ // SymbolTestsCore fixture's `ObjCClassWrapperFixtures` namespace
+ // to surface NSObject-derived classes for the broader ObjC-interop
+ // metadata Suites; the wrapper itself is canonically tested
+ // against NSObject's runtime metadata.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ObjCClassWrapperMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let kindRawValue: UInt64
+ }
+
+ static let foundationNSObject = Entry(
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRaw))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ObjCClassWrapperMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ObjCResilientClassStubInfoBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ObjCResilientClassStubInfoBaselineGenerator.swift
new file mode 100644
index 00000000..431d7bc9
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ObjCResilientClassStubInfoBaselineGenerator.swift
@@ -0,0 +1,77 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ObjCResilientClassStubInfoBaseline.swift`.
+///
+/// `ObjCResilientClassStubInfo` is the trailing-object payload that holds
+/// a `RelativeDirectRawPointer` to the resilient class stub. It only
+/// appears when a class has `hasObjCResilientClassStub == true`, which
+/// fires when ObjC interop is on AND the class is non-generic AND its
+/// metadata strategy is `Resilient` or `Singleton` (i.e. the metadata
+/// requires runtime relocation).
+///
+/// Phase B4 introduced `ObjCResilientStubFixtures.ResilientObjCStubChild`
+/// (a Swift class inheriting `SymbolTestsHelper.Object`) as the canonical
+/// carrier. Cross-module inheritance from a class declared in another
+/// `BUILD_LIBRARY_FOR_DISTRIBUTION = YES` module triggers the resilient
+/// metadata strategy, so the descriptor carries the trailing record.
+package enum ObjCResilientClassStubInfoBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ // Public members declared directly in ObjCResilientClassStubInfo.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized;
+ // `stub` is the inner Layout's stored field, exercised
+ // transitively via the `layout` test.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let descriptor = try BaselineFixturePicker.class_ResilientObjCStubChild(in: machO)
+ let classWrapper = try Class(descriptor: descriptor, in: machO)
+ let stubInfo = try required(classWrapper.objcResilientClassStubInfo)
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ObjCResilientClassStubInfo is the trailing-object record on a
+ // class whose metadata strategy is Resilient/Singleton (i.e. the
+ // metadata requires runtime relocation/initialization). The
+ // Suite drives `ObjCResilientStubFixtures.ResilientObjCStubChild`
+ // (parent `SymbolTestsHelper.Object`, cross-module) and asserts
+ // cross-reader agreement on the record offset and the stub
+ // reference's relative-offset scalar.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ObjCResilientClassStubInfoBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let sourceClassOffset: Int
+ let offset: Int
+ let layoutStubRelativeOffset: Int32
+ }
+
+ static let resilientObjCStubChild = Entry(
+ sourceClassOffset: \(raw: BaselineEmitter.hex(descriptor.offset)),
+ offset: \(raw: BaselineEmitter.hex(stubInfo.offset)),
+ layoutStubRelativeOffset: \(literal: stubInfo.layout.stub.relativeOffset)
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ObjCResilientClassStubInfoBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/OverrideTableHeaderBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/OverrideTableHeaderBaselineGenerator.swift
new file mode 100644
index 00000000..2fdc9a5f
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/OverrideTableHeaderBaselineGenerator.swift
@@ -0,0 +1,69 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/OverrideTableHeaderBaseline.swift`.
+///
+/// `OverrideTableHeader` is the trailing-object header that announces a
+/// class's override table (entries follow). We pick the header from
+/// `Classes.SubclassTest` (which overrides several methods inherited from
+/// `ClassTest`) and record the `numEntries` scalar.
+package enum OverrideTableHeaderBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.class_SubclassTest(in: machO)
+ let classWrapper = try Class(descriptor: descriptor, in: machO)
+ let header = try required(classWrapper.overrideTableHeader)
+
+ let entryExpr = emitEntryExpr(for: header)
+
+ // Public members declared directly in OverrideTableHeader.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let headerComment = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: headerComment)
+
+ enum OverrideTableHeaderBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumEntries: UInt32
+ }
+
+ static let subclassTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("OverrideTableHeaderBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for header: OverrideTableHeader) -> String {
+ let offset = header.offset
+ let numEntries = header.layout.numEntries
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumEntries: \(literal: numEntries)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/ResilientSuperclassBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ResilientSuperclassBaselineGenerator.swift
new file mode 100644
index 00000000..3c97a315
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/ResilientSuperclassBaselineGenerator.swift
@@ -0,0 +1,70 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ResilientSuperclassBaseline.swift`.
+///
+/// `ResilientSuperclass` is the trailing-object record carrying a
+/// `RelativeDirectRawPointer` to the superclass when a class has
+/// `hasResilientSuperclass == true`. The fixture `ResilientChild`
+/// (whose parent `SymbolTestsHelper.ResilientBase` lives in a different
+/// module) is the canonical carrier — Phase B2 introduced it to give
+/// `ResilientSuperclassTests` a stably-named, deterministic subject.
+package enum ResilientSuperclassBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ // Public members declared directly in ResilientSuperclass.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized;
+ // `superclass` is the inner Layout's stored field, exercised
+ // transitively via the `layout` test.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let descriptor = try BaselineFixturePicker.class_ResilientChild(in: machO)
+ let classWrapper = try Class(descriptor: descriptor, in: machO)
+ let resilientSuperclass = try required(classWrapper.resilientSuperclass)
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ResilientSuperclass is the trailing-object record on a class
+ // whose parent lives in a different module. The Suite drives
+ // `ResilientClassFixtures.ResilientChild` (parent
+ // `SymbolTestsHelper.ResilientBase`) and asserts cross-reader
+ // agreement on the record offset and the superclass reference's
+ // relative-offset scalar.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ResilientSuperclassBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let sourceClassOffset: Int
+ let offset: Int
+ let layoutSuperclassRelativeOffset: Int32
+ }
+
+ static let resilientChild = Entry(
+ sourceClassOffset: \(raw: BaselineEmitter.hex(descriptor.offset)),
+ offset: \(raw: BaselineEmitter.hex(resilientSuperclass.offset)),
+ layoutSuperclassRelativeOffset: \(literal: resilientSuperclass.layout.superclass.relativeOffset)
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ResilientSuperclassBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/StoredClassMetadataBoundsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/StoredClassMetadataBoundsBaselineGenerator.swift
new file mode 100644
index 00000000..26e8e029
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/StoredClassMetadataBoundsBaselineGenerator.swift
@@ -0,0 +1,54 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/StoredClassMetadataBoundsBaseline.swift`.
+///
+/// Phase B2: `StoredClassMetadataBounds` is exercised as a real
+/// InProcess wrapper. The Suite dlsym's the nominal type descriptor of
+/// `ResilientClassFixtures.ResilientChild`, materialises the
+/// `ClassDescriptor`, then chases the resilient-metadata-bounds
+/// pointer via the InProcess `ReadingContext`. The bounds are
+/// runtime-allocated, so their address (`offset`) is ASLR-randomized
+/// and the `negativeSizeInWords` / `positiveSizeInWords` shape reflects
+/// the resilient root's metadata, which can drift across toolchain
+/// versions. The Suite asserts invariants (non-zero offset, sane word
+/// counts) rather than pinning literals.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum StoredClassMetadataBoundsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // StoredClassMetadataBounds is reachable via
+ // ClassDescriptor.resilientMetadataBounds(in:context:). Phase B2
+ // converted the Suite to an InProcess-only real test against
+ // `ResilientClassFixtures.ResilientChild` (parent
+ // `SymbolTestsHelper.ResilientBase`, cross-module). The bounds
+ // are runtime-allocated so no ABI literal is pinned — the Suite
+ // asserts invariants on the resolved record instead.
+ //
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum StoredClassMetadataBoundsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("StoredClassMetadataBoundsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Class/VTableDescriptorHeaderBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Class/VTableDescriptorHeaderBaselineGenerator.swift
new file mode 100644
index 00000000..52b3401d
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Class/VTableDescriptorHeaderBaselineGenerator.swift
@@ -0,0 +1,72 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/VTableDescriptorHeaderBaseline.swift`.
+///
+/// `VTableDescriptorHeader` is the trailing-object header that announces a
+/// class's vtable. We pick the header from `Classes.ClassTest` (which has
+/// a non-empty vtable) and record both layout scalars: `vTableOffset` and
+/// `vTableSize`.
+package enum VTableDescriptorHeaderBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.class_ClassTest(in: machO)
+ let classWrapper = try Class(descriptor: descriptor, in: machO)
+ let header = try required(classWrapper.vTableDescriptorHeader)
+
+ let entryExpr = emitEntryExpr(for: header)
+
+ // Public members declared directly in VTableDescriptorHeader.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let headerComment = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: headerComment)
+
+ enum VTableDescriptorHeaderBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutVTableOffset: UInt32
+ let layoutVTableSize: UInt32
+ }
+
+ static let classTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("VTableDescriptorHeaderBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for header: VTableDescriptorHeader) -> String {
+ let offset = header.offset
+ let vTableOffset = header.layout.vTableOffset
+ let vTableSize = header.layout.vTableSize
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutVTableOffset: \(literal: vTableOffset),
+ layoutVTableSize: \(literal: vTableSize)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..de7afd0e
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorBaselineGenerator.swift
@@ -0,0 +1,72 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ContextDescriptorBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `ContextDescriptor` declares only the `offset` and `layout` ivars
+/// (`init(layout:offset:)` is filtered as memberwise-synthesized). Protocol-
+/// extension members (`parent`, `genericContext`, `subscript(dynamicMember:)`,
+/// etc.) live on `ContextDescriptorProtocol` and are covered by
+/// `ContextDescriptorProtocolTests`, per the protocol-extension attribution
+/// rule documented in `BaselineGenerator.swift`.
+///
+/// We materialize a representative `ContextDescriptor` by reading the bare
+/// header at `Structs.StructTest`'s offset.
+package enum ContextDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let structTest = try BaselineFixturePicker.struct_StructTest(in: machO)
+ // Read the bare ContextDescriptor header at the same offset so the
+ // baseline reflects the canonical descriptor view (flags only at the
+ // header level — the layout's `parent` is a relative pointer and not
+ // a stable scalar).
+ let descriptor: ContextDescriptor = try machO.readWrapperElement(offset: structTest.offset)
+ let entryExpr = emitEntryExpr(for: descriptor)
+
+ let registered = ["layout", "offset"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ContextDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutFlagsRawValue: UInt32
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ContextDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for descriptor: ContextDescriptor) -> String {
+ let offset = descriptor.offset
+ let flagsRaw = descriptor.layout.flags.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..3a9a0baf
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorFlagsBaselineGenerator.swift
@@ -0,0 +1,100 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ContextDescriptorFlagsBaseline.swift`.
+///
+/// `ContextDescriptorFlags` is the bit-packed `OptionSet` carried in every
+/// descriptor's first 4 bytes. The instance vars (`kind`, `version`,
+/// `kindSpecificFlagsRawValue`, `kindSpecificFlags`, `hasInvertibleProtocols`,
+/// `isUnique`, `isGeneric`) all derive from `rawValue`; the three static
+/// `let`s (`hasInvertibleProtocols`, `isUnique`, `isGeneric`) collapse with
+/// the instance vars under PublicMemberScanner's name-only key.
+///
+/// We sample the flags off the fixture's `Structs.StructTest` descriptor —
+/// a struct kind whose `kindSpecificFlags` resolves to the `.type(...)`
+/// case (carrying a `TypeContextDescriptorFlags` payload).
+package enum ContextDescriptorFlagsBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let flags = descriptor.layout.flags
+ let entryExpr = emitEntryExpr(for: flags)
+
+ // Public members declared directly in ContextDescriptorFlags.swift.
+ // The three static `let`s (`hasInvertibleProtocols`, `isUnique`,
+ // `isGeneric`) and their same-named derived instance vars collapse
+ // to single MethodKey entries.
+ let registered = [
+ "hasInvertibleProtocols",
+ "init(rawValue:)",
+ "isGeneric",
+ "isUnique",
+ "kind",
+ "kindSpecificFlags",
+ "kindSpecificFlagsRawValue",
+ "rawValue",
+ "version",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ContextDescriptorFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt32
+ let kindRawValue: UInt8
+ let version: UInt8
+ let kindSpecificFlagsRawValue: UInt16
+ let hasKindSpecificFlags: Bool
+ let hasInvertibleProtocols: Bool
+ let isUnique: Bool
+ let isGeneric: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ContextDescriptorFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for flags: ContextDescriptorFlags) -> String {
+ let rawValue = flags.rawValue
+ let kindRawValue = flags.kind.rawValue
+ let version = flags.version
+ let kindSpecificFlagsRawValue = flags.kindSpecificFlagsRawValue
+ let hasKindSpecificFlags = flags.kindSpecificFlags != nil
+ let hasInvertibleProtocols = flags.hasInvertibleProtocols
+ let isUnique = flags.isUnique
+ let isGeneric = flags.isGeneric
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRawValue)),
+ version: \(raw: BaselineEmitter.hex(version)),
+ kindSpecificFlagsRawValue: \(raw: BaselineEmitter.hex(kindSpecificFlagsRawValue)),
+ hasKindSpecificFlags: \(literal: hasKindSpecificFlags),
+ hasInvertibleProtocols: \(literal: hasInvertibleProtocols),
+ isUnique: \(literal: isUnique),
+ isGeneric: \(literal: isGeneric)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorKindBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorKindBaselineGenerator.swift
new file mode 100644
index 00000000..b5170737
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorKindBaselineGenerator.swift
@@ -0,0 +1,70 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ContextDescriptorKindBaseline.swift`.
+///
+/// `ContextDescriptorKind` is a `UInt8`-backed enum. PublicMemberScanner does
+/// NOT emit MethodKey entries for enum cases (only for `func`/`var`/`init`/
+/// `subscript`), so the Suite covers `description` and `mangledType`.
+///
+/// We extract a representative `ContextDescriptorKind` value from the
+/// fixture's `Structs.StructTest` descriptor (`.struct`).
+package enum ContextDescriptorKindBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let kind = descriptor.layout.flags.kind
+ let entryExpr = emitEntryExpr(for: kind)
+
+ let registered = [
+ "description",
+ "mangledType",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ContextDescriptorKindBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt8
+ let description: String
+ let mangledType: String
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ContextDescriptorKindBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for kind: ContextDescriptorKind) -> String {
+ let rawValue = kind.rawValue
+ let description = kind.description
+ let mangledType = kind.mangledType
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ description: \(literal: description),
+ mangledType: \(literal: mangledType)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorKindSpecificFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorKindSpecificFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..6be978cd
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorKindSpecificFlagsBaselineGenerator.swift
@@ -0,0 +1,73 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ContextDescriptorKindSpecificFlagsBaseline.swift`.
+///
+/// `ContextDescriptorKindSpecificFlags` is a sum type whose three case-
+/// extraction accessors (`protocolFlags`, `typeFlags`, `anonymousFlags`)
+/// return optionals. We sample the fixture's `Structs.StructTest` descriptor
+/// (a struct kind) so the live value is `.type(...)` — `typeFlags != nil`,
+/// the other two `nil`.
+///
+/// PublicMemberScanner does NOT emit MethodKey entries for the underlying
+/// enum cases.
+package enum ContextDescriptorKindSpecificFlagsBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let flags = try required(descriptor.layout.flags.kindSpecificFlags)
+ let entryExpr = emitEntryExpr(for: flags)
+
+ let registered = [
+ "anonymousFlags",
+ "protocolFlags",
+ "typeFlags",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ContextDescriptorKindSpecificFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let hasProtocolFlags: Bool
+ let hasTypeFlags: Bool
+ let hasAnonymousFlags: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ContextDescriptorKindSpecificFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for flags: ContextDescriptorKindSpecificFlags) -> String {
+ let hasProtocolFlags = flags.protocolFlags != nil
+ let hasTypeFlags = flags.typeFlags != nil
+ let hasAnonymousFlags = flags.anonymousFlags != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ hasProtocolFlags: \(literal: hasProtocolFlags),
+ hasTypeFlags: \(literal: hasTypeFlags),
+ hasAnonymousFlags: \(literal: hasAnonymousFlags)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..9cbb95d2
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorProtocolBaselineGenerator.swift
@@ -0,0 +1,107 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ContextDescriptorProtocolBaseline.swift`.
+///
+/// Per the protocol-extension attribution rule (see `BaselineGenerator.swift`),
+/// `parent`, `genericContext`, `moduleContextDescriptor`,
+/// `isCImportedContextDescriptor`, and `subscript(dynamicMember:)` all live
+/// on `ContextDescriptorProtocol` and are exercised here, NOT on the
+/// concrete-descriptor Suites.
+///
+/// The methods return live optionals (descriptor wrappers, generic contexts,
+/// module descriptors) we don't embed as literals; instead the companion
+/// Suite verifies cross-reader-consistent results at runtime against the
+/// presence flags recorded here. The dynamic-member `subscript` is exercised
+/// indirectly by going through the subscript syntax (`descriptor.kind`).
+package enum ContextDescriptorProtocolBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let hasParent = (try descriptor.parent(in: machO)) != nil
+ let hasGenericContext = try descriptor.genericContext(in: machO) != nil
+ let hasModuleContextDescriptor = try descriptor.moduleContextDescriptor(in: machO) != nil
+ let isCImported = try descriptor.isCImportedContextDescriptor(in: machO)
+ // The dynamic-member subscript routes to `layout.flags`; pick a stable
+ // scalar (`kind.rawValue`) to assert against.
+ let subscriptKindRawValue = descriptor.kind.rawValue
+
+ let entryExpr = emitEntryExpr(
+ hasParent: hasParent,
+ hasGenericContext: hasGenericContext,
+ hasModuleContextDescriptor: hasModuleContextDescriptor,
+ isCImported: isCImported,
+ subscriptKindRawValue: subscriptKindRawValue
+ )
+
+ // Public members in protocol body + protocol extensions on
+ // `ContextDescriptorProtocol`. Each name collapses to one MethodKey
+ // under PublicMemberScanner's name-only key, so the various MachO/
+ // InProcess/ReadingContext overloads of `parent`/`genericContext`/
+ // etc. flatten into single entries.
+ let registered = [
+ "genericContext",
+ "isCImportedContextDescriptor",
+ "moduleContextDescriptor",
+ "parent",
+ "subscript(dynamicMember:)",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live wrapper payloads (parent/genericContext/moduleContextDescriptor)
+ // aren't embedded as literals; the companion Suite
+ // (ContextDescriptorProtocolTests) verifies the methods produce
+ // cross-reader-consistent results at runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ContextDescriptorProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let hasParent: Bool
+ let hasGenericContext: Bool
+ let hasModuleContextDescriptor: Bool
+ let isCImportedContextDescriptor: Bool
+ let subscriptKindRawValue: UInt8
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ContextDescriptorProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ hasParent: Bool,
+ hasGenericContext: Bool,
+ hasModuleContextDescriptor: Bool,
+ isCImported: Bool,
+ subscriptKindRawValue: UInt8
+ ) -> String {
+ let expr: ExprSyntax = """
+ Entry(
+ hasParent: \(literal: hasParent),
+ hasGenericContext: \(literal: hasGenericContext),
+ hasModuleContextDescriptor: \(literal: hasModuleContextDescriptor),
+ isCImportedContextDescriptor: \(literal: isCImported),
+ subscriptKindRawValue: \(raw: BaselineEmitter.hex(subscriptKindRawValue))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorWrapperBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorWrapperBaselineGenerator.swift
new file mode 100644
index 00000000..e62fc59c
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ContextDescriptorWrapperBaselineGenerator.swift
@@ -0,0 +1,159 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ContextDescriptorWrapperBaseline.swift`.
+///
+/// `ContextDescriptorWrapper` is a 6-case sum type covering every kind of
+/// context descriptor (type / protocol / anonymous / extension / module /
+/// opaqueType). Members include 5 case-extraction accessors, 9 boolean
+/// `is*` predicates, 4 alternate-projection vars (`contextDescriptor`,
+/// `namedContextDescriptor`, `typeContextDescriptor`,
+/// `typeContextDescriptorWrapper`), the `parent`/`genericContext` instance
+/// methods, and the static `resolve` family.
+///
+/// **Scope decision:** This Suite asserts the wrapper's behaviour against
+/// the `Structs.StructTest` representative (an `isStruct: true` instance,
+/// every other `is*` accessor `false`). Broader kind coverage (a class /
+/// enum / protocol / opaqueType variant) is deferred to the dedicated
+/// concrete-kind Suites in Tasks 7-11; those Suites hit the wrapper through
+/// their own pickers and round-trip the `is*` predicates implicitly.
+package enum ContextDescriptorWrapperBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let wrapper = ContextDescriptorWrapper.type(.struct(descriptor))
+ let entryExpr = try emitEntryExpr(for: wrapper, in: machO)
+
+ // Public members declared directly in ContextDescriptorWrapper.swift.
+ // The `resolve` static func family (Self vs Self?, MachO vs pointer
+ // vs ReadingContext) collapses to one MethodKey under
+ // PublicMemberScanner's name-only key.
+ let registered = [
+ "anonymousContextDescriptor",
+ "contextDescriptor",
+ "extensionContextDescriptor",
+ "genericContext",
+ "isAnonymous",
+ "isClass",
+ "isEnum",
+ "isExtension",
+ "isModule",
+ "isOpaqueType",
+ "isProtocol",
+ "isStruct",
+ "isType",
+ "moduleContextDescriptor",
+ "namedContextDescriptor",
+ "opaqueTypeDescriptor",
+ "parent",
+ "protocolDescriptor",
+ "resolve",
+ "typeContextDescriptor",
+ "typeContextDescriptorWrapper",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Picker: `Structs.StructTest` — an `isStruct: true` representative.
+ // Other `is*` accessors are all `false` for this picker; broader
+ // kind coverage lives in the dedicated concrete-kind Suites.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ContextDescriptorWrapperBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let isType: Bool
+ let isStruct: Bool
+ let isClass: Bool
+ let isEnum: Bool
+ let isProtocol: Bool
+ let isAnonymous: Bool
+ let isExtension: Bool
+ let isModule: Bool
+ let isOpaqueType: Bool
+ let hasProtocolDescriptor: Bool
+ let hasExtensionContextDescriptor: Bool
+ let hasOpaqueTypeDescriptor: Bool
+ let hasModuleContextDescriptor: Bool
+ let hasAnonymousContextDescriptor: Bool
+ let hasTypeContextDescriptor: Bool
+ let hasTypeContextDescriptorWrapper: Bool
+ let hasNamedContextDescriptor: Bool
+ let hasParent: Bool
+ let hasGenericContext: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ContextDescriptorWrapperBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for wrapper: ContextDescriptorWrapper,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let descriptorOffset = wrapper.contextDescriptor.offset
+ let isType = wrapper.isType
+ let isStruct = wrapper.isStruct
+ let isClass = wrapper.isClass
+ let isEnum = wrapper.isEnum
+ let isProtocol = wrapper.isProtocol
+ let isAnonymous = wrapper.isAnonymous
+ let isExtension = wrapper.isExtension
+ let isModule = wrapper.isModule
+ let isOpaqueType = wrapper.isOpaqueType
+ let hasProtocolDescriptor = wrapper.protocolDescriptor != nil
+ let hasExtensionContextDescriptor = wrapper.extensionContextDescriptor != nil
+ let hasOpaqueTypeDescriptor = wrapper.opaqueTypeDescriptor != nil
+ let hasModuleContextDescriptor = wrapper.moduleContextDescriptor != nil
+ let hasAnonymousContextDescriptor = wrapper.anonymousContextDescriptor != nil
+ let hasTypeContextDescriptor = wrapper.typeContextDescriptor != nil
+ let hasTypeContextDescriptorWrapper = wrapper.typeContextDescriptorWrapper != nil
+ let hasNamedContextDescriptor = wrapper.namedContextDescriptor != nil
+ let hasParent = (try wrapper.parent(in: machO)) != nil
+ let hasGenericContext = (try wrapper.genericContext(in: machO)) != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ isType: \(literal: isType),
+ isStruct: \(literal: isStruct),
+ isClass: \(literal: isClass),
+ isEnum: \(literal: isEnum),
+ isProtocol: \(literal: isProtocol),
+ isAnonymous: \(literal: isAnonymous),
+ isExtension: \(literal: isExtension),
+ isModule: \(literal: isModule),
+ isOpaqueType: \(literal: isOpaqueType),
+ hasProtocolDescriptor: \(literal: hasProtocolDescriptor),
+ hasExtensionContextDescriptor: \(literal: hasExtensionContextDescriptor),
+ hasOpaqueTypeDescriptor: \(literal: hasOpaqueTypeDescriptor),
+ hasModuleContextDescriptor: \(literal: hasModuleContextDescriptor),
+ hasAnonymousContextDescriptor: \(literal: hasAnonymousContextDescriptor),
+ hasTypeContextDescriptor: \(literal: hasTypeContextDescriptor),
+ hasTypeContextDescriptorWrapper: \(literal: hasTypeContextDescriptorWrapper),
+ hasNamedContextDescriptor: \(literal: hasNamedContextDescriptor),
+ hasParent: \(literal: hasParent),
+ hasGenericContext: \(literal: hasGenericContext)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ContextProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ContextProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..7c02fba3
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ContextProtocolBaselineGenerator.swift
@@ -0,0 +1,68 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ContextProtocolBaseline.swift`.
+///
+/// Per the protocol-extension attribution rule (see `BaselineGenerator.swift`),
+/// the `parent()` family of overloads declared in
+/// `extension ContextProtocol { ... }` belongs to this Suite, not to the
+/// concrete `Struct`/`Enum`/`Class` Suites that conform.
+///
+/// We materialize a representative `Struct` context off the `Structs.StructTest`
+/// descriptor — a concrete (non-module) context whose `parent` chain
+/// terminates at the `SymbolTestsCore` module.
+package enum ContextProtocolBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let context = try Struct(descriptor: descriptor, in: machO)
+ let hasParent = (try context.parent(in: machO)) != nil
+
+ let entryExpr = emitEntryExpr(hasParent: hasParent)
+
+ let registered = ["parent"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // The `parent` accessor returns a `SymbolOrElement?`
+ // we don't embed as a literal; the companion Suite verifies the
+ // method produces cross-reader-consistent results at runtime against
+ // the presence flag recorded here.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ContextProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let hasParent: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ContextProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(hasParent: Bool) -> String {
+ let expr: ExprSyntax = """
+ Entry(
+ hasParent: \(literal: hasParent)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ContextWrapperBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ContextWrapperBaselineGenerator.swift
new file mode 100644
index 00000000..cef7420c
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ContextWrapperBaselineGenerator.swift
@@ -0,0 +1,76 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ContextWrapperBaseline.swift`.
+///
+/// `ContextWrapper` is the high-level sum type covering all context wrappers
+/// (analogous to `ContextDescriptorWrapper` but at the `*Context` level).
+/// Members include `context` (the unified projection), the static
+/// `forContextDescriptorWrapper(_:in:)` constructor family, and `parent(in:)`.
+///
+/// Picker: we route `Structs.StructTest`'s descriptor through
+/// `ContextWrapper.forContextDescriptorWrapper` to produce a `.type(.struct(...))`
+/// wrapper. The `forContextDescriptorWrapper` overloads (MachO + InProcess +
+/// ReadingContext) collapse to one MethodKey under PublicMemberScanner's
+/// name-only key.
+package enum ContextWrapperBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let descriptorWrapper = ContextDescriptorWrapper.type(.struct(descriptor))
+ let wrapper = try ContextWrapper.forContextDescriptorWrapper(descriptorWrapper, in: machO)
+ let entryExpr = try emitEntryExpr(for: wrapper, in: machO)
+
+ let registered = [
+ "context",
+ "forContextDescriptorWrapper",
+ "parent",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ContextWrapperBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let hasParent: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ContextWrapperBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for wrapper: ContextWrapper,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let descriptorOffset = wrapper.context.descriptor.offset
+ let hasParent = (try wrapper.parent(in: machO)) != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ hasParent: \(literal: hasParent)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/DispatchClass/DispatchClassMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/DispatchClass/DispatchClassMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..734d101a
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/DispatchClass/DispatchClassMetadataBaselineGenerator.swift
@@ -0,0 +1,60 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/DispatchClassMetadataBaseline.swift`.
+///
+/// Phase C4: `DispatchClassMetadata` is exercised in the test as a real
+/// InProcess wrapper resolved against `Classes.ClassTest.self`'s runtime
+/// class metadata. Its observable state (the `kind` slot — descriptor /
+/// isa pointer — and the `offset` slot — runtime metadata pointer
+/// bit-pattern) is ASLR-randomized per process invocation, so no ABI
+/// literal can be pinned here. The Suite asserts non-zero / decoded-kind
+/// invariants instead.
+///
+/// `DispatchClassMetadata` mirrors the layout of `dispatch_object_t` /
+/// `OS_object`-rooted runtime objects (libdispatch's class layout used
+/// for ObjC interop with `dispatch_*` types). SymbolTestsCore declares
+/// no `dispatch_*` carrier; the test reuses an arbitrary Swift class
+/// metadata pointer to exercise the wrapper's accessor surface.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum DispatchClassMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // DispatchClassMetadata mirrors libdispatch's runtime class
+ // layout (OS_object). It's not a Swift type descriptor and no
+ // static carrier is reachable from SymbolTestsCore. The Suite
+ // resolves the wrapper against `Classes.ClassTest.self`'s runtime
+ // class metadata pointer (via dlsym + the C metadata accessor)
+ // and exercises the wrapper accessor surface. No ABI literal is
+ // pinned because the `kind` slot is the descriptor / isa pointer
+ // and the `offset` slot is the runtime metadata pointer
+ // bit-pattern — both ASLR-randomized per process.
+ //
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum DispatchClassMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("DispatchClassMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumBaselineGenerator.swift
new file mode 100644
index 00000000..af38b971
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumBaselineGenerator.swift
@@ -0,0 +1,108 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/EnumBaseline.swift` from the `SymbolTestsCore`
+/// fixture via the MachOFile reader.
+///
+/// `Enum` is the high-level wrapper around `EnumDescriptor`. Like its
+/// `Struct`/`Class` counterparts it carries a number of `Optional` ivars
+/// gated on the descriptor's flags. The baseline uses the
+/// **presence-flag** pattern (no value embedding) for the optionals
+/// because the underlying types (`TypeGenericContext`,
+/// `SingletonMetadataPointer`, etc.) are not cheaply Equatable; presence
+/// + cardinality catches the structural invariant we care about.
+///
+/// The `noPayloadEnumTest` picker exercises the simplest path: a plain
+/// no-payload enum with no metadata initialization or canonical
+/// specializations.
+package enum EnumBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let noPayloadDescriptor = try BaselineFixturePicker.enum_NoPayloadEnumTest(in: machO)
+
+ let noPayloadEnum = try Enum(descriptor: noPayloadDescriptor, in: machO)
+
+ let noPayloadExpr = emitEntryExpr(for: noPayloadEnum)
+
+ // Public ivars + initializers declared directly in Enum.swift.
+ // Two `init(descriptor:in:)` overloads (MachO + Context) collapse to
+ // a single MethodKey under PublicMemberScanner's name-based key.
+ let registered = [
+ "canonicalSpecializedMetadatas",
+ "canonicalSpecializedMetadatasCachingOnceToken",
+ "canonicalSpecializedMetadatasListCount",
+ "descriptor",
+ "foreignMetadataInitialization",
+ "genericContext",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "invertibleProtocolSet",
+ "singletonMetadataInitialization",
+ "singletonMetadataPointer",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum EnumBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let hasGenericContext: Bool
+ let hasForeignMetadataInitialization: Bool
+ let hasSingletonMetadataInitialization: Bool
+ let canonicalSpecializedMetadatasCount: Int
+ let hasCanonicalSpecializedMetadatasListCount: Bool
+ let hasCanonicalSpecializedMetadatasCachingOnceToken: Bool
+ let hasInvertibleProtocolSet: Bool
+ let hasSingletonMetadataPointer: Bool
+ }
+
+ static let noPayloadEnumTest = \(raw: noPayloadExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("EnumBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for instance: Enum) -> String {
+ let descriptorOffset = instance.descriptor.offset
+ let hasGenericContext = instance.genericContext != nil
+ let hasForeignMetadataInitialization = instance.foreignMetadataInitialization != nil
+ let hasSingletonMetadataInitialization = instance.singletonMetadataInitialization != nil
+ let canonicalSpecializedMetadatasCount = instance.canonicalSpecializedMetadatas.count
+ let hasCanonicalSpecializedMetadatasListCount = instance.canonicalSpecializedMetadatasListCount != nil
+ let hasCanonicalSpecializedMetadatasCachingOnceToken = instance.canonicalSpecializedMetadatasCachingOnceToken != nil
+ let hasInvertibleProtocolSet = instance.invertibleProtocolSet != nil
+ let hasSingletonMetadataPointer = instance.singletonMetadataPointer != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ hasGenericContext: \(literal: hasGenericContext),
+ hasForeignMetadataInitialization: \(literal: hasForeignMetadataInitialization),
+ hasSingletonMetadataInitialization: \(literal: hasSingletonMetadataInitialization),
+ canonicalSpecializedMetadatasCount: \(literal: canonicalSpecializedMetadatasCount),
+ hasCanonicalSpecializedMetadatasListCount: \(literal: hasCanonicalSpecializedMetadatasListCount),
+ hasCanonicalSpecializedMetadatasCachingOnceToken: \(literal: hasCanonicalSpecializedMetadatasCachingOnceToken),
+ hasInvertibleProtocolSet: \(literal: hasInvertibleProtocolSet),
+ hasSingletonMetadataPointer: \(literal: hasSingletonMetadataPointer)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..962d00e2
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumDescriptorBaselineGenerator.swift
@@ -0,0 +1,131 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/EnumDescriptorBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `EnumDescriptor` carries the `offset`/`layout` ivars (the
+/// `init(layout:offset:)` initializer is filtered as memberwise-synthesized)
+/// plus a long set of derived `var`s split across two same-file extensions:
+/// the case-count accessors (`numberOfCases`, `numberOfEmptyCases`,
+/// `numberOfPayloadCases`, `payloadSizeOffset`, `hasPayloadSizeOffset`) and
+/// the predicate family (`isSingleEmptyCaseOnly`, `isSinglePayloadCaseOnly`,
+/// `isSinglePayload`, `isMultiPayload`, `hasPayloadCases`).
+///
+/// Three pickers feed the baseline so each predicate's true branch is
+/// witnessed by at least one entry: `NoPayloadEnumTest` (4 empty cases,
+/// no payload), `SinglePayloadEnumTest` (one payload case + two empty
+/// cases — the canonical `isSinglePayload` case), and `MultiPayloadEnumTests`
+/// (4 cases, 3 payloads — the canonical `isMultiPayload` case).
+package enum EnumDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let noPayload = try BaselineFixturePicker.enum_NoPayloadEnumTest(in: machO)
+ let singlePayload = try BaselineFixturePicker.enum_SinglePayloadEnumTest(in: machO)
+ let multiPayload = try BaselineFixturePicker.enum_MultiPayloadEnumTest(in: machO)
+
+ let noPayloadExpr = emitEntryExpr(for: noPayload)
+ let singlePayloadExpr = emitEntryExpr(for: singlePayload)
+ let multiPayloadExpr = emitEntryExpr(for: multiPayload)
+
+ // Members directly declared in EnumDescriptor.swift (across the main
+ // body and two same-file extensions).
+ let registered = [
+ "hasPayloadCases",
+ "hasPayloadSizeOffset",
+ "isMultiPayload",
+ "isSingleEmptyCaseOnly",
+ "isSinglePayload",
+ "isSinglePayloadCaseOnly",
+ "layout",
+ "numberOfCases",
+ "numberOfEmptyCases",
+ "numberOfPayloadCases",
+ "offset",
+ "payloadSizeOffset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum EnumDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumPayloadCasesAndPayloadSizeOffset: UInt32
+ let layoutNumEmptyCases: UInt32
+ let layoutFlagsRawValue: UInt32
+ let numberOfCases: Int
+ let numberOfEmptyCases: Int
+ let numberOfPayloadCases: Int
+ let payloadSizeOffset: Int
+ let hasPayloadSizeOffset: Bool
+ let isSingleEmptyCaseOnly: Bool
+ let isSinglePayloadCaseOnly: Bool
+ let isSinglePayload: Bool
+ let isMultiPayload: Bool
+ let hasPayloadCases: Bool
+ }
+
+ static let noPayloadEnumTest = \(raw: noPayloadExpr)
+
+ static let singlePayloadEnumTest = \(raw: singlePayloadExpr)
+
+ static let multiPayloadEnumTest = \(raw: multiPayloadExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("EnumDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for descriptor: EnumDescriptor) -> String {
+ let offset = descriptor.offset
+ let numPayloadCasesAndPayloadSizeOffset = descriptor.layout.numPayloadCasesAndPayloadSizeOffset
+ let numEmptyCases = descriptor.layout.numEmptyCases
+ let flagsRaw = descriptor.layout.flags.rawValue
+ let numberOfCases = descriptor.numberOfCases
+ let numberOfEmptyCases = descriptor.numberOfEmptyCases
+ let numberOfPayloadCases = descriptor.numberOfPayloadCases
+ let payloadSizeOffset = descriptor.payloadSizeOffset
+ let hasPayloadSizeOffset = descriptor.hasPayloadSizeOffset
+ let isSingleEmptyCaseOnly = descriptor.isSingleEmptyCaseOnly
+ let isSinglePayloadCaseOnly = descriptor.isSinglePayloadCaseOnly
+ let isSinglePayload = descriptor.isSinglePayload
+ let isMultiPayload = descriptor.isMultiPayload
+ let hasPayloadCases = descriptor.hasPayloadCases
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumPayloadCasesAndPayloadSizeOffset: \(raw: BaselineEmitter.hex(numPayloadCasesAndPayloadSizeOffset)),
+ layoutNumEmptyCases: \(raw: BaselineEmitter.hex(numEmptyCases)),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw)),
+ numberOfCases: \(literal: numberOfCases),
+ numberOfEmptyCases: \(literal: numberOfEmptyCases),
+ numberOfPayloadCases: \(literal: numberOfPayloadCases),
+ payloadSizeOffset: \(literal: payloadSizeOffset),
+ hasPayloadSizeOffset: \(literal: hasPayloadSizeOffset),
+ isSingleEmptyCaseOnly: \(literal: isSingleEmptyCaseOnly),
+ isSinglePayloadCaseOnly: \(literal: isSinglePayloadCaseOnly),
+ isSinglePayload: \(literal: isSinglePayload),
+ isMultiPayload: \(literal: isMultiPayload),
+ hasPayloadCases: \(literal: hasPayloadCases)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumFunctionsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumFunctionsBaselineGenerator.swift
new file mode 100644
index 00000000..5cf3690c
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumFunctionsBaselineGenerator.swift
@@ -0,0 +1,97 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/EnumFunctionsBaseline.swift`.
+///
+/// `EnumFunctions.swift` declares the value type `EnumTagCounts` (with two
+/// public stored ivars) and one top-level helper function
+/// `getEnumTagCounts(payloadSize:emptyCases:payloadCases:)`.
+///
+/// Top-level free functions do not have an enclosing type, so
+/// `PublicMemberScanner` cannot emit a `MethodKey` for them; they are
+/// covered indirectly by the consumers that exercise the helper. The
+/// registered set therefore captures only `EnumTagCounts.numTags` and
+/// `EnumTagCounts.numTagBytes`.
+///
+/// We compute the baseline via a deterministic input set so the literal is
+/// reader-independent — `getEnumTagCounts` is a pure function with no
+/// MachO dependency.
+package enum EnumFunctionsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public ivars declared on EnumTagCounts in EnumFunctions.swift.
+ let registered = [
+ "numTagBytes",
+ "numTags",
+ ]
+
+ // Pure-function baseline: we evaluate `getEnumTagCounts` against a
+ // small set of inputs covering each branch (no empty cases,
+ // payload < 4 bytes, payload >= 4 bytes, large numTags) so the
+ // companion Suite can re-evaluate and assert literal equality.
+ let counts = [
+ // (payloadSize, emptyCases, payloadCases)
+ (UInt64(0), UInt32(0), UInt32(0)),
+ (UInt64(0), UInt32(4), UInt32(0)), // small payload, emptyCases > 0
+ (UInt64(1), UInt32(256), UInt32(1)), // payload 1, casesPerTagBitValue path
+ (UInt64(4), UInt32(1), UInt32(2)), // payload >= 4, +1 path
+ (UInt64(8), UInt32(65536), UInt32(0)), // large numTags → 4-byte tag bytes
+ ]
+ let entries: [(input: (UInt64, UInt32, UInt32), output: EnumTagCounts)] = counts.map { input in
+ let output = getEnumTagCounts(payloadSize: input.0, emptyCases: input.1, payloadCases: input.2)
+ return (input: input, output: output)
+ }
+ let entriesExpr = emitEntriesExpr(for: entries)
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // EnumFunctions baselines are reader-independent: the helper
+ // `getEnumTagCounts` is a pure function. The Suite asserts literal
+ // equality against the cases below.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum EnumFunctionsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let payloadSize: UInt64
+ let emptyCases: UInt32
+ let payloadCases: UInt32
+ let numTags: UInt32
+ let numTagBytes: UInt32
+ }
+
+ static let cases: [Entry] = \(raw: entriesExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("EnumFunctionsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntriesExpr(
+ for entries: [(input: (UInt64, UInt32, UInt32), output: EnumTagCounts)]
+ ) -> String {
+ let lines = entries.map { entry -> String in
+ let (payloadSize, emptyCases, payloadCases) = entry.input
+ return """
+ Entry(
+ payloadSize: \(BaselineEmitter.hex(payloadSize)),
+ emptyCases: \(BaselineEmitter.hex(emptyCases)),
+ payloadCases: \(BaselineEmitter.hex(payloadCases)),
+ numTags: \(BaselineEmitter.hex(entry.output.numTags)),
+ numTagBytes: \(BaselineEmitter.hex(entry.output.numTagBytes))
+ )
+ """
+ }
+ return "[\n\(lines.joined(separator: ",\n"))\n]"
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..a2fb8674
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumMetadataBaselineGenerator.swift
@@ -0,0 +1,46 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/EnumMetadataBaseline.swift`.
+///
+/// Like the `StructMetadata` / `ClassMetadata` baselines, this generator
+/// does NOT consume the MachOFile fixture: `EnumMetadata` instances can
+/// only be obtained by invoking the metadata accessor function from a
+/// *loaded* MachOImage in the current process. Encoding live pointer
+/// values in a literal would not be stable across runs, so the Suite
+/// tests cover correctness via cross-reader equality at runtime instead.
+package enum EnumMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in EnumMetadata.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // EnumMetadata can only be materialized via MachOImage's accessor
+ // function at runtime; live pointer values are not embedded here.
+ // The companion Suite (EnumMetadataTests) relies on cross-reader
+ // equality between (MachOImage, fileContext, imageContext,
+ // inProcess) for correctness.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum EnumMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("EnumMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumMetadataProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumMetadataProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..76f256bd
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/EnumMetadataProtocolBaselineGenerator.swift
@@ -0,0 +1,46 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/EnumMetadataProtocolBaseline.swift`.
+///
+/// Like `StructMetadataProtocolBaselineGenerator`, this only emits the
+/// registered member names. The protocol's `enumDescriptor`/`payloadSize`
+/// methods all require a live `EnumMetadata` instance, which is only
+/// reachable through MachOImage at runtime. Cross-reader equality
+/// assertions in the companion Suite (EnumMetadataProtocolTests) cover
+/// correctness.
+package enum EnumMetadataProtocolBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in EnumMetadataProtocol.swift.
+ // Both `enumDescriptor` and `payloadSize` have multiple overloads
+ // (MachO/InProcess/ReadingContext) — they collapse to single
+ // MethodKey entries via PublicMemberScanner's name-only key.
+ let registered = [
+ "enumDescriptor",
+ "payloadSize",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live EnumMetadata pointers cannot be embedded as literals; the
+ // companion Suite (EnumMetadataProtocolTests) verifies the methods
+ // produce cross-reader-consistent results at runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum EnumMetadataProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("EnumMetadataProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Enum/MultiPayloadEnumDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/MultiPayloadEnumDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..ae196e7b
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Enum/MultiPayloadEnumDescriptorBaselineGenerator.swift
@@ -0,0 +1,135 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/MultiPayloadEnumDescriptorBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `MultiPayloadEnumDescriptor` lives in the `__swift5_mpenum` section and
+/// carries variable-length spare-bit metadata for multi-payload enums. The
+/// descriptor's public surface mixes:
+/// - `offset` / `layout` ivars (the `init(layout:offset:)` initializer is
+/// filtered as memberwise-synthesized)
+/// - method overloads that resolve runtime data (`mangledTypeName`,
+/// `contents`, `payloadSpareBits`, `payloadSpareBitMaskByteOffset`,
+/// `payloadSpareBitMaskByteCount` — each appears in three flavors:
+/// MachO + InProcess + ReadingContext, all collapsing to one MethodKey)
+/// - derived bit-twiddling accessors (`contentsSizeInWord`, `flags`,
+/// `usesPayloadSpareBits`, the index family, and the
+/// `TopLevelDescriptor` conformance's `actualSize`)
+///
+/// We use the multi-payload picker (`Enums.MultiPayloadEnumTests`) which
+/// has 4 cases, 3 of them with payloads — a canonical multi-payload
+/// descriptor.
+package enum MultiPayloadEnumDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.multiPayloadEnumDescriptor_MultiPayloadEnumTest(in: machO)
+
+ let multiPayloadExpr = try emitEntryExpr(for: descriptor, in: machO)
+
+ // Members directly declared in MultiPayloadEnumDescriptor.swift
+ // (across the main body and three same-file extensions, plus the
+ // `TopLevelDescriptor` extension carrying `actualSize`). Method
+ // overloads (MachO + InProcess + ReadingContext) collapse to a
+ // single MethodKey under the scanner's name-based deduplication.
+ let registered = [
+ "actualSize",
+ "contents",
+ "contentsSizeInWord",
+ "flags",
+ "layout",
+ "mangledTypeName",
+ "offset",
+ "payloadSpareBitMaskByteCount",
+ "payloadSpareBitMaskByteCountIndex",
+ "payloadSpareBitMaskByteOffset",
+ "payloadSpareBits",
+ "payloadSpareBitsIndex",
+ "sizeFlagsIndex",
+ "usesPayloadSpareBits",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MultiPayloadEnumDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutSizeFlags: UInt32
+ let mangledTypeNameRawString: String
+ let contentsSizeInWord: UInt32
+ let flags: UInt32
+ let usesPayloadSpareBits: Bool
+ let sizeFlagsIndex: Int
+ let payloadSpareBitMaskByteCountIndex: Int
+ let payloadSpareBitsIndex: Int
+ let actualSize: Int
+ let contentsCount: Int
+ let payloadSpareBitsCount: Int
+ let payloadSpareBitMaskByteOffset: UInt32
+ let payloadSpareBitMaskByteCount: UInt32
+ }
+
+ static let multiPayloadEnumTest = \(raw: multiPayloadExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MultiPayloadEnumDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for descriptor: MultiPayloadEnumDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let offset = descriptor.offset
+ let layoutSizeFlags = descriptor.layout.sizeFlags
+ let mangledTypeName = try descriptor.mangledTypeName(in: machO)
+ let mangledTypeNameRawString = mangledTypeName.rawString
+ let contentsSizeInWord = descriptor.contentsSizeInWord
+ let flags = descriptor.flags
+ let usesPayloadSpareBits = descriptor.usesPayloadSpareBits
+ let sizeFlagsIndex = descriptor.sizeFlagsIndex
+ let payloadSpareBitMaskByteCountIndex = descriptor.payloadSpareBitMaskByteCountIndex
+ let payloadSpareBitsIndex = descriptor.payloadSpareBitsIndex
+ let actualSize = descriptor.actualSize
+ let contentsCount = try descriptor.contents(in: machO).count
+ let payloadSpareBitsCount = try descriptor.payloadSpareBits(in: machO).count
+ let payloadSpareBitMaskByteOffset = try descriptor.payloadSpareBitMaskByteOffset(in: machO)
+ let payloadSpareBitMaskByteCount = try descriptor.payloadSpareBitMaskByteCount(in: machO)
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutSizeFlags: \(raw: BaselineEmitter.hex(layoutSizeFlags)),
+ mangledTypeNameRawString: \(literal: mangledTypeNameRawString),
+ contentsSizeInWord: \(raw: BaselineEmitter.hex(contentsSizeInWord)),
+ flags: \(raw: BaselineEmitter.hex(flags)),
+ usesPayloadSpareBits: \(literal: usesPayloadSpareBits),
+ sizeFlagsIndex: \(literal: sizeFlagsIndex),
+ payloadSpareBitMaskByteCountIndex: \(literal: payloadSpareBitMaskByteCountIndex),
+ payloadSpareBitsIndex: \(literal: payloadSpareBitsIndex),
+ actualSize: \(literal: actualSize),
+ contentsCount: \(literal: contentsCount),
+ payloadSpareBitsCount: \(literal: payloadSpareBitsCount),
+ payloadSpareBitMaskByteOffset: \(raw: BaselineEmitter.hex(payloadSpareBitMaskByteOffset)),
+ payloadSpareBitMaskByteCount: \(raw: BaselineEmitter.hex(payloadSpareBitMaskByteCount))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExistentialMetatypeMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExistentialMetatypeMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..b21e91ec
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExistentialMetatypeMetadataBaselineGenerator.swift
@@ -0,0 +1,57 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ExistentialMetatypeMetadataBaseline.swift`.
+///
+/// Phase C3: emits ABI literals derived from in-process resolution of
+/// `Any.Type.self`'s `ExistentialMetatypeMetadata`. The kind raw value
+/// matches `MetadataKind.existentialMetatype` (0x306); `instanceType`
+/// points to `Any.self`'s metadata; `flags` mirrors `Any.self`'s
+/// existential flags into the metatype layout.
+///
+/// Registered names track the wrapper's directly-declared public surface
+/// (`layout`, `offset`); the layout subfields (`kind`, `instanceType`,
+/// `flags`) are exercised inside the `layout` test body.
+package enum ExistentialMetatypeMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let context = InProcessContext()
+ let metadata = try ExistentialMetatypeMetadata.resolve(
+ at: InProcessMetadataPicker.stdlibAnyMetatype,
+ in: context
+ )
+ let kindRaw = metadata.kind.rawValue
+ let flagsRaw = metadata.layout.flags.rawValue
+
+ let registered = ["layout", "offset"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess `Any.Type.self`; no Mach-O section presence.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ExistentialMetatypeMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let kindRawValue: UInt32
+ let flagsRawValue: UInt32
+ }
+
+ static let stdlibAnyMetatype = Entry(
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRaw)),
+ flagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ExistentialMetatypeMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExistentialTypeFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExistentialTypeFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..f2ec4534
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExistentialTypeFlagsBaselineGenerator.swift
@@ -0,0 +1,88 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ExistentialTypeFlagsBaseline.swift`.
+///
+/// Phase C3: emits ABI literals derived from in-process resolution of
+/// stdlib existential metadata flags. Two metadata sources:
+/// - `Any.self` flags (`0x80000000`) — `numberOfWitnessTables`,
+/// `hasSuperclassConstraint`, `specialProtocol`, `rawValue`.
+/// - `AnyObject.self` flags (`0x0`) — `classConstraint`. Required
+/// because `Any.self`'s flags trap the source's
+/// `UInt8(rawValue & 0x80000000)` accessor.
+package enum ExistentialTypeFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let context = InProcessContext()
+
+ let anyMetadata = try ExistentialTypeMetadata.resolve(
+ at: InProcessMetadataPicker.stdlibAnyExistential,
+ in: context
+ )
+ let anyFlags = anyMetadata.layout.flags
+ let anyRawValue = anyFlags.rawValue
+ let anyNumberOfWitnessTables = anyFlags.numberOfWitnessTables
+ let anyHasSuperclassConstraint = anyFlags.hasSuperclassConstraint
+ let anySpecialProtocolRaw = anyFlags.specialProtocol.rawValue
+
+ let anyObjectMetadata = try ExistentialTypeMetadata.resolve(
+ at: InProcessMetadataPicker.stdlibAnyObjectExistential,
+ in: context
+ )
+ let anyObjectFlags = anyObjectMetadata.layout.flags
+ let anyObjectRawValue = anyObjectFlags.rawValue
+ let anyObjectClassConstraintRaw = anyObjectFlags.classConstraint.rawValue
+
+ let registered = [
+ "classConstraint",
+ "hasSuperclassConstraint",
+ "init(rawValue:)",
+ "numberOfWitnessTables",
+ "rawValue",
+ "specialProtocol",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess (`Any.self` + `AnyObject.self`); no Mach-O section presence.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ExistentialTypeFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct AnyEntry {
+ let rawValue: UInt32
+ let numberOfWitnessTables: UInt32
+ let hasSuperclassConstraint: Bool
+ let specialProtocolRawValue: UInt8
+ }
+
+ struct AnyObjectEntry {
+ let rawValue: UInt32
+ let classConstraintRawValue: UInt8
+ }
+
+ static let stdlibAnyExistential = AnyEntry(
+ rawValue: \(raw: BaselineEmitter.hex(anyRawValue)),
+ numberOfWitnessTables: \(raw: BaselineEmitter.hex(anyNumberOfWitnessTables)),
+ hasSuperclassConstraint: \(literal: anyHasSuperclassConstraint),
+ specialProtocolRawValue: \(raw: BaselineEmitter.hex(anySpecialProtocolRaw))
+ )
+
+ static let stdlibAnyObjectExistential = AnyObjectEntry(
+ rawValue: \(raw: BaselineEmitter.hex(anyObjectRawValue)),
+ classConstraintRawValue: \(raw: BaselineEmitter.hex(anyObjectClassConstraintRaw))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ExistentialTypeFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExistentialTypeMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExistentialTypeMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..b65e85f2
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExistentialTypeMetadataBaselineGenerator.swift
@@ -0,0 +1,93 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ExistentialTypeMetadataBaseline.swift`.
+///
+/// Phase C3: emits ABI literals derived from in-process resolution of two
+/// stdlib existential metadata sources:
+/// - `Any.self` — maximally-general existential, kind 0x303, flags
+/// `0x80000000` (`classConstraint == .any`), zero protocols. Anchors
+/// `layout`, `offset`, `numberOfProtocols`, `superclassConstraint`,
+/// `protocols`.
+/// - `AnyObject.self` — class-bounded existential with zero witness
+/// tables (flags `0x0`). Required for `isClassBounded` / `isObjC` /
+/// `representation` because `Any.self`'s flags decode to a value that
+/// traps the source's `UInt8(rawValue & 0x80000000)` accessor.
+///
+/// Registered names track the wrapper's directly-declared public surface
+/// (`layout`, `offset`, `isClassBounded`, `isObjC`, `representation`,
+/// `superclassConstraint`, `protocols`).
+package enum ExistentialTypeMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let context = InProcessContext()
+
+ let anyMetadata = try ExistentialTypeMetadata.resolve(
+ at: InProcessMetadataPicker.stdlibAnyExistential,
+ in: context
+ )
+ let anyKindRaw = anyMetadata.kind.rawValue
+ let anyFlagsRaw = anyMetadata.layout.flags.rawValue
+ let anyNumProtocols = anyMetadata.layout.numberOfProtocols
+
+ let anyObjectMetadata = try ExistentialTypeMetadata.resolve(
+ at: InProcessMetadataPicker.stdlibAnyObjectExistential,
+ in: context
+ )
+ let anyObjectIsClassBounded = anyObjectMetadata.isClassBounded
+ let anyObjectIsObjC = anyObjectMetadata.isObjC
+
+ let registered = [
+ "isClassBounded",
+ "isObjC",
+ "layout",
+ "offset",
+ "protocols",
+ "representation",
+ "superclassConstraint",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess (`Any.self` + `AnyObject.self`); no Mach-O section presence.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ExistentialTypeMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let kindRawValue: UInt32
+ let flagsRawValue: UInt32
+ let numberOfProtocols: UInt32
+ let isClassBounded: Bool
+ let isObjC: Bool
+ }
+
+ static let stdlibAnyExistential = Entry(
+ kindRawValue: \(raw: BaselineEmitter.hex(anyKindRaw)),
+ flagsRawValue: \(raw: BaselineEmitter.hex(anyFlagsRaw)),
+ numberOfProtocols: \(raw: BaselineEmitter.hex(anyNumProtocols)),
+ isClassBounded: false,
+ isObjC: false
+ )
+
+ static let stdlibAnyObjectExistential = Entry(
+ kindRawValue: \(raw: BaselineEmitter.hex(anyObjectMetadata.kind.rawValue)),
+ flagsRawValue: \(raw: BaselineEmitter.hex(anyObjectMetadata.layout.flags.rawValue)),
+ numberOfProtocols: \(raw: BaselineEmitter.hex(anyObjectMetadata.layout.numberOfProtocols)),
+ isClassBounded: \(literal: anyObjectIsClassBounded),
+ isObjC: \(literal: anyObjectIsObjC)
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ExistentialTypeMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExtendedExistentialTypeMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExtendedExistentialTypeMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..3dd7105a
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExtendedExistentialTypeMetadataBaselineGenerator.swift
@@ -0,0 +1,61 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ExtendedExistentialTypeMetadataBaseline.swift`.
+///
+/// Phase C3: emits ABI literals derived from in-process resolution of
+/// `(any Sequence).self`'s `ExtendedExistentialTypeMetadata`. Kind
+/// raw value matches `MetadataKind.extendedExistential` (0x307). The
+/// `shape` field is a pointer to the runtime-allocated
+/// `ExtendedExistentialTypeShape` for `(any Sequence)`. The shape
+/// pointer's address may carry an in-process tag bit which the runtime
+/// strips during resolution; we record the post-strip address here.
+///
+/// Registered names track the wrapper's directly-declared public surface
+/// (`layout`, `offset`); the layout subfields (`kind`, `shape`) are
+/// exercised inside the `layout` test body.
+@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
+package enum ExtendedExistentialTypeMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let context = InProcessContext()
+ let metadata = try ExtendedExistentialTypeMetadata.resolve(
+ at: InProcessMetadataPicker.stdlibAnyEquatable,
+ in: context
+ )
+ let kindRaw = metadata.kind.rawValue
+
+ let registered = ["layout", "offset"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess `(any Sequence).self`; no Mach-O section presence.
+ //
+ // Note: the shape pointer's address is non-deterministic across
+ // process invocations (runtime allocates lazily on first access).
+ // Tests assert `shape.address != 0` rather than pinning a literal.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ExtendedExistentialTypeMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let kindRawValue: UInt32
+ }
+
+ static let stdlibAnyEquatable = Entry(
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRaw))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ExtendedExistentialTypeMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExtendedExistentialTypeShapeBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExtendedExistentialTypeShapeBaselineGenerator.swift
new file mode 100644
index 00000000..4a9a3e31
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExtendedExistentialTypeShapeBaselineGenerator.swift
@@ -0,0 +1,69 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ExtendedExistentialTypeShapeBaseline.swift`.
+///
+/// Phase C3: emits ABI literals derived from in-process resolution of
+/// the shape pointer of `(any Sequence).self`'s
+/// `ExtendedExistentialTypeMetadata`. The shape's `flags` raw value
+/// encodes the special-kind / has-generalization / has-type-expression /
+/// has-suggested-witnesses / has-implicit-generic-params bits. Its
+/// `requirementSignatureHeader` carries `numParams`/`numRequirements` for
+/// the parameterized protocol (Sequence has primary associated type
+/// Element, which contributes one parameter and a same-type requirement
+/// fixing it to `Int`).
+///
+/// Registered names track the wrapper's directly-declared public surface
+/// (`existentialType`, `layout`, `offset`); the layout subfields (`flags`,
+/// `requirementSignatureHeader`) are exercised inside the `layout` test
+/// body. The shape's runtime address is non-deterministic so `offset` is
+/// asserted only as non-zero.
+@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
+package enum ExtendedExistentialTypeShapeBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let context = InProcessContext()
+ let metadata = try ExtendedExistentialTypeMetadata.resolve(
+ at: InProcessMetadataPicker.stdlibAnyEquatable,
+ in: context
+ )
+ let shape = try metadata.layout.shape.resolve(in: context)
+ let flagsRaw = shape.layout.flags.rawValue
+ let numParams = shape.layout.requirementSignatureHeader.numParams
+
+ let registered = [
+ "existentialType",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess shape of `(any Sequence).self`; no Mach-O section presence.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ExtendedExistentialTypeShapeBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let flagsRawValue: UInt32
+ let requirementSignatureNumParams: UInt16
+ }
+
+ static let equatableShape = Entry(
+ flagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw)),
+ requirementSignatureNumParams: \(raw: BaselineEmitter.hex(numParams))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ExtendedExistentialTypeShapeBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExtendedExistentialTypeShapeFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExtendedExistentialTypeShapeFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..b40a4bb3
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/ExtendedExistentialTypeShapeFlagsBaselineGenerator.swift
@@ -0,0 +1,57 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ExtendedExistentialTypeShapeFlagsBaseline.swift`.
+///
+/// Phase C3: emits ABI literals derived from in-process resolution of the
+/// shape flags of `(any Sequence).self`. Currently `OptionSet`
+/// boilerplate (`init(rawValue:)` and `rawValue`); the test round-trips
+/// through both. The raw value reflects the special-kind /
+/// has-generalization-signature / has-type-expression /
+/// has-suggested-witnesses / has-implicit-generic-params bits set by
+/// the runtime for `(any Sequence)`.
+@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
+package enum ExtendedExistentialTypeShapeFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let context = InProcessContext()
+ let metadata = try ExtendedExistentialTypeMetadata.resolve(
+ at: InProcessMetadataPicker.stdlibAnyEquatable,
+ in: context
+ )
+ let shape = try metadata.layout.shape.resolve(in: context)
+ let rawValue = shape.layout.flags.rawValue
+
+ let registered = [
+ "init(rawValue:)",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess shape of `(any Sequence).self`; no Mach-O section presence.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ExtendedExistentialTypeShapeFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt32
+ }
+
+ static let equatableShape = Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ExtendedExistentialTypeShapeFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/NonUniqueExtendedExistentialTypeShapeBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/NonUniqueExtendedExistentialTypeShapeBaselineGenerator.swift
new file mode 100644
index 00000000..1fe14758
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ExistentialType/NonUniqueExtendedExistentialTypeShapeBaselineGenerator.swift
@@ -0,0 +1,52 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/NonUniqueExtendedExistentialTypeShapeBaseline.swift`.
+///
+/// `NonUniqueExtendedExistentialTypeShape` is the non-unique variant of
+/// `ExtendedExistentialTypeShape`, emitted statically by the compiler
+/// before runtime deduplication. Once the runtime uniques shapes,
+/// `ExtendedExistentialTypeMetadata.shape` always points at the unique
+/// form — so the non-unique form is not reachable through
+/// `InProcessMetadataPicker`. `SymbolTestsCore` doesn't currently emit a
+/// non-unique shape statically either. The Suite stays sentinel and
+/// asserts structural members behave correctly against a synthetic
+/// memberwise instance.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum NonUniqueExtendedExistentialTypeShapeBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in
+ // NonUniqueExtendedExistentialTypeShape.swift. The three
+ // `existentialType` overloads collapse to one MethodKey under
+ // PublicMemberScanner's name-only key.
+ let registered = [
+ "existentialType",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: sentinel — non-unique shape only reachable from compiler-emitted
+ // static records before runtime dedup; runtime metadata always points at
+ // the unique form. SymbolTestsCore doesn't currently emit one statically.
+ //
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum NonUniqueExtendedExistentialTypeShapeBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("NonUniqueExtendedExistentialTypeShapeBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ExtensionContextBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ExtensionContextBaselineGenerator.swift
new file mode 100644
index 00000000..a6bbed3e
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ExtensionContextBaselineGenerator.swift
@@ -0,0 +1,78 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ExtensionContextBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `ExtensionContext` is the high-level wrapper around an
+/// `ExtensionContextDescriptor`. Beyond the descriptor itself, it pulls in
+/// `genericContext` and `extendedContextMangledName` (both `Optional`).
+/// The optional payloads aren't stable Swift literals, so the `Entry`
+/// records only presence flags.
+package enum ExtensionContextBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.extension_first(in: machO)
+ let context = try ExtensionContext(descriptor: descriptor, in: machO)
+
+ let entryExpr = emitEntryExpr(for: context)
+
+ // Public members declared directly in ExtensionContext.swift.
+ // Both `init(descriptor:in:)` overloads (MachO + ReadingContext)
+ // collapse to a single MethodKey under PublicMemberScanner's
+ // name-based deduplication.
+ let registered = [
+ "descriptor",
+ "extendedContextMangledName",
+ "genericContext",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ExtensionContextBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let hasGenericContext: Bool
+ let hasExtendedContextMangledName: Bool
+ }
+
+ static let firstExtension = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ExtensionContextBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for instance: ExtensionContext) -> String {
+ let descriptorOffset = instance.descriptor.offset
+ let hasGenericContext = instance.genericContext != nil
+ let hasExtendedContextMangledName = instance.extendedContextMangledName != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ hasGenericContext: \(literal: hasGenericContext),
+ hasExtendedContextMangledName: \(literal: hasExtendedContextMangledName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ExtensionContextDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ExtensionContextDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..0e1c0389
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ExtensionContextDescriptorBaselineGenerator.swift
@@ -0,0 +1,70 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ExtensionContextDescriptorBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `ExtensionContextDescriptor` declares only the `offset` and `layout`
+/// ivars (`init(layout:offset:)` is filtered as memberwise-synthesized).
+/// The protocol-extension `extendedContext(in:)` family of methods is
+/// attributed to `ExtensionContextDescriptorProtocol` by
+/// `PublicMemberScanner` (see the protocol-extension attribution rule in
+/// `BaselineGenerator.swift`); its baseline/Suite live separately.
+package enum ExtensionContextDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.extension_first(in: machO)
+ let entryExpr = emitEntryExpr(for: descriptor)
+
+ // Public members declared directly in ExtensionContextDescriptor.swift.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ExtensionContextDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutFlagsRawValue: UInt32
+ }
+
+ static let firstExtension = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ExtensionContextDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for descriptor: ExtensionContextDescriptor
+ ) -> String {
+ let offset = descriptor.offset
+ let flagsRaw = descriptor.layout.flags.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ExtensionContextDescriptorProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ExtensionContextDescriptorProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..a6879b24
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ExtensionContextDescriptorProtocolBaselineGenerator.swift
@@ -0,0 +1,77 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ExtensionContextDescriptorProtocolBaseline.swift`.
+///
+/// `extendedContext(in:)` is declared in
+/// `Extension/ExtensionContextDescriptor.swift` as a protocol-extension
+/// method on `ExtensionContextDescriptorProtocol`. `PublicMemberScanner`
+/// attributes it to the extended protocol (see the protocol-extension
+/// attribution rule in `BaselineGenerator.swift`), so the Suite/baseline
+/// for this method lives here, not on `ExtensionContextDescriptor`.
+///
+/// The three `extendedContext(in:)` overloads (MachO / InProcess /
+/// ReadingContext) collapse to a single MethodKey via PublicMemberScanner's
+/// name-only key. The `MangledName` payload is a deep ABI tree we don't
+/// embed as a literal; instead we record presence as a flag so the
+/// companion Suite (ExtensionContextDescriptorProtocolTests) can verify
+/// cross-reader-consistent results.
+package enum ExtensionContextDescriptorProtocolBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.extension_first(in: machO)
+ let hasExtendedContext = (try descriptor.extendedContext(in: machO)) != nil
+ let entryExpr = emitEntryExpr(hasExtendedContext: hasExtendedContext)
+
+ // Public members declared in protocol extensions on
+ // `ExtensionContextDescriptorProtocol`. The three
+ // `extendedContext(in:)` overloads collapse to a single MethodKey
+ // via PublicMemberScanner's name-only key.
+ let registered = [
+ "extendedContext",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // The MangledName payload returned by `extendedContext(in:)` is a
+ // deep ABI tree we don't embed as a literal; the companion Suite
+ // (ExtensionContextDescriptorProtocolTests) verifies the methods
+ // produce cross-reader-consistent results at runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ExtensionContextDescriptorProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let hasExtendedContext: Bool
+ }
+
+ static let firstExtension = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ExtensionContextDescriptorProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(hasExtendedContext: Bool) -> String {
+ let expr: ExprSyntax = """
+ Entry(
+ hasExtendedContext: \(literal: hasExtendedContext)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/FieldDescriptor/FieldDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/FieldDescriptor/FieldDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..cf88e3d7
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/FieldDescriptor/FieldDescriptorBaselineGenerator.swift
@@ -0,0 +1,116 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/FieldDescriptorBaseline.swift`.
+///
+/// `FieldDescriptor` describes the per-type field-layout payload referenced
+/// from a `TypeContextDescriptor` (and resolved via
+/// `TypeContextDescriptorProtocol.fieldDescriptor(in:)`). Beyond the layout
+/// trio (`offset`, `layout`, `init(layout:offset:)` — the synthesized
+/// initializer is filtered) it carries one derived var (`kind`) and two
+/// reader methods (`mangledTypeName(in:)`, `records(in:)`) plus their
+/// in-process and ReadingContext overloads.
+///
+/// Picker variants:
+/// - `GenericStructNonRequirement` — three concrete fields
+/// (`field1: Double`, `field2: A`, `field3: Int`). Exercises the
+/// non-trivial records-array branch.
+/// - `StructTest` — zero stored properties (the public `body` is a
+/// computed property, which doesn't surface in the field descriptor).
+/// Exercises the empty-records-array branch.
+///
+/// We pin: descriptor offset, kind raw value, records count, and the
+/// per-field count of mangled-name / field-name pairs (recorded in
+/// the FieldRecord Suite separately; here we just record the count).
+package enum FieldDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let genericDescriptor = try BaselineFixturePicker.struct_GenericStructNonRequirement(in: machO)
+ let genericFieldDescriptor = try required(try genericDescriptor.fieldDescriptor(in: machO))
+
+ let structTestDescriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let structTestFieldDescriptor = try required(try structTestDescriptor.fieldDescriptor(in: machO))
+
+ let genericExpr = try emitEntryExpr(for: genericFieldDescriptor, in: machO)
+ let structTestExpr = try emitEntryExpr(for: structTestFieldDescriptor, in: machO)
+
+ // Public members declared directly in FieldDescriptor.swift (across
+ // the body and three same-file extensions: MachO + InProcess +
+ // ReadingContext). Overload triples collapse to single MethodKey
+ // entries under the scanner's name-based deduplication.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "kind",
+ "layout",
+ "mangledTypeName",
+ "offset",
+ "records",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live MangledName payloads aren't embedded as literals; the
+ // companion Suite (FieldDescriptorTests) verifies the methods
+ // produce cross-reader-consistent results at runtime against the
+ // presence flags / counts recorded here.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum FieldDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let kindRawValue: UInt16
+ let layoutNumFields: Int
+ let layoutFieldRecordSize: Int
+ let recordsCount: Int
+ let hasMangledTypeName: Bool
+ }
+
+ static let genericStructNonRequirement = \(raw: genericExpr)
+
+ static let structTest = \(raw: structTestExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("FieldDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for descriptor: FieldDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let offset = descriptor.offset
+ let kindRawValue = descriptor.layout.kind
+ let layoutNumFields = Int(descriptor.layout.numFields)
+ let layoutFieldRecordSize = Int(descriptor.layout.fieldRecordSize)
+ let records = try descriptor.records(in: machO)
+ let recordsCount = records.count
+ let hasMangledTypeName = (try? descriptor.mangledTypeName(in: machO)) != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRawValue)),
+ layoutNumFields: \(literal: layoutNumFields),
+ layoutFieldRecordSize: \(literal: layoutFieldRecordSize),
+ recordsCount: \(literal: recordsCount),
+ hasMangledTypeName: \(literal: hasMangledTypeName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/FieldRecord/FieldRecordBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/FieldRecord/FieldRecordBaselineGenerator.swift
new file mode 100644
index 00000000..f3a92abd
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/FieldRecord/FieldRecordBaselineGenerator.swift
@@ -0,0 +1,101 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/FieldRecordBaseline.swift`.
+///
+/// `FieldRecord` describes a single field declared by a Swift type — its
+/// `RelativeDirectPointer` to the field's type and a
+/// `RelativeDirectPointer` to its source name. Beyond the layout
+/// trio (`offset`, `layout`, `init(layout:offset:)` — synthesized initializer
+/// is filtered) it carries two reader methods (`mangledTypeName(in:)` and
+/// `fieldName(in:)`) plus their in-process and ReadingContext overloads.
+///
+/// Picker: `GenericStructNonRequirement`'s field descriptor surfaces
+/// three records (`field1`, `field2`, `field3`). We pin the first two
+/// to exercise both a concrete-type field (`field1: Double`) and a
+/// generic-parameter field (`field2: A`).
+package enum FieldRecordBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_GenericStructNonRequirement(in: machO)
+ let fieldDescriptor = try required(try descriptor.fieldDescriptor(in: machO))
+ let records = try fieldDescriptor.records(in: machO)
+
+ let firstRecord = try required(records.first)
+ let secondRecord = try required(records.dropFirst().first)
+
+ let firstExpr = try emitEntryExpr(for: firstRecord, in: machO)
+ let secondExpr = try emitEntryExpr(for: secondRecord, in: machO)
+
+ // Public members declared directly in FieldRecord.swift (across the
+ // body and three same-file extensions: MachO + InProcess +
+ // ReadingContext). Overload triples collapse to single MethodKey
+ // entries under the scanner's name-based deduplication.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "fieldName",
+ "layout",
+ "mangledTypeName",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live MangledName payloads aren't embedded as literals; the
+ // companion Suite (FieldRecordTests) verifies the methods produce
+ // cross-reader-consistent results at runtime against the field
+ // names / presence flags recorded here.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum FieldRecordBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutFlagsRawValue: UInt32
+ let fieldName: String
+ let hasMangledTypeName: Bool
+ }
+
+ static let firstRecord = \(raw: firstExpr)
+
+ static let secondRecord = \(raw: secondExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("FieldRecordBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for record: FieldRecord,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let offset = record.offset
+ let layoutFlagsRawValue = record.layout.flags.rawValue
+ let fieldName = try record.fieldName(in: machO)
+ let hasMangledTypeName = (try? record.mangledTypeName(in: machO)) != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(layoutFlagsRawValue)),
+ fieldName: \(literal: fieldName),
+ hasMangledTypeName: \(literal: hasMangledTypeName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/FieldRecord/FieldRecordFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/FieldRecord/FieldRecordFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..cdc6cb3f
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/FieldRecord/FieldRecordFlagsBaselineGenerator.swift
@@ -0,0 +1,95 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/FieldRecordFlagsBaseline.swift`.
+///
+/// `FieldRecordFlags` is a 32-bit `OptionSet` carried in every
+/// `FieldRecord`'s leading `flags` field. It declares three orthogonal
+/// option bits:
+/// - `0x1` — `isIndirectCase`
+/// - `0x2` — `isVariadic`
+/// - `0x4` — `isArtificial`
+/// The static `let`s collapse with their same-named OptionSet membership
+/// checks under PublicMemberScanner's name-only key.
+///
+/// The baseline embeds canonical synthetic raw values exercising each
+/// branch plus combinations.
+package enum FieldRecordFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let empty = emitEntryExpr(rawValue: 0x0)
+ let isIndirectCase = emitEntryExpr(rawValue: 0x1)
+ let isVariadic = emitEntryExpr(rawValue: 0x2)
+ let isArtificial = emitEntryExpr(rawValue: 0x4)
+ let allBits = emitEntryExpr(rawValue: 0x7)
+
+ // Public members declared directly in FieldRecordFlags.swift.
+ let registered = [
+ "init(rawValue:)",
+ "isArtificial",
+ "isIndirectCase",
+ "isVariadic",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // FieldRecordFlags is exercised against synthetic raw values
+ // covering each option bit (isIndirectCase / isVariadic /
+ // isArtificial) plus the empty and all-bits combinations. Live
+ // carriers are also exercised by the FieldRecord Suite's
+ // per-fixture readings (the SymbolTestsCore fixture's records
+ // all carry flags == 0x0).
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum FieldRecordFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt32
+ let isIndirectCase: Bool
+ let isVariadic: Bool
+ let isArtificial: Bool
+ }
+
+ static let empty = \(raw: empty)
+
+ static let isIndirectCase = \(raw: isIndirectCase)
+
+ static let isVariadic = \(raw: isVariadic)
+
+ static let isArtificial = \(raw: isArtificial)
+
+ static let allBits = \(raw: allBits)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("FieldRecordFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(rawValue: UInt32) -> String {
+ let flags = FieldRecordFlags(rawValue: rawValue)
+ let isIndirectCase = flags.contains(.isIndirectCase)
+ let isVariadic = flags.contains(.isVariadic)
+ let isArtificial = flags.contains(.isArtificial)
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ isIndirectCase: \(literal: isIndirectCase),
+ isVariadic: \(literal: isVariadic),
+ isArtificial: \(literal: isArtificial)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ForeignType/ForeignClassMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ForeignType/ForeignClassMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..a042489f
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ForeignType/ForeignClassMetadataBaselineGenerator.swift
@@ -0,0 +1,68 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ForeignClassMetadataBaseline.swift`.
+///
+/// Phase B6: `ForeignClassMetadata` is exercised as a real InProcess
+/// test against `CFString.self` — the Swift compiler emits kind 0x203
+/// foreign-class metadata for CoreFoundation types imported into Swift.
+/// SymbolTestsCore's `ForeignTypeFixtures` references CFString /
+/// CFArray to make the bridging usage visible at the fixture level,
+/// but the canonical `ForeignClassMetadata` carrier is CoreFoundation's
+/// own metadata which the runtime returns via
+/// `unsafeBitCast(CFString.self, ...)`.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum ForeignClassMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let pointer = InProcessMetadataPicker.coreFoundationCFString
+ let context = InProcessContext()
+ let metadata = try ForeignClassMetadata.resolve(at: pointer, in: context)
+ let kindRaw = metadata.layout.kind
+
+ let registered = [
+ "classDescriptor",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess (`CoreFoundation.CFString.self`); no SymbolTestsCore section presence.
+ //
+ // ForeignClassMetadata is the metadata kind the Swift compiler
+ // emits for CoreFoundation foreign classes (CFString, CFArray, etc.).
+ // The metadata lives in CoreFoundation; Swift uses
+ // `unsafeBitCast(CFString.self, to: UnsafeRawPointer.self)` to
+ // obtain the metadata pointer at runtime. Phase B6 introduced
+ // `ForeignTypeFixtures` to surface CFString/CFArray references
+ // in SymbolTestsCore so the bridging usage is documented; the
+ // canonical carrier is CoreFoundation's own runtime metadata.
+ //
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ForeignClassMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let kindRawValue: UInt64
+ }
+
+ static let coreFoundationCFString = Entry(
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRaw))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ForeignClassMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ForeignType/ForeignReferenceTypeMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ForeignType/ForeignReferenceTypeMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..2468a564
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ForeignType/ForeignReferenceTypeMetadataBaselineGenerator.swift
@@ -0,0 +1,48 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/ForeignReferenceTypeMetadataBaseline.swift`.
+///
+/// `ForeignReferenceTypeMetadata` is the metadata for the Swift 5.7
+/// "foreign reference type" import — C++ types annotated with
+/// `SWIFT_SHARED_REFERENCE`. SymbolTestsCore has no such imports, so
+/// no live carrier is reachable. The Suite asserts structural members
+/// behave correctly against a synthetic memberwise instance.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum ForeignReferenceTypeMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "classDescriptor",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ForeignReferenceTypeMetadata describes the Swift 5.7 "foreign
+ // reference type" import (C++ types with SWIFT_SHARED_REFERENCE).
+ // SymbolTestsCore has no such imports, so no live carrier is
+ // reachable. The Suite asserts structural members behave against
+ // a synthetic memberwise instance.
+ //
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ForeignReferenceTypeMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ForeignReferenceTypeMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Function/FunctionTypeFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Function/FunctionTypeFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..d81f5183
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Function/FunctionTypeFlagsBaselineGenerator.swift
@@ -0,0 +1,49 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/FunctionTypeFlagsBaseline.swift`.
+///
+/// Phase C2: emits the runtime-anchored `numberOfParameters` literal
+/// derived from in-process resolution of `((Int) -> Void).self`'s
+/// `FunctionTypeMetadata.layout.flags`. Other `FunctionTypeFlags`
+/// accessors (`rawValue`, `convention`, `isThrowing`, etc.) are pure
+/// raw-value bit decoders and remain tracked via the sentinel
+/// allowlist (`pureDataUtilityEntries`).
+package enum FunctionTypeFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let pointer = InProcessMetadataPicker.stdlibFunctionIntToVoid
+ let context = InProcessContext()
+ let metadata = try FunctionTypeMetadata.resolve(at: pointer, in: context)
+ let numberOfParameters = metadata.layout.flags.numberOfParameters
+
+ let registered = ["numberOfParameters"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess `((Int) -> Void).self` flags slice.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum FunctionTypeFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let numberOfParameters: UInt64
+ }
+
+ static let stdlibFunctionIntToVoid = Entry(
+ numberOfParameters: \(raw: BaselineEmitter.hex(numberOfParameters))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("FunctionTypeFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Function/FunctionTypeMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Function/FunctionTypeMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..14866794
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Function/FunctionTypeMetadataBaselineGenerator.swift
@@ -0,0 +1,52 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/FunctionTypeMetadataBaseline.swift`.
+///
+/// Phase C2: emits ABI literals derived from in-process resolution of
+/// `((Int) -> Void).self`'s `FunctionTypeMetadata`.
+///
+/// Registered names track the wrapper's directly-declared public surface
+/// (`layout`, `offset`); the layout subfields (`kind`, `flags`) are
+/// exercised inside the `layout` test body.
+package enum FunctionTypeMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let pointer = InProcessMetadataPicker.stdlibFunctionIntToVoid
+ let context = InProcessContext()
+ let metadata = try FunctionTypeMetadata.resolve(at: pointer, in: context)
+ let kindRaw = metadata.kind.rawValue
+ let flagsRaw = metadata.layout.flags.rawValue
+
+ let registered = ["layout", "offset"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess `((Int) -> Void).self`; no Mach-O section presence.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum FunctionTypeMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let kindRawValue: UInt32
+ let flagsRawValue: UInt64
+ }
+
+ static let stdlibFunctionIntToVoid = Entry(
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRaw)),
+ flagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("FunctionTypeMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericContextBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericContextBaselineGenerator.swift
new file mode 100644
index 00000000..a10d82ef
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericContextBaselineGenerator.swift
@@ -0,0 +1,223 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericContextBaseline.swift`.
+///
+/// `GenericContext` (the typealias `TargetGenericContext`)
+/// and `TypeGenericContext` (the typealias
+/// `TargetGenericContext`) are both
+/// instantiations of the generic `TargetGenericContext` struct. The
+/// PublicMemberScanner emits MethodKey entries under the typeName
+/// `TargetGenericContext` (the actual struct declaration name), so this
+/// Suite's `testedTypeName` is `TargetGenericContext`.
+///
+/// Fixture choice: we sample several generic structs that exercise the
+/// principal branches of the parser:
+/// - `GenericStructNonRequirement` — params only, no requirements
+/// - `GenericStructLayoutRequirement` — layout requirement
+/// - `GenericStructSwiftProtocolRequirement` — protocol
+/// requirement (Swift)
+/// - `ParameterPackRequirementTest` — typePackHeader/typePacks
+/// - `InvertibleProtocolRequirementTest: ~Copyable` —
+/// conditionalInvertibleProtocolSet
+///
+/// We record presence/cardinality (counts; presence flags for optional
+/// payloads) rather than full structural equality — the underlying types
+/// (`GenericRequirementDescriptor`, `GenericPackShapeDescriptor`, etc.) are
+/// not cheap to deep-compare and the meaningful invariant is "the field is
+/// present and has the expected count when expected, absent otherwise".
+package enum GenericContextBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let nonRequirementContext = try requireTypeGenericContext(
+ for: try BaselineFixturePicker.struct_GenericStructNonRequirement(in: machO),
+ in: machO
+ )
+ let layoutContext = try requireTypeGenericContext(
+ for: try BaselineFixturePicker.struct_GenericStructLayoutRequirement(in: machO),
+ in: machO
+ )
+ let protocolContext = try requireTypeGenericContext(
+ for: try BaselineFixturePicker.struct_GenericStructSwiftProtocolRequirement(in: machO),
+ in: machO
+ )
+ let packContext = try requireTypeGenericContext(
+ for: try BaselineFixturePicker.struct_ParameterPackRequirementTest(in: machO),
+ in: machO
+ )
+ let invertibleContext = try requireTypeGenericContext(
+ for: try BaselineFixturePicker.struct_InvertibleProtocolRequirementTest(in: machO),
+ in: machO
+ )
+
+ let nonRequirementExpr = emitEntryExpr(for: nonRequirementContext)
+ let layoutExpr = emitEntryExpr(for: layoutContext)
+ let protocolExpr = emitEntryExpr(for: protocolContext)
+ let packExpr = emitEntryExpr(for: packContext)
+ let invertibleExpr = emitEntryExpr(for: invertibleContext)
+
+ // Public members declared directly in GenericContext.swift on
+ // `TargetGenericContext`. The three `init(contextDescriptor:in:)`
+ // overloads (MachO + InProcess + ReadingContext) collapse to one
+ // MethodKey under PublicMemberScanner's name-based deduplication;
+ // `init(contextDescriptor:)` is the InProcess variant.
+ let registered = [
+ "allParameters",
+ "allRequirements",
+ "allTypePacks",
+ "allValues",
+ "asGenericContext",
+ "conditionalInvertibleProtocolSet",
+ "conditionalInvertibleProtocolsRequirements",
+ "conditionalInvertibleProtocolsRequirementsCount",
+ "currentParameters",
+ "currentRequirements",
+ "currentTypePacks",
+ "currentValues",
+ "depth",
+ "header",
+ "init(contextDescriptor:)",
+ "init(contextDescriptor:in:)",
+ "offset",
+ "parameters",
+ "parentParameters",
+ "parentRequirements",
+ "parentTypePacks",
+ "parentValues",
+ "requirements",
+ "size",
+ "typePackHeader",
+ "typePacks",
+ "uniqueCurrentRequirements",
+ "uniqueCurrentRequirementsInProcess",
+ "valueHeader",
+ "values",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericContextBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let size: Int
+ let depth: Int
+ let parametersCount: Int
+ let requirementsCount: Int
+ let hasTypePackHeader: Bool
+ let typePacksCount: Int
+ let hasValueHeader: Bool
+ let valuesCount: Int
+ let parentParametersCount: Int
+ let parentRequirementsCount: Int
+ let parentTypePacksCount: Int
+ let parentValuesCount: Int
+ let hasConditionalInvertibleProtocolSet: Bool
+ let hasConditionalInvertibleProtocolsRequirementsCount: Bool
+ let conditionalInvertibleProtocolsRequirementsCount: Int
+ let currentParametersCount: Int
+ let currentRequirementsCount: Int
+ let currentTypePacksCount: Int
+ let currentValuesCount: Int
+ let allParametersCount: Int
+ let allRequirementsCount: Int
+ let allTypePacksCount: Int
+ let allValuesCount: Int
+ }
+
+ static let nonRequirement = \(raw: nonRequirementExpr)
+
+ static let layoutRequirement = \(raw: layoutExpr)
+
+ static let protocolRequirement = \(raw: protocolExpr)
+
+ static let parameterPack = \(raw: packExpr)
+
+ static let invertibleProtocol = \(raw: invertibleExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericContextBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func requireTypeGenericContext(
+ for descriptor: StructDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> TypeGenericContext {
+ try required(try descriptor.typeGenericContext(in: machO))
+ }
+
+ private static func emitEntryExpr(
+ for context: TargetGenericContext
+ ) -> String {
+ let offset = context.offset
+ let size = context.size
+ let depth = context.depth
+ let parametersCount = context.parameters.count
+ let requirementsCount = context.requirements.count
+ let hasTypePackHeader = context.typePackHeader != nil
+ let typePacksCount = context.typePacks.count
+ let hasValueHeader = context.valueHeader != nil
+ let valuesCount = context.values.count
+ let parentParametersCount = context.parentParameters.count
+ let parentRequirementsCount = context.parentRequirements.count
+ let parentTypePacksCount = context.parentTypePacks.count
+ let parentValuesCount = context.parentValues.count
+ let hasSet = context.conditionalInvertibleProtocolSet != nil
+ let hasCount = context.conditionalInvertibleProtocolsRequirementsCount != nil
+ let conditionalReqsCount = context.conditionalInvertibleProtocolsRequirements.count
+ let currentParametersCount = context.currentParameters.count
+ let currentRequirementsCount = context.currentRequirements.count
+ let currentTypePacksCount = context.currentTypePacks.count
+ let currentValuesCount = context.currentValues.count
+ let allParametersCount = context.allParameters.count
+ let allRequirementsCount = context.allRequirements.count
+ let allTypePacksCount = context.allTypePacks.count
+ let allValuesCount = context.allValues.count
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ size: \(literal: size),
+ depth: \(literal: depth),
+ parametersCount: \(literal: parametersCount),
+ requirementsCount: \(literal: requirementsCount),
+ hasTypePackHeader: \(literal: hasTypePackHeader),
+ typePacksCount: \(literal: typePacksCount),
+ hasValueHeader: \(literal: hasValueHeader),
+ valuesCount: \(literal: valuesCount),
+ parentParametersCount: \(literal: parentParametersCount),
+ parentRequirementsCount: \(literal: parentRequirementsCount),
+ parentTypePacksCount: \(literal: parentTypePacksCount),
+ parentValuesCount: \(literal: parentValuesCount),
+ hasConditionalInvertibleProtocolSet: \(literal: hasSet),
+ hasConditionalInvertibleProtocolsRequirementsCount: \(literal: hasCount),
+ conditionalInvertibleProtocolsRequirementsCount: \(literal: conditionalReqsCount),
+ currentParametersCount: \(literal: currentParametersCount),
+ currentRequirementsCount: \(literal: currentRequirementsCount),
+ currentTypePacksCount: \(literal: currentTypePacksCount),
+ currentValuesCount: \(literal: currentValuesCount),
+ allParametersCount: \(literal: allParametersCount),
+ allRequirementsCount: \(literal: allRequirementsCount),
+ allTypePacksCount: \(literal: allTypePacksCount),
+ allValuesCount: \(literal: allValuesCount)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericContextDescriptorFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericContextDescriptorFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..2b0abee0
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericContextDescriptorFlagsBaselineGenerator.swift
@@ -0,0 +1,96 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericContextDescriptorFlagsBaseline.swift`.
+///
+/// `GenericContextDescriptorFlags` is a 16-bit `OptionSet` carried in the
+/// `GenericContextDescriptorHeader` of every generic type's descriptor. The
+/// three static option bits are `hasTypePacks`, `hasConditionalInvertedProtocols`,
+/// and `hasValues`; their same-named instance forms (via OptionSet `contains`)
+/// collapse to one MethodKey under PublicMemberScanner's name-only key.
+///
+/// The baseline embeds canonical synthetic raw values exercising each branch:
+/// - default (`0x0`) — none set
+/// - typePacks only (`0x1`)
+/// - conditional inverted protocols only (`0x2`)
+/// - values only (`0x4`)
+/// - all three (`0x7`)
+package enum GenericContextDescriptorFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let noneEntry = emitEntryExpr(rawValue: 0x0)
+ let typePacksEntry = emitEntryExpr(rawValue: 0x1)
+ let conditionalEntry = emitEntryExpr(rawValue: 0x2)
+ let valuesEntry = emitEntryExpr(rawValue: 0x4)
+ let allEntry = emitEntryExpr(rawValue: 0x7)
+
+ // Public members declared directly in GenericContextDescriptorFlags.swift.
+ // The three static `let`s collapse with their same-named OptionSet
+ // membership checks under PublicMemberScanner's name-only key.
+ let registered = [
+ "hasConditionalInvertedProtocols",
+ "hasTypePacks",
+ "hasValues",
+ "init(rawValue:)",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // GenericContextDescriptorFlags is exercised against synthetic raw
+ // values covering each option bit (none / typePacks / conditional /
+ // values / all). The fixture has live carriers too — see the
+ // GenericContextDescriptorHeader Suite for in-binary readings.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericContextDescriptorFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt16
+ let hasTypePacks: Bool
+ let hasConditionalInvertedProtocols: Bool
+ let hasValues: Bool
+ }
+
+ static let none = \(raw: noneEntry)
+
+ static let typePacksOnly = \(raw: typePacksEntry)
+
+ static let conditionalOnly = \(raw: conditionalEntry)
+
+ static let valuesOnly = \(raw: valuesEntry)
+
+ static let all = \(raw: allEntry)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericContextDescriptorFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(rawValue: UInt16) -> String {
+ let flags = GenericContextDescriptorFlags(rawValue: rawValue)
+ let hasTypePacks = flags.contains(.hasTypePacks)
+ let hasConditionalInvertedProtocols = flags.contains(.hasConditionalInvertedProtocols)
+ let hasValues = flags.contains(.hasValues)
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ hasTypePacks: \(literal: hasTypePacks),
+ hasConditionalInvertedProtocols: \(literal: hasConditionalInvertedProtocols),
+ hasValues: \(literal: hasValues)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericContextDescriptorHeaderBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericContextDescriptorHeaderBaselineGenerator.swift
new file mode 100644
index 00000000..c95258ad
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericContextDescriptorHeaderBaselineGenerator.swift
@@ -0,0 +1,110 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericContextDescriptorHeaderBaseline.swift`.
+///
+/// `GenericContextDescriptorHeader` is the base 8-byte header carried at the
+/// start of every `GenericContext` payload (4 × `UInt16`: `numParams`,
+/// `numRequirements`, `numKeyArguments`, `flags`). The `TypeGenericContext`
+/// variant subclasses this layout with two additional `RelativeOffset`
+/// pointers and is exercised separately by the
+/// `TypeGenericContextDescriptorHeader` Suite.
+///
+/// We pick the header from the first extension descriptor with a generic
+/// context — extensions on generic types (e.g.
+/// `extension Extensions.ExtensionBaseStruct where Element: Equatable`)
+/// surface a `GenericContext` whose `Header` is the plain
+/// `GenericContextDescriptorHeader`.
+package enum GenericContextDescriptorHeaderBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let header = try pickHeader(in: machO)
+ let entryExpr = emitEntryExpr(for: header)
+
+ // Public members declared directly in GenericContextDescriptorHeader.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let headerComment = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: headerComment)
+
+ enum GenericContextDescriptorHeaderBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumParams: UInt16
+ let layoutNumRequirements: UInt16
+ let layoutNumKeyArguments: UInt16
+ let layoutFlagsRawValue: UInt16
+ }
+
+ static let firstExtensionGenericHeader = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericContextDescriptorHeaderBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ /// Picks a `GenericContextDescriptorHeader` from the first generic
+ /// extension context in the fixture. Walks the parent chain of every
+ /// type descriptor until an `ExtensionContextDescriptor` whose
+ /// `isGeneric` flag is set is found, then materializes its
+ /// `GenericContext` and returns the header. Falls back to
+ /// `RequiredError` if the fixture has no generic extension at all.
+ package static func pickHeader(
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> GenericContextDescriptorHeader {
+ for typeDescriptor in try machO.swift.contextDescriptors {
+ var current: SymbolOrElement? = try typeDescriptor.parent(in: machO)
+ while let cursor = current {
+ if let resolved = cursor.resolved {
+ if let ext = resolved.extensionContextDescriptor,
+ ext.flags.isGeneric,
+ let context = try ext.genericContext(in: machO) {
+ return context.header
+ }
+ current = try resolved.parent(in: machO)
+ } else {
+ current = nil
+ }
+ }
+ }
+ throw RequiredError.requiredNonOptional
+ }
+
+ private static func emitEntryExpr(for header: GenericContextDescriptorHeader) -> String {
+ let offset = header.offset
+ let numParams = header.layout.numParams
+ let numRequirements = header.layout.numRequirements
+ let numKeyArguments = header.layout.numKeyArguments
+ let flagsRawValue = header.layout.flags.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumParams: \(literal: numParams),
+ layoutNumRequirements: \(literal: numRequirements),
+ layoutNumKeyArguments: \(literal: numKeyArguments),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRawValue))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericEnvironmentBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericEnvironmentBaselineGenerator.swift
new file mode 100644
index 00000000..c1b50541
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericEnvironmentBaselineGenerator.swift
@@ -0,0 +1,46 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/GenericEnvironmentBaseline.swift`.
+///
+/// `GenericEnvironment` is the runtime-side bookkeeping that the Swift
+/// runtime uses while instantiating a generic type's metadata. It is
+/// materialized from the descriptor's
+/// `defaultInstantiationPattern` at runtime and is not directly surfaced by
+/// the static `MachOFile` reader on any SymbolTestsCore type. The Suite
+/// records only the registered member names and documents the missing
+/// runtime coverage.
+package enum GenericEnvironmentBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in GenericEnvironment.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // GenericEnvironment is materialized at runtime by the metadata
+ // initialization machinery and is not surfaced by the static
+ // MachOFile reader for SymbolTestsCore. The Suite documents the
+ // missing runtime coverage.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericEnvironmentBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericEnvironmentBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericEnvironmentFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericEnvironmentFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..a6f73014
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericEnvironmentFlagsBaselineGenerator.swift
@@ -0,0 +1,89 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericEnvironmentFlagsBaseline.swift`.
+///
+/// `GenericEnvironmentFlags` is a 32-bit `OptionSet` that bit-packs two
+/// counters into a single rawValue: the lowest 12 bits store
+/// `numberOfGenericParameterLevels`; the next 16 bits (shifted by 12) store
+/// `numberOfGenericRequirements`. The `SymbolTestsCore` fixture has no live
+/// `GenericEnvironment` carrier (the structure is materialized by the
+/// runtime's metadata initialization machinery, not the static descriptor
+/// records), so the baseline embeds canonical synthetic raw values that
+/// exercise both bit-fields together.
+///
+/// - `0x0` — both counters zero
+/// - `0x1` — 1 parameter level, 0 requirements
+/// - `0x1003` — 3 parameter levels, 1 requirement (`(1 << 12) | 0x3`)
+/// - `0xfffff` — 0xFFF parameter levels (max), 0xFF requirements (`0xFF << 12 | 0xFFF`)
+package enum GenericEnvironmentFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let zeroEntry = emitEntryExpr(rawValue: 0x0)
+ let oneLevelEntry = emitEntryExpr(rawValue: 0x1)
+ let threeLevelsOneReqEntry = emitEntryExpr(rawValue: 0x1003)
+ let maxEntry = emitEntryExpr(rawValue: 0xFFFFF)
+
+ // Public members declared directly in GenericEnvironmentFlags.swift.
+ // `init(rawValue:)` is the OptionSet-synthesized initializer.
+ let registered = [
+ "init(rawValue:)",
+ "numberOfGenericParameterLevels",
+ "numberOfGenericRequirements",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // GenericEnvironmentFlags has no live SymbolTestsCore source (the
+ // structure is materialized by the runtime's metadata initialization
+ // machinery), so the baseline embeds synthetic raw values exercising
+ // both bit-fields (parameter levels + requirements).
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericEnvironmentFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt32
+ let numberOfGenericParameterLevels: UInt32
+ let numberOfGenericRequirements: UInt32
+ }
+
+ static let zero = \(raw: zeroEntry)
+
+ static let oneLevel = \(raw: oneLevelEntry)
+
+ static let threeLevelsOneRequirement = \(raw: threeLevelsOneReqEntry)
+
+ static let maxAll = \(raw: maxEntry)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericEnvironmentFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(rawValue: UInt32) -> String {
+ let flags = GenericEnvironmentFlags(rawValue: rawValue)
+ let levels = flags.numberOfGenericParameterLevels
+ let requirements = flags.numberOfGenericRequirements
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ numberOfGenericParameterLevels: \(raw: BaselineEmitter.hex(levels)),
+ numberOfGenericRequirements: \(raw: BaselineEmitter.hex(requirements))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericPackShapeDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericPackShapeDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..90b2c04c
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericPackShapeDescriptorBaselineGenerator.swift
@@ -0,0 +1,86 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericPackShapeDescriptorBaseline.swift`.
+///
+/// `GenericPackShapeDescriptor` is the per-pack record carried in the
+/// trailing `typePacks` array of a generic context whose
+/// `GenericContextDescriptorFlags.hasTypePacks` bit is set. Each descriptor
+/// records the pack `kind` (metadata or witnessTable), `index`, and
+/// `shapeClass` plus an `unused` filler.
+///
+/// The fixture's `ParameterPackRequirementTest` declares one
+/// pack parameter, which surfaces a single pack-shape descriptor.
+package enum GenericPackShapeDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_ParameterPackRequirementTest(in: machO)
+ let context = try required(try descriptor.typeGenericContext(in: machO))
+ let pack = try required(context.typePacks.first)
+
+ let entryExpr = emitEntryExpr(for: pack)
+
+ // Public members declared directly in GenericPackShapeDescriptor.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "kind",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericPackShapeDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutKind: UInt16
+ let layoutIndex: UInt16
+ let layoutShapeClass: UInt16
+ let layoutUnused: UInt16
+ let kindRawValue: UInt16
+ }
+
+ static let parameterPackFirstShape = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericPackShapeDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for pack: GenericPackShapeDescriptor) -> String {
+ let offset = pack.offset
+ let layoutKind = pack.layout.kind
+ let layoutIndex = pack.layout.index
+ let layoutShapeClass = pack.layout.shapeClass
+ let layoutUnused = pack.layout.unused
+ let kindRawValue = pack.kind.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutKind: \(literal: layoutKind),
+ layoutIndex: \(literal: layoutIndex),
+ layoutShapeClass: \(literal: layoutShapeClass),
+ layoutUnused: \(literal: layoutUnused),
+ kindRawValue: \(literal: kindRawValue)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericPackShapeHeaderBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericPackShapeHeaderBaselineGenerator.swift
new file mode 100644
index 00000000..c858f142
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericPackShapeHeaderBaselineGenerator.swift
@@ -0,0 +1,75 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericPackShapeHeaderBaseline.swift`.
+///
+/// `GenericPackShapeHeader` is the trailing-object header announcing the
+/// pack-shape array on a generic context whose
+/// `GenericContextDescriptorFlags.hasTypePacks` bit is set. It records
+/// `numPacks` and `numShapeClasses` (both `UInt16`).
+///
+/// The fixture's `ParameterPackRequirementTest` declares one
+/// pack parameter, surfacing a single header.
+package enum GenericPackShapeHeaderBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_ParameterPackRequirementTest(in: machO)
+ let context = try required(try descriptor.typeGenericContext(in: machO))
+ let header = try required(context.typePackHeader)
+
+ let entryExpr = emitEntryExpr(for: header)
+
+ // Public members declared directly in GenericPackShapeHeader.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let headerComment = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: headerComment)
+
+ enum GenericPackShapeHeaderBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumPacks: UInt16
+ let layoutNumShapeClasses: UInt16
+ }
+
+ static let parameterPackHeader = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericPackShapeHeaderBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for header: GenericPackShapeHeader) -> String {
+ let offset = header.offset
+ let numPacks = header.layout.numPacks
+ let numShapeClasses = header.layout.numShapeClasses
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumPacks: \(literal: numPacks),
+ layoutNumShapeClasses: \(literal: numShapeClasses)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericParamDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericParamDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..7a05f1ca
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericParamDescriptorBaselineGenerator.swift
@@ -0,0 +1,91 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericParamDescriptorBaseline.swift`.
+///
+/// `GenericParamDescriptor` is a one-byte descriptor packed into the
+/// generic-context payload (immediately after the header). Its layout
+/// `rawValue` packs `hasKeyArgument` (high bit) plus a `GenericParamKind`
+/// in the low 6 bits.
+///
+/// Fixture choices:
+/// - `GenericStructLayoutRequirement.parameters[0]` — kind=type,
+/// hasKeyArgument=true (the `A: AnyObject` parameter that's a key
+/// argument for runtime type-resolution).
+/// - `ParameterPackRequirementTest.parameters[0]` — kind=typePack,
+/// hasKeyArgument=true (the `each Element` pack parameter).
+package enum GenericParamDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let layoutDescriptor = try BaselineFixturePicker.struct_GenericStructLayoutRequirement(in: machO)
+ let layoutContext = try required(try layoutDescriptor.typeGenericContext(in: machO))
+ let layoutParam = try required(layoutContext.parameters.first)
+
+ let packDescriptor = try BaselineFixturePicker.struct_ParameterPackRequirementTest(in: machO)
+ let packContext = try required(try packDescriptor.typeGenericContext(in: machO))
+ let packParam = try required(packContext.parameters.first)
+
+ let layoutExpr = emitEntryExpr(for: layoutParam)
+ let packExpr = emitEntryExpr(for: packParam)
+
+ // Public members declared directly in GenericParamDescriptor.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "hasKeyArgument",
+ "kind",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericParamDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutRawValue: UInt8
+ let hasKeyArgument: Bool
+ let kindRawValue: UInt8
+ }
+
+ static let layoutRequirementParam0 = \(raw: layoutExpr)
+
+ static let parameterPackParam0 = \(raw: packExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericParamDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for param: GenericParamDescriptor) -> String {
+ let offset = param.offset
+ let rawValue = param.layout.rawValue
+ let hasKeyArgument = param.hasKeyArgument
+ let kindRawValue = param.kind.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutRawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ hasKeyArgument: \(literal: hasKeyArgument),
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRawValue))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementBaselineGenerator.swift
new file mode 100644
index 00000000..2541fc0c
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementBaselineGenerator.swift
@@ -0,0 +1,126 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericRequirementBaseline.swift`.
+///
+/// `GenericRequirement` is the high-level wrapper around
+/// `GenericRequirementDescriptor`. Beyond the descriptor itself it pre-resolves
+/// `paramManagledName` and `content` (a `ResolvedGenericRequirementContent`).
+/// We exercise the same set of fixture variants as the descriptor Suite so
+/// each requirement-content branch has a wrapper-side baseline:
+/// - layout
+/// - protocol (Swift)
+/// - protocol (ObjC)
+/// - baseClass
+/// - sameType
+///
+/// Each `Entry` records the descriptor offset (for cross-Suite anchoring)
+/// and the resolved content discriminant. The mangled-name string parses
+/// to a deep tree we don't embed; runtime cross-reader equality covers it.
+package enum GenericRequirementBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let layoutDescriptor = try BaselineFixturePicker.struct_GenericStructLayoutRequirement(in: machO)
+ let layoutReq = try makeRequirement(for: layoutDescriptor, in: machO)
+
+ let swiftProtocolDescriptor = try BaselineFixturePicker.struct_GenericStructSwiftProtocolRequirement(in: machO)
+ let swiftProtocolReq = try makeRequirement(for: swiftProtocolDescriptor, in: machO)
+
+ let objcProtocolDescriptor = try BaselineFixturePicker.struct_GenericStructObjCProtocolRequirement(in: machO)
+ let objcProtocolReq = try makeRequirement(for: objcProtocolDescriptor, in: machO)
+
+ let baseClassDescriptor = try BaselineFixturePicker.struct_BaseClassRequirementTest(in: machO)
+ let baseClassReq = try makeRequirement(for: baseClassDescriptor, in: machO)
+
+ let sameTypeDescriptor = try BaselineFixturePicker.struct_SameTypeRequirementTest(in: machO)
+ let sameTypeReq = try makeRequirement(for: sameTypeDescriptor, in: machO)
+
+ let layoutExpr = emitEntryExpr(for: layoutReq)
+ let swiftProtocolExpr = emitEntryExpr(for: swiftProtocolReq)
+ let objcProtocolExpr = emitEntryExpr(for: objcProtocolReq)
+ let baseClassExpr = emitEntryExpr(for: baseClassReq)
+ let sameTypeExpr = emitEntryExpr(for: sameTypeReq)
+
+ // Public members declared directly in GenericRequirement.swift.
+ // The three `init(descriptor:in:)` overloads (MachO + InProcess +
+ // ReadingContext) collapse to one MethodKey under PublicMemberScanner's
+ // name-based deduplication; `init(descriptor:)` is the InProcess form.
+ let registered = [
+ "content",
+ "descriptor",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "paramManagledName",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericRequirementBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let resolvedContentCase: String
+ }
+
+ static let layoutRequirement = \(raw: layoutExpr)
+
+ static let swiftProtocolRequirement = \(raw: swiftProtocolExpr)
+
+ static let objcProtocolRequirement = \(raw: objcProtocolExpr)
+
+ static let baseClassRequirement = \(raw: baseClassExpr)
+
+ static let sameTypeRequirement = \(raw: sameTypeExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericRequirementBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func makeRequirement(
+ for descriptor: StructDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> GenericRequirement {
+ let context = try required(try descriptor.typeGenericContext(in: machO))
+ let firstRequirement = try required(context.currentRequirements.first)
+ return try GenericRequirement(descriptor: firstRequirement, in: machO)
+ }
+
+ private static func emitEntryExpr(for requirement: GenericRequirement) -> String {
+ let descriptorOffset = requirement.descriptor.offset
+ let resolvedContentCase = describeResolvedContent(requirement.content)
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ resolvedContentCase: \(literal: resolvedContentCase)
+ )
+ """
+ return expr.description
+ }
+
+ private static func describeResolvedContent(_ content: ResolvedGenericRequirementContent) -> String {
+ switch content {
+ case .type: return "type"
+ case .protocol: return "protocol"
+ case .layout: return "layout"
+ case .conformance: return "conformance"
+ case .invertedProtocols: return "invertedProtocols"
+ }
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementContentBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementContentBaselineGenerator.swift
new file mode 100644
index 00000000..c0b42dfe
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementContentBaselineGenerator.swift
@@ -0,0 +1,103 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericRequirementContentBaseline.swift`.
+///
+/// `GenericRequirementContent` and `ResolvedGenericRequirementContent` are
+/// `@CaseCheckable(.public)` / `@AssociatedValue(.public)` enums; the macro-
+/// generated case-presence helpers and associated-value extractors are not
+/// visited by `PublicMemberScanner` (it only inspects source-level decls,
+/// not macro expansions). The only public member declared in source — and
+/// therefore the only one this Suite has to cover — is the nested
+/// `GenericRequirementContent.InvertedProtocols` struct's two stored
+/// properties (`genericParamIndex`, `protocols`).
+///
+/// The `InvertedProtocols` payload is materialized by the parser via an
+/// in-memory load of `RelativeOffset.layout.content` for the
+/// `invertedProtocols` requirement kind. The fixture's
+/// `InvertibleProtocolRequirementTest: ~Copyable`
+/// generic struct emits exactly one such requirement, so we use it as the
+/// live carrier.
+package enum GenericRequirementContentBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_InvertibleProtocolRequirementTest(in: machO)
+ let context = try required(try descriptor.typeGenericContext(in: machO))
+ // Look at the conditional invertible protocols requirements first;
+ // fall back to scanning the regular requirements for the
+ // invertedProtocols kind.
+ let invertedProtocols = try requireInvertedProtocols(in: context)
+
+ let entryExpr = emitEntryExpr(for: invertedProtocols)
+
+ // Public members declared directly on
+ // GenericRequirementContent.InvertedProtocols. The two case-iterating
+ // helpers macro-injected onto the parent enums are out of scope.
+ let registered = [
+ "genericParamIndex",
+ "protocols",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Only GenericRequirementContent.InvertedProtocols has visible public
+ // surface (case-iterating helpers on the parent enums are emitted
+ // by macros and not visited by PublicMemberScanner).
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericRequirementContentBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let genericParamIndex: UInt16
+ let protocolsRawValue: UInt16
+ }
+
+ static let invertibleProtocolRequirement = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericRequirementContentBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func requireInvertedProtocols(
+ in context: TypeGenericContext
+ ) throws -> GenericRequirementContent.InvertedProtocols {
+ // Walk both the conditional set and the regular requirements to find
+ // an `.invertedProtocols` discriminant.
+ let candidates =
+ context.conditionalInvertibleProtocolsRequirements
+ + context.requirements
+ for requirement in candidates {
+ if case .invertedProtocols(let payload) = requirement.content {
+ return payload
+ }
+ }
+ throw RequiredError.requiredNonOptional
+ }
+
+ private static func emitEntryExpr(for value: GenericRequirementContent.InvertedProtocols) -> String {
+ let genericParamIndex = value.genericParamIndex
+ let protocolsRawValue = value.protocols.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ genericParamIndex: \(literal: genericParamIndex),
+ protocolsRawValue: \(raw: BaselineEmitter.hex(protocolsRawValue))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..268099dc
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementDescriptorBaselineGenerator.swift
@@ -0,0 +1,142 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericRequirementDescriptorBaseline.swift`.
+///
+/// `GenericRequirementDescriptor` is the per-requirement record carried in
+/// the trailing `requirements` array of a generic context. Each descriptor
+/// holds a `flags`, a `param: RelativeDirectPointer`, and a
+/// `content: RelativeOffset` whose interpretation depends on `flags.kind`.
+///
+/// Fixture choices (one per kind branch the parser exercises):
+/// - `GenericStructLayoutRequirement.requirements[0]` — kind `.layout`
+/// - `GenericStructSwiftProtocolRequirement.requirements[0]` —
+/// kind `.protocol` (Swift)
+/// - `GenericStructObjCProtocolRequirement.requirements[0]` —
+/// kind `.protocol` (ObjC)
+/// - `BaseClassRequirementTest.requirements[0]` — kind `.baseClass`
+/// - `SameTypeRequirementTest.requirements[0]` — kind `.sameType`
+///
+/// Each entry records the descriptor's offset, the flags rawValue (the
+/// load-bearing scalar), and the requirement-content kind. Equality of
+/// the resolved param/content payloads (mangled names, protocol pointers)
+/// is asserted at runtime via `isContentEqual` cross-reader checks.
+package enum GenericRequirementDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let layoutDescriptor = try BaselineFixturePicker.struct_GenericStructLayoutRequirement(in: machO)
+ let layoutReq = try requireFirstRequirement(of: layoutDescriptor, in: machO)
+
+ let swiftProtocolDescriptor = try BaselineFixturePicker.struct_GenericStructSwiftProtocolRequirement(in: machO)
+ let swiftProtocolReq = try requireFirstRequirement(of: swiftProtocolDescriptor, in: machO)
+
+ let objcProtocolDescriptor = try BaselineFixturePicker.struct_GenericStructObjCProtocolRequirement(in: machO)
+ let objcProtocolReq = try requireFirstRequirement(of: objcProtocolDescriptor, in: machO)
+
+ let baseClassDescriptor = try BaselineFixturePicker.struct_BaseClassRequirementTest(in: machO)
+ let baseClassReq = try requireFirstRequirement(of: baseClassDescriptor, in: machO)
+
+ let sameTypeDescriptor = try BaselineFixturePicker.struct_SameTypeRequirementTest(in: machO)
+ let sameTypeReq = try requireFirstRequirement(of: sameTypeDescriptor, in: machO)
+
+ let layoutExpr = emitEntryExpr(for: layoutReq)
+ let swiftProtocolExpr = emitEntryExpr(for: swiftProtocolReq)
+ let objcProtocolExpr = emitEntryExpr(for: objcProtocolReq)
+ let baseClassExpr = emitEntryExpr(for: baseClassReq)
+ let sameTypeExpr = emitEntryExpr(for: sameTypeReq)
+
+ // Public members declared directly in GenericRequirementDescriptor.swift.
+ // The three `paramMangledName(in:)` overloads (MachO + InProcess +
+ // ReadingContext) and the matching `type(in:)` / `resolvedContent(in:)` /
+ // `isContentEqual(to:in:)` families collapse to one MethodKey each
+ // under PublicMemberScanner's name-based deduplication.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "content",
+ "isContentEqual",
+ "layout",
+ "offset",
+ "paramMangledName",
+ "resolvedContent",
+ "type",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericRequirementDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let flagsRawValue: UInt32
+ let kindRawValue: UInt8
+ let contentKindCase: String
+ }
+
+ static let layoutRequirement = \(raw: layoutExpr)
+
+ static let swiftProtocolRequirement = \(raw: swiftProtocolExpr)
+
+ static let objcProtocolRequirement = \(raw: objcProtocolExpr)
+
+ static let baseClassRequirement = \(raw: baseClassExpr)
+
+ static let sameTypeRequirement = \(raw: sameTypeExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericRequirementDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func requireFirstRequirement(
+ of descriptor: StructDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> GenericRequirementDescriptor {
+ let context = try required(try descriptor.typeGenericContext(in: machO))
+ return try required(context.currentRequirements.first)
+ }
+
+ private static func emitEntryExpr(for requirement: GenericRequirementDescriptor) -> String {
+ let offset = requirement.offset
+ let flagsRawValue = requirement.layout.flags.rawValue
+ let kindRawValue = requirement.layout.flags.kind.rawValue
+ let contentKindCase = describeContentKind(requirement.content)
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ flagsRawValue: \(raw: BaselineEmitter.hex(flagsRawValue)),
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRawValue)),
+ contentKindCase: \(literal: contentKindCase)
+ )
+ """
+ return expr.description
+ }
+
+ /// Stable string label for the `GenericRequirementContent` discriminant.
+ /// We don't embed the resolved payload (relative pointers, mangled
+ /// names) — runtime cross-reader equality covers those.
+ private static func describeContentKind(_ content: GenericRequirementContent) -> String {
+ switch content {
+ case .type: return "type"
+ case .protocol: return "protocol"
+ case .layout: return "layout"
+ case .conformance: return "conformance"
+ case .invertedProtocols: return "invertedProtocols"
+ }
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..d0b12e9d
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericRequirementFlagsBaselineGenerator.swift
@@ -0,0 +1,102 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericRequirementFlagsBaseline.swift`.
+///
+/// `GenericRequirementFlags` is a 32-bit `OptionSet` carried in every
+/// `GenericRequirementDescriptor`'s leading `flags` field. It packs a
+/// `GenericRequirementKind` into the lowest 5 bits plus three orthogonal
+/// option bits at higher offsets:
+/// - `0x20` — `isPackRequirement`
+/// - `0x80` — `hasKeyArgument`
+/// - `0x100` — `isValueRequirement`
+/// The static `let`s collapse with their same-named OptionSet membership
+/// checks under PublicMemberScanner's name-only key.
+///
+/// The baseline embeds canonical synthetic raw values exercising each
+/// branch of the kind decoder plus combinations with the option bits.
+package enum GenericRequirementFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let protocolDefault = emitEntryExpr(rawValue: 0x0) // kind=protocol, no opts
+ let sameType = emitEntryExpr(rawValue: 0x1) // kind=sameType
+ let layoutOnly = emitEntryExpr(rawValue: 0x1F) // kind=layout (0x1F)
+ let protocolWithKey = emitEntryExpr(rawValue: 0x80) // protocol + hasKeyArgument
+ let packWithKey = emitEntryExpr(rawValue: 0xA0) // pack + hasKeyArgument
+ let valueRequirement = emitEntryExpr(rawValue: 0x100) // isValueRequirement
+
+ // Public members declared directly in GenericRequirementFlags.swift.
+ let registered = [
+ "hasKeyArgument",
+ "init(rawValue:)",
+ "isPackRequirement",
+ "isValueRequirement",
+ "kind",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // GenericRequirementFlags is exercised against synthetic raw values
+ // covering each kind (protocol/sameType/layout) plus combinations
+ // with the three option bits (isPackRequirement/hasKeyArgument/
+ // isValueRequirement). Live carriers are also exercised by the
+ // GenericRequirementDescriptor Suite's per-fixture readings.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericRequirementFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt32
+ let kindRawValue: UInt8
+ let isPackRequirement: Bool
+ let hasKeyArgument: Bool
+ let isValueRequirement: Bool
+ }
+
+ static let protocolDefault = \(raw: protocolDefault)
+
+ static let sameType = \(raw: sameType)
+
+ static let layoutOnly = \(raw: layoutOnly)
+
+ static let protocolWithKey = \(raw: protocolWithKey)
+
+ static let packWithKey = \(raw: packWithKey)
+
+ static let valueRequirement = \(raw: valueRequirement)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericRequirementFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(rawValue: UInt32) -> String {
+ let flags = GenericRequirementFlags(rawValue: rawValue)
+ let kindRawValue = flags.kind.rawValue
+ let isPackRequirement = flags.contains(.isPackRequirement)
+ let hasKeyArgument = flags.contains(.hasKeyArgument)
+ let isValueRequirement = flags.contains(.isValueRequirement)
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRawValue)),
+ isPackRequirement: \(literal: isPackRequirement),
+ hasKeyArgument: \(literal: hasKeyArgument),
+ isValueRequirement: \(literal: isValueRequirement)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericValueDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericValueDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..afbc80c8
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericValueDescriptorBaselineGenerator.swift
@@ -0,0 +1,77 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericValueDescriptorBaseline.swift`.
+///
+/// `GenericValueDescriptor` is the per-value record carried in the
+/// trailing `values` array of a generic context whose
+/// `GenericContextDescriptorFlags.hasValues` bit is set. Each descriptor
+/// records the value `type` (currently only `GenericValueType.int`).
+///
+/// Phase B7 introduced `GenericValueParameters.swift` so that
+/// `GenericValueFixtures.FixedSizeArray` surfaces a
+/// single `GenericValueDescriptor` on its generic context.
+package enum GenericValueDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_FixedSizeArray(in: machO)
+ let context = try required(try descriptor.typeGenericContext(in: machO))
+ let value = try required(context.values.first)
+
+ let entryExpr = emitEntryExpr(for: value)
+
+ // Public members declared directly in GenericValueDescriptor.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ "type",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericValueDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutType: UInt32
+ let typeRawValue: UInt32
+ }
+
+ static let fixedSizeArrayFirstValue = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericValueDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for value: GenericValueDescriptor) -> String {
+ let offset = value.offset
+ let layoutType = value.layout.type
+ let typeRawValue = value.type.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutType: \(literal: layoutType),
+ typeRawValue: \(literal: typeRawValue)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericValueHeaderBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericValueHeaderBaselineGenerator.swift
new file mode 100644
index 00000000..6982a3e7
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericValueHeaderBaselineGenerator.swift
@@ -0,0 +1,73 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GenericValueHeaderBaseline.swift`.
+///
+/// `GenericValueHeader` is the trailing-object header announcing the
+/// integer-value-parameter array on a generic context whose
+/// `GenericContextDescriptorFlags.hasValues` bit is set. It records
+/// `numValues` (UInt32).
+///
+/// Phase B7 introduced `GenericValueParameters.swift` so that
+/// `GenericValueFixtures.FixedSizeArray` surfaces a
+/// single `GenericValueHeader` on its generic context.
+package enum GenericValueHeaderBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_FixedSizeArray(in: machO)
+ let context = try required(try descriptor.typeGenericContext(in: machO))
+ let header = try required(context.valueHeader)
+
+ let entryExpr = emitEntryExpr(for: header)
+
+ // Public members declared directly in GenericValueHeader.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let headerComment = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: headerComment)
+
+ enum GenericValueHeaderBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumValues: UInt32
+ }
+
+ static let fixedSizeArrayHeader = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericValueHeaderBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for header: GenericValueHeader) -> String {
+ let offset = header.offset
+ let numValues = header.layout.numValues
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumValues: \(literal: numValues)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericWitnessTableBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericWitnessTableBaselineGenerator.swift
new file mode 100644
index 00000000..7362113d
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/GenericWitnessTableBaselineGenerator.swift
@@ -0,0 +1,50 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/GenericWitnessTableBaseline.swift`.
+///
+/// `GenericWitnessTable` is the per-conformance witness-table layout
+/// emitted alongside generic protocol conformances. It records the
+/// witness table size, instantiator/private-data hooks. The structure is
+/// reachable from a `ProtocolConformanceDescriptor`'s
+/// `GenericWitnessTableSection` trailing object, but the
+/// `SymbolTestsCore` fixture does NOT surface any conformance whose
+/// witness-table layout reaches the parser as a `GenericWitnessTable`
+/// instance through the current public API.
+///
+/// Until the upstream parser exposes a discoverable carrier, the Suite
+/// records only the registered member names and documents the missing
+/// runtime coverage.
+package enum GenericWitnessTableBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in GenericWitnessTable.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // GenericWitnessTable is not surfaced by the current public API
+ // for any SymbolTestsCore conformance. The Suite documents the
+ // missing runtime coverage.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericWitnessTableBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericWitnessTableBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Generic/TypeGenericContextDescriptorHeaderBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/TypeGenericContextDescriptorHeaderBaselineGenerator.swift
new file mode 100644
index 00000000..4c905d53
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Generic/TypeGenericContextDescriptorHeaderBaselineGenerator.swift
@@ -0,0 +1,82 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TypeGenericContextDescriptorHeaderBaseline.swift`.
+///
+/// `TypeGenericContextDescriptorHeader` extends the plain
+/// `GenericContextDescriptorHeader` layout with two additional pointers
+/// (`instantiationCache` and `defaultInstantiationPattern`) — the
+/// runtime-side metadata-instantiation hooks. We pick the header from the
+/// generic struct `GenericFieldLayout.GenericStructLayoutRequirement`
+/// whose `typeGenericContext` exists and whose generic context exercises a
+/// non-trivial layout requirement.
+package enum TypeGenericContextDescriptorHeaderBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_GenericStructLayoutRequirement(in: machO)
+ let typeContext = try required(try descriptor.typeGenericContext(in: machO))
+ let header = typeContext.header
+
+ let entryExpr = emitEntryExpr(for: header)
+
+ // Public members declared directly in
+ // TypeGenericContextDescriptorHeader.swift. `init(layout:offset:)` is
+ // filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let headerComment = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: headerComment)
+
+ enum TypeGenericContextDescriptorHeaderBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumParams: UInt16
+ let layoutNumRequirements: UInt16
+ let layoutNumKeyArguments: UInt16
+ let layoutFlagsRawValue: UInt16
+ }
+
+ static let genericStructLayoutRequirement = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeGenericContextDescriptorHeaderBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for header: TypeGenericContextDescriptorHeader) -> String {
+ let offset = header.offset
+ let numParams = header.layout.numParams
+ let numRequirements = header.layout.numRequirements
+ let numKeyArguments = header.layout.numKeyArguments
+ let flagsRawValue = header.layout.flags.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumParams: \(literal: numParams),
+ layoutNumRequirements: \(literal: numRequirements),
+ layoutNumKeyArguments: \(literal: numKeyArguments),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRawValue))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Heap/GenericBoxHeapMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Heap/GenericBoxHeapMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..3c152405
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Heap/GenericBoxHeapMetadataBaselineGenerator.swift
@@ -0,0 +1,47 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/GenericBoxHeapMetadataBaseline.swift`.
+///
+/// `GenericBoxHeapMetadata` is the runtime metadata for a Swift box
+/// (used by indirect enum cases and capture buffers). The Swift runtime
+/// allocates these on demand; no static record is reachable from the
+/// SymbolTestsCore section walks. The Suite asserts the type's
+/// structural members behave correctly against a synthetic memberwise
+/// instance.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum GenericBoxHeapMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // GenericBoxHeapMetadata is allocated by the Swift runtime on
+ // demand; no static carrier is reachable from SymbolTestsCore.
+ // The Suite asserts structural members behave against a
+ // synthetic memberwise instance.
+ //
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GenericBoxHeapMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GenericBoxHeapMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Heap/HeapLocalVariableMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Heap/HeapLocalVariableMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..3493fcf1
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Heap/HeapLocalVariableMetadataBaselineGenerator.swift
@@ -0,0 +1,48 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/HeapLocalVariableMetadataBaseline.swift`.
+///
+/// `HeapLocalVariableMetadata` is the metadata for closure capture
+/// buffers (heap-allocated local-variable boxes). The Swift runtime
+/// allocates these on demand from a closure's capture list; no static
+/// record is reachable from the SymbolTestsCore section walks. The
+/// Suite asserts the type's structural members behave correctly
+/// against a synthetic memberwise instance.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum HeapLocalVariableMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // HeapLocalVariableMetadata is allocated by the Swift runtime
+ // on demand from a closure's capture list; no static carrier
+ // is reachable from SymbolTestsCore. The Suite asserts
+ // structural members behave against a synthetic memberwise
+ // instance.
+ //
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum HeapLocalVariableMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("HeapLocalVariableMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Mangling/MangledNameBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Mangling/MangledNameBaselineGenerator.swift
new file mode 100644
index 00000000..07077107
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Mangling/MangledNameBaselineGenerator.swift
@@ -0,0 +1,88 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/MangledNameBaseline.swift`.
+///
+/// `MangledName` is the parser/decoder for Swift's mangled-name byte
+/// stream. Carriers exist throughout the fixture: every multi-payload
+/// enum's `mangledTypeName`, every associated-type record's mangled
+/// names, etc. We pick the multi-payload-enum descriptor's
+/// `mangledTypeName` for `Enums.MultiPayloadEnumTests` as a stable
+/// carrier — it's deterministic across builds and exercises the
+/// non-empty-elements / lookup-element paths.
+///
+/// The Suite asserts cross-reader equality on:
+/// - `isEmpty` — same boolean across readers
+/// - `rawString` — byte-equal across readers
+/// - presence of `lookupElements` — count match
+package enum MangledNameBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.multiPayloadEnumDescriptor_MultiPayloadEnumTest(in: machO)
+ let mangledName = try descriptor.mangledTypeName(in: machO)
+ let entryExpr = emitEntryExpr(for: mangledName)
+
+ // Public members declared in MangledName.swift. The three
+ // `resolve` overloads (MachO + InProcess + ReadingContext)
+ // collapse to one MethodKey under PublicMemberScanner's
+ // name-only key.
+ let registered = [
+ "description",
+ "isEmpty",
+ "rawString",
+ "resolve",
+ "symbolString",
+ "typeString",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Carrier: the mangledTypeName of the MultiPayloadEnumDescriptor
+ // for Enums.MultiPayloadEnumTests. The Suite asserts cross-reader
+ // equality on (isEmpty, rawString, element-count, lookup-count).
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MangledNameBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let isEmpty: Bool
+ let rawString: String
+ let lookupElementsCount: Int
+ }
+
+ static let multiPayloadEnumName = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MangledNameBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for mangledName: MangledName) -> String {
+ let isEmpty = mangledName.isEmpty
+ let rawString = mangledName.rawString
+ let lookupElementsCount = mangledName.lookupElements.count
+
+ let expr: ExprSyntax = """
+ Entry(
+ isEmpty: \(literal: isEmpty),
+ rawString: \(literal: rawString),
+ lookupElementsCount: \(literal: lookupElementsCount)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadataAccessorsListEntryBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadataAccessorsListEntryBaselineGenerator.swift
new file mode 100644
index 00000000..9aa1ad97
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadataAccessorsListEntryBaselineGenerator.swift
@@ -0,0 +1,48 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/CanonicalSpecializedMetadataAccessorsListEntryBaseline.swift`.
+///
+/// `CanonicalSpecializedMetadataAccessorsListEntry` is a trailing-objects
+/// payload appended to descriptors that declare canonical metadata
+/// prespecializations (the `hasCanonicalMetadataPrespecializations` bit).
+/// The `SymbolTestsCore` fixture does NOT use any `@_specialize`
+/// prespecialization directives, so no descriptor in the fixture surfaces a
+/// non-empty `canonicalSpecializedMetadataAccessors` array. Consequently we
+/// emit only the registered member names — the structural layout is exercised
+/// indirectly by `Class.canonicalSpecializedMetadataAccessors` reads when
+/// the fixture is extended with prespecialized types.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum CanonicalSpecializedMetadataAccessorsListEntryBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // SymbolTestsCore declares no canonical-metadata prespecializations,
+ // so no live entry is materialised. The companion Suite asserts the
+ // type's structural members exist; runtime payloads will be exercised
+ // when prespecialized types are added to the fixture.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum CanonicalSpecializedMetadataAccessorsListEntryBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("CanonicalSpecializedMetadataAccessorsListEntryBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadatasCachingOnceTokenBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadatasCachingOnceTokenBaselineGenerator.swift
new file mode 100644
index 00000000..cb03e4e6
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadatasCachingOnceTokenBaselineGenerator.swift
@@ -0,0 +1,43 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/CanonicalSpecializedMetadatasCachingOnceTokenBaseline.swift`.
+///
+/// `CanonicalSpecializedMetadatasCachingOnceToken` is appended to descriptors
+/// with the `hasCanonicalMetadataPrespecializations` bit, between the
+/// metadata accessors list and the trailing data. The `SymbolTestsCore`
+/// fixture declares no prespecializations, so no live token is materialised.
+/// We emit only the registered member names.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum CanonicalSpecializedMetadatasCachingOnceTokenBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // SymbolTestsCore declares no canonical-metadata prespecializations,
+ // so no live token is materialised. The Suite asserts the type's
+ // structural members exist.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum CanonicalSpecializedMetadatasCachingOnceTokenBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("CanonicalSpecializedMetadatasCachingOnceTokenBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadatasListCountBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadatasListCountBaselineGenerator.swift
new file mode 100644
index 00000000..37ae2fd0
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadatasListCountBaselineGenerator.swift
@@ -0,0 +1,47 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/CanonicalSpecializedMetadatasListCountBaseline.swift`.
+///
+/// `CanonicalSpecializedMetadatasListCount` is a one-`UInt32` raw-representable
+/// wrapper; the count is read from the trailing-objects payload of descriptors
+/// with the `hasCanonicalMetadataPrespecializations` bit. The `SymbolTestsCore`
+/// fixture declares no prespecializations, so no live count is materialised.
+///
+/// The Suite covers the round-trip through `init(rawValue:)` / `rawValue` to
+/// witness the macro-style constructor of a raw-representable type.
+package enum CanonicalSpecializedMetadatasListCountBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "init(rawValue:)",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // RawRepresentable wrapper around a UInt32 count; SymbolTestsCore
+ // declares no canonical-metadata prespecializations, so the value is
+ // exercised via constant round-trip rather than by reading the
+ // fixture.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum CanonicalSpecializedMetadatasListCountBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ /// Constant round-trip witness used by the companion Suite.
+ static let sampleRawValue: UInt32 = 0x2A
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("CanonicalSpecializedMetadatasListCountBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadatasListEntryBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadatasListEntryBaselineGenerator.swift
new file mode 100644
index 00000000..3af0def0
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/CanonicalSpecializedMetadatasListEntryBaselineGenerator.swift
@@ -0,0 +1,42 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/CanonicalSpecializedMetadatasListEntryBaseline.swift`.
+///
+/// `CanonicalSpecializedMetadatasListEntry` is a trailing-objects payload
+/// appended to descriptors that declare canonical metadata prespecializations.
+/// The `SymbolTestsCore` fixture does NOT use any `@_specialize` / canonical-
+/// metadata prespecialization directives, so no descriptor surfaces a
+/// non-empty `canonicalSpecializedMetadatas` array.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum CanonicalSpecializedMetadatasListEntryBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // SymbolTestsCore declares no canonical-metadata prespecializations,
+ // so no live entry is materialised.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum CanonicalSpecializedMetadatasListEntryBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("CanonicalSpecializedMetadatasListEntryBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/FixedArrayTypeMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/FixedArrayTypeMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..7420bb0f
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/FixedArrayTypeMetadataBaselineGenerator.swift
@@ -0,0 +1,46 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/FixedArrayTypeMetadataBaseline.swift`.
+///
+/// `FixedArrayTypeMetadata` is the runtime metadata kind for the experimental
+/// `FixedArray` Swift built-in (`MetadataKind.fixedArray = 0x308`). The
+/// `SymbolTestsCore` fixture does not declare any such types, so no live
+/// instance can be reached through the static section walks. We emit only
+/// the registered member names; the structural members are exercised
+/// indirectly via `MetadataWrapper.fixedArray(_:)` once a fixed-array fixture
+/// is added.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum FixedArrayTypeMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // SymbolTestsCore declares no FixedArray types, so no live metadata
+ // is reachable. The Suite asserts the type's structural members
+ // exist; runtime payloads will be exercised when a fixed-array
+ // fixture is added.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum FixedArrayTypeMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("FixedArrayTypeMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/FullMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/FullMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..0236db4e
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/FullMetadataBaselineGenerator.swift
@@ -0,0 +1,47 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/FullMetadataBaseline.swift`.
+///
+/// `FullMetadata` is the (`HeaderType.Layout`, `Metadata.Layout`)
+/// pair preceded by the metadata pointer (the "full" metadata layout
+/// includes the pre-header type-witness pointers). Live `FullMetadata`
+/// instances are reachable only through MachOImage's metadata accessor (via
+/// `MetadataProtocol.asFullMetadata`); the Suite (`FullMetadataTests`)
+/// materialises a `FullMetadata` for `Structs.StructTest`
+/// and asserts cross-reader equality between the (image, imageContext,
+/// inProcess) reader axes.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum FullMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // FullMetadata is materialised from a MachOImage metadata accessor
+ // (via MetadataProtocol.asFullMetadata); live pointer values are not
+ // embedded here. The companion Suite asserts cross-reader equality
+ // between (MachOImage, imageContext, inProcess).
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum FullMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("FullMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/HeapMetadataHeaderBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/HeapMetadataHeaderBaselineGenerator.swift
new file mode 100644
index 00000000..ca86f404
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/HeapMetadataHeaderBaselineGenerator.swift
@@ -0,0 +1,44 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/HeapMetadataHeaderBaseline.swift`.
+///
+/// `HeapMetadataHeader` is the prefix preceding heap metadata records (the
+/// `(layoutString, destroy, valueWitnesses)` triple); the `valueWitnesses`
+/// pointer is reachable through `MetadataProtocol.asFullMetadata` for any
+/// heap-class metadata. Live header instances are reachable only through
+/// MachOImage's accessor invocation, so we emit only the registered member
+/// names; the Suite verifies cross-reader equality at runtime.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum HeapMetadataHeaderBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // HeapMetadataHeader is materialised from MachOImage's accessor
+ // (via FullMetadata header projection); live pointer values are
+ // not embedded here.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum HeapMetadataHeaderBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("HeapMetadataHeaderBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/HeapMetadataHeaderPrefixBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/HeapMetadataHeaderPrefixBaselineGenerator.swift
new file mode 100644
index 00000000..38a8b4da
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/HeapMetadataHeaderPrefixBaselineGenerator.swift
@@ -0,0 +1,44 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/HeapMetadataHeaderPrefixBaseline.swift`.
+///
+/// `HeapMetadataHeaderPrefix` is the single-`destroy`-pointer slot
+/// embedded in every heap metadata's three-word layout prefix
+/// `(layoutString, destroy, valueWitnesses)`. Phase C5 converts this
+/// suite to a real test that materialises the prefix at the second word
+/// of `Classes.ClassTest`'s heap metadata layout (MachOImage-only path —
+/// `MachOFile` cannot invoke runtime accessor functions). Live pointer
+/// values are not embedded here because the runtime-installed `destroy`
+/// callback is process-lifetime-stable but not reader-stable.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum HeapMetadataHeaderPrefixBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: MachOImage path on `Classes.ClassTest`'s class metadata
+ // (the prefix lives at `interop.offset - HeapMetadataHeader.layoutSize
+ // + TypeMetadataLayoutPrefix.layoutSize`).
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum HeapMetadataHeaderPrefixBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("HeapMetadataHeaderPrefixBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/TypeMetadataHeaderBaseBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/TypeMetadataHeaderBaseBaselineGenerator.swift
new file mode 100644
index 00000000..6fa85f9e
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/TypeMetadataHeaderBaseBaselineGenerator.swift
@@ -0,0 +1,42 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/TypeMetadataHeaderBaseBaseline.swift`.
+///
+/// `TypeMetadataHeaderBase` is the minimal value-witness-pointer prefix
+/// (just the `valueWitnesses` field) shared by every metadata header
+/// hierarchy. Live header instances are materialised through MachOImage's
+/// accessor; live pointer values are not embedded.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum TypeMetadataHeaderBaseBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // TypeMetadataHeaderBase is materialised from MachOImage's accessor
+ // (via FullMetadata header projection); live pointer values aren't
+ // embedded.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeMetadataHeaderBaseBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeMetadataHeaderBaseBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/TypeMetadataHeaderBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/TypeMetadataHeaderBaselineGenerator.swift
new file mode 100644
index 00000000..c5323993
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/TypeMetadataHeaderBaselineGenerator.swift
@@ -0,0 +1,42 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/TypeMetadataHeaderBaseline.swift`.
+///
+/// `TypeMetadataHeader` is the (`layoutString`, `valueWitnesses`) prefix
+/// preceding value-type metadata records. Live header instances are
+/// materialised through `MetadataProtocol.asFullMetadata` from a MachOImage
+/// metadata accessor; live pointer values are not embedded.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum TypeMetadataHeaderBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // TypeMetadataHeader is materialised from MachOImage's accessor
+ // (via FullMetadata header projection); live pointer values aren't
+ // embedded.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeMetadataHeaderBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeMetadataHeaderBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/TypeMetadataLayoutPrefixBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/TypeMetadataLayoutPrefixBaselineGenerator.swift
new file mode 100644
index 00000000..acc708fc
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/Headers/TypeMetadataLayoutPrefixBaselineGenerator.swift
@@ -0,0 +1,41 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/TypeMetadataLayoutPrefixBaseline.swift`.
+///
+/// `TypeMetadataLayoutPrefix` is the single-`layoutString`-pointer prefix
+/// preceding every type metadata header. Live header instances are
+/// materialised through MachOImage's accessor; live pointer values are not
+/// embedded.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum TypeMetadataLayoutPrefixBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // TypeMetadataLayoutPrefix is materialised from MachOImage's
+ // accessor; live pointer values aren't embedded.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeMetadataLayoutPrefixBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeMetadataLayoutPrefixBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataAccessorFunctionBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataAccessorFunctionBaselineGenerator.swift
new file mode 100644
index 00000000..36cfefbf
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataAccessorFunctionBaselineGenerator.swift
@@ -0,0 +1,48 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MetadataAccessorFunctionBaseline.swift`.
+///
+/// `MetadataAccessorFunction` wraps a raw function pointer to a Swift
+/// runtime metadata accessor. The pointer can only be obtained from a
+/// loaded MachOImage (the function lives in the image's text segment), so
+/// the structural payload is reachable solely through MachOImage. We emit
+/// only the registered method name; the Suite (`MetadataAccessorFunctionTests`)
+/// invokes `callAsFunction(request:)` against `Structs.StructTest`'s accessor
+/// and asserts the returned `MetadataResponse` resolves to a non-nil
+/// `StructMetadata`.
+///
+/// `init(ptr:)` is `package`-scoped and not visited by the public scanner;
+/// the six `callAsFunction` overloads collapse to a single `MethodKey`
+/// under PublicMemberScanner's name-only keying.
+package enum MetadataAccessorFunctionBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "callAsFunction",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // MetadataAccessorFunction is materialised solely through MachOImage
+ // (the underlying pointer is the runtime function's text address).
+ // No literal payload is embedded; the Suite invokes the accessor at
+ // runtime and asserts a non-nil StructMetadata response.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MetadataAccessorFunctionBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MetadataAccessorFunctionBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataBaselineGenerator.swift
new file mode 100644
index 00000000..66c1c8b9
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataBaselineGenerator.swift
@@ -0,0 +1,45 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MetadataBaseline.swift`.
+///
+/// `Metadata` is the kind-erased one-pointer header shared by every
+/// `MetadataKind`; its only stored field is `kind: StoredPointer`. Because
+/// the `kind` value of a Swift class metadata is the descriptor pointer (not
+/// a runtime kind tag), live `Metadata.layout.kind` values are not stable
+/// across runs. The Suite (`MetadataTests`) materialises a value-type
+/// `Metadata` (StructTest) — whose `kind` IS a stable scalar — and asserts
+/// the cross-reader equality block at runtime.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum MetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Metadata is materialised through MachOImage's metadata accessor at
+ // runtime (the Suite uses StructTest as a stable value-type witness).
+ // Live pointer values aren't embedded here.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataBoundsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataBoundsBaselineGenerator.swift
new file mode 100644
index 00000000..05a3b2f7
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataBoundsBaselineGenerator.swift
@@ -0,0 +1,54 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MetadataBoundsBaseline.swift`.
+///
+/// `MetadataBounds` is the one-`(UInt32, UInt32)` payload describing a class
+/// metadata's negative/positive prefix bounds. The Suite validates the
+/// structural fields via a constant round-trip — `MetadataBounds(layout:offset:)`
+/// preserves the supplied `negativeSizeInWords`/`positiveSizeInWords`.
+///
+/// Phase C5 considered conversion to a real test and kept sentinel — same
+/// rationale as `ClassMetadataBounds`, which has no runtime derivation
+/// path from a class metadata pointer (only static factories
+/// `forSwiftRootClass`/`forAddressPointAndSize` and the `adjustForSubclass`
+/// instance method).
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized; the
+/// inherited `totalSizeInBytes`/`addressPointInBytes` are attributed to
+/// `MetadataBoundsProtocol`.
+package enum MetadataBoundsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: bit-packing constants for MetadataBounds (no MachO fixture
+ // is required; the Suite verifies the memberwise round-trip directly).
+ // Phase C5 kept this Suite sentinel — see CoverageAllowlistEntries
+ // for the rationale.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MetadataBoundsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ /// Constants used by the companion Suite to drive the round-trip.
+ static let sampleNegativeSizeInWords: UInt32 = 0x2
+ static let samplePositiveSizeInWords: UInt32 = 0x10
+ static let sampleOffset: Int = 0x100
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MetadataBoundsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataBoundsProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataBoundsProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..b4293c5d
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataBoundsProtocolBaselineGenerator.swift
@@ -0,0 +1,52 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MetadataBoundsProtocolBaseline.swift`.
+///
+/// Per the protocol-extension attribution rule (see `BaselineGenerator.swift`),
+/// `totalSizeInBytes` and `addressPointInBytes` are declared in
+/// `extension MetadataBoundsProtocol { ... }` and attribute to the
+/// protocol, not to concrete bounds carriers like `MetadataBounds`.
+///
+/// The Suite uses a constant `MetadataBounds` round-trip to assert the
+/// derived sizes match the closed-form formula
+/// `(neg + pos) * sizeof(StoredPointer)` and
+/// `neg * sizeof(StoredPointer)` respectively.
+package enum MetadataBoundsProtocolBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "addressPointInBytes",
+ "totalSizeInBytes",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // The derived sizes are computed from the closed-form formulas
+ // totalSizeInBytes = (neg + pos) * sizeof(StoredPointer)
+ // addressPointInBytes = neg * sizeof(StoredPointer)
+ // The Suite drives a constant MetadataBounds(neg=2, pos=16) and
+ // checks both expressions.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MetadataBoundsProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ /// Constants matching `MetadataBoundsBaseline` so the Suites
+ /// stay aligned without cross-baseline references.
+ static let sampleNegativeSizeInWords: UInt32 = 0x2
+ static let samplePositiveSizeInWords: UInt32 = 0x10
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MetadataBoundsProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataInitialization/ForeignMetadataInitializationBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataInitialization/ForeignMetadataInitializationBaselineGenerator.swift
new file mode 100644
index 00000000..38a68845
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataInitialization/ForeignMetadataInitializationBaselineGenerator.swift
@@ -0,0 +1,44 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/ForeignMetadataInitializationBaseline.swift`.
+///
+/// `ForeignMetadataInitialization` is a single-`completionFunction`-pointer
+/// trailing-objects payload appended to descriptors with the
+/// `hasForeignMetadataInitialization` bit. The bit fires for foreign-class
+/// metadata bridging (e.g. `@_objcRuntimeName` / Core Foundation classes
+/// imported into Swift). The `SymbolTestsCore` fixture does not declare any
+/// such types, so no live entry is materialised.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum ForeignMetadataInitializationBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // SymbolTestsCore declares no foreign-class types, so no live
+ // ForeignMetadataInitialization entry is materialised. The Suite
+ // asserts the type's structural members exist.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ForeignMetadataInitializationBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ForeignMetadataInitializationBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataInitialization/SingletonMetadataInitializationBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataInitialization/SingletonMetadataInitializationBaselineGenerator.swift
new file mode 100644
index 00000000..f2fe6b4f
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataInitialization/SingletonMetadataInitializationBaselineGenerator.swift
@@ -0,0 +1,101 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/SingletonMetadataInitializationBaseline.swift`.
+///
+/// `SingletonMetadataInitialization` is the trailing-objects payload appended
+/// to descriptors with the `hasSingletonMetadataInitialization` bit. It
+/// carries three `RelativeOffset`s: `initializationCacheOffset`,
+/// `incompleteMetadata`, and `completionFunction`. The bit fires for resilient
+/// classes (those that cross module boundaries on inheritance) and certain
+/// generic-class shapes; the `SymbolTestsCore` fixture's
+/// `Classes.ExternalSwiftSubclassTest`, `Classes.ExternalObjCSubclassTest`,
+/// and `GenericFieldLayout.GenericClass*InheritNSObject` declarations are
+/// candidate carriers.
+///
+/// We discover a representative descriptor at generator runtime by walking
+/// every class descriptor and picking the first one whose bit is set;
+/// emitting only the relative-offset values keeps the baseline stable across
+/// MachO rebuilds (the offsets are layout-invariant for a given fixture).
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum SingletonMetadataInitializationBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.class_singletonMetadataInitFirst(in: machO)
+ let classObject = try Class(descriptor: descriptor, in: machO)
+ let initialization = try required(classObject.singletonMetadataInitialization)
+
+ let entryExpr = emitEntryExpr(for: initialization, descriptorOffset: descriptor.offset)
+
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // The picker selects the first ClassDescriptor in SymbolTestsCore that
+ // carries the hasSingletonMetadataInitialization bit. Relative offsets
+ // are layout-invariant for a fixed source so the baseline stays
+ // stable across rebuilds.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum SingletonMetadataInitializationBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ /// `RelativeOffset` is `Int32`; we store it as `UInt64`
+ /// (bitPattern) here because `BaselineEmitter.hex` sign-extends
+ /// to UInt64, so negative Int32 values would not fit a signed
+ /// Int64 literal. The Suite reads the field via
+ /// `Int32(truncatingIfNeeded:)` to recover the signed value.
+ struct Entry {
+ let descriptorOffset: Int
+ let initializationCacheRelativeOffsetBits: UInt64
+ let incompleteMetadataRelativeOffsetBits: UInt64
+ let completionFunctionRelativeOffsetBits: UInt64
+ }
+
+ static let firstSingletonInit = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("SingletonMetadataInitializationBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for initialization: SingletonMetadataInitialization,
+ descriptorOffset: Int
+ ) -> String {
+ // RelativeOffset is `Int32`; the layout fields are the raw signed
+ // offsets relative to the descriptor. We emit them as UInt64
+ // bitPatterns since the hex helper sign-extends to UInt64 (negative
+ // Int32 values overflow a signed Int64 literal).
+ let cache = initialization.layout.initializationCacheOffset
+ let incomplete = initialization.layout.incompleteMetadata
+ let completion = initialization.layout.completionFunction
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ initializationCacheRelativeOffsetBits: \(raw: BaselineEmitter.hex(cache)),
+ incompleteMetadataRelativeOffsetBits: \(raw: BaselineEmitter.hex(incomplete)),
+ completionFunctionRelativeOffsetBits: \(raw: BaselineEmitter.hex(completion))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..69f302b4
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataProtocolBaselineGenerator.swift
@@ -0,0 +1,72 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MetadataProtocolBaseline.swift`.
+///
+/// Per the protocol-extension attribution rule (see `BaselineGenerator.swift`),
+/// every method declared in the multiple `extension MetadataProtocol { ... }`
+/// blocks (and the constrained `extension MetadataProtocol where HeaderType:
+/// TypeMetadataHeaderBaseProtocol { ... }` blocks) attributes to
+/// `MetadataProtocol`, not to concrete metadatas. The (MachO, in-process,
+/// ReadingContext) overload triples collapse to a single `MethodKey` under
+/// PublicMemberScanner's name-only keying.
+///
+/// The Suite (`MetadataProtocolTests`) materialises a
+/// `StructMetadata`-conforming carrier (`Structs.StructTest`) via a
+/// MachOImage metadata accessor and asserts each method:
+/// - Static factories (`createInMachO`, `createInProcess`) round-trip
+/// `Metadata.self`-typed lookups against a runtime metatype.
+/// - Wrapper accessors (`asMetadataWrapper`, `asMetadata`,
+/// `asFullMetadata`) round-trip the offset.
+/// - Pointer-flavoured `asMetatype()` recovers the original `Any.Type`.
+/// - Property `kind` matches `MetadataKind.struct` for the StructTest
+/// carrier.
+/// - `valueWitnesses`/`typeLayout` resolve through the full-metadata
+/// header.
+/// - `isAnyExistentialType` is `false` for the struct carrier.
+/// - `typeContextDescriptorWrapper` resolves to the StructTest descriptor.
+package enum MetadataProtocolBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared in `extension MetadataProtocol { ... }`
+ // blocks (across body, in-process, and ReadingContext variants).
+ // Overload pairs collapse to single MethodKey entries under
+ // PublicMemberScanner's name-only key.
+ let registered = [
+ "asFullMetadata",
+ "asMetadata",
+ "asMetadataWrapper",
+ "asMetatype",
+ "createInMachO",
+ "createInProcess",
+ "isAnyExistentialType",
+ "kind",
+ "typeContextDescriptorWrapper",
+ "typeLayout",
+ "valueWitnesses",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // MetadataProtocol's extension members operate against a live
+ // metadata carrier; the carrier comes from MachOImage's accessor
+ // function. The companion Suite verifies the cross-reader equality
+ // block at runtime against this name-only baseline.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MetadataProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MetadataProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataRequestBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataRequestBaselineGenerator.swift
new file mode 100644
index 00000000..0f851c13
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataRequestBaselineGenerator.swift
@@ -0,0 +1,60 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MetadataRequestBaseline.swift`.
+///
+/// `MetadataRequest` is a `MutableFlagSet` packing `state` (8 bits) and
+/// `isBlocking` (1 bit) into a single `Int` raw value. The Suite drives the
+/// type via constant round-trips through the three initialisers (no MachO
+/// fixture is required) and asserts the bit-packing invariants. Phase C5
+/// wraps the assertions in `usingInProcessOnly` so the suite is classified
+/// as `.inProcessOnly` rather than `.sentinel` — the `InProcessContext` is
+/// otherwise unused.
+///
+/// Public surface (after PublicMemberScanner name-only collapsing):
+/// - `init(rawValue:)`, `init`, `init(state:isBlocking:)` — three distinct
+/// keys (the parameter labels disambiguate them under
+/// PublicMemberScanner).
+/// - `completeAndBlocking` — static convenience constructor.
+/// - `state`, `isBlocking`, `rawValue` — projected bitfield accessors
+/// (rawValue inherited from `MutableFlagSet` but redeclared in body).
+package enum MetadataRequestBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "completeAndBlocking",
+ "init",
+ "init(rawValue:)",
+ "init(state:isBlocking:)",
+ "isBlocking",
+ "rawValue",
+ "state",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: bit-packing constants for MetadataRequest's MutableFlagSet
+ // (no MachO fixture is required; the Suite verifies invariants
+ // directly under `usingInProcessOnly`).
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MetadataRequestBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ /// Constants used by the companion Suite to drive bit-packing
+ /// round-trips.
+ static let completeAndBlockingExpectedRawValue: Int = 0x100
+ static let layoutCompleteRawValue: Int = 0x3F
+ static let abstractRawValue: Int = 0xFF
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MetadataRequestBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataResponseBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataResponseBaselineGenerator.swift
new file mode 100644
index 00000000..18e91918
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataResponseBaselineGenerator.swift
@@ -0,0 +1,48 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MetadataResponseBaseline.swift`.
+///
+/// `MetadataResponse` is the (`Pointer`, `MetadataState`)
+/// tuple returned by `MetadataAccessorFunction.callAsFunction(...)`. Live
+/// instances are reachable only through MachOImage's accessor invocation.
+/// The Suite (`MetadataResponseTests`) materialises a response by invoking
+/// `Structs.StructTest`'s accessor on the loaded MachOImage and asserts:
+/// - `value.resolve(in: machOImage)` returns a non-nil
+/// `MetadataWrapper.struct(_:)`.
+/// - `state` decodes a known state (`.complete` for blocking
+/// `MetadataRequest()` calls).
+///
+/// `init(value:state:)` is internal-scoped on the source side; the only
+/// public members the scanner sees are `value` and `state`.
+package enum MetadataResponseBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "state",
+ "value",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // MetadataResponse is materialised solely through MachOImage's
+ // accessor invocation; the Suite verifies the public projections at
+ // runtime against this name-only baseline.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MetadataResponseBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MetadataResponseBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataWrapperBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataWrapperBaselineGenerator.swift
new file mode 100644
index 00000000..e7876527
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetadataWrapperBaselineGenerator.swift
@@ -0,0 +1,53 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/MetadataWrapperBaseline.swift`.
+///
+/// `MetadataWrapper` is the `@CaseCheckable(.public)` /
+/// `@AssociatedValue(.public)` enum dispatching across every metadata
+/// kind. PublicMemberScanner sees only the source-declared members
+/// (macro-injected case-presence helpers and associated-value extractors
+/// are out of scope per `GenericRequirementContentBaseline`'s pattern):
+/// - `anyMetadata`, `metadata` (computed properties)
+/// - `valueWitnessTable` (3 overloads collapsing to one MethodKey)
+/// - `resolve` (3 overloads collapsing to one MethodKey)
+///
+/// Live wrappers are materialised only via MachOImage's accessor
+/// (`StructTest`'s `MetadataResponse.value.resolve(in:)`). The Suite asserts
+/// the wrapper enum's `case` discriminant matches `.struct` and the
+/// projected `metadata`/`anyMetadata` round-trip the offset.
+package enum MetadataWrapperBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "anyMetadata",
+ "metadata",
+ "resolve",
+ "valueWitnessTable",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // MetadataWrapper is materialised through MachOImage's accessor
+ // (StructTest); the macro-injected case-presence helpers and
+ // associated-value extractors are not visited by
+ // PublicMemberScanner, so only the four source-declared members
+ // appear in the registered set.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MetadataWrapperBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MetadataWrapperBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetatypeMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetatypeMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..47c9bcb6
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/MetatypeMetadataBaselineGenerator.swift
@@ -0,0 +1,51 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/MetatypeMetadataBaseline.swift`.
+///
+/// Phase C2: emits ABI literals derived from in-process resolution of
+/// `type(of: Int.self)`'s `MetatypeMetadata`. The kind raw value matches
+/// `MetadataKind.metatype` (0x304); `instanceType` points to `Int.self`'s
+/// metadata (a struct kind 0x200).
+///
+/// Registered names track the wrapper's directly-declared public
+/// surface (`layout`, `offset`); the layout subfields (`kind`,
+/// `instanceType`) are exercised inside the `layout` test body.
+package enum MetatypeMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let pointer = InProcessMetadataPicker.stdlibIntMetatype
+ let context = InProcessContext()
+ let metatype = try MetatypeMetadata.resolve(at: pointer, in: context)
+ let kindRaw = metatype.kind.rawValue
+
+ let registered = ["layout", "offset"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess (stdlib `type(of: Int.self)`); no Mach-O section presence.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum MetatypeMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let kindRawValue: UInt32
+ }
+
+ static let stdlibIntMetatype = Entry(
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRaw))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("MetatypeMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/SingletonMetadataPointerBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/SingletonMetadataPointerBaselineGenerator.swift
new file mode 100644
index 00000000..24fb0e92
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Metadata/SingletonMetadataPointerBaselineGenerator.swift
@@ -0,0 +1,46 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/SingletonMetadataPointerBaseline.swift`.
+///
+/// `SingletonMetadataPointer` is a trailing-objects payload appended to
+/// descriptors with the `hasSingletonMetadataPointer` bit. The
+/// `SymbolTestsCore` fixture has no descriptor that surfaces this bit (it
+/// fires for cross-module canonical metadata caching, which the fixture
+/// doesn't use), so no live entry is materialised. We emit only the
+/// registered member names. Phase C5 considered conversion via
+/// `InProcessMetadataPicker` and kept sentinel because the trailing
+/// payload requires a descriptor with the corresponding bit, not just a
+/// runtime metadata pointer.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum SingletonMetadataPointerBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: SymbolTestsCore declares no descriptors carrying a singleton-
+ // metadata-pointer trailing object, so no live entry is materialised.
+ // The Suite asserts the type's structural members exist. Phase C5
+ // kept this Suite sentinel — see CoverageAllowlistEntries.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum SingletonMetadataPointerBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("SingletonMetadataPointerBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ModuleContextBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ModuleContextBaselineGenerator.swift
new file mode 100644
index 00000000..0ac61e85
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ModuleContextBaselineGenerator.swift
@@ -0,0 +1,73 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ModuleContextBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `ModuleContext` is the high-level wrapper around a
+/// `ModuleContextDescriptor`. Its only ivars are `descriptor` and `name`.
+/// We embed both: `name` as a string literal and `descriptor.offset` as
+/// a hex value.
+package enum ModuleContextBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.module_SymbolTestsCore(in: machO)
+ let context = try ModuleContext(descriptor: descriptor, in: machO)
+
+ let entryExpr = emitEntryExpr(for: context)
+
+ // Public members declared directly in ModuleContext.swift.
+ // Both `init(descriptor:in:)` overloads (MachO + ReadingContext)
+ // collapse to a single MethodKey under PublicMemberScanner's
+ // name-based deduplication.
+ let registered = [
+ "descriptor",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "name",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ModuleContextBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let name: String
+ }
+
+ static let symbolTestsCore = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ModuleContextBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for instance: ModuleContext) -> String {
+ let descriptorOffset = instance.descriptor.offset
+ let name = instance.name
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ name: \(literal: name)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ModuleContextDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ModuleContextDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..bc367c64
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ModuleContextDescriptorBaselineGenerator.swift
@@ -0,0 +1,64 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ModuleContextDescriptorBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `ModuleContextDescriptor` declares only the `offset` and `layout` ivars
+/// (`init(layout:offset:)` is filtered as memberwise-synthesized). The
+/// `Layout` carries the `flags + parent + name` triple; `flags.rawValue`
+/// is the only stable scalar worth embedding here. The `name` lookup lives
+/// on `NamedContextDescriptorProtocol` and is exercised by the
+/// `ModuleContextTests` Suite via the wrapper.
+package enum ModuleContextDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.module_SymbolTestsCore(in: machO)
+ let entryExpr = emitEntryExpr(for: descriptor)
+
+ let registered = ["layout", "offset"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ModuleContextDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutFlagsRawValue: UInt32
+ }
+
+ static let symbolTestsCore = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ModuleContextDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for descriptor: ModuleContextDescriptor) -> String {
+ let offset = descriptor.offset
+ let flagsRaw = descriptor.layout.flags.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/NamedContextDescriptorProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/NamedContextDescriptorProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..6002b78a
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/NamedContextDescriptorProtocolBaselineGenerator.swift
@@ -0,0 +1,72 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/NamedContextDescriptorProtocolBaseline.swift`.
+///
+/// Per the protocol-extension attribution rule (see `BaselineGenerator.swift`),
+/// `name(in:)` and `mangledName(in:)` are declared in
+/// `extension NamedContextDescriptorProtocol { ... }` and attribute to the
+/// protocol, not to concrete descriptor types like `StructDescriptor`.
+///
+/// Picker: `Structs.StructTest` — its `name(in:)` is the stable string
+/// `"StructTest"` we embed verbatim.
+package enum NamedContextDescriptorProtocolBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let name = try descriptor.name(in: machO)
+ let hasMangledName = (try? descriptor.mangledName(in: machO)) != nil
+
+ let entryExpr = emitEntryExpr(name: name, hasMangledName: hasMangledName)
+
+ let registered = [
+ "mangledName",
+ "name",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // The MangledName payload is a deep ABI tree we don't embed as a
+ // literal; the companion Suite (NamedContextDescriptorProtocolTests)
+ // verifies the methods produce cross-reader-consistent results at
+ // runtime against the presence flag recorded here.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum NamedContextDescriptorProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let name: String
+ let hasMangledName: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("NamedContextDescriptorProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(name: String, hasMangledName: Bool) -> String {
+ let expr: ExprSyntax = """
+ Entry(
+ name: \(literal: name),
+ hasMangledName: \(literal: hasMangledName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..51a15e95
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueMetadataBaselineGenerator.swift
@@ -0,0 +1,45 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/OpaqueMetadataBaseline.swift`.
+///
+/// `OpaqueMetadata` is a single-`kind`-field metadata for opaque
+/// types built into the Swift runtime (e.g. `Builtin.RawPointer`'s
+/// metadata). It is materialised by the runtime; no static record is
+/// reachable from SymbolTestsCore section walks.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum OpaqueMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // OpaqueMetadata wraps a runtime-only opaque-type metadata
+ // header; no static carrier is reachable from SymbolTestsCore.
+ // The Suite asserts structural members against a synthetic
+ // memberwise instance.
+ //
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum OpaqueMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("OpaqueMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueTypeBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueTypeBaselineGenerator.swift
new file mode 100644
index 00000000..2a634fd0
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueTypeBaselineGenerator.swift
@@ -0,0 +1,60 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/OpaqueTypeBaseline.swift`.
+///
+/// `OpaqueType` is the high-level wrapper around `OpaqueTypeDescriptor`.
+/// Beyond holding the descriptor it pre-resolves the optional
+/// `genericContext`, the trailing `[MangledName]` underlying-type
+/// arguments, and the optional `invertedProtocols` set.
+///
+/// The fixture's `OpaqueReturnTypes` declarations DO cause the compiler
+/// to emit opaque type descriptors, but the SymbolTestsCore build
+/// indexes them in a way that's not directly reachable from
+/// `swift.contextDescriptors` nor from any context's parent chain on
+/// the current toolchain. The Suite registers the type's public
+/// surface and exercises members against a synthetic memberwise
+/// instance.
+///
+/// Adding a fixture variant that surfaces an opaque type via a
+/// reachable channel (e.g. a top-level `var x: some P` whose
+/// underlying-type relationship can be walked back) would let the
+/// Suite exercise the live carriers; the present fixture does not.
+package enum OpaqueTypeBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared in OpaqueType.swift.
+ let registered = [
+ "descriptor",
+ "genericContext",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "invertedProtocols",
+ "underlyingTypeArgumentMangledNames",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // OpaqueType wraps an OpaqueTypeDescriptor; SymbolTestsCore's
+ // opaque-type descriptors aren't directly reachable from
+ // swift.contextDescriptors or via parent chains on the current
+ // toolchain. The Suite registers the public surface and
+ // exercises members against a synthetic memberwise instance.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum OpaqueTypeBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("OpaqueTypeBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueTypeDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueTypeDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..5b67b702
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueTypeDescriptorBaselineGenerator.swift
@@ -0,0 +1,46 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/OpaqueTypeDescriptorBaseline.swift`.
+///
+/// `OpaqueTypeDescriptor` is the section-stored opaque type descriptor
+/// emitted by the compiler for each `some P` opaque return type.
+/// SymbolTestsCore's opaque-type descriptors aren't directly reachable
+/// from `swift.contextDescriptors` or via parent chains on the current
+/// toolchain — see the OpaqueType Suite for the same caveat. The Suite
+/// here registers the public surface and exercises members against a
+/// synthetic memberwise instance.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum OpaqueTypeDescriptorBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // OpaqueTypeDescriptor — see OpaqueTypeBaseline for the
+ // discoverability caveat. Synthetic memberwise instance only.
+ //
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum OpaqueTypeDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("OpaqueTypeDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueTypeDescriptorProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueTypeDescriptorProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..18faca0b
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/OpaqueType/OpaqueTypeDescriptorProtocolBaselineGenerator.swift
@@ -0,0 +1,45 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/OpaqueTypeDescriptorProtocolBaseline.swift`.
+///
+/// `OpaqueTypeDescriptorProtocol` extends every conforming type
+/// (currently only `OpaqueTypeDescriptor`) with the
+/// `numUnderlyingTypeArugments` accessor — the kind-specific flags
+/// raw value cast to `Int`. SymbolTestsCore's opaque-type descriptors
+/// aren't directly reachable on the current toolchain (see
+/// OpaqueTypeBaseline), so the Suite exercises the accessor against a
+/// synthetic memberwise `OpaqueTypeDescriptor`.
+package enum OpaqueTypeDescriptorProtocolBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "numUnderlyingTypeArugments",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // OpaqueTypeDescriptorProtocol — see OpaqueTypeBaseline for the
+ // discoverability caveat. The Suite exercises the
+ // numUnderlyingTypeArugments accessor against a synthetic
+ // memberwise OpaqueTypeDescriptor whose
+ // ContextDescriptorFlags' kind-specific bits encode a known
+ // count.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum OpaqueTypeDescriptorProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("OpaqueTypeDescriptorProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/Invertible/InvertibleProtocolSetBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/Invertible/InvertibleProtocolSetBaselineGenerator.swift
new file mode 100644
index 00000000..70b96811
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/Invertible/InvertibleProtocolSetBaselineGenerator.swift
@@ -0,0 +1,90 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/InvertibleProtocolSetBaseline.swift`.
+///
+/// `InvertibleProtocolSet` is a 16-bit `OptionSet` over the invertible
+/// protocol kinds (`copyable`, `escapable`). Both `Copyable` and
+/// `Escapable` are stdlib protocols with no `__swift5_protos` records of
+/// their own (the bits are encoded inline on each type's
+/// `RequirementInSignature`), so the baseline records canonical synthetic
+/// raw values for each branch:
+/// - default (`0x0`) — neither copyable nor escapable
+/// - copyable only (`0x1`)
+/// - escapable only (`0x2`)
+/// - both (`0x3`) — exercises `hasCopyable && hasEscapable`
+package enum InvertibleProtocolSetBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let noneEntry = emitEntryExpr(rawValue: 0x0)
+ let copyableEntry = emitEntryExpr(rawValue: 0x1)
+ let escapableEntry = emitEntryExpr(rawValue: 0x2)
+ let bothEntry = emitEntryExpr(rawValue: 0x3)
+
+ // Public members declared directly in InvertibleProtocolSet.swift.
+ // `init(rawValue:)` and `rawValue` come from the OptionSet conformance.
+ // The static `.copyable` / `.escapable` OptionSet values surface as
+ // declared static vars.
+ let registered = [
+ "copyable",
+ "escapable",
+ "hasCopyable",
+ "hasEscapable",
+ "init(rawValue:)",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // InvertibleProtocolSet has no live SymbolTestsCore source (the
+ // Copyable/Escapable bits are encoded inline on type generic
+ // signatures), so the baseline embeds synthetic raw values that
+ // exercise each branch (none / copyable-only / escapable-only / both).
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum InvertibleProtocolSetBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt16
+ let hasCopyable: Bool
+ let hasEscapable: Bool
+ }
+
+ static let none = \(raw: noneEntry)
+
+ static let copyableOnly = \(raw: copyableEntry)
+
+ static let escapableOnly = \(raw: escapableEntry)
+
+ static let both = \(raw: bothEntry)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("InvertibleProtocolSetBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(rawValue: UInt16) -> String {
+ let set = InvertibleProtocolSet(rawValue: rawValue)
+ let hasCopyable = set.hasCopyable
+ let hasEscapable = set.hasEscapable
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ hasCopyable: \(literal: hasCopyable),
+ hasEscapable: \(literal: hasEscapable)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/Invertible/InvertibleProtocolsRequirementCountBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/Invertible/InvertibleProtocolsRequirementCountBaselineGenerator.swift
new file mode 100644
index 00000000..63528e82
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/Invertible/InvertibleProtocolsRequirementCountBaselineGenerator.swift
@@ -0,0 +1,68 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/InvertibleProtocolsRequirementCountBaseline.swift`.
+///
+/// `InvertibleProtocolsRequirementCount` is a thin `RawRepresentable`
+/// wrapper around a `UInt16` count of invertible-protocol requirements
+/// in a generic signature. It surfaces no derived accessors — the public
+/// API is the synthesized `init(rawValue:)` plus the `rawValue` storage.
+///
+/// The fixture has no live count to source from (the count is implied by
+/// the surrounding requirement-signature scan, not stored as a separate
+/// value), so the baseline records a synthetic round-trip pair.
+package enum InvertibleProtocolsRequirementCountBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let zeroEntry = emitEntryExpr(rawValue: 0)
+ let smallEntry = emitEntryExpr(rawValue: 3)
+
+ // Public members declared directly in InvertibleProtocolsRequirementCount.swift.
+ let registered = [
+ "init(rawValue:)",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // InvertibleProtocolsRequirementCount has no live SymbolTestsCore
+ // source (the count is implied by the surrounding requirement
+ // scan), so the baseline embeds synthetic raw values.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum InvertibleProtocolsRequirementCountBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt16
+ }
+
+ static let zero = \(raw: zeroEntry)
+
+ static let small = \(raw: smallEntry)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("InvertibleProtocolsRequirementCountBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(rawValue: UInt16) -> String {
+ let count = InvertibleProtocolsRequirementCount(rawValue: rawValue)
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(count.rawValue))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ObjC/ObjCProtocolPrefixBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ObjC/ObjCProtocolPrefixBaselineGenerator.swift
new file mode 100644
index 00000000..62453517
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ObjC/ObjCProtocolPrefixBaselineGenerator.swift
@@ -0,0 +1,71 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ObjCProtocolPrefixBaseline.swift`.
+///
+/// `ObjCProtocolPrefix` is the in-memory prefix of an Objective-C
+/// `protocol_t` record (the `isa` slot plus the name pointer). We
+/// materialize one via the fixture's ObjC inheriting protocol
+/// (`Protocols.ObjCInheritingProtocolTest: NSObjectProtocol`), which
+/// synthesizes an ObjC reference whose prefix resolves to
+/// `NSObject` (the runtime backing of the `NSObjectProtocol`).
+package enum ObjCProtocolPrefixBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let prefix = try BaselineFixturePicker.objcProtocolPrefix_first(in: machO)
+ let name = try prefix.name(in: machO)
+ let entryExpr = emitEntryExpr(offset: prefix.offset, name: name)
+
+ // Public members declared directly in ObjCProtocolPrefix.swift.
+ // The `name(in:)` and `mangledName(in:)` overloads (MachO + InProcess
+ // + ReadingContext) collapse to single MethodKeys under the
+ // scanner's name-based deduplication. `init(layout:offset:)` is
+ // filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "mangledName",
+ "name",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ObjCProtocolPrefixBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let name: String
+ }
+
+ static let firstPrefix = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ObjCProtocolPrefixBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(offset: Int, name: String) -> String {
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ name: \(literal: name)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ObjC/RelativeObjCProtocolPrefixBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ObjC/RelativeObjCProtocolPrefixBaselineGenerator.swift
new file mode 100644
index 00000000..4eca5d22
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ObjC/RelativeObjCProtocolPrefixBaselineGenerator.swift
@@ -0,0 +1,50 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/RelativeObjCProtocolPrefixBaseline.swift`.
+///
+/// `RelativeObjCProtocolPrefix` is the relative-pointer variant of the
+/// ObjC protocol prefix used in serialized binary contexts. The
+/// `SymbolTestsCore` fixture's ObjC reference uses the absolute-pointer
+/// `ObjCProtocolPrefix` form, not the relative variant. The baseline
+/// therefore registers the public members for the Coverage Invariant
+/// test; the Suite documents the absent runtime coverage.
+package enum RelativeObjCProtocolPrefixBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in RelativeObjCProtocolPrefix.swift.
+ // The two `mangledName(in:)` overloads (MachO + ReadingContext) and
+ // the standalone `mangledName()` collapse to a single MethodKey
+ // under the scanner's name-based deduplication. `init(layout:offset:)`
+ // is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "mangledName",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // The SymbolTestsCore fixture does not surface a
+ // RelativeObjCProtocolPrefix payload (the absolute-pointer
+ // `ObjCProtocolPrefix` is used for the NSObjectProtocol witness).
+ // The Suite documents the missing runtime coverage.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum RelativeObjCProtocolPrefixBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("RelativeObjCProtocolPrefixBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolBaseRequirementBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolBaseRequirementBaselineGenerator.swift
new file mode 100644
index 00000000..b8df424b
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolBaseRequirementBaselineGenerator.swift
@@ -0,0 +1,69 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolBaseRequirementBaseline.swift`.
+///
+/// `ProtocolBaseRequirement` is the empty-layout marker companion to
+/// `ProtocolRequirement` (both declared in `ProtocolRequirement.swift`).
+/// It carries no payload other than the trailing-object header offset.
+///
+/// Picker: `Protocols.ProtocolWitnessTableTest` — the protocol's
+/// `baseRequirement` slot resolves to a live instance.
+package enum ProtocolBaseRequirementBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.protocol_ProtocolWitnessTableTest(in: machO)
+ let protocolType = try `Protocol`(descriptor: descriptor, in: machO)
+ let baseRequirement = try required(protocolType.baseRequirement)
+
+ let entryExpr = emitEntryExpr(for: baseRequirement)
+
+ // Public members declared on `ProtocolBaseRequirement` (the second
+ // struct in ProtocolRequirement.swift). `init(layout:offset:)` is
+ // filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolBaseRequirementBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ }
+
+ static let witnessTableTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolBaseRequirementBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for baseRequirement: ProtocolBaseRequirement) -> String {
+ let offset = baseRequirement.offset
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..a95e2f05
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolBaselineGenerator.swift
@@ -0,0 +1,109 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolBaseline.swift`.
+///
+/// `Protocol` is the high-level wrapper around `ProtocolDescriptor` —
+/// it eagerly materializes the descriptor's name, base requirement,
+/// requirementInSignatures, and trailing `ProtocolRequirement` array.
+///
+/// Two pickers feed the baseline so multiple branches are witnessed:
+/// - `Protocols.ProtocolTest` — exercises `requirementInSignatures`
+/// (its `Body: ProtocolTest` associated-type constraint surfaces a
+/// non-empty requirement-in-signature array).
+/// - `Protocols.ProtocolWitnessTableTest` — exercises the trailing
+/// `requirements` array (5 method requirements: `a`/`b`/`c`/`d`/`e`).
+package enum ProtocolBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let protocolTestDescriptor = try BaselineFixturePicker.protocol_ProtocolTest(in: machO)
+ let protocolTest = try `Protocol`(descriptor: protocolTestDescriptor, in: machO)
+ let protocolTestExpr = emitEntryExpr(for: protocolTest)
+
+ let witnessTableTestDescriptor = try BaselineFixturePicker.protocol_ProtocolWitnessTableTest(in: machO)
+ let witnessTableTest = try `Protocol`(descriptor: witnessTableTestDescriptor, in: machO)
+ let witnessTableTestExpr = emitEntryExpr(for: witnessTableTest)
+
+ // Public members declared directly in Protocol.swift (across the main
+ // body and two same-file extensions, both in the ReadingContext block).
+ // Stored properties (descriptor/protocolFlags/name/baseRequirement/
+ // requirementInSignatures/requirements) collapse with the two
+ // `init(descriptor:in:)` overloads under PublicMemberScanner's name-
+ // based deduplication.
+ let registered = [
+ "baseRequirement",
+ "descriptor",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "name",
+ "numberOfRequirements",
+ "numberOfRequirementsInSignature",
+ "protocolFlags",
+ "requirementInSignatures",
+ "requirements",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let name: String
+ let descriptorOffset: Int
+ let protocolFlagsRawValue: UInt16
+ let numberOfRequirements: Int
+ let numberOfRequirementsInSignature: Int
+ let hasBaseRequirement: Bool
+ let requirementsCount: Int
+ let requirementInSignaturesCount: Int
+ }
+
+ static let protocolTest = \(raw: protocolTestExpr)
+
+ static let protocolWitnessTableTest = \(raw: witnessTableTestExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for protocolType: MachOSwiftSection.`Protocol`) -> String {
+ let name = protocolType.name
+ let descriptorOffset = protocolType.descriptor.offset
+ let protocolFlagsRawValue = protocolType.protocolFlags.rawValue
+ let numberOfRequirements = protocolType.numberOfRequirements
+ let numberOfRequirementsInSignature = protocolType.numberOfRequirementsInSignature
+ let hasBaseRequirement = protocolType.baseRequirement != nil
+ let requirementsCount = protocolType.requirements.count
+ let requirementInSignaturesCount = protocolType.requirementInSignatures.count
+
+ let expr: ExprSyntax = """
+ Entry(
+ name: \(literal: name),
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ protocolFlagsRawValue: \(raw: BaselineEmitter.hex(protocolFlagsRawValue)),
+ numberOfRequirements: \(literal: numberOfRequirements),
+ numberOfRequirementsInSignature: \(literal: numberOfRequirementsInSignature),
+ hasBaseRequirement: \(literal: hasBaseRequirement),
+ requirementsCount: \(literal: requirementsCount),
+ requirementInSignaturesCount: \(literal: requirementInSignaturesCount)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolContextDescriptorFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolContextDescriptorFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..f6c6461f
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolContextDescriptorFlagsBaselineGenerator.swift
@@ -0,0 +1,80 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOExtensions
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolContextDescriptorFlagsBaseline.swift`.
+///
+/// `ProtocolContextDescriptorFlags` is the kind-specific 16-bit `FlagSet`
+/// reachable via `ContextDescriptorFlags.kindSpecificFlags?.protocolFlags`
+/// for protocol-kind context descriptors. It exposes `isResilient`,
+/// `classConstraint`, and `specialProtocolKind` accessors plus the
+/// `init(rawValue:)` synthesized initializer and the `rawValue` storage.
+///
+/// Picker: `Protocols.ProtocolTest` — its kind-specific flags slot
+/// resolves to a real `ProtocolContextDescriptorFlags` value.
+package enum ProtocolContextDescriptorFlagsBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.protocol_ProtocolTest(in: machO)
+ let flags = try required(descriptor.layout.flags.kindSpecificFlags?.protocolFlags)
+ let entryExpr = emitEntryExpr(for: flags)
+
+ // Public members declared directly in ProtocolContextDescriptorFlags.swift.
+ let registered = [
+ "classConstraint",
+ "init(rawValue:)",
+ "isResilient",
+ "rawValue",
+ "specialProtocolKind",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolContextDescriptorFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt16
+ let isResilient: Bool
+ let classConstraintRawValue: UInt8
+ let specialProtocolKindRawValue: UInt8
+ }
+
+ static let protocolTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolContextDescriptorFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for flags: ProtocolContextDescriptorFlags) -> String {
+ let rawValue = flags.rawValue
+ let isResilient = flags.isResilient
+ let classConstraintRawValue = flags.classConstraint.rawValue
+ let specialProtocolKindRawValue = flags.specialProtocolKind.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ isResilient: \(literal: isResilient),
+ classConstraintRawValue: \(raw: BaselineEmitter.hex(classConstraintRawValue)),
+ specialProtocolKindRawValue: \(raw: BaselineEmitter.hex(specialProtocolKindRawValue))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..175a3104
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolDescriptorBaselineGenerator.swift
@@ -0,0 +1,87 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolDescriptorBaseline.swift`.
+///
+/// Members directly declared in `ProtocolDescriptor.swift` (across the body
+/// and three same-file extensions). Protocol-extension methods that surface
+/// at compile-time — `name(in:)`, `mangledName(in:)` — live on
+/// `NamedContextDescriptorProtocol` and are exercised in Task 6 under
+/// `NamedContextDescriptorProtocolTests`. The `parent`/`genericContext`/
+/// etc. lookups live on `ContextDescriptorProtocol` (see `ContextDescriptorProtocolTests`).
+///
+/// Picker: `Protocols.ProtocolTest` — its `associatedTypes(in:)` returns
+/// `["Body"]`, so the entry-point method is exercised with non-empty data.
+package enum ProtocolDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.protocol_ProtocolTest(in: machO)
+ let entryExpr = try emitEntryExpr(for: descriptor, in: machO)
+
+ // Public members declared directly in ProtocolDescriptor.swift.
+ // The three `associatedTypes` overloads (MachO/InProcess/ReadingContext)
+ // collapse to a single MethodKey under the scanner's name-based
+ // deduplication. `init(layout:offset:)` is filtered as memberwise-
+ // synthesized.
+ let registered = [
+ "associatedTypes",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumRequirementsInSignature: UInt32
+ let layoutNumRequirements: UInt32
+ let layoutFlagsRawValue: UInt32
+ let associatedTypes: [String]
+ }
+
+ static let protocolTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for descriptor: ProtocolDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let offset = descriptor.offset
+ let layoutNumRequirementsInSignature = descriptor.layout.numRequirementsInSignature
+ let layoutNumRequirements = descriptor.layout.numRequirements
+ let layoutFlagsRawValue = descriptor.layout.flags.rawValue
+ let associatedTypes = try descriptor.associatedTypes(in: machO)
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumRequirementsInSignature: \(literal: layoutNumRequirementsInSignature),
+ layoutNumRequirements: \(literal: layoutNumRequirements),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(layoutFlagsRawValue)),
+ associatedTypes: \(literal: associatedTypes)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolDescriptorFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolDescriptorFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..f6bfa2fc
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolDescriptorFlagsBaselineGenerator.swift
@@ -0,0 +1,102 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolDescriptorFlagsBaseline.swift`.
+///
+/// `ProtocolDescriptorFlags` is the standalone 32-bit flag word used by
+/// the runtime metadata sections (NOT the kind-specific flags reachable
+/// via `ContextDescriptorFlags`). It exposes `isSwift`, `isResilient`,
+/// `classConstraint`, `dispatchStrategy`, `specialProtocolKind`, and
+/// `needsProtocolWitnessTable` accessors plus `init(rawValue:)` and
+/// `rawValue` storage.
+///
+/// The fixture has no live `ProtocolDescriptorFlags` instance to source
+/// from (it's a Runtime/ABI structure synthesized in-process), so the
+/// baseline records canonical bit patterns from synthetic raw values
+/// covering each accessor branch:
+/// - Swift (default): `0x1` (`isSwift: true`).
+/// - Resilient + Swift: `0x401`.
+/// - ObjC dispatch (`isSwift: false`, dispatchStrategy = objc): `0x0`.
+package enum ProtocolDescriptorFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let swiftEntry = emitEntryExpr(rawValue: 0x1)
+ let resilientEntry = emitEntryExpr(rawValue: 0x401)
+ let objcEntry = emitEntryExpr(rawValue: 0x0)
+
+ // Public members declared directly in ProtocolDescriptorFlags.swift.
+ // `init(rawValue:)` is the synthesized memberwise initializer.
+ let registered = [
+ "classConstraint",
+ "dispatchStrategy",
+ "init(rawValue:)",
+ "isResilient",
+ "isSwift",
+ "needsProtocolWitnessTable",
+ "rawValue",
+ "specialProtocolKind",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ProtocolDescriptorFlags has no live SymbolTestsCore source, so the
+ // baseline embeds synthetic raw values that exercise each branch
+ // (Swift default, Swift+resilient, ObjC dispatch).
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolDescriptorFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt32
+ let isSwift: Bool
+ let isResilient: Bool
+ let classConstraintRawValue: UInt8
+ let dispatchStrategyRawValue: UInt8
+ let specialProtocolKindRawValue: UInt8
+ let needsProtocolWitnessTable: Bool
+ }
+
+ static let swift = \(raw: swiftEntry)
+
+ static let resilient = \(raw: resilientEntry)
+
+ static let objc = \(raw: objcEntry)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolDescriptorFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(rawValue: UInt32) -> String {
+ let flags = ProtocolDescriptorFlags(rawValue: rawValue)
+ let isSwift = flags.isSwift
+ let isResilient = flags.isResilient
+ let classConstraintRawValue = flags.classConstraint.rawValue
+ let dispatchStrategyRawValue = flags.dispatchStrategy.rawValue
+ let specialProtocolKindRawValue = flags.specialProtocolKind.rawValue
+ let needsProtocolWitnessTable = flags.needsProtocolWitnessTable
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ isSwift: \(literal: isSwift),
+ isResilient: \(literal: isResilient),
+ classConstraintRawValue: \(raw: BaselineEmitter.hex(classConstraintRawValue)),
+ dispatchStrategyRawValue: \(raw: BaselineEmitter.hex(dispatchStrategyRawValue)),
+ specialProtocolKindRawValue: \(raw: BaselineEmitter.hex(specialProtocolKindRawValue)),
+ needsProtocolWitnessTable: \(literal: needsProtocolWitnessTable)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolDescriptorRefBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolDescriptorRefBaselineGenerator.swift
new file mode 100644
index 00000000..070d1413
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolDescriptorRefBaselineGenerator.swift
@@ -0,0 +1,116 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolDescriptorRefBaseline.swift`.
+///
+/// `ProtocolDescriptorRef` is a tagged pointer wrapping a Swift
+/// `ProtocolDescriptor` or an Objective-C protocol prefix, distinguished
+/// by the low bit (`isObjC`). The fixture has no live `ProtocolDescriptorRef`
+/// payload to source from (the type is a Runtime/ABI carrier reconstructed
+/// on demand), so the baseline records canonical bit patterns for both
+/// sides:
+/// - Swift form: the storage is the descriptor pointer (low bit clear).
+/// - ObjC form: the storage carries the low bit set.
+/// The Suite (`ProtocolDescriptorRefTests`) constructs the refs via the
+/// `forSwift(_:)` / `forObjC(_:)` factories and verifies the predicates
+/// and accessors round-trip, plus an end-to-end `name(in:)` check via
+/// the materialized ObjC inheriting protocol fixture.
+package enum ProtocolDescriptorRefBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let objcPrefix = try BaselineFixturePicker.objcProtocolPrefix_first(in: machO)
+ let objcPrefixOffset = objcPrefix.offset
+ let objcName = try objcPrefix.name(in: machO)
+
+ let swiftEntryExpr = emitSyntheticEntryExpr(storage: 0xDEAD_BEEF_0000, isObjC: false)
+ let objcEntryExpr = emitSyntheticEntryExpr(storage: 0xDEAD_BEEF_0001, isObjC: true)
+ let liveObjcExpr = emitLiveObjcEntryExpr(prefixOffset: objcPrefixOffset, name: objcName)
+
+ // Public members declared directly in ProtocolDescriptorRef.swift.
+ // Multiple overloads of `objcProtocol`/`swiftProtocol`/`name`
+ // (MachO + InProcess + ReadingContext) collapse to single MethodKeys
+ // under the scanner's name-based deduplication.
+ let registered = [
+ "dispatchStrategy",
+ "forObjC",
+ "forSwift",
+ "init(storage:)",
+ "isObjC",
+ "name",
+ "objcProtocol",
+ "storage",
+ "swiftProtocol",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ProtocolDescriptorRef has no live carrier in SymbolTestsCore; the
+ // baseline embeds synthetic storage bits to exercise the Swift/ObjC
+ // tagged-pointer split. The `liveObjc` entry pins the resolved name
+ // of the ObjC inheriting protocol's NSObjectProtocol witness.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolDescriptorRefBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let storage: UInt64
+ let isObjC: Bool
+ let dispatchStrategyRawValue: UInt8
+ }
+
+ struct LiveObjcEntry {
+ let prefixOffset: Int
+ let name: String
+ }
+
+ static let swift = \(raw: swiftEntryExpr)
+
+ static let objc = \(raw: objcEntryExpr)
+
+ static let liveObjc = \(raw: liveObjcExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolDescriptorRefBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitSyntheticEntryExpr(storage: UInt64, isObjC: Bool) -> String {
+ let ref = isObjC
+ ? ProtocolDescriptorRef.forObjC(StoredPointer(storage))
+ : ProtocolDescriptorRef.forSwift(StoredPointer(storage))
+ let dispatchStrategyRawValue = ref.dispatchStrategy.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ storage: \(raw: BaselineEmitter.hex(ref.storage)),
+ isObjC: \(literal: ref.isObjC),
+ dispatchStrategyRawValue: \(raw: BaselineEmitter.hex(dispatchStrategyRawValue))
+ )
+ """
+ return expr.description
+ }
+
+ private static func emitLiveObjcEntryExpr(prefixOffset: Int, name: String) -> String {
+ let expr: ExprSyntax = """
+ LiveObjcEntry(
+ prefixOffset: \(raw: BaselineEmitter.hex(prefixOffset)),
+ name: \(literal: name)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRecordBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRecordBaselineGenerator.swift
new file mode 100644
index 00000000..13b8621a
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRecordBaselineGenerator.swift
@@ -0,0 +1,82 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+import MachOKit
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolRecordBaseline.swift`.
+///
+/// `ProtocolRecord` is the one-pointer entry stored in the
+/// `__swift5_protos` section. We pick the first record from the fixture
+/// (which always exists, since `SymbolTestsCore` declares many protocols)
+/// and record its offset plus the resolved descriptor offset.
+package enum ProtocolRecordBaselineGenerator {
+ package static func generate(
+ in machO: MachOFile,
+ outputDirectory: URL
+ ) throws {
+ let record = try BaselineFixturePicker.protocolRecord_first(in: machO)
+ let resolvedDescriptor = try required(record.protocolDescriptor(in: machO))
+ let resolvedDescriptorOffset = resolvedDescriptor.offset
+ let resolvedDescriptorName = try resolvedDescriptor.name(in: machO)
+
+ let entryExpr = emitEntryExpr(
+ recordOffset: record.offset,
+ resolvedDescriptorOffset: resolvedDescriptorOffset,
+ resolvedDescriptorName: resolvedDescriptorName
+ )
+
+ // Public members declared directly in ProtocolRecord.swift.
+ // The two `protocolDescriptor(in:)` overloads (MachO + ReadingContext)
+ // collapse to a single MethodKey under the scanner's name-based
+ // deduplication. `init(layout:offset:)` is filtered as memberwise-
+ // synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ "protocolDescriptor",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolRecordBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let resolvedDescriptorOffset: Int
+ let resolvedDescriptorName: String
+ }
+
+ static let firstRecord = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolRecordBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ recordOffset: Int,
+ resolvedDescriptorOffset: Int,
+ resolvedDescriptorName: String
+ ) -> String {
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(recordOffset)),
+ resolvedDescriptorOffset: \(raw: BaselineEmitter.hex(resolvedDescriptorOffset)),
+ resolvedDescriptorName: \(literal: resolvedDescriptorName)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRequirementBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRequirementBaselineGenerator.swift
new file mode 100644
index 00000000..a916a514
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRequirementBaselineGenerator.swift
@@ -0,0 +1,87 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolRequirementBaseline.swift`.
+///
+/// `ProtocolRequirement` is the trailing-object record describing a single
+/// requirement (method, property accessor, associated-type access function,
+/// etc.) on a Swift protocol. It exposes `flags` (the
+/// `ProtocolRequirementFlags` bit field) and `defaultImplementation` (a
+/// relative pointer to a default-implementation symbol when the protocol
+/// extension provides one).
+///
+/// Picker: `Protocols.ProtocolWitnessTableTest` — its 5 method
+/// requirements (`a`/`b`/`c`/`d`/`e`) flesh out the trailing array; we
+/// pick the first requirement and exercise its accessors.
+///
+/// The companion `ProtocolBaseRequirement` type (declared in the same
+/// `ProtocolRequirement.swift` file) gets its own baseline / Suite
+/// (`ProtocolBaseRequirementBaseline` / `ProtocolBaseRequirementTests`).
+package enum ProtocolRequirementBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.protocol_ProtocolWitnessTableTest(in: machO)
+ let protocolType = try `Protocol`(descriptor: descriptor, in: machO)
+ let firstRequirement = try required(protocolType.requirements.first)
+
+ let firstRequirementExpr = try emitRequirementEntryExpr(for: firstRequirement, in: machO)
+
+ // Public members declared on `ProtocolRequirement` (the first struct
+ // in ProtocolRequirement.swift). `init(layout:offset:)` is filtered
+ // as memberwise-synthesized.
+ let registered = [
+ "defaultImplementationSymbols",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolRequirementBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutFlagsRawValue: UInt32
+ let hasDefaultImplementation: Bool
+ }
+
+ static let firstRequirement = \(raw: firstRequirementExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolRequirementBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitRequirementEntryExpr(
+ for requirement: ProtocolRequirement,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let offset = requirement.offset
+ let layoutFlagsRawValue = requirement.layout.flags.rawValue
+ let hasDefaultImplementation = (try requirement.defaultImplementationSymbols(in: machO)) != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(layoutFlagsRawValue)),
+ hasDefaultImplementation: \(literal: hasDefaultImplementation)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRequirementFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRequirementFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..9250a4c4
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRequirementFlagsBaselineGenerator.swift
@@ -0,0 +1,105 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolRequirementFlagsBaseline.swift`.
+///
+/// `ProtocolRequirementFlags` is a 32-bit `OptionSet` packing the
+/// requirement kind in its low nibble plus an `isInstance` and
+/// `maybeAsync` bit. Its derived accessors:
+/// - `kind` — splits the low nibble into `ProtocolRequirementKind`.
+/// - `isCoroutine` — true for `readCoroutine`/`modifyCoroutine`.
+/// - `isAsync` — `!isCoroutine && contains(.maybeAsync)`.
+/// - `isInstance` — `contains(.isInstance)`.
+///
+/// Two pickers feed the baseline so multiple branches are witnessed:
+/// - The first requirement of `ProtocolWitnessTableTest` (a method) —
+/// surfaces a real, live flags value with kind = `.method`.
+/// - Synthetic raw values for the remaining branches the live fixture
+/// does not exercise (`.readCoroutine` for `isCoroutine`,
+/// `.method | maybeAsync` for `isAsync`).
+package enum ProtocolRequirementFlagsBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.protocol_ProtocolWitnessTableTest(in: machO)
+ let protocolType = try `Protocol`(descriptor: descriptor, in: machO)
+ let firstRequirement = try required(protocolType.requirements.first)
+ let liveFlags = firstRequirement.layout.flags
+
+ let liveEntryExpr = emitEntryExpr(rawValue: liveFlags.rawValue)
+ // Synthetic: `.readCoroutine` (kind = 5) — exercises `isCoroutine: true`.
+ let coroutineEntryExpr = emitEntryExpr(rawValue: 0x5)
+ // Synthetic: `.method | maybeAsync` (kind = 1, async bit) —
+ // exercises `isAsync: true`.
+ let asyncEntryExpr = emitEntryExpr(rawValue: 0x21)
+
+ // Public members declared directly in ProtocolRequirementFlags.swift.
+ // `init(rawValue:)` and `rawValue` come from the OptionSet conformance.
+ // The `.isInstance` / `.maybeAsync` static OptionSet values are
+ // captured via the `isInstance` accessor and `maybeAsync` static.
+ let registered = [
+ "init(rawValue:)",
+ "isAsync",
+ "isCoroutine",
+ "isInstance",
+ "kind",
+ "maybeAsync",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolRequirementFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt32
+ let kindRawValue: UInt8
+ let isCoroutine: Bool
+ let isAsync: Bool
+ let isInstance: Bool
+ }
+
+ static let witnessTableMethod = \(raw: liveEntryExpr)
+
+ static let readCoroutine = \(raw: coroutineEntryExpr)
+
+ static let methodAsync = \(raw: asyncEntryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolRequirementFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(rawValue: UInt32) -> String {
+ let flags = ProtocolRequirementFlags(rawValue: rawValue)
+ let kindRawValue = flags.kind.rawValue
+ let isCoroutine = flags.isCoroutine
+ let isAsync = flags.isAsync
+ let isInstance = flags.isInstance
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRawValue)),
+ isCoroutine: \(literal: isCoroutine),
+ isAsync: \(literal: isAsync),
+ isInstance: \(literal: isInstance)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRequirementKindBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRequirementKindBaselineGenerator.swift
new file mode 100644
index 00000000..80bbf6f0
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolRequirementKindBaselineGenerator.swift
@@ -0,0 +1,63 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolRequirementKindBaseline.swift`.
+///
+/// `ProtocolRequirementKind` is a closed `UInt8` enum tagging each
+/// `ProtocolRequirement.flags.kind` value. The only public method
+/// declared in source is the `CustomStringConvertible.description`
+/// computed property; the cases themselves are out of scope for
+/// PublicMemberScanner (it does not visit `EnumCaseDeclSyntax`).
+///
+/// The baseline records the description string for every case so the
+/// Suite can iterate them deterministically.
+package enum ProtocolRequirementKindBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let baseProtocol = ProtocolRequirementKind.baseProtocol.description
+ let method = ProtocolRequirementKind.method.description
+ let initRequirement = ProtocolRequirementKind.`init`.description
+ let getter = ProtocolRequirementKind.getter.description
+ let setter = ProtocolRequirementKind.setter.description
+ let readCoroutine = ProtocolRequirementKind.readCoroutine.description
+ let modifyCoroutine = ProtocolRequirementKind.modifyCoroutine.description
+ let associatedTypeAccessFunction = ProtocolRequirementKind.associatedTypeAccessFunction.description
+ let associatedConformanceAccessFunction = ProtocolRequirementKind.associatedConformanceAccessFunction.description
+
+ // Public members declared directly in ProtocolRequirementKind.swift.
+ // Only `description` (in the CustomStringConvertible extension) is a
+ // member declaration — case declarations are not visited.
+ let registered = [
+ "description",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolRequirementKindBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ static let baseProtocolDescription = \(literal: baseProtocol)
+ static let methodDescription = \(literal: method)
+ static let initDescription = \(literal: initRequirement)
+ static let getterDescription = \(literal: getter)
+ static let setterDescription = \(literal: setter)
+ static let readCoroutineDescription = \(literal: readCoroutine)
+ static let modifyCoroutineDescription = \(literal: modifyCoroutine)
+ static let associatedTypeAccessFunctionDescription = \(literal: associatedTypeAccessFunction)
+ static let associatedConformanceAccessFunctionDescription = \(literal: associatedConformanceAccessFunction)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolRequirementKindBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolWitnessTableBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolWitnessTableBaselineGenerator.swift
new file mode 100644
index 00000000..d6251138
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ProtocolWitnessTableBaselineGenerator.swift
@@ -0,0 +1,70 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolWitnessTableBaseline.swift`.
+///
+/// `ProtocolWitnessTable` is a thin trailing-object wrapper exposing a
+/// pointer to the `ProtocolConformanceDescriptor` that owns the table.
+/// It carries no derived accessors of its own — the public API is just
+/// the layout-wrapper trio (`offset`, `layout`, `init(layout:offset:)`).
+///
+/// We pick a live witness-table pattern from the first `ProtocolConformance`
+/// in the fixture that surfaces one (most conformances do), and record
+/// the offset.
+package enum ProtocolWitnessTableBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let conformance = try required(
+ try machO.swift.protocolConformances.first(where: { $0.witnessTablePattern != nil })
+ )
+ let witnessTable = try required(conformance.witnessTablePattern)
+ let entryExpr = emitEntryExpr(for: witnessTable)
+
+ // Public members declared directly in ProtocolWitnessTable.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolWitnessTableBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ }
+
+ static let firstWitnessTable = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolWitnessTableBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for witnessTable: ProtocolWitnessTable) -> String {
+ let offset = witnessTable.offset
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ResilientWitnessBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ResilientWitnessBaselineGenerator.swift
new file mode 100644
index 00000000..1d28e6e1
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ResilientWitnessBaselineGenerator.swift
@@ -0,0 +1,100 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ResilientWitnessBaseline.swift`.
+///
+/// `ResilientWitness` describes a single requirement-implementation pair
+/// stored in a protocol conformance's resilient witness table. Each
+/// witness carries a `RelativeProtocolRequirementPointer` plus a relative
+/// pointer to the implementation symbol.
+///
+/// Picker: the first `ProtocolConformance` from the fixture with a
+/// non-empty `resilientWitnesses` array. We pin the resolved offset of
+/// the first witness's `requirement(in:)` and the boolean presence of
+/// `implementationSymbols(in:)`. `implementationAddress(in:)` is a
+/// MachO-only debug formatter (see `ResilientWitness.swift` doc-comment)
+/// — we register the name but do not assert on the live address string
+/// (it's a base-16 representation of an in-memory pointer).
+package enum ResilientWitnessBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let conformance = try BaselineFixturePicker.protocolConformance_resilientWitnessFirst(in: machO)
+ let firstWitness = try required(conformance.resilientWitnesses.first)
+
+ let requirement = try firstWitness.requirement(in: machO)
+ let hasRequirement = requirement != nil
+ let hasImplementationSymbols = (try firstWitness.implementationSymbols(in: machO)) != nil
+ let implementationOffset = firstWitness.implementationOffset
+
+ let entryExpr = emitEntryExpr(
+ offset: firstWitness.offset,
+ hasRequirement: hasRequirement,
+ hasImplementationSymbols: hasImplementationSymbols,
+ implementationOffset: implementationOffset
+ )
+
+ // Public members declared directly in ResilientWitness.swift.
+ // The `requirement(in:)` and `implementationSymbols(in:)` overloads
+ // (MachO + InProcess + ReadingContext) collapse to single MethodKeys
+ // under the scanner's name-based deduplication.
+ // `implementationAddress(in:)` is a MachO-only debug formatter —
+ // tracked here, exercised for type-correctness in the Suite.
+ let registered = [
+ "implementationAddress",
+ "implementationOffset",
+ "implementationSymbols",
+ "layout",
+ "offset",
+ "requirement",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ResilientWitnessBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let hasRequirement: Bool
+ let hasImplementationSymbols: Bool
+ let implementationOffset: Int
+ }
+
+ static let firstWitness = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ResilientWitnessBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ offset: Int,
+ hasRequirement: Bool,
+ hasImplementationSymbols: Bool,
+ implementationOffset: Int
+ ) -> String {
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ hasRequirement: \(literal: hasRequirement),
+ hasImplementationSymbols: \(literal: hasImplementationSymbols),
+ implementationOffset: \(raw: BaselineEmitter.hex(implementationOffset))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ResilientWitnessesHeaderBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ResilientWitnessesHeaderBaselineGenerator.swift
new file mode 100644
index 00000000..2c649724
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Protocol/ResilientWitnessesHeaderBaselineGenerator.swift
@@ -0,0 +1,69 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ResilientWitnessesHeaderBaseline.swift`.
+///
+/// `ResilientWitnessesHeader` is the trailing-object header that announces
+/// the resilient-witness array length (`numWitnesses`).
+///
+/// Picker: the first `ProtocolConformance` from the fixture with a
+/// non-empty `resilientWitnesses` array (so the header materializes).
+package enum ResilientWitnessesHeaderBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let conformance = try BaselineFixturePicker.protocolConformance_resilientWitnessFirst(in: machO)
+ let header = try required(conformance.resilientWitnessesHeader)
+
+ let entryExpr = emitEntryExpr(for: header)
+
+ // Public members declared directly in ResilientWitnessesHeader.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let headerComment = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: headerComment)
+
+ enum ResilientWitnessesHeaderBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumWitnesses: UInt32
+ }
+
+ static let firstHeader = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ResilientWitnessesHeaderBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for header: ResilientWitnessesHeader) -> String {
+ let offset = header.offset
+ let numWitnesses = header.layout.numWitnesses
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumWitnesses: \(literal: numWitnesses)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/GlobalActorReferenceBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/GlobalActorReferenceBaselineGenerator.swift
new file mode 100644
index 00000000..cf366436
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/GlobalActorReferenceBaselineGenerator.swift
@@ -0,0 +1,80 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/GlobalActorReferenceBaseline.swift`.
+///
+/// `GlobalActorReference` is the trailing object of
+/// `TargetProtocolConformanceDescriptor` carrying the actor type that
+/// isolates the conformance (e.g. `extension X: @MainActor P`). Present
+/// iff `ProtocolConformanceFlags.hasGlobalActorIsolation` is set.
+///
+/// Picker: the first conformance from the fixture with the
+/// `hasGlobalActorIsolation` bit. The fixture's
+/// `Actors.GlobalActorIsolatedConformanceTest` declares both
+/// `: @MainActor Actors.GlobalActorIsolatedProtocolTest` and
+/// `: @CustomGlobalActor Actors.CustomGlobalActorIsolatedProtocolTest`,
+/// so a global-actor reference is always available.
+///
+/// We pin the `offset` of the trailing reference and the type-name string
+/// (resolved via `typeName(in:)`). The conformance pointer slot exists for
+/// runtime dispatch; the dumper only uses the type-name pointer, so the
+/// baseline only validates that.
+package enum GlobalActorReferenceBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let conformance = try BaselineFixturePicker.protocolConformance_globalActorFirst(in: machO)
+ let reference = try required(conformance.globalActorReference)
+ let typeName = try reference.typeName(in: machO)
+ let entryExpr = emitEntryExpr(offset: reference.offset, typeNameString: typeName.symbolString)
+
+ // Public members declared directly in GlobalActorReference.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ // `typeName` collapses across MachO/InProcess/ReadingContext
+ // overloads under the scanner's name-based deduplication.
+ let registered = [
+ "layout",
+ "offset",
+ "typeName",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum GlobalActorReferenceBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let typeNameSymbolString: String
+ }
+
+ static let firstReference = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("GlobalActorReferenceBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(offset: Int, typeNameString: String) -> String {
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ typeNameSymbolString: \(literal: typeNameString)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/ProtocolConformanceBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/ProtocolConformanceBaselineGenerator.swift
new file mode 100644
index 00000000..51f2d6a9
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/ProtocolConformanceBaselineGenerator.swift
@@ -0,0 +1,144 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolConformanceBaseline.swift`.
+///
+/// `ProtocolConformance` is the high-level wrapper around
+/// `ProtocolConformanceDescriptor`. The init eagerly materializes the
+/// descriptor's protocol/typeReference/witnessTablePattern plus the
+/// trailing-objects payload (retroactiveContextDescriptor / conditional
+/// requirements / pack shape descriptors / resilient witnesses /
+/// generic witness table / global actor reference) gated on the flag bits
+/// of `ProtocolConformanceFlags`.
+///
+/// Three pickers feed the baseline so each trailing-object branch is
+/// witnessed by at least one entry:
+/// - `Structs.StructTest: Protocols.ProtocolTest` — the simplest path:
+/// non-retroactive, no global-actor isolation, no resilient witnesses,
+/// no conditional requirements. Surfaces the empty-trailing-objects
+/// baseline for the `protocol` / `typeReference` / `witnessTablePattern`
+/// stored properties.
+/// - The first conditional conformance from
+/// `ConditionalConformanceVariants.ConditionalContainerTest` — surfaces
+/// the `conditionalRequirements` array (and `numConditionalRequirements`
+/// flag bits) with a non-zero count.
+/// - The first global-actor-isolated conformance from `Actors`
+/// (`Actors.GlobalActorIsolatedConformanceTest: @MainActor ...` etc.) —
+/// surfaces the `globalActorReference` trailing object.
+/// - The first conformance with resilient witnesses (reused from Task 10's
+/// `protocolConformance_resilientWitnessFirst`) — surfaces
+/// `resilientWitnessesHeader` and a non-empty `resilientWitnesses`
+/// array.
+package enum ProtocolConformanceBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let structTest = try BaselineFixturePicker.protocolConformance_StructTestProtocolTest(in: machO)
+ let conditional = try BaselineFixturePicker.protocolConformance_conditionalFirst(in: machO)
+ let globalActor = try BaselineFixturePicker.protocolConformance_globalActorFirst(in: machO)
+ let resilient = try BaselineFixturePicker.protocolConformance_resilientWitnessFirst(in: machO)
+
+ let structTestExpr = emitEntryExpr(for: structTest)
+ let conditionalExpr = emitEntryExpr(for: conditional)
+ let globalActorExpr = emitEntryExpr(for: globalActor)
+ let resilientExpr = emitEntryExpr(for: resilient)
+
+ // Public members declared directly in ProtocolConformance.swift
+ // (across the body and the same-file ReadingContext extension).
+ // The `init(descriptor:in:)` MachO and ReadingContext overloads
+ // collapse to a single MethodKey under PublicMemberScanner's
+ // name-based deduplication. `flags` is a derived computed
+ // property over `descriptor.flags`.
+ let registered = [
+ "conditionalPackShapeDescriptors",
+ "conditionalRequirements",
+ "descriptor",
+ "flags",
+ "genericWitnessTable",
+ "globalActorReference",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "protocol",
+ "resilientWitnesses",
+ "resilientWitnessesHeader",
+ "retroactiveContextDescriptor",
+ "typeReference",
+ "witnessTablePattern",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolConformanceBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let flagsRawValue: UInt32
+ let hasProtocol: Bool
+ let hasWitnessTablePattern: Bool
+ let hasRetroactiveContextDescriptor: Bool
+ let conditionalRequirementsCount: Int
+ let conditionalPackShapeDescriptorsCount: Int
+ let hasResilientWitnessesHeader: Bool
+ let resilientWitnessesCount: Int
+ let hasGenericWitnessTable: Bool
+ let hasGlobalActorReference: Bool
+ }
+
+ static let structTestProtocolTest = \(raw: structTestExpr)
+
+ static let conditionalFirst = \(raw: conditionalExpr)
+
+ static let globalActorFirst = \(raw: globalActorExpr)
+
+ static let resilientFirst = \(raw: resilientExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolConformanceBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for conformance: ProtocolConformance) -> String {
+ let descriptorOffset = conformance.descriptor.offset
+ let flagsRawValue = conformance.flags.rawValue
+ let hasProtocol = conformance.protocol != nil
+ let hasWitnessTablePattern = conformance.witnessTablePattern != nil
+ let hasRetroactiveContextDescriptor = conformance.retroactiveContextDescriptor != nil
+ let conditionalRequirementsCount = conformance.conditionalRequirements.count
+ let conditionalPackShapeDescriptorsCount = conformance.conditionalPackShapeDescriptors.count
+ let hasResilientWitnessesHeader = conformance.resilientWitnessesHeader != nil
+ let resilientWitnessesCount = conformance.resilientWitnesses.count
+ let hasGenericWitnessTable = conformance.genericWitnessTable != nil
+ let hasGlobalActorReference = conformance.globalActorReference != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ flagsRawValue: \(raw: BaselineEmitter.hex(flagsRawValue)),
+ hasProtocol: \(literal: hasProtocol),
+ hasWitnessTablePattern: \(literal: hasWitnessTablePattern),
+ hasRetroactiveContextDescriptor: \(literal: hasRetroactiveContextDescriptor),
+ conditionalRequirementsCount: \(literal: conditionalRequirementsCount),
+ conditionalPackShapeDescriptorsCount: \(literal: conditionalPackShapeDescriptorsCount),
+ hasResilientWitnessesHeader: \(literal: hasResilientWitnessesHeader),
+ resilientWitnessesCount: \(literal: resilientWitnessesCount),
+ hasGenericWitnessTable: \(literal: hasGenericWitnessTable),
+ hasGlobalActorReference: \(literal: hasGlobalActorReference)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/ProtocolConformanceDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/ProtocolConformanceDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..7e1837f7
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/ProtocolConformanceDescriptorBaselineGenerator.swift
@@ -0,0 +1,105 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolConformanceDescriptorBaseline.swift`.
+///
+/// `ProtocolConformanceDescriptor` is the raw section-level descriptor
+/// pulled from `__swift5_proto`. The wrapper exposes the layout-trio
+/// (`offset`, `layout`, `init(layout:offset:)` — the last filtered as
+/// memberwise-synthesized), the `typeReference` computed property (turns
+/// the layout's relative offset + type-reference-kind flag into a
+/// `TypeReference` enum), plus three same-file extension helpers
+/// (`protocolDescriptor`, `resolvedTypeReference`, `witnessTablePattern`)
+/// each with three reader overloads (MachO + InProcess + ReadingContext)
+/// that all collapse to a single MethodKey under the scanner's name-based
+/// deduplication.
+///
+/// Picker: `Structs.StructTest: Protocols.ProtocolTest` — the simplest
+/// path: a non-retroactive struct conformance with a resolvable witness
+/// table and a `directTypeDescriptor` type reference.
+package enum ProtocolConformanceDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let conformance = try BaselineFixturePicker.protocolConformance_StructTestProtocolTest(in: machO)
+ let descriptor = conformance.descriptor
+
+ let entryExpr = try emitEntryExpr(for: descriptor, in: machO)
+
+ // Public members declared directly in ProtocolConformanceDescriptor.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ // The three reader overloads of `protocolDescriptor`, `resolvedTypeReference`,
+ // and `witnessTablePattern` each collapse to one MethodKey.
+ let registered = [
+ "layout",
+ "offset",
+ "protocolDescriptor",
+ "resolvedTypeReference",
+ "typeReference",
+ "witnessTablePattern",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolConformanceDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutFlagsRawValue: UInt32
+ let typeReferenceKindRawValue: UInt8
+ let hasProtocolDescriptor: Bool
+ let hasWitnessTablePattern: Bool
+ let resolvedTypeReferenceIsDirectTypeDescriptor: Bool
+ }
+
+ static let structTestProtocolTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolConformanceDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for descriptor: ProtocolConformanceDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let offset = descriptor.offset
+ let layoutFlagsRawValue = descriptor.layout.flags.rawValue
+ let typeReferenceKindRawValue = descriptor.layout.flags.typeReferenceKind.rawValue
+ let hasProtocolDescriptor = (try descriptor.protocolDescriptor(in: machO)) != nil
+ let hasWitnessTablePattern = (try descriptor.witnessTablePattern(in: machO)) != nil
+ let resolvedTypeReference = try descriptor.resolvedTypeReference(in: machO)
+ let isDirectTypeDescriptor: Bool
+ if case .directTypeDescriptor = resolvedTypeReference {
+ isDirectTypeDescriptor = true
+ } else {
+ isDirectTypeDescriptor = false
+ }
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(layoutFlagsRawValue)),
+ typeReferenceKindRawValue: \(raw: BaselineEmitter.hex(typeReferenceKindRawValue)),
+ hasProtocolDescriptor: \(literal: hasProtocolDescriptor),
+ hasWitnessTablePattern: \(literal: hasWitnessTablePattern),
+ resolvedTypeReferenceIsDirectTypeDescriptor: \(literal: isDirectTypeDescriptor)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/ProtocolConformanceFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/ProtocolConformanceFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..a8a03187
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ProtocolConformance/ProtocolConformanceFlagsBaselineGenerator.swift
@@ -0,0 +1,120 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ProtocolConformanceFlagsBaseline.swift`.
+///
+/// `ProtocolConformanceFlags` is the 32-bit flag word stored in
+/// `ProtocolConformanceDescriptor.Layout.flags`. It packs the
+/// `typeReferenceKind` (low 3 bits, shifted by 3), three boolean bits
+/// (isRetroactive / isSynthesizedNonUnique / isConformanceOfProtocol),
+/// the resilient/generic/global-actor witness-table presence bits, the
+/// `numConditionalRequirements` byte, and the
+/// `numConditionalPackShapeDescriptors` byte.
+///
+/// Three pickers feed the baseline so each branch is witnessed by at
+/// least one entry:
+/// - `Structs.StructTest: Protocols.ProtocolTest` — the simplest
+/// baseline path: defaultDirectTypeDescriptor kind, all flags clear,
+/// zero conditional requirements.
+/// - The first conditional conformance — surfaces a non-zero
+/// `numConditionalRequirements` value.
+/// - The first global-actor-isolated conformance — surfaces
+/// `hasGlobalActorIsolation: true`.
+/// - The first resilient-witness conformance — surfaces
+/// `hasResilientWitnesses: true`.
+package enum ProtocolConformanceFlagsBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let structTest = try BaselineFixturePicker.protocolConformance_StructTestProtocolTest(in: machO)
+ let conditional = try BaselineFixturePicker.protocolConformance_conditionalFirst(in: machO)
+ let globalActor = try BaselineFixturePicker.protocolConformance_globalActorFirst(in: machO)
+ let resilient = try BaselineFixturePicker.protocolConformance_resilientWitnessFirst(in: machO)
+
+ let structTestExpr = emitEntryExpr(rawValue: structTest.flags.rawValue)
+ let conditionalExpr = emitEntryExpr(rawValue: conditional.flags.rawValue)
+ let globalActorExpr = emitEntryExpr(rawValue: globalActor.flags.rawValue)
+ let resilientExpr = emitEntryExpr(rawValue: resilient.flags.rawValue)
+
+ // Public members declared directly in ProtocolConformanceFlags.swift.
+ let registered = [
+ "hasGenericWitnessTable",
+ "hasGlobalActorIsolation",
+ "hasNonDefaultSerialExecutorIsIsolatingCurrentContext",
+ "hasResilientWitnesses",
+ "init(rawValue:)",
+ "isConformanceOfProtocol",
+ "isRetroactive",
+ "isSynthesizedNonUnique",
+ "numConditionalPackShapeDescriptors",
+ "numConditionalRequirements",
+ "rawValue",
+ "typeReferenceKind",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ProtocolConformanceFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt32
+ let typeReferenceKindRawValue: UInt8
+ let isRetroactive: Bool
+ let isSynthesizedNonUnique: Bool
+ let isConformanceOfProtocol: Bool
+ let hasGlobalActorIsolation: Bool
+ let hasNonDefaultSerialExecutorIsIsolatingCurrentContext: Bool
+ let hasResilientWitnesses: Bool
+ let hasGenericWitnessTable: Bool
+ let numConditionalRequirements: UInt32
+ let numConditionalPackShapeDescriptors: UInt32
+ }
+
+ static let structTestProtocolTest = \(raw: structTestExpr)
+
+ static let conditionalFirst = \(raw: conditionalExpr)
+
+ static let globalActorFirst = \(raw: globalActorExpr)
+
+ static let resilientFirst = \(raw: resilientExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ProtocolConformanceFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(rawValue: UInt32) -> String {
+ let flags = ProtocolConformanceFlags(rawValue: rawValue)
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ typeReferenceKindRawValue: \(raw: BaselineEmitter.hex(flags.typeReferenceKind.rawValue)),
+ isRetroactive: \(literal: flags.isRetroactive),
+ isSynthesizedNonUnique: \(literal: flags.isSynthesizedNonUnique),
+ isConformanceOfProtocol: \(literal: flags.isConformanceOfProtocol),
+ hasGlobalActorIsolation: \(literal: flags.hasGlobalActorIsolation),
+ hasNonDefaultSerialExecutorIsIsolatingCurrentContext: \(literal: flags.hasNonDefaultSerialExecutorIsIsolatingCurrentContext),
+ hasResilientWitnesses: \(literal: flags.hasResilientWitnesses),
+ hasGenericWitnessTable: \(literal: flags.hasGenericWitnessTable),
+ numConditionalRequirements: \(raw: BaselineEmitter.hex(flags.numConditionalRequirements)),
+ numConditionalPackShapeDescriptors: \(raw: BaselineEmitter.hex(flags.numConditionalPackShapeDescriptors))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/StructBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/StructBaselineGenerator.swift
new file mode 100644
index 00000000..29b6ef03
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/StructBaselineGenerator.swift
@@ -0,0 +1,122 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+// Pattern note: this generator and its corresponding Suite use **presence flags**
+// (`hasGenericContext: Bool`, etc.) for heavy optional ivars rather than full
+// structural equality. Rationale: the underlying types (TypeGenericContext,
+// SingletonMetadataPointer, ...) are non-Equatable and would require deep,
+// brittle equality assertions. Presence + cardinality catches the structural
+// invariant we care about — that the descriptor's optional fields appear when
+// expected and not when not.
+//
+// Limitation: a regression that produces a *wrong-shaped* generic context (with
+// the optional field set but its contents corrupted) is not caught by these
+// tests. Where deeper structural assertions matter, Tasks 12 (Generic/) and 14
+// (Metadata/) will add type-specific tests.
+
+/// Emits `__Baseline__/StructBaseline.swift` from the `SymbolTestsCore`
+/// fixture via the MachOFile reader.
+///
+/// `Struct` is the high-level wrapper around `StructDescriptor`. Beyond the
+/// descriptor itself, each ivar is `Optional`/array-shaped depending on
+/// flags. The baseline `Entry` only records *presence/absence* of each
+/// optional member and the count of canonical specializations; richer payload
+/// shapes (e.g. `TypeGenericContext`) are not stable Swift literals worth
+/// embedding here, so we let the cross-reader equality assertions guard them
+/// at runtime.
+package enum StructBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let structTestDescriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let genericStructDescriptor = try BaselineFixturePicker.struct_GenericStructNonRequirement(in: machO)
+
+ let structTestStruct = try Struct(descriptor: structTestDescriptor, in: machO)
+ let genericStructStruct = try Struct(descriptor: genericStructDescriptor, in: machO)
+
+ let structTestExpr = emitEntryExpr(for: structTestStruct)
+ let genericStructExpr = emitEntryExpr(for: genericStructStruct)
+
+ // Public members declared directly in Struct.swift, per scanner output.
+ // Two `init(descriptor:in:)` overloads (MachO + Context) collapse to one
+ // MethodKey under PublicMemberScanner's name-based deduplication.
+ let registered = [
+ "canonicalSpecializedMetadatas",
+ "canonicalSpecializedMetadatasCachingOnceToken",
+ "canonicalSpecializedMetadatasListCount",
+ "descriptor",
+ "foreignMetadataInitialization",
+ "genericContext",
+ "init(descriptor:)",
+ "init(descriptor:in:)",
+ "invertibleProtocolSet",
+ "singletonMetadataInitialization",
+ "singletonMetadataPointer",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum StructBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let hasGenericContext: Bool
+ let hasForeignMetadataInitialization: Bool
+ let hasSingletonMetadataInitialization: Bool
+ let canonicalSpecializedMetadatasCount: Int
+ let hasCanonicalSpecializedMetadatasListCount: Bool
+ let hasCanonicalSpecializedMetadatasCachingOnceToken: Bool
+ let hasInvertibleProtocolSet: Bool
+ let hasSingletonMetadataPointer: Bool
+ }
+
+ static let structTest = \(raw: structTestExpr)
+
+ static let genericStructNonRequirement = \(raw: genericStructExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("StructBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for instance: Struct) -> String {
+ let descriptorOffset = instance.descriptor.offset
+ let hasGenericContext = instance.genericContext != nil
+ let hasForeignMetadataInitialization = instance.foreignMetadataInitialization != nil
+ let hasSingletonMetadataInitialization = instance.singletonMetadataInitialization != nil
+ let canonicalSpecializedMetadatasCount = instance.canonicalSpecializedMetadatas.count
+ let hasCanonicalSpecializedMetadatasListCount = instance.canonicalSpecializedMetadatasListCount != nil
+ let hasCanonicalSpecializedMetadatasCachingOnceToken = instance.canonicalSpecializedMetadatasCachingOnceToken != nil
+ let hasInvertibleProtocolSet = instance.invertibleProtocolSet != nil
+ let hasSingletonMetadataPointer = instance.singletonMetadataPointer != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ hasGenericContext: \(literal: hasGenericContext),
+ hasForeignMetadataInitialization: \(literal: hasForeignMetadataInitialization),
+ hasSingletonMetadataInitialization: \(literal: hasSingletonMetadataInitialization),
+ canonicalSpecializedMetadatasCount: \(literal: canonicalSpecializedMetadatasCount),
+ hasCanonicalSpecializedMetadatasListCount: \(literal: hasCanonicalSpecializedMetadatasListCount),
+ hasCanonicalSpecializedMetadatasCachingOnceToken: \(literal: hasCanonicalSpecializedMetadatasCachingOnceToken),
+ hasInvertibleProtocolSet: \(literal: hasInvertibleProtocolSet),
+ hasSingletonMetadataPointer: \(literal: hasSingletonMetadataPointer)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/StructDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/StructDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..74c5b255
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/StructDescriptorBaselineGenerator.swift
@@ -0,0 +1,74 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/StructDescriptorBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `StructDescriptor` declares only two members directly (the `offset` ivar
+/// and the `layout` ivar; `init(layout:offset:)` is filtered as a memberwise
+/// synthesized initializer). All `name`/`fields`/`numberOfFields` etc. live on
+/// `TypeContextDescriptorProtocol` (a protocol-extension Suite) and will be
+/// covered by Task 9, not here.
+package enum StructDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let structTest = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let genericStruct = try BaselineFixturePicker.struct_GenericStructNonRequirement(in: machO)
+
+ let structTestExpr = try emitEntryExpr(for: structTest)
+ let genericStructExpr = try emitEntryExpr(for: genericStruct)
+
+ let registered = ["layout", "offset"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum StructDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutNumFields: Int
+ let layoutFieldOffsetVector: Int
+ let layoutFlagsRawValue: UInt32
+ }
+
+ static let structTest = \(raw: structTestExpr)
+
+ static let genericStructNonRequirement = \(raw: genericStructExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("StructDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for descriptor: StructDescriptor) throws -> String {
+ let offset = descriptor.offset
+ let numFields = Int(descriptor.layout.numFields)
+ let fieldOffsetVector = Int(descriptor.layout.fieldOffsetVector)
+ let flagsRaw = descriptor.layout.flags.rawValue
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutNumFields: \(literal: numFields),
+ layoutFieldOffsetVector: \(literal: fieldOffsetVector),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/StructMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/StructMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..d9765679
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/StructMetadataBaselineGenerator.swift
@@ -0,0 +1,50 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/StructMetadataBaseline.swift`.
+///
+/// Unlike the descriptor-side baselines, this generator does NOT consume the
+/// MachOFile fixture: `StructMetadata` instances can only be obtained by
+/// invoking the metadata accessor function from a *loaded* MachOImage in the
+/// current process. Encoding live pointer values in a literal would not be
+/// stable across runs, so the Suite tests cover correctness via cross-reader
+/// equality at runtime instead.
+///
+/// Consequently, the generated file only carries the registered member names
+/// for the Coverage Invariant test (Task 16) to consult.
+package enum StructMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in StructMetadata.swift.
+ // `init(layout:offset:)` is filtered as memberwise synthesized.
+ let registered = [
+ "descriptorOffset",
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // StructMetadata can only be materialized via MachOImage's accessor
+ // function at runtime; live pointer values are not embedded here. The
+ // companion Suite (StructMetadataTests) relies on cross-reader
+ // equality between (MachOImage, fileContext, imageContext, inProcess)
+ // for correctness.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum StructMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("StructMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/StructMetadataProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/StructMetadataProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..6615e1d5
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/StructMetadataProtocolBaselineGenerator.swift
@@ -0,0 +1,45 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/StructMetadataProtocolBaseline.swift`.
+///
+/// Like `StructMetadataBaselineGenerator`, this only emits the registered
+/// member names. The protocol's `structDescriptor`/`fieldOffsets` family of
+/// methods all require a live `StructMetadata` instance, which is only
+/// reachable through MachOImage at runtime. Cross-reader equality assertions
+/// in the companion Suite (StructMetadataProtocolTests) cover correctness.
+package enum StructMetadataProtocolBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in StructMetadataProtocol.swift.
+ // Both `structDescriptor` and `fieldOffsets` have multiple overloads
+ // (MachO/InProcess/ReadingContext) — they collapse to single
+ // MethodKey entries via PublicMemberScanner's name-only key.
+ let registered = [
+ "fieldOffsets",
+ "structDescriptor",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live StructMetadata pointers cannot be embedded as literals; the
+ // companion Suite (StructMetadataProtocolTests) verifies the methods
+ // produce cross-reader-consistent results at runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum StructMetadataProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("StructMetadataProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/TupleType/TupleTypeMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/TupleType/TupleTypeMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..0ea47cbb
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/TupleType/TupleTypeMetadataBaselineGenerator.swift
@@ -0,0 +1,56 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TupleTypeMetadataBaseline.swift`.
+///
+/// Phase C2: emits ABI literals derived from in-process resolution of
+/// `(Int, String).self`'s `TupleTypeMetadata`.
+///
+/// Registered names track the wrapper's directly-declared public surface
+/// (`layout`, `offset`, `elements`); the layout subfields (`kind`,
+/// `numberOfElements`, `labels`) are exercised inside the `layout` test
+/// body.
+package enum TupleTypeMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let pointer = InProcessMetadataPicker.stdlibTupleIntString
+ let context = InProcessContext()
+ let metadata = try TupleTypeMetadata.resolve(at: pointer, in: context)
+ let kindRaw = metadata.kind.rawValue
+ let count = metadata.layout.numberOfElements
+ let labelsAddress = metadata.layout.labels.address
+
+ let registered = ["elements", "layout", "offset"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess (stdlib `(Int, String).self`); no Mach-O section presence.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TupleTypeMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let kindRawValue: UInt32
+ let numberOfElements: UInt64
+ let labelsAddress: UInt64
+ }
+
+ static let stdlibTupleIntString = Entry(
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRaw)),
+ numberOfElements: \(raw: BaselineEmitter.hex(count)),
+ labelsAddress: \(raw: BaselineEmitter.hex(labelsAddress))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TupleTypeMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/TupleType/TupleTypeMetadataElementBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/TupleType/TupleTypeMetadataElementBaselineGenerator.swift
new file mode 100644
index 00000000..932762d8
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/TupleType/TupleTypeMetadataElementBaselineGenerator.swift
@@ -0,0 +1,46 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TupleTypeMetadataElementBaseline.swift`.
+///
+/// Phase C2: emits ABI literals derived from in-process resolution of the
+/// first `Element` of `(Int, String).self`'s `TupleTypeMetadata`.
+package enum TupleTypeMetadataElementBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let pointer = InProcessMetadataPicker.stdlibTupleIntString
+ let context = InProcessContext()
+ let tuple = try TupleTypeMetadata.resolve(at: pointer, in: context)
+ let firstElement = try tuple.elements(in: context).first!
+ let elementOffset = firstElement.offset
+
+ let registered = ["offset", "type"]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: swift package --allow-writing-to-package-directory regen-baselines
+ // Source: InProcess first element of `(Int, String)`; no Mach-O section presence.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TupleTypeMetadataElementBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: UInt64
+ }
+
+ static let firstElementOfIntStringTuple = Entry(
+ offset: \(raw: BaselineEmitter.hex(elementOffset))
+ )
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TupleTypeMetadataElementBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorBaselineGenerator.swift
new file mode 100644
index 00000000..45de4d81
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorBaselineGenerator.swift
@@ -0,0 +1,97 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TypeContextDescriptorBaseline.swift` from the
+/// `SymbolTestsCore` fixture via the MachOFile reader.
+///
+/// `TypeContextDescriptor` is the bare type-descriptor header common to
+/// struct/enum/class kinds — it carries `offset`/`layout` plus three same-
+/// file extensions adding `enumDescriptor`/`structDescriptor`/`classDescriptor`
+/// kind-projection methods (each with MachO + InProcess + ReadingContext
+/// overloads that collapse to one MethodKey under PublicMemberScanner's
+/// name-only key). Protocol-extension members (`name(in:)`, `fields(in:)`,
+/// `metadataAccessorFunction(in:)`, etc.) live on
+/// `TypeContextDescriptorProtocol` and are covered by
+/// `TypeContextDescriptorProtocolBaseline` per the protocol-extension
+/// attribution rule.
+///
+/// We materialize a representative `TypeContextDescriptor` by reading the
+/// bare header at the offset of `Structs.StructTest`. Because the picker
+/// targets a struct, `structDescriptor()` returns non-nil and the other
+/// two kind projections (`enumDescriptor`/`classDescriptor`) return nil.
+package enum TypeContextDescriptorBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let structTest = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let descriptor: TypeContextDescriptor = try machO.readWrapperElement(offset: structTest.offset)
+
+ let entryExpr = try emitEntryExpr(for: descriptor, in: machO)
+
+ // Public members directly declared in TypeContextDescriptor.swift
+ // (across the body and three same-file extensions). Protocol-extension
+ // methods like `name(in:)` are attributed to
+ // `TypeContextDescriptorProtocol` and live in their own baseline.
+ let registered = [
+ "classDescriptor",
+ "enumDescriptor",
+ "layout",
+ "offset",
+ "structDescriptor",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeContextDescriptorBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutFlagsRawValue: UInt32
+ let hasEnumDescriptor: Bool
+ let hasStructDescriptor: Bool
+ let hasClassDescriptor: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeContextDescriptorBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for descriptor: TypeContextDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let offset = descriptor.offset
+ let flagsRaw = descriptor.layout.flags.rawValue
+ let hasEnumDescriptor = (try descriptor.enumDescriptor(in: machO)) != nil
+ let hasStructDescriptor = (try descriptor.structDescriptor(in: machO)) != nil
+ let hasClassDescriptor = (try descriptor.classDescriptor(in: machO)) != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutFlagsRawValue: \(raw: BaselineEmitter.hex(flagsRaw)),
+ hasEnumDescriptor: \(literal: hasEnumDescriptor),
+ hasStructDescriptor: \(literal: hasStructDescriptor),
+ hasClassDescriptor: \(literal: hasClassDescriptor)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..5331d6d4
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorFlagsBaselineGenerator.swift
@@ -0,0 +1,141 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOExtensions
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TypeContextDescriptorFlagsBaseline.swift`.
+///
+/// `TypeContextDescriptorFlags` is the kind-specific 16-bit `FlagSet`
+/// reachable via `ContextDescriptorFlags.kindSpecificFlags?.typeFlags`. It
+/// carries both kind-agnostic flag accessors (`hasImportInfo`,
+/// `hasLayoutString`, `noMetadataInitialization`,
+/// `hasSingletonMetadataInitialization`,
+/// `hasForeignMetadataInitialization`,
+/// `hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer`) and
+/// class-specific accessors (`classIsActor`, `classIsDefaultActor`,
+/// `classHasVTable`, `classHasOverrideTable`, `classHasResilientSuperclass`,
+/// `classHasDefaultOverrideTable`,
+/// `classResilientSuperclassReferenceKind`,
+/// `classAreImmdiateMembersNegative`).
+///
+/// Two pickers feed the baseline so each branch is witnessed:
+/// - `Structs.StructTest` for the kind-agnostic accessors (and to confirm
+/// the class-only flags read as `false` for non-class kinds).
+/// - `Classes.ClassTest` for the class-specific accessors (so
+/// `classHasVTable` / `classResilientSuperclassReferenceKind` etc. have
+/// a real-world value to assert).
+package enum TypeContextDescriptorFlagsBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let structDescriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let structFlags = try required(structDescriptor.layout.flags.kindSpecificFlags?.typeFlags)
+ let structEntryExpr = emitEntryExpr(for: structFlags)
+
+ let classDescriptor = try BaselineFixturePicker.class_ClassTest(in: machO)
+ let classFlags = try required(classDescriptor.layout.flags.kindSpecificFlags?.typeFlags)
+ let classEntryExpr = emitEntryExpr(for: classFlags)
+
+ // Public members declared directly in TypeContextDescriptorFlags.swift.
+ let registered = [
+ "classAreImmdiateMembersNegative",
+ "classHasDefaultOverrideTable",
+ "classHasOverrideTable",
+ "classHasResilientSuperclass",
+ "classHasVTable",
+ "classIsActor",
+ "classIsDefaultActor",
+ "classResilientSuperclassReferenceKind",
+ "hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer",
+ "hasForeignMetadataInitialization",
+ "hasImportInfo",
+ "hasLayoutString",
+ "hasSingletonMetadataInitialization",
+ "init(rawValue:)",
+ "noMetadataInitialization",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeContextDescriptorFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt16
+ let noMetadataInitialization: Bool
+ let hasSingletonMetadataInitialization: Bool
+ let hasForeignMetadataInitialization: Bool
+ let hasImportInfo: Bool
+ let hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer: Bool
+ let hasLayoutString: Bool
+ let classHasDefaultOverrideTable: Bool
+ let classIsActor: Bool
+ let classIsDefaultActor: Bool
+ let classResilientSuperclassReferenceKindRawValue: UInt8
+ let classAreImmdiateMembersNegative: Bool
+ let classHasResilientSuperclass: Bool
+ let classHasOverrideTable: Bool
+ let classHasVTable: Bool
+ }
+
+ static let structTest = \(raw: structEntryExpr)
+
+ static let classTest = \(raw: classEntryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeContextDescriptorFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for flags: TypeContextDescriptorFlags) -> String {
+ let rawValue = flags.rawValue
+ let noMetadataInitialization = flags.noMetadataInitialization
+ let hasSingletonMetadataInitialization = flags.hasSingletonMetadataInitialization
+ let hasForeignMetadataInitialization = flags.hasForeignMetadataInitialization
+ let hasImportInfo = flags.hasImportInfo
+ let hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer = flags.hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer
+ let hasLayoutString = flags.hasLayoutString
+ let classHasDefaultOverrideTable = flags.classHasDefaultOverrideTable
+ let classIsActor = flags.classIsActor
+ let classIsDefaultActor = flags.classIsDefaultActor
+ let classResilientSuperclassReferenceKindRawValue = flags.classResilientSuperclassReferenceKind.rawValue
+ let classAreImmdiateMembersNegative = flags.classAreImmdiateMembersNegative
+ let classHasResilientSuperclass = flags.classHasResilientSuperclass
+ let classHasOverrideTable = flags.classHasOverrideTable
+ let classHasVTable = flags.classHasVTable
+
+ let expr: ExprSyntax = """
+ Entry(
+ rawValue: \(raw: BaselineEmitter.hex(rawValue)),
+ noMetadataInitialization: \(literal: noMetadataInitialization),
+ hasSingletonMetadataInitialization: \(literal: hasSingletonMetadataInitialization),
+ hasForeignMetadataInitialization: \(literal: hasForeignMetadataInitialization),
+ hasImportInfo: \(literal: hasImportInfo),
+ hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer: \(literal: hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer),
+ hasLayoutString: \(literal: hasLayoutString),
+ classHasDefaultOverrideTable: \(literal: classHasDefaultOverrideTable),
+ classIsActor: \(literal: classIsActor),
+ classIsDefaultActor: \(literal: classIsDefaultActor),
+ classResilientSuperclassReferenceKindRawValue: \(raw: BaselineEmitter.hex(classResilientSuperclassReferenceKindRawValue)),
+ classAreImmdiateMembersNegative: \(literal: classAreImmdiateMembersNegative),
+ classHasResilientSuperclass: \(literal: classHasResilientSuperclass),
+ classHasOverrideTable: \(literal: classHasOverrideTable),
+ classHasVTable: \(literal: classHasVTable)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..21eecbb1
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorProtocolBaselineGenerator.swift
@@ -0,0 +1,125 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TypeContextDescriptorProtocolBaseline.swift`.
+///
+/// Per the protocol-extension attribution rule (see `BaselineGenerator.swift`),
+/// `metadataAccessorFunction`, `fieldDescriptor`, `genericContext`,
+/// `typeGenericContext` and the 7 derived booleans
+/// (`hasSingletonMetadataInitialization`, `hasForeignMetadataInitialization`,
+/// `hasImportInfo`,
+/// `hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer`,
+/// `hasLayoutString`, `hasCanonicalMetadataPrespecializations`,
+/// `hasSingletonMetadataPointer`) live in
+/// `extension TypeContextDescriptorProtocol { ... }` and attribute to the
+/// protocol, not to concrete descriptors like `StructDescriptor`/
+/// `EnumDescriptor`/`ClassDescriptor`.
+///
+/// Picker: `Structs.StructTest`. The booleans all read `false` for this
+/// non-generic, no-import struct; `metadataAccessorFunction` returns `nil`
+/// when the picker is read out of `MachOFile` (the accessor is only
+/// reachable from a loaded `MachOImage`); `fieldDescriptor` resolves to a
+/// non-trivial `FieldDescriptor` we record by presence; `genericContext`
+/// returns `nil` (struct is non-generic).
+package enum TypeContextDescriptorProtocolBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+
+ let entryExpr = try emitEntryExpr(for: descriptor, in: machO)
+
+ // Public members declared in `extension TypeContextDescriptorProtocol { ... }`
+ // (across the body, an in-process variant, and a ReadingContext variant).
+ // Overload pairs collapse to single MethodKey entries under
+ // PublicMemberScanner's name-only key.
+ let registered = [
+ "fieldDescriptor",
+ "genericContext",
+ "hasCanonicalMetadataPrespecializations",
+ "hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer",
+ "hasForeignMetadataInitialization",
+ "hasImportInfo",
+ "hasLayoutString",
+ "hasSingletonMetadataInitialization",
+ "hasSingletonMetadataPointer",
+ "metadataAccessorFunction",
+ "typeGenericContext",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live FieldDescriptor / GenericContext / MetadataAccessorFunction
+ // payloads aren't embedded as literals; the companion Suite
+ // (TypeContextDescriptorProtocolTests) verifies the methods produce
+ // cross-reader-consistent results at runtime against the presence
+ // flags recorded here.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeContextDescriptorProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let hasFieldDescriptor: Bool
+ let hasGenericContext: Bool
+ let hasTypeGenericContext: Bool
+ let hasSingletonMetadataInitialization: Bool
+ let hasForeignMetadataInitialization: Bool
+ let hasImportInfo: Bool
+ let hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer: Bool
+ let hasLayoutString: Bool
+ let hasCanonicalMetadataPrespecializations: Bool
+ let hasSingletonMetadataPointer: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeContextDescriptorProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for descriptor: StructDescriptor,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let hasFieldDescriptor = (try? descriptor.fieldDescriptor(in: machO)) != nil
+ let hasGenericContext = (try descriptor.genericContext(in: machO)) != nil
+ let hasTypeGenericContext = (try descriptor.typeGenericContext(in: machO)) != nil
+ let hasSingletonMetadataInitialization = descriptor.hasSingletonMetadataInitialization
+ let hasForeignMetadataInitialization = descriptor.hasForeignMetadataInitialization
+ let hasImportInfo = descriptor.hasImportInfo
+ let hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer = descriptor.hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer
+ let hasLayoutString = descriptor.hasLayoutString
+ let hasCanonicalMetadataPrespecializations = descriptor.hasCanonicalMetadataPrespecializations
+ let hasSingletonMetadataPointer = descriptor.hasSingletonMetadataPointer
+
+ let expr: ExprSyntax = """
+ Entry(
+ hasFieldDescriptor: \(literal: hasFieldDescriptor),
+ hasGenericContext: \(literal: hasGenericContext),
+ hasTypeGenericContext: \(literal: hasTypeGenericContext),
+ hasSingletonMetadataInitialization: \(literal: hasSingletonMetadataInitialization),
+ hasForeignMetadataInitialization: \(literal: hasForeignMetadataInitialization),
+ hasImportInfo: \(literal: hasImportInfo),
+ hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer: \(literal: hasCanonicalMetadataPrespecializationsOrSingletonMetadataPointer),
+ hasLayoutString: \(literal: hasLayoutString),
+ hasCanonicalMetadataPrespecializations: \(literal: hasCanonicalMetadataPrespecializations),
+ hasSingletonMetadataPointer: \(literal: hasSingletonMetadataPointer)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorWrapperBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorWrapperBaselineGenerator.swift
new file mode 100644
index 00000000..e583c9ee
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextDescriptorWrapperBaselineGenerator.swift
@@ -0,0 +1,93 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TypeContextDescriptorWrapperBaseline.swift`.
+///
+/// `TypeContextDescriptorWrapper` is the 3-case sum type covering the
+/// `enum`/`struct`/`class` type-descriptor kinds. Members include three
+/// alternate-projection vars (`contextDescriptor`, `namedContextDescriptor`,
+/// `typeContextDescriptor`), the `asContextDescriptorWrapper` var, the
+/// `asPointerWrapper(in:)` func, and the `parent`/`genericContext`/
+/// `typeGenericContext` instance methods (each with MachO + InProcess +
+/// ReadingContext overloads that collapse to one MethodKey under
+/// PublicMemberScanner's name-only key). The static `resolve` family in
+/// `extension TypeContextDescriptorWrapper: Resolvable { ... }` collapses
+/// likewise.
+///
+/// Picker: `Structs.StructTest`'s descriptor wrapped in `.struct(...)`.
+package enum TypeContextDescriptorWrapperBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let wrapper = TypeContextDescriptorWrapper.struct(descriptor)
+ let entryExpr = try emitEntryExpr(for: wrapper, in: machO)
+
+ // Public members declared directly in TypeContextDescriptorWrapper.swift
+ // (the `TypeContextDescriptorWrapper` enum body and its `Resolvable`
+ // extension). The `ValueTypeDescriptorWrapper` enum declared in the
+ // same file is covered by its own baseline / Suite.
+ let registered = [
+ "asContextDescriptorWrapper",
+ "asPointerWrapper",
+ "contextDescriptor",
+ "genericContext",
+ "namedContextDescriptor",
+ "parent",
+ "resolve",
+ "typeContextDescriptor",
+ "typeGenericContext",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeContextDescriptorWrapperBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let hasParent: Bool
+ let hasGenericContext: Bool
+ let hasTypeGenericContext: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeContextDescriptorWrapperBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for wrapper: TypeContextDescriptorWrapper,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let descriptorOffset = wrapper.contextDescriptor.offset
+ let hasParent = (try wrapper.parent(in: machO)) != nil
+ let hasGenericContext = (try wrapper.genericContext(in: machO)) != nil
+ let hasTypeGenericContext = (try wrapper.typeGenericContext(in: machO)) != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ hasParent: \(literal: hasParent),
+ hasGenericContext: \(literal: hasGenericContext),
+ hasTypeGenericContext: \(literal: hasTypeGenericContext)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextWrapperBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextWrapperBaselineGenerator.swift
new file mode 100644
index 00000000..4a8b95a7
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeContextWrapperBaselineGenerator.swift
@@ -0,0 +1,78 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TypeContextWrapperBaseline.swift`.
+///
+/// `TypeContextWrapper` is the high-level sum type covering the
+/// `enum`/`struct`/`class` type contexts (analogous to
+/// `TypeContextDescriptorWrapper` but at the `*Context` level — wrapping
+/// the high-level `Enum`/`Struct`/`Class` types, not their descriptors).
+///
+/// Members include the alternate-projection vars
+/// (`contextDescriptorWrapper`, `typeContextDescriptorWrapper`), the
+/// `asPointerWrapper(in:)` instance func, and the static
+/// `forTypeContextDescriptorWrapper` family (3 overloads collapse to one
+/// MethodKey under PublicMemberScanner's name-only key).
+///
+/// Picker: route `Structs.StructTest`'s descriptor through
+/// `TypeContextWrapper.forTypeContextDescriptorWrapper` to produce a
+/// `.struct(...)` wrapper.
+package enum TypeContextWrapperBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let descriptorWrapper = TypeContextDescriptorWrapper.struct(descriptor)
+ let wrapper = try TypeContextWrapper.forTypeContextDescriptorWrapper(descriptorWrapper, in: machO)
+ let entryExpr = emitEntryExpr(for: wrapper)
+
+ let registered = [
+ "asPointerWrapper",
+ "contextDescriptorWrapper",
+ "forTypeContextDescriptorWrapper",
+ "typeContextDescriptorWrapper",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeContextWrapperBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let isStruct: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeContextWrapperBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(for wrapper: TypeContextWrapper) -> String {
+ let descriptorOffset = wrapper.typeContextDescriptorWrapper.contextDescriptor.offset
+ let isStruct = wrapper.isStruct
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ isStruct: \(literal: isStruct)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeMetadataRecordBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeMetadataRecordBaselineGenerator.swift
new file mode 100644
index 00000000..76511129
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeMetadataRecordBaselineGenerator.swift
@@ -0,0 +1,126 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOExtensions
+import MachOFoundation
+import MachOKit
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TypeMetadataRecordBaseline.swift`.
+///
+/// `TypeMetadataRecord` mirrors `TargetTypeMetadataRecord` from the Swift
+/// runtime — one entry per 4-byte slot in `__swift5_types`/`__swift5_types2`.
+/// Public members are `offset`/`layout` plus the derived `typeKind` var
+/// and the `contextDescriptor` resolution method (MachO + ReadingContext
+/// overloads collapse to a single MethodKey under PublicMemberScanner's
+/// name-only key).
+///
+/// We materialize a representative record by walking
+/// `__swift5_types`/`__swift5_types2` and picking the first entry whose
+/// resolved descriptor is `Structs.StructTest`. The `typeKind` for that
+/// record is `.directTypeDescriptor` and `contextDescriptor(in:)`
+/// resolves to a `.type(.struct(...))` `ContextDescriptorWrapper`.
+package enum TypeMetadataRecordBaselineGenerator {
+ package static func generate(
+ in machO: MachOFile,
+ outputDirectory: URL
+ ) throws {
+ let structTest = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let record = try findTypeMetadataRecord(targetingDescriptorOffset: structTest.offset, in: machO)
+
+ let entryExpr = try emitEntryExpr(for: record, in: machO)
+
+ let registered = [
+ "contextDescriptor",
+ "layout",
+ "offset",
+ "typeKind",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeMetadataRecordBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let offset: Int
+ let layoutRelativeOffset: Int32
+ let typeKindRawValue: UInt8
+ let contextDescriptorOffset: Int
+ }
+
+ static let structTestRecord = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeMetadataRecordBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ /// Walks `__swift5_types` (and `__swift5_types2` if present) and returns
+ /// the `TypeMetadataRecord` whose resolved descriptor lives at
+ /// `targetOffset`. Used to find the record that points at
+ /// `Structs.StructTest`.
+ private static func findTypeMetadataRecord(
+ targetingDescriptorOffset targetOffset: Int,
+ in machO: MachOFile
+ ) throws -> TypeMetadataRecord {
+ for sectionName in [MachOSwiftSectionName.__swift5_types, .__swift5_types2] {
+ let section: any SectionProtocol
+ do {
+ section = try machO.section(for: sectionName)
+ } catch {
+ continue
+ }
+ let sectionOffset = if let cache = machO.cache {
+ section.address - cache.mainCacheHeader.sharedRegionStart.cast()
+ } else {
+ section.offset
+ }
+ let recordSize = TypeMetadataRecord.layoutSize
+ let records: [TypeMetadataRecord] = try machO.readWrapperElements(
+ offset: sectionOffset,
+ numberOfElements: section.size / recordSize
+ )
+ for record in records {
+ guard let resolved = try? record.contextDescriptor(in: machO) else { continue }
+ if resolved.contextDescriptor.offset == targetOffset {
+ return record
+ }
+ }
+ }
+ throw RequiredError.requiredNonOptional
+ }
+
+ private static func emitEntryExpr(
+ for record: TypeMetadataRecord,
+ in machO: MachOFile
+ ) throws -> String {
+ let offset = record.offset
+ // `relativeOffset` is a signed 32-bit displacement that can be
+ // negative (the descriptor often lives BEFORE the record). Emit it
+ // as a decimal literal so the baseline `Int32` field accepts it
+ // directly; hex-as-zero-extended-UInt64 wouldn't compile.
+ let layoutRelativeOffset = record.layout.nominalTypeDescriptor.relativeOffset
+ let typeKindRawValue = record.typeKind.rawValue
+ let contextDescriptorOffset = try required(record.contextDescriptor(in: machO)).contextDescriptor.offset
+
+ let expr: ExprSyntax = """
+ Entry(
+ offset: \(raw: BaselineEmitter.hex(offset)),
+ layoutRelativeOffset: \(literal: layoutRelativeOffset),
+ typeKindRawValue: \(raw: BaselineEmitter.hex(typeKindRawValue)),
+ contextDescriptorOffset: \(raw: BaselineEmitter.hex(contextDescriptorOffset))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeReferenceBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeReferenceBaselineGenerator.swift
new file mode 100644
index 00000000..9366a8f0
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Type/TypeReferenceBaselineGenerator.swift
@@ -0,0 +1,130 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOExtensions
+import MachOFoundation
+import MachOKit
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TypeReferenceBaseline.swift`.
+///
+/// `TypeReference` is the 4-case sum type covering the runtime's
+/// `TypeReferenceKind` (`directTypeDescriptor`/`indirectTypeDescriptor`/
+/// `directObjCClassName`/`indirectObjCClass`). Public members are
+/// `forKind(_:at:)` (the static constructor that picks the right arm
+/// based on the kind byte) and the `resolve` instance methods (MachO +
+/// InProcess + ReadingContext overloads collapse to one MethodKey under
+/// PublicMemberScanner's name-only key). The `ResolvedTypeReference`
+/// enum declared in the same file has only cases, no methods/vars, so
+/// it doesn't need its own baseline.
+///
+/// Fixture: walk `__swift5_types`/`__swift5_types2`, find the record
+/// pointing at `Structs.StructTest`, and use its relative offset and
+/// `typeKind` to materialize a `TypeReference.directTypeDescriptor(...)`.
+/// `forKind(.directTypeDescriptor, at: …)` reproduces the same value.
+package enum TypeReferenceBaselineGenerator {
+ package static func generate(
+ in machO: MachOFile,
+ outputDirectory: URL
+ ) throws {
+ let structTest = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let record = try findTypeMetadataRecord(targetingDescriptorOffset: structTest.offset, in: machO)
+
+ // The record's `nominalTypeDescriptor` field offset is the absolute
+ // file offset of the field — `record.offset(of:)` already includes
+ // `record.offset`. We resolve relative pointers against this address.
+ let recordFieldOffset = record.offset(of: \.nominalTypeDescriptor)
+ let relativeOffset = record.layout.nominalTypeDescriptor.relativeOffset
+
+ let entryExpr = emitEntryExpr(
+ recordFieldOffset: recordFieldOffset,
+ relativeOffset: relativeOffset,
+ kindRawValue: record.typeKind.rawValue,
+ descriptorOffset: structTest.offset
+ )
+
+ let registered = [
+ "forKind",
+ "resolve",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeReferenceBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let recordFieldOffset: Int
+ let relativeOffset: Int32
+ let kindRawValue: UInt8
+ let resolvedDescriptorOffset: Int
+ }
+
+ static let structTestRecord = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeReferenceBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func findTypeMetadataRecord(
+ targetingDescriptorOffset targetOffset: Int,
+ in machO: MachOFile
+ ) throws -> TypeMetadataRecord {
+ for sectionName in [MachOSwiftSectionName.__swift5_types, .__swift5_types2] {
+ let section: any SectionProtocol
+ do {
+ section = try machO.section(for: sectionName)
+ } catch {
+ continue
+ }
+ let sectionOffset = if let cache = machO.cache {
+ section.address - cache.mainCacheHeader.sharedRegionStart.cast()
+ } else {
+ section.offset
+ }
+ let recordSize = TypeMetadataRecord.layoutSize
+ let records: [TypeMetadataRecord] = try machO.readWrapperElements(
+ offset: sectionOffset,
+ numberOfElements: section.size / recordSize
+ )
+ for record in records {
+ guard let resolved = try? record.contextDescriptor(in: machO) else { continue }
+ if resolved.contextDescriptor.offset == targetOffset {
+ return record
+ }
+ }
+ }
+ throw RequiredError.requiredNonOptional
+ }
+
+ private static func emitEntryExpr(
+ recordFieldOffset: Int,
+ relativeOffset: Int32,
+ kindRawValue: UInt8,
+ descriptorOffset: Int
+ ) -> String {
+ // `relativeOffset` is a signed 32-bit displacement that can be
+ // negative (the descriptor often lives BEFORE the record). Emit
+ // as a decimal literal so the baseline's `Int32` field accepts
+ // it directly.
+ let expr: ExprSyntax = """
+ Entry(
+ recordFieldOffset: \(raw: BaselineEmitter.hex(recordFieldOffset)),
+ relativeOffset: \(literal: relativeOffset),
+ kindRawValue: \(raw: BaselineEmitter.hex(kindRawValue)),
+ resolvedDescriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset))
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Type/ValueMetadataBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Type/ValueMetadataBaselineGenerator.swift
new file mode 100644
index 00000000..eea88ff9
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Type/ValueMetadataBaselineGenerator.swift
@@ -0,0 +1,46 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/ValueMetadataBaseline.swift`.
+///
+/// `ValueMetadata` is the kind-erased value-type metadata wrapper (the
+/// runtime layout shared by `StructMetadata` and `EnumMetadata`'s value
+/// arms). Like its concrete-kind cousins, instances can only be obtained
+/// by invoking the metadata accessor function from a *loaded* MachOImage
+/// in the current process; live pointer values aren't stable across runs,
+/// so we emit only the registered member names and let the companion
+/// Suite verify cross-reader equality at runtime.
+package enum ValueMetadataBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared directly in ValueMetadata.swift.
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ let registered = [
+ "layout",
+ "offset",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ValueMetadata can only be materialized via a MachOImage accessor
+ // function at runtime; live pointer values are not embedded here. The
+ // companion Suite (ValueMetadataTests) relies on cross-reader
+ // equality between the available reader axes for correctness.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ValueMetadataBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ValueMetadataBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Type/ValueMetadataProtocolBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Type/ValueMetadataProtocolBaselineGenerator.swift
new file mode 100644
index 00000000..fa022104
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Type/ValueMetadataProtocolBaselineGenerator.swift
@@ -0,0 +1,46 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/ValueMetadataProtocolBaseline.swift`.
+///
+/// Per the protocol-extension attribution rule (see `BaselineGenerator.swift`),
+/// `descriptor` is declared in `extension ValueMetadataProtocol { ... }`
+/// (across body, in-process, and ReadingContext variants) and attributes
+/// to the protocol. The three overloads collapse to one MethodKey under
+/// PublicMemberScanner's name-only key.
+///
+/// Like `StructMetadataProtocolBaseline`, this only emits the registered
+/// member name. The protocol's `descriptor` method requires a live
+/// `ValueMetadata`-conforming instance, only reachable through MachOImage
+/// at runtime. Cross-reader equality assertions in the companion Suite
+/// (ValueMetadataProtocolTests) cover correctness.
+package enum ValueMetadataProtocolBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "descriptor",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // Live ValueMetadata pointers cannot be embedded as literals; the
+ // companion Suite (ValueMetadataProtocolTests) verifies the method
+ // produces cross-reader-consistent results at runtime.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ValueMetadataProtocolBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ValueMetadataProtocolBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/Type/ValueTypeDescriptorWrapperBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/Type/ValueTypeDescriptorWrapperBaselineGenerator.swift
new file mode 100644
index 00000000..b7b73100
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/Type/ValueTypeDescriptorWrapperBaselineGenerator.swift
@@ -0,0 +1,90 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import MachOFoundation
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ValueTypeDescriptorWrapperBaseline.swift`.
+///
+/// `ValueTypeDescriptorWrapper` is the 2-case sum type covering the
+/// `enum`/`struct` value-type kinds (no `class` arm). It lives in the same
+/// file as `TypeContextDescriptorWrapper` but is a distinct type — the
+/// scanner attributes its public members to the `ValueTypeDescriptorWrapper`
+/// MethodKey namespace.
+///
+/// Members include three alternate-projection vars (`contextDescriptor`,
+/// `namedContextDescriptor`, `typeContextDescriptor`), the
+/// `asTypeContextDescriptorWrapper`/`asContextDescriptorWrapper` projection
+/// vars, and the `parent`/`genericContext` instance methods plus the
+/// `resolve` static family in the `Resolvable` extension. Each method
+/// collapses across MachO + InProcess + ReadingContext overloads under
+/// PublicMemberScanner's name-only key.
+///
+/// Picker: `Structs.StructTest`'s descriptor wrapped in `.struct(...)`.
+package enum ValueTypeDescriptorWrapperBaselineGenerator {
+ package static func generate(
+ in machO: some MachOSwiftSectionRepresentableWithCache,
+ outputDirectory: URL
+ ) throws {
+ let descriptor = try BaselineFixturePicker.struct_StructTest(in: machO)
+ let wrapper = ValueTypeDescriptorWrapper.struct(descriptor)
+ let entryExpr = try emitEntryExpr(for: wrapper, in: machO)
+
+ // Public members declared directly in TypeContextDescriptorWrapper.swift
+ // for the `ValueTypeDescriptorWrapper` enum (body + Resolvable extension).
+ let registered = [
+ "asContextDescriptorWrapper",
+ "asTypeContextDescriptorWrapper",
+ "contextDescriptor",
+ "genericContext",
+ "namedContextDescriptor",
+ "parent",
+ "resolve",
+ "typeContextDescriptor",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ValueTypeDescriptorWrapperBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let descriptorOffset: Int
+ let hasParent: Bool
+ let hasGenericContext: Bool
+ }
+
+ static let structTest = \(raw: entryExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ValueTypeDescriptorWrapperBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntryExpr(
+ for wrapper: ValueTypeDescriptorWrapper,
+ in machO: some MachOSwiftSectionRepresentableWithCache
+ ) throws -> String {
+ let descriptorOffset = wrapper.contextDescriptor.offset
+ let hasParent = (try wrapper.parent(in: machO)) != nil
+ let hasGenericContext = (try wrapper.genericContext(in: machO)) != nil
+
+ let expr: ExprSyntax = """
+ Entry(
+ descriptorOffset: \(raw: BaselineEmitter.hex(descriptorOffset)),
+ hasParent: \(literal: hasParent),
+ hasGenericContext: \(literal: hasGenericContext)
+ )
+ """
+ return expr.description
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ValueWitnessTable/TypeLayoutBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ValueWitnessTable/TypeLayoutBaselineGenerator.swift
new file mode 100644
index 00000000..4cba0dae
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ValueWitnessTable/TypeLayoutBaselineGenerator.swift
@@ -0,0 +1,53 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/TypeLayoutBaseline.swift`.
+///
+/// `TypeLayout` is the (size, stride, flags, extraInhabitantCount)
+/// quadruple projected from a `ValueWitnessTable`. It declares four
+/// stored properties, a `dynamicMemberLookup` subscript that bridges
+/// to `ValueWitnessFlags` keypaths, and `CustomStringConvertible` /
+/// `CustomDebugStringConvertible` descriptions. The Suite re-evaluates
+/// each accessor against synthetic instances; cross-reader equality is
+/// covered by the live-carrier paths in the Metadata Suite.
+package enum TypeLayoutBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ // Public members declared in TypeLayout.swift.
+ let registered = [
+ "debugDescription",
+ "description",
+ "extraInhabitantCount",
+ "flags",
+ "size",
+ "stride",
+ "subscript(dynamicMember:)",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // TypeLayout is a pure value-type projection of (size, stride,
+ // flags, extraInhabitantCount) from a ValueWitnessTable. The
+ // Suite re-evaluates each accessor against a synthetic instance
+ // — the underlying `flags` raw value is constructed from
+ // ValueWitnessFlags' static `let isNonPOD` etc. constants so
+ // the Suite is reader-independent.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum TypeLayoutBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("TypeLayoutBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ValueWitnessTable/ValueWitnessFlagsBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ValueWitnessTable/ValueWitnessFlagsBaselineGenerator.swift
new file mode 100644
index 00000000..0ba3064e
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ValueWitnessTable/ValueWitnessFlagsBaselineGenerator.swift
@@ -0,0 +1,131 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+@testable import MachOSwiftSection
+
+/// Emits `__Baseline__/ValueWitnessFlagsBaseline.swift`.
+///
+/// `ValueWitnessFlags` is a 32-bit `OptionSet` carried in every
+/// `ValueWitnessTable` / `TypeLayout`. The bit layout:
+/// - low 8 bits — `alignmentMask` (alignment - 1)
+/// - bit 16 — `isNonPOD`
+/// - bit 17 — `isNonInline`
+/// - bit 19 — `hasSpareBits`
+/// - bit 20 — `isNonBitwiseTakable`
+/// - bit 21 — `hasEnumWitnesses`
+/// - bit 22 — `inComplete`
+/// - bit 23 — `isNonCopyable`
+/// - bit 24 — `isNonBitwiseBorrowable`
+///
+/// The flags type is reader-independent — the Suite re-evaluates each
+/// accessor against synthetic raw values.
+package enum ValueWitnessFlagsBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let entries: [(label: String, rawValue: UInt32)] = [
+ // POD value type: alignment 8 (mask 7), inline storage,
+ // bitwise-takable, copyable.
+ ("podStruct", 0x0000_0007),
+ // Non-POD class instance: alignment 8 (mask 7), inline,
+ // not bitwise-takable, not copyable, has-enum-witnesses
+ // off.
+ ("nonPodReference", 0x0011_0007),
+ // Out-of-line storage (non-inline): alignment 8.
+ ("nonInlineStorage", 0x0002_0007),
+ // Has enum witnesses + spare bits.
+ ("enumWithSpareBits", 0x0028_0007),
+ // Incomplete (still being initialized).
+ ("incomplete", 0x0040_0007),
+ // Non-copyable (~Copyable).
+ ("nonCopyable", 0x0080_0007),
+ // Non-bitwise-borrowable.
+ ("nonBitwiseBorrowable", 0x0100_0007),
+ ]
+ let entriesExpr = emitEntriesExpr(for: entries)
+
+ // Public members declared in ValueWitnessFlags.swift. The
+ // OptionSet `static let` constants collapse into the
+ // option-set membership accessors under PublicMemberScanner's
+ // name-only key (e.g. `isNonPOD` and the `static let isNonPOD`
+ // share the name). We register each unique name once.
+ let registered = [
+ "alignment",
+ "alignmentMask",
+ "hasEnumWitnesses",
+ "hasSpareBits",
+ "inComplete",
+ "init(rawValue:)",
+ "isBitwiseBorrowable",
+ "isBitwiseTakable",
+ "isCopyable",
+ "isIncomplete",
+ "isInlineStorage",
+ "isNonBitwiseBorrowable",
+ "isNonBitwiseTakable",
+ "isNonCopyable",
+ "isNonInline",
+ "isNonPOD",
+ "isPOD",
+ "maxNumExtraInhabitants",
+ "rawValue",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ValueWitnessFlags is a pure raw-value bit decoder (no MachO
+ // dependency). The baseline embeds canonical synthetic raw
+ // values exercising each documented bit field.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ValueWitnessFlagsBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+
+ struct Entry {
+ let rawValue: UInt32
+ let alignmentMask: UInt64
+ let alignment: UInt64
+ let isPOD: Bool
+ let isInlineStorage: Bool
+ let isBitwiseTakable: Bool
+ let isBitwiseBorrowable: Bool
+ let isCopyable: Bool
+ let hasEnumWitnesses: Bool
+ let isIncomplete: Bool
+ }
+
+ static let cases: [Entry] = \(raw: entriesExpr)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ValueWitnessFlagsBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+
+ private static func emitEntriesExpr(for entries: [(label: String, rawValue: UInt32)]) -> String {
+ let lines = entries.map { entry -> String in
+ let flags = ValueWitnessFlags(rawValue: entry.rawValue)
+ return """
+ // \(entry.label)
+ Entry(
+ rawValue: \(BaselineEmitter.hex(entry.rawValue)),
+ alignmentMask: \(BaselineEmitter.hex(flags.alignmentMask)),
+ alignment: \(BaselineEmitter.hex(flags.alignment)),
+ isPOD: \(flags.isPOD),
+ isInlineStorage: \(flags.isInlineStorage),
+ isBitwiseTakable: \(flags.isBitwiseTakable),
+ isBitwiseBorrowable: \(flags.isBitwiseBorrowable),
+ isCopyable: \(flags.isCopyable),
+ hasEnumWitnesses: \(flags.hasEnumWitnesses),
+ isIncomplete: \(flags.isIncomplete)
+ )
+ """
+ }
+ return "[\n\(lines.joined(separator: ",\n"))\n]"
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Baseline/Generators/ValueWitnessTable/ValueWitnessTableBaselineGenerator.swift b/Sources/MachOFixtureSupport/Baseline/Generators/ValueWitnessTable/ValueWitnessTableBaselineGenerator.swift
new file mode 100644
index 00000000..1647f8f6
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Baseline/Generators/ValueWitnessTable/ValueWitnessTableBaselineGenerator.swift
@@ -0,0 +1,55 @@
+import Foundation
+import SwiftSyntax
+import SwiftSyntaxBuilder
+
+/// Emits `__Baseline__/ValueWitnessTableBaseline.swift`.
+///
+/// `ValueWitnessTable` is the runtime-allocated table of value-witness
+/// function pointers (initializeBufferWithCopyOfBuffer / destroy /
+/// assignWithCopy / etc.) plus the type-layout metadata (size /
+/// stride / flags / extraInhabitants). It's reachable only via
+/// `MetadataProtocol.valueWitnesses(in:)` from a loaded MachOImage —
+/// the function pointers live in the runtime image. The Suite
+/// materialises the value-witness table for `Structs.StructTest` and
+/// asserts cross-reader equality on the structural fields (size /
+/// stride / flags raw / numExtraInhabitants); the function pointers
+/// themselves vary per process and aren't compared literally.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+package enum ValueWitnessTableBaselineGenerator {
+ package static func generate(outputDirectory: URL) throws {
+ let registered = [
+ "layout",
+ "offset",
+ "typeLayout",
+ ]
+
+ let header = """
+ // AUTO-GENERATED — DO NOT EDIT.
+ // Regenerate via: Scripts/regen-baselines.sh
+ // Source fixture: SymbolTestsCore.framework
+ //
+ // ValueWitnessTable is reachable solely through
+ // `MetadataProtocol.valueWitnesses(in:)` from a loaded
+ // MachOImage — the function pointers live in the runtime image.
+ // The Suite materialises the table for Structs.StructTest and
+ // asserts cross-reader equality on the size / stride / flags /
+ // numExtraInhabitants ivars; per-process function pointers are
+ // not compared literally.
+ //
+ // `init(layout:offset:)` is filtered as memberwise-synthesized.
+ """
+
+ let file: SourceFileSyntax = """
+ \(raw: header)
+
+ enum ValueWitnessTableBaseline {
+ static let registeredTestMethodNames: Set = \(literal: registered)
+ }
+ """
+
+ let formatted = file.formatted().description + "\n"
+ let outputURL = outputDirectory.appendingPathComponent("ValueWitnessTableBaseline.swift")
+ try formatted.write(to: outputURL, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Coverage/CoverageAllowlist.swift b/Sources/MachOFixtureSupport/Coverage/CoverageAllowlist.swift
new file mode 100644
index 00000000..2d6c8064
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Coverage/CoverageAllowlist.swift
@@ -0,0 +1,65 @@
+import Foundation
+
+/// Why a `(typeName, memberName)` pair is allowed to skip cross-reader fixture coverage.
+package enum SentinelReason: Hashable {
+ /// The type is allocated by the Swift runtime at type-load time and is
+ /// never serialized into the fixture's Mach-O image. Covered via
+ /// `InProcessMetadataPicker` + single-reader assertions instead.
+ case runtimeOnly(detail: String)
+
+ /// SymbolTestsCore currently lacks a sample that surfaces this metadata
+ /// shape. Should be eliminated by extending the fixture (Phase B).
+ case needsFixtureExtension(detail: String)
+
+ /// Pure raw-value enum / marker protocol / pure-data utility. Sentinel
+ /// status is intended to be permanent. Future follow-ups may pin
+ /// `rawValue` literals as a deeper assertion.
+ case pureDataUtility(detail: String)
+}
+
+/// Either a legacy "scanner-saw-it-but-it-shouldn't-count" exemption (kept as-is
+/// from PR #85) or a typed sentinel with a reason.
+package enum AllowlistKind: Hashable {
+ case legacyExempt(reason: String)
+ case sentinel(SentinelReason)
+}
+
+/// A single entry exempting one (typeName, memberName) pair from coverage requirements.
+package struct CoverageAllowlistEntry: Hashable, CustomStringConvertible {
+ package let key: MethodKey
+ package let kind: AllowlistKind
+
+ package init(typeName: String, memberName: String, reason: String) {
+ self.key = MethodKey(typeName: typeName, memberName: memberName)
+ self.kind = .legacyExempt(reason: reason)
+ }
+
+ package init(typeName: String, memberName: String, sentinel: SentinelReason) {
+ self.key = MethodKey(typeName: typeName, memberName: memberName)
+ self.kind = .sentinel(sentinel)
+ }
+
+ package var description: String {
+ switch kind {
+ case .legacyExempt(let reason):
+ return "\(key) // legacyExempt: \(reason)"
+ case .sentinel(let reason):
+ return "\(key) // sentinel: \(reason)"
+ }
+ }
+}
+
+package enum CoverageAllowlistHelpers {
+ /// Construct flat `[CoverageAllowlistEntry]` with the same `SentinelReason`
+ /// applied to every member of `typeName`. Used in `CoverageAllowlistEntries.entries`
+ /// to avoid repeating the reason on every method.
+ package static func sentinelGroup(
+ typeName: String,
+ members: [String],
+ reason: SentinelReason
+ ) -> [CoverageAllowlistEntry] {
+ members.map { memberName in
+ CoverageAllowlistEntry(typeName: typeName, memberName: memberName, sentinel: reason)
+ }
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Coverage/FixtureSuite.swift b/Sources/MachOFixtureSupport/Coverage/FixtureSuite.swift
new file mode 100644
index 00000000..1c6a7693
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Coverage/FixtureSuite.swift
@@ -0,0 +1,29 @@
+import Foundation
+
+/// Conformance contract for fixture-based test suites participating in coverage tracking.
+///
+/// Each Suite type provides:
+/// - `testedTypeName`: the source-code Type whose public members the Suite covers
+/// (e.g. "StructDescriptor"). Must match the type name exactly as it appears in
+/// `Sources/MachOSwiftSection/Models/`.
+/// - `registeredTestMethodNames`: the member names covered by `@Test` methods in this Suite.
+/// For each entry "foo", the Coverage Invariant test expects a public member
+/// `.foo` (any overload group) to exist in the source.
+///
+/// **Actor isolation:** This protocol is `@MainActor`-isolated because all current
+/// conformers inherit from `MachOSwiftSectionFixtureTests`, which is `@MainActor`.
+/// Code iterating `[any FixtureSuite.Type]` (e.g., the Coverage Invariant Test in
+/// Task 16) must run on the main actor too.
+///
+/// **Suite inclusion rule:** Every Swift file under `Sources/MachOSwiftSection/Models/`
+/// gets a corresponding `Tests.swift` Suite UNLESS:
+/// - The file declares only `*Layout` types (covered by LayoutTests).
+/// - The file declares only enums/flags/protocols with no public func/var/init.
+/// - The file is excluded via `CoverageAllowlistEntries.swift` with a documented reason.
+///
+/// The Coverage Invariant Test (Task 16) catches drift between source and Suites.
+@MainActor
+package protocol FixtureSuite {
+ static var testedTypeName: String { get }
+ static var registeredTestMethodNames: Set { get }
+}
diff --git a/Sources/MachOFixtureSupport/Coverage/MethodKey.swift b/Sources/MachOFixtureSupport/Coverage/MethodKey.swift
new file mode 100644
index 00000000..5f762443
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Coverage/MethodKey.swift
@@ -0,0 +1,20 @@
+import Foundation
+
+package struct MethodKey: Hashable, Comparable, CustomStringConvertible {
+ package let typeName: String
+ package let memberName: String
+
+ package init(typeName: String, memberName: String) {
+ self.typeName = typeName
+ self.memberName = memberName
+ }
+
+ package static func < (lhs: MethodKey, rhs: MethodKey) -> Bool {
+ if lhs.typeName != rhs.typeName { return lhs.typeName < rhs.typeName }
+ return lhs.memberName < rhs.memberName
+ }
+
+ package var description: String {
+ "\(typeName).\(memberName)"
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Coverage/PublicMemberScanner.swift b/Sources/MachOFixtureSupport/Coverage/PublicMemberScanner.swift
new file mode 100644
index 00000000..1682c08d
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Coverage/PublicMemberScanner.swift
@@ -0,0 +1,220 @@
+import Foundation
+import SwiftSyntax
+import SwiftParser
+
+/// Scans a directory of Swift source files and extracts the set of public/open
+/// `func`, `var`, `init`, and `subscript` members, keyed by `(typeName, memberName)`.
+///
+/// Skipped:
+/// - `internal`, `private`, `fileprivate` declarations
+/// - `@_spi(...)` declarations (treated as non-public)
+/// - members on types named exactly `Layout` (the nested record struct used
+/// by `*Descriptor`/`*Metadata` wrappers — exercised via parent's tests
+/// and `LayoutTests` rather than standalone Suites). Top-level types
+/// whose name happens to end with `Layout` (e.g., `TypeLayout`) are NOT
+/// filtered.
+/// - `init(layout:offset:)` synthesized by `@MemberwiseInit`
+/// - extensions on enums whose name ends with `Kind`/`Flags` and similar pure-data utilities
+/// (handled via allowlist if they slip through)
+///
+/// Identifier normalization: backtick-quoted identifiers (e.g.,
+/// `` `Protocol` ``, `` `protocol` ``) appear without the backticks in
+/// emitted MethodKeys so they align with `Suite.testedTypeName` /
+/// `registeredTestMethodNames` (which are plain Strings).
+package struct PublicMemberScanner {
+ package let sourceRoot: URL
+
+ package init(sourceRoot: URL) {
+ self.sourceRoot = sourceRoot
+ }
+
+ package func scan(applyingAllowlist allowlist: Set = []) throws -> Set {
+ let files = try collectSwiftFiles(under: sourceRoot)
+ var result: Set = []
+ for fileURL in files {
+ let source = try String(contentsOf: fileURL, encoding: .utf8)
+ let tree = Parser.parse(source: source)
+ let visitor = PublicMemberVisitor(viewMode: .sourceAccurate)
+ visitor.walk(tree)
+ for key in visitor.collected {
+ if allowlist.contains(key) { continue }
+ result.insert(key)
+ }
+ }
+ return result
+ }
+
+ private func collectSwiftFiles(under root: URL) throws -> [URL] {
+ let fileManager = FileManager.default
+ let enumerator = fileManager.enumerator(at: root, includingPropertiesForKeys: nil)
+ var files: [URL] = []
+ while let url = enumerator?.nextObject() as? URL {
+ if url.pathExtension == "swift" { files.append(url) }
+ }
+ return files
+ }
+}
+
+private final class PublicMemberVisitor: SyntaxVisitor {
+ private(set) var collected: [MethodKey] = []
+ private var typeStack: [String] = []
+ /// Tracks `@_spi(...)` status of each enclosing scope. A member is SPI if its
+ /// own attributes carry `@_spi`, OR any enclosing extension/type does.
+ private var spiStack: [Bool] = []
+
+ override func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind {
+ typeStack.append(stripBackticks(node.name.text))
+ spiStack.append(hasSPI(attributes: node.attributes))
+ return .visitChildren
+ }
+ override func visitPost(_ node: ClassDeclSyntax) {
+ typeStack.removeLast()
+ spiStack.removeLast()
+ }
+
+ override func visit(_ node: StructDeclSyntax) -> SyntaxVisitorContinueKind {
+ typeStack.append(stripBackticks(node.name.text))
+ spiStack.append(hasSPI(attributes: node.attributes))
+ return .visitChildren
+ }
+ override func visitPost(_ node: StructDeclSyntax) {
+ typeStack.removeLast()
+ spiStack.removeLast()
+ }
+
+ override func visit(_ node: EnumDeclSyntax) -> SyntaxVisitorContinueKind {
+ typeStack.append(stripBackticks(node.name.text))
+ spiStack.append(hasSPI(attributes: node.attributes))
+ return .visitChildren
+ }
+ override func visitPost(_ node: EnumDeclSyntax) {
+ typeStack.removeLast()
+ spiStack.removeLast()
+ }
+
+ override func visit(_ node: ProtocolDeclSyntax) -> SyntaxVisitorContinueKind {
+ typeStack.append(stripBackticks(node.name.text))
+ spiStack.append(hasSPI(attributes: node.attributes))
+ return .visitChildren
+ }
+ override func visitPost(_ node: ProtocolDeclSyntax) {
+ typeStack.removeLast()
+ spiStack.removeLast()
+ }
+
+ override func visit(_ node: ExtensionDeclSyntax) -> SyntaxVisitorContinueKind {
+ // Push the extended type as the current scope. Strip surrounding
+ // backticks so identifiers like `extension `Protocol`` resolve to
+ // the same MethodKey typeName ("Protocol") that Suites declare via
+ // their `testedTypeName: String` constants.
+ typeStack.append(stripBackticks(node.extendedType.trimmedDescription))
+ spiStack.append(hasSPI(attributes: node.attributes))
+ return .visitChildren
+ }
+ override func visitPost(_ node: ExtensionDeclSyntax) {
+ typeStack.removeLast()
+ spiStack.removeLast()
+ }
+
+ override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind {
+ guard isPublicLike(node.modifiers, attributes: node.attributes) else { return .skipChildren }
+ guard let typeName = currentTypeName() else { return .skipChildren }
+ if shouldSkip(typeName: typeName) { return .skipChildren }
+ collected.append(MethodKey(typeName: typeName, memberName: stripBackticks(node.name.text)))
+ return .skipChildren
+ }
+
+ override func visit(_ node: VariableDeclSyntax) -> SyntaxVisitorContinueKind {
+ guard isPublicLike(node.modifiers, attributes: node.attributes) else { return .skipChildren }
+ guard let typeName = currentTypeName() else { return .skipChildren }
+ if shouldSkip(typeName: typeName) { return .skipChildren }
+ for binding in node.bindings {
+ if let pattern = binding.pattern.as(IdentifierPatternSyntax.self) {
+ collected.append(MethodKey(typeName: typeName, memberName: stripBackticks(pattern.identifier.text)))
+ }
+ }
+ return .skipChildren
+ }
+
+ override func visit(_ node: InitializerDeclSyntax) -> SyntaxVisitorContinueKind {
+ guard isPublicLike(node.modifiers, attributes: node.attributes) else { return .skipChildren }
+ guard let typeName = currentTypeName() else { return .skipChildren }
+ if shouldSkip(typeName: typeName) { return .skipChildren }
+ if isMemberwiseSynthesizedInit(node) { return .skipChildren }
+ let signature = node.signature.parameterClause.parameters.map { $0.firstName.text }.joined(separator: ":")
+ let memberName = signature.isEmpty ? "init" : "init(\(signature):)"
+ collected.append(MethodKey(typeName: typeName, memberName: memberName))
+ return .skipChildren
+ }
+
+ override func visit(_ node: SubscriptDeclSyntax) -> SyntaxVisitorContinueKind {
+ guard isPublicLike(node.modifiers, attributes: node.attributes) else { return .skipChildren }
+ guard let typeName = currentTypeName() else { return .skipChildren }
+ if shouldSkip(typeName: typeName) { return .skipChildren }
+ let signature = node.parameterClause.parameters.map { $0.firstName.text }.joined(separator: ":")
+ let memberName = signature.isEmpty ? "subscript" : "subscript(\(signature):)"
+ collected.append(MethodKey(typeName: typeName, memberName: memberName))
+ return .skipChildren
+ }
+
+ private func currentTypeName() -> String? {
+ typeStack.last
+ }
+
+ private func shouldSkip(typeName: String) -> Bool {
+ // Skip the nested `Layout` struct used by `*Descriptor`/`*Metadata`
+ // wrappers (e.g., `StructDescriptor.Layout`). Those record types
+ // intentionally project raw on-disk fields and are exercised via
+ // their parent's tests, not as standalone Suites.
+ //
+ // We deliberately match only the nested name (after typeStack
+ // resolution returns the immediate enclosing identifier "Layout"),
+ // NOT every type whose name happens to end with "Layout". A
+ // top-level type like `TypeLayout` is a real public API surface
+ // with its own Suite, so it must NOT be filtered here.
+ if typeName == "Layout" { return true }
+ return false
+ }
+
+ private func isPublicLike(_ modifiers: DeclModifierListSyntax, attributes: AttributeListSyntax) -> Bool {
+ // Reject if any @_spi attribute is present on the member itself,
+ // or on any enclosing extension/type scope.
+ if hasSPI(attributes: attributes) { return false }
+ if spiStack.contains(true) { return false }
+ // Accept only if `public` or `open` modifier exists.
+ for modifier in modifiers {
+ let name = modifier.name.text
+ if name == "public" || name == "open" { return true }
+ }
+ return false
+ }
+
+ private func hasSPI(attributes: AttributeListSyntax) -> Bool {
+ for attribute in attributes {
+ if let attr = attribute.as(AttributeSyntax.self),
+ attr.attributeName.trimmedDescription == "_spi" {
+ return true
+ }
+ }
+ return false
+ }
+
+ private func isMemberwiseSynthesizedInit(_ node: InitializerDeclSyntax) -> Bool {
+ // Detect explicit synthesis when authoring class declares @MemberwiseInit;
+ // the macro expands to init(layout: ..., offset: ...).
+ let names = node.signature.parameterClause.parameters.map { $0.firstName.text }
+ return names == ["layout", "offset"] || names == ["offset", "layout"]
+ }
+
+ /// Identifiers that collide with Swift keywords (e.g., `protocol`,
+ /// `Protocol`) appear in source as backtick-quoted (`` `protocol` ``). The
+ /// token text retains those backticks; strip them so MethodKey lookups
+ /// align with the unquoted form Suites use in `testedTypeName` /
+ /// `registeredTestMethodNames`.
+ private func stripBackticks(_ identifier: String) -> String {
+ var stripped = identifier
+ if stripped.hasPrefix("`") { stripped.removeFirst() }
+ if stripped.hasSuffix("`") { stripped.removeLast() }
+ return stripped
+ }
+}
diff --git a/Sources/MachOFixtureSupport/Coverage/SuiteBehaviorScanner.swift b/Sources/MachOFixtureSupport/Coverage/SuiteBehaviorScanner.swift
new file mode 100644
index 00000000..fd5c03e2
--- /dev/null
+++ b/Sources/MachOFixtureSupport/Coverage/SuiteBehaviorScanner.swift
@@ -0,0 +1,182 @@
+import Foundation
+import SwiftSyntax
+import SwiftParser
+
+/// Scans `*Tests.swift` Suite source files and reports per-method behavior:
+/// whether each `@Test func` exercises any reader/context machinery, only
+/// touches the in-process context, or is a pure registration-only sentinel.
+///
+/// Classification rules (applied in order):
+///
+/// 1. If the `@Test func` body itself references any reader/context
+/// identifier (`acrossAllReaders`, `acrossAllContexts`, `machOFile`,
+/// `machOImage`, `fileContext`, `imageContext`) → `.acrossAllReaders`.
+/// 2. Otherwise, if the body explicitly uses `usingInProcessOnly` or
+/// `inProcessContext` → `.inProcessOnly`.
+/// 3. Otherwise, fall back to the *enclosing class body*: if the entire
+/// class references any cross-reader identifier (typically through a
+/// private helper like `loadStructTestMetadata()` that the test calls),
+/// treat the method as `.acrossAllReaders` because the helper-call
+/// pattern means the test transitively exercises the reader. If only
+/// `usingInProcessOnly` / `inProcessContext` shows up class-wide, treat
+/// it as `.inProcessOnly`.
+/// 4. Bodies and classes with none of those markers classify as
+/// `.sentinel` (registration-only / synthetic memberwise tests).
+///
+/// Used by `MachOSwiftSectionCoverageInvariantTests` to enforce that every
+/// sentinel-only method is declared in `CoverageAllowlistEntries`.
+package struct SuiteBehaviorScanner {
+ package enum MethodBehavior: Equatable {
+ case acrossAllReaders
+ case inProcessOnly
+ case sentinel
+ }
+
+ package let suiteRoot: URL
+
+ package init(suiteRoot: URL) {
+ self.suiteRoot = suiteRoot
+ }
+
+ package func scan() throws -> [MethodKey: MethodBehavior] {
+ let files = try collectSwiftFiles(under: suiteRoot)
+ var result: [MethodKey: MethodBehavior] = [:]
+ for fileURL in files {
+ let source = try String(contentsOf: fileURL, encoding: .utf8)
+ let tree = Parser.parse(source: source)
+ let visitor = SuiteBehaviorVisitor(viewMode: .sourceAccurate)
+ visitor.walk(tree)
+ for entry in visitor.collected {
+ let key = MethodKey(typeName: entry.testedTypeName, memberName: entry.methodName)
+ result[key] = entry.behavior
+ }
+ }
+ return result
+ }
+
+ private func collectSwiftFiles(under root: URL) throws -> [URL] {
+ let fileManager = FileManager.default
+ let enumerator = fileManager.enumerator(at: root, includingPropertiesForKeys: nil)
+ var files: [URL] = []
+ while let url = enumerator?.nextObject() as? URL {
+ if url.pathExtension == "swift" { files.append(url) }
+ }
+ return files
+ }
+}
+
+private final class SuiteBehaviorVisitor: SyntaxVisitor {
+ struct Entry {
+ let testedTypeName: String
+ let methodName: String
+ let behavior: SuiteBehaviorScanner.MethodBehavior
+ }
+ private(set) var collected: [Entry] = []
+ private var currentTestedTypeName: String?
+ /// The serialized text of the enclosing class/struct member block, used
+ /// as a fallback when the immediate `@Test func` body has no reader
+ /// markers (the test typically calls a private helper that does).
+ private var currentEnclosingClassBodyText: String?
+
+ override func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind {
+ currentTestedTypeName = extractTestedTypeName(from: node.memberBlock)
+ currentEnclosingClassBodyText = node.memberBlock.description
+ return .visitChildren
+ }
+ override func visitPost(_ node: ClassDeclSyntax) {
+ currentTestedTypeName = nil
+ currentEnclosingClassBodyText = nil
+ }
+
+ override func visit(_ node: StructDeclSyntax) -> SyntaxVisitorContinueKind {
+ currentTestedTypeName = extractTestedTypeName(from: node.memberBlock)
+ currentEnclosingClassBodyText = node.memberBlock.description
+ return .visitChildren
+ }
+ override func visitPost(_ node: StructDeclSyntax) {
+ currentTestedTypeName = nil
+ currentEnclosingClassBodyText = nil
+ }
+
+ override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind {
+ guard hasTestAttribute(node.attributes),
+ let testedTypeName = currentTestedTypeName,
+ let body = node.body else {
+ return .skipChildren
+ }
+ let behavior = inferBehavior(
+ fromBody: body,
+ enclosingClassBodyText: currentEnclosingClassBodyText
+ )
+ collected.append(Entry(
+ testedTypeName: testedTypeName,
+ methodName: node.name.text,
+ behavior: behavior
+ ))
+ return .skipChildren
+ }
+
+ private func extractTestedTypeName(from memberBlock: MemberBlockSyntax) -> String? {
+ for member in memberBlock.members {
+ guard let varDecl = member.decl.as(VariableDeclSyntax.self) else { continue }
+ let isStatic = varDecl.modifiers.contains(where: { $0.name.text == "static" })
+ guard isStatic else { continue }
+ for binding in varDecl.bindings {
+ guard let pattern = binding.pattern.as(IdentifierPatternSyntax.self),
+ pattern.identifier.text == "testedTypeName",
+ let initializer = binding.initializer,
+ let stringLit = initializer.value.as(StringLiteralExprSyntax.self)
+ else { continue }
+ let value = stringLit.segments.compactMap {
+ $0.as(StringSegmentSyntax.self)?.content.text
+ }.joined()
+ if !value.isEmpty { return value }
+ }
+ }
+ return nil
+ }
+
+ private func hasTestAttribute(_ attributes: AttributeListSyntax) -> Bool {
+ for attribute in attributes {
+ if let attr = attribute.as(AttributeSyntax.self),
+ attr.attributeName.trimmedDescription == "Test" {
+ return true
+ }
+ }
+ return false
+ }
+
+ private static let crossReaderMarkers = [
+ "acrossAllReaders", "acrossAllContexts",
+ "machOFile", "machOImage",
+ "fileContext", "imageContext",
+ ]
+ private static let inProcessMarkers = ["usingInProcessOnly", "inProcessContext"]
+
+ private func inferBehavior(
+ fromBody body: CodeBlockSyntax,
+ enclosingClassBodyText: String?
+ ) -> SuiteBehaviorScanner.MethodBehavior {
+ let bodyText = body.description
+ if Self.crossReaderMarkers.contains(where: { bodyText.contains($0) }) {
+ return .acrossAllReaders
+ }
+ if Self.inProcessMarkers.contains(where: { bodyText.contains($0) }) {
+ return .inProcessOnly
+ }
+ // Fall back to the enclosing class body. Tests frequently call a
+ // private helper (e.g. `loadStructTestMetadata()`) whose body is the
+ // only place the reader is referenced; the @Test func body itself
+ // contains no reader marker. Treat the test as `.acrossAllReaders`
+ // when the enclosing class as a whole references reader markers.
+ if let enclosingText = enclosingClassBodyText {
+ if Self.crossReaderMarkers.contains(where: { enclosingText.contains($0) }) {
+ return .acrossAllReaders
+ }
+ if Self.inProcessMarkers.contains(where: { enclosingText.contains($0) }) {
+ return .inProcessOnly
+ }
+ }
+ return .sentinel
+ }
+}
diff --git a/Sources/MachOTestingSupport/DemangleOptions.swift b/Sources/MachOFixtureSupport/DemangleOptions.swift
similarity index 100%
rename from Sources/MachOTestingSupport/DemangleOptions.swift
rename to Sources/MachOFixtureSupport/DemangleOptions.swift
diff --git a/Sources/MachOTestingSupport/DumpableTests.swift b/Sources/MachOFixtureSupport/DumpableTests.swift
similarity index 100%
rename from Sources/MachOTestingSupport/DumpableTests.swift
rename to Sources/MachOFixtureSupport/DumpableTests.swift
diff --git a/Sources/MachOTestingSupport/DyldSharedCachePath.swift b/Sources/MachOFixtureSupport/DyldSharedCachePath.swift
similarity index 100%
rename from Sources/MachOTestingSupport/DyldSharedCachePath.swift
rename to Sources/MachOFixtureSupport/DyldSharedCachePath.swift
diff --git a/Sources/MachOTestingSupport/Extensions.swift b/Sources/MachOFixtureSupport/Extensions.swift
similarity index 100%
rename from Sources/MachOTestingSupport/Extensions.swift
rename to Sources/MachOFixtureSupport/Extensions.swift
diff --git a/Sources/MachOFixtureSupport/FixtureLoadError.swift b/Sources/MachOFixtureSupport/FixtureLoadError.swift
new file mode 100644
index 00000000..ca4aace7
--- /dev/null
+++ b/Sources/MachOFixtureSupport/FixtureLoadError.swift
@@ -0,0 +1,23 @@
+import Foundation
+
+package enum FixtureLoadError: Error, CustomStringConvertible {
+ case fixtureFileMissing(path: String)
+ case imageNotFoundAfterDlopen(path: String, dlerror: String?)
+
+ package var description: String {
+ switch self {
+ case .fixtureFileMissing(let path):
+ return """
+ Fixture binary not found at \(path).
+ Build it with:
+ xcodebuild -project Tests/Projects/SymbolTests/SymbolTests.xcodeproj \\
+ -scheme SymbolTestsCore -configuration Release build
+ """
+ case .imageNotFoundAfterDlopen(let path, let dlerror):
+ return """
+ dlopen succeeded but MachOImage(name:) returned nil for \(path).
+ dlerror: \(dlerror ?? "")
+ """
+ }
+ }
+}
diff --git a/Sources/MachOFixtureSupport/InProcess/InProcessMetadataPicker.swift b/Sources/MachOFixtureSupport/InProcess/InProcessMetadataPicker.swift
new file mode 100644
index 00000000..169e20bc
--- /dev/null
+++ b/Sources/MachOFixtureSupport/InProcess/InProcessMetadataPicker.swift
@@ -0,0 +1,227 @@
+import Foundation
+import MachOSwiftSectionC
+
+/// Static `UnsafeRawPointer` constants exposing Swift runtime metadata
+/// for Suites that exercise `*Metadata` types without a fixture-binary
+/// section presence (runtime-allocated metadata).
+///
+/// Each constant is a `unsafeBitCast(.self, to: UnsafeRawPointer.self)`
+/// — this is the standard idiom for obtaining a metadata pointer from a
+/// Swift type reference. The pointer is stable for the test process's
+/// lifetime; the Swift runtime uniques metadata.
+///
+/// Suites consume these via `MachOSwiftSectionFixtureTests.usingInProcessOnly(_:)`.
+package enum InProcessMetadataPicker {
+ // MARK: - stdlib metatype
+
+ /// `type(of: Int.self)` — runtime-allocated `MetatypeMetadata` whose
+ /// `instanceType` is `Int.self`. Exercises `MetatypeMetadata.kind` +
+ /// `instanceType` chain.
+ ///
+ /// Note: `Int.self.self` is NOT the metatype metadata pointer — Swift
+ /// folds `T.self.self` to `T.self` (same metadata pointer to the
+ /// underlying type, kind 0x200/struct in this case). To obtain the
+ /// `MetatypeMetadata` instance the runtime allocates for `Int.Type`,
+ /// use `type(of: Int.self)`, which yields the `Int.Type.Type` value
+ /// whose pointer is the metatype metadata (kind 0x304).
+ package nonisolated(unsafe) static let stdlibIntMetatype: UnsafeRawPointer = {
+ unsafeBitCast(type(of: Int.self), to: UnsafeRawPointer.self)
+ }()
+
+ // MARK: - stdlib tuple
+
+ /// `(Int, String).self` — covers `TupleTypeMetadata` + `TupleTypeMetadata.Element`.
+ package nonisolated(unsafe) static let stdlibTupleIntString: UnsafeRawPointer = {
+ unsafeBitCast((Int, String).self, to: UnsafeRawPointer.self)
+ }()
+
+ // MARK: - stdlib function
+
+ /// `((Int) -> Void).self` — covers `FunctionTypeMetadata` + `FunctionTypeFlags`.
+ package nonisolated(unsafe) static let stdlibFunctionIntToVoid: UnsafeRawPointer = {
+ unsafeBitCast(((Int) -> Void).self, to: UnsafeRawPointer.self)
+ }()
+
+ // MARK: - stdlib existential
+
+ /// `Any.self` — covers `ExistentialTypeMetadata` for the maximally-general
+ /// existential.
+ ///
+ /// Note: `Any.self` has flags `0x80000000` (bit 31 set →
+ /// `classConstraint == .any`). Calling `flags.classConstraint` traps
+ /// because the source's accessor does `UInt8(rawValue & 0x80000000)`,
+ /// which overflows for any value ≥ 256. Tests that exercise
+ /// `classConstraint` / `isClassBounded` / `isObjC` / `representation`
+ /// must therefore use `stdlibAnyObjectExistential` instead.
+ package nonisolated(unsafe) static let stdlibAnyExistential: UnsafeRawPointer = {
+ unsafeBitCast(Any.self, to: UnsafeRawPointer.self)
+ }()
+
+ /// `AnyObject.self` — class-bounded existential with zero witness tables
+ /// (flags `0x0`). Safe substitute for `stdlibAnyExistential` when a test
+ /// needs to call `flags.classConstraint`.
+ package nonisolated(unsafe) static let stdlibAnyObjectExistential: UnsafeRawPointer = {
+ unsafeBitCast(AnyObject.self, to: UnsafeRawPointer.self)
+ }()
+
+ /// `(any Sequence).self` — covers `ExtendedExistentialTypeMetadata`
+ /// (with shape) and `ExtendedExistentialTypeShape`.
+ ///
+ /// Note: parameterized protocol existentials (with primary associated
+ /// types) are the only existentials whose runtime metadata kind is
+ /// `extendedExistential` (0x307). Bare existentials like `(any Equatable)`
+ /// or `Any` produce kind `existential` (0x303). The constant name retains
+ /// `stdlibAnyEquatable` for plan continuity, but the underlying type is
+ /// `(any Sequence)` because `Equatable` lacks a primary associated
+ /// type. Parameterized protocol existential metadata requires macOS
+ /// 13.0+ at the language-runtime level.
+ @available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
+ package nonisolated(unsafe) static let stdlibAnyEquatable: UnsafeRawPointer = {
+ unsafeBitCast((any Sequence).self, to: UnsafeRawPointer.self)
+ }()
+
+ /// `(Any).Type.self` — covers `ExistentialMetatypeMetadata`.
+ package nonisolated(unsafe) static let stdlibAnyMetatype: UnsafeRawPointer = {
+ unsafeBitCast(Any.Type.self, to: UnsafeRawPointer.self)
+ }()
+
+ // MARK: - stdlib opaque
+
+ /// `Int8.self` proxies for OpaqueMetadata; Swift runtime exposes opaque
+ /// metadata via Builtin types but `Builtin.Int8` isn't visible outside
+ /// the standard library, so use the user-visible `Int8` whose metadata
+ /// includes the same opaque-metadata layout.
+ package nonisolated(unsafe) static let stdlibOpaqueInt8: UnsafeRawPointer = {
+ unsafeBitCast(Int8.self, to: UnsafeRawPointer.self)
+ }()
+
+ // MARK: - stdlib fixed array (macOS 26+ only)
+
+ #if compiler(>=6.2)
+ @available(macOS 26.0, *)
+ package nonisolated(unsafe) static let stdlibInlineArrayInt3: UnsafeRawPointer = {
+ unsafeBitCast(InlineArray<3, Int>.self, to: UnsafeRawPointer.self)
+ }()
+ #endif
+
+ // MARK: - ObjC class wrapper
+
+ /// `NSObject.self` — an unmodified ObjC class. The Swift runtime
+ /// represents pure ObjC class metadata through an
+ /// `ObjCClassWrapperMetadata` (kind 0x305) whose `objcClass` field
+ /// points at the actual ObjC class metadata. This is the canonical
+ /// in-process source for `ObjCClassWrapperMetadataTests` (Phase B3).
+ package nonisolated(unsafe) static let foundationNSObjectWrapper: UnsafeRawPointer = {
+ unsafeBitCast(NSObject.self, to: UnsafeRawPointer.self)
+ }()
+
+ // MARK: - foreign class
+
+ /// `CFString.self` — a CoreFoundation type imported as a Swift
+ /// foreign class. The Swift compiler emits `ForeignClassMetadata`
+ /// (kind 0x203) for such types; the metadata lives in CoreFoundation
+ /// and is reached via `unsafeBitCast(CFString.self, ...)`. This is
+ /// the canonical in-process source for `ForeignClassMetadataTests`
+ /// (Phase B6).
+ package nonisolated(unsafe) static let coreFoundationCFString: UnsafeRawPointer = {
+ unsafeBitCast(CFString.self, to: UnsafeRawPointer.self)
+ }()
+}
+
+extension InProcessMetadataPicker {
+ /// Returns a metadata pointer for SymbolTestsCore's nominal type by
+ /// dlsym'ing the type's metadata accessor function and invoking it.
+ ///
+ /// `symbol` is the Swift mangled C symbol of the metadata accessor
+ /// (no leading underscore — `dlsym` adds it), e.g.
+ /// `$s15SymbolTestsCore7ClassesO9ClassTestCMa`.
+ ///
+ /// The fixture binary is loaded into the current process on first
+ /// call (idempotent). In the test process, `MachOSwiftSectionFixtureTests`
+ /// has already loaded it; this function's `dlopen` is then a no-op.
+ /// In the standalone `baseline-generator` process, this function's
+ /// load is the one that brings the framework's symbols into scope.
+ package static func fixtureMetadata(symbol: String) throws -> UnsafeRawPointer {
+ // Ensure the SymbolTestsCore fixture binary is dlopen'd into the
+ // current process. In the test process, MachOSwiftSectionFixtureTests
+ // already does this; calling here is a no-op the second time. In the
+ // standalone baseline-generator process, this is the only path that
+ // loads the framework.
+ try ensureFixtureLoaded()
+ guard let handle = dlopen(nil, RTLD_NOW) else {
+ throw FixtureLoadError.imageNotFoundAfterDlopen(path: "", dlerror: nil)
+ }
+ guard let accessorAddress = dlsym(handle, symbol) else {
+ throw FixtureLoadError.imageNotFoundAfterDlopen(
+ path: symbol,
+ dlerror: dlerror().map { String(cString: $0) }
+ )
+ }
+ // Type metadata accessor signature: `MetadataResponse(MetadataRequest)`
+ // with `swiftcall` calling convention. Swift `@convention(c)` cannot
+ // express a struct return that matches `swiftcc`, so dispatch through
+ // the C wrapper that uses `__attribute__((swiftcall))` internally.
+ // For non-generic types, pass MetadataRequest(0) and return the
+ // metadata pointer from the response.
+ let response = swift_section_callAccessor0(accessorAddress, 0)
+ guard let metadataPointer = response.Metadata else {
+ throw FixtureLoadError.imageNotFoundAfterDlopen(
+ path: symbol,
+ dlerror: "metadata accessor returned nil"
+ )
+ }
+ return UnsafeRawPointer(metadataPointer)
+ }
+
+ /// Returns the address of a fixture-binary symbol by resolving it via
+ /// `dlsym` against the in-process image. Use this to obtain the address
+ /// of a Swift descriptor (e.g. `...Mn`) or any other static symbol
+ /// without invoking it through a metadata accessor.
+ ///
+ /// `symbol` is the Swift mangled C symbol (no leading underscore —
+ /// `dlsym` adds it).
+ package static func fixtureSymbol(_ symbol: String) throws -> UnsafeRawPointer {
+ try ensureFixtureLoaded()
+ guard let handle = dlopen(nil, RTLD_NOW) else {
+ throw FixtureLoadError.imageNotFoundAfterDlopen(path: "", dlerror: nil)
+ }
+ guard let address = dlsym(handle, symbol) else {
+ throw FixtureLoadError.imageNotFoundAfterDlopen(
+ path: symbol,
+ dlerror: dlerror().map { String(cString: $0) }
+ )
+ }
+ return UnsafeRawPointer(address)
+ }
+
+ /// Idempotently dlopens `SymbolTestsCore.framework` so that subsequent
+ /// `dlsym(RTLD_NOW, ...)` calls can locate fixture-binary symbols.
+ /// Resolves the framework path relative to this source file, mirroring
+ /// `MachOSwiftSectionFixtureTests.dlopenOnce` so the test process and
+ /// the standalone `baseline-generator` process behave identically.
+ private static func ensureFixtureLoaded() throws {
+ _ = dlopenOnce
+ }
+
+ private static let dlopenOnce: Void = {
+ let absolute = resolveFixturePath(MachOImageName.SymbolTestsCore.rawValue)
+ _ = absolute.withCString { dlopen($0, RTLD_LAZY) }
+ }()
+
+ /// Resolve a relative `MachOImageName` path (rooted at the package-relative
+ /// `../../Tests/...` convention used by `loadFromFile`) to an absolute path.
+ ///
+ /// Caveat: `MachOImageName.SymbolTestsCore.rawValue` is rooted as if the
+ /// caller lives in `Sources//Foo.swift`, i.e. exactly two
+ /// `../` hops to reach the package root. This file lives one level deeper
+ /// in `Sources/MachOFixtureSupport/InProcess/`, so we anchor against
+ /// `Sources/MachOFixtureSupport/` (one path component up from `#filePath`'s
+ /// parent) to make the existing `../../...` rawValue resolve correctly.
+ private static func resolveFixturePath(_ relativePath: String) -> String {
+ if relativePath.hasPrefix("/") { return relativePath }
+ let parentOfThisFile = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
+ let oneLevelUp = parentOfThisFile.deletingLastPathComponent()
+ let url = URL(fileURLWithPath: relativePath, relativeTo: oneLevelUp)
+ return url.standardizedFileURL.path
+ }
+}
diff --git a/Sources/MachOTestingSupport/MachOFileName.swift b/Sources/MachOFixtureSupport/MachOFileName.swift
similarity index 100%
rename from Sources/MachOTestingSupport/MachOFileName.swift
rename to Sources/MachOFixtureSupport/MachOFileName.swift
diff --git a/Sources/MachOTestingSupport/MachOImageName.swift b/Sources/MachOFixtureSupport/MachOImageName.swift
similarity index 60%
rename from Sources/MachOTestingSupport/MachOImageName.swift
rename to Sources/MachOFixtureSupport/MachOImageName.swift
index 450e3f7f..80e31f74 100644
--- a/Sources/MachOTestingSupport/MachOImageName.swift
+++ b/Sources/MachOFixtureSupport/MachOImageName.swift
@@ -18,6 +18,9 @@ package enum MachOImageName: String {
case DesignLibrary
case SFSymbols
+ case SymbolTests = "../../Tests/Projects/SymbolTests/DerivedData/SymbolTests/Build/Products/Release/SymbolTests.framework/Versions/A/SymbolTests"
+ case SymbolTestsCore = "../../Tests/Projects/SymbolTests/DerivedData/SymbolTests/Build/Products/Release/SymbolTestsCore.framework/Versions/A/SymbolTestsCore"
+
var path: String {
"/\(rawValue)"
}
diff --git a/Sources/MachOTestingSupport/SnapshotDumpableTests.swift b/Sources/MachOFixtureSupport/SnapshotDumpableTests.swift
similarity index 100%
rename from Sources/MachOTestingSupport/SnapshotDumpableTests.swift
rename to Sources/MachOFixtureSupport/SnapshotDumpableTests.swift
diff --git a/Sources/MachOTestingSupport/SnapshotInterfaceTests.swift b/Sources/MachOFixtureSupport/SnapshotInterfaceTests.swift
similarity index 100%
rename from Sources/MachOTestingSupport/SnapshotInterfaceTests.swift
rename to Sources/MachOFixtureSupport/SnapshotInterfaceTests.swift
diff --git a/Sources/MachOTestingSupport/SwiftStdlibDemangle.swift b/Sources/MachOFixtureSupport/SwiftStdlibDemangle.swift
similarity index 100%
rename from Sources/MachOTestingSupport/SwiftStdlibDemangle.swift
rename to Sources/MachOFixtureSupport/SwiftStdlibDemangle.swift
diff --git a/Sources/MachOTestingSupport/URL+.swift b/Sources/MachOFixtureSupport/URL+.swift
similarity index 100%
rename from Sources/MachOTestingSupport/URL+.swift
rename to Sources/MachOFixtureSupport/URL+.swift
diff --git a/Sources/MachOTestingSupport/XcodeMachOFileName.swift b/Sources/MachOFixtureSupport/XcodeMachOFileName.swift
similarity index 100%
rename from Sources/MachOTestingSupport/XcodeMachOFileName.swift
rename to Sources/MachOFixtureSupport/XcodeMachOFileName.swift
diff --git a/Sources/MachOSwiftSection/Protocols/SwiftSectionRepresentable.swift b/Sources/MachOSwiftSection/Protocols/SwiftSectionRepresentable.swift
index ce01475e..a74943b7 100644
--- a/Sources/MachOSwiftSection/Protocols/SwiftSectionRepresentable.swift
+++ b/Sources/MachOSwiftSection/Protocols/SwiftSectionRepresentable.swift
@@ -5,6 +5,7 @@ public protocol SwiftSectionRepresentable {
var associatedTypes: [AssociatedType] { get throws }
var builtinTypes: [BuiltinType] { get throws }
+ var contextDescriptors: [ContextDescriptorWrapper] { get throws }
var typeContextDescriptors: [TypeContextDescriptorWrapper] { get throws }
var protocolDescriptors: [ProtocolDescriptor] { get throws }
var protocolConformanceDescriptors: [ProtocolConformanceDescriptor] { get throws }
diff --git a/Sources/MachOTestingSupport/DyldCacheTests.swift b/Sources/MachOTestingSupport/DyldCacheTests.swift
index bd7daa71..566acc45 100644
--- a/Sources/MachOTestingSupport/DyldCacheTests.swift
+++ b/Sources/MachOTestingSupport/DyldCacheTests.swift
@@ -2,6 +2,7 @@ import Foundation
import Testing
import MachOKit
import MachOFoundation
+import MachOFixtureSupport
@MainActor
package class DyldCacheTests: Sendable {
diff --git a/Sources/MachOTestingSupport/MachOFileTests.swift b/Sources/MachOTestingSupport/MachOFileTests.swift
index 711157ec..e5c4ce4d 100644
--- a/Sources/MachOTestingSupport/MachOFileTests.swift
+++ b/Sources/MachOTestingSupport/MachOFileTests.swift
@@ -2,6 +2,7 @@ import Foundation
import Testing
import MachOKit
import MachOFoundation
+import MachOFixtureSupport
@MainActor
package class MachOFileTests: Sendable {
diff --git a/Sources/MachOTestingSupport/MachOImageTests.swift b/Sources/MachOTestingSupport/MachOImageTests.swift
index 3e8bd13e..83ca25f2 100644
--- a/Sources/MachOTestingSupport/MachOImageTests.swift
+++ b/Sources/MachOTestingSupport/MachOImageTests.swift
@@ -2,6 +2,7 @@ import Foundation
import Testing
import MachOKit
import MachOFoundation
+import MachOFixtureSupport
@MainActor
package class MachOImageTests: Sendable {
diff --git a/Sources/MachOTestingSupport/MachOSwiftSectionFixtureTests.swift b/Sources/MachOTestingSupport/MachOSwiftSectionFixtureTests.swift
new file mode 100644
index 00000000..da69a78e
--- /dev/null
+++ b/Sources/MachOTestingSupport/MachOSwiftSectionFixtureTests.swift
@@ -0,0 +1,153 @@
+import Foundation
+import Testing
+import MachOKit
+import MachOFoundation
+import MachOReading
+import MachOResolving
+import MachOFixtureSupport
+
+@MainActor
+package class MachOSwiftSectionFixtureTests: Sendable {
+ package let machOFile: MachOFile
+ package let machOImage: MachOImage
+
+ package let fileContext: MachOContext
+ package let imageContext: MachOContext
+ package let inProcessContext: InProcessContext
+
+ package class var fixtureFileName: MachOFileName { .SymbolTestsCore }
+ package class var fixtureImageName: MachOImageName { .SymbolTestsCore }
+ package class var preferredArchitecture: CPUType { .arm64 }
+
+ package init() async throws {
+ // 1) Load MachO from disk.
+ let file: File
+ do {
+ file = try loadFromFile(named: Self.fixtureFileName)
+ } catch {
+ // If the file doesn't exist on disk, surface a fixture-specific
+ // error with rebuild instructions. Otherwise propagate the original
+ // error so unrelated load failures aren't masked.
+ let resolvedPath = Self.resolveFixturePath(Self.fixtureFileName.rawValue)
+ if !FileManager.default.fileExists(atPath: resolvedPath) {
+ throw FixtureLoadError.fixtureFileMissing(path: resolvedPath)
+ }
+ throw error
+ }
+ switch file {
+ case .fat(let fatFile):
+ self.machOFile = try required(
+ fatFile.machOFiles().first(where: { $0.header.cpuType == Self.preferredArchitecture })
+ ?? fatFile.machOFiles().first
+ )
+ case .machO(let machO):
+ self.machOFile = machO
+ @unknown default:
+ fatalError()
+ }
+
+ // 2) Ensure fixture is dlopen'd into the test process so MachOImage(name:) succeeds.
+ // `MachOImage(name:)` matches by the bare module name (last path component
+ // with extension stripped), not by the full path. Derive that from the
+ // fixtureImageName rawValue, which is a relative filesystem path.
+ try Self.ensureFixtureLoaded()
+ let imageLookupName = Self.imageLookupName(from: Self.fixtureImageName.rawValue)
+ guard let image = MachOImage(name: imageLookupName) else {
+ throw FixtureLoadError.imageNotFoundAfterDlopen(
+ path: Self.fixtureImageName.rawValue,
+ dlerror: Self.lastDlerror()
+ )
+ }
+ self.machOImage = image
+
+ // 3) Three ReadingContext instances over the same fixture.
+ self.fileContext = MachOContext(machOFile)
+ self.imageContext = MachOContext(machOImage)
+ self.inProcessContext = InProcessContext()
+ }
+
+ private static let dlopenOnce: Void = {
+ let absolute = resolveFixturePath(MachOImageName.SymbolTestsCore.rawValue)
+ _ = absolute.withCString { dlopen($0, RTLD_LAZY) }
+ }()
+
+ private static func ensureFixtureLoaded() throws {
+ _ = dlopenOnce
+ }
+
+ /// Resolve a relative MachOImageName path (rooted at the package-relative `../../Tests/...`
+ /// convention) to an absolute filesystem path. Uses the same anchor strategy as
+ /// `loadFromFile` for parity: relative paths resolve against the directory containing
+ /// this source file (i.e. `Sources/MachOTestingSupport/`).
+ private static func resolveFixturePath(_ relativePath: String) -> String {
+ if relativePath.hasPrefix("/") { return relativePath }
+ let url = URL(fileURLWithPath: relativePath, relativeTo: URL(fileURLWithPath: #filePath))
+ return url.standardizedFileURL.path
+ }
+
+ private static func lastDlerror() -> String? {
+ guard let cString = dlerror() else { return nil }
+ return String(cString: cString)
+ }
+
+ /// Derive the bare module name `MachOImage(name:)` expects (last path component
+ /// with extension stripped) from a path-form `MachOImageName.rawValue`.
+ private static func imageLookupName(from rawValue: String) -> String {
+ let lastComponent = rawValue.components(separatedBy: "/").last ?? rawValue
+ return lastComponent.components(separatedBy: ".").first ?? lastComponent
+ }
+}
+
+extension MachOSwiftSectionFixtureTests {
+ /// Run `body` against each (label, reader) pair, asserting all results equal the first.
+ /// Returns the unique value. Fails fast with the label of the first mismatching reader.
+ package func acrossAllReaders(
+ file fileWork: () throws -> T,
+ image imageWork: () throws -> T,
+ inProcess inProcessWork: (() throws -> T)? = nil,
+ sourceLocation: SourceLocation = #_sourceLocation
+ ) throws -> T {
+ let fromFile = try fileWork()
+ let fromImage = try imageWork()
+ #expect(fromFile == fromImage, "MachOFile vs MachOImage diverged", sourceLocation: sourceLocation)
+ if let inProcessWork {
+ let fromInProcess = try inProcessWork()
+ #expect(fromFile == fromInProcess, "MachOFile vs InProcess diverged", sourceLocation: sourceLocation)
+ }
+ return fromFile
+ }
+
+ /// Run `body` against each ReadingContext (file/image/inProcess), asserting all equal.
+ package func acrossAllContexts(
+ file fileWork: () throws -> T,
+ image imageWork: () throws -> T,
+ inProcess inProcessWork: (() throws -> T)? = nil,
+ sourceLocation: SourceLocation = #_sourceLocation
+ ) throws -> T {
+ let fromFileCtx = try fileWork()
+ let fromImageCtx = try imageWork()
+ #expect(fromFileCtx == fromImageCtx, "fileContext vs imageContext diverged", sourceLocation: sourceLocation)
+ if let inProcessWork {
+ let fromInProcessCtx = try inProcessWork()
+ #expect(fromFileCtx == fromInProcessCtx, "fileContext vs inProcessContext diverged", sourceLocation: sourceLocation)
+ }
+ return fromFileCtx
+ }
+}
+
+extension MachOSwiftSectionFixtureTests {
+ /// Run `body` against the in-process reader only. Used by Suites covering
+ /// runtime-only metadata types (MetatypeMetadata, TupleTypeMetadata,
+ /// FunctionTypeMetadata, etc.) — types that the Swift runtime allocates
+ /// at type-load time and that have no Mach-O section to read from.
+ ///
+ /// Cross-reader equality is not asserted because `MachOFile` and
+ /// `MachOImage` cannot reach this metadata. Single-reader assertion +
+ /// baseline literal pinning is the deepest coverage achievable.
+ package func usingInProcessOnly(
+ _ work: (InProcessContext) throws -> T,
+ sourceLocation: SourceLocation = #_sourceLocation
+ ) throws -> T {
+ try work(inProcessContext)
+ }
+}
diff --git a/Sources/MachOTestingSupport/XcodeMachOFileTests.swift b/Sources/MachOTestingSupport/XcodeMachOFileTests.swift
index 53825862..3d889a28 100644
--- a/Sources/MachOTestingSupport/XcodeMachOFileTests.swift
+++ b/Sources/MachOTestingSupport/XcodeMachOFileTests.swift
@@ -2,6 +2,7 @@ import Foundation
import Testing
import MachOKit
import MachOFoundation
+import MachOFixtureSupport
package class XcodeMachOFileTests {
package let machOFile: MachOFile
diff --git a/Sources/baseline-generator/BaselineGeneratorMain.swift b/Sources/baseline-generator/BaselineGeneratorMain.swift
new file mode 100644
index 00000000..a4ef134a
--- /dev/null
+++ b/Sources/baseline-generator/BaselineGeneratorMain.swift
@@ -0,0 +1,33 @@
+import Foundation
+import ArgumentParser
+import MachOFixtureSupport
+
+@main
+@available(macOS 12, macCatalyst 15, iOS 15, tvOS 15, watchOS 8, *)
+struct BaselineGeneratorMain: AsyncParsableCommand {
+ static let configuration = CommandConfiguration(
+ commandName: "baseline-generator",
+ abstract: "Regenerates ABI baselines for MachOSwiftSection fixture tests."
+ )
+
+ @Option(
+ name: .long,
+ help: "Output directory for baseline files. Defaults to Tests/MachOSwiftSectionTests/Fixtures/__Baseline__."
+ )
+ var output: String = "Tests/MachOSwiftSectionTests/Fixtures/__Baseline__"
+
+ @Option(
+ name: .long,
+ help: "Restrict regeneration to a specific Suite, e.g. StructDescriptor. If omitted, regenerates all baselines."
+ )
+ var suite: String?
+
+ func run() async throws {
+ let outputURL = URL(fileURLWithPath: output)
+ if let suite {
+ try await BaselineGenerator.generate(suite: suite, outputDirectory: outputURL)
+ } else {
+ try await BaselineGenerator.generateAll(outputDirectory: outputURL)
+ }
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/AssociatedTypeTests.swift b/Tests/IntegrationTests/DyldCacheAssociatedTypeTests.swift
similarity index 92%
rename from Tests/MachOSwiftSectionTests/AssociatedTypeTests.swift
rename to Tests/IntegrationTests/DyldCacheAssociatedTypeTests.swift
index 2c6d5208..58386d99 100644
--- a/Tests/MachOSwiftSectionTests/AssociatedTypeTests.swift
+++ b/Tests/IntegrationTests/DyldCacheAssociatedTypeTests.swift
@@ -3,10 +3,11 @@ import Testing
import Demangling
@testable import SwiftDump
@testable import MachOTestingSupport
+import MachOFixtureSupport
@_spi(Internals) @testable import MachOSymbols
@testable @_spi(Internals) import SwiftInspection
-final class AssociatedTypeTests: DyldCacheTests, @unchecked Sendable {
+final class DyldCacheAssociatedTypeTests: DyldCacheTests, @unchecked Sendable {
@MainActor
@Test
func associatedTypes() throws {
diff --git a/Tests/MachOSwiftSectionTests/LayoutTests.swift b/Tests/IntegrationTests/LayoutTests.swift
similarity index 100%
rename from Tests/MachOSwiftSectionTests/LayoutTests.swift
rename to Tests/IntegrationTests/LayoutTests.swift
diff --git a/Tests/MachOSwiftSectionTests/MetadataAccessorTests.swift b/Tests/IntegrationTests/MetadataAccessorTests.swift
similarity index 99%
rename from Tests/MachOSwiftSectionTests/MetadataAccessorTests.swift
rename to Tests/IntegrationTests/MetadataAccessorTests.swift
index fc490632..df517adf 100644
--- a/Tests/MachOSwiftSectionTests/MetadataAccessorTests.swift
+++ b/Tests/IntegrationTests/MetadataAccessorTests.swift
@@ -4,6 +4,7 @@ import Testing
import Demangling
import MachOKit
@testable import MachOTestingSupport
+import MachOFixtureSupport
@testable import MachOSwiftSection
@testable import SwiftDump
diff --git a/Tests/MachOSwiftSectionTests/OpaqueTypeTests.swift b/Tests/IntegrationTests/OpaqueTypeTests.swift
similarity index 99%
rename from Tests/MachOSwiftSectionTests/OpaqueTypeTests.swift
rename to Tests/IntegrationTests/OpaqueTypeTests.swift
index f6ae3eea..78843469 100644
--- a/Tests/MachOSwiftSectionTests/OpaqueTypeTests.swift
+++ b/Tests/IntegrationTests/OpaqueTypeTests.swift
@@ -2,6 +2,7 @@ import Foundation
import Testing
import Demangling
@testable import MachOTestingSupport
+import MachOFixtureSupport
import MachOSwiftSection
@testable import SwiftDump
@_spi(Internals) import MachOSymbols
diff --git a/Tests/MachOSwiftSectionTests/PrimitiveTypeMappingTests.swift b/Tests/IntegrationTests/PrimitiveTypeMappingTests.swift
similarity index 95%
rename from Tests/MachOSwiftSectionTests/PrimitiveTypeMappingTests.swift
rename to Tests/IntegrationTests/PrimitiveTypeMappingTests.swift
index 0ccb53ff..1f10edbe 100644
--- a/Tests/MachOSwiftSectionTests/PrimitiveTypeMappingTests.swift
+++ b/Tests/IntegrationTests/PrimitiveTypeMappingTests.swift
@@ -4,6 +4,7 @@ import MachOKit
import Demangling
import MachOFoundation
@testable import MachOTestingSupport
+import MachOFixtureSupport
@testable import MachOSwiftSection
@testable import SwiftDump
@testable @_spi(Internals) import SwiftInspection
diff --git a/Tests/MachOSwiftSectionTests/ProtocolGenericContextTests.swift b/Tests/IntegrationTests/ProtocolGenericContextTests.swift
similarity index 96%
rename from Tests/MachOSwiftSectionTests/ProtocolGenericContextTests.swift
rename to Tests/IntegrationTests/ProtocolGenericContextTests.swift
index ab1ba120..4db8c3a2 100644
--- a/Tests/MachOSwiftSectionTests/ProtocolGenericContextTests.swift
+++ b/Tests/IntegrationTests/ProtocolGenericContextTests.swift
@@ -2,6 +2,7 @@ import Foundation
import Testing
@testable import MachOSwiftSection
@testable import MachOTestingSupport
+import MachOFixtureSupport
final class ProtocolGenericContextTests: MachOFileTests, @unchecked Sendable {
override class var fileName: MachOFileName { .SymbolTestsCore }
diff --git a/Tests/MachOSwiftSectionTests/ProtocolRequirementSignatureTests.swift b/Tests/IntegrationTests/ProtocolRequirementSignatureTests.swift
similarity index 96%
rename from Tests/MachOSwiftSectionTests/ProtocolRequirementSignatureTests.swift
rename to Tests/IntegrationTests/ProtocolRequirementSignatureTests.swift
index ef1edcbc..7d04d4d4 100644
--- a/Tests/MachOSwiftSectionTests/ProtocolRequirementSignatureTests.swift
+++ b/Tests/IntegrationTests/ProtocolRequirementSignatureTests.swift
@@ -3,6 +3,7 @@ import Testing
@testable import MachOSwiftSection
@testable import SwiftDump
@testable import MachOTestingSupport
+import MachOFixtureSupport
final class ProtocolRequirementSignatureTests: MachOFileTests, @unchecked Sendable {
override class var fileName: MachOFileName { .SymbolTestsCore }
diff --git a/Tests/MachOSwiftSectionTests/SymbolIndexStoreTests.swift b/Tests/IntegrationTests/SymbolIndexStoreTests.swift
similarity index 99%
rename from Tests/MachOSwiftSectionTests/SymbolIndexStoreTests.swift
rename to Tests/IntegrationTests/SymbolIndexStoreTests.swift
index 633d0579..43125cec 100644
--- a/Tests/MachOSwiftSectionTests/SymbolIndexStoreTests.swift
+++ b/Tests/IntegrationTests/SymbolIndexStoreTests.swift
@@ -3,6 +3,7 @@ import Testing
import Dependencies
@testable import MachOSwiftSection
@testable import MachOTestingSupport
+import MachOFixtureSupport
@_spi(Internals) @testable import MachOSymbols
@_spi(Internals) @testable import MachOCaches
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextDescriptorFlagsTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextDescriptorFlagsTests.swift
new file mode 100644
index 00000000..75217ca6
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextDescriptorFlagsTests.swift
@@ -0,0 +1,60 @@
+import Foundation
+import Testing
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `AnonymousContextDescriptorFlags`.
+///
+/// The flags type is a small `FlagSet` value-type whose instances are
+/// stored inside a descriptor's `layout.flags.kindSpecificFlags`. We
+/// extract the live instance from the fixture's first anonymous
+/// descriptor and assert the `rawValue` and the derived `hasMangledName`
+/// match the baseline; we also verify the `init(rawValue:)` round-trip.
+@Suite
+final class AnonymousContextDescriptorFlagsTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "AnonymousContextDescriptorFlags"
+ static var registeredTestMethodNames: Set {
+ AnonymousContextDescriptorFlagsBaseline.registeredTestMethodNames
+ }
+
+ /// Helper: extract the `AnonymousContextDescriptorFlags` from the
+ /// fixture's first anonymous descriptor against both readers.
+ private func loadFirstFlags() throws -> (file: AnonymousContextDescriptorFlags, image: AnonymousContextDescriptorFlags) {
+ let fileDescriptor = try BaselineFixturePicker.anonymous_first(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.anonymous_first(in: machOImage)
+ let fileFlags = try required(fileDescriptor.layout.flags.kindSpecificFlags?.anonymousFlags)
+ let imageFlags = try required(imageDescriptor.layout.flags.kindSpecificFlags?.anonymousFlags)
+ return (file: fileFlags, image: imageFlags)
+ }
+
+ @Test func rawValue() async throws {
+ let flags = try loadFirstFlags()
+ let result = try acrossAllReaders(
+ file: { flags.file.rawValue },
+ image: { flags.image.rawValue }
+ )
+ #expect(result == AnonymousContextDescriptorFlagsBaseline.firstAnonymous.rawValue)
+ }
+
+ @Test("init(rawValue:)") func initializerWithRawValue() async throws {
+ // Round-trip construction: `init(rawValue:)` must reproduce the
+ // baseline's stored rawValue verbatim, and the derived
+ // `hasMangledName` must match the live extraction.
+ let constructed = AnonymousContextDescriptorFlags(
+ rawValue: AnonymousContextDescriptorFlagsBaseline.firstAnonymous.rawValue
+ )
+ #expect(constructed.rawValue == AnonymousContextDescriptorFlagsBaseline.firstAnonymous.rawValue)
+ #expect(constructed.hasMangledName == AnonymousContextDescriptorFlagsBaseline.firstAnonymous.hasMangledName)
+ }
+
+ @Test func hasMangledName() async throws {
+ let flags = try loadFirstFlags()
+ let result = try acrossAllReaders(
+ file: { flags.file.hasMangledName },
+ image: { flags.image.hasMangledName }
+ )
+ #expect(result == AnonymousContextDescriptorFlagsBaseline.firstAnonymous.hasMangledName)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextDescriptorProtocolTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextDescriptorProtocolTests.swift
new file mode 100644
index 00000000..a600754c
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextDescriptorProtocolTests.swift
@@ -0,0 +1,53 @@
+import Foundation
+import Testing
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `AnonymousContextDescriptorProtocol`.
+///
+/// The protocol provides the `mangledName(in:)` family of overloads (MachO,
+/// InProcess, ReadingContext) plus the `hasMangledName` derived var.
+/// The MangledName payload is a deep ABI tree we don't embed as a literal;
+/// instead we verify cross-reader-consistent results at runtime.
+@Suite
+final class AnonymousContextDescriptorProtocolTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "AnonymousContextDescriptorProtocol"
+ static var registeredTestMethodNames: Set {
+ AnonymousContextDescriptorProtocolBaseline.registeredTestMethodNames
+ }
+
+ @Test func hasMangledName() async throws {
+ let fileDescriptor = try BaselineFixturePicker.anonymous_first(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.anonymous_first(in: machOImage)
+
+ // `hasMangledName` is a pure-derivation getter on the protocol;
+ // every reader must agree.
+ let result = try acrossAllReaders(
+ file: { fileDescriptor.hasMangledName },
+ image: { imageDescriptor.hasMangledName }
+ )
+ // The presence flag's value is recorded against the same picker
+ // (`anonymous_first`) on this Suite's own baseline.
+ #expect(result == AnonymousContextDescriptorProtocolBaseline.firstAnonymous.hasMangledName)
+ }
+
+ @Test func mangledName() async throws {
+ let fileDescriptor = try BaselineFixturePicker.anonymous_first(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.anonymous_first(in: machOImage)
+
+ // Cross-reader equality on the *presence* of the mangled name.
+ // (The actual MangledName tree should also be Equatable, since
+ // MangledName: Hashable, but we use presence-only here for parity
+ // with the wrapper Suite and because the picker's first anonymous
+ // context happens to have no mangled name in this fixture.)
+ let filePresence = (try fileDescriptor.mangledName(in: machOFile)) != nil
+ let imagePresence = (try imageDescriptor.mangledName(in: machOImage)) != nil
+ let imageCtxPresence = (try imageDescriptor.mangledName(in: imageContext)) != nil
+
+ #expect(filePresence == imagePresence)
+ #expect(filePresence == imageCtxPresence)
+ #expect(filePresence == AnonymousContextDescriptorProtocolBaseline.firstAnonymous.hasMangledName)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextDescriptorTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextDescriptorTests.swift
new file mode 100644
index 00000000..4efa52b6
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextDescriptorTests.swift
@@ -0,0 +1,46 @@
+import Foundation
+import Testing
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `AnonymousContextDescriptor`.
+///
+/// `AnonymousContextDescriptor` declares only `offset` and `layout`
+/// directly (the `init(layout:offset:)` is filtered as a memberwise
+/// synthesized initializer). Protocol-extension members (`mangledName(in:)`,
+/// `hasMangledName`) live on `AnonymousContextDescriptorProtocol` and are
+/// covered by `AnonymousContextDescriptorProtocolTests`.
+@Suite
+final class AnonymousContextDescriptorTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "AnonymousContextDescriptor"
+ static var registeredTestMethodNames: Set {
+ AnonymousContextDescriptorBaseline.registeredTestMethodNames
+ }
+
+ @Test func offset() async throws {
+ let fileSubject = try BaselineFixturePicker.anonymous_first(in: machOFile)
+ let imageSubject = try BaselineFixturePicker.anonymous_first(in: machOImage)
+
+ let result = try acrossAllReaders(
+ file: { fileSubject.offset },
+ image: { imageSubject.offset }
+ )
+ #expect(result == AnonymousContextDescriptorBaseline.firstAnonymous.offset)
+ }
+
+ @Test func layout() async throws {
+ let fileSubject = try BaselineFixturePicker.anonymous_first(in: machOFile)
+ let imageSubject = try BaselineFixturePicker.anonymous_first(in: machOImage)
+
+ // Cross-reader equality on the only stable scalar field
+ // (`flags.rawValue`); `parent` is a relative pointer whose value
+ // varies by reader.
+ let flagsRaw = try acrossAllReaders(
+ file: { fileSubject.layout.flags.rawValue },
+ image: { imageSubject.layout.flags.rawValue }
+ )
+ #expect(flagsRaw == AnonymousContextDescriptorBaseline.firstAnonymous.layoutFlagsRawValue)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextTests.swift
new file mode 100644
index 00000000..36464e0d
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/Anonymous/AnonymousContextTests.swift
@@ -0,0 +1,96 @@
+import Foundation
+import Testing
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `AnonymousContext` (the high-level wrapper
+/// around `AnonymousContextDescriptor`).
+///
+/// Anonymous contexts in `SymbolTestsCore` arise from generic parameter
+/// scopes and other unnamed contexts; they're discovered via the parent
+/// chain of generic types, not via top-level `__swift5_types` records.
+///
+/// `init(descriptor:in:)` (MachO + ReadingContext overloads) and
+/// `init(descriptor:)` (in-process) are covered by dedicated tests; the
+/// other ivars use the established presence-flag pattern (`MangledName`
+/// and `GenericContext` aren't cheaply Equatable).
+@Suite
+final class AnonymousContextTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "AnonymousContext"
+ static var registeredTestMethodNames: Set {
+ AnonymousContextBaseline.registeredTestMethodNames
+ }
+
+ /// Helper: instantiate the `AnonymousContext` wrapper using the
+ /// MachO-direct initializer for both readers.
+ private func loadFirstAnonymousContexts() throws -> (file: AnonymousContext, image: AnonymousContext) {
+ let fileDescriptor = try BaselineFixturePicker.anonymous_first(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.anonymous_first(in: machOImage)
+ let file = try AnonymousContext(descriptor: fileDescriptor, in: machOFile)
+ let image = try AnonymousContext(descriptor: imageDescriptor, in: machOImage)
+ return (file: file, image: image)
+ }
+
+ // MARK: - Initializers
+
+ @Test("init(descriptor:in:)") func initializerWithMachO() async throws {
+ let fileDescriptor = try BaselineFixturePicker.anonymous_first(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.anonymous_first(in: machOImage)
+
+ // Both file/image MachO-based initializers must succeed and produce
+ // a descriptor whose offset matches the baseline. The
+ // ReadingContext-based overload also exists.
+ let fileContext_ = try AnonymousContext(descriptor: fileDescriptor, in: machOFile)
+ let imageContext_ = try AnonymousContext(descriptor: imageDescriptor, in: machOImage)
+ let fileCtxContext = try AnonymousContext(descriptor: fileDescriptor, in: fileContext)
+ let imageCtxContext = try AnonymousContext(descriptor: imageDescriptor, in: imageContext)
+
+ #expect(fileContext_.descriptor.offset == AnonymousContextBaseline.firstAnonymous.descriptorOffset)
+ #expect(imageContext_.descriptor.offset == AnonymousContextBaseline.firstAnonymous.descriptorOffset)
+ #expect(fileCtxContext.descriptor.offset == AnonymousContextBaseline.firstAnonymous.descriptorOffset)
+ #expect(imageCtxContext.descriptor.offset == AnonymousContextBaseline.firstAnonymous.descriptorOffset)
+ }
+
+ @Test("init(descriptor:)") func initializerInProcess() async throws {
+ // The InProcess `init(descriptor:)` requires a pointer-form
+ // descriptor resolved against MachOImage; reproduce that here.
+ let imageDescriptor = try BaselineFixturePicker.anonymous_first(in: machOImage)
+ let pointerDescriptor = imageDescriptor.asPointerWrapper(in: machOImage)
+ let inProcessContext_ = try AnonymousContext(descriptor: pointerDescriptor)
+
+ // The in-process `descriptor.offset` is a pointer bit pattern, not
+ // a file offset — we just assert it resolved.
+ #expect(inProcessContext_.descriptor.offset != 0)
+ }
+
+ // MARK: - Ivars
+
+ @Test func descriptor() async throws {
+ let contexts = try loadFirstAnonymousContexts()
+ let descriptorOffsets = try acrossAllReaders(
+ file: { contexts.file.descriptor.offset },
+ image: { contexts.image.descriptor.offset }
+ )
+ #expect(descriptorOffsets == AnonymousContextBaseline.firstAnonymous.descriptorOffset)
+ }
+
+ @Test func genericContext() async throws {
+ let contexts = try loadFirstAnonymousContexts()
+ let presence = try acrossAllReaders(
+ file: { contexts.file.genericContext != nil },
+ image: { contexts.image.genericContext != nil }
+ )
+ #expect(presence == AnonymousContextBaseline.firstAnonymous.hasGenericContext)
+ }
+
+ @Test func mangledName() async throws {
+ let contexts = try loadFirstAnonymousContexts()
+ let presence = try acrossAllReaders(
+ file: { contexts.file.mangledName != nil },
+ image: { contexts.image.mangledName != nil }
+ )
+ #expect(presence == AnonymousContextBaseline.firstAnonymous.hasMangledName)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/AssociatedType/AssociatedTypeDescriptorTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/AssociatedType/AssociatedTypeDescriptorTests.swift
new file mode 100644
index 00000000..47ef7497
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/AssociatedType/AssociatedTypeDescriptorTests.swift
@@ -0,0 +1,113 @@
+import Foundation
+import Testing
+import MachOKit
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `AssociatedTypeDescriptor`.
+///
+/// Each `@Test` exercises one ivar / derived var / reader method declared
+/// in `AssociatedTypeDescriptor.swift`. The cross-reader assertions use
+/// counts/presence flags rather than full structural equality —
+/// `MangledName` payloads parse to deep ABI trees that we don't deep-compare;
+/// presence + cardinality is the meaningful invariant.
+///
+/// Picker: `AssociatedTypeWitnessPatterns.ConcreteWitnessTest` conforming
+/// to `AssociatedTypeWitnessPatterns.AssociatedPatternProtocol` (5 concrete
+/// witnesses).
+@Suite
+final class AssociatedTypeDescriptorTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "AssociatedTypeDescriptor"
+ static var registeredTestMethodNames: Set {
+ AssociatedTypeDescriptorBaseline.registeredTestMethodNames
+ }
+
+ // MARK: - Helpers
+
+ private func loadDescriptors() throws -> (file: AssociatedTypeDescriptor, image: AssociatedTypeDescriptor) {
+ let file = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machOFile)
+ let image = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machOImage)
+ return (file: file, image: image)
+ }
+
+ // MARK: - Ivars
+
+ @Test func offset() async throws {
+ let descriptors = try loadDescriptors()
+ let result = try acrossAllReaders(
+ file: { descriptors.file.offset },
+ image: { descriptors.image.offset }
+ )
+ #expect(result == AssociatedTypeDescriptorBaseline.concreteWitnessTest.offset)
+ }
+
+ @Test func layout() async throws {
+ // Cross-reader equality on the per-descriptor layout values.
+ let descriptors = try loadDescriptors()
+ let numAssociatedTypes = try acrossAllReaders(
+ file: { descriptors.file.layout.numAssociatedTypes },
+ image: { descriptors.image.layout.numAssociatedTypes }
+ )
+ #expect(numAssociatedTypes == AssociatedTypeDescriptorBaseline.concreteWitnessTest.layoutNumAssociatedTypes)
+
+ let recordSize = try acrossAllReaders(
+ file: { descriptors.file.layout.associatedTypeRecordSize },
+ image: { descriptors.image.layout.associatedTypeRecordSize }
+ )
+ #expect(recordSize == AssociatedTypeDescriptorBaseline.concreteWitnessTest.layoutAssociatedTypeRecordSize)
+ }
+
+ // MARK: - TopLevelDescriptor conformance
+
+ @Test func actualSize() async throws {
+ let descriptors = try loadDescriptors()
+ let result = try acrossAllReaders(
+ file: { descriptors.file.actualSize },
+ image: { descriptors.image.actualSize }
+ )
+ #expect(result == AssociatedTypeDescriptorBaseline.concreteWitnessTest.actualSize)
+ }
+
+ // MARK: - Reader methods
+
+ @Test func conformingTypeName() async throws {
+ let descriptors = try loadDescriptors()
+ let presence = try acrossAllReaders(
+ file: { (try? descriptors.file.conformingTypeName(in: machOFile)) != nil },
+ image: { (try? descriptors.image.conformingTypeName(in: machOImage)) != nil }
+ )
+ #expect(presence == AssociatedTypeDescriptorBaseline.concreteWitnessTest.hasConformingTypeName)
+
+ // ReadingContext-based overload also exercised.
+ let imageCtxPresence = (try? descriptors.image.conformingTypeName(in: imageContext)) != nil
+ #expect(imageCtxPresence == AssociatedTypeDescriptorBaseline.concreteWitnessTest.hasConformingTypeName)
+ }
+
+ @Test func protocolTypeName() async throws {
+ let descriptors = try loadDescriptors()
+ let presence = try acrossAllReaders(
+ file: { (try? descriptors.file.protocolTypeName(in: machOFile)) != nil },
+ image: { (try? descriptors.image.protocolTypeName(in: machOImage)) != nil }
+ )
+ #expect(presence == AssociatedTypeDescriptorBaseline.concreteWitnessTest.hasProtocolTypeName)
+
+ // ReadingContext-based overload also exercised.
+ let imageCtxPresence = (try? descriptors.image.protocolTypeName(in: imageContext)) != nil
+ #expect(imageCtxPresence == AssociatedTypeDescriptorBaseline.concreteWitnessTest.hasProtocolTypeName)
+ }
+
+ @Test func associatedTypeRecords() async throws {
+ let descriptors = try loadDescriptors()
+ let count = try acrossAllReaders(
+ file: { try descriptors.file.associatedTypeRecords(in: machOFile).count },
+ image: { try descriptors.image.associatedTypeRecords(in: machOImage).count }
+ )
+ #expect(count == AssociatedTypeDescriptorBaseline.concreteWitnessTest.recordsCount)
+
+ // ReadingContext-based overload also exercised.
+ let imageCtxCount = try descriptors.image.associatedTypeRecords(in: imageContext).count
+ #expect(imageCtxCount == AssociatedTypeDescriptorBaseline.concreteWitnessTest.recordsCount)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/AssociatedType/AssociatedTypeRecordTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/AssociatedType/AssociatedTypeRecordTests.swift
new file mode 100644
index 00000000..a50f4479
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/AssociatedType/AssociatedTypeRecordTests.swift
@@ -0,0 +1,90 @@
+import Foundation
+import Testing
+import MachOKit
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `AssociatedTypeRecord`.
+///
+/// Each `@Test` exercises one ivar / reader method declared in
+/// `AssociatedTypeRecord.swift`. The cross-reader assertions use the
+/// resolved name string (cheaply equatable) and a presence flag for the
+/// `MangledName` payload (a deep ABI tree we don't deep-compare).
+///
+/// Picker: the first record from
+/// `AssociatedTypeWitnessPatterns.ConcreteWitnessTest`'s
+/// `AssociatedTypeDescriptor` (witnessing `First = Int`).
+@Suite
+final class AssociatedTypeRecordTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "AssociatedTypeRecord"
+ static var registeredTestMethodNames: Set {
+ AssociatedTypeRecordBaseline.registeredTestMethodNames
+ }
+
+ // MARK: - Helpers
+
+ private func loadFirstRecord() throws -> (file: AssociatedTypeRecord, image: AssociatedTypeRecord) {
+ let fileDescriptor = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machOImage)
+ let fileRecords = try fileDescriptor.associatedTypeRecords(in: machOFile)
+ let imageRecords = try imageDescriptor.associatedTypeRecords(in: machOImage)
+ let file = try required(fileRecords.first)
+ let image = try required(imageRecords.first)
+ return (file: file, image: image)
+ }
+
+ // MARK: - Ivars
+
+ @Test func offset() async throws {
+ let records = try loadFirstRecord()
+ let result = try acrossAllReaders(
+ file: { records.file.offset },
+ image: { records.image.offset }
+ )
+ #expect(result == AssociatedTypeRecordBaseline.firstRecord.offset)
+ }
+
+ @Test func layout() async throws {
+ // The layout struct holds two RelativeDirectPointers; we exercise
+ // cross-reader equality via the resolved `name` string (asserted
+ // separately by the `name()` test). This test is the
+ // structural-presence anchor — it just verifies the layout
+ // accessor is available and consistent across readers.
+ let records = try loadFirstRecord()
+ let nameStringMatches = try acrossAllReaders(
+ file: { try records.file.name(in: machOFile) },
+ image: { try records.image.name(in: machOImage) }
+ )
+ #expect(nameStringMatches == AssociatedTypeRecordBaseline.firstRecord.name)
+ }
+
+ // MARK: - Reader methods
+
+ @Test func name() async throws {
+ let records = try loadFirstRecord()
+ let result = try acrossAllReaders(
+ file: { try records.file.name(in: machOFile) },
+ image: { try records.image.name(in: machOImage) }
+ )
+ #expect(result == AssociatedTypeRecordBaseline.firstRecord.name)
+
+ // ReadingContext-based overload also exercised.
+ let imageCtxResult = try records.image.name(in: imageContext)
+ #expect(imageCtxResult == AssociatedTypeRecordBaseline.firstRecord.name)
+ }
+
+ @Test func substitutedTypeName() async throws {
+ let records = try loadFirstRecord()
+ let presence = try acrossAllReaders(
+ file: { (try? records.file.substitutedTypeName(in: machOFile)) != nil },
+ image: { (try? records.image.substitutedTypeName(in: machOImage)) != nil }
+ )
+ #expect(presence == AssociatedTypeRecordBaseline.firstRecord.hasSubstitutedTypeName)
+
+ // ReadingContext-based overload also exercised.
+ let imageCtxPresence = (try? records.image.substitutedTypeName(in: imageContext)) != nil
+ #expect(imageCtxPresence == AssociatedTypeRecordBaseline.firstRecord.hasSubstitutedTypeName)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/AssociatedType/AssociatedTypeTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/AssociatedType/AssociatedTypeTests.swift
new file mode 100644
index 00000000..d4c36276
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/AssociatedType/AssociatedTypeTests.swift
@@ -0,0 +1,103 @@
+import Foundation
+import Testing
+import MachOKit
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `AssociatedType` (the high-level wrapper around
+/// `AssociatedTypeDescriptor`).
+///
+/// Each `@Test` exercises one ivar / initializer of `AssociatedType`. The
+/// cross-reader assertions use cardinality (`records.count`) and presence
+/// flags (`MangledName.elements.isEmpty`) — the underlying types
+/// (`MangledName`, `[AssociatedTypeRecord]`) parse to deep ABI trees we
+/// don't deep-compare; presence + cardinality is the meaningful invariant.
+///
+/// Picker: `AssociatedTypeWitnessPatterns.ConcreteWitnessTest` conforming
+/// to `AssociatedTypeWitnessPatterns.AssociatedPatternProtocol` (5 concrete
+/// witnesses).
+@Suite
+final class AssociatedTypeTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "AssociatedType"
+ static var registeredTestMethodNames: Set {
+ AssociatedTypeBaseline.registeredTestMethodNames
+ }
+
+ // MARK: - Helpers
+
+ private func loadAssociatedTypes() throws -> (file: AssociatedType, image: AssociatedType) {
+ let fileDescriptor = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machOImage)
+ let file = try AssociatedType(descriptor: fileDescriptor, in: machOFile)
+ let image = try AssociatedType(descriptor: imageDescriptor, in: machOImage)
+ return (file: file, image: image)
+ }
+
+ // MARK: - Initializers
+
+ @Test("init(descriptor:in:)") func initializerWithMachO() async throws {
+ let fileDescriptor = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machOImage)
+
+ let fileMachO = try AssociatedType(descriptor: fileDescriptor, in: machOFile)
+ let imageMachO = try AssociatedType(descriptor: imageDescriptor, in: machOImage)
+ let fileCtx = try AssociatedType(descriptor: fileDescriptor, in: fileContext)
+ let imageCtx = try AssociatedType(descriptor: imageDescriptor, in: imageContext)
+
+ #expect(fileMachO.descriptor.offset == AssociatedTypeBaseline.concreteWitnessTest.descriptorOffset)
+ #expect(imageMachO.descriptor.offset == AssociatedTypeBaseline.concreteWitnessTest.descriptorOffset)
+ #expect(fileCtx.descriptor.offset == AssociatedTypeBaseline.concreteWitnessTest.descriptorOffset)
+ #expect(imageCtx.descriptor.offset == AssociatedTypeBaseline.concreteWitnessTest.descriptorOffset)
+ }
+
+ @Test("init(descriptor:)") func initializerInProcess() async throws {
+ // The InProcess `init(descriptor:)` walks the descriptor via raw
+ // pointer arithmetic; we just assert it succeeds and produces a
+ // non-zero descriptor offset (the absolute pointer is per-process).
+ let imageDescriptor = try BaselineFixturePicker.associatedTypeDescriptor_ConcreteWitnessTest(in: machOImage)
+ let pointerWrapper = imageDescriptor.asPointerWrapper(in: machOImage)
+ let inProcess = try AssociatedType(descriptor: pointerWrapper)
+ #expect(inProcess.descriptor.offset != 0)
+ #expect(inProcess.records.count == AssociatedTypeBaseline.concreteWitnessTest.recordsCount)
+ }
+
+ // MARK: - Ivars
+
+ @Test func descriptor() async throws {
+ let associatedTypes = try loadAssociatedTypes()
+ let result = try acrossAllReaders(
+ file: { associatedTypes.file.descriptor.offset },
+ image: { associatedTypes.image.descriptor.offset }
+ )
+ #expect(result == AssociatedTypeBaseline.concreteWitnessTest.descriptorOffset)
+ }
+
+ @Test func conformingTypeName() async throws {
+ let associatedTypes = try loadAssociatedTypes()
+ let presence = try acrossAllReaders(
+ file: { !associatedTypes.file.conformingTypeName.elements.isEmpty },
+ image: { !associatedTypes.image.conformingTypeName.elements.isEmpty }
+ )
+ #expect(presence == AssociatedTypeBaseline.concreteWitnessTest.hasConformingTypeName)
+ }
+
+ @Test func protocolTypeName() async throws {
+ let associatedTypes = try loadAssociatedTypes()
+ let presence = try acrossAllReaders(
+ file: { !associatedTypes.file.protocolTypeName.elements.isEmpty },
+ image: { !associatedTypes.image.protocolTypeName.elements.isEmpty }
+ )
+ #expect(presence == AssociatedTypeBaseline.concreteWitnessTest.hasProtocolTypeName)
+ }
+
+ @Test func records() async throws {
+ let associatedTypes = try loadAssociatedTypes()
+ let count = try acrossAllReaders(
+ file: { associatedTypes.file.records.count },
+ image: { associatedTypes.image.records.count }
+ )
+ #expect(count == AssociatedTypeBaseline.concreteWitnessTest.recordsCount)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/BuiltinType/BuiltinTypeDescriptorTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/BuiltinType/BuiltinTypeDescriptorTests.swift
new file mode 100644
index 00000000..e8fef867
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/BuiltinType/BuiltinTypeDescriptorTests.swift
@@ -0,0 +1,109 @@
+import Foundation
+import Testing
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `BuiltinTypeDescriptor`.
+///
+/// Picker: the first descriptor in the `__swift5_builtin` section of
+/// SymbolTestsCore. The fixture's `BuiltinTypeFields` namespace causes
+/// the compiler to emit one descriptor per primitive backing type used
+/// in stored fields. The Suite asserts cross-reader equality of the
+/// layout fields and the typeName resolution.
+///
+/// `init(layout:offset:)` is filtered as memberwise-synthesized.
+@Suite
+final class BuiltinTypeDescriptorTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "BuiltinTypeDescriptor"
+ static var registeredTestMethodNames: Set {
+ BuiltinTypeDescriptorBaseline.registeredTestMethodNames
+ }
+
+ private func loadDescriptors() throws -> (file: BuiltinTypeDescriptor, image: BuiltinTypeDescriptor) {
+ let file = try BaselineFixturePicker.builtinTypeDescriptor_first(in: machOFile)
+ let image = try BaselineFixturePicker.builtinTypeDescriptor_first(in: machOImage)
+ return (file: file, image: image)
+ }
+
+ @Test func offset() async throws {
+ let descriptors = try loadDescriptors()
+ let result = try acrossAllReaders(
+ file: { descriptors.file.offset },
+ image: { descriptors.image.offset }
+ )
+ #expect(result == BuiltinTypeDescriptorBaseline.firstBuiltin.descriptorOffset)
+ }
+
+ @Test func layout() async throws {
+ let descriptors = try loadDescriptors()
+ let size = try acrossAllReaders(
+ file: { descriptors.file.layout.size },
+ image: { descriptors.image.layout.size }
+ )
+ let stride = try acrossAllReaders(
+ file: { descriptors.file.layout.stride },
+ image: { descriptors.image.layout.stride }
+ )
+ let alignmentAndFlags = try acrossAllReaders(
+ file: { descriptors.file.layout.alignmentAndFlags },
+ image: { descriptors.image.layout.alignmentAndFlags }
+ )
+ let numExtraInhabitants = try acrossAllReaders(
+ file: { descriptors.file.layout.numExtraInhabitants },
+ image: { descriptors.image.layout.numExtraInhabitants }
+ )
+
+ #expect(size == BuiltinTypeDescriptorBaseline.firstBuiltin.size)
+ #expect(stride == BuiltinTypeDescriptorBaseline.firstBuiltin.stride)
+ #expect(alignmentAndFlags == BuiltinTypeDescriptorBaseline.firstBuiltin.alignmentAndFlags)
+ #expect(numExtraInhabitants == BuiltinTypeDescriptorBaseline.firstBuiltin.numExtraInhabitants)
+ }
+
+ @Test func alignment() async throws {
+ let descriptors = try loadDescriptors()
+ let result = try acrossAllReaders(
+ file: { descriptors.file.alignment },
+ image: { descriptors.image.alignment }
+ )
+ #expect(result == BuiltinTypeDescriptorBaseline.firstBuiltin.alignment)
+ }
+
+ @Test func isBitwiseTakable() async throws {
+ let descriptors = try loadDescriptors()
+ let result = try acrossAllReaders(
+ file: { descriptors.file.isBitwiseTakable },
+ image: { descriptors.image.isBitwiseTakable }
+ )
+ #expect(result == BuiltinTypeDescriptorBaseline.firstBuiltin.isBitwiseTakable)
+ }
+
+ @Test func hasMangledName() async throws {
+ let descriptors = try loadDescriptors()
+ let result = try acrossAllReaders(
+ file: { descriptors.file.hasMangledName },
+ image: { descriptors.image.hasMangledName }
+ )
+ #expect(result == BuiltinTypeDescriptorBaseline.firstBuiltin.hasMangledName)
+ }
+
+ @Test func typeName() async throws {
+ let descriptors = try loadDescriptors()
+ // typeName resolution returns an Optional. The
+ // baseline records whether the mangled-name pointer is non-null
+ // (`hasMangledName`); the resolved name itself isn't byte-stable
+ // across builds, so we only assert non-nil presence.
+ let viaFile = try descriptors.file.typeName(in: machOFile)
+ let viaImage = try descriptors.image.typeName(in: machOImage)
+ if BuiltinTypeDescriptorBaseline.firstBuiltin.hasMangledName {
+ #expect(viaFile != nil)
+ #expect(viaImage != nil)
+ }
+ // ReadingContext path also exercised.
+ let viaContext = try descriptors.image.typeName(in: imageContext)
+ if BuiltinTypeDescriptorBaseline.firstBuiltin.hasMangledName {
+ #expect(viaContext != nil)
+ }
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/BuiltinType/BuiltinTypeTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/BuiltinType/BuiltinTypeTests.swift
new file mode 100644
index 00000000..983248d1
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/BuiltinType/BuiltinTypeTests.swift
@@ -0,0 +1,71 @@
+import Foundation
+import Testing
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `BuiltinType` (the high-level wrapper around
+/// `BuiltinTypeDescriptor`).
+///
+/// Picker: the first `BuiltinTypeDescriptor` from the
+/// `__swift5_builtin` section (matches `BuiltinTypeDescriptorBaseline`'s
+/// carrier).
+@Suite
+final class BuiltinTypeTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "BuiltinType"
+ static var registeredTestMethodNames: Set {
+ BuiltinTypeBaseline.registeredTestMethodNames
+ }
+
+ private func loadBuiltins() throws -> (file: BuiltinType, image: BuiltinType) {
+ let fileDescriptor = try BaselineFixturePicker.builtinTypeDescriptor_first(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.builtinTypeDescriptor_first(in: machOImage)
+ let file = try BuiltinType(descriptor: fileDescriptor, in: machOFile)
+ let image = try BuiltinType(descriptor: imageDescriptor, in: machOImage)
+ return (file: file, image: image)
+ }
+
+ @Test("init(descriptor:in:)") func initializerWithMachO() async throws {
+ let fileDescriptor = try BaselineFixturePicker.builtinTypeDescriptor_first(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.builtinTypeDescriptor_first(in: machOImage)
+
+ let fileBuiltin = try BuiltinType(descriptor: fileDescriptor, in: machOFile)
+ let imageBuiltin = try BuiltinType(descriptor: imageDescriptor, in: machOImage)
+ let fileCtxBuiltin = try BuiltinType(descriptor: fileDescriptor, in: fileContext)
+ let imageCtxBuiltin = try BuiltinType(descriptor: imageDescriptor, in: imageContext)
+
+ #expect(fileBuiltin.descriptor.offset == BuiltinTypeBaseline.firstBuiltin.descriptorOffset)
+ #expect(imageBuiltin.descriptor.offset == BuiltinTypeBaseline.firstBuiltin.descriptorOffset)
+ #expect(fileCtxBuiltin.descriptor.offset == BuiltinTypeBaseline.firstBuiltin.descriptorOffset)
+ #expect(imageCtxBuiltin.descriptor.offset == BuiltinTypeBaseline.firstBuiltin.descriptorOffset)
+ }
+
+ @Test("init(descriptor:)") func initializerInProcess() async throws {
+ // The InProcess `init(descriptor:)` walks the descriptor via raw
+ // pointer. We assert it succeeds and the descriptor offset is
+ // non-zero (the absolute pointer is per-process).
+ let imageDescriptor = try BaselineFixturePicker.builtinTypeDescriptor_first(in: machOImage)
+ let pointerWrapper = imageDescriptor.asPointerWrapper(in: machOImage)
+ let inProcess = try BuiltinType(descriptor: pointerWrapper)
+ #expect(inProcess.descriptor.offset != 0)
+ }
+
+ @Test func descriptor() async throws {
+ let builtins = try loadBuiltins()
+ let result = try acrossAllReaders(
+ file: { builtins.file.descriptor.offset },
+ image: { builtins.image.descriptor.offset }
+ )
+ #expect(result == BuiltinTypeBaseline.firstBuiltin.descriptorOffset)
+ }
+
+ @Test func typeName() async throws {
+ let builtins = try loadBuiltins()
+ let presence = try acrossAllReaders(
+ file: { builtins.file.typeName != nil },
+ image: { builtins.image.typeName != nil }
+ )
+ #expect(presence == BuiltinTypeBaseline.firstBuiltin.hasTypeName)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorFlagsTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorFlagsTests.swift
new file mode 100644
index 00000000..ac70bb64
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorFlagsTests.swift
@@ -0,0 +1,120 @@
+import Foundation
+import Testing
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `ContextDescriptorFlags`.
+///
+/// The flags type is the bit-packed `OptionSet` carried in the first 4 bytes
+/// of every descriptor. We sample it off `Structs.StructTest`'s descriptor.
+/// The three static `let`s (`hasInvertibleProtocols`, `isUnique`, `isGeneric`)
+/// collapse with their same-named instance vars under PublicMemberScanner's
+/// name-only key; we register one entry per name and exercise the
+/// instance-derivation path here.
+@Suite
+final class ContextDescriptorFlagsTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "ContextDescriptorFlags"
+ static var registeredTestMethodNames: Set {
+ ContextDescriptorFlagsBaseline.registeredTestMethodNames
+ }
+
+ /// Helper: extract the `ContextDescriptorFlags` from
+ /// `Structs.StructTest`'s descriptor against both readers.
+ private func loadStructTestFlags() throws -> (file: ContextDescriptorFlags, image: ContextDescriptorFlags) {
+ let fileDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOImage)
+ return (file: fileDescriptor.layout.flags, image: imageDescriptor.layout.flags)
+ }
+
+ @Test func rawValue() async throws {
+ let flags = try loadStructTestFlags()
+ let result = try acrossAllReaders(
+ file: { flags.file.rawValue },
+ image: { flags.image.rawValue }
+ )
+ #expect(result == ContextDescriptorFlagsBaseline.structTest.rawValue)
+ }
+
+ @Test("init(rawValue:)") func initializerWithRawValue() async throws {
+ // Round-trip construction: `init(rawValue:)` must reproduce the
+ // baseline's stored rawValue verbatim, and the derived accessors
+ // (`kind`, `version`, etc.) must match the live extraction.
+ let constructed = ContextDescriptorFlags(
+ rawValue: ContextDescriptorFlagsBaseline.structTest.rawValue
+ )
+ #expect(constructed.rawValue == ContextDescriptorFlagsBaseline.structTest.rawValue)
+ #expect(constructed.kind.rawValue == ContextDescriptorFlagsBaseline.structTest.kindRawValue)
+ #expect(constructed.version == ContextDescriptorFlagsBaseline.structTest.version)
+ #expect(constructed.kindSpecificFlagsRawValue == ContextDescriptorFlagsBaseline.structTest.kindSpecificFlagsRawValue)
+ #expect(constructed.hasInvertibleProtocols == ContextDescriptorFlagsBaseline.structTest.hasInvertibleProtocols)
+ #expect(constructed.isUnique == ContextDescriptorFlagsBaseline.structTest.isUnique)
+ #expect(constructed.isGeneric == ContextDescriptorFlagsBaseline.structTest.isGeneric)
+ }
+
+ @Test func kind() async throws {
+ let flags = try loadStructTestFlags()
+ let result = try acrossAllReaders(
+ file: { flags.file.kind.rawValue },
+ image: { flags.image.kind.rawValue }
+ )
+ #expect(result == ContextDescriptorFlagsBaseline.structTest.kindRawValue)
+ }
+
+ @Test func version() async throws {
+ let flags = try loadStructTestFlags()
+ let result = try acrossAllReaders(
+ file: { flags.file.version },
+ image: { flags.image.version }
+ )
+ #expect(result == ContextDescriptorFlagsBaseline.structTest.version)
+ }
+
+ @Test func kindSpecificFlagsRawValue() async throws {
+ let flags = try loadStructTestFlags()
+ let result = try acrossAllReaders(
+ file: { flags.file.kindSpecificFlagsRawValue },
+ image: { flags.image.kindSpecificFlagsRawValue }
+ )
+ #expect(result == ContextDescriptorFlagsBaseline.structTest.kindSpecificFlagsRawValue)
+ }
+
+ @Test func kindSpecificFlags() async throws {
+ let flags = try loadStructTestFlags()
+ // `kindSpecificFlags` returns `ContextDescriptorKindSpecificFlags?`,
+ // which isn't trivially Equatable. Use presence-only assertion.
+ let presence = try acrossAllReaders(
+ file: { flags.file.kindSpecificFlags != nil },
+ image: { flags.image.kindSpecificFlags != nil }
+ )
+ #expect(presence == ContextDescriptorFlagsBaseline.structTest.hasKindSpecificFlags)
+ }
+
+ @Test func hasInvertibleProtocols() async throws {
+ let flags = try loadStructTestFlags()
+ let result = try acrossAllReaders(
+ file: { flags.file.hasInvertibleProtocols },
+ image: { flags.image.hasInvertibleProtocols }
+ )
+ #expect(result == ContextDescriptorFlagsBaseline.structTest.hasInvertibleProtocols)
+ }
+
+ @Test func isUnique() async throws {
+ let flags = try loadStructTestFlags()
+ let result = try acrossAllReaders(
+ file: { flags.file.isUnique },
+ image: { flags.image.isUnique }
+ )
+ #expect(result == ContextDescriptorFlagsBaseline.structTest.isUnique)
+ }
+
+ @Test func isGeneric() async throws {
+ let flags = try loadStructTestFlags()
+ let result = try acrossAllReaders(
+ file: { flags.file.isGeneric },
+ image: { flags.image.isGeneric }
+ )
+ #expect(result == ContextDescriptorFlagsBaseline.structTest.isGeneric)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorKindSpecificFlagsTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorKindSpecificFlagsTests.swift
new file mode 100644
index 00000000..547b60f2
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorKindSpecificFlagsTests.swift
@@ -0,0 +1,59 @@
+import Foundation
+import Testing
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `ContextDescriptorKindSpecificFlags`.
+///
+/// `ContextDescriptorKindSpecificFlags` is a sum type with three case-
+/// extraction accessors (`protocolFlags`, `typeFlags`, `anonymousFlags`).
+/// We sample off `Structs.StructTest`'s descriptor — a struct kind whose
+/// flags resolve to the `.type(...)` case (so `typeFlags != nil`, the
+/// other two `nil`). PublicMemberScanner does NOT emit MethodKey entries
+/// for enum cases.
+@Suite
+final class ContextDescriptorKindSpecificFlagsTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "ContextDescriptorKindSpecificFlags"
+ static var registeredTestMethodNames: Set {
+ ContextDescriptorKindSpecificFlagsBaseline.registeredTestMethodNames
+ }
+
+ /// Helper: extract the `ContextDescriptorKindSpecificFlags` from
+ /// `Structs.StructTest`'s descriptor against both readers.
+ private func loadStructTestKindSpecificFlags() throws -> (file: ContextDescriptorKindSpecificFlags, image: ContextDescriptorKindSpecificFlags) {
+ let fileDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOImage)
+ let fileFlags = try required(fileDescriptor.layout.flags.kindSpecificFlags)
+ let imageFlags = try required(imageDescriptor.layout.flags.kindSpecificFlags)
+ return (file: fileFlags, image: imageFlags)
+ }
+
+ @Test func protocolFlags() async throws {
+ let flags = try loadStructTestKindSpecificFlags()
+ let presence = try acrossAllReaders(
+ file: { flags.file.protocolFlags != nil },
+ image: { flags.image.protocolFlags != nil }
+ )
+ #expect(presence == ContextDescriptorKindSpecificFlagsBaseline.structTest.hasProtocolFlags)
+ }
+
+ @Test func typeFlags() async throws {
+ let flags = try loadStructTestKindSpecificFlags()
+ let presence = try acrossAllReaders(
+ file: { flags.file.typeFlags != nil },
+ image: { flags.image.typeFlags != nil }
+ )
+ #expect(presence == ContextDescriptorKindSpecificFlagsBaseline.structTest.hasTypeFlags)
+ }
+
+ @Test func anonymousFlags() async throws {
+ let flags = try loadStructTestKindSpecificFlags()
+ let presence = try acrossAllReaders(
+ file: { flags.file.anonymousFlags != nil },
+ image: { flags.image.anonymousFlags != nil }
+ )
+ #expect(presence == ContextDescriptorKindSpecificFlagsBaseline.structTest.hasAnonymousFlags)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorKindTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorKindTests.swift
new file mode 100644
index 00000000..14e3031a
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorKindTests.swift
@@ -0,0 +1,48 @@
+import Foundation
+import Testing
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `ContextDescriptorKind`.
+///
+/// `ContextDescriptorKind` is a `UInt8`-backed enum. PublicMemberScanner does
+/// NOT emit MethodKey entries for enum cases (only for `func`/`var`/`init`/
+/// `subscript`), so we only register `description` and `mangledType`.
+///
+/// The kind value is sampled off `Structs.StructTest`'s descriptor — a
+/// `.struct` kind whose `description == "struct"` and `mangledType == "V"`.
+@Suite
+final class ContextDescriptorKindTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "ContextDescriptorKind"
+ static var registeredTestMethodNames: Set {
+ ContextDescriptorKindBaseline.registeredTestMethodNames
+ }
+
+ /// Helper: extract the `ContextDescriptorKind` from
+ /// `Structs.StructTest`'s descriptor against both readers.
+ private func loadStructTestKinds() throws -> (file: ContextDescriptorKind, image: ContextDescriptorKind) {
+ let fileDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOImage)
+ return (file: fileDescriptor.layout.flags.kind, image: imageDescriptor.layout.flags.kind)
+ }
+
+ @Test func description() async throws {
+ let kinds = try loadStructTestKinds()
+ let result = try acrossAllReaders(
+ file: { kinds.file.description },
+ image: { kinds.image.description }
+ )
+ #expect(result == ContextDescriptorKindBaseline.structTest.description)
+ }
+
+ @Test func mangledType() async throws {
+ let kinds = try loadStructTestKinds()
+ let result = try acrossAllReaders(
+ file: { kinds.file.mangledType },
+ image: { kinds.image.mangledType }
+ )
+ #expect(result == ContextDescriptorKindBaseline.structTest.mangledType)
+ }
+}
diff --git a/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorProtocolTests.swift b/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorProtocolTests.swift
new file mode 100644
index 00000000..690071fa
--- /dev/null
+++ b/Tests/MachOSwiftSectionTests/Fixtures/ContextDescriptor/ContextDescriptorProtocolTests.swift
@@ -0,0 +1,101 @@
+import Foundation
+import Testing
+import MachOFoundation
+@testable import MachOSwiftSection
+@testable import MachOTestingSupport
+import MachOFixtureSupport
+
+/// Fixture-based Suite for `ContextDescriptorProtocol`.
+///
+/// Per the protocol-extension attribution rule (see `BaselineGenerator.swift`),
+/// `parent`, `genericContext`, `moduleContextDescriptor`,
+/// `isCImportedContextDescriptor`, and `subscript(dynamicMember:)` are all
+/// owned by this Suite, NOT by the concrete-descriptor Suites.
+///
+/// Each `@Test` exercises the protocol-extension method through one of the
+/// conforming concrete types (`Structs.StructTest`'s `StructDescriptor`).
+/// Returned wrappers (`SymbolOrElement?`,
+/// `GenericContext?`, etc.) aren't trivially Equatable, so we assert on
+/// presence flags recorded in the baseline.
+@Suite
+final class ContextDescriptorProtocolTests: MachOSwiftSectionFixtureTests, FixtureSuite, @unchecked Sendable {
+ static let testedTypeName = "ContextDescriptorProtocol"
+ static var registeredTestMethodNames: Set {
+ ContextDescriptorProtocolBaseline.registeredTestMethodNames
+ }
+
+ @Test func parent() async throws {
+ let fileDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOImage)
+
+ let presence = try acrossAllReaders(
+ file: { (try fileDescriptor.parent(in: machOFile)) != nil },
+ image: { (try imageDescriptor.parent(in: machOImage)) != nil }
+ )
+ #expect(presence == ContextDescriptorProtocolBaseline.structTest.hasParent)
+
+ // ReadingContext-based overload also exercised.
+ let imageCtxPresence = (try imageDescriptor.parent(in: imageContext)) != nil
+ #expect(imageCtxPresence == ContextDescriptorProtocolBaseline.structTest.hasParent)
+ }
+
+ @Test func genericContext() async throws {
+ let fileDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOImage)
+
+ let presence = try acrossAllReaders(
+ file: { (try fileDescriptor.genericContext(in: machOFile)) != nil },
+ image: { (try imageDescriptor.genericContext(in: machOImage)) != nil }
+ )
+ #expect(presence == ContextDescriptorProtocolBaseline.structTest.hasGenericContext)
+
+ // ReadingContext-based overload also exercised.
+ let imageCtxPresence = (try imageDescriptor.genericContext(in: imageContext)) != nil
+ #expect(imageCtxPresence == ContextDescriptorProtocolBaseline.structTest.hasGenericContext)
+ }
+
+ @Test func moduleContextDescriptor() async throws {
+ let fileDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOImage)
+
+ let presence = try acrossAllReaders(
+ file: { (try fileDescriptor.moduleContextDescriptor(in: machOFile)) != nil },
+ image: { (try imageDescriptor.moduleContextDescriptor(in: machOImage)) != nil }
+ )
+ #expect(presence == ContextDescriptorProtocolBaseline.structTest.hasModuleContextDescriptor)
+
+ // ReadingContext-based overload also exercised.
+ let imageCtxPresence = (try imageDescriptor.moduleContextDescriptor(in: imageContext)) != nil
+ #expect(imageCtxPresence == ContextDescriptorProtocolBaseline.structTest.hasModuleContextDescriptor)
+ }
+
+ @Test func isCImportedContextDescriptor() async throws {
+ let fileDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOImage)
+
+ let result = try acrossAllReaders(
+ file: { try fileDescriptor.isCImportedContextDescriptor(in: machOFile) },
+ image: { try imageDescriptor.isCImportedContextDescriptor(in: machOImage) }
+ )
+ #expect(result == ContextDescriptorProtocolBaseline.structTest.isCImportedContextDescriptor)
+
+ // ReadingContext-based overload also exercised.
+ let imageCtxResult = try imageDescriptor.isCImportedContextDescriptor(in: imageContext)
+ #expect(imageCtxResult == ContextDescriptorProtocolBaseline.structTest.isCImportedContextDescriptor)
+ }
+
+ @Test("subscript(dynamicMember:)") func subscriptDynamicMember() async throws {
+ let fileDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOFile)
+ let imageDescriptor = try BaselineFixturePicker.struct_StructTest(in: machOImage)
+
+ // The dynamic-member subscript routes any `KeyPath