Commit Graph

331 Commits

Author SHA1 Message Date
Erik Eckstein
a3026a3988 [concurrency] SILGen: emit hop_to_executor instructions in actor-isolated closures.
This is the second part after emitting hop_to_executor instructions in regular functions.
2020-11-19 10:52:05 +01:00
Erik Eckstein
9fc11717cc [concurrency] SILGen: only emit hop_to_executor instructions in async functions. 2020-11-05 13:58:40 +01: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
David Zarzycki
3952715bed [SIL] NFC: Move #include of CanTypeVisitor.h
This improves incremental rebuild performance.
2020-07-02 11:04:25 -04:00
Arnold Schwaighofer
970c27248f Merge pull request #31470 from aschwaighofer/fix_rdar62560867
SIL: Thread type expansion context through to function convention apis
2020-05-06 11:52:19 -07:00
Dmitri Gribenko
c6cf6cf4b2 Remove dead code in SILGenProlog.cpp 2020-05-06 11:22:30 +02: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
Meghana Gupta
8e800e49bf Recommit #29812 with fixes (#30342) 2020-03-13 19:34:16 -07:00
Rintaro Ishizaki
ccbc26d947 Revert "Use in_guaranteed for let captures (#29812)"
This reverts commit 13b9915c6f.
2020-03-10 16:08:08 -07:00
Meghana Gupta
13b9915c6f Use in_guaranteed for let captures (#29812)
* Use in_guaranteed for let captures

With this all let values will be captured with in_guaranteed convention
by the closure. Following are the main changes :

SILGen changes:
- A new CaptureKind::Immutable is introduced, to capture let values as in_guaranteed.
- SILGen of in_guaranteed capture had to be fixed.
  in_guaranteed captures as per convention are consumed by the closure. And so SILGen should not generate a destroy_addr for an in_guaranteed capture.
  But LetValueInitialization can push Dealloc and Release states of the captured arg in the Cleanup stack, and there is no way to access the CleanupHandle and disable the emission of destroy_addr while emitting the captures in SILGenFunction::emitCaptures.
  So we now create, temporary allocation of the in_guaranteed capture iduring SILGenFunction::emitCaptures without emitting destroy_addr for it.

SILOptimizer changes:
- Handle in_guaranteed in CopyForwarding.
- Adjust dealloc_stack of in_guaranteed capture to occur after destroy_addr for on_stack closures in ClosureLifetimeFixup.

IRGen changes :
  - Since HeapLayout can be non-fixed now, make sure emitSize is used conditionally
  - Don't consider ClassPointerSource kind parameter type for fulfillments while generating code for partial apply forwarder.
    The TypeMetadata of ClassPointSource kind sources are not populated in HeapLayout's NecessaryBindings. If we have a generic parameter on the HeapLayout which can be fulfilled by a ClassPointerSource, its TypeMetaData will not be found while constructing the dtor function of the HeapLayout.
    So it is important to skip considering sources of ClassPointerSource kind, so that TypeMetadata of a dependent generic parameters gets populated in HeapLayout's NecessaryBindings.
2020-03-10 12:23:02 -07:00
Slava Pestov
8214e18850 SILGen: Clean up invariants around capture lists 2019-12-19 23:47:24 -05:00
Slava Pestov
1401cbaf2b SILGen: Fudge emitProlog() to emit unreachable later
For some reason, doing it in the other order causes a crash.
I suspect this is because we create new instructions below,
but if there's no insertion point, the instruction is never
added to a basic block.
2019-12-13 15:39:47 -05:00
Arnold Schwaighofer
33f4f57cc4 SILGen: Add TypeExpansionContext to SILGen 2019-11-11 14:21:52 -08:00
Joe Groff
03c7919b4a SIL: Add fields to SILFunctionType for substituted function types.
https://forums.swift.org/t/improving-the-representation-of-polymorphic-interfaces-in-sil-with-substituted-function-types/29711

This prepares SIL to be able to more accurately preserve the calling convention of
polymorphic generic interfaces by letting the type system represent "substituted function types".
We add a couple of fields to SILFunctionType to support this:

- A substitution map, accessed by `getSubstitutions()`, which maps the generic signature
  of the function to its concrete implementation. This will allow, for instance, a protocol
  witness for a requirement of type `<Self: P> (Self, ...) -> ...` for a concrete conforming
  type `Foo` to express its type as `<Self: P> (Self, ...) -> ... for <Foo>`, preserving the relation
  to the protocol interface without relying on the pile of hacks that is the `witness_method`
  protocol.

- A bool for whether the generic signature of the function is "implied" by the substitutions.
  If true, the generic signature isn't really part of the calling convention of the function.
  This will allow closure types to distinguish a closure being passed to a generic function, like
  `<T, U> in (*T, *U) -> T for <Int, String>`, from the concrete type `(*Int, *String) -> Int`,
  which will make it easier for us to differentiate the representation of those as types, for
  instance by giving them different pointer authentication discriminators to harden arm64e
  code.

This patch is currently NFC, it just introduces the new APIs and takes a first pass at updating
code to use them. Much more work will need to be done once we start exercising these new
fields.

This does bifurcate some existing APIs:

- SILFunctionType now has two accessors to get its generic signature.
  `getSubstGenericSignature` gets the generic signature that is used to apply its
  substitution map, if any. `getInvocationGenericSignature` gets the generic signature
  used to invoke the function at apply sites. These differ if the generic signature is
  implied.
- SILParameterInfo and SILResultInfo values carry the unsubstituted types of the parameters
  and results of the function. They now have two APIs to get that type. `getInterfaceType`
  returns the unsubstituted type of the generic interface, and
  `getArgumentType`/`getReturnValueType` produce the substituted type that is used at
  apply sites.
2019-10-25 13:38:51 -07:00
Brent Royal-Gordon
ca25640cc3 Merge branch 'master' into everything-evil 2019-10-14 13:24:03 -07:00
Hamish Knight
9061d3da71 CaptureInfo no longer needs to be passed by reference
Now that it's only a word in size, it can be passed
by value.
2019-10-13 12:10:26 -07:00
Brent Royal-Gordon
ab96afacb5 [SILGen] Assert that captures have been computed
Before using the capture info, SILGen now asserts that it has computed, except for declarations which are not in a local context and therefore can’t have captures.

This causes failures in REPL tests, but they are actual failures—there’s a bug in TypeCheckREPL.
2019-10-11 19:16:58 -07:00
Slava Pestov
d8b61ff24b Sema: Peel off typeCheckParameterList()'s specifier computation into a request
Since getSpecifier() now kicks off a request instead of always
returning what was previously set, we can't pass a ParamSpecifier
to the ParamDecl constructor anymore. Instead, callers either
call setSpecifier() if the ParamDecl is synthesized, or they
rely on the request, which can compute the specifier in three
specific cases:

- Ordinary parsed parameters get their specifier from the TypeRepr.

- The 'self' parameter's specifier is based on the self access kind.

- Accessor parameters are either the 'newValue' parameter of a
  setter, or a cloned subscript parameter.

For closure parameters with inferred types, we still end up
calling setSpecifier() twice, once to set the initial defalut
value and a second time when applying the solution in the
case that we inferred an 'inout' specifier. In practice this
should not be a big problem because expression type checking
walks the AST in a pre-determined order anyway.
2019-10-10 15:00:07 -04:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Doug Gregor
ab5d161c05 [SILGen] Separate the initialization of a wrapped property from a wrapped value
Teach SILGen to emit a separate SIL function to capture the
initialization of the backing storage type for a wrapped property
based on the wrapped value. This eliminates manual code expansion at
every use site.
2019-09-24 09:11:53 -07:00
Slava Pestov
533d41d0db SIL: Compute lowered local captures of SILDeclRefs and not AnyFunctionRefs
Unfortuantely this commit is bigger than I would like but I couldn't think
of any reasonable ways to split it up.

The general idea here is that capture computation is now done for a
SILDeclRef and not an AnyFunctionRef. This allows SIL to represent the
captures of a default argument generator.
2019-09-18 14:26:01 -04:00
Slava Pestov
9c5bd44f8e AST: Push ValueDecl::isSettable() down to AbstractStorageDecl 2019-07-31 21:26:02 -04:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
Joe Groff
af0291b072 Merge pull request #25929 from jckarter/dont-explode-inout-tuples
SILGen: Don't explode inout tuples in init allocating entry points.
2019-07-01 19:24:33 -07:00
Joe Groff
c02787d291 SILGen: Don't explode inout tuples in init allocating entry points.
rdar://problem/51302498
2019-07-01 17:05:22 -07:00
Slava Pestov
06ecb8d5c7 SIL: Remove CaptureKind::None and clean up some other capture-related logic 2019-06-27 20:59:22 -04:00
Michael Gottesman
dccd6eb0d6 [silgen] Change ManagedValue::copyInto to have same paramter order as ManagedValue::{forward,assign}Into.
ManagedValue::{forward,assign}Into both have the signature SILGenFunction &,
SILLocation, SILValue. For some reason copyInto has SILLocation and SILValue
swapped. This commit standardizes copyInto to match the others.
2019-05-15 13:47:39 -07:00
Slava Pestov
16d5716e71 SIL: Use the best resilience expansion when lowering types
This is a large patch; I couldn't split it up further while still
keeping things working. There are four things being changed at
once here:

- Places that call SILType::isAddressOnly()/isLoadable() now call
  the SILFunction overload and not the SILModule one.

- SILFunction's overloads of getTypeLowering() and getLoweredType()
  now pass the function's resilience expansion down, instead of
  hardcoding ResilienceExpansion::Minimal.

- Various other places with '// FIXME: Expansion' now use a better
  resilience expansion.

- A few tests were updated to reflect SILGen's improved code
  generation, and some new tests are added to cover more code paths
  that previously were uncovered and only manifested themselves as
  standard library build failures while I was working on this change.
2019-04-26 22:47:59 -04:00
Doug Gregor
2e9f8cf981 Capture a placeholder opaque value expression when needed. 2019-04-23 11:32:28 -07:00
Slava Pestov
c93ec45e62 SIL: Plumb resilience expansion through when lowering capture types
For now this is NFC.
2019-03-13 02:08:32 -04:00
Slava Pestov
568816aa91 SILGen: Always use minimal resilience expansion for the calling convention 2019-03-12 03:06:32 -04:00
Slava Pestov
c791c4a137 SIL: SILUndef must be aware of the resilience expansion
The ownership kind is Any for trivial types, or Owned otherwise, but
whether a type is trivial or not will soon depend on the resilience
expansion.

This means that a SILModule now uniques two SILUndefs per type instead
of one, and serialization uses two distinct sentinel IDs for this
purpose as well.

For now, the resilience expansion is not actually used here, so this
change is NFC, other than changing the module format.
2019-03-12 00:30:35 -04:00
Michael Gottesman
d012762d26 [sil] Ban passing non-trivial values to copy_value, destroy_value.
I also fixed a small violation in SILGenProlog/added a test for it.
2019-01-29 16:54:37 -08:00
Slava Pestov
1e05d36125 SILGen: Centralize DynamicSelfType hackyness a bit
Get rid of some randomly-placed calls to eraseDynamicSelfType() and
refactors things in preparation for the next change.
2019-01-11 15:55:45 -05:00
Suyash Srijan
3b8128ccf9 [silgen] Move diagnostic note creation to SILGenStmt 2018-11-26 21:50:31 +00:00
Suyash Srijan
4f39e3b588 [silgen] [ast] adds param name to diagnostics 2018-11-26 18:32:06 +00:00
Suyash Srijan
f2491398ea [silgen] check if the body is not null before accessing it 2018-11-19 22:58:12 +00:00
Suyash Srijan
01fa184fcb [silgen] emit a diagnostic note only if the body is not empty 2018-11-18 19:26:45 +00:00
Suyash Srijan
b7df15c30d [silgen] emit diagnostic (note) about unreachable function body 2018-11-17 01:35:59 +00:00
Suyash Srijan
54616ec089 [silgen] Removes whitespace 2018-11-16 01:34:55 +00:00
Suyash Srijan
0d02829342 [silgen] move unreachable code emission to void emitProlog() 2018-11-16 01:31:35 +00:00
Suyash Srijan
f632e0bd46 [silgen] Update prolog code to emit unreachable if a func param is uninhabited 2018-11-15 22:41:53 +00:00
Adrian Prantl
81f9ea33be SILGen: Preserve function argument debug info for arguments needing alloc_stack
This fixes a logic error in the existing code that cause these
function arguments to appear twice, once as local variable and once as
formal parameter.

rdar://problem/37410759
2018-08-31 10:35:52 -07:00
Slava Pestov
f316d46a26 SILGen: Remove support for anonymous closure arguments that bind to tuples containing InOutType
The constraint solver no longer produces such ASTs.

Also remove a comment and some other dead code referencing the
long-gone 'deshadowing' pass.
2018-08-10 18:42:06 -07:00
Slava Pestov
4b258e86e6 AST: Stop setting contextual types on ParamDecls
VarDecl::getType() lazily maps the interface type into context if needed.
2018-08-10 13:33:12 -07:00
Slava Pestov
e606aad80f SILGen: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 22:09:13 -07:00
John McCall
a3bdc89d47 Tell cleanups whether they're being emitted for the normal or unwind path.
NFC, but this may become semantically important for coroutines, because
an active coroutine must be aborted instead of ended on the unwind path.
2018-07-05 02:48:41 -04:00
Ben Cohen
2b04e9f105 Suppress a number of warnings in no-assert builds (#17721)
* Supress a number of warnings about things used only in asserts

* Re-use a couple of variables instead of supressing the warning
2018-07-04 07:15:14 -07:00
Slava Pestov
195577813b SIL: Remove type lowering support for InOutType
There is still some unfortunate hackery around InOutType in
SILGenProlog.cpp, but I don't want to clean it up yet.
2018-06-13 15:38:52 -07:00
Slava Pestov
296ce3f312 AST: Remove hack-around for getInterfaceType() on ParamDecl returning InOutType
Most callers did not want the InOutType here, and checked
the ParamDecl's flags instead.
2018-06-13 15:38:52 -07:00