Commit Graph

57 Commits

Author SHA1 Message Date
Alexis Laferrière
758351110a [Sema] Allow the use of SPI in API for SPI modules
When the whole module has an SPI distribution, SPI declarations can be
used in API.

rdar://75335462
2021-04-20 15:02:51 -07:00
Doug Gregor
b5e4b085aa Infer ConcurrentValue conformances for structs and enums.
When a struct or enum has only ConcurrentValue-conforming instance
data, infer conformance to ConcurrentValue.
2021-03-02 00:23:33 -08:00
Arnold Schwaighofer
cf2177f5a4 Fix test case 2021-02-12 11:26:42 -08:00
Arnold Schwaighofer
084db0d38f Revert "Merge pull request #34848 from aschwaighofer/make_prespecialization_experimental"
This reverts commit 3aec862e62, reversing
changes made to 158427bd5b.
2021-02-12 10:12:01 -08:00
Alexis Laferrière
da6c325365 Fix unchecked access to SPI decls from indirect clients
rdar://70502938
2021-02-10 12:33:14 -08:00
Alexis Laferrière
c76269ec1a [ModuleInterface] Preserve SPI information for indirect conformances
rdar://73082943
2021-01-26 15:28:27 -08:00
Alexis Laferrière
05534f13e0 [Sema] Reword the warning on @_spi import of a public module 2020-12-01 13:26:44 -08:00
Alexis Laferrière
aa865387fd [Sema] Warn on @_spi imports of modules built from their public interface
This warning should help understand missing SPI diagnostics when the
compiler loads a public module when a private one is expected.

rdar://71859081
2020-12-01 11:27:45 -08:00
Arnold Schwaighofer
8346bf7e90 Pre-specialization: This is an experimental feature
Only enable if explicitly required.
2020-11-20 09:13:16 -08:00
Slava Pestov
6934857417 Sema: Tweak associated conformance exportability diagnostics
Let's point out the associated type with a separate note, so
that we can diagnose other availability failures, such as
deprecation and OS version availability.
2020-11-09 23:43:51 -05:00
Slava Pestov
8af4405f36 AST: 'lazy' property initializers are never @inlinable
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.
2020-10-22 02:13:41 -04:00
Slava Pestov
fa50221d35 Sema: Use VarDecl::isLayoutExposedToClients() when checking VarDecl exportability 2020-10-22 01:45:56 -04:00
Slava Pestov
b4c568e2d1 Sema: Use VarDecl::isLayoutExposedToClients() when checking if @_spi 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.
2020-10-22 01:11:56 -04:00
Slava Pestov
5f5372a3fc Sema: Don't check SPI violations in diagnoseInlinableDeclRefAccess()
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.
2020-10-22 01:11:46 -04:00
Slava Pestov
a824e5a33b Sema: Refactor getDisallowedOriginKind() to take an ExportContext
Converting the innermost DeclContext into a Decl won't work if
the innermost DeclContext is the parent context of a VarDecl.

Instead, use the relevant bit of state from the ExportContext,
which is computed correctly.

This fixes a regression caused by an earlier commit in this PR
which our test suite did not catch.
2020-10-20 01:02:31 -04:00
Slava Pestov
f48aa51884 Sema: Remove ExportabilityChecker
Availability checking already knows how to check exportability for
types and conformances referenced from inlinable function signatures
and bodies.

Let's generalize this to work on non-inlinable function signatures
as well, allowing us to get rid of the ExportabilityChecker altogether.
2020-10-20 01:00:43 -04:00
Slava Pestov
94e999a1b5 Sema: Pull availability checking out of resolveType()
We used to diagnose references to unavailable declarations in
two places:

- inside Exprs, right after type checking the expression
- inside TypeReprs, from resolveType()

In broad terms, resolveType() is called with TypeReprs
stored inside both Stmts and Decls.

To handle the first case, I added a new overload of
diagAvailability() that takes a Stmt, to be called from
typeCheckStmt(). This doesn't actually walk into any Exprs
stored inside the statement; this means it only walks
Patterns and such.

