Skip to content

Another pile of availability checking fixes #34390

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 10 commits into from
Oct 22, 2020

Conversation

slavapestov
Copy link
Contributor

See the individual commits for details.

…leFunctionKind()

getFragileFunctionKind() would report that all initializers in
non-resilient public types were inlinable, including static
properties.

This was later patched by VarDecl::isInitExposedToClients(),
which was checked in diagnoseInlinableDeclRefAccess().
However, the latter function only looked at the innermost
DeclContexts, not all parent contexts, so it would incorrectly
diagnose code with a nested DeclContext inside of a static
property initializer.

Fix this by changing getFragileFunctionKind() to call
isInitExposedToClients() and simplifying
diagnoseInlinableDeclRefAccess().

This commit also introduces a new isLayoutExposedToClients()
method, which is similar to isInitExposedToClients(), except
it also returns 'true' if the property does not have an
initializer (and in fact the latter is implemented in terms
of the former).
There's no need to check for that here, because we also run
diagnoseDeclRefExportability() on declarations referenced
from inlinable code.

This changes some diagnostics; we now produce the same diagnostic
for references to SPI types in declaration signatures and for
references to non-type SPI declarations in inlinable function bodies.

Also note that the old inlinable reference diagnostic no longer has
to handle the 'public' and 'open' access levels, which previously
happened for '@_spi'; so I changed those entries in the %select to
%error.
…Frozen structs

We require that all stored properties in a @Frozen struct have
public or @usableFromInline types, even if the property itself
is not public. This is so that clients can correctly generate
code to manipulate the @Frozen struct.

This check was only looking for bona-fide stored properties,
and missing out looking at properties that have backing storage,
namely 'lazy' properties and property wrappers.
…attribute is allowed

We need to prohibit 'lazy' properties and property wrappers from
being declared @_spi inside of a @Frozen struct. Making them SPI
doesn't make sense, because these properties will be omitted from the
module interface and not taken into account when clients manipulate
values of this type.
…eference public types

This is the same restriction as with @Frozen structs. Even though
classes are lowered as a single reference and clients don't usually
manipulate their stored property layout directly, @Frozen classes
can have @inlinable designated initializers.
@slavapestov slavapestov marked this pull request as draft October 22, 2020 05:13
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3b16db72421667134be9eee9c676152075531912

Even if a nominal type does not have its own generic parameters,
we need to visit its conformances, because it might be defined
in a constrained extension or have a 'where' clause of its own.
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3b16db72421667134be9eee9c676152075531912

In @Frozen structs, stored properties and property wrappers must
have inlinable initial value expressions, since they are re-emitted
into designated initializer bodies, which themselves might be
@inlinable.

However, 'lazy' properties don't follow this pattern; the
initial value expression is emitted inside the getter, which
is never @inlinable.
@slavapestov slavapestov force-pushed the misc-availability-fixes branch from 3b16db7 to 8af4405 Compare October 22, 2020 06:14
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov marked this pull request as ready for review October 22, 2020 06:17
@slavapestov slavapestov requested a review from xymus October 22, 2020 06:17
@slavapestov slavapestov merged commit fe89764 into swiftlang:main Oct 22, 2020
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.

2 participants