Commit Graph

354 Commits

Author SHA1 Message Date
Joe Groff
77a0923ca6 SILGen: Emit convenience initializers as allocating entry points.
And only dispatch designated inits by their allocating entry points. rdar://problem/29634243
2018-09-13 12:31:23 -07:00
Slava Pestov
c69d43e87d SILGen: Fix crash when emitting foreign-to-native thunk for allocating init in -swift-version 5
This comes up when we import a static factory method as a convenience init.
The thunk was using DynamicSelfType as the type of a basic block argument,
because that was the type of the 'self' parameter in -swift-version 5.

Fixes <rdar://problem/44242156>.
2018-09-11 15:22:30 -07:00
John McCall
6d4c724101 Distinguish different kinds of l-value reads in SILGen.
This is NFC for now, but I plan to build on this to (1) immediately
remove some unnecessary materialization and loads of the base value
and (2) to allow clients to load a borrowed value.
2018-08-30 19:42:53 -04:00
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
Slava Pestov
dd3364a7d1 SIL: Add AbstractionPattern::getFunctionParamType()
I will need to rip out AbstractionPattern::getFunctionInputType().
This is the eventual replacement.
2018-08-18 01:54:18 -04:00
Michael Gottesman
53403e29ac [+0-all-args] Remove the SILOption EnableGuaranteedNormalArguments and minimally simplify code.
I made this change by removing the SILOption and then doing a compile, fix loop. I
purposely did not move around the code to make the refactoring really easy to
see.
2018-07-29 20:15:51 -07:00
Slava Pestov
e606aad80f SILGen: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 22:09:13 -07:00
Doug Gregor
d9faa7415c [Type Checker] Add a request kind for ‘dynamic’.
Separate out the semantic state for the ‘dynamic’ check (from the
presence of the attribute), and move all of the computation of the
‘dynamic’ bit into the request-evaluator.

In the process, this fixes a bug where implicitly-synthesized initializers
in subclasses of imported classes would not be implicitly made ‘final’.
2018-07-18 14:50:39 -07:00
Slava Pestov
45fb11ce3c AST: Add ExistentialLayout::getSuperclass(), rename superclass to explicitSuperclass
More groundwork for protocols with superclass constraints.
In several places we need to distinguish between existential
types that have a superclass term (MyClass & Proto) and
existential types containing a protocol with a superclass
constraint.

This is similar to how I can write 'AnyObject & Proto', or
write 'Proto1 & Proto2' where Proto1 has an ': AnyObject'
in its inheritance clause.

Note that some of the usages will be revisited later as
I do more refactoring and testing. This is just a first pass.
2018-07-02 22:06:33 -07:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Joe Groff
55706bfd44 SILGen: Pseudogeneric partial applications do not produce pseudogeneric results.
partial_apply always fully applies the generic environment, so the result is not generic at all. Fixes rdar://problem/41474371 | SR-8107.
2018-06-27 09:25:01 -07:00
Arnold Schwaighofer
b9728151df SILGen: Fix no escape verification if the closure throws an exception
It is safe to omit the retain/release dance in the reabstraction thunk
because we know we have an aditional reference outstanding for the
is_escaping verification.

The problem with throwing an objc exception inside a noescape closure is
that we verify the reference count of the closure sentinel. The
reabstraction thunk would increase the reference count call the
implementation function that then throws skipping the decrement.

rdar://40857699
2018-06-08 13:04:52 -07:00
Slava Pestov
d8fc9decf9 AST: Remove GenericSignature::getSubstitutionMap() 2018-05-28 19:45:28 -07:00
Doug Gregor
cb3bf10d62 [SILGen] Eliminate SubstitutionList from SILGenFunction::emitApply(). 2018-05-11 17:37:27 -07:00
Doug Gregor
c9b50e0171 [SILGen] Eliminate SubstitutionList from the LValue infrastructure. 2018-05-11 17:37:27 -07:00
Doug Gregor
4b5abbddbc [SIL] Teach *ApplyInst to traffic in SubstitutionMap.
Push SubstitutionMaps through most of SILGen and the SIL optimizers
that involve the various *ApplyInsts.
2018-05-11 13:18:06 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Doug Gregor
d5c9f71a6d [SIL] Switch InitBlockStorageHeaderInst over to SubstitutionMap. 2018-05-03 08:48:54 -07:00
Doug Gregor
d2cf60c465 Revert "[SIL] Replace more SubstitutionLists with SubstitutionMap" 2018-05-03 08:35:20 -07:00
Doug Gregor
216906cf59 [SIL] Switch InitBlockStorageHeaderInst over to SubstitutionMap. 2018-05-03 00:05:21 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
Arnold Schwaighofer
544cf1a64f SILGen: Emit withoutActuallyEscaping verification for @noescape closures stored in blocks
rdar://39682865
2018-05-01 07:24:19 -07:00
Arnold Schwaighofer
e36655fddc SILGen: Remove PostponedCleanup in favor or the SIL pass that fixes
closure lifetimes.

SILGen will now unconditionally emit

  %cvt = convert_escape_to_noescape [guaranteed] %op

