-
Notifications
You must be signed in to change notification settings - Fork 0
fix: SyntaxHighlighter crashes on background queue due to implicit MainActor isolation #693
Copy link
Copy link
Open
Labels
Description
Summary
Pine crashes immediately on launch when opening a file. SyntaxHighlighter.resolveGrammar(language:fileName:) is called on the background com.pine.syntax-highlight serial queue, but Swift runtime asserts MainActor isolation and triggers dispatch_assert_queue_fail → SIGTRAP.
Crash Stack
Thread 1 Crashed:: Dispatch queue: com.pine.syntax-highlight (QOS: USER_INITIATED)
_dispatch_assert_queue_fail
dispatch_assert_queue
_swift_task_checkIsolatedSwift
swift_task_isCurrentExecutorWithFlagsImpl
closure #1 in SyntaxHighlighter.resolveGrammar(language:fileName:) (SyntaxHighlighter.swift:500)
SyntaxHighlighter.resolveGrammar(language:fileName:) (SyntaxHighlighter.swift:500)
SyntaxHighlighter.computeMatches (SyntaxHighlighter.swift:674)
SyntaxHighlighter.highlightAsync (SyntaxHighlighter.swift:802)
Root Cause
SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor in build settings makes SyntaxHighlighter (a class) implicitly @MainActor. But highlightAsync dispatches work to a background serial queue (com.pine.syntax-highlight), and resolveGrammar accesses @MainActor-isolated state from that queue. Swift runtime detects the violation and crashes.
Motivation
App crashes on launch — completely blocks usage.
Implementation ideas
- Mark
SyntaxHighlighterasnonisolated(it manages its own thread safety via NSLock + serial queue) - Or mark specific methods/closures as
nonisolated/@Sendable - Same pattern may affect other classes that do background work:
GitStatusProvider,ProjectSearchProvider,WorkspaceManager - Audit all classes that dispatch to background queues
Reactions are currently unavailable