Commit Graph

823 Commits

Author SHA1 Message Date
Michael Gottesman
e3eb9aecb4 [sil] Introduce FullApplySiteKind and ApplySiteKind to allow for exhaustive switching over FullApplySites and ApplySiteKind.
Currently there is a bug in the closure specializer that was caused by
BeginApply not being handled correctly. Rather than just fixing that and leaving
the badness, I am instead in this commit introducing enums for apply sites so we
can avoid this problem in the future by using exhaustive switches to guide
developers adding new types of apply sites in the future.

rdar://44612356
2018-09-20 19:19:02 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
swift-ci
cc329fee03 Merge pull request #19141 from aschwaighofer/remove_constant_string_literal 2018-09-10 15:51:47 -07:00
Michael Gottesman
0290cd4323 [sil] Eliminate end_borrow_argument now that end_borrow has a single operand.
I changed all of the places that used end_borrow_argument to use end_borrow.

NOTE: I discovered in the process of this patch that we are not verifying
guaranteed block arguments completely. I disabled the tests here that show this
bad behavior and am going to re-enable them with more tests in a separate PR.
This has not been a problem since SILGen does not emit any such arguments as
guaranteed today. But once I do the SILGenPattern work this will change.

rdar://33440767
2018-09-06 14:04:57 -07:00
Arnold Schwaighofer
73df12c09f Remove dead constant_string_literal
constant_string_literal was added to support a one word representation
of String that never materialized.
2018-09-05 12:13:57 -07:00
Michael Gottesman
c599539044 [sil] Eliminate the src parameter from end_borrow.
This does not eliminate the entrypoints on SILBuilder yet. I want to do this in
two parts so that it is functionally easier to disentangle changing the APIs
above SILBuilder and changing the underlying instruction itself.

rdar://33440767
2018-09-04 16:38:24 -07:00
Adrian Prantl
81f9ea33be SILGen: Preserve function argument debug info for arguments needing alloc_stack
This fixes a logic error in the existing code that cause these
function arguments to appear twice, once as local variable and once as
formal parameter.

rdar://problem/37410759
2018-08-31 10:35:52 -07:00
Erik Eckstein
99a9ed5535 SIL: remove the pinning instructions: strong_pin, strong_unpin, is_unique_or_pinned
They are not used anymore after removing the pinning addressors.
2018-08-23 12:47:56 -07:00
John McCall
8613761487 Fix some edge cases when inlining coroutines.
The current inlining strategy doesn't support inlining coroutines
when there are multiple end_apply or abort_apply instructions in
the caller, so refuse to inline such cases.  Also, handle the case
where there are no yield instructions in the callee, which can
happen if e.g. the callee calls a no-return function.

I also simplified the code somewhat by removing the vestiges of the
code that tried to unify control flow with switches.

As an unrelated fix, suppress function signature optimization for
coroutines for now.
2018-08-20 19:23:11 -04:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Andrew Trick
c9033ed938 Add a SIL attribute [without_actually_escaping].
ConvertFunction and reabstraction thunks need this attribute. Otherwise,
there is no way to identify that withoutActuallyEscaping was used
to explicitly perform a conversion.

