Commit Graph

1116 Commits

Author SHA1 Message Date
Alexis Laferrière
f4d2d2a30f [Sema] Reenable access-level on imports tests 2023-03-14 09:35:24 -07:00
Allan Shortlidge
4058ad1421 AST: Improved inferred availability accuracy.
Previously, when creating availability attributes for synthesized declarations
we would identify some set of reference declarations that the synthesized
declaration should be as-available-as. The availability attributes of the
reference declarations would then be merged together to create the attributes
for the synthesized declaration. The problem with this approach is that the
reference declarations themselves may implicitly inherit availability from their
enclosing scopes, so the resulting merged attributes could be incomplete. The
fix is to walk though the enclosing scopes of the reference declarations,
merging the availability attributes found at each level.

Additionally, the merging algorithm that produces inferred availability
attributes failed to deal with conflicts between platform specific and platform
agnostic availability. Now the merging algorithm notices when platform agnostic
availability should take precedence and avoids generating conflicting platform
specific attributes.

Resolves rdar://106575142
2023-03-13 18:27:03 -07:00
Allan Shortlidge
b36b946e97 Sema: Only add implicit imports to module interface during resilience typechecking.
Previously, implicit imports were also being added to the module interface during override checking (without any diagnostic).

Additionally, correct the structure of the import which contained an extra, duplicated path component. It would be diagnosed as a scoped import and written into the interface like this:

```
import UIKit/*.UIKit*/
```

Resolves rdar://104935794
2023-03-13 11:37:59 -07:00
Allan Shortlidge
f6b1cc0134 Tests: Add a regression test for module interface printing of conditionally available property wrappers. 2023-03-12 18:02:49 -07:00
Doug Gregor
b412c6c884 [Macros] Treat FreestandingExpressionMacros as a suppressible feature
When the feature isn't available, use the older `@expression` syntax to
work around limitations of older compilers.
2023-03-09 20:33:30 -08:00
Kavon Farvardin
b78e2f58e7 Ensure all decls using move-only types are feature-guarded
rdar://106262652
2023-03-05 16:28:09 -08:00
Doug Gregor
6a9e9d6f24 Merge pull request #64116 from DougGregor/macro-escape-declared-names-printing 2023-03-05 07:42:19 -08:00
swift-ci
b15957631a Merge pull request #64059 from kavon/staging-bootstrap-with-copyable
Turn on the `Copyable` as an inferred generic constraint by default
2023-03-04 22:46:40 -08:00
Doug Gregor
1a4d6b6519 [Macros] Ensure that we escape macro declared names in printing.
Fixes an issue where we couldn't round-trip macro declared names
2023-03-04 22:41:09 -08:00
Kavon Farvardin
091d63a5c8 revise how the Copyable constraint is added
The _Copyable constraint was implemented as a marker protocol.
That protocol is part of the KnownProtocol's in the compiler.
When `ASTContext::getProtocol(KnownProtocolKind kind)` tries
to find the ProtocolDecl for Copyable, it will look in the
stdlib module (i.e., Swift module), which is where I initially
planned to put it.

That created problems initially when some regression tests
use `-parse-stdlib` failed to do that protocol lookup, which is
essential for adding the constraint (given the current implementation).

That led to believe we need to pull Copyable out of the stdlib, but that's
wrong. In fact, when building the Swift module itself, we do `-parse-stdlib`
but we also include `-module-name Swift`. This causes the _Copyable protocol
defined in the Stdlib to be correctly discovered while building the stdlib
itself (see the test case in this commit). So, the only downside of
having the Copyable protocol in the Stdlib is that `-parse-stdlib` tests
in the compiler can't use move-only types correctly, as they'll be
allowed in generic contexts. No real program would build like this.

Until I have time to do a further refactoring, this is an acceptable trade-off.

