Commit Graph

1232 Commits

Author SHA1 Message Date
Slava Pestov
4128211f29 SILGen: Clean up emitLoadActorExecutorForCallee() 2021-02-11 00:18:47 -05:00
Slava Pestov
c781ac02ad SILGen: Fix assertion failure when accessing a property with a __consuming getter
We checked isMutating() on the accessor, and if it was false, called
isNonMutatingSelfIndirect(), which would assert that the accessor
satisfies isNonMutating().

However, isNonMutating() is not the opposite of isMutating(); rather,
one of isMutating(), isNonMutating() or isConsuming() is true.
Change the assertion to reflect this case.

Fixes rdar://problem/74095841.
2021-02-10 18:36:32 -05:00
Slava Pestov
6630383643 AST: Split off Effects.h from Decl.h
Also remove the hash and equality operations on ProtocolRethrowsRequirementList;
this is no longer needed now that the AnyValue type eraser is gone.
2021-02-09 00:11:01 -05:00
Erik Eckstein
ec64f2a255 SILLocation: replace CleanupLocation::get(loc) with CleanupLocation(loc)
No need to have a static get function - the constructor can be used directly.
NFC
2021-01-29 20:28:21 +01:00
Philippe Hausler
6e05240426 AsyncSequence and protocol conformance rethrows (#35224)
* Initial draft of async sequences

* Adjust AsyncSequence associated type requirements

* Add a draft implementation of AsyncSequence and associated functionality

* Correct merge damage and rename from GeneratorProtocol to AsyncIteratorProtocol

* Add AsyncSequence types to the cmake lists

* Add cancellation support

* [DRAFT] Implementation of protocol conformance rethrowing

* Account for ASTVerifier passes to ensure throwing and by conformance rethrowing verifies appropriately

* Remove commented out code

* OtherConstructorDeclRefExpr can also be a source of a rethrowing kind function

* Re-order the checkApply logic to account for existing throwing calculations better

* Extract rethrowing calculation into smaller functions

* Allow for closures and protocol conformances to contribute to throwing

* Add unit tests for conformance based rethrowing

* Restrict rethrowing requirements to only protocols marked with @rethrows

* Correct logic for gating of `@rethrows` and adjust the determinates to be based upon throws and not rethrows spelling

* Attempt to unify the async sequence features together

* Reorder try await to latest syntax

* revert back to the inout diagnosis

* House mutations in local scope

* Revert "House mutations in local scope"

This reverts commit d91f1b25b59fff8e4be107c808895ff3f293b394.

* Adjust for inout diagnostics and fall back to original mutation strategy

* Convert async flag to source locations and add initial try support to for await in syntax

* Fix case typo of MinMax.swift

* Adjust rethrowing tests to account for changes associated with @rethrows

* Allow parsing and diagnostics associated with try applied to for await in syntax

* Correct the code-completion for @rethrows

* Additional corrections for the code-completion for @rethrows this time for the last in the list

* Handle throwing cases of iteration of async sequences

* restore building XCTest

* First wave of feedback fixes

* Rework constraints checking for async sequence for-try-await-in checking

* Allow testing of for-await-in parsing and silgen testing and add unit tests for both

* Remove async sequence operators for now

* Back out cancellation of AsyncIteratorProtocols

* Restructure protocol conformance throws checking and cache results

* remove some stray whitespaces

* Correct some merge damage

* Ensure the throwing determinate for applying for-await-in always has a valid value and adjust the for-await-in silgen test to reflect the cancel changes

* Squelch the python linter for line length
2021-01-25 18:48:50 -08:00
Kavon Farvardin
60fa93f131 emit hop_to_executor before & sometimes after implicitly-async calls
implicitly-async calls are calls to synchronous
actor-isolated functions. Synchronous functions
cannot perform hop_to_executor, so implicitly
async calls have the convention that the caller
is responsible for switching to the right
executor prior to entering the actor-isolated
callee.

It follows naturally that the caller must then
switch back to the appropriate executor after
the implicitly-async call completed.

Now, if the caller is not isolated to a
_specific_ actor, then we are (currently)
_not_ emitting a hop to go back to the
caller's executor, because that caller's
executor is unspecified (and currently not
accessable in SIL). This behavior may change
in the future; tracked in rdar://71905765
2020-12-07 17:40:17 -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
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
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
Erik Eckstein
c5bbe516c7 [concurrency] SILGen: emit hop_to_executor instructions
Emit hop_to_executor instruction in the prolog of actor-isolated async functions and after all async calls in such functions.

rdar://problem/70299168
2020-11-04 09:57:40 +01:00
Joe Groff
e7ec8c35af SILGen: Caller-side codegen for invoking foreign async functions
Immediately before invoking the ObjC API, get the current continuation, capture it into a block to
pass as the completion handler, and then await the continuation, whose resume/error successors
serve as the semantic return/throw result of the call. This should complete the caller-side part
of SILGen; the completion handler block implementation is however still only a stub.
2020-11-03 08:28:30 -08:00
John McCall
e35f077a9b Merge pull request #33349 from ellishg/master
[IRGen] Call objc_direct methods correctly
2020-10-30 03:03:54 -04:00
Joe Groff
7ab9e87b68 SILGen: Stub out support for invoking foreign async methods.
Allow SILGen to not crash when invoking foreign async methods by emitting
`undef` for the completion callback going into the call, and for the
results that would be channeled back through awaiting the continuation.
2020-10-27 10:22:32 -07:00
Ellis Hoag
3aa081c56e [IRGen] Call objc_direct methods correctly 2020-10-23 11:54:07 -05:00
swift-ci
7e16e3b4d2 Merge pull request #30630 from martinboehme/cxx-constructors 2020-10-20 14:37:29 -07:00
zoecarver
5774610eaf [cxx-interop] Fix patch formatting with clang-format.
Fix all formatting of the changes made by this patch.
2020-10-09 10:42:55 -07:00
zoecarver
f04de9f128 [cxx-interop] Skip metatypes when lowering C++ constructor SIL function type.
When lowering a C++ constructor's function type to a SIL function type,
skip over the "self" metatype parameter.
2020-10-09 10:42:54 -07:00
Alexey Komnin
4fa17bf597 SR-12022: refactor LiteralExpr to combine common initializer code 2020-10-01 15:45:16 +03: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
Varun Gandhi
eeec16f143 [NFC] Remove redundant ExtInfo parameter for getBridgedFunctionType.
At all call-sites, the extInfo passed as the third argument is computed directly
from the second argument, so we compute it directly in getBridgedFunctionType.
2020-08-27 13:14:05 -07:00
Erik Eckstein
755f6aa2e4 AST, SIL: Remove UTF16 encoding from StringLiteralExpr and StringLiteralInst
The UTF16 encoding is not used (anymore). I think it became obsolete with the switch to the UTF8 String representation.
2020-08-06 19:09:09 +02:00
Joe Groff
3a3d2fdf4f Merge pull request #33275 from jckarter/opaque-substitution-substitution
SILGen: Lower formal callee type pre-opaque-type-substitution.
2020-08-04 07:53:09 -07:00
Joe Groff
a07fce6dc3 SILGen: Lower formal callee type pre-opaque-type-substitution.
Prior to this fix, if we called a generic function with a substitutable opaque type as its formal substitution,
as in:

```
func opaque() -> some Any { return { } as ()->() }
func generic<T>(_ x: T) -> T { return x }

let x = generic(opaque())
```

then we would generate the formal type of the callee using the substitutions *after* opaque type expansion,
causing us to emit functions and metatypes at the wrong abstraction level and crash with SIL-level type mismatches.

Fixes rdar://problem/65683913.
2020-08-03 18:09:48 -07:00
Varun Gandhi
3882beb85d [NFC] Use consistent naming scheme for predicate methods. (#33265)
bool throws() -> isThrowing(), bool async() -> isAsync()
2020-08-03 16:37:29 -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
Brent Royal-Gordon
9a838bb654 Differentiate between Swift 5 and “Swift 6” #file
In -swift-version 5 and earlier, #file will continue to be a synonym for #filePath; in a future -swift-version (“Swift 6 mode”), it will become a synonym for #fileID. #file in libraries will be interpreted according to the language mode the library was compiled in, not the language mode its client uses.

Implement this behavior, tied to a frontend flag instead of a language version. We do so by splitting the old `MagicIdentifierLiteralExprKind::File` into two separate cases, `FileIDSpelledAsFile` and `FilePathSpelledAsFile`, and propagating this distinction throughout the AST. This seems cleaner than looking up the setting for the module the declaration belongs to every time we see `File`.

This doesn’t handle module interfaces yet; we’ll take care of those in a separate commit.
2020-07-13 14:06:55 -07:00
Brent Royal-Gordon
0e569f5d9e Add support for #fileID
This temporarily breaks -enable-experimental-concise-pound-file.

fixup adding #fileID
2020-07-13 14:05:13 -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
Michael Gottesman
ac3109a21d [eager-specializer] Fix for ownership and add a bunch of missing code coverage for ossa.
Specifically, we were missing a bunch of coverage around specializing guaranteed
parameters and non-trivial values in general.
2020-07-09 21:46:19 -07:00
Arnold Schwaighofer
28fba4f5e6 Merge pull request #32195 from aschwaighofer/dyn_repl_objc_method_generic_class
Mark non-foreign entry points of `@objc dynamic` methods in generic c…
2020-06-10 10:31:18 -07:00
Erik Eckstein
9168b81a17 Don't require the stdlib to contain the _finalizeUninitializedArray intrinsic function.
Prevent SILGen to crash if the compiler is used with a stdlib which does not have the _finalizeUninitializedArray intrinsic function.

rdar://problem/64195028
2020-06-10 13:26:16 +02:00
Arnold Schwaighofer
825a2a259b Mark non-foreign entry points of @objc dynamic methods in generic classes dynamically_replaceable
```
class Generic<T> {
  @objc dynamic func method() {}
}

extension Generic {
  @_dynamicReplacement(for:method())
  func replacement() {}
}
```

The standard mechanism of using Objective-C categories for dynamically
replacing @objc methods in generic classes does not work.

Instead we mark the native entry point as replaceable.

Because this affects all @objc methods in generic classes (whether there
is a replacement or not) by making the native entry point
`[dynamically_replaceable]` (regardless of optimization mode) we guard this by
the -enable-implicit-dynamic flag because we are late in the release cycle.

* Replace isNativeDynamic and isObjcDynamic by calls to shouldUse*Dispatch and
  shouldUse*Replacement
  This disambiguates between which dispatch method we should use at call
  sites and how these methods should  implement dynamic function
  replacement.

* Don't emit the method entry for @_dynamicReplacement(for:) of generic class
  methods
  There is not way to call this entry point since we can't generate an
  objective-c category for generic classes.

rdar://63679357
2020-06-09 09:23:29 -07:00
Erik Eckstein
1559fe333f SIL: a new library intrinsic to "finalize" array literals
For COW support in SIL it's required to "finalize" array literals.
_finalizeUninitializedArray is a compiler known stdlib function which is called after all elements of an array literal are stored.
This runtime function marks the array literal as finished.

  %uninitialized_result_tuple = apply %_allocateUninitializedArray(%count)
  %mutable_array = tuple_extract %uninitialized_result_tuple, 0
  %elem_base_address = tuple_extract %uninitialized_result_tuple, 1
  ...
  store %elem_0 to %elem_addr_0
  store %elem_1 to %elem_addr_1
  ...
  %final_array = apply %_finalizeUninitializedArray(%mutable_array)

In this commit _finalizeUninitializedArray is still a no-op because the COW support is not used in the Array implementation yet.
2020-06-08 10:24:29 +02:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Michael Gottesman
c217262a59 [silgen] Rename DelegateInitSelfWritebackCleanup -> OwnedValueWritebackCleanup.
This cleanup is meant to be used with a value that is temporarily taken from a
memory location for a lexical scope. At end of scope, the value is returned back
to the original memory location.

It is used to implement in SILGen "move only loadable values". Note, a "move
only loadable value" is not a "move only type". It is just an abstraction for
working with a single copy of a loadable value as if that single copy was a move
only value.

This is currently only being used in initializer emission since we treat self in
such a context as a "move only value" before we delegate to a
super/convenience/peer initializer since we have to allow for such initializers
to change the underlying class we have stored which in certain use cases require
self to be guaranteed as /never/ being retained. The move only value
representation makes this easy to do/enforce.

My hope is that by changing the name of this cleanup it is more obvious what it
is meant to do and can become (hopefully) generally useful.
2020-05-15 22:34:48 -07:00
Slava Pestov
23cbd7fd04 SILGen: Fix source location for the enum payload argument source
We should use the source location of the call site, and not the enum
element declaration, otherwise we emit incorrect debug info.

Fixes <rdar://problem/63067437>.
2020-05-12 19:42:26 -04:00
Joe Groff
c5863ac0f3 SILOptimizer: Constant fold the _kvcKeyPathString of literal key paths.
Eliminate the intermediate key path object when a literal key path is passed to a function that
just wants its KVC string to pass down to an ObjC API.
2020-05-07 13:33:01 -07:00
Arnold Schwaighofer
147144baa6 SIL: Thread type expansion context through to function convention apis
This became necessary after recent function type changes that keep
substituted generic function types abstract even after substitution to
correctly handle automatic opaque result type substitution.

Instead of performing the opaque result type substitution as part of
substituting the generic args the underlying type will now be reified as
part of looking at the parameter/return types which happens as part of
the function convention apis.

rdar://62560867
2020-05-04 13:53:30 -07:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Slava Pestov
052309e045 SILGen: Remove CallSite::SubstResultType
There was a bunch of book-keeping here that became dead.
2020-03-18 19:26:29 -04:00
Slava Pestov
b5732d3a3a SILGen: Eliminate the notion of 'extra call sites'
Now that curry thunks are gone, we can do a bit more refactoring
to guarantee that an ApplyExpr always has the *exact* number of
call sites expected.

Extra call sites are handled by emitting the innermost ApplyExpr
as an indirect callee, eliminating a special code path.
2020-03-18 19:26:29 -04:00
Slava Pestov
4aa75163a6 SILGen: Remove curry thunks
Now that CSApply transforms partial applications into closures,
we never see AST with partially-applied method calls. So all the
machinery for emitting curry thunks is now gone.
2020-03-18 19:26:14 -04:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
John McCall
585c28d0c3 Plumb a result SILType through SILGen's emitTransformedValue.
This fixes an immediate bug with subst-to-orig conversion of
parameter functions that I'm surprised isn't otherwise tested.
More importantly, it preserves valuable information that should
let us handle a much wider variety of variant representations
that aren't necessarily expressed in the AbstractionPattern.
2020-03-12 00:23:13 -04:00
Brent Royal-Gordon
8e5ca8abdf [NFC] Generate #file -> #filePath table ahead of time 2020-03-05 17:23:44 -08:00
Brent Royal-Gordon
f34fa7ffcd Match prototype’s #file string format to upcoming SE-0274 revision 2020-03-05 16:01:13 -08:00
Slava Pestov
4b9c82de5b SILGen: Fix substitution map when calling property wrapper backing initializer
If we're emitting a designated constructor inside a constrained extension,
we have to use the correct substitution map for calling the property wrapper
backing initializer.

Factor out the computation of this substitution map and use it consistently.

Fixes <rdar://problem/59245068>.
2020-02-25 18:18:54 -05:00
Joe Groff
45e941c23a SILGen: Apply substitutions before bridging or thunking.
Even if differently-substituted function types have different value representations,
we can still share reabstraction and bridging thunks among types that are equivalent after
substitution, so handle these by generating thunks in terms of the unsubstituted type and
converting to the needed substitution form at the use site.
2020-02-24 12:14:21 -08:00
Brent Royal-Gordon
c896794946 Merge pull request #29135 from brentdax/concise-for-thee-but-not-for-me
Use #file string for force-unwrap and force-try
2020-01-13 11:52:24 -08:00