Skip to content

Fix highlight region destruction during synchronous layout - #15

Merged
gtokman merged 1 commit into
mainfrom
codex/highlight-region-deinit-crash
Oct 9, 2026
Merged

gtokman merged 1 commit into
mainfrom
codex/highlight-region-deinit-crash

Conversation

@gtokman

@gtokman gtokman commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

Synchronous UIKit text layout can abort while LTXTextLayout.updateHighlightRegions() releases a highlight region. Litext's default MainActor isolation gives this otherwise ordinary Swift class an implicit isolated destructor. On affected runtimes, destruction inside a synchronous task-local scope enters swift_task_deinitOnExecutorImpl and fails in TaskLocal::StopLookupScope with an invalid free (swiftlang/swift#85663).

Fix

Declare an empty nonisolated deinit on LTXHighlightRegion. Its properties and methods retain their existing isolation; destruction has no custom actor-bound cleanup and no longer calls the isolated-deinit runtime. Add a synchronous XCTest that clears a region dictionary inside a task-local scope, checks immediate release, and verifies that the surrounding task-local value is restored.

Validation

  • Compiled the actual region source into an optimized iOS simulator app with Swift 6.3.3 and default MainActor isolation. On iOS 26.2, the original class terminated with SIGABRT; the patched class completed 100 releases and restored task-local values successfully.
  • Generated SIL confirms that the patched destructor no longer references swift_task_deinitOnExecutor.
  • Built the full Litext source target and ran the new XCTest in an isolated macOS SwiftPM harness: one test passed.
  • No xcodebuild, full MarkdownView suite, or physical-device test was run. The exact reported iOS 26.3 runtime is not installed locally.

@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
markdown-view Ready Ready Preview, v0 Oct 9, 2026 6:49pm UTC

Request Review

@gtokman
gtokman marked this pull request as ready for review October 9, 2026 18:58
@gtokman
gtokman merged commit 2d297c5 into main Oct 9, 2026
5 of 6 checks passed

This branch was successfully deployed

1 active deployment
Preview — 051a4476 Deployed Oct 9, 2026 by vercel[bot]
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.

1 participant