instructions. The mandatory ClosureLifetimeFixup pass ensures that %op's
lifetime spans %cvt's uses.

The code in DefiniteInitialization that handled a subset of cases is
removed.
2018-04-13 13:44:09 -07:00
Arnold Schwaighofer
36d5408125 SIL: Add an [escaped] attribute to convert_escape_to_noescape instruction
To mark when a user of it is known to escape the value. This happens
with materializeForSet arguments which are captured and used in the
write-back. This means we need to keep the context alive until after
the write-back.

Follow-up patches to fully replace the PostponedCleanup hack in SILGen
by a mandatory SIL transformation pass to guarantee the proper lifetime
will use this flag to be more conservative when extending the lifetime.

The problem:

%pa = partial_apply %f(%some_context)
%cvt = convert_escape_to_noescape [not_guaranteed] [escaped] %pa
%ptr = %materialize_for_set(..., %cvt)
...  write_back
... // <-- %pa needs to be alive until after write_back
2018-04-13 12:40:10 -07:00
Joe Groff
e49fa5c4db SILGen: Guard against unexpected nulls passed into ObjC overrides.
We want to treat arguments to ObjC override and protocol conformance thunks like "call results", since they might be called from ObjC code that doesn't fulfill its nullability promises in practice. Fixes SR-7240 | rdar://problem/38675815.
2018-03-23 16:04:29 -07:00
Doug Gregor
b8efde988f [SILGen] Fix ownership handling for createConvertEscapeToNoEscape().
Introduce SILGenBuilder::createConvertEscapeToNoEscape() to correctly handle
ownership, and switch all relevant callers to it.
2018-03-20 13:02:49 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
Michael Gottesman
9cc1fcc2b2 [+0-normal-args] Update some bridging code to use SILGenBuilder APIs so cleanups are on the cast result, not the cast operand.
Found with the ownership verifier when fixing objc_bridging_any.swift for +0 arguments.
2018-03-11 23:49:51 -07:00
Michael Gottesman
e27c8c8ca5 [+0-normal-args] When building the bodies of thunks, be sure to convert from +0 to +1.
Caught by the ownership verifier on the file test/SILGen/objc_currying.swift
when compiling with +0 enabled.

rdar://34222540
2018-02-28 13:58:41 -08:00
Michael Gottesman
1f15ebfbdd [+0-all-args] Use SILGenBuilder APIs when converting bridged to native errors.
By using this API, we properly forward ownership when we perform this
conversion. Previously if we had a guaranteed bridged error argument, we would
wrap the bridged error argument in an class existential box and then destroy
that box, violating the +0 contract. Instead now we forward the ownership
correctly through the init_existential_ref.

Found while updating SILGen tests for +0 arguments.

rdar://34222540
2018-02-28 12:30:21 -08:00
Michael Gottesman
80dabe966c [+0-all-args] Verify thunks right after we generate their bodies.
Previously, we were not verifying these thunks later in the pipeline. This makes
it harder to track down verifier errors in such thunks. Instead, this PR just
moves the thunk verification to right after we generate the thunk body,
i.e. right after the bad code would have been emitted.

Found while debugging test/SILGen/objc_bridging_any.swift for +0-all-args.

rdar://34222540
2018-02-23 13:58:42 -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
Mark Lacey
3654dcc8fe Remove getImplicitlyUnwrappedOptionalObjectType. 2018-02-03 10:57:11 -08: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
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
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
John McCall
898739489c Merge pull request #13078 from rjmccall/bridging-peephole-optionality-bug
Don't naively apply the bridging peephole to AnyObject? -> Any? -> AnyObject
2017-11-27 20:22:54 -05:00
John McCall
549efbc240 Don't naively apply the bridging peephole to AnyObject? -> Any? -> AnyObject.
Also, fix some logic in the peephole that was incorrectly recognizing
T? -> U? -> AnyObject as a force instead of a request to create NSNull.

In both cases, we ought to still be able to do much better than the
unpeepholed code by just applying the peephole and then merging in NSNull
in the nil case, but in the short term we need to fix this bug.

Fixes rdar://35402853
2017-11-27 19:33:38 -05:00
Michael Gottesman
35fd24ed74 [+0-all-args] Create SILGenBuilder::createTuple().
This takes a series of ManagedValues and combines them together into 1 tuple. It
assumes that all non-trivial ManagedValues are all at +1 or all at +0. It leaves
the verification to the ownership verifier since this would immediately trigger
the ownership verifier when the instruction is created by the SILBuilder.

rdar://34222540
2017-11-27 16:20:21 -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
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
cce30cc9bb SIL: Remove SILFunction::mapTypeOutOfContext() 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
John McCall
f9e28aff2a When building a block-to-func reabstraction thunk, be sure to bridge
the block's formal parameter and result types, because otherwise
the bridging code gets real confused.

Fixes rdar://35402696
2017-11-15 03:10:29 -05:00
Slava Pestov
76391cbcbb SILGen: Fix bridging of optional function types to AnyObject
Fixes <rdar://problem/35403187>.
2017-11-13 17:37:15 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00