Skip to content

Conversation

@NSFatalError
Copy link
Owner

@NSFatalError NSFatalError commented Aug 18, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a unified GlobalActorIsolation type to represent nonisolated or isolated contexts and expose the corresponding attribute when present.
  • Refactor

    • Replaced the previous preference enum with the new unified isolation type and renamed the configuration to a "preferred" isolation value.
    • Isolation is now derived from declarations when available, otherwise defaults to nonisolated.
  • Tests

    • Updated tests to match the new API shape and assertion style for isolation handling.

@NSFatalError NSFatalError self-assigned this Aug 18, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 18, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Public API refactor replaces GlobalActorIsolationPreference with GlobalActorIsolation, updates settings and extractor APIs and DeclBuilder to use the new type, adds a GlobalActorIsolation helper, removes the old preference helper, and updates tests to the new API and value shape.

Changes

Cohort / File(s) Summary
Global actor isolation model
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift, .../GlobalActorIsolationPreference.swift
Added GlobalActorIsolation enum (cases: nonisolated, isolated(trimmedType: TypeSyntax)) with trimmedType and trimmedAttribute accessors; removed GlobalActorIsolationPreference.
Builders update
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift, Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift
DeclBuilder.inheritedGlobalActorIsolation now returns GlobalActorIsolation? and selects settings.preferredGlobalActorIsolation or infers from declaration, defaulting to .nonisolated; settings property and initializer parameter renamed to preferredGlobalActorIsolation: GlobalActorIsolation?.
Parameter extraction
Sources/PrincipleMacros/Parameters/ParameterExtractor.swift
globalActorIsolationPreference(withLabel:) renamed to preferredGlobalActorIsolation(withLabel:) and now returns GlobalActorIsolation?; extraction updated to construct .isolated(trimmedType: ...) from member access base.
Tests
Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift
Tests renamed and updated to call preferredGlobalActorIsolation(...) and assert using attribute/description (@<isolation>) rather than previous enum shape; some assertions simplified to inline literals.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant DeclBuilder
  participant Settings
  participant Declaration

  Client->>DeclBuilder: request inheritedGlobalActorIsolation
  DeclBuilder->>Settings: read preferredGlobalActorIsolation?
  alt preferred provided
    Settings-->>DeclBuilder: GlobalActorIsolation
    DeclBuilder-->>Client: return preferred isolation
  else not provided
    DeclBuilder->>Declaration: read basicDeclaration.globalActor?
    Declaration-->>DeclBuilder: Attribute/TypeSyntax?
    alt inferred type present
      DeclBuilder-->>Client: .isolated(trimmedType)
    else none
      DeclBuilder-->>Client: .nonisolated
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Added global actor preference extraction #12 — Modifies the same global-actor isolation extraction surfaces (DeclBuilderSettings, ParameterExtractor, helper types); appears to be an earlier/related refactor.
  • Docs #4 — Updates ParameterExtractor tests and API surface; closely related to the test and extractor changes here.

Poem

I hop through code with joyful paws,
Replacing prefs with clearer laws.
New enum, new scent, old file gone,
I nudge the builder at the dawn.
With @-bright whiskers, syntax sings — hooray! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8ccc03f and ba58f2d.

📒 Files selected for processing (3)
  • Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (1 hunks)
  • Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (2 hunks)
  • Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/global-actor-isolation-refactor

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Aug 18, 2025

Codecov Report

❌ Patch coverage is 72.22222% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ros/Builders/Declarations/Common/DeclBuilder.swift 0.00% 7 Missing ⚠️
...leMacros/Syntax/Helpers/GlobalActorIsolation.swift 85.71% 2 Missing ⚠️
...ders/Declarations/Common/DeclBuilderSettings.swift 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift (1)

25-30: Confirm AttributeSyntax convenience initializer availability across your SwiftSyntax version

Using AttributeSyntax(attributeName:) is concise, but availability varies across SwiftSyntax versions. If you target multiple toolchains, consider the explicit initializer to guarantee the “@” is present.

If you run into availability issues, this explicit form is robust:

