     return diagnostics.contains { $0.message.severity == .error }
   }
 
+  /// Enter a diagnostic transaction delimited by a function that returns
+  /// true if any diagnoses during the transaction should be emitted or false
+  /// to ignore them all.
+  public func transact<T>(_ f: () -> (shouldDiagnose: Bool, T)) -> T {
+    defer { self.transactionIDPool += 1 }
+    let lastTransactionID = self.activeTransaction
+    let newUID = self.transactionIDPool
+    self.activeTransaction = newUID
+    let (commitDiags, result) = f()
+    defer { self.activeTransaction = lastTransactionID }
+    if commitDiags {
+      guard
+        let transactionDiagnostics = self.transactionDiagnostics[newUID]
+      else {
+        return result
+      }
+
+      for diagnostic in transactionDiagnostics {
+        diagnostics.append(diagnostic)
+        for consumer in consumers.values {
+          consumer.handle(diagnostic)
+        }
+      }
+    } else {
+      self.transactionDiagnostics.removeValue(forKey: newUID)
+    }
+    return result
+  }
+
   /// Emits a diagnostic message into the engine.
   ///
   /// - Parameters:

  /// The current set of emitted diagnostics.
  private(set) public var diagnostics = [Diagnostic]()

  /// The set of consumers receiving diagnostic notifications from this engine.
  private(set) private var consumers = [UUID: DiagnosticConsumer]()

  /// Creates a new DiagnosticEngine with no diagnostics registered.
  public init() {}

    let diagnostic = Diagnostic(message: message,
                                node: node,
                                actions: actions)

    if let activeID = self.activeTransaction {
      self.transactionDiagnostics[activeID, default: []].append(diagnostic)
      return message
    }

    diagnostics.append(diagnostic)
    for consumer in consumers.values {
      consumer.handle(diagnostic)
