Skip to content

Make font-holding config structs Sendable via SendableFont wrapper - #125

Draft
Jun Yan (junyan72) wants to merge 2 commits into
mainfrom
make-font-config-structs-sendable
Draft

Make font-holding config structs Sendable via SendableFont wrapper#125
Jun Yan (junyan72) wants to merge 2 commits into
mainfrom
make-font-config-structs-sendable

Conversation

@junyan72

Copy link
Copy Markdown
Contributor

Summary

Make the font-holding configuration structs safely Sendable under strict concurrency by centralizing the unchecked assertion in a single internal wrapper, instead of applying @unchecked Sendable to each struct.

  • Add internal SendableFont value type (Utilities/SendableFont.swift) that wraps MDFont (UIFont/NSFont) and carries the sole @unchecked Sendable assertion, documented in one auditable place.
  • TextFonts, MarkdownRenderConfig.MarkdownInlineTextStyle, and MarkdownRenderConfig.CitationConfig now store SendableFont privately and expose their existing public MDFont API via computed accessors. The structs stay declared Hashable, Sendable (unchanged public surface, no @unchecked).
  • No consumer source break: public initializers and font property types are identical; MDFont remains the native alias everywhere in the rendering path (NSAttributedString boundaries, font metrics) and in tests.
  • Avoids leaking a retroactive Sendable conformance onto the platform font types.

Closes #124

Validation

  • xcodebuild build -scheme SwiftStreamingMarkdown -destination "platform=iOS Simulator,name=iPhone 17" -skipMacroValidation SWIFT_STRICT_CONCURRENCY=completeBUILD SUCCEEDED, zero errors and zero font/SendableFont Sendable warnings (remaining strict-concurrency warnings are unrelated: LaTeX regexes, view controllers, TableView mocks).
  • swiftlint --strict on the three changed/added files — 0 violations.
  • Existing test suite unaffected: tests use MDFont factory methods, which still resolve to the native font type.

OSS readiness

  • No secrets, internal URLs, private identifiers, or product-only service names were added.
  • Public docs, fixtures, or notices were updated if behavior or dependencies changed. (public API surface unchanged; no docs update needed)
  • Third-party dependency changes (adds, removes, version bumps) are intentional and reviewed. (no dependency changes)
  • Streaming/incomplete markdown behavior remains covered by fixtures or tests. (no rendering-path changes)

Introduce an internal SendableFont value type that centralizes the
@unchecked Sendable assertion for MDFont (UIFont/NSFont). TextFonts,
MarkdownInlineTextStyle, and CitationConfig now store SendableFont
privately and expose their existing public MDFont API via computed
accessors, so they are plainly Sendable without a per-struct unchecked
assertion and without leaking a retroactive Sendable conformance onto
the platform font types.

Closes #124

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes the single @unchecked Sendable assertion needed for platform fonts (UIFont/NSFont) into an internal SendableFont wrapper so public configuration types can remain plainly Sendable under strict concurrency without scattering @unchecked Sendable across multiple structs.

Changes:

  • Added internal SendableFont wrapper that holds MDFont and carries the only @unchecked Sendable conformance.
  • Updated TextFonts to store fonts privately as SendableFont/SendableFont? while preserving the existing public MDFont API via computed accessors.
  • Updated MarkdownRenderConfig.MarkdownInlineTextStyle and MarkdownRenderConfig.CitationConfig to use private SendableFont storage and computed MDFont accessors, keeping public initializer signatures and types unchanged.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Sources/MarkdownText/Utilities/SendableFont.swift Introduces a single internal wrapper type that centralizes the unchecked Sendable assertion for platform fonts.
Sources/MarkdownText/Style/TextFonts.swift Moves stored font variants to private SendableFont backing storage while exposing the same public MDFont-typed API.
Sources/MarkdownText/Models/MarkdownRenderConfig.swift Updates inline text style and citation config to store fonts via SendableFont backing fields and keep public MDFont accessors/initializers.

Use internal-prefixed property names (internalNormal, internalFont, etc.)
instead of a leading underscore for the private SendableFont storage,
per repo naming convention.

Refs #124

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@junyan72
Jun Yan (junyan72) marked this pull request as draft July 7, 2026 22:11
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.

Upgrade SPM to Swift 6

2 participants