-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AST] Add a new attribute @hasAsyncAlternative #36027
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -387,6 +387,9 @@ namespace swift { | |
ASTVerifierOverrideKind ASTVerifierOverride = | ||
ASTVerifierOverrideKind::NoOverride; | ||
|
||
/// Allow @hasAsyncAlternative attribute | ||
bool EnableExperimentalHasAsyncAlternative = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need a flag for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, wasn't sure whether it being behind concurrency only was okay :). Good to know! |
||
|
||
/// Sets the target we are building for and updates platform conditions | ||
/// to match. | ||
/// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// REQUIRES: concurrency | ||
|
||
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -experimental-has-async-alternative-attribute | ||
|
||
@hasAsyncAlternative | ||
func func1() {} | ||
|
||
@hasAsyncAlternative("betterFunc") | ||
func func2() {} | ||
|
||
@hasAsyncAlternative("betterFunc(param:)") | ||
func func3() {} | ||
|
||
@hasAsyncAlternative("not+identifier") // expected-error {{argument of 'hasAsyncAlternative' attribute must be an identifier or full function name}} | ||
func func4() {} | ||
|
||
@hasAsyncAlternative("$dollarname") // expected-error {{argument of 'hasAsyncAlternative' attribute must be an identifier or full function name}} | ||
func func5() {} | ||
|
||
@hasAsyncAlternative("TypePrefix.func") // expected-error {{argument of 'hasAsyncAlternative' attribute must be an identifier or full function name}} | ||
func func6() {} | ||
|
||
@hasAsyncAlternative("interpreted \()") // expected-error {{argument of 'hasAsyncAlternative' cannot be an interpolated string literal}} | ||
func func7() {} | ||
|
||
@hasAsyncAlternative("missingRParen" // expected-error {{expected ')' in 'hasAsyncAlternative' attribute}} | ||
func func8() {} | ||
|
||
@hasAsyncAlternative // expected-note {{attribute already specified here}} | ||
@hasAsyncAlternative("other") // expected-error {{duplicate attribute}} | ||
func duplicate() {} | ||
|
||
@hasAsyncAlternative // expected-error {{'@hasAsyncAlternative' attribute cannot be applied to this declaration}} | ||
protocol SomeProto { | ||
@hasAsyncAlternative | ||
func protoFunc() | ||
} | ||
|
||
@hasAsyncAlternative // expected-error {{'@hasAsyncAlternative' attribute cannot be applied to this declaration}} | ||
struct SomeStruct: SomeProto { | ||
func protoFunc() { } | ||
|
||
@hasAsyncAlternative | ||
func structFunc() { } | ||
|
||
@hasAsyncAlternative | ||
static func staticStructFunc() { } | ||
} | ||
|
||
@hasAsyncAlternative // expected-error {{'@hasAsyncAlternative' attribute cannot be applied to this declaration}} | ||
class SomeClass: SomeProto { | ||
func protoFunc() { } | ||
|
||
@hasAsyncAlternative | ||
func classFunc() { } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// RUN: %target-typecheck-verify-swift | ||
|
||
@hasAsyncAlternative // expected-error {{'hasAsyncAlternative' attribute is only valid when experimental concurrency is enabled}} | ||
func func1() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// REQUIRES: concurrency | ||
|
||
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency | ||
|
||
@hasAsyncAlternative // expected-error {{'hasAsyncAlternative' support is required to be explicitly enabled using -experimental-has-async-alternative-attribute}} | ||
func func1() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll want type checking to resolve this to a Decl*, and serialization to serialize the Decl reference rather than the name (so clients don't have to resolve the Decl again).