diff --git a/Tests/SafeDIToolFuzzerTests/SafeDIToolGraphFuzzerTests.swift b/Tests/SafeDIToolFuzzerTests/SafeDIToolGraphFuzzerTests.swift index d019e6dd8..93bff2709 100644 --- a/Tests/SafeDIToolFuzzerTests/SafeDIToolGraphFuzzerTests.swift +++ b/Tests/SafeDIToolFuzzerTests/SafeDIToolGraphFuzzerTests.swift @@ -7633,7 +7633,7 @@ struct SafeDIToolGraphFuzzerTests { /// one compile and one link. static let smokeSeeds: [UInt64] = [4, 5, 12, 18, 25, 30, 40, 53, 59, 62, 70, 86, 94, 97, 98, 99, 133, 161, 212, 267, 304, 327, 378, 466, 520, 582, 691, 705, 731, 930, 2_186, 2_314, 2_420, 2_449, 2_611, 3_360, 4_002, 4_224, 4_516, 5_889, 6_388] - static let smokeAndKnownIssueFixtureHash: UInt64 = 0x263F78543B155B18 + static let smokeAndKnownIssueFixtureHash: UInt64 = 0x1FEA9E97EB1A6EF2 /// The remedies the remedy oracle applies in the smoke batch's rejected graphs. `SafeDIToolGraphFuzzerRemedyTests` /// holds a representative of every kind. @@ -7643,15 +7643,15 @@ struct SafeDIToolGraphFuzzerTests { /// them; `corpusPartitionHash` pins the whole corpus's. The partition draws nothing from the seed, so changing it /// changes neither the graphs nor the pins on them: these pins make a change to the partition deliberate. They /// move with the generator and, this one, with the smoke and known-issue seeds too, as the fixture hashes do. - static let smokeAndKnownIssuePartitionHash: UInt64 = 0x626765D8C1C72910 + static let smokeAndKnownIssuePartitionHash: UInt64 = 0xC1D9B3C5E55B6FA9 /// The corpus, seeds `0..")], - seeds: [1_049, 3_019, 4_622, 4_839], + seeds: [1_049, 2_787, 3_019, 4_622, 4_839], ), ] diff --git a/Tests/SafeDIToolTestSupport/GraphFuzzer.swift b/Tests/SafeDIToolTestSupport/GraphFuzzer.swift index 6d0306b49..fb74be7ee 100644 --- a/Tests/SafeDIToolTestSupport/GraphFuzzer.swift +++ b/Tests/SafeDIToolTestSupport/GraphFuzzer.swift @@ -3081,6 +3081,7 @@ enum GraphFuzzerGenerator { twinRandom = GraphFuzzerRandomNumberGenerator(seed: seed ^ Self.twinRandomSeedMask) renamedLazyReaderRandom = GraphFuzzerRandomNumberGenerator(seed: seed ^ Self.renamedLazyReaderRandomSeedMask) renameSplitRandom = GraphFuzzerRandomNumberGenerator(seed: seed ^ Self.renameSplitRandomSeedMask) + lazyInstanceNamedApartRandom = GraphFuzzerRandomNumberGenerator(seed: seed ^ Self.lazyInstanceNamedApartRandomSeedMask) seamDependencyRandom = GraphFuzzerRandomNumberGenerator(seed: seed ^ GraphFuzzerSeamDependencyDraw.seamRandomSeedMask) prefix = GraphFuzzerFixture.typeNamePrefix(forSeed: seed) // One draw decides, so graphs that are not mixed draw exactly what they drew before mixed graphs existed. @@ -3180,6 +3181,8 @@ enum GraphFuzzerGenerator { finalDeclarations = addingMockRootEnteringDenseCycleTwice(to: finalDeclarations) // Drawn after it, from a stream of its own, so that every other draw of a graph it draws in is drawn as before. finalDeclarations = addingErasedBuilderFirstReachingMockedType(to: finalDeclarations) + // Drawn after it, from a stream of its own, so that every other draw of a graph it draws in is drawn as before. + finalDeclarations = addingLazyInstanceReadBesideLabelNamedApart(to: finalDeclarations) // In a graph split across modules, every file names its module and imports the seam's, so that a type of the // caller can name what the seam's module declares, such as the creation stamps' counter. let isSplit = finalDeclarations.contains { $0.module == .seamModule } @@ -3717,6 +3720,9 @@ enum GraphFuzzerGenerator { /// Draws only `addingRenameFulfilledByValueAndWrapper`'s choices: whether a graph gains `RenameSplitRoot`'s tree, and /// every shape of that tree. private var renameSplitRandom: GraphFuzzerRandomNumberGenerator + /// Draws only `addingLazyInstanceReadBesideLabelNamedApart`'s choices: whether a graph gains `ApartScreen`'s tree, + /// and every shape of that tree. + private var lazyInstanceNamedApartRandom: GraphFuzzerRandomNumberGenerator /// The files `markerFreeFileRandom` moved a declaration into: each named, holding the declaration alone, and in the /// module of the type, `ownerName`, whose file it was drawn in. private var markerFreeFiles = [(ownerName: String, fileName: String, declaration: String)]() @@ -9277,6 +9283,55 @@ enum GraphFuzzerGenerator { private static let renamedLazyReaderRandomSeedMask: UInt64 = 0x52656E4C617A79 + // MARK: A lazy instance read beside a label its mock names apart + + /// The base corpus's draw, in one graph of sixteen, of a rename of a lazy instance whose label a mock names apart. + /// `ApartScreen`, whose mock is generated, instantiates or receives `apartValue` as an `ApartLegacy` and receives + /// `ApartLogger` and `ApartTracker` (built beneath the screen, a type receiving `apartValue` in another form would be + /// hidden by the screen's, which the plugin rejects). The tracker receives `apartValue` as a + /// `LazilyInstantiated` (its `Sendable` kind in a `Sendable` graph), which the mock promotes and names + /// apart from the screen's `ApartLegacy`. The logger receives the same wrapper only if available, as an optional, + /// and renames its instance, `@Received(fulfilledByDependencyNamed: "apartValue", ofType: ApartValue.self)`. The + /// rename must read the instance through the wrapper the mock names apart, never through the logger's optional + /// binding, which does not compile. The logger's and the screen's properties come in orders of their own. + /// `lazyInstanceNamedApartRandom` draws only for this pass, after every other, and only in the base corpus. + private mutating func addingLazyInstanceReadBesideLabelNamedApart(to declarations: [TypeDeclaration]) -> [TypeDeclaration] { + guard features.isEmpty, lazyInstanceNamedApartRandom.percentChance(6) else { return declarations } + var declarations = declarations + let screenInstantiatesLegacy = lazyInstanceNamedApartRandom.percentChance(50) + let conformances = sendability == .mixed ? ["@unchecked Sendable"] : [] + func append(_ name: String, arguments: [String] = [], _ properties: [PropertyDeclaration]) { + var properties = properties + for index in properties.indices.reversed() { + properties.swapAt(index, lazyInstanceNamedApartRandom.integer(in: 0...index)) + } + declarations.append(TypeDeclaration( + name: "\(prefix)\(name)", + instantiableArguments: arguments, + properties: properties, + declaresHelperTypes: false, + additionalConformances: conformances, + )) + } + let valueName = "\(prefix)ApartValue" + let wrapped = "\(lazilyInstantiatedWrapper(isSendable: sendability == .sendable))<\(valueName)>" + append("ApartValue", []) + append("ApartLegacy", []) + append("ApartTracker", [PropertyDeclaration(attribute: "@Received", label: "apartValue", type: wrapped)]) + append("ApartLogger", [ + PropertyDeclaration(attribute: "@Received(onlyIfAvailable: true)", label: "apartValue", type: "\(wrapped)?"), + PropertyDeclaration(attribute: "@Received(fulfilledByDependencyNamed: \"apartValue\", ofType: \(valueName).self)", label: "apartRenamed", type: valueName), + ]) + append("ApartScreen", arguments: ["generateMock: true"], [ + PropertyDeclaration(attribute: screenInstantiatesLegacy ? "@Instantiated" : "@Received", label: "apartValue", type: "\(prefix)ApartLegacy"), + PropertyDeclaration(attribute: "@Received", label: "apartLogger", type: "\(prefix)ApartLogger"), + PropertyDeclaration(attribute: "@Received", label: "apartTracker", type: "\(prefix)ApartTracker"), + ]) + return declarations + } + + private static let lazyInstanceNamedApartRandomSeedMask: UInt64 = 0x4170617274 + // MARK: A rename fulfilled by a value and by a wrapper /// The base corpus's draw, in one graph of sixteen, of one type whose rename is fulfilled by a label one parent