Commit Graph

1195 Commits

Author SHA1 Message Date
Doug Gregor
2fd1912f5a Simplify printing of marker protocols in Swift interfaces
Thanks to a great idea from Slava, simplify the printing of marker
protocols in Swift interfaces while maintaining backward compatibility.
For compilers that cannot handle marker protocols, print a typealias
to `Any` instead, which is a good stand-in for just about everything.
2021-02-18 22:58:19 -08:00
Becca (née Brent) Royal-Gordon
e6aee251be Merge pull request #35904 from beccadax/go-back-to-the-shadow
Warn about module name shadowing in interfaces
2021-02-16 15:32:41 -08:00
Slava Pestov
cdbba60674 AST: ASTPrinter support for 'reasync'
Part of <rdar://problem/71098795>.
2021-02-15 22:18:54 -05:00
Becca Royal-Gordon
ba3b2610b8 Shorten diagnostic and refer to bug report instead
diag::warning_module_shadowing_may_break_module_interface was *enormous* but still described the problem too tersely to convey everything that was needed. Instead, reference a bug report that describes the problem and its workarounds in more detail.
2021-02-12 17:30:47 -08:00
Doug Gregor
e8375e13ee Define a feature for @concurrent functions. 2021-02-12 16:36:12 -08:00
Becca Royal-Gordon
c2f3725f56 Warn about module name shadowing in interfaces
There is a known issue with module interfaces where a type with the same name as a module will disrupt references to types in that module. Fully fixing it will require a new language feature (SR-898) which is not yet available. In the meantime, module interfaces support a workaround flag (“-Xfrontend -module-interface-preserve-types-as-written”) which prints an alternate form that usually works. However, you have to know to add this flag, and it’s not obvious because nothing breaks until a compiler tries to consume the affected module interface (or sometimes even one of its clients).

This commit emits a warning during module interface emission whenever the module interface either imports a type with the same name as the module being built, or declares a type with the same name as a visible module. This lets the user know that the type may cause problems and they might need to implement a workaround.
2021-02-10 19:03:06 -08:00
Doug Gregor
c26c5029a5 [Actor isolation] Compute actor isolation properly even in Swift interfaces.
The check that limited inference of actor isolation meant that we were
incorrectly computing actor isolation for (e.g.) overrides when
parsing from Swift interfaces. Only limit inference for cases where we
are guaranteed to synthesize an attribute by inference.
2021-02-10 15:55:51 -08:00
Doug Gregor
43df1d8363 [Concurrency] Don't spuriously record protocols inherited by Actor. 2021-02-10 15:52:03 -08:00
Evan Wilde
8b80331c3d Updating tests to use actor
This patch updates the `actor class` spelling to `actor` in almost all
of the tests. There are places where I verify that we sanely handle
`actor` as an attribute though. These include:

 - test/decl/class/actor/basic.swift
 - test/decl/protocol/special/Actor.swift
 - test/SourceKit/CursorInfo/cursor_info_concurrency.swift
 - test/attr/attr_objc_async.swift
 - test/ModuleInterface/actor_protocol.swift
2021-02-10 08:09:13 -08:00
swift-ci
bcfafc1b07 Merge pull request #35854 from davezarzycki/pr35854 2021-02-09 13:07:51 -08:00
David Zarzycki
5a17429b25 [Testing] Add missing REQUIRES: concurrency 2021-02-09 13:26:44 -05:00
Doug Gregor
b1aa56dbd1 Clean up test comment and mark as REQUIRES: concurrency 2021-02-09 09:28:17 -08:00
Doug Gregor
643ce71a09 Peer into the types of declarations to find async/actors/etc. 2021-02-08 22:50:48 -08:00
Doug Gregor
627e4f03a3 Properly print protocols that inherit marker protocols under $MarkerProtocol 2021-02-08 22:37:13 -08:00
Doug Gregor
aa139a101c [Module interface] Use features in module interface generation.
When generating a module interface, emit `#if` around any declarations
that are tied to specific, named language features. This allows module
interfaces to be processed by older Swift compilers that do not
support these newer features, such as async/await or actors.

The amount of effort required to correctly handle a new kind of
feature varies somewhat drastically based on the feature itself. The
"simple" case is where a particular declaration can only exist if a
feature is available. For example, and `async` declaration is fairly
easy to handle; a `@_marker` protocol's conformances are not.

