Commit Graph

1246 Commits

Author SHA1 Message Date
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
Arnold Schwaighofer
b25344b02b SILGen: Conditionally use @callee_guaranteed contexts
We need to borrow guaranteed values with sil ownership and need to
distinguish between @callee_guaranteed and other context conventions in
a few places.

SR-5441
rdar://33255593
2017-11-03 07:09:50 -07:00
Huon Wilson
0236db7be1 [SIL] Witness methods store the conformance from which they come. 2017-11-01 11:33:26 -07:00
Slava Pestov
73311c61f8 SILGen: Use ManagedValue variant of createAllocRefDynamic(), NFC
Also, enable the SIL ownership verifier for test/SILGen/objc_protocols.swift.
2017-10-24 18:17:53 -07:00
Slava Pestov
045c6496ff SILGen: Fix memory leak when calling constructor requirement of @objc protocol
Fixes <rdar://problem/30478887> / <https://bugs.swift.org/browse/SR-3935>.
2017-10-21 01:42:51 -07:00
Doug Gregor
cd3c63cbfd [AST] Stop including GenericSignature.h in other headers.
Except GenericEnvironment.h, because you can't meaningfully use a
GenericEnvironment without its signature. Lots less depends on
GenericSignature.h now. NFC
2017-10-12 14:23:46 -07:00
Robert Widmann
053164be0c [NFC] Remove dead code in EnumElement construction
Seems to have been copied and pasted from the other
apply paths but its condition is directly refuted by
an assert.
2017-10-12 03:02:54 -04:00
Slava Pestov
514aa991b3 SILGen: Clean up SILGenApply a bit 2017-10-04 03:53:16 -07:00
Slava Pestov
e806b6248d SIL: Remove dynamic_method instruction 2017-10-04 03:53:16 -07:00
Slava Pestov
7bf3b90b62 SIL: Split off objc_method / objc_super_method from class_method / super_method
This replaces the '[volatile]' flag. Now, class_method and
super_method are only used for vtable dispatch.

The witness_method instruction is still overloaded for use
with both ObjC protocol requirements and Swift protocol
requirements; the next step is to make it only mean the
latter, also using objc_method for ObjC protocol calls.
2017-10-03 22:13:31 -07:00
Slava Pestov
a85f602636 SILGen: Clean up class_method instruction construction a bit 2017-10-03 18:48:19 -07:00