fixes rdar://104898230
2023-03-04 11:42:09 -08:00
Meghana Gupta
b262311f24 Disable access level import tests 2023-03-03 17:33:30 -08:00
swift-ci
d0f88433da Merge pull request #63822 from kavon/resilient-noncopyable
Support resilient properties of move-only type
2023-03-03 01:24:37 -08:00
Sophia Poirier
a9e5075a94 Merge pull request #64039 from sophiapoirier/pack-type-syntax-each
[Variadic Generics] type parameter pack syntax change: T... -> each T
2023-03-02 19:17:19 -08:00
Doug Gregor
4d3f1fa67b Merge pull request #64044 from DougGregor/macros-feature-flags
Clean up feature flags for macros.
2023-03-02 19:03:32 -08:00
Allan Shortlidge
5d680532c7 Merge pull request #64015 from tshortli/unavailable-actor
AST: Emit correct synthesized availability attributes for `unownedExecutor` property
2023-03-02 17:48:19 -08:00
Kavon Farvardin
410673c51f add a bunch of hopeful tests 2023-03-02 15:14:24 -08:00
Sophia Poirier
70cffb06f3 [Variadic Generics] type parameter pack syntax change: T... -> each T 2023-03-02 14:42:28 -08:00
Doug Gregor
f88d2c638f Clean up feature flags for macros.
Enable expression macros by default, and add separate feature flags for
attached and freestanding macros.
2023-03-02 14:34:59 -08:00
Alexis Laferrière
fbac54546d Merge pull request #64014 from xymus/access-level-import
[Sema] Diagnose exportability of decls limited by a non-public import
2023-03-02 10:11:15 -08:00
Allan Shortlidge
9c76e0d1bf AST: Emit correct synthesized availability attributes for unownedExecutor property.
When synthesizing a declaration and inferring its availability, the synthesized attribute should factor in unavailability of the parent declarations. This recently regressed with https://github.com/apple/swift/pull/63361. However, the previous implementation did not produce correct results, either, because the logic for merging availability attributes produced a non-sensical result when both `unavailable` and `introduced:` availability attributes were merged. For example, this was the result for the synthesized `unownedExecutor` property of an actor when the actor was marked unavailable:

```
@available(macOS, unavailable)
actor A {
  // Incorrectly synthesized availability for `unownedExecutor` which results from merging
  // the unavailability of the parent and the availability of the UnownedSerialExecutor type.
  @available(macOS, unavailable, introduced: macOS 10.15)
  @_semantics("defaultActor") nonisolated final var unownedExecutor: UnownedSerialExecutor { get }
}
```

This is fixed by omitting all version components from the synthesized attribute when the overall attribute kind is "unavailable".

Additionally, I discovered that the `concurrency_availability.swift` test case was no longer testing what it intended to test. The conformances to `Actor` for each `actor` in the test were no longer being synthesized and therefore `unownedExecutor` was not being synthesized. That was fixed by importing the `_Concurrency` module directly, which seems to be necessary because of the `-parse-stdlib` flag in the test.

Resolves rdar://106055566
2023-03-02 10:09:30 -08:00
Allan Shortlidge
e101b225ef NFC: Remove unnecessary -disable-availability-checking flags from test. 2023-03-02 10:09:29 -08:00
Alexis Laferrière
0d82ba3059 [ModuleInterface] Fixup tests about access-level on imports and dependencies 2023-03-01 14:41:11 -08:00
Alexis Laferrière
87f8650e41 Merge pull request #63974 from xymus/access-level-import-swiftinterface
[ModuleInterface] Hide non-public imports from a resilient module
2023-03-01 14:38:01 -08:00
Saleem Abdulrasool
2626f23bf5 Merge pull request #63880 from compnerd/development-vfs
stdlib: remove VS injection for Swift development
2023-03-01 09:09:55 -08:00
Alexis Laferrière
94aeb8c0ff [ModuleInterface] Hide non-public imports from a resilient module
When using access level on imports, consider non-public imports to be
implementation details not exposed to clients. As such, a client loading
a library doesn't need to load non-public transitive dependencies.

