-
Notifications
You must be signed in to change notification settings - Fork 342
Add support for availability-style features #10098
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
Conversation
#9815 has the codegen and serialization changes. |
clang/lib/Parse/ParseExpr.cpp
Outdated
@@ -3999,6 +4008,23 @@ std::optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() { | |||
Actions.CodeCompletion().CodeCompleteAvailabilityPlatformName(); | |||
return std::nullopt; | |||
} | |||
|
|||
if (Tok.is(tok::identifier) && GetLookAheadToken(1).is(tok::equal)) { |
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.
suggest: tok::colon
instead of tok:equal
, so it matches the feat: <feature>
style ones
clang/include/clang/Sema/ScopeInfo.h
Outdated
ObjCShouldCallSuper(false), ObjCIsDesignatedInit(false), | ||
ObjCWarnForNoDesignatedInitChain(false), ObjCIsSecondaryInit(false), | ||
ObjCWarnForNoInitDelegation(false), NeedsCoroutineSuspends(true), | ||
FoundImmediateEscalatingExpression(false), ErrorTrap(Diag) {} |
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.
suggest to not clang-format this after adding the new line, so we reduce the downstream diff.
clang/lib/AST/ASTContext.cpp
Outdated
} | ||
|
||
bool ASTContext::hasUnavailableFeature(const Decl *D) const { | ||
if (D->hasAttrs()) |
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.
nitpick: using early exist instead of nesting the for loop inside the if check.
@@ -3539,6 +3539,10 @@ def fno_builtin : Flag<["-"], "fno-builtin">, Group<f_Group>, | |||
def fno_builtin_ : Joined<["-"], "fno-builtin-">, Group<f_Group>, | |||
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, | |||
HelpText<"Disable implicit builtin knowledge of a specific function">; | |||
def ffeature_availability_EQ : Joined<["-"], "ffeature-availability=">, Group<f_Group>, |
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.
Silly question: why do we need this flag if all the features are defined in a header?
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.
I added this flag for testing purposes before we decided on the availability domain definition spec. I can remove it as it's not needed anymore. I left it in as I thought it could be handy when testing or debugging the feature.
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.
Thanks for the explanation! this matches with what I thought.
@tshortli I added an API for retrieving the information about availability domain on a decl. 81991a7 The function returns a pair of feature name and |
It's still possible to get the |
Yes, that looks reasonable. Thanks! |
95fa011
to
6d736cf
Compare
This commit extends the `__availability` attribute to accept a feature name and a boolean-like integer argument (0 or 1) to indicate availability based on feature presence or absence. `__builtin_available` and `@available` take a feature name as their arguments. References to annotated declarations in unguarded contexts are rejected. For example: ``` __attribute__((availability(domain:feature1, 0))) void available_func(void); __attribute__((availability(domain:feature1, 1))) void unavailable_func(void); if (__builtin_available(feature1)) { available_func(); unavailable_func(); // error } else { available_func(); // error unavailable_func(); } ``` rdar://137999979
6d736cf
to
b53735b
Compare
This patch doesn't include the codegen and serialization changes that are needed to support the availability-style features.
rdar://137999979