Commit Graph

706 Commits

Author SHA1 Message Date
Joe Groff 2d194e7765 Merge pull request #15034 from jckarter/keypath-resilience-silgen
SILGen: Emit property descriptors for (some) decls that need them.
2018-03-07 16:49:36 -08:00
Joe Groff a8e3c4fc8b SILGen: Emit property descriptors for (some) decls that need them.
If a property or subscript is referenceable from other modules, we need to give it a descriptor so that we can reliably build an equivalent key path in or out of that module.

There are some cases that we should handle but don't yet:

- Global and static properties ought to be key-path-able someday, so we should make descriptors for them, but this might need a new key path component kind.
- Subscripts with indexes that aren't Hashable in the current module ought to get descriptors too, in case we ever support non-hashable key path components, and also because a generic subscript might be substituted with Hashable types by an external user, or an external module might post-hoc extend a type to be Hashable, so we really need to change things so that the client supplies the hashing and equality implementations for the indexes instead of the descriptor.
2018-03-07 15:32:12 -08:00
Joe Groff 34e77c0f25 Merge pull request #14893 from jckarter/keypath-resilience-silgen-refactor
SILGen: Refactor key path component lowering.
2018-03-01 11:19:26 -08:00
Joe Groff 2f0a3f2e2d SILGen: Refactor key path component lowering.
Factor out the code to lower an individual key path component to be independent of overall KeyPathExpr lowering, so that we can soon reuse the same code paths to build property descriptors for resilient properties. NFC intended.
2018-02-28 15:06:44 -08:00
swift-ci 07c7b5a526 Merge pull request #14886 from gottesmm/pr-1d8a01abff8ba53eef44341acc0e36484a133f95 2018-02-28 14:04:13 -08:00
Michael Gottesman dc56ec150e [+0-normal-args] When partially applying a super method, be sure that upcasted self is at +1.
Since I used ensurePlusOne, this should not have any effect on the compiler
today. This happens quite often once "normal arguments" are at +0 though.

I also changed this code to use SILGenBuilder APIs to ensure that ownership is
forwarded correctly.

Found when updating SILGen tests for +0.

rdar://34222540
2018-02-28 12:47:10 -08:00
Michael Gottesman 56556b785f [silgenapply] Centralize top level SILGenFunction entrypoints (i.e. SILGenFunction entrypoints) in 1 section of SILGenApply.cpp. 2018-02-27 12:59:35 -08:00
Michael Gottesman 1de4cc0fc3 [silgen] In SILGenApply.cpp, consistently indent classes in LLVM style.
Some of the classes in this file were using LLVM style for long classes, i.e.:

```
namespace {
class Foo {
  ... long class ...
};
} // end anonymous namespace
```

Other places, we were adding a level of indentation, i.e.:

```
namespace {
  class Foo {
    ... long class ...
  };
} // end anonymous namespace
```

This PR just standardizes the classes in this file that follow the later style,
to instead follow the former style.
2018-02-27 12:59:35 -08:00
Michael Gottesman b74ed23022 [silgen] Add some "flags" to SILGenApply.cpp to organize it a little better. 2018-02-27 12:59:26 -08:00
swift-ci 706e3dbba8 Merge pull request #14857 from gottesmm/pr-2b8da82466d75390465abccce3442cda2d85c5ca 2018-02-27 12:25:03 -08:00
Michael Gottesman b6bffcaced [silgen] prepareApplyExpr => CallEmission::forApplyExpr.
prepareApplyExpr is a static function that changes an expr into a CallEmission
and has no other uses beyond that purpose. This is the definition of a static
factory method. This PR performs that refactor.

NFC.
2018-02-27 11:01:46 -08:00
Michael Gottesman 536bc5a4e7 [silgen] Add some comments to Callee's constructors that explain which constructor corresponds to which factory methods.
NFC.
2018-02-27 10:01:06 -08:00
Arnold Schwaighofer 025a8b909a Fix PostponedCleanup and use it in more places.
It can't be moved because there are pointers to it
2018-02-13 04:19:59 -08:00
Arnold Schwaighofer 64943836ba SILGen: Support for trivial @noescape function types
- Emit a withoutActuallyEscapingClosure partial apply
This is to convert an @noescape closure to an escaping closure.
This needs to be done in preparation of @noescape closure contexts
becoming trivial.