For the second case, a new DeclAvailabilityChecker is
now defined in TypeCheckAccess.cpp. It's structure is
analogous to the other three walkers there:

- AccessControlChecker
- UsableFromInlineChecker
- ExportabilityChecker

The new implementation of availability checking for types
introduces a lot more code than the old online logic
it replaces. However, I hope to consolidate some of the
code duplication among the four checkers that are defined
in TypeCheckAccess.cpp, and do some other cleanups that
will make the benefit of the new approach apparent.
2020-10-14 23:42:02 -04:00
Arnold Schwaighofer
2a2cf91dcd Add support for marking a _specialize attribute as SPI
```
  @_specialize(exported: true, spi: SPIGroupName, where T == Int)
  public func myFunc() { }
```

The specialized entry point is only visible for modules that import
using `_spi(SPIGroupName) import ModuleDefiningMyFunc `.

rdar://64993425
2020-10-12 09:19:29 -07:00
Alexis Laferrière
357bf8fb3a [Sema] Test the interfaces generated by SPI/private_swiftinterface.swift 2020-09-16 11:20:59 -07:00
Alexis Laferrière
c133693ac6 [Sema] Accept more use of @_spi as it can be generated in swiftinterface 2020-09-16 11:20:59 -07:00
Alexis Laferrière
dac3922090 [Sema] Accept use of SPI in inlinable SPI declarations
rdar://63978500
rdar://63189125
2020-09-16 11:20:56 -07:00
Alexis Laferrière
cbb7228451 [Sema] Evaluate SPI groups for all decls, not only public ones
Remove the fast path skipping evaluating SPI groups for non-public
decls. This knowledge is still required to allow the use of SPI types in
the signatures of `@usableFromInline` declarations and in internal
properties of structs in non library evolution compilation.

rdar://68530659
rdar://68527580
2020-09-08 16:58:45 -07:00
Alexis Laferrière
3acbd0917e [Sema] Type-check exportability of SPI conformances
Report the use of conformances declared as SPI in public declarations
and inlinable code.

rdar://problem/66659715
2020-09-01 11:11:26 -07:00
Alexis Laferrière
bfe74f53cd [ModuleInterface] Only skip extensions without public members
Additionnal restrictions to still print some extensions to
implementation-only imported types if marked SPI.
2020-08-21 15:18:26 -07:00
Alexis Laferrière
fd78da5137 [ModuleInterface] Don't print extensions to implementation-only imported types
Extensions to implementation-only types are accepted at type-checking
only if they don't define any public members. However if they declared a
conformance to a public type they were also printed in the
swiftinterface, making it unparsable because of an unknown type.

Still accept such extensions but don't print them.

rdar://problem/67516588
2020-08-20 17:12:31 -07:00
Alexis Laferrière
73252e8bf4 [Sema] Only warn when exporting implementation-only types in SPI
Downgrade to a warning the diagnostics on the use of an
implemenetation-only type in SPI to allow support for
-experimental-spi-imports.
2020-07-30 09:20:13 -07:00
Alexis Laferrière
0cce54954a [ModuleInterface] Print some implementation-only imports in the private interface
Print implementation-only imports in the private textual interface
only if also importing SPI. This allows to export types from
implementation-only imports in SPI and brings the private textual
interfaces in line with the binary interfaces.

This is a temporary solution as we need to better design the language
feature around this.

This feature requires passing -experimental-spi-imports to the frontend
that generates the private swiftinterface file.
2020-07-30 09:20:12 -07:00
Alexis Laferrière
930c8f2208 Merge pull request #32910 from xymus/spi-property-wrappers-storage
[Sema] SPI groups on a wrapped property propagates to the backing storage
2020-07-16 18:02:29 -07:00
Alexis Laferrière
47e4e29362 [Sema] SPI info on a wrapped property should propagate to the backing storage 2020-07-16 14:47:28 -07:00
Alexis Laferrière
28799e61a1 Merge pull request #32793 from xymus/spi-req-in-spi-proto
[Sema] Only require a default implementation for SPI requirements in non-SPI protocols
2020-07-14 17:00:07 -07:00
Alexis Laferrière
d70b0c9249 [Sema] SPI requirements in SPI protocols don't need a default implementation
The check for SPI protocol requirements needing a default implementation
should ignore requirements in a protocol that is SPI too. The protocol
can’t be conformed to without knowing of the requirement.