Fixes rdar://73326633.
2021-02-08 16:01:39 -08:00
David Zarzycki
9ab4c35e51 [Testing] Unbreak read-only source builds 2021-02-05 08:25:58 -05:00
Artem Chikin
60c562c4a8 Merge pull request #35749 from artemcm/NoExtraClangImporterArgsInSubContexts
Avoid false FileDependnecies among Implicitly-build Swift and Clang modules
2021-02-04 08:51:19 -08:00
Artem Chikin
6f3fda1369 Avoid false FileDependnecies among Implicitly-build Swift and Clang modules
`InterfaceSubContextDelegateImpl` causes sub-instances to inherit `-fmodule-map-file=` options.
Those Module Maps become file dependencies of all downstream PCMs and their depending Swift modules, even though they really aren't.
This causes frequent re-builds of the Module Cache contents when seemingly-unrelated files are touched.

Explicit Module Builds rely on these options for building Swift Interface files, so for now we just disable inheritance of these options in Implicit Module builds.
2021-02-03 16:47:46 -08:00
Alexis Laferrière
be843eda4e Merge pull request #35717 from xymus/fix-extensions-with-if-config
[ModuleInterface] Don't print extensions only for a nested #if
2021-02-02 17:14:57 -08:00
Alexis Laferrière
dd85b1dd60 [ModuleInterface] Don't print extensions for nested #if
rdar://71350414
2021-02-02 13:43:38 -08:00
Alexis Laferrière
fe4d46cea9 Merge pull request #35590 from xymus/reword-module-build-error
[ModuleInterface] Update wording of the "failed to build module" error
2021-01-26 18:52:24 -08:00
Alexis Laferrière
b79c7b627b [ModuleInterface] Update wording of the "failed to build module" error
The error shown when the compiler fails to build a module from its
textual interface has been creating some confusion. This is a proposal
to make it more useful to the programmer not working in the SDK, insist
on looking at the previous errors first, put less emphasis on possible
compiler bugs, and always show alternatives to the incompatible
compilers issue as this is the most common case now.
2021-01-26 15:36:46 -08:00
Doug Gregor
5897dbed5c Update tests for deterministic serialization/printing of members 2021-01-20 13:40:48 -08:00
Alexis Laferrière
8992d2c6b9 [Sema] Accept availability macros in @_originallyDefinedIn
Availability macros passed via the frontend flag -define-availability
should be accepted by @_originallyDefinedIn where they behave as they do
in @available.

rdar://72354787
2021-01-13 10:44:06 -08:00
David Zarzycki
e4ce4119d4 [testing] add missing REQUIRES: concurrency 2021-01-08 08:26:29 -05:00
Kavon Farvardin
a2c57d13c3 [concurrency] initial declaration of MainActor
Implementation is left as a TODO for now.

Resolves rdar://72161578
Partially resolves rdar://72105129
2021-01-06 15:01:22 -08:00
Kavon Farvardin
f76645dab1 [concurrency] global actors in reslient modules need thick metatype.
Resolves rdar://72604101
2021-01-06 15:01:22 -08:00
Xi Ge
1ba1bd93b2 PrebuiltModules: being resilient to 0-specified build number
swift-driver passes down an SDK version number with a non-existing build number as 0.
The compiler should be resilient to this so we can locate prebuilt module cache.

rdar://72230172
2020-12-11 13:50:51 -08:00
Alexis Laferrière
2ce140dfa0 [ModuleInterface] Print custom attributes on function protocol requirements
Protocol requirements declared as a function with a result-builder
custom attribute should keep that attribute in the generated textual
swiftinterface file.

rdar://72063255
2020-12-08 11:26:07 -08:00
Alexis Laferrière
92a1615dd8 [Frontend] Add import decl loc to messages from -Rmodule-loading 2020-11-20 08:08:05 -08:00
Alexis Laferrière
de42b1f2fa [Frontend] Optional remarks on loaded modules location
Passing the frontend flag -Rmodule-loading makes the compiler emit
remarks with the path of every module loaded. The path for Swift modules
is either the swiftinterface file for modules built with library
evolution or the binary swiftmodule otherwise. The path for clangmodules
is always in the cache which could be improved as it may be less useful.

Here's an extract of the output for a simple SwiftUI app:

<unknown>:0: remark: loaded module from
/Users/xymus/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/2VJP7CNCGWRF0/SwiftShims-18ZF6992O9H75.pcm
<unknown>:0: remark: loaded module from
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk/usr/lib/swift/Swift.swiftmodule/x86_64-apple-ios-simulator.swiftinterface
<unknown>:0: remark: loaded module from
/Users/xymus/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/2VJP7CNCGWRF0/os-1HVC6DNXVU37C.pcm
<unknown>:0: remark: loaded module from
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk/usr/lib/swift/os.swiftmodule/x86_64-apple-ios-simulator.swiftinterface
<unknown>:0: remark: loaded module from
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/x86_64-apple-ios-simulator.swiftinterface
2020-11-19 20:06:23 -08:00
Varun Gandhi
3784900df9 [AST] Account for parameter bridging in Clang type computation. 2020-10-29 22:22:00 -07:00
John McCall
2f0883542f Merge pull request #34388 from rjmccall/import-concurrency
Implicitly import _Concurrency under -enable-experimental-concurrency
2020-10-22 12:06:01 -04:00
Argyrios Kyrtzidis
91a8a82c4f Merge pull request #34384 from akyrtzi/util-prebuild-modules-stop-system-depend-track
[utils/swift_build_sdk_interfaces.py] Remove passing '-track-system-dependencies' when prebuilding modules from the interfaces
2020-10-21 22:56:14 -07:00
John McCall
a8464dcaf1 Implicitly import _Concurrency under -enable-experimental-concurrency 2020-10-22 00:53:15 -04:00
swift-ci
cb900a6b69 Merge pull request #34057 from varungandhi-apple/vg-track-isDerivable-update-mangling 2020-10-21 18:18:43 -07:00
Argyrios Kyrtzidis
a9f497d20c [utils/swift_build_sdk_interfaces.py] Remove passing '-track-system-dependencies' when prebuilding modules from the interfaces
Including all the system header dependencies and `stat`ing them all the time introduces significant performance overhead for normal compilation, and other features like code-completion, without being worth it in practice.
2020-10-21 17:12:23 -07:00
Varun Gandhi
6cb71c6b45 [ASTPrinter] Print Clang type only if not derivable from Swift type. 2020-10-21 15:57:57 -07:00
Doug Gregor
b6c0145932 [SE-0289] Continue printing @_functionBuilder in .swiftinterfaces.
Maintain the ability for older Swift compilers to read .swiftinterfaces
that make use of result builders by always emitting @_functionBuilder
rather than the newer @resultBuilder.
2020-10-20 22:24:41 -07:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Doug Gregor
dee5356021 [Concurrency] Add inferred actor-isolation attributes.
When we infer an actor-isolation attribute on a declaration, add an
implicit attribute that will show up in the printed interface and get
serialized.

... and clean up the type resolution logic for global actor attributes
to make it use CustomAttrTypeRequest, so the result gets appropriately
cached in CustomAttr for serialization.
2020-10-14 10:20:39 -07:00
Alexis Laferrière
fa6f1b6b96 Merge pull request #33439 from xymus/expand-avail
[Sema] Define availability specification macros with a frontend flag
2020-10-08 09:25:32 -07:00
Alexis Laferrière
c6fc53e844 [Sema] Define availability via compiler flag
Introduce availability macros defined by a frontend flag.
This feature makes it possible to set the availability
versions at the moment of compilation instead of having
it hard coded in the sources. It can be used by projects
with a need to change the availability depending on the
compilation context while using the same sources.

The availability macro is defined with the `-define-availability` flag:

swift MyLib.swift -define-availability "_iOS8Aligned:macOS 10.10, iOS 8.0" ..

The macro can be used in code instead of a platform name and version:
@available(_iOS8Aligned, *)
public func foo() {}

rdar://problem/65612624
2020-10-06 11:25:20 -07:00
Xi Ge
00eb2e9db2 Frontend: add a frontend flag to disable building module from textual interface
This is for testing purposes to ensure prebuilt modules are up to date.

rdar://68770805
2020-10-05 11:52:05 -07:00
Brent Royal-Gordon
df2924e558 Merge pull request #34068 from brentdax/technically-its-more-of-a-concurrency-experiment
Emit -enable-experimental-concurrency into module interfaces
2020-09-25 10:18:07 -07:00
Brent Royal-Gordon
0a94737ff1 Emit -enable-experimental-concurrency into module interfaces
…when the module is built with that flag. Fixes rdar://69322538.
2020-09-24 15:26:10 -07:00
swift-ci
9805f2bad7 Merge pull request #34002 from 3405691582/EraseNotUnsetEnv 2020-09-24 13:40:11 -07:00
Slava Pestov
4ff6cda180 Add module interface printing test with non-trivial pattern binding initializer
A stored property can be part of a pattern binding entry whose pattern
declares multiple bindings with a single initializer, for example:

struct S {
  let (x, y) = (0, 0)
}

Make sure these round-trip correctly.
2020-09-22 13:54:42 -04:00