Commit Graph

1481 Commits

Author SHA1 Message Date
Doug Gregor
ecd830e342 Rework BuiltinProtocolConformance to be more like NormalProtocolConformance.
Give BuiltinProtocolConformance a generic signature, which can be used to
describe the generic parameters used within the builtin conformance, e.g.,
`<T1, T2, T3>` for a tuple type `(T1, T2, T3)`. Also store the
conditional requirements as trailing objects, requiring them to be
precomputed by whatever builds the conformances. Together, this means
that builtin protocol conformances act like normal conformances with
respect to conditional requirements and substitutions: they will be
defined generically, then a specialized conformance will be layered on
top to provide the substitutions.
2021-07-27 23:49:27 -07:00
Azoy
20cc067844 [AST] Introduce BuiltinProtocolConformance 2021-07-27 23:49:27 -07:00
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
2021-07-22 23:27:05 -07:00
Alexis Laferrière
f460de4847 Merge pull request #38393 from xymus/trace-serializing-conf
[Serialization] Add pretty stacktraces to conformance serialization
2021-07-15 09:12:18 -07:00
Alexis Laferrière
90f0369226 [Serialization] Add pretty stacktraces to conformance serialization
This code path can report compiler inconsistencies, so let's make the
pretty stacktrace more useful when debugging. We probably want to make
the assert on witness.getDecl() a hard error too, but this would break
existing projects at this time.
2021-07-14 13:31:08 -07:00
Doug Gregor
06bbc70b3e Module printing and serialization support for @unchecked Sendable 2021-07-11 12:29:54 -07:00
Doug Gregor
29f5d7a64a [SE-0302] Implement '@unchecked Sendable' syntax.
Parse and provide semantic checking for '@unchecked Sendable', for a
Sendable conformance that doesn't perform additional semantic checks
for correctness.