This behave like `@_implementationOnly imports` at a module-wide level,
but it is restricted to resilient modules only. An import with any
access-level in a non-resilient module remains visible to transitive
clients.
2023-03-01 00:11:59 -08:00
Artem Chikin
3ea5087e2f Add Swift compilation flags to enable Clang's validate-per-build-session module behavior
Add '-validate-clang-modules-once' and '-clang-build-session-file' corresponding to Clang's '-fmodules-validate-once-per-build-session' and '-fbuild-session-file='. Ensure they are propagated to module interface build sub-invocations.

We require these to be first-class Swift options in order to ensure they are propagated to both: ClangImporter and implicit interface build compiler sub-invocations.

Compiler portion of rdar://105982120
2023-02-28 13:19:05 -08:00
Saleem Abdulrasool
4075d706a2 stdlib: remove the dependency on the injected modules
Inject the necessary module maps and apinotes via the VFS.  This cleans
up the developer build in preparation for a secondary change to remove
this need for deployed scenarios as well.  Injecting the content via the
VFS will enable us restore the ability to work with a pristine
installation of Visual Studio, dropping the custom action for the Swift
installer, and open the pathway to per-user installation of Swift.

Thanks to @bnbarham for the help and discussion in resolving the test
issues.
2023-02-28 09:40:51 -08:00
Allan Shortlidge
f1a8740ba5 AST: Only treat @backDeployed functions as fragile on platforms with an active attribute.
Previously, typechecking and SILGen would treat a function body as fragile as long as the declaration had a `@backDeployed` attribute, regardless of the platform specified by the attribute. This was overly conservative since back deployed functions are only emitted into the client on specific platforms. Now a `@backDeployed` function can reference non-`public` declarations on the platforms it is resilient on:

```
@backDeployed(before: iOS 15)
public func foo() {
  #if os(iOS)
  // Fragile; this code may be emitted into the client.
  #else
  // Resilient; this code won't ever be exposed to clients.
  #endif
}
```

Resolves rdar://105298520
2023-02-23 10:39:42 -08:00
Allan Shortlidge
a65d2ea57b Sema: Avoid emitting fixit to prefix import with @preconcurrency in swiftinterfaces.
Resolves rdar://105711934
2023-02-22 12:53:10 -08:00
Alejandro Alonso
023c40c809 Add option to explicitly import Builtin 2023-02-16 15:23:45 -08:00
Allan Shortlidge
e7c24bd2dd Merge pull request #63701 from tshortli/main-actor-missing-on-closure-param
AST: Print the custom attributes attached to `AttributedTypeRepr`
2023-02-15 23:48:26 -08:00
Allan Shortlidge
7bfc448a30 AST: Print the custom attributes attached to AttributedTypeRepr.
This ensures that global actor attributes are included when printing a `TypeRepr` representing a global actor bound function type.

Resolves rdar://105475701
2023-02-15 18:13:52 -08:00
Allan Shortlidge
b11dcb985e Frontend: Add a rebuild diagnostic explaining why the adjacent swiftmodule was ignored.
In https://github.com/apple/swift/pull/42486 new behavior was introduced to ignore adjacent .swiftmodule files in the SDK. This behavior has caught a few people off guard so it seems like there should be diagnostics clarifying why a rebuild is occurring in this scenario.

Resolves rdar://105477473
2023-02-15 10:06:39 -08:00
Ben Barham
e15ea7ae4d Merge pull request #63403 from bnbarham/so-much-re-index
[Index] Prevent re-indexing system modules repeatedly
2023-02-11 22:40:47 -08:00
Doug Gregor
04eca73d60 [Macros] Stop parsing the ": <type>" syntax. We always require parameters 2023-02-09 22:11:23 -08:00
Ben Barham
6269643b4d [Index] Prevent re-indexing system modules repeatedly
If a module was first read using the adjacent swiftmodule and then
reloaded using the swiftinterface, we would do an up to date check on
the adjacent module but write out the unit using the swiftinterface.
This would cause the same modules to be indexed repeatedly for the first
invocation using a new SDK. On the next run we would instead raad the
swiftmodule from the cache and thus the out of date check would match
up.