rdar://65286171
2020-07-13 16:11:02 -07:00
Alexis Laferrière
ba2455a17c [Sema] Add test case for SPI requirements on name vs type 2020-07-13 16:11:02 -07:00
Alexis Laferrière
5be252a8b3 [Sema] Move the check for SPI protocol requirements to existing logic
Asides from removing duplicated code this change also now checks implicit SPI
requirements and applies only in library evolution mode.
2020-07-13 16:00:34 -07:00
Alexis Laferrière
4d2d0548e7 [ModuleInterface] Fix test for SPI attributes on unsupported decls 2020-07-10 08:42:19 -07:00
Alexis Laferrière
de2774799e Merge pull request #32211 from xymus/fix-invalid-spi-attr
[ModuleInterface] Don't print SPI attributes on unsupported decls
2020-07-09 13:04:15 -07:00
Hamish Knight
751e68177c [test] Remove uses of -sil-merge-partial-modules
Replace with -merge-modules, which means we can
also remove the now redundant
`-disable-diagnostic-passes` &
`-disable-sil-perf-optzns` options.
2020-07-01 23:14:50 -07:00
Alexis Laferrière
63d9acda3e [Sema] Report public use of local SPIs by the exportability checker
This change improves slightly the quality of the diagnostics and detects
the use of local SPI types on public property with a default value.
2020-06-29 11:18:04 -07:00
Alexis Laferrière
ead9bc3ce3 [ModuleInterface] Don't print SPI attributes on unsupported decls
When emitting the private swiftinterface, the compiler prints the
attribute explicitly even when it is deduced from the context. This can
lead to unparsable private swiftinterface files.

As a narrow fix, check if the decl type is supported before printing the
attribute.

rdar://64039069
2020-06-05 12:25:43 -07:00
Alexis Laferrière
21bf781067 Merge pull request #32049 from xymus/spi-unique-imports
[ModuleInterface] Print the SPI attribute only once per group and import
2020-06-01 11:24:21 -07:00
Alexis Laferrière
8fefdece2c Use a SetVector when looking up the SPI attributes on imports
Using a SetVector fixes an issue where many source files imported the
same SPI group from the same module, the emitted private textual
interfaces superfluously repeated the `@_spi` attribute on the import.

rdar://problem/63681845
2020-05-27 16:11:12 -07:00
Alexis Laferrière
6bead5c436 [Parse] Fix source range of SPI attributes
rdar://problem/63554849
2020-05-26 12:56:36 -07:00
Alexis Laferrière
aa0f555cde No dummy constraint in the public swiftinterface for SPI extensions
rdar://problem/63352700
2020-05-19 13:13:59 -07:00
Alexis Laferrière
4c4724cdce Merge pull request #31744 from xymus/dont-leak-ioi-in-spi
[Sema] Forbid leaking implementation-only imported types in SPI decls
2020-05-13 11:14:27 -07:00
Alexis Laferrière
08abc0dbec [Sema] Fix leak of implementation-only imported types in SPI signatures 2020-05-12 16:54:38 -07:00
Alexis Laferrière
d004f8403c [Sema] Forbid stored property marked SPI in frozen structs 2020-05-12 13:37:34 -07:00
Alexis Laferrière
5210dcb509 [Sema] An SPI protocol requirement must have a default implementation 2020-05-12 13:37:34 -07:00
Alexis Laferrière
f46542f0e4 Merge pull request #31591 from xymus/spi-equatable
Allow SPI access within the same module in checkAccess
2020-05-08 11:29:12 -07:00
Alexis Laferrière
4fcebd1256 Allow SPI access within the same module in checkAccess
rdar://problem/61043406
rdar://problem/61987739
2020-05-06 11:19:44 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Alexis Laferrière
2b5fc3a8d7 [SPI Test] Test how modules can expose imported SPI through their SPI 2020-03-04 16:43:05 -08:00