-        return AttributeSyntax(attributeName: type)
+        return AttributeSyntax(
+            atSign: .atSignToken(),
+            attributeName: type
+        )

Sanity-check that the printed form matches expectations (e.g., “@mainactor”), which your tests already assert against.

Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (1)

29-37: Effective isolation is never nil; consider making the type non-optional

The property always returns a value (.nonisolated at minimum). Exposing it as GlobalActorIsolation instead of GlobalActorIsolation? would simplify call sites and avoid optional chaining. If keeping optional for API continuity is intentional, no action needed.

Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (1)

67-85: Extraction logic looks solid; minor robustness note on TypeSyntax creation

The .self gate and base extraction are correct. Building TypeSyntax via string interpolation works well in SwiftSyntax’s DSL, but it silently depends on description round-tripping. If you ever need stricter guarantees, consider parsing the base into a TypeSyntax via TypeSyntax("(raw: ...)") (explicit raw interpolation) to avoid accidental trivia changes.

Example (no behavior change, just explicit intent):

-            return .isolated("\(globalActor)")
+            return .isolated("\(raw: globalActor)")
Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (1)

100-104: Attribute-based verification for isolated cases is appropriate

Asserting on attribute?.description matches the new API surface neatly. Consider adding a case for a nested type referencing Self.SomeActor.self to guard against potential base-resolution regressions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8eccf67 and 8ccc03f.

📒 Files selected for processing (6)
  • Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (1 hunks)
  • Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift (1 hunks)
  • Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (2 hunks)
  • Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift (1 hunks)
  • Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (0 hunks)
  • Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (3 hunks)
💤 Files with no reviewable changes (1)
  • Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift
🧰 Additional context used
🧬 Code Graph Analysis (4)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift (4)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
  • nonisolated (11-15)
Sources/PrincipleMacros/Syntax/Extensions/WithAttributesSyntax.swift (1)
  • globalActor (11-18)
Sources/PrincipleMacros/Builders/Declarations/Types/ActorDeclBuilder.swift (1)
  • declaration (11-14)
Sources/PrincipleMacros/Syntax/Custom/TypeDeclSyntax.swift (1)
  • isFinal (30-35)
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (3)
Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (1)
  • preferredGlobalActorIsolation (67-85)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
  • nonisolated (11-15)
Sources/PrincipleMacros/Syntax/Extensions/WithAttributesSyntax.swift (1)
  • globalActor (11-18)
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift (2)
Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (1)
  • preferredGlobalActorIsolation (67-85)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
  • nonisolated (11-15)
Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (1)
Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (2)
  • trailingClosure (40-47)
  • preferredGlobalActorIsolation (67-85)
🔇 Additional comments (6)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift (1)

16-23: No Action Needed: Swift 6 Mode Is Guaranteed

The package’s Package.swift specifies // swift-tools-version: 6.0, so SE-0380 (switch-as-expression) is fully supported. You can safely keep the current implementation without adding explicit return statements.

Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift (1)

14-22: API rename and integration are coherent

The rename to preferredGlobalActorIsolation and the new type wiring are consistent with the rest of the refactor. Initializer defaults and property exposure look good.

Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (4)

49-50: Trailing-closure assertions simplified—LGTM

Comparing descriptions directly is clear and keeps the tests focused on extracted shape rather than syntax node identity.

Also applies to: 56-57


81-85: Covers missing isolation case well

Nil return when parameter is absent is validated. Good baseline.


88-92: Good check for explicit nonisolated preference

The equality against .nonisolated ensures the enum case is surfaced as intended.


107-111: Error path test remains meaningful

The unexpected syntax path is preserved; good coverage to prevent silent acceptance of “.Type”.

@NSFatalError NSFatalError merged commit 9c7315d into main Aug 18, 2025
1 of 2 checks passed
@NSFatalError NSFatalError deleted the feature/global-actor-isolation-refactor branch August 18, 2025 21:20
NSFatalError added a commit that referenced this pull request Aug 18, 2025
@coderabbitai coderabbitai bot mentioned this pull request Nov 22, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 1, 2025
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