Commit Graph

762 Commits

Author SHA1 Message Date
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
Jordan Rose
5bf9b9ac76 [SIL] Avoid std::function in transform-iterators
In a non-rigorous test, this change shaves off 20% of the time spent
in SIL optimizations for the standard library in a +Asserts build.
(Admittedly the wins for a no-asserts build will be much lower because
SILInstructionResultArray has a bunch of assertions in its
constructor.)
2018-05-04 17:48:52 -07:00
swift-ci
ad0712c02b Merge remote-tracking branch 'origin/master' into master-next 2018-05-04 08:49:40 -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
swift-ci
604f5930fe Merge remote-tracking branch 'origin/master' into master-next 2018-05-03 19:29:42 -07:00
Doug Gregor
503d9ce1f5 [SIL] Store SubstitutionMaps in MarkUninitializedBehaviorInst. 2018-05-03 15:40:10 -07:00
swift-ci
5f22c9ceec Merge remote-tracking branch 'origin/master' into master-next 2018-05-03 13:49:29 -07:00
Doug Gregor
ae9d0f6f18 [SIL] Store SubstitutionMaps in all of the "apply"-like instructions.
Replace the tail-allocated Substitution arrays with a SubstitutionMap.
This only affects the internal representation of the instructions, not their
constructors or serialization.
2018-05-03 12:57:12 -07:00
Doug Gregor
4136a1897a [AST] Split SubstitutionMap::Storage into its own header.
Now that SubstitutionMap is used in so many places, reduce it's header
dependencies by moving SubstitutionMap::Storage into its own separate
implementation header. Use forward declarations of other entities
(GenericSignature, Substitution) instead.

Good for build times and general sanity.
2018-05-03 09:49:09 -07:00
Doug Gregor
b1f338a00b [SIL Opt] Switch GenericSpecializationInformation over to SubstitutionMap.
There isn't a clean cut point here, so switch
GenericSpecializationInformation from SubstitutionList to
SubstitutionMap and carry along dual SubstitutionMap/SubstitutionList
representations for a small part of ReabstractionInfo.
2018-05-03 09:27:21 -07:00
swift-ci
5ce78da1d3 Merge remote-tracking branch 'origin/master' into master-next 2018-05-03 08:49:46 -07:00
Doug Gregor
408aaa5332 [SIL] Use SubstitutionMap in BuiltinInst. 2018-05-03 08:48:55 -07:00