Commit Graph

893 Commits

Author SHA1 Message Date
John McCall
2d5276d84d Clean up l-value emission in SILGen.
There were several bits of code which were unnecessarily
repeating the core logic of breaking down an access strategy
and either setting up an LValue or directly emitting it.
These places have now been unified to just create and then
load or othrwise use an LValue.

Introduce a visitor which handles the common parts of breaking
down an access strategy and computing information like the
LValueTypeData.  In addition to its direct benefits (which are
somewhat lost in the boilerplate of capturing local state into
the visitor subclass), this eliminates some of the ad-hocness
of how the various emission paths use AccessStrategy.

Finally, implement the MaterializeToTemporary strategy in its
full generality by using the actual read and write sub-strategies
instead of always falling back on calling the getter and setter.
This part is not NFC because it causes us to perform the read
part of a read/write to a stored-with-observers property by
directly accessing the storage instead of calling the getter.
2018-07-19 22:06:04 -04:00
Joe Groff
3474079988 SILGen: Delay function conversions to types with opened archetype arguments.
This comes up when invoking protocol methods on an existential that have covariant arguments of function type with Self arguments, e.g.:

```swift
protocol P {
  mutating func foo(_: (Self) -> Void)
}
func bar(x: inout P) {
  x.foo { y in return }
}
```

Although the type-erased method is presented as formally taking an argument of the existential type P, it still has a conversion thunk to perform type erasure on the argument coming from the underlying implementation. Since the `self` argument is inout, it isn't formally opened until late when formal accesses begin, so this closure conversion must also be deferred until after that occurs.
2018-07-19 12:58:06 -07:00
swift-ci
99858b71a5 Merge pull request #17759 from CodaFi/SILly-inputs 2018-07-05 13:09:22 -07:00
Robert Widmann
a79c11f5d8 Drop more uses of getInput() from SIL 2018-07-05 10:52:41 -07:00
John McCall
a3bdc89d47 Tell cleanups whether they're being emitted for the normal or unwind path.
NFC, but this may become semantically important for coroutines, because
an active coroutine must be aborted instead of ended on the unwind path.
2018-07-05 02:48:41 -04:00
Ben Cohen
2b04e9f105 Suppress a number of warnings in no-assert builds (#17721)
* Supress a number of warnings about things used only in asserts

* Re-use a couple of variables instead of supressing the warning
2018-07-04 07:15:14 -07:00
John McCall
20bfb72926 Enter unsafe begin_access scopes after calling addressors and
materializeForSet.
2018-06-28 17:05:09 -07:00
Slava Pestov
195577813b SIL: Remove type lowering support for InOutType
There is still some unfortunate hackery around InOutType in
SILGenProlog.cpp, but I don't want to clean it up yet.
2018-06-13 15:38:52 -07:00
Slava Pestov
e79119de06 SILGen: Don't emit unreachable code warnings for functions returning Never indirectly 2018-06-04 22:34:53 -07:00
Slava Pestov
d01b31e4b9 SILGen: Remove a usage of the "bad" SubstitutionMap::get() variant
The only time the generic signature of the callee won't
match the generic signature of the substitution map is when
the callee is a non-generic closure inside a generic context.

Instead of remapping substitutions it suffices to just drop
them.
2018-05-28 20:57:59 -07:00
Slava Pestov
d8fc9decf9 AST: Remove GenericSignature::getSubstitutionMap() 2018-05-28 19:45:28 -07:00
Slava Pestov
ebb1198d57 AST: There's no longer any reason to pass SubstitutionMap by const reference
SubstitutionMaps are now just a trivial pointer-sized value, so
pass them by value instead.

I did have to move a couple of functors from Type.h to SubstitutionMap.h
to resolve some issues with forward declarations.
2018-05-19 00:45:36 -07:00
Joe Groff
30ffad03ff SILGen: Correctly compute access kind for base of read-write computed properties.
The base access kind of a readwrite access depends on the mutating-ness of both the getter and setter, not the setter alone.
2018-05-17 18:40:15 -07:00
Joe Groff
fce4988dd0 SILGen: Emit default arguments as "delayed arguments".
This causes default arguments to get emitted after formal evaluation of `self`, allowing protocol methods to access the opened `Self` type of an existential receiver. Fixes rdar://problem/39524104
2018-05-17 13:17:44 -07:00
Joe Groff
b8dc2d2dff SILGen: Remove unused BorrowDirect and BorrowIndirect delayed arg kinds.
NFC
2018-05-17 13:17:44 -07:00
Davide Italiano
a4a46eae64 [SILGen] When emitting an apply, don't decode the dbgloc unconditionally.
Turns out it's really expensive and not really needed. On my machine
the testcase reported in SR-7691 goes down from 24 seconds to 2 seconds
after this change.

<rdar://problem/40258978>
2018-05-16 10:19:28 -07:00
Doug Gregor
ef020c74aa Eliminate all vestiges of Substitution and SubstitutionList.
Introduced during the bring-up of the generics system in July, 2012,
Substitution (and SubstitutionList) has been completely superseded by
SubstitutionMap. R.I.P.
2018-05-11 21:43:40 -07:00
Doug Gregor
cb3bf10d62 [SILGen] Eliminate SubstitutionList from SILGenFunction::emitApply(). 2018-05-11 17:37:27 -07:00
Doug Gregor
9a0e57f987 [SILGen] Simplify SubstitutionMap handling in emitApplyOfLibraryIntrinsic. 2018-05-11 17:37:27 -07:00
Doug Gregor
5c0733f3ac [SILGen] Eliminate Substitution from key-path equals/hash generation. 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
921d41ca10 [SILGen] Eliminate emitApplyOfLibraryIntrinsic() for SubstitutionList.
There was only one caller; update it to use the SubstitutionMap version.
2018-05-11 17:37:26 -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
408aaa5332 [SIL] Use SubstitutionMap in BuiltinInst. 2018-05-03 08:48:55 -07:00
Doug Gregor
d2cf60c465 Revert "[SIL] Replace more SubstitutionLists with SubstitutionMap" 2018-05-03 08:35:20 -07:00
Doug Gregor
ed1983d9d0 [SIL] Use SubstitutionMap in BuiltinInst. 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
Slava Pestov
db9380f9a8 SILGen: Fix latent bugs in emitApplyAllocatingInitializer()
The condition we want to test for emitting a downcast is isRequired(),
not isInheritable(). The latter is only true for convenience
initializers.

The other fix is that we actually have to emit a class_method
dispatch here to support class hierarchies conforming to literal
protocols.
2018-05-01 17:40:12 -06:00
Doug Gregor
0ea8f3da66 [SILGen] Fix no-parameter subscript accessor emission more thoroughly. 2018-04-26 13:53:28 -07:00
Doug Gregor
d7c68871cb [SILGen] Don't assert on subscripts with no index arguments. 2018-04-26 10:05:52 -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
Slava Pestov
b2e85f7eb5 SILGen: Use a concrete conformance if we have a witness_method call on a concrete type 2018-04-05 17:17:24 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
Mark Lacey
1dec7cc70e Remove SILGenModule::getLoweredEnumElementDecl.
This became a no-op at some point during the IUO work.
2018-03-14 23:59:26 -07:00
Slava Pestov
dac689a470 SILGen: Remove unused method 2018-03-14 17:21:39 -07:00
Slava Pestov
ebf017042a SILGen: Simplify AccessorBaseArgPreparer::prepareAccessorObjectBaseArg()
It's always an error to materialize an rvalue and pass it
as inout, even if the base type is class-constrained.
2018-03-14 16:14:36 -07:00
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