Part of rdar://78269000.
2021-07-11 12:29:53 -07:00
Yuta Saito
6362a98aa0 [Frontend] Add -public-autolink-library option (#35936)
Foundation imports CoreFoundation with `@_implementationOnly`,
so CoreFoundation's modulemap won't be read, and the dependent libraries
of CoreFoundation will not be automatically linked when using static
linking.

For example, CoreFoundation depends on libicui18n and it's modulemap has
`link "icui18n"` statement. If Foundation imports CoreFoundation with
`@_implementationOnly` as a private dependency, the toolchain doesn't have
CoreFoundation's modulemap and Foundation's swiftmodule  doesn't import
CoreFoundation. So the swiftc can't know that libicui18n is required.

This new option will add LINK_LIBRARY entry in swiftmodule to
specify dependent libraries (in the example case, Foundation's
swiftmodule should have LINK_LIBRARY entry of libicui18n)


See also: [Autolinking behavior of @_implementationOnly with static linking](https://forums.swift.org/t/autolinking-behavior-of-implementationonly-with-static-linking/44393)
2021-06-15 12:38:19 +01:00
Doug Gregor
bd8626fa1b [Concurrency] Parse and add 'isolated' parameters to the type system. 2021-06-07 23:59:38 -07:00
QuietMisdreavus
40b084e5c0 Merge pull request #37640 from apple/QuietMisdreavus/spi-symbols
add symbol-graph flag to include SPI symbols
2021-06-04 11:34:48 -06:00
Doug Gregor
03f55d7bb4 Revert "Revert "Remove @actorIndependent attribute.""
This reverts commit 7c0b50e8ea.
2021-06-03 14:03:57 -07:00
Ben Barham
1fea98cbad [Serialization] Allow conformances with no witness if allowing errors
Note that deserialization already handles this case when recovery is
enabled.
2021-06-02 11:45:29 +10:00
Ben Barham
c490f928cb [Serialization] Serialize unresolved types as errors if allowing errors 2021-06-02 11:45:29 +10:00
Ben Barham
073a5828a2 [Serialization] Skip verifying attributes when allowing errors
When allowing errors any attribute could be on any decl, so don't verify
whether an attribute can appear on a decl. Note that these attributes
aren't serialized anyway since they'll be set to invalid during
typechecking and hence skipped.
2021-06-02 11:44:53 +10:00
Ben Barham
7856f2d83d [Serialization] Skip serializing invalid destructors if allowing errors 2021-06-02 11:39:14 +10:00
Ben Barham
a3e4f1ac2c Merge pull request #37472 from bnbarham/cleanup-allow-errors
[Serialization] Add whether allowing errors to the pretty stack output
2021-05-26 11:07:47 +10:00
Karoy Lorentey
7c0b50e8ea Revert "Remove @actorIndependent attribute." 2021-05-24 14:43:32 -07:00
Ben Barham
b9a97586c3 [Serialization] Cleanup allow module with errors references 2021-05-22 13:12:46 +10:00
Ben Barham
6b6986732a [Serialization] Skip MissingMembers when allowing errors
A normal compilation would error before merging modules when there are
MissingMemberDecls, so the missing member case is unreachable. That's
not true when allowing errors though, where we continue regardless. Skip
the missing member instead of crashing.

Resolves rdar://76365694.
2021-05-21 13:54:10 +10:00
Victoria Mitchell
d281722589 add symbol-graph flag to include SPI symbols
rdar://70794131
2021-05-20 15:10:49 -06:00
Doug Gregor
4d91f79bd5 Merge pull request #37462 from DougGregor/remove-actor-independent 2021-05-18 12:08:17 -07:00
Ben Barham
ccd39760cf Merge pull request #37441 from bnbarham/serialization-crashes
[Serialization] Do not assert when inherited type is null
2021-05-18 09:14:06 +10:00
Doug Gregor
d6e8fd81f5 Remove @actorIndependent attribute.
`@actorIndependent` has been superseded by `nonisolated`. Remove
the old spelling entirely.
2021-05-17 12:21:10 -07:00
Xi Ge
5c5715f626 Serialization: embed subminor and build version in the user module version entry 2021-05-17 10:15:47 -07:00
Ben Barham
c1e4362dfd [Serialization] Do not assert when inherited type is null
When compiling with allow errors, it's possible to have invalid
inherited types - both null and ErrorType.

Cleaned up the tests a little - moved the majority of
Frontend/allow-errors.swift into separate files in
Serialization/AllowErrors and use split_file.py instead of #defines.

Resolves rdar://78048470
2021-05-15 16:35:23 +10:00
Erik Eckstein
762e9c7882 Serialization: serialize if the module is a static library
If the `-static` option is specified, store that in the generated
swiftmodule file.  When de-serializing, recover this information in the
representative SILModule.

This will be used for code generation on Windows.  It is the missing
piece to allow static linking to function properly.  It additionally
opens the path to additional optimization on ELF-ish targets - GOT, PLT
references can be avoided when the linked module is known to be static.

Co-authored by: Saleem Abdulrasool <compnerd@compnerd.org>
2021-05-02 09:34:52 -07:00
Xi Ge
043d492c65 Merge branch 'main' into 73992299-1 2021-04-30 10:19:57 -07:00
Xi Ge
fe5c7ef995 ModuleInterface/Serialization: allow library authors to define a custom module version number
This allows library authors to pass down a project version number so that library users can conditionally
import that library based on the available version in the search paths.

Needed for rdar://73992299
2021-04-30 10:00:45 -07:00
Hamish Knight
f439275380 Mark imported @completionHandlerAsync attrs as implicit
Mark imported `@completionHandlerAsync` attrs as
implicit, which avoids printing them in generated
interfaces. And for the sake of completion,
serialize the implicit bit in case it's used
elsewhere in the future.

To make sure we continue to print
`@completionHandlerAsync` attributes explicitly
written by the user in Swift, add a SourceKit
interface test.

Resolves rdar://76685011
2021-04-30 11:14:50 +01:00
Ben Barham
4ec4520e0b Merge pull request #36968 from bnbarham/swift-serialization-crash
[Serialization] Add some checks for invalid types
2021-04-21 09:08:28 +10:00
Ben Barham
f876e0cd1a [Serialization] Add some checks for invalid types
When allowing errors there's various cases where an invalid type is used
during serialization:
  - Invalid explicit conformances on an extension
  - Superclass with invalid generic type

Add checks to skip these to avoid crashing.

Resolves rdar://75379780.
2021-04-20 13:39:46 +10:00
QuietMisdreavus
170dcd88bc Merge pull request #36863 from apple/QuietMisdreavus/docs-inheritance
[SymbolGraph] Add information about "inherited docs" for synthesized symbols
2021-04-19 19:40:38 -06:00
Kavon Farvardin
4f6eb85fe3 allow type initializers to be 'async'
implicit calls to an async super.init are not allowed
2021-04-15 10:08:53 -07:00
Ben Barham
f1efd02ac4 Merge pull request #36896 from bnbarham/extract-basic-info
[Gardening] Extract basic source info structs from RawComment.h
2021-04-14 18:46:48 +10:00
Ben Barham
c54c9c7079 [Gardening] Extract basic source info structs from RawComment.h 2021-04-14 10:05:27 +10:00
Alex Hoppen
380db634fa [Serialization] Serialize internal closure labels
Since 865e80f9c4 we are keeping track of internal closure labels in the closure’s type. With this change, wer are also serializing them to the swiftmodules.

Furthermore, this change adjusts the printing behaviour to print the parameter labels in the swiftinterfaces.

Resolves rdar://63633158
2021-04-13 08:53:46 +02:00
Victoria Mitchell
f4154d6019 add flag to skip docs on synthesized symbols 2021-04-11 17:40:37 -05:00
Victoria Mitchell
ba2b92be4e call it PrintMessages instead 2021-04-07 08:58:20 -06:00
Victoria Mitchell
0c5955b7fa silence symbolgraph-extract output without -v flag
rdar://72630103
2021-04-06 16:40:38 -06:00
Kavon Farvardin
f9452b23f4 implement parsing for effects specifiers on 'get' accessors
An effectful 'get' accessor must be the only accessor for the
property.
2021-03-26 07:54:53 -07:00
Holly Borla
3ca1292ec2 Merge pull request #36521 from hborla/property-wrapper-request-refactoring
[Property Wrappers] Rework the dependencies between property wrapper requests.
2021-03-19 21:27:31 -07:00
Holly Borla
21a86b5d2f [NFC][Property Wrappers] Split PropertyWrapperBackingPropertyInfoRequest into
two separate requests - one to synthesize the auxiliary declarations, and
another to compute how the backing storage is initialized.
2021-03-19 13:03:13 -07:00
Doug Gregor
52096a640e SE-0302: Rename ConcurrentValue/@concurrent to Sendable/@Sendable. 2021-03-18 23:48:21 -07:00
Doug Gregor
3a357e9978 Add global actor-qualified function types.
Introduce the notion of global actor-qualified function types, e.g.,

    @MainActor () -> Void

to describe synchronous functions that must execute on a particular
global actor.
2021-03-17 00:51:16 -07:00
Evan Wilde
eaab395973 Remove ExplicitCompletionHandlerIndex flag
Assuming that we don't typecheck a deserialized module, we don't
actually need the ExplicitCompletionHandlerIndex. We used this flag to
determine whether we could trust the number stored in the handler index
or just take the last parameter of the function we're attached to.

Since we only typecheck it before serialization, we can safely check
that the completion handler location is valid before choosing whether we
should trust it or not.
2021-03-13 13:38:15 -08:00
Evan Wilde
9f412616d8 Remove AsyncFunctionName from serialization
We can get the DeclName of the async function from the resolved function
decl itself, so we don't actually need to serialize it. This patch pulls
the declNameRef from the serialization.
2021-03-13 13:38:15 -08:00
Evan Wilde
2b0def501f Replace @hasAsyncAlt with @completionHandlerAsync
This patch replaces the @hasAsyncAlternative attribute with
@completionHandlerAsync. The @completionHandlerAsync attribute takes the
function decl name of the async function and optionally the index of the
completion hander parameter in the function that it's attached to.
If the completion handler index is not provided, it's assumed to be the
last parameter in the parameter list.

We resolve the async function while typechecking the attribute. Before
resolving, we verify that the function the attribute is attached to
isn't async, that it has enough parameters to at least have the
indicated completion handler referenced by the index, that the
completion handler is an escaping non-auto-closure function that returns
Void.

The async function declaration resolution isn't perfect yet, but I want
to get this patch up and we can refine it later. It pulls all of the
delcs with the specified declname in the same context as the
function that the attribute is attached to. Going through that list, it
keeps any that are async functions. If there are none, we emit an error
saying that there are no viable functions, if there are multiple we emit
an error saying that the decl name is ambiguous, and if there is one
function, we keep that as the resolve async function declaration.

This does not take into account the data types of the completion handler
or the async function. There are some complexities to making this
mapping. Here are the pieces:
 - If the completion handler takes a single data type, the async
   function should return that type. (easy case)
 - If the completion handler takes a `Result<T, Error>`, the async
   function is a throwing function that returns a T. (Medium difficulty)
 - If the completion handler looks like `(T?, Error?) -> Void`, we have
   an ambiguous situation between the following async functions:
   - func foo() async throws -> T
   - func foo() async throws -> T?
   That is, we cannot tell whether the `T?` in the completion handler is
   optional because it will be nil on an error, or if it is intended to
   be optional.

This can be done later if it becomes a problem.
2021-03-13 13:38:15 -08:00
Doug Gregor
2a28fed34d Allow one to separately specify the ABI name of a module.
Introduce a new compiler flag `-module-abi-name <name>` that uses the
given name as the ABI name for the module (rather than the module's
name in source code). The ABI name impacts name mangling and metadata.
2021-03-12 07:42:07 -08:00
Robert Widmann
779276a0c6 Bail On Checking Invalid Precedence Group
When the user spells an invalid precedence group, the Relation for that
group will fail to resolve the decl. We need to handle this in
checkPrecedenceGroup. Also add some asserts while I'm here.

rdar://75248642
2021-03-11 12:40:23 -08:00
Ben Barham
ce70727e6f [Deserialization] Output a diagnostic for invalid decls or types
47b068d445 output a diagnostic if a
deserialized decl was invalid (checking `Decl::isInvalid`). It had two
major issues:
  1. It incorrectly output diagnostics for valid modules
  2. It did not catch call invalid declarations

(1) is caused by `isInvalid` falling back to checking the storage for
accessors when the interface type hasn't already been computed (a
fallback to prevent a cycle due to `SimpleDidSetRequest` typechecking
the body). Since the `VarDecl` hasn't finished deserializing, it returns
`true` for its `isInvalid` check (even though it would later return
`false`).

For (2), only `ValueDecl`s would ever be invalid, since other
declarations use a bit in `Decl` to check for validity. As that's not
serialized, those would always be valid in deserialization.

To avoid both these issues, instead output a flag for each declaration
representing whether it is invalid (or not). Read that during
deserialization and output a diagnostic if it is invalid. To be extra
sure that a diagnostic is always output on an error, also output one
when deserializing any `ErrorType`. This ensures that SILGen does not
run when allowing errors (and an error is present), as it is likely to
crash when presented with an invalid AST.

Resolves rdar://74541834
2021-03-03 12:12:20 +10:00