Skip to content
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

Fix __isOSVersionAtLeast for Android #80496

Conversation

jooyunghan
Copy link
Contributor

Allow pre-release APIs on pre-release devices.

The current implementation requires ANDROID_API_FUTURE to use new APIs on pre-release system. This makes it hard to maintain the codebase because it should be switched a concrete version (e.g. ANDROID_API_X on release of X).

Instead, we can just allow pre-release APIs on pre-release system without mandating the major version of ANDROID_API_FUTURE.

Note that this doesn't make API guards just no-op in pre-release builds. We can still rely on its compile-time checks and it still works as expected with release builds. Even with pre-release builds, it's the same as before because we would pass ANDROID_API_FUTURE to make the calls anyway.

Allow pre-release APIs on pre-release devices.

The current implementation requires __ANDROID_API_FUTURE__ to use new APIs on pre-release system. This makes it hard to maintain the codebase because it should be switched a concrete version (e.g. __ANDROID_API_X__ on release of X).

Instead, we can just allow pre-release APIs on pre-release system without mandating the major version of __ANDROID_API_FUTURE__.

Note that this doesn't make API guards just no-op in pre-release builds. We can still rely on its compile-time checks and it still works as expected with release builds. Even with pre-release builds, it's the same as before because we would pass __ANDROID_API_FUTURE__ to make the calls anyway.
Copy link

github-actions bot commented Feb 2, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@DanAlbert
Copy link
Member

This will incorrectly allow APIs from version N when the build target is a preview of N-1, right?

@jooyunghan
Copy link
Contributor Author

Well, I don't think it's regression. Without the change, we'll have to guard both symbols with __builtin_available(android __ANDROID_API_FUTURE__, *), which allows both symbols.

Afaik, when there's two in-development versions, preview build doesn't need to distinguish two versions. For example, if N is a final SDK version and N+1 and N+2 are in-dev versions, a preview build should allow both N+1 and N+2 because both versions are in-development.

@DanAlbert
Copy link
Member

But a preview of N+1 won't have the N+2 APIs? __builtin_available(android N+2) when run on a preview of N+1 would pass and the call would segfault, right? That would be a regression. There's currently no correct use of __builtin_available that will cause an unavailable API to be called.

@jooyunghan
Copy link
Contributor Author

But a preview of N+1 won't have the N+2 APIs? __builtin_available(android N+2) when run on a preview of N+1 would pass and the call would segfault, right? That would be a regression.

I don't think it's a problem or regression because it's still a preview. Besides, an API for N+2 guarded with __builtin_available(android 10000) (as of today) and __builtin_available(android N+2) (as this change enables) while it's missing will show the same behavior.

@jooyunghan
Copy link
Contributor Author

Hi @DanAlbert, a friendly ping.

@DanAlbert
Copy link
Member

Right now you use __builtin_available(android 10000). That will never cause an unavailable function to be called. After this patch, you would be able to write __builtin_available(android N+2), and that would cause unavailable functions in some configurations, which would crash. __builtin_available currently protects you from calling unavailable functions. After this change it would not do that.

Is my understanding wrong, or are you saying that's not a regression?

@jooyunghan
Copy link
Contributor Author

Right now you use__builtin_available(android 10000). That will never cause an unavailable function to be called.

__builtin_available(android 10000) will be eval to true in preview build and false in release build.

After this patch, you would be able to write __builtin_available(android N+2), and that would cause unavailable functions in some configurations, which would crash.

__builtin_available(android N+2) would be eval to true in preview build and false in release build (until N+2 is finalize).

Copy link
Member

@DanAlbert DanAlbert left a comment

Choose a reason for hiding this comment

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

Discussed over IM. Not a regression because the problem I'm worried about __builtin_available returning true when it should not) already exists with an N+1 preview when using __builtin_available(android 10000). That's probably going to be something we have to deal with eventually, but I don't think we can deal with that here until the OS gives us clearer signals.

@jooyunghan
Copy link
Contributor Author

Thanks Dan for approval!

Elliott (@enh-google), do you have any concern?

@enh-google
Copy link
Contributor

"if danalbert's happy, i'm happy" --- he thinks about this stuff a lot more deeply than i do :-)

Copy link
Contributor

@enh-google enh-google left a comment

Choose a reason for hiding this comment

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

(danalbert seems convinced, so i have nothing to add...)

@jooyunghan
Copy link
Contributor Author

Hi all
Who do I need to ask for merge?

@pirama-arumuga-nainar pirama-arumuga-nainar merged commit ec516ff into llvm:main Feb 21, 2024
6 checks passed
Copy link

@jooyunghan Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants