Skip to content

Add MainActor concurrency support#113

Open
acyment wants to merge 6 commits intocucumberswift:mainfrom
acyment:main
Open

Add MainActor concurrency support#113
acyment wants to merge 6 commits intocucumberswift:mainfrom
acyment:main

Conversation

@acyment
Copy link
Copy Markdown

@acyment acyment commented Jan 20, 2026

Summary

  • Add @mainactor annotations across DSL, Gherkin, and Parser components
  • Implement Sendable conformance for value types (Lexer.Position, Step.Keyword, Reporter.Result)
  • Refactor core components for proper MainActor isolation
  • Update test observation and step execution to work with concurrency model

Changes

This PR adds Swift concurrency support by:

  • Annotating all DSL types with @mainactor
  • Adding @mainactor to Gherkin AST and Parser classes
  • Making value types Sendable for safe cross-actor sharing
  • Refactoring Lexer to not inherit from StringReader
  • Updating hook functions and protocols with concurrency annotations

All changes maintain backward compatibility while enabling safe concurrent execution in Swift 6+.

Annotate DSL classes, structs, protocols, and functions with @mainactor
to ensure thread-safety and proper isolation in Swift concurrency.
Annotate Gherkin AST, Parser classes, and enums with @mainactor to
ensure thread-safety and proper isolation in Swift concurrency.
Annotate hook functions, protocols (CucumberTestObserver, Positionable,
Taggable), and supporting types with @mainactor for concurrency safety.
Make Lexer.Position, Step.Keyword, and Reporter.Result conform to
Sendable to enable safe sharing across concurrency domains.
Mark methods as nonisolated or wrap with MainActor.assumeIsolated
to comply with Swift concurrency requirements.
- Rewrite Lexer to not inherit from StringReader and properly
  implement string reading with index tracking
- Update Cucumber class with @mainactor
- Refactor step execution and test observation to work with
  MainActor isolation
- Update JSONReporter to handle keyword type changes
- Make StubGenerator methods static for isolation
@ianhlavats
Copy link
Copy Markdown
Collaborator

@acyment thanks for this PR! Here are some suggestions for improvement:

  1. Replace assumeIsolated with safe dispatching
  2. Drop the Lexer rewrite and just add @MainActor to StringReader instead
  3. Add tests for any behavioral changes
  4. Revert the regexForTokens visibility change

@ianhlavats
Copy link
Copy Markdown
Collaborator

Also @acyment can you please rename your source branch from "main" something else (e.g. feature/swift-concurrency)? The "main" branch name conflicts with our main branch and there is a known bug in GitHub Actions that prevents workflows from running in this case due to ambiguous branch refs. I'd like to run the workflow on your PR but I'm not able to until you make that change. Thanks.

@ianhlavats
Copy link
Copy Markdown
Collaborator

I ran the tests locally. There are compilation errors and test failures introduced by this PR. It needs a lot of work.

@acyment
Copy link
Copy Markdown
Author

acyment commented Mar 17, 2026 via email

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