Skip to content

Swift 6 #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Swift 6 #318

wants to merge 16 commits into from

Conversation

makoni
Copy link
Collaborator

@makoni makoni commented Jul 10, 2025

Summary of Changes

Issue: #271

1. Swift Concurrency & Thread Safety

  • Adds @unchecked Sendable conformance to many core classes and structs (e.g., Element, Document, Node, Tag, Entities, etc.), allowing safe usage in concurrent contexts and aligning with Swift's evolving concurrency model.
  • Refactors singleton/shared state in Tag and Entities to use thread-safe access (e.g., locks and registries), preventing race conditions and improving reliability in multi-threaded usage.

2. Package & Platform Updates

  • Updates the Swift tools version in Package.swift from 5.9 to 6.0, enabling the latest Swift language features and tooling improvements.

3. Code Quality & Consistency

  • Makes several properties let instead of var for immutability and performance.
  • Refactors certain method signatures to use [UInt8] instead of ArraySlice<UInt8>, simplifying usage and consistency.
  • Adds @MainActor annotations to various methods and tests, clarifying main-thread affinity where necessary.

4. Test Suite Improvements

  • Removes the deprecated LinuxMain.swift file and the manual allTests arrays from all test classes, as these are no longer needed with modern SwiftPM/XCTest.
  • Cleans up test files to rely on automatic test discovery, simplifying maintenance and making the test suite more idiomatic for Swift.

@aehlke
Copy link
Collaborator

aehlke commented Jul 10, 2025

Thank you for the PR!! This is great work. I will review

Thanks especially for the test runner cleanup. That was a pain point in maintaining this

Refactors certain method signatures to use [UInt8] instead of ArraySlice, simplifying usage and consistency.

This is done for performance reasons to avoid copying data when it can be avoided. If this adds friction, please add both [UInt8] and ArraySlice, and avoid using [UInt8] when ArraySlice will suffice for internally-used methods. In fact I would like to change more [UInt8] usage over to ArraySlice where possible, though it is more challenging to work with so it should probably only be for lib-internal use

@aehlke
Copy link
Collaborator

aehlke commented Jul 11, 2025

Hi @scinfu could you please add @makoni as a maintainer as well (or grant me admin privileges to manage contributors) thank you

@makoni
Copy link
Collaborator Author

makoni commented Jul 11, 2025

Reverted some changes to keep using ArraySlice 👌

@aehlke
Copy link
Collaborator

aehlke commented Jul 14, 2025

@makoni just one more question for you above re: MainActor... thanks again

@scinfu
Copy link
Owner

scinfu commented Jul 14, 2025

Hi @scinfu could you please add @makoni as a maintainer as well (or grant me admin privileges to manage contributors) thank you

@aehlke invited!
My account is an individual plan i can't manage privilage.

@aehlke
Copy link
Collaborator

aehlke commented Jul 14, 2025

@makoni tests are failing due to

error: 'swiftsoup': package 'swiftsoup' is using Swift tools version 6.0.0 but the installed version is 5.9.2

(should be an easy fix, I can help later on...)

Copy link

@aehlke
Copy link
Collaborator

aehlke commented Jul 17, 2025

@makoni thank you for the hard work on these updates

I see there are 2 failures on the Ubuntu build:

/__w/SwiftSoup/SwiftSoup/Tests/SwiftSoupTests/DocumentTest.swift:362: error: DocumentTest.testMetaCharsetUpdateXmlIso2022JP : XCTAssertEqual failed: ("<?xml version="1.0" encoding="iso2022jp"?>
<root>
 node
</root>") is not equal to ("<?xml version="&#x31;&#x2e;&#x30;" encoding="&#x69;&#x73;&#x6f;&#x32;&#x30;&#x32;&#x32;&#x6a;&#x70;"?>
<root>
 &#x6e;&#x6f;&#x64;&#x65;
</root>") - 
Test Case 'DocumentTest.testMetaCharsetUpdateXmlIso2022JP' failed (0.0 seconds)

I'm not sure at the moment what's causing this

It would also be great to retain the test suite on Swift 5.9 for backwards compatibility - many (including myself) still haven't upgraded to Swift 6. But maybe that doesn't matter since the individual module can be built on Swift 6 and used in a Swift 5 codebase I guess (haven't investigated how this works yet)

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.

3 participants