The impact of this varies depending on the size of the module graph in
the initial compilation and the number of jobs started at the same time.
Each SDK dependency is re-indexed *and* reloaded, which is a drain on
both CPU and memory. Thus, if many jobs are initially started and
they're all going down this path, it can cause the system to run out of
memory very quickly.

Resolves rdar://103119964.
2023-02-09 11:49:13 -08:00
Pavel Yaskevich
8eebb5bec1 Merge pull request #63522 from xedin/revert-type-wrappers
[AST/Sema/SIL] Revert TypeWrappers feature functionality
2023-02-09 09:27:18 -08:00
Doug Gregor
85ba74b812 Introduce a separate feature to cover @freestanding(expression) 2023-02-08 11:26:14 -08:00
Pavel Yaskevich
5dded3da73 [Tests] NFC: Remove test-cases associated with TypeWrappers feature 2023-02-08 10:14:34 -08:00
Allan Shortlidge
022abe4d3b NFC: Update tests to use accepted spelling for @backDeployed. 2023-02-01 22:04:33 -08:00
Allan Shortlidge
df1750d8b7 NFC: Rename files containing tests for the @backDeployed attribute to match the approved spelling. 2023-02-01 22:04:33 -08:00
Pavel Yaskevich
7a81eb3810 Merge pull request #63274 from xedin/runtime-metadata-impl-alignment
[AST/Sema] RuntimeMetadata: Align implementation with proposal
2023-02-01 12:37:24 -08:00
Allan Shortlidge
11a55ec3a0 ModuleInterface: Coallesce @_backDeploy attributes when printed.
This should improve the readability of declarations with `@_backDeploy` attributes for multiple platforms.

Resolves rdar://104712811
2023-01-31 13:59:22 -08:00
Pavel Yaskevich
a6a726e1fb [Sema] RuntimeMetadata: Make sure that attrs on unavailable extensions always have a type 2023-01-30 21:03:07 -08:00
Pavel Yaskevich
67b74a0633 [Sema] RuntimeMetadata: Diagnose missing explicit reflection metadata attributes
Diagnose situations where a sub-class or a protocol do not have all
of the reflection metadata attributes required by a superclass.

Resolves: rdar://103990788
2023-01-30 14:14:47 -08:00
Alexis Laferrière
c285c5e2ef [ModuleInterface] Improve swift-export-as test to use the swiftinterfaces 2023-01-27 11:37:47 -08:00
Alexis Laferrière
39fb1c5f55 [ModuleInterface] Intro export-as for Swift modules
Introduce a new flag `-export-as` to specify a name used to identify the
target module in swiftinterfaces. This provides an analoguous feature
for Swift module as Clang's `export_as` feature.

In practice it should be used when a lower level module `MyKitCore` is
desired to be shown publicly as a downstream module `MyKit`. This should
be used in conjunction with `@_exported import MyKitCore` from `MyKit`
that allows clients to refer to all services as being part of `MyKit`,
while the new `-export-as MyKit` from `MyKitCore` will ensure that the
clients swiftinterfaces also use the `MyKit` name for all services.

In the current implementation, the export-as name is used in the
module's clients and not in the declarer's swiftinterface (e.g.
`MyKitCore`'s swiftinterface still uses the `MyKitCore` module name).
This way the module swiftinterface can be verified. In the future, we
may want a similar behavior for other modules in between `MyKitCore` and
`MyKit` as verifying a swiftinterface referencing `MyKit` without it
being imported would fail.

rdar://103888618
2023-01-26 14:27:31 -08:00
Doug Gregor
5a9a654adb Adopt @freestanding(expression) for all @expression macros 2023-01-25 17:07:38 -08:00
Alexis Laferrière
595654492b Merge pull request #63176 from xymus/ambiguous-fixes
[ModuleInterface] Don't alias the stdlib or builtin modules in alias module names mode
2023-01-24 08:27:34 -08:00
Allan Shortlidge
6f721ae8e0 Sema: Avoid diagnosing over-availability in swiftinterfaces.
Resolves rdar://104576016
2023-01-23 18:33:25 -08:00