Skip to content

[ASTGen] Generate "nonisolated" decl modifier #79468

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

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/ASTGen/Sources/ASTGen/DeclAttrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,8 @@ extension ASTGenVisitor {
return self.generateAccessControlAttr(declModifier: node, level: .public)
case .open:
return self.generateAccessControlAttr(declModifier: node, level: .open)
case .nonisolated:
return self.generateNonisolatedAttr(declModifier: node)?.asDeclAttribute
case .weak, .unowned:
return self.generateReferenceOwnershipAttr(declModifier: node)?.asDeclAttribute
default:
Expand Down Expand Up @@ -2001,6 +2003,27 @@ extension ASTGenVisitor {
}
}

func generateNonisolatedAttr(declModifier node: DeclModifierSyntax) -> BridgedNonisolatedAttr? {
let isUnsafe: Bool
switch node.detail?.detail.rawText {
case "unsafe":
isUnsafe = true
case nil:
isUnsafe = false
case let text?:
// TODO: Diagnose
_ = text
fatalError("invalid argument for nonisolated modifier")
}

return BridgedNonisolatedAttr.createParsed(
self.ctx,
atLoc: nil,
range: self.generateSourceRange(node),
isUnsafe: isUnsafe
)
}

func generateReferenceOwnershipAttr(declModifier node: DeclModifierSyntax) -> BridgedReferenceOwnershipAttr? {
// 'weak' -> .weak
// 'weak(<unexpected>)' -> .weak (with diagnostics)
Expand Down
9 changes: 9 additions & 0 deletions test/ASTGen/attrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,12 @@ struct NE : ~Escapable {}
}
@lifetime(borrow borrow) func testNameConflict(_ borrow: E) -> NE { NE() }
@lifetime(result: source) func testTarget(_ result: inout NE, _ source: consuming NE) { result = source }

actor MyActor {
nonisolated let constFlag: Bool = false
nonisolated(unsafe) var mutableFlag: Bool = false
}
func testNonIsolated(actor: MyActor) {
_ = actor.constFlag
_ = actor.mutableFlag
}