Commit Graph

1131 Commits

Author SHA1 Message Date
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
3405691582
62a13e9ecd [test] Erase SDKROOT since env -u is not portable.
The `env -u` flag is not portable and not available on all platforms, so
this unit test will fail when the feature is unavailable.  Instead of
trying to unset the field, just erase it instead, since trying to copy
the entire invoked environment is difficult.
2020-09-19 21:05:01 -04:00
Xi Ge
028a75572c ModuleInterface: remark potential version differences between SDK and prebuilt modules
Prebuilt-module directory now contains a SystemVersion.plist file copied from the SDK
it's built from. This patch teaches the compiler to remark this version and the SDK version
when -Rmodule-interface-rebuild is specified. The difference between these versions could
help us debug unusable prebuilt modules.
2020-09-04 11:45:05 -07:00
Brent Royal-Gordon
8fbd449501 Merge pull request #33114 from brentdax/check-your-interfaces-at-the-door
Verify that just-emitted module interfaces parse and typecheck
2020-08-24 20:33:58 -07:00
Slava Pestov
ce550f2464 AST: Try harder to preserve type sugar in AbstractGenericSignatureRequest
AbstractGenericSignatureRequest tries to minimize the number of GSBs that we
spin up by only creating a GSB if the generic parameter and requirement types
are canonical. If they're not canonical, it first canonicalizes them, then
kicks off a request to compute the canonical signature, and finally, re-applies
type sugar.

We would do this by building a mapping for re-sugaring generic parameters,
however this mapping was only populated for the newly-added generic parameters.

If some of the newly-added generic requirements mention the base signature's
generic parameters, they would remain canonicalized.

Fixes <rdar://problem/67579220>.
2020-08-24 19:16:36 -04: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
Brent Royal-Gordon
22e3cff700 Tweak diagnostic for failed module interface verification 2020-08-07 17:45:04 -07:00
Brent Royal-Gordon
5f523fee66 Add flag to verify just-emitted module interfaces
The driver can now schedule jobs which typecheck just-emitted module interfaces to ensure that they can be consumed later. This can be enabled manually by passing `-verify-emitted-module-interface` to the driver.
2020-08-07 17:45:03 -07:00
Brent Royal-Gordon
9bc787ef5f Add a “typecheck module interface” mode 2020-08-07 16:00:15 -07:00
Arnold Schwaighofer
54c758f2a1 Convert the EagerSpecializer pass to a function pass
Should be NFC.
2020-07-27 13:55:59 -07:00
Xi Ge
1b40abd52c test: fix ModuleInterface/emit-forward-modules.swift 2020-07-20 11:39:07 -07:00
Mike Ash
8362ddd1a0 [Test] Disable ModuleInterface/emit-forward-modules.swift until it can be fixed 2020-07-20 11:29:42 -04:00
Xi Ge
f9396f2812 ModuleInterface: teach -compile-module-from-interface to emit forwarding module
-compile-module-from-interface action now takes arguments of -candidate-module-file.
If one of the candidate module files is up-to-date, the action emits a forwarding
module pointing to the candidate module instead of building a binary module.
2020-07-18 19:13:47 -07:00
Xi Ge
f5477d67af ModuleInterface: teach the compiler to look into SDK-versioned prebuilt module cache dir
To support multiple versions of SDKs of the same platform, we should move prebuilt
module cache into an SDK-versioned sub-directory and teach the compiler to look into
the directory if present.

rdar://65488510
2020-07-14 10:40:16 -07:00
Robert Widmann
39ad5e48ba Merge pull request #32789 from compnerd/pipe-dream
test: use `-log-path` for stderr access in ModuleInterface tests
2020-07-10 14:35:29 -07:00