     "Incremental compilation: New definition: \(aspect) of top-level name '\(name)' in \(input).swiftdeps"
   }
 
+  @DB func foundDependent(of defInput: String, compiling useInput: String) -> [Diagnostic.Message] {
+    "Incremental compilation: Found dependent of \(defInput).swift:  {compile: \(useInput).o <= \(useInput).swift}"
+  }
+  @DB func hasMalformed(_ newInput: String) -> [Diagnostic.Message] {
+    "Incremental compilation: Has malformed dependency source; will queue  {compile: \(newInput).o <= \(newInput).swift}"
+  }
+  @DB func failedToFindSource(_ input: String) -> [Diagnostic.Message] {
+      .warning("Failed to find source file for '\(input).swiftdeps', recovering with a full rebuild. Next build will be incremental.")
+  }
+  @DB func failedToReadSomeSource(compiling input: String) -> [Diagnostic.Message] {
+    "Incremental compilation: Failed to read some dependencies source; compiling everything  {compile: \(input).o <= \(input).swift}"
+  }
+
+  // MARK: - tracing
+  @DB func trace(@TraceBuilder _ steps: () -> String) -> [Diagnostic.Message] {
+    steps()
+  }
+
   // MARK: - scheduling
   @DB func schedulingAlwaysRebuild(_ input: String) -> [Diagnostic.Message] {
     "Incremental compilation: scheduling dependents of \(input).swift; -driver-always-rebuild-dependents"

      findingBatchingCompiling("main")
      fingerprintChanged(.interface, "main")
      fingerprintChanged(.implementation, "main")
      "Incremental compilation: Traced: interface of source file main.swiftdeps in main.swift -> interface of top-level name 'foo' in main.swift -> implementation of source file other.swiftdeps in other.swift"
      "Incremental compilation: Queuing because of dependencies discovered later:  {compile: other.o <= other.swift}"
      "Incremental compilation: Scheduling invalidated  {compile: other.o <= other.swift}"
      findingBatchingCompiling("other")
      schedLinking
    }

    defining topLevelName: String,
    removeInputFromInvocation: Bool,
    removeSwiftDepsFile: Bool,
    afterRestoringBadPriors: Bool,
    removedFileDependsOnChangedFile: Bool
  ) throws -> ModuleDependencyGraph {
    let inputs = ["main", "other"] + (removeInputFromInvocation ? [] : [removedInput])
    let extraArguments = removeInputFromInvocation
      ? [] : [inputPath(basename: removedInput).pathString]
    
    let driver = try doABuild(
      "restoring incrementality after removal of \(removedInput)",
      checkDiagnostics: true,
      extraArguments: extraArguments,
      whenAutolinking: autolinkLifecycleExpectedDiags
    ) {
      !removeInputFromInvocation || afterRestoringBadPriors ? readGraph : createdGraphFromSwiftdeps
      enablingCrossModule

      if !removedFileDependsOnChangedFile {
        skippingAll(inputs)
      } else {
        schedulingChanged("main")
        let unchangedInputs = inputs.filter {$0 != "main"}
        maySkip(unchangedInputs)
        queuingInitial("main")
        notSchedulingDependentsUnknownChanges("main")
        skipping(unchangedInputs)
        findingBatchingCompiling("main")

        fingerprintChanged(.interface, "main")
        fingerprintChanged(.implementation, "main")

        let affectedInputs = removeInputFromInvocation && !afterRestoringBadPriors
        ? ["other"]
        : [removedInput, "other"]
        for input in affectedInputs {
          trace {
            TraceStep(.interface, source: "main")
            TraceStep(.interface, .topLevel(name: "foo"), "main")
            TraceStep(.implementation, .sourceFileProvide(name: "\(input).swiftdeps"),
                      input == removedInput && afterRestoringBadPriors
                      ? nil : input)
          }
        }
        if removeInputFromInvocation && afterRestoringBadPriors {
          failedToFindSource(removedInput)
          failedToReadSomeSource(compiling: "main")
        }
        let affectedInputsInBuild = affectedInputs.filter(inputs.contains)
        queuingLater(affectedInputsInBuild)
        schedulingInvalidated(affectedInputsInBuild)
        let affectedInputsInInvocationOrder = inputs.filter(affectedInputsInBuild.contains)
        findingBatchingCompiling(affectedInputsInInvocationOrder)
        schedLinking
      }
    }