The destination of a [without_actually_escaping] conversion always has
an escaping function type. The source may have either an escaping or
@noescape function type. The conversion itself may be a nop, and there
is nothing distinctive about it. The thing that is special about these
conversions is that the source function type may have unboxed
captures. i.e. they have @inout_aliasable parameters. Exclusivity
requires that the compiler enforce a SIL data flow invariant that
nonescaping closures with unboxed captures can never be stored or
passed as an @escaping function argument. Adding this attribute allows
the compiler to enforce the invariant in general with an escape hatch
for withoutActuallyEscaping.
2018-08-14 17:14:25 -07:00
Jordan Rose
886475b51a Make SILInstructionResultArray::begin() and end() inlinable (#18612)
These are trivial functions and should be inlined away; the only
tricky bit is they need to be defined after the iterator type.
This gives a slight speedup of stdlib compilation time (about 5%
of the time spent generating the swiftmodule).
2018-08-10 10:25:31 -07:00
swift-ci
71f0248b0a Merge remote-tracking branch 'origin/master' into master-next 2018-08-06 11:07:55 -07:00
swift-ci
1623f42447 Merge pull request #18292 from mhong/master_bytes_string 2018-08-06 09:05:58 -07:00
swift-ci
bf137ae65b Merge remote-tracking branch 'origin/master' into master-next 2018-07-31 18:59:26 -07:00
Andrew Trick
06d0973ebe Merge pull request #18315 from atrick/fix-argument-convention
Fix several incorrect uses of ApplySite::getArgumentConvention.
2018-07-31 18:09:54 -07:00
Mingsheng Hong
9cb7f494fa Merge branch 'master' of github.com:apple/swift into master_bytes_string 2018-07-31 10:59:06 -07:00
swift-ci
45338c78ba Merge remote-tracking branch 'origin/master' into master-next 2018-07-30 15:49:06 -07:00
Andrew Trick
a349133347 Added getArgForOperand for BranchInst and CondBranchInst.
Allows a SIL pass to follow a def-use chain through phis.

Other terminators can also propagate values through block arguments, but they
always need special handling.
2018-07-30 14:42:30 -07:00
Andrew Trick
89ed064808 Fix several incorrect uses of ApplySite::getArgumentConvention.
At least most of these were latent bugs since the code was
unreachable in the PartialApply case. But that's no excuse to misuse
the API.

Also, whenever referring to an integer index, be explicit about
whether it is an applied argument or callee argument.
2018-07-28 00:05:40 -07:00
swift-ci
fbc52103e6 Merge remote-tracking branch 'origin/master' into master-next 2018-07-27 13:09:06 -07:00
Mingsheng Hong
ba38bcb279 Introduce a new 'bytes' form of the string_literal SIL instruction. Have it
print and parse as a stable hexadecimal form that isn't interpreted as UTF8.

One use case is in representing serialized protobuf strings (as in the
tensorflow branch: f7ed452eba/lib/SILOptimizer/Mandatory/TFPartition.cpp (L3875)).

The original work was done by @lattner and merged into the tensorflow
branch. This PR is to upstream those changes.
2018-07-27 11:58:00 -07:00
Andrew Trick
4a283be626 [nfc] ApplySite argument APIs: cleanup and add comments.
Use consistent terminology, clarify comments, and group APIs.
This matches the documentation in SILDevelopment.md.
2018-07-27 11:18:35 -07:00
Bob Wilson
61fd167cf7 Merge remote-tracking branch 'origin/master' into master-next 2018-07-19 15:58:02 -07:00
Erik Eckstein
7d8835354b ClosureSpecializer: extend the benefit-analysis so that specialization is also done in case a closure is passed through multiple call-levels.
This fixes a performance regression for stdlib's sort.

SR-8267
rdar://problem/42246895
2018-07-19 09:59:52 -07:00
swift-ci
2507876125 Merge remote-tracking branch 'origin/master' into master-next 2018-07-06 17:08:57 -07:00
Joe Groff
849d9397d6 SIL: Generate external key path references with local candidate components.
The other side of #17404. Since we don't want to generate up front key path metadata for properties/subscripts with no withheld implementation details, the client should generate a key path component that can be used to represent a key path component based on its public interface.
2018-07-06 14:24:07 -07:00
swift-ci
decf2b1130 Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 11:49:26 -07:00
David Zarzycki
476d869e55 [SIL] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:33 -04:00
swift-ci
5e49ce352a Merge remote-tracking branch 'origin/master' into master-next 2018-06-26 19:50:13 -07:00
Andrew Trick
9d4b4c755c Rewrite SILCombiner::propagateConcreteTypeOfInitExistential. (#17315)
Fixes <rdar://40555427> [SR-7773]:
SILCombiner::propagateConcreteTypeOfInitExistential fails to full propagate type
substitutions.

Fixes <rdar://problem/40923849>
SILCombiner::propagateConcreteTypeOfInitExistential crashes on protocol
compositions.

This rewrite fixes several fundamental bugs in the SILCombiner optimization that
propagates concrete types. In particular, the pass needs to handle:

- Arguments of callee Self type in non-self position.
- Indirect and direct return values of Self type.
- Types that indirectly depend on Self within callee function signature.
- Protocol composition existentials.
- All of the above need to work for protocol extensions as well as witness methods.
- For protocol extensions, conformance lookup should be based on the existential's conformance list.

Additionally, the optimization should not depend on a SILFunction's DeclContext,
which is not serialized. (In fact, we should prevent SIL passes from using
DeclContext). Furthermore, the code needs to be expressed in a way that one can
reason about correctness and invariants.

The root cause of these bugs is that SIL passes are written based on untested
assumptions of Swift type system. A SIL pass needs to handle all verifiable SIL
input because passes need to be composable. Bail-out logic can be added to
simplify the design; however, _the bail-out logic itself cannot make any
assumptions about the language or type system_ that aren't clearly and
explicitly enforced in the SIL verifier. This is a common mistake and major
source of bugs.

I created as many unit tests as I reasonably could to prevent this code from
regressing. Creating enough unit tests to cover all corner cases that were
broken in the original code would be intractable. But the code has been
simplified such that many corner cases disappear.

This opens up some oportunity for generalizing the optimization and eliminating
special cases. However, I want this PR to be limited to fixing correctness
issues only. In the long term, it would be preferable to replace this
optimization entirely with a much more powerful general type propagation pass.
2018-06-26 19:33:31 -07:00
Bob Wilson
796122fa45 Merge remote-tracking branch 'origin/master' into master-next 2018-06-12 15:06:47 -07:00
David Zarzycki
52fd7cb2c9 [SIL] Perf: Cache basic block during SILSuccessor iteration
'operator*' in this patch becomes a hot spot in some scenarios. For
example: an enum with an unusually large number of cases.
2018-05-29 09:44:07 -04:00
swift-ci
2ee4fa9e73 Merge remote-tracking branch 'origin/master' into master-next 2018-05-24 10:29:06 -07:00
Andrew Trick
e29c2089a4 Rework AccessStorageAnalysis design. 2018-05-23 09:23:39 -07:00
swift-ci
23f5553589 Merge remote-tracking branch 'origin/master' into master-next 2018-05-11 23:09:52 -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
swift-ci
7b7c4d7469 Merge remote-tracking branch 'origin/master' into master-next 2018-05-11 21:10:05 -07:00
Doug Gregor
911ed60a98 Eliminate dead code making use of SubstitutionList. 2018-05-11 17:37:27 -07:00
swift-ci
fe33d12ead Merge remote-tracking branch 'origin/master' into master-next 2018-05-11 16:29:53 -07:00
Doug Gregor
09446defef Eliminate yet more SubstitutionLists from SIL in search of a steady-state 2018-05-11 13:18:06 -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
swift-ci
fed5ddea66 Merge remote-tracking branch 'origin/master' into master-next 2018-05-11 04:29:13 -07:00
David Zarzycki
77494e2ba5 [SIL] NFC: Keep building after clang r332076 2018-05-11 06:32:25 -04:00
swift-ci
bed7dc124d Merge remote-tracking branch 'origin/master' into master-next 2018-05-10 16:09:03 -07:00
Andrew Trick
fe326266cc [exclusivity] Add a [builtin] flag to begin_[unpaired_]access.
This flag supports promoting KeyPath access violations to an error in
Swift 4+, while building the standard library in Swift 3 mode. This is
only necessary as long as the standard library continues to build in
Swift 3 mode. Once the standard library build migrates, it can all be
ripped out.

<rdar://problem/40115738> [Exclusivity] Enforce Keypath access as an error, not a warning in 4.2.
2018-05-09 21:42:37 -07:00
swift-ci
17045afe85 Merge remote-tracking branch 'origin/master' into master-next 2018-05-08 16:09:15 -07:00
Andrew Trick
55ba1437d7 Add a comment on getCalleeArgIndexOfFirstAppliedArg() that I find personally helpful. 2018-05-08 12:44:41 -07:00
swift-ci
b966d3fbc1 Merge remote-tracking branch 'origin/master' into master-next 2018-05-07 08:29:22 -07:00
Jordan Rose
f6e85d1d64 [SIL] Simplify SILInstructionResultArray::iterator
No major change in execution time, but why make things more
complicated than they need to be? It does make
SILInstructionResultArray::begin drop out of the top ten functions in
the inverted call stack (not counting performLLVM).
2018-05-04 17:48:52 -07:00