Commit Graph

582 Commits

Author SHA1 Message Date
swift-ci
48eb400a93 Merge pull request #17826 from brentdax/public-optional 2018-07-20 14:12:55 -07:00
Arnold Schwaighofer
a3fd504025 SILGen: When transforming to AnyHashable materialize the value in a temporary
emitAnyHashable expects an address value.

rdar://40583597
2018-07-13 07:08:10 -07:00
Brent Royal-Gordon
919121a048 Make IUO unwraps in thunks use the IUO message
@jckarter pointed out that force unwraps emitted in thunks are always for IUOs and should use the implicit unwrap message.
2018-07-12 19:09:57 -07:00
Brent Royal-Gordon
b6e35038b2 [SILGen] Output a different message for failed IUO force-unwraps
Modifies SILGen and the `Swift._diagnoseUnexpectedNilOptional` call to print a slightly different message for force unwraps which were implicitly inserted by the compiler for IUOs. The message is chosen based on the presence of certain flags in the `ForceValueExpr`, not on the type of the value being unwrapped.
2018-07-12 19:09:56 -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
Arnold Schwaighofer
fd62f871fc SILGen: createWithoutActuallyEscapingClosure needs to use a substitution map in the context of the current generic enviroment
We used a substitution map derived from a thunk that might have been
created in a different function if that other function used the same
thunk type.
Instead use a substitution map that was derived from the
current functions generic environment.

rdar://41331672
SR-8064
2018-06-22 12:29:37 -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
Slava Pestov
b7b30bc6fb SILGen: Don't emit unreachable code warnings for result re-abstraction in witness thunks 2018-06-04 22:34:39 -07:00
Slava Pestov
a500390f03 SILGen: Fix invalid SIL emitted when protocol requirement witnessed by base class convenience init
If the derived class is final and the base class is not, the
protocol requirement can be witnessed by a non-required
initializer. Non-required initializers have initializing
but not allocating entry points in the vtable.

The fix here statically dispatches to the allocating
initializer instead. The test verifies that the allocating
entry point uses alloc_ref_dynamic, so you will get an
instance of the correct subclass.

This fix does not handle the resilient case where the
conformance is defined in a different module, and the original
module adds an override of the convenience init later.
I filed <rdar://problem/40639124> to track the resilient case.

Fixes <rdar://problem/40003840>.
2018-05-29 20:36:39 -07:00
Slava Pestov
d8fc9decf9 AST: Remove GenericSignature::getSubstitutionMap() 2018-05-28 19:45:28 -07:00
Doug Gregor
049c56dde6 Eliminate getForwardingSubstitutions().
Use the SubstitutionMap version everywhere.
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
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
Arnold Schwaighofer
b510227224 SILGen: Remove variable with negated name: 2018-03-30 08:51:06 -07:00
Arnold Schwaighofer
3ab1580cf9 SILGen: Don't postpone the cleanup of the convertEscapeToNoEscape inside an bind optional
This would violate dominance since the convertEscapeToNoEscape
instruction does not dominate the postpone point.

rdar://38124009
2018-03-30 06:20:13 -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
Slava Pestov
b61255c2b8 SILGen: Simplify buildWithoutActuallyEscapingThunkType() 2018-03-18 00:13:55 -07:00
Slava Pestov
85f2dc309f SILGen: Remove some unnecessary substitution map gymnastics from withoutActuallyEscaping thunk 2018-03-18 00:13:55 -07:00
Mark Lacey
85f25003ce Replace uses of getOptionalObjectType(bool &).
Instead, use the one that doesn't have a reference parameter.
2018-03-16 21:19:49 -07:00
Michael Gottesman
69b38b629d [silgen] When emitting a vtable thunk, verify the thunk after emission rather than when we tear down the SILGenModule.
This makes it easier to find bugs in the vtable thunk emission code since we
just error right where we emit the thunk.
2018-03-15 14:30:59 -07:00
Michael Gottesman
8b1d38aba8 [+0-normal-args] When transforming, be sure to use SILGenBuilder APIs to ensure that cleanups are properly forwarded.
Caught by the ownership verifier when updating objc_bridging_peephole.swift for +0 args.
2018-03-11 23:49:51 -07:00
Arnold Schwaighofer
1e4f55de8d Merge pull request #15046 from aschwaighofer/without_actually_escaping_verification
Implement withoutActuallyEscaping verification
2018-03-09 09:34:06 -08:00
Michael Gottesman
8af8e4f7c7 [+0-all-args] Fix SILGenBuilder::createFunctionInputArgument(...) for in_guaranteed parameters
This method was not distinguishing in between in_guaranteed and in
parameters. This would cause the curry thunk where this is used to not copy
in_guaranteed parameters before passing in the parameter to the
partial_apply. This can not affect +1 code since the curry thunk will always
have self at +1.

I also refactored code in:

1. SILGenPoly.
2. SILGenProlog.
3. SILGenConstructor.

to use this function instead of their own reimplementations of the same thing.

This should be NFC for +1 code and is tested by test updates when +0 is enabled.

rdar://34222540
2018-03-08 16:51:38 -08:00
Pavel Yaskevich
d8b355dbae Revert "[CSSolver] Use correct locator when matching function result types re…" 2018-03-07 23:19:30 -08:00
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