Commit Graph

834 Commits

Author SHA1 Message Date
Joe Groff
5087e411c2 SILGen: Implement native-to-foreign thunks for async methods.
Bridging an async Swift method back to an ObjC completion-handler-based API requires
that the ObjC thunk spawn a task on which to execute the Swift async API and pass
its results back on to the completion handler.
2020-12-08 10:04:40 -08:00
Erik Eckstein
8e03bd3e67 [concurrency] SILGen: emit @asyncHandler functions.
An asyncHandler function is split into two functions:
1. The asyncHandler body function: it contains the body of the function, but is emitted as an async function.
2. The original function: it just contains
      _runAsyncHandler(operation: asyncHandlerBodyFunction)

rdar://problem/71247879
2020-12-01 08:48:40 +01:00
Arnold Schwaighofer
3aec862e62 Merge pull request #34848 from aschwaighofer/make_prespecialization_experimental
Pre-specialization: This is an experimental feature
2020-11-30 10:22:49 -08:00
Doug Gregor
dab6fb7098 [Concurrency] Implement SIL generation for "async let".
Implement SIL generation for "async let" constructs, which involves:

1. Creating a child task future at the point of declaration of the "async let",
which runs the initializer in an async closure.
2. Entering a cleanup to destroy the child task.
3. Entering a cleanup to cancel the child task.
4. Waiting for the child task when any of the variables is reference.
5. Decomposing the result of the child task to write the results into the
appropriate variables.

Implements rdar://71123479.
2020-11-27 22:50:39 -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
Joe Groff
0ca29b504f Merge pull request #34525 from jckarter/foreign-async-silgen
SILGen: Caller-side codegen for invoking foreign async functions
2020-11-12 06:55:04 -08:00
Michael Gottesman
67608e044b Merge pull request #34669 from gottesmm/pr-e67e6b91001b244349fb8858b70cfa52b2738c8d
[ownership] Extract out SILOwnershipKind from ValueOwnershipKind into its own type and rename Invalid -> Any.
2020-11-10 18:01:39 -08:00
Joe Groff
368dc0f401 SILGen: Generate bodies for completion handler block impls 2020-11-10 16:36:50 -08:00
Michael Gottesman
c026e95cce [ownership] Extract out SILOwnershipKind from ValueOwnershipKind into its own type and rename Invalid -> Any.
This makes it easier to understand conceptually why a ValueOwnershipKind with
Any ownership is invalid and also allowed me to explicitly document the lattice
that relates ownership constraints/value ownership kinds.
2020-11-10 14:29:11 -08:00
Ben Barham
241559dc88 [Serialization] Add an option to output modules regardless of errors
Adds a new frontend option
"-experimental-allow-module-with-compiler-errors". If any compilation
errors occur while generating the .swiftmodule, this mode will skip SIL
entirely and only serialize the (likey invalid) AST.

This existence of this option during generation is serialized into the
resulting .swiftmodule. Errors found in deserialization are only allowed
if it is set.

Primarily intended for IDE requests (eg. indexing and code completion)
to ensure robust cross-module results, despite possible errors.

Resolves rdar://69815975
2020-11-10 14:47:22 +10:00
Ben Barham
7cee600bcd [SILGen] Add flag to skip typechecking and SIL gen for function bodies
Adds a new flag "-experimental-skip-all-function-bodies" that skips
typechecking and SIL generation for all function bodies (where
possible).

`didSet` functions are still typechecked and have SIL generated as their
body is checked for the `oldValue` parameter, but are not serialized.
Parsing will generally be skipped as well, but this isn't necessarily
the case since other flags (eg. "-verify-syntax-tree") may force delayed
parsing off.
2020-11-06 12:08:19 +10: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
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Doug Gregor
4ddf6e565a Teach SuperclassDeclRequest to always diagnose circularity.
Rather than relying on clients to cope with the potential for circular
inheritance of superclass declarations, teach SuperclassDeclRequest to
establish whether circular inheritance has occurred and produce "null"
in such cases. This allows other clients to avoid having to think about

To benefit from this, have SuperclassTypeRequest evaluate
SuperclassDeclRequest first and, if null, produce a Type(). This
ensures that we don't get into an inconsistent situation where there
is a superclass type but no superclass declaration.
2020-09-29 17:42:17 -07:00
Varun Gandhi
6dfdb7b548 [NFC] Clean up construction of ExtInfo(Builder). 2020-09-24 00:38:45 -07:00
Varun Gandhi
7b967a8030 Merge pull request #33085 from varungandhi-apple/vg-clang-types-in-sil-retry
Propagate Clang function types through SIL
2020-09-22 08:48:34 -07:00
Varun Gandhi
5e9bf1f7c6 [SIL] Store ClangTypeInfo in SILFunctionType.
This patch includes a large number of changes to make sure that:
1. When ExtInfo values are created, we store a ClangTypeInfo if applicable.
2. We reduce dependence on storing SIL representations in ASTExtInfo values.
3. Reduce places where we sloppily create ASTExtInfo values which should
   store a Clang type but don't. In certain places, this is unavoidable;
   see [NOTE: ExtInfo-Clang-type-invariant].

