Skip to content

Build the engine under the strictest compiler settings - #384

Merged
alexkroman merged 2 commits into
mainfrom
chore/strict-engine-compiler
Nov 25, 2026
Merged

alexkroman merged 2 commits into
mainfrom
chore/strict-engine-compiler

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Builds every engine target (AssemblyAI, BlurtEngine, CommandFixture, BlurtEngineTests) under one shared strictSettings array in Package.swift. Every new diagnostic is fixed. There are no behavior changes.

Enabled

  • Upcoming features:
    • ExistentialAny (SE-0335)
    • MemberImportVisibility (SE-0444)
    • InternalImportsByDefault (SE-0409)
    • InferIsolatedConformances (SE-0470)
    • ImmutableWeakCaptures (SE-0481)
  • .strictMemorySafety() (SE-0458)
  • .treatAllWarnings(as: .error) (SE-0480)
  • unsafeFlags:
    • -require-explicit-sendable
    • -warn-long-function-bodies=500 and -warn-long-expression-type-checking=500. The slowest type-check today is 181 ms.
    • Both apps resolve and build the package with these flags.
  • scripts/ios-typecheck.sh passes the same flags, so the engine's iOS-only code is held to the same bar. Comments in both files say to change the two lists together.

Deliberately excluded (reasons in a Package.swift comment)

These change what the code does, not what the compiler checks:

  • NonisolatedNonsendingByDefault (SE-0461): moves where every nonisolated async function runs.
  • Default MainActor isolation (SE-0466): would put audio and network work on the main thread.
  • ApproachableConcurrency: bundles the two above.
  • -enable-actor-data-race-checks: adds run-time traps; Swift 6's dynamic isolation checks already cover them.

Diagnostics fixed

Setting Count
StrictMemorySafety 163 (+1 after rebasing on main)
InternalImportsByDefault 35 (AssemblyAI) + 152 (BlurtEngine)
ExistentialAny 33
MemberImportVisibility 24
InferIsolatedConformances 4

Memory safety: about 156 unsafe acknowledgements on existing Core Audio, Accessibility, Keychain and keyboard-layout pointer code, with none of it rewritten.

  • @safe marks three types that keep raw audio handles private: AudioRouteMonitor, SystemAudioRecorder and MixWriter.
  • @preconcurrency @unsafe import AVFoundation where the capture code needs it.
  • The compiler forced a few optional-binding rewrites. Each is equivalent to what it replaces: guard let x became guard let x = unsafe x.

Imports: each new public import is the minimum the compiler accepts. An unneeded one is itself a warning, and warnings are now errors.

Review check: I stripped any, unsafe, @safe/@unsafe, nonisolated, import lines and comments out of the diff. What was left is only those markers on reflowed lines.

Two small follow-ons:

  • jscpd: marking the pointer calls made two MixWriter tests' buffer setup identical, so it now lives in one withMonoList test helper.
  • swift-format: its formatter writes for unsafe buffer in buffers but its own linter flags the spacing, so that one loop carries // swift-format-ignore with a comment explaining why.

Verification

  • Full scripts/check.sh run from a checkout named blurt, as CI uses:
    • every step green, including the xcodegen drift check and both periphery scans;
    • engine coverage 93.87%;
    • 369 iOS tests, BlurtiOSCore coverage 96.12%.
  • The jscpd clone was the only failure in that run; it's fixed in the second commit (jscpd: 0 clones).
  • After rebasing onto the current main:
    • the strict build is clean, with the newly landed code included;
    • 1334 engine tests pass;
    • whole-repo SwiftLint is clean;
    • ios-typecheck.sh passes.

🤖 Generated with Claude Code

alexkroman-assembly and others added 2 commits November 24, 2026 17:41
Package.swift now applies one shared `strictSettings` array to AssemblyAI,
BlurtEngine, CommandFixture and BlurtEngineTests: ExistentialAny,
MemberImportVisibility, InternalImportsByDefault, InferIsolatedConformances,
ImmutableWeakCaptures, strict memory safety, all warnings as errors,
-require-explicit-sendable, and a 500 ms type-checking threshold for function
bodies and expressions. Features that change run-time behaviour rather than
checking (NonisolatedNonsendingByDefault, default MainActor isolation,
ApproachableConcurrency, -enable-actor-data-race-checks) are left off, with
the reasons in the manifest. ios-typecheck.sh passes the same flags for the
engine's iOS shape.

The fixes are diagnostics only: `any` on existentials, `public import` where
a public API exposes an imported type, imports a file was relying on another
file for, `unsafe` acknowledgements on the existing pointer and buffer code,
`@safe` on the three classes that keep raw audio handles private,
`@unsafe` on the `@preconcurrency` AVFoundation imports, and `nonisolated` on
the fixture's AppKit conformances to keep them as they were. No logic changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Marking the unsafe pointer calls reflowed the capacity and after-close
tests' AudioBufferList setup into identical lines, which jscpd flags as a
clone. One withMonoList helper holds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexkroman
alexkroman enabled auto-merge November 25, 2026 01:43
@alexkroman
alexkroman added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 39b79eb Nov 25, 2026
13 checks passed
@alexkroman
alexkroman deleted the chore/strict-engine-compiler branch November 25, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants