Commit Graph

555 Commits

Author SHA1 Message Date
Arnold Schwaighofer
89e972f5a8 SILGen: Implement withoutActuallyEscaping verification
Check that an ``withoutActuallyEscaping(noescape_closure) { // scope}`` closure
has not escaped in the scope using the ``is_escaping_closure %closure``
instruction.

rdar://35525730
2018-03-07 09:00:12 -08:00
Pavel Yaskevich
cddb82165b [SILGen] Add support thunk support for () -> T to () -> Void conversions 2018-03-01 12:48:14 -08:00
swift-ci
777241513b Merge pull request #14641 from gottesmm/pr-3aaad2fed3dce4737ba129e61694d0530d801995 2018-02-14 13:56:55 -08:00
swift-ci
de617e7f0d Merge pull request #14638 from gottesmm/pr-e1619ccbacf71f7743e6bdab88cdb0d6ad7708b1 2018-02-14 11:11:14 -08:00
Michael Gottesman
499e59c10f [+0-normal-args] When initializating an Any with trivial inline buffer contents, put a cleanup on the Any.
Otherwise, it looks like we are storing a non-trivial value (Any) to memory
without a +1 cleanup, violating invariants. The change itself is harmless since
destroying an Any containing only trivial things in the inline buffer is a
no-op.

This is the last change I need to enable the only +1 into memory assert.

rdar://34222540
2018-02-14 10:31:31 -08:00
Michael Gottesman
223b9aeaf9 [gardening] Update some code to use more modern SILGenBuilder APIs. 2018-02-14 10:31:30 -08:00
Michael Gottesman
0607ee1d83 [+0-normal-args] When forcing an argument into memory when performing a translating transform thunk, make sure it is at +1.
Fixes an issue where it was possible for a +0 pointer from an argument to get to
this thunk transform code. This is significantly more likely to happen when all
arguments are at +0.

This is tested by a SILGen test that I updated out of tree. It shouldn't effect
normal +1 code.

rdar://34222540
2018-02-14 09:36:12 -08:00
Arnold Schwaighofer
a9fa8c9c2b Merge pull request #14514 from aschwaighofer/wip_closure_capture_abi_part2
WIP: Closure ABI - Make @noescape Swift closures trivial
2018-02-14 05:19:25 -08:00
Michael Gottesman
8a7e652e81 [+0-normal-args] Change SILGenFunction::emitDynamicMethodRef to return a ManagedValue.
There are a bunch of methods in this area that do not use ManagedValues, but
that should. This is another step towards unwinding the hairball.

rdar://34222540
2018-02-13 13:11:11 -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
d63bb3fc53 Remove most uses of OptionalTypeKind.
What remains are places where we are conflating optionality with
either nullability or failability.
2018-02-10 16:24:09 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Mark Lacey
f08823757a IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T>.
Stop creating ImplicitlyUnwrappedOptional<T> so that we can remove it
from the type system.

Enable the code that generates disjunctions for Optional<T> and
rewrites expressions based on the original declared type being 'T!'.

Most of the changes supporting this were previously merged to master,
but some things were difficult to merge to master without actually
removing IUOs from the type system:
- Dynamic member lookup and dynamic subscripting
- Changes to ensure the bridging peephole still works

Past commits have attempted to retain as much fidelity with how we
were printing things as possible. There are some cases where we still
are not printing things the same way:
- In diagnostics we will print '?' rather than '!'
- Some SourceKit and Code Completion output where we print a Type
  rather than Decl.

Things like module printing via swift-ide-test attempt to print '!'
any place that we now have Optional types that were declared as IUOs.

There are some diagnostics regressions related to the fact that we can
no longer "look through" IUOs. For the same reason some output and
functionality changes in Code Completion. I have an idea of how we can
restore these, and have opened a bug to investigate doing so.

There are some small source compatibility breaks that result from
this change:
- Results of dynamic lookup that are themselves declared IUO can in
  rare circumstances be inferred differently. This shows up in
  test/ClangImporter/objc_parse.swift, where we have
    var optStr = obj.nsstringProperty
  Rather than inferring optStr to be 'String!?', we now infer this to
  be 'String??', which is in line with the expectations of SE-0054.
  The fact that we were only inferring the outermost IUO to be an
  Optional in Swift 4 was a result of the incomplete implementation of
  SE-0054 as opposed to a particular design. This should rarely cause
  problems since in the common-case of actually using the property rather
  than just assigning it to a value with inferred type, we will behave
  the same way.
- Overloading functions with inout parameters strictly by a difference
  in optionality (i.e. Optional<T> vs. ImplicitlyUnwrappedOptional<T>)
  will result in an error rather than the diagnostic that was added
  in Swift 4.1.
- Any place where '!' was being used where it wasn't supposed to be
  allowed by SE-0054 will now treat the '!' as if it were '?'.
  Swift 4.1 generates warnings for these saying that putting '!'
  in that location is deprecated. These locations include for example
  typealiases or any place where '!' is nested in another type like
  `Int!?` or `[Int!]`.

This commit effectively means ImplicitlyUnwrappedOptional<T> is no
longer part of the type system, although I haven't actually removed
all of the code dealing with it yet.

ImplicitlyUnwrappedOptional<T> is is dead, long live implicitly
unwrapped Optional<T>!

Resolves rdar://problem/33272674.
2018-01-31 12:15:58 -08:00
Mark Lacey
b65f1948c7 Revert "IUO: Convert an explicit check for IUO to check for any optional." 2018-01-09 17:59:51 -08:00
Mark Lacey
65aa56595f IUO: Convert an explicit check for IUO to check for any optional.
We should only ever reach this point with an input type that is
optional and output type that is non-optional if in fact the input
type was originally declared as IUO. If we were to hit this point
today with a plain optional, we end up eventually hitting the
llvm_unreachable at the end of the function.
2018-01-09 08:56:02 -08:00
Slava Pestov
dde7917a0f SILGen: Don't emit spurious warning with a Never-returning protocol witness thunk
Fixes <https://bugs.swift.org/browse/SR-2729>.
2018-01-05 23:41:41 -08:00
Slava Pestov
38dfe296e9 SILGen: Remove selfType parameter from SILGenFunction::emitProtocolWitness() 2018-01-04 21:53:35 -08:00
Slava Pestov
5bf63b2a82 SILGen: Simplify getWitnessDispatchKind() 2018-01-04 21:53:34 -08:00
Michael Gottesman
5f5ed55741 [silgen] When emitting a curry thunk, if the canonical type of the function differs from the actual function type in a non-ABI compatible way, use a canonical function thunk instead of a convert_function.
convert_function can only be used for to convert in between ABI compatible
functions.

rdar://34222540
2017-12-30 18:41:37 -05:00
Michael Gottesman
c62caf6644 [silgen] Simplify code to use SILGenBuilder. 2017-12-12 13:15:35 -08:00
Pavel Yaskevich
515520e524 [CSSolver/SILGen] Fix solver to support function conversion with collection subtyping
Fix collection subtyping relation in function argument position
by emiting special re-abstraction thunk with collection upcast.

Resolves: rdar://problem/35702810
2017-11-30 16:47:18 -08:00
swift-ci
20d770181d Merge pull request #13172 from gottesmm/pr-99b23ece87bbb2aff6590a2488b6179dfd5ff517 2017-11-30 10:59:48 -08:00
Michael Gottesman
497b62df8d [+0-all-args] PartialApply always takes parameters at +1. Use an ensurePlusOne to make sure we create a copy if we need to.
rdar://34222540
2017-11-30 09:59:41 -08:00
John McCall
364178f6f1 Blocks can only be converted to AnyObject with a cast under ObjCInterop.
I don't think there's a way to test this right now because we don't
actually support SwiftValue and so on except under ObjCInterop, but
it's certainly more future-proof.
2017-11-29 17:03:33 -05:00
John McCall
ad0f8ab3b2 Weaken an assertion: conversions can go through Any but still end up
at AnyObject?.

Also, ensure that @convention(block) functions can be erased to
AnyObject, and teach SILGen how to do this with unchecked_ref_cast.

Fixes a source compatibility suite regression.
2017-11-29 02:58:04 -05:00
Arnold Schwaighofer
3e04f21a41 SIL: Remove EnableGuaranteedClosureContext now that it is the default 2017-11-27 07:25:03 -08:00
Slava Pestov
8167946102 SILGen: Remove unnecessary 'inout difference' check in protocol witness emission 2017-11-20 12:59:03 -05:00
Slava Pestov
e688da3b88 SILGen: Allow +0 parameter forwarding in protocol witness and re-abstraction thunks 2017-11-20 00:37:38 -05:00
Slava Pestov
b9f22aec15 SILGen: Fix loadable +0 to +1 reabstraction 2017-11-19 23:58:49 -05:00
Slava Pestov
1460f6023a SILGen: Use emitShallowDestructure{Value,Address}Operation() when re-abstracting tuples 2017-11-19 23:58:49 -05:00
Slava Pestov
8f10485798 SILGen: Tighten up assertions 2017-11-19 23:58:48 -05:00
Slava Pestov
cce30cc9bb SIL: Remove SILFunction::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Slava Pestov
f07cde75e7 AST: Move mapTypeOutOfContext() from GenericEnvironment to TypeBase
It doesn't actually *use* the generic environment.
2017-11-15 22:52:13 -08:00
Arnold Schwaighofer
197f585e80 Merge pull request #12876 from aschwaighofer/silgen_fix_callee_guaranteed_lvalue_capture
SILGen: Fix @callee_guaranteed prolog emission for captured l-values
2017-11-12 07:05:51 -08:00
Arnold Schwaighofer
8ea33dff0c SILGen: Fix @callee_guaranteed prolog emission for captured l-values
We need to deallocate the copy we created in the temporary location.

... and properly forward cleanup after inserting a convert_function
instruction. This didn't come up before because closures where consumed
by the ultimate apply in the chain and no compensating destroy was
neccessary.

SR-5441
rdar://33255593
2017-11-11 10:39:41 -08:00
Arnold Schwaighofer
68d0a8774a SIL: Make adjustFunction type of closures parameterized on whether we use
guaranteed closures

This is going to go away once we change the default to guaranteed
closures.

SR-5441
rdar://33255593
2017-11-10 15:18:01 -08:00
Huon Wilson
4a2d422185 Merge pull request #12531 from huonw/conditional-conformance-irgen
IRGen for conditional conformances
2017-11-10 14:01:51 -08:00
Slava Pestov
17da172b01 SILGen: Factor out SILGenFunction::emitClassMethodRef() 2017-11-08 21:27:31 -08:00
Huon Wilson
99c4cddfca [SILGen] Store conditional conformances in SILWitnessTables. 2017-11-08 17:02:50 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05: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
Andrew Trick
d369aa4070 Support @noescape SIL function types. (#12420)
Support for @noescape SILFunctionTypes.

These are the underlying SIL changes necessary to implement the new
closure capture ABI.

Note: This includes a change to function name mangling that
primarily affects reabstraction thunks.

The new ABI will allow stack allocation of non-escaping closures as a
simple optimization.

The new ABI, and the stack allocation optimization, also require
closure context to be @guaranteed. That will be implemented as the
next step.

Many SIL passes pattern match partial_apply sequences. These all
needed to be fixed to handle the convert_function that SILGen now
emits. The conversion is now needed whenever a function declaration,
which has an escaping type, is passed into a @NoEscape argument.

In addition to supporting new SIL patterns, some optimizations like
inlining and SIL combine are now stronger which could perturb some
benchmark results.

These underlying SIL changes should be merged now to avoid conflicting
with other work. Minor benchmark discrepancies can be investigated as part of
the stack-allocation work.

* Add a noescape attribute to SILFunctionType.

And set this attribute correctly when lowering formal function types to SILFunctionTypes based on @escaping.

This will allow stack allocation of closures, and unblock a related ABI change.

* Flip the polarity on @noescape on SILFunctionType and clarify that
we don't default it.

* Emit withoutActuallyEscaping using a convert_function instruction.

It might be better to use a specialized instruction here, but I'll leave that up to Andy.

Andy: And I'll leave that to Arnold who is implementing SIL support for guaranteed ownership of thick function types.

* Fix SILGen and SIL Parsing.

* Fix the LoadableByAddress pass.

* Fix ClosureSpecializer.

* Fix performance inliner constant propagation.

* Fix the PartialApplyCombiner.

* Adjust SILFunctionType for thunks.

* Add mangling for @noescape/@escaping.

* Fix test cases for @noescape attribute, mangling, convert_function, etc.

* Fix exclusivity test cases.

* Fix AccessEnforcement.

* Fix SILCombine of convert_function -> apply.

* Fix ObjC bridging thunks.

* Various MandatoryInlining fixes.

* Fix SILCombine optimizeApplyOfConvertFunction.

* Fix more test cases after merging (again).

* Fix ClosureSpecializer. Hande convert_function cloning.

Be conservative when combining convert_function. Most of our code doesn't know
how to deal with function type mismatches yet.

* Fix MandatoryInlining.

Be conservative with function conversion. The inliner does not yet know how to
cast arguments or convert between throwing forms.

* Fix PartialApplyCombiner.
2017-10-17 13:07:25 -07:00
Doug Gregor
cb3d6d13c9 Minor simplifications suggested by Slava 2017-10-10 10:01:39 -07:00
Doug Gregor
a11f9c36a0 [AST] Remove ModuleDecl from TypeBase::getCanonicalType(). 2017-10-10 10:01:39 -07:00
Doug Gregor
936a701b15 [AST] Stop uniquing canonical GSBs based on the module.
Now that the GenericSignatureBuilder is no longer sensitive to the input
module, stop uniquing the canonical GSBs based on that module. The main
win here is when deserializing a generic environment: we would end up 
creating a canonical GSB in the module we deserialized and another
canonical GSB in the module in which it is used.
2017-10-10 09:41:23 -07:00
Doug Gregor
ef542ffd8a [GSB] Eliminate the stored LookupConformanceFn to the GSB.
Implement a module-agnostic conformance lookup operation within the GSB
itself, so it does not need to be supplied by the code constructing the
generic signature builder. This makes the generic signature builder
(closer to) being module-agnostic.
2017-10-10 09:41:23 -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