Ideally, we would check that the appropriate SILExtInfo does always store
a ClangTypeInfo. However, the presence of the HasClangFunctionTypes option
means that we would need to condition that assertion based on a dynamic check.
Plumbing the setting down to SILExtInfoBuilder's checkInvariants would be too
much work. So we weaken the check for now; we should strengthen it once we
"turn on" HasClangFunctionTypes and remove the dynamic feature switch.
2020-09-16 10:34:42 -07:00
Hamish Knight
cb099454d6 Allow SILGen to emit only a specific set of SILDeclRefs
Extend ASTLoweringDescriptor to store a set of
SILDeclRefs to emit through `emitFunctionDefinition`.
2020-09-15 19:20:11 +01:00
Hamish Knight
44a8b56168 Rename getFiles to getFilesToEmit
Rename the member on ASTLoweringDescriptor and
IRGenDescriptor to make it more explicit it returns
the files that need emitting, rather than just the
files that happen to be present. This distinction
will become important once we start emitting code
only for a specific set of symbols.
2020-09-15 19:20:10 +01:00
Hamish Knight
add22194fd [SILGen] Allow lazy type-checking
Remove the type-checking call from
OptimizedIRRequest, and sink it down into SILGen
and IRGen when we come to emit the source files.
2020-09-15 19:20:10 +01:00
Hamish Knight
a54765b3d0 Merge pull request #33781 from hamishknight/is-this-odr 2020-09-03 19:59:24 -07:00
Slava Pestov
b9cd6caa72 SILGen: Emit hoisted declarations at the top level 2020-09-03 16:16:51 -04:00
Hamish Knight
ef5335ad00 [SILGen] Move thunk emission to emitFunctionDefinition 2020-09-02 21:09:11 -07:00
Hamish Knight
0f40089f91 [SILGen] Move closure emission to emitFunctionDefinition 2020-09-02 21:09:09 -07:00
Hamish Knight
cc8344aaae [SILGen] Remove astNode param from preEmitFunction
The AST node can be retrieved from the passed
SILLocation.
2020-09-02 21:09:09 -07:00
Hamish Knight
ac63abc8c2 [SILGen] Consolidate emission of SILDeclRef definitions
Fill in the missing SILDeclRef cases in
`emitDelayedFunction`, and rename it to
`emitFunctionDefinition`. This will allow SIL to
be emitted only for a specific set of symbols.
2020-09-02 21:09:09 -07:00
Joe Groff
f588f2f478 Merge pull request #33650 from jckarter/global_init_mangling
Remove hardcoded symbol name parsing from SILOptimizer passes
2020-08-28 08:34:35 -07:00
Nate Chandler
f74a3b47fc [SIL] Added async flag to SILExtInfo. 2020-08-25 17:33:27 -07:00
Joe Groff
d82a767e13 SIL: Add a SILFunction::Purpose for global init once functions 2020-08-25 17:06:09 -07:00
Nate Chandler
94b5f76654 Revert "[SIL] Add SILFunctionType flag for async."
This reverts commit 9b8828848d.
2020-08-25 13:37:26 -07:00
Nate Chandler
9b8828848d [SIL] Add SILFunctionType flag for async. 2020-08-19 11:29:58 -07:00
Varun Gandhi
f219e58ada [NFC] Refactor ExtInfo to use a builder-pattern based API.
Since the two ExtInfos share a common ClangTypeInfo, and C++ doesn't let us
forward declare nested classes, we need to hoist out AnyFunctionType::ExtInfo
and SILFunctionType::ExtInfo to the top-level.

We also add some convenience APIs on (AST|SIL)ExtInfo for frequently used
withXYZ methods. Note that all non-default construction still goes through the
builder's build() method.

We do not add any checks for invariants here; those will be added later.
2020-07-31 13:55:55 -07:00
Michael Gottesman
e3fa1376f6 [silgen] Mark a bunch of functions that SILGen open-codeds as "auto-generated" and thus not user generated code.
This ensures that we do not emit diagnostics onto these functions. I noticed we
were doing this with my work on opt-remarks when I was hitting diagnostics in
these functions in a set of subsequent commits.

The way that I found these is that I went through this file and looked for any
cases where we were never calling emitStmt on a user provided function body.