- Insert escaping to noescape conversions

- Fix SILGen for @noescape

- Postpone closure cleanups to outside the argument scope

- Apply postponement recursively for closures passed to subscripts

- Only skip applying escapeness conversions for Swift thick functions

- Fix parameter convention for noescape closures in thunks

Part of:
SR-5441
rdar://36116691
2018-02-13 04:19:59 -08:00
Mark Lacey b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Arnold Schwaighofer fac09e985b SIL : Use the enum 's generic signature and the payloads type for an indirect enum payload's box type.
i.e for:

enum Indirect<T> {
  indirect cast payload(first: T, second :T)
}

let _ = Indirect<X>

The payload's SIL box type will be:

$<t_0_0> { var (first: t_0_0, second: t_0_0) } <X>

rdar: //36799330
2018-01-27 15:33:47 -08:00
John McCall 52bb547a7e Merge pull request #13866 from rjmccall/accessor-decl
Split AccessorDecl out from FuncDecl.  NFC.
2018-01-12 17:02:35 -05:00
John McCall 7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Michael Gottesman 20d47009a7 [+0-all] Use +1 for builtins. 2018-01-12 10:09:49 -08:00
Slava Pestov 72735ec1c6 SILGen: Remove unnecessary isFinal() check from getBaseAccessorFunctionRef() 2018-01-04 21:53:35 -08:00
Slava Pestov 2590142b7b SILGen: Remove shouldReferenceForeignAccessor()
Also, the 'isDirectAccess' parameter to various methods is now dead,
because it was never being set to true in the foreign case anyway.
2018-01-04 21:53:34 -08:00
Mark Lacey b6430d0644 IUO: Add ImplicitlyUnwrappedFunctionConversionExpr.
This expression node is only used when applying the results of
expression type checking. It initially appears above the function
reference that returns an optional that needs to be unwrapped, and
then when dealing with function application we remove this and insert
a node to force-unwrap the result of the function application.
2018-01-04 11:40:45 -08:00
Andrew Trick 17fa484f04 SILGen. Fix temporary LValue cleanup.
Use the LValue formal evaluation scope to destroy temporary lvalues that aren't
part of the expression's resulting value.

Disable an old hack that destroyed call site arguments after the call.

This is the first step in cleanup up LValue materialization.
2018-01-01 19:05:22 -08:00
Slava Pestov c16c2c35bf SIL: Move getOverriddenVTableEntry() from TypeLowering to SILDeclRef
There's no reason for this to be an instance method on the TypeLowering
object, because it (no longer?) uses any type lowering operations.
2017-12-18 23:28:33 -08:00
Michael Gottesman 62e6d2f65d [silgen] Teach emitApplyOfLibraryIntrinsic how to convert arguments to the appropriate +0/+1 convention.
Sometimes we need to copy/borrow now.

*NOTE* right now it is basically impossible to test this using a fake stdlib
since I would need to implement Array or String in my local stdlib since this
comes up via ArrayToPointer/friends. If/when we flip the switch though, this is
guaranteed to be tested by stdlib dependent tests that we already have in tree.

rdar://34222540
2017-12-05 12:59:10 -08:00
Slava Pestov 1f79af7504 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 16:26:43 -08:00
Arnold Schwaighofer ea9907ae15 Revert "SIL: Use objc_method instruction for Objective-C protocol method calls" 2017-11-29 11:19:46 -08:00
Slava Pestov 1ee0970934 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 01:22:05 -08:00
Arnold Schwaighofer 3e04f21a41 SIL: Remove EnableGuaranteedClosureContext now that it is the default 2017-11-27 07:25:03 -08:00
Slava Pestov 8f10485798 SILGen: Tighten up assertions 2017-11-19 23:58:48 -05:00
Michael Gottesman 04056ce243 [silgen] When emitting convertBridgeObjectToRef, forward ownership through the instruction rather than unconditionally adding a cleanup.
Otherwise, we may put cleanups on borrowed values.

rdar://34222540
2017-11-19 16:00:45 -08:00
Arnold Schwaighofer ce2966dd6e Merge pull request #12957 from aschwaighofer/callee_guaranteed_closures
SILGen: Remaining fixes for @callee_guaranteed closures and enable it
2017-11-16 11:12:54 -08:00
Slava Pestov 75fe659eab SILGen: Fix a warning 2017-11-15 22:52:28 -08:00
Arnold Schwaighofer 0971d82f70 SILGen: Remaining fixes for @callee_guaranteed closures and enable it
- Fix block to func reabstraction thunks block argument handling
- Forward cast ownership
- Fix applyPartiallyAppliedSuperMethod ownership for @callee_guaranteed closures
- Avoid a copy in buildBlockToFuncThunkBody
- Update tests for callee_guaranteed closures

SR-5441
rdar://33255593
2017-11-15 19:46:08 -08:00
Arnold Schwaighofer 982db5ac39 Merge pull request #12866 from aschwaighofer/fix_silgen_emit_dynamic_partial_apply
SILGen: With @callee_guaranteed closures emitDynamicPartialApply will…
2017-11-12 07:05:33 -08:00
Arnold Schwaighofer f60f95e5ce SILGen: With @callee_guaranteed closures emitDynamicPartialApply will leave a
cleanup for the closure context that needs to be cleared

SR-5441
rdar://33255593
2017-11-10 17:29:34 -08:00
swift-ci 2996e332b4 Merge pull request #12861 from adrian-prantl/35430708 2017-11-10 16:33:21 -08:00
Adrian Prantl b998c103fc Debug Info: Associate a function call with the beginning of the expression.
Before this change, stepping through the code
  1 foo(x,
  2     f(a)
  3     f(b)
  4   )

would visit the code in the order 2, 3, 4, with the function call
being on line 4.  After this patch the order is 2, 3, 1 with the
function call being on line 1. This is both closer to what clang
generates for simialar C code and more useful to the programmer since
it is easier to understand which function is being called in a nested
expression.

rdar://problem/35430708
2017-11-10 14:37:47 -08:00
Slava Pestov 17da172b01 SILGen: Factor out SILGenFunction::emitClassMethodRef() 2017-11-08 21:27:31 -08:00
Slava Pestov 24ec007d73 SILGen: Remove "assume +0" hack
Now that we emit the callee at the right time, we no longer need
to force emit the 'self' argument source at +0 and possibly
convert it to +1 later.

This is NFC, except it means we end_borrow the self value a bit
sooner sometimes, which is a good thing.
2017-11-08 21:27:30 -08:00
Slava Pestov 661069430c SILGen: Simplify SILGenApply::visitDeclRefExpr() 2017-11-08 19:18:07 -08:00
Slava Pestov 5fd8e71ace SILGen: More dynamic method call cleanup 2017-11-08 01:31:56 -08:00
Slava Pestov 2a0cb060f8 SILGen: Look up the callee method after evaluating arguments 2017-11-08 01:31:55 -08:00
Slava Pestov cb75ab74f6 SILGen: Simplify AnyObject dispatch logic a bit 2017-11-07 16:10:06 -08:00
Slava Pestov 806935ccbb SILGen: Remove a usage of the callee ManagedValue before emitting arguments
Ideally we would evaluate arguments before the callee value,
but more changes have to happen before that.
2017-11-07 16:09:35 -08:00
swift-ci 69a6e5e260 Merge pull request #12789 from rjmccall/sil-coroutines 2017-11-07 03:22:22 -08:00
John McCall 5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Slava Pestov ced25fb0d7 SILGen: Remove more references to the 'uncurry level' concept 2017-11-06 18:48:20 -08:00
Slava Pestov e2e73d2711 SILGen: Clean up some duplication in getConstantAtUncurryLevel() and getTypeInfoAtUncurryLevel() 2017-11-06 18:28:06 -08:00
Arnold Schwaighofer f352ef1839 Merge pull request #12719 from aschwaighofer/silgen_callee_guaranteed
SILGen: Conditionally use @callee_guaranteed contexts
2017-11-03 12:21:54 -07:00