Refactored GlobalActorIsolation type#15
Conversation
WalkthroughThis PR renames several public APIs, adjusts access-control and global-actor isolation derivation, updates enum associated labels, and aligns tests. Key updates include switching to inlinableAccessControlLevel, adopting explicitGlobalActorIsolation, exposing inheritedGlobalActorAttribute, and standardizing on trimmedType across type-builder contexts. Changes
Sequence Diagram(s)sequenceDiagram
actor Client
participant DeclBuilder
participant Settings as DeclBuilderSettings
participant Modifiers as WithModifiersSyntax
participant Isolation as GlobalActorIsolation
Client->>DeclBuilder: build(...)
DeclBuilder->>Settings: read explicitGlobalActorIsolation
alt explicit set
DeclBuilder->>Isolation: use explicit isolation
else not set
DeclBuilder->>DeclBuilder: derive from basicDeclaration.globalActor
DeclBuilder->>Isolation: .isolated(trimmedType: ...)
end
DeclBuilder->>Modifiers: inlinableAccessControlLevel(inheritedBy:maxAllowed:)
Modifiers-->>DeclBuilder: TokenSyntax?
Isolation-->>DeclBuilder: inlinableAttribute?
DeclBuilder-->>Client: built declaration + attributes/modifiers
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
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. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift (1)
14-22: Public API rename is fine; consider adding deprecated shims for smoother migrationRenaming to
explicitGlobalActorIsolationis clearer. Since this is a public surface, consider temporary deprecated aliases to reduce churn for downstream users.Add a deprecated passthrough property and initializer:
// Inside DeclBuilderSettings @available(*, deprecated, message: "Use explicitGlobalActorIsolation instead.") public var preferredGlobalActorIsolation: GlobalActorIsolation? { get { explicitGlobalActorIsolation } set { explicitGlobalActorIsolation = newValue } } @available(*, deprecated, message: "Use init(accessControlLevel:explicitGlobalActorIsolation:) instead.") public init( accessControlLevel: AccessControlLevel, preferredGlobalActorIsolation: GlobalActorIsolation? ) { self.init( accessControlLevel: accessControlLevel, explicitGlobalActorIsolation: preferredGlobalActorIsolation ) }Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilder.swift (2)
36-37: Drop redundant TypeSyntax wrapping.
extendedType.trimmedis already aTypeSyntax. The extraTypeSyntax(...)construction is unnecessary.- .extension(trimmedType: TypeSyntax(extendedType.trimmed)), + .extension(trimmedType: extendedType.trimmed),
25-32: Avoid shadowingtrimmedTypebinding in the switchIn the
switchoverTypeDeclBuilderContext.current, the pattern nametrimmedTypeshadows the surrounding property, which can be confusing. Consider renaming the bound value for clarity:• File: Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilder.swift
Lines: 25–32Suggested change:
- case let .extension(trimmedType): - trimmedType + case let .extension(trimmedType: t): + tSources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (1)
21-27: Good switch to inlinableAccessControlLevel; avoid local shadowing of settings.Logic change is correct. Minor readability nit:
let settings = settings.accessControlLevelshadows the property name.- let settings = settings.accessControlLevel + let aclSettings = settings.accessControlLevel return basicDeclaration.inlinableAccessControlLevel( - inheritedBy: settings.inheritingDeclaration, - maxAllowed: settings.maxAllowed + inheritedBy: aclSettings.inheritingDeclaration, + maxAllowed: aclSettings.maxAllowed )
📜 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.
📒 Files selected for processing (7)
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift(1 hunks)Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift(1 hunks)Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilder.swift(1 hunks)Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilderContext.swift(1 hunks)Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift(1 hunks)Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift(1 hunks)Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (6)
Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (3)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
nonisolated(11-15)Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (1)
globalActorIsolationPreference(67-85)Sources/PrincipleMacros/Syntax/Extensions/WithAttributesSyntax.swift (1)
globalActor(11-18)
Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilderContext.swift (4)
Sources/PrincipleMacros/Builders/Declarations/Types/EnumDeclBuilder.swift (1)
typeDeclaration(16-21)Sources/PrincipleMacros/Builders/Declarations/Types/StatefulDeclBuilder.swift (1)
typeDeclaration(16-21)Sources/PrincipleMacros/Syntax/Custom/StatefulDeclSyntax.swift (2)
extension StructDeclSyntax: StatefulDeclSyntax {}(14-14)extension ClassDeclSyntax: StatefulDeclSyntax {}(13-13)Sources/PrincipleMacros/Builders/Declarations/Types/ClassDeclBuilder.swift (1)
typeDeclaration(16-21)
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift (2)
Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (1)
globalActorIsolationPreference(67-85)Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
nonisolated(11-15)
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (3)
Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift (1)
inlinableAccessControlLevel(46-73)Sources/PrincipleMacros/Syntax/Extensions/WithAttributesSyntax.swift (1)
globalActor(11-18)Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
nonisolated(11-15)
Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilder.swift (4)
Sources/PrincipleMacros/Syntax/Extensions/TypeSyntax.swift (2)
standardized(65-74)standardized(18-35)Sources/PrincipleMacros/Builders/Declarations/Types/ClassDeclBuilder.swift (1)
typeDeclaration(16-21)Sources/PrincipleMacros/Builders/Declarations/Types/StatefulDeclBuilder.swift (1)
typeDeclaration(16-21)Sources/PrincipleMacros/Builders/Declarations/Types/EnumDeclBuilder.swift (1)
typeDeclaration(16-21)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift (4)
Sources/PrincipleMacros/Syntax/Extensions/WithAttributesSyntax.swift (1)
globalActor(11-18)Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
nonisolated(11-15)Sources/PrincipleMacros/Syntax/Extensions/SyntaxProtocol.swift (1)
withTrailingSpace(11-36)Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (1)
globalActorIsolationPreference(67-85)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build-and-test (macos)
🔇 Additional comments (6)
Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilderContext.swift (1)
14-14: All.extensioncases now usetrimmedType:– no unlabeled.extension(usages were found.Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift (1)
25-31: LGTM:inlinableAttributereturns a spaced attribute ready for inliningConstructing
AttributeSyntaxfrom the trimmed type and appending a trailing space aligns with the “inlinable” usage elsewhere.Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (1)
100-104: LGTM: assertion now validates the type-based isolation directlyComparing
trimmedType?.descriptionto the expected isolation string aligns the test with the new type-centric API.Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift (1)
46-73: All references toaccessControlLevel(inheritedBy:)have been updated
A repo-wide search foraccessControlLevel((excluding tests) only matched the local helpers and property accessors inWithModifiersSyntax.swift. There are no external call sites that need renaming.Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (2)
32-41: Global-actor derivation logic reads correctly.Explicit isolation takes precedence, and fallback derives from the declaration attribute using a trimmed type. This is consistent with the new
.isolated(trimmedType:)API.
42-44: Confirm intent to expose inheritedGlobalActorAttribute as public API.New public surface area can affect semver. If this is only used internally (or for tests), consider lowering visibility; otherwise, adding a brief doc comment about when it returns nil would help consumers.
Do you want this property to be part of the public API? If not, I can provide a patch to make it
internaland add doc comments.
| public var trimmedType: TypeSyntax? { | ||
| switch self { | ||
| case let .isolated(type): | ||
| type | ||
| case let .isolated(trimmedType): | ||
| trimmedType | ||
| case .nonisolated: | ||
| nil | ||
| } | ||
| } |
There was a problem hiding this comment.
Bug: missing return statements in switch within computed property
The switch inside trimmedType omits return in each case and will not compile. Add explicit returns or rewrite without switch.
Apply one of the following:
Option A (minimal change):
public var trimmedType: TypeSyntax? {
switch self {
- case let .isolated(trimmedType):
- trimmedType
+ case let .isolated(trimmedType):
+ return trimmedType
case .nonisolated:
- nil
+ return nil
}
}Option B (more concise):
- public var trimmedType: TypeSyntax? {
- switch self {
- case let .isolated(trimmedType):
- trimmedType
- case .nonisolated:
- nil
- }
- }
+ public var trimmedType: TypeSyntax? {
+ if case let .isolated(trimmedType) = self {
+ return trimmedType
+ }
+ return nil
+ }🤖 Prompt for AI Agents
In Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift around
lines 16 to 23, the computed property trimmedType uses a switch where each case
lacks an explicit return causing a compile error; fix by either adding explicit
returns (e.g., return trimmedType and return nil) in each case, or replace the
switch with a concise expression (for example use if case let .isolated(t) =
self { return t } else { return nil } or a single-line computed return using a
pattern match) so the property returns a TypeSyntax? value.
Summary by CodeRabbit
New Features
Refactor
Tests