I also eliminated two places where we were setting a new DebugScope even though
preEmitFunction already does that for us.
2020-07-28 14:11:52 -07:00
marcrasi
493b4a8ef8 Merge pull request #32916 from marcrasi/remove-gen-sig-more-places
[AutoDiff] remove all-concrete gen sig from more places
2020-07-21 22:51:41 -07:00
Holly Borla
61cb9a5f4f Merge pull request #32866 from hborla/property-wrapper-autoclosure
[Property Wrappers] Use autoclosure information from CSApply to compute `VarDecl::getPropertyWrapperInitValueInterfaceType`
2020-07-17 09:16:05 -07:00
Brent Royal-Gordon
4394e92c3f Merge pull request #32700 from brentdax/magical-and-evolutionary
Revise #file changes from SE-0274
2020-07-17 01:57:23 -07:00
Robert Widmann
638977454b Remove SharedTimer Infrastructure
Teach the UnifiedStatsReporter to directly construct
llvm::NamedRegionTimer for itself.
2020-07-16 17:35:50 -07:00
Marc Rasi
7191c9c21d [AutoDiff] remove all-concrete gen sig from more places 2020-07-15 17:28:14 -07:00
Holly Borla
a6c33a9611 [Property Wrappers] Use autoclosure information from CSApply to compute
`VarDecl::getPropertyWrapperInitValueInterfaceType`.
2020-07-13 17:22:29 -07:00
Brent Royal-Gordon
7f91145efc [NFC] Rename “MagicFileString” -> “FileID”
Doing this NFC renaming first helps clarify the functional changes to come.
2020-07-13 14:05:13 -07:00
Brent Royal-Gordon
acc01aea03 [NFC] Add MagicIdentifierKinds.def
Extracts the list of magic identifier literal kinds into a separate file and updates a lot of code to use macro metaprogramming instead of naming half a dozen cases manually. This is a complicated change, but it should be NFC.
2020-07-13 14:05:13 -07:00
Dan Zheng
383482b657 [AutoDiff] Fix derivative generic signature same-type requirements. (#32803)
Fix SILGen for `@derivative` attributes where the derivative generic signature
is equal to the original generic signature and has all concrete generic
parameters (i.e. all generic parameters are bound to concrete types via
same-type requirements).

SILGen should emit a differentiability witness with no generic signature.
This is already done for `@differentiable` attributes.

Resolves TF-1292.
2020-07-09 20:02:10 -07:00
Hamish Knight
5792a72b95 Always link SIL for partial modules in SILGen
Previously we would only link `.sib` partial
modules in SILGen, with other kinds of serialized
ASTs being linked just before the SILOptimizer if
`-sil-merge-partial-modules` was specified.
However linking them always seems to be the desired
behaviour, so adjust SILGen to link SIL for all
serialized AST inputs.
2020-07-01 23:14:01 -07:00
Hamish Knight
bccdc0e062 NFC: Rename performSILGeneration -> performASTLowering
And also rename the underlying request and
descriptor.

This rename is motivated by the fact that the
operation may instead perform parsing of SIL files
and/or deserialization of SIB files.
2020-05-27 09:36:11 -07:00
Slava Pestov
2965cd29eb SILGen: Emit enum element constructors using the 'on-demand' mechanism
Enum element constructors are used when an enum element satisfies
a protocol requirement. Instead of emitting them as part of
emitGlobalFunctionRef(), let's sink it down to getFunction() where
we do all other on-demand function body emission.
2020-05-15 02:19:24 -04:00
Slava Pestov
ee92a117e6 SILGen: Simplify on-demand function emission
This mechanism is used for imported functions with bodies synthesized
by the ClangImporter, as well as on-demand accessors synthesized when
required for a protocol conformance (eg, a _read accessor, or a
_modify on a property whose opaque access pattern doesn't use a
_modify, such as an @objc dynamic property).

Previously this was intertwined with the 'delayed function' mechanism,
which is similar, but used for a different case -- implicit functions
inside the same translation unit.

Untangle these to allow further simplifications.
2020-05-15 02:19:24 -04:00
Slava Pestov
89a671d35f SILGen: Refactor emitOrDelayFunction() to not take a closure
Since the closure is completely determined by the SILDeclRef,
we can centralize the emission logic in one place.
2020-05-15 02:19:24 -04:00
Slava Pestov
d258c35209 SILGen: Remove obsolete hack preventing emission of allocating init for unavailable initializer
Fixes <rdar://problem/63188572>.
2020-05-14 20:00:24 -04:00
Hamish Knight
a3660f2bd1 [SILGen] Merge the two SILGen requests
They both do essentially the same thing, with the
single-file request being the single-element case
of the whole-module request, with only the call to
`getAllForModule` really caring about the
difference.
2020-05-13 17:42:01 -07:00
Hamish Knight
9a940a7f92 [SILGen] Assert the SourceFile has been type-checked 2020-05-13 17:42:00 -07:00