Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Tests/SafeDIToolFuzzerTests/SafeDIToolGraphFuzzerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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..<corpusSeedCount`, which ci.yml fuzzes on every pull request and push to main and
/// `SAFEDI_GRAPH_FUZZER_ITERATIONS=corpus` selects. `knownIssues` lists every one that fails.
static let corpusSeedCount = 5_000

static let corpusFixtureHash: UInt64 = 0xA793E05ADD90EC7F
static let corpusFixtureHash: UInt64 = 0x5F6096F77B47A820

static let corpusPartitionHash: UInt64 = 0xB0AAC60BBF6E3D32
static let corpusPartitionHash: UInt64 = 0xB2FB2367E1CDF49A

/// How many of the corpus's graphs the tool accepts, and which ones, as a `GraphFuzzerSeedSetSum`, which
/// shards of the corpus can add up.
Expand All @@ -7676,10 +7676,10 @@ struct SafeDIToolGraphFuzzerTests {
.receivedLazilyInstantiatedInstance: 363,
.forwardedProperty: 1_714,
.optionalForwardedProperty: 889,
.requiredReceive: 2_546,
.requiredReceive: 2_554,
.requiredOptionalReceive: 371,
.onlyIfAvailableReceive: 2_293,
.requiredAlias: 1_365,
.onlyIfAvailableReceive: 2_322,
.requiredAlias: 1_446,
.onlyIfAvailableAlias: 1_033,
.aliasOfOnlyIfAvailableAlias: 78,
.aliasOfOptionalFormOfProperty: 83,
Expand Down Expand Up @@ -7709,7 +7709,7 @@ struct SafeDIToolGraphFuzzerTests {
.forwardedPropertiesTypealiasArgument: 156,
.forwardedTupleBuilderReceivedByMockedType: 137,
.multipleRoots: 2_134,
.generateMock: 2_528,
.generateMock: 2_532,
.lazyCycle: 1_524,
.constantCycleCloser: 301,
.builderReceivedInsideItsTree: 179,
Expand All @@ -7719,13 +7719,13 @@ struct SafeDIToolGraphFuzzerTests {
.sendableBuildersReceivingEachOther: 80,
.receivedLoopMemberWithCycleParameters: 17,
.sendableReceivedLoopMemberWithCycleParameters: 8,
.sameLabelWithDifferentTypes: 1_316,
.sameLabelWithDifferentTypes: 1_405,
.labelSpelledAsGeneratedName: 699,
.dependencyMockCannotBuild: 1_579,
.dependencyMockCannotBuildReceivedBeneathItsOwner: 267,
.dependencyMockCannotBuildReceivedLazilyBesideItsMockedOwner: 68,
.dependencyMockCannotBuildLazilyInstantiatedReceivedAsOtherKindBesideItsMockedOwner: 9,
.sendableAndNonSendableWrappers: 591,
.sendableAndNonSendableWrappers: 592,
.mockedTypeOnLazyCycle: 704,
.typesReceivingEachOtherOnlyIfAvailable: 298,
.labelReceivedAsInstanceAndAsInstantiator: 244,
Expand Down Expand Up @@ -7901,7 +7901,7 @@ struct SafeDIToolGraphFuzzerTests {
mirroredPairsSum: GraphFuzzerSeedSetSum(value: 0xCFD5A9DE3C2D61F5),
skipCounts: [
.requiredParameter: 1_666,
.twoFormsOfOneLabel: 182,
.twoFormsOfOneLabel: 360,
.requiredOptionalReceiveOfNonOptionalDeclaration: 49,
.requiredReceiveOfUncreatedAlias: 40,
],
Expand Down Expand Up @@ -10539,7 +10539,7 @@ struct SafeDIToolGraphFuzzerTests {
GraphFuzzerKnownIssue(
reason: compileTimeAssertionsDifferBetweenIntegrationsReason,
signatures: [.integrationsDiffer(containing: "<compile-time assertions>")],
seeds: [1_049, 3_019, 4_622, 4_839],
seeds: [1_049, 2_787, 3_019, 4_622, 4_839],
),
]

Expand Down
55 changes: 55 additions & 0 deletions Tests/SafeDIToolTestSupport/GraphFuzzer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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)]()
Expand Down Expand Up @@ -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<ApartValue>` (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
Expand Down
Loading