Skip to content

[Sema] Don't check availability in assigned properties initializers for -check-api-availaiblity-only mode #39847

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 2 commits into from
Oct 26, 2021

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Oct 20, 2021

For a non-public property where the type is defined by an assignment, like internal var internalAssigned = NewStruct(), type-checking the type's availability is done via checking the initializer expression.

In -check-api-availaiblity-only mode, pass down a flag to not check availability in expressions for initializer expressions of such non-public properties.

To make sure this doesn't have unintended side-effects on generated code, forbid IR generation when the flag -check-api-availaiblity-only is used.

rdar://84389825


Followup to #39640.

@xymus xymus requested a review from nkcsgexi October 20, 2021 22:53
@xymus
Copy link
Contributor Author

xymus commented Oct 20, 2021

@swift-ci Please smoke test

@xymus
Copy link
Contributor Author

xymus commented Oct 20, 2021

cc @davidungar for your interest in availability issues.

This is part of the work started in #39640 that introduced a mode to check the availability of the public API only. This is to be used when we are not generating a binary but only the module files including swiftinterfaces.

@xymus xymus requested a review from davidungar October 20, 2021 23:01
@davidungar
Copy link
Contributor

Thanks for thinking of me. I haven't looked at it yet but right off the bat, it would help if the summary clarified the purpose of the PR. Is it to speed up compilation in a certain scenario? Or is it to improve type checking in some other way?

@davidungar
Copy link
Contributor

LGTM

@xymus
Copy link
Contributor Author

xymus commented Oct 21, 2021

@davidungar The -check-api-availablity-only flag toggles an availability checking mode appropriate for projects building only a module interface and no binaries. This applies to Swift only frameworks that are backported to armv7 on iOS, these archs never had support for Swift frameworks in the OS but we still want the compiler to see the (unavailable) module content when targetting these archs. For such a case, -check-api-availablity-only ends up checking only what will be in the module interface (API, SPI, inlinable code, etc.) and skip functions bodies and other internal details.

@xymus
Copy link
Contributor Author

xymus commented Oct 21, 2021

Currently some of these projects disable availability checking all together, which is very very bad. This mode should be more appropriate to their needs, raising only errors relevant to their use cases.

Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

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

Makes sense to me!

@xymus xymus force-pushed the api-avail-init-properties branch from 20be277 to 8254808 Compare October 25, 2021 20:42
xymus added 2 commits October 25, 2021 13:46
For a non-public property where the type is defined by an assignment, like
`internal var internalAssigned = NewStruct()`, type-checking the type's
availability is done via checking the initializer expression.

In -check-api-availaiblity-only mode, pass down a flag to not check
availability in expressions for initializer expressions of such
non-public properties.

rdar://84389825
@xymus xymus force-pushed the api-avail-init-properties branch from 8254808 to d2ec6b9 Compare October 25, 2021 20:47
@xymus xymus changed the title [Sema] Skip type-checking initializer of non-public properties in -check-api-availaiblity-only mode [Sema] Don't check availability in assigned properties initializers for -check-api-availaiblity-only mode Oct 25, 2021
@xymus
Copy link
Contributor Author

xymus commented Oct 25, 2021

This is a different implementation. Skipping the whole type checking lead to errors at serialization as skipping function bodies doesn't skip property initialization.

Instead, let's pass down a flag to disable availability checking in expression when type-checking the property initializer.

@swift-ci Please smoke test

@xymus
Copy link
Contributor Author

xymus commented Oct 25, 2021

@swift-ci Please smoke test Linux

@xymus xymus merged commit bc15343 into swiftlang:main Oct 26, 2021
@xymus xymus deleted the api-avail-init-properties branch October 26, 2021 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants