Commit Graph

2195 Commits

Author SHA1 Message Date
Michael Gottesman
1209592421 Merge pull request #13536 from gottesmm/rdar_36032876
In SILCodeMotion, be sure to invalidate global enum tag dataflow state when deleting instructions
2017-12-19 16:09:16 -08:00
Devin Coughlin
88232d6e3b [Exclusivity] Look through block arguments to find noescape closures (#13497)
Update static enforcement to look through noescape blocks to find an underlying
noescape closure when a closure is converted to a block and passed as an
argument to a function. This fixes a false negative when the closure performs
an access that conflicts with an already in-progress access.

These new diagnostics are warnings for source compatibility but will
be upgraded to errors in the future.

rdar://problem/32912660
2017-12-19 13:38:09 -08:00
Michael Gottesman
af8d9b8c78 [silcodemotion] Instead of storing enum values directly into the block state structures, use a global "blotable" store to allow for invalidation without touching potentially free-ed pointers. Fix up all of the places where we violate this invariant.
rdar://36032876
2017-12-19 11:20:59 -08:00
Michael Gottesman
269c5e86cd [silcodemotion] Now that we have sunk the context into each block state, we do not need to pass in the context to any routines on the block state.
rdar://36032876
2017-12-19 10:55:36 -08:00
Michael Gottesman
77441fcdd1 [silcodemotion] For now stash a pointer to EnumCaseDataflowContext in each of the block states that we are tracking.
In a subsequent commit, I will change this to use a trailing objects
implementation so we can just use pointer arithmetic to find the offset. But for
now I am going for simplicity since this is a bug fix.

rdar://36032876
2017-12-19 10:21:31 -08:00
Michael Gottesman
48bb2d16f1 [silcodemotion] Rename BBToDataflowStateMap -> EnumCaseDataflowContext.
rdar://36032876
2017-12-19 10:13:10 -08:00
Michael Gottesman
9cda9056b6 [silcodemotion] Add support for dumping BBEnumTagDataflowState.
rdar://36032876
2017-12-19 10:11:56 -08:00
Michael Gottesman
42e1df166a [silcodemotion] Move generic code motion code below enum tag dataflow based code motion.
This gets rid of forward declaration issues in the file with some subsequent
changes I am going to be making.

rdar://36032876
2017-12-19 10:10:07 -08:00
Pavel Yaskevich
10c385d1b7 [Mangling/ABI] Add special LabelList to store parameter labels
Instead of mangling parameter labels as part of the function type
move them to the end of the function name instead, to match the
language semantics.
2017-12-18 15:44:24 -08:00
Adam Nemet
5d7b8106c3 Add opt-remarks to the Speculative Devirtualizer pass 2017-12-18 13:29:46 -08:00
swift-ci
ac95e6116b Merge pull request #13503 from anemet/opt-remark-devirt 2017-12-18 12:09:22 -08:00
Adam Nemet
3a9012d742 Add opt-remarks to the Devirtualizer pass 2017-12-18 10:18:13 -08:00
John McCall
b13f30ff30 Move a convenience API for changing a SILFunctionType into the AST. NFC. 2017-12-15 18:19:07 -05:00
Erik Eckstein
5d1827b5ba Remove a wrong assert in the specializer.
In case of partial specialization, the replacement type of a substitution can be generic.
I couldn't find a small unit test for this bug fix. But it is tested by compiling the stdlib with the change in Collection.swift.

rdar://problem/36033852
2017-12-14 15:28:07 -08:00
Andrew Trick
b39de959fa Fix a theoretical copy forwarding bug.
Reviewing the code with Arnold revealed a corner case where forward propagating
a copy into multiple operands of the same instruction wasn't properly detected.
I don't think this case was possible given the language rules, but nonetheless
it is valid SIL and needs to be handled.

This is confusing because in some cases we optimize that situation correctly,
and in other cases we try to assert that it doesn't happen. So, I simplified the
code to bailout anywhere that we see multiple operands of the same value. This
isn't an expected situation that needs to be optimized.
2017-12-14 09:37:12 -08:00
Joe Shajrawi
e598ec4f70 Merge pull request #13336 from shajrawi/cast_opt_bug_fix
Cast Optimizer: bail out when we can't do the cast
2017-12-12 16:08:23 -08:00
Joe Shajrawi
0559e7cd3e Cast Optimizer: optimizeBridgedSwiftToObjCCast - should never reach an unreachable code path: if the Destination does not have the same type, is not a bridgeable CF type and isn't a superclass/subclass of the source operand then bail before going through with the code generation.
This commit makes sure we bail early + adds a test case wherein we did not do that until now.
2017-12-12 13:41:35 -08:00
Andrew Trick
2caf1748a5 CopyForwarding - small redesign to fix bugs.
Copy forwarding was designed with some assumptions about symmetry of
operations. If copy_value/destroy_value are expanded somewhere for a given
value, then they should be expanded everywhere. The pass took a conservative
approach to SIL patterns that were guaranteed safe, and bailed out on unknown
patterns. However, due to some over-aggressive code factoring, the assumption
wasn't being checked in one corner case.

This redesign makes a clear distinction between the requirements for forward
vs. backward propagation.

Fixes <rdar://35646292> Swift CI: resilience bot seg faults in
stdlib/RangeReplaceable.swift.gyb
2017-12-10 01:17:13 -08:00
Rintaro Ishizaki
08ef4e324f [CMake] Add swift-syntax-generated-headers to the global dependencies 2017-12-05 17:03:12 +09:00
Andrew Trick
32a8dbcfa8 Fix a dangling stack pointer in SILCombine.
The bug was introduced recently:
commit ac8a48b2
Date:   Fri Oct 6 12:34:14 2017 -0700

Fixes <rdar://35800315> (crash using freed OpenedArchetypesTracker).
2017-12-04 10:04:48 -08:00
Andrew Trick
708aadfada Cleanup SILCombine code in preparation for a bug fix.
This is not NFC because the isUseAfterFree helper and surrounding code
is rewritten. The previous code's intention is unclear, but it was at
best imprecise and unsafe w.r.t. future SIL changes.

Pattern matching code that becomes highly complicated should
be commented with motivating SIL examples.
2017-12-04 10:04:48 -08:00
swift-ci
5e7aba6568 Merge pull request #13228 from gottesmm/pr-5feef94b3c080c9a6cf510b23576b94c19fbe1a9 2017-12-02 18:38:14 -08:00
Michael Gottesman
5263e9e74e [sil] Eliminate redundant method SILFunction::hasUnqualifiedOwnership().
We can just !SILFunction::hasQualifiedOwnership(). Plus as Andy pointed out,
even ignoring the functional aspects, having APIs with names this close can
create confusion.
2017-12-02 17:42:34 -08:00
Arnold Schwaighofer
a6504fb5ac Outliner: Can't handle polymorphic objc methods
rdar://35796830
2017-12-01 13:57:31 -08:00
Jordan Rose
8f8f00012a Merge pull request #12834 from jrose-apple/restrict-cross-module-struct-initializers-2
Implementation of SE-0189 "Restrict cross-module struct initializers to be delegating"

rdar://problem/34777878
2017-11-30 13:32:45 -08: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
Arnold Schwaighofer
ea9907ae15 Revert "SIL: Use objc_method instruction for Objective-C protocol method calls" 2017-11-29 11:19:46 -08:00
Slava Pestov
a3b1308c76 Merge pull request #13139 from slavapestov/no-more-volatile-witness-method
SIL: Use objc_method instruction for Objective-C protocol method calls
2017-11-29 02:12:46 -08:00
Slava Pestov
1ee0970934 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 01:22:05 -08:00
Michael Gottesman
6d654b3cbd [+0-all-args] Loosen whitelist in AccessSummaryAnalysis to allow partial applies to be borrowed.
rdar://34222540
2017-11-28 21:47:33 -08:00
Joe Groff
16f5e64ef2 Merge pull request #13101 from jckarter/address-only-bridged-cast-leak
SIL: Correct handling of bridging casts with address-only types.
2017-11-28 10:50:01 -08:00
Slava Pestov
2f0bc945fe SILOptimizer: Make a function static 2017-11-27 22:27:35 -08:00
Slava Pestov
1d6ec8e69e SILOptimizer: Fix incorrect check for unsupported generic case
We don't have a way to represent a cast in SIL where the destination
type introduces new archetypes that depend on the input value, sort
of like opening an existential.

Previously we would only rule out the case where the class itself
was generic, but a class can also be nested inside another generic
context.

Fixes <rdar://problem/35478838>.
2017-11-27 22:27:35 -08:00
Slava Pestov
47a3a66e52 SILOptimizer: Kill off duplicated getAllSubclasses() algorithm 2017-11-27 22:20:14 -08:00
Joe Groff
5eb830cf22 SIL: Correct handling of bridging casts with address-only types.
We would leak AnyHashable or other bridged address-only value types when turning a take-always cast into a bridging call, since the bridging method takes the value as guaranteed and we didn't arrange to destroy the value after the bridging happened. The code had unnecessarily different paths for indirect and direct arguments, and furthermore, has an untestable path for when the self argument of the bridging method is taken at +1 (when it's currently only ever +0). Join up the direct and indirect logic, and move the handling of differences down to where we introduce retain/releases so that we generate in-memory operations when appropriate. Fixes SR-6465 | rdar://problem/35678523.
2017-11-27 18:30:20 -08:00
Arnold Schwaighofer
3e04f21a41 SIL: Remove EnableGuaranteedClosureContext now that it is the default 2017-11-27 07:25:03 -08:00
Slava Pestov
7f84ae5449 SILOptimizer: Remove special handling of transparent functions from dead function elimination
This is no longer sound after https://github.com/apple/swift/pull/12903.
We no longer special-case the linkage of transparent functions at all.
2017-11-20 00:21:49 -05:00
Andrew Trick
8ffcf761af [sil-opaque-values] Fix EscapeAnalysis to track opaque values.
This is trivially tested by simply building generic code with opaque values at
-O.
2017-11-18 17:13:57 -08:00
Joe Shajrawi
4d5949942d Merge branch 'master' into sil-serialization-before-optimizations5 2017-11-17 16:17:16 -08:00
swift-ci
012cc4a6e7 Merge pull request #12933 from anemet/opt-remark-generic-specialization 2017-11-17 10:05:22 -08:00
Devin Coughlin
cf9a09e18d [Exclusivity] Diagnose when noescape closure is passed via reabstraction thunk
This fixes a serious false negative in static exclusivity enforcement when
a noescape closure performs an access that conflicts with an in-progress access
but is not reported because the closure is passed via a reabstraction thunk.

When diagnosing at a call site, the enforcement now looks through partial
applies that are passed as noescape arguments. If the partial apply takes
an argument that is itself a noescape partial apply, it recursively checks
the captures for that partial apply for conflicts and diagnoses if it finds one.

This means, for example, that the compiler will now diagnose when there is a
conflict involving a closure with a concrete return type that is passed to a
function that expects a closure returning a generic type. To preserve source
compatibility these diagnostics are emitted as warnings for now. The intent is
that they will be upgraded to errors in a future version of Swift.

rdar://problem/35215926, SR-6103
2017-11-16 16:01:08 -08:00
Adam Nemet
bd8764caaa Add opt remarks to Generic Specializer pass
Adds a combined API to output both debug message and optimization remarks.

The previously added test partial_specialization_debug.sil ensures that it's an
NFC for debug output.
2017-11-16 10:10:24 -08:00
Slava Pestov
cce30cc9bb SIL: Remove SILFunction::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Slava Pestov
f07cde75e7 AST: Move mapTypeOutOfContext() from GenericEnvironment to TypeBase
It doesn't actually *use* the generic environment.
2017-11-15 22:52:13 -08:00
Michael Gottesman
49adf11a00 [cfg] Add back in bool return value, returning a value to it this time. 2017-11-15 21:52:50 -08:00
Slava Pestov
2aa126e680 SILOptimizer: Fix a warning 2017-11-15 20:58:58 -08:00
swift-ci
9733024390 Merge pull request #12947 from adrian-prantl/35459092 2017-11-15 14:27:40 -08:00
Adrian Prantl
78e074dbf6 Fix the debug locations of inserted operations in AvailableValueAggregator.
This mandatory pass inserts struct_extract operations before earlier
stores to the aggregate but didn't set the debug location of those new
instructions to the location of the store, which caused unexpected
stepping behavior in the debugger.

Fixes a regression from e74367f2b3.
<rdar://problem/35459092>
2017-11-15 13:30:39 -08:00
swift-ci
00e71a1a38 Merge pull request #12926 from gottesmm/pr-7d7ad787aa26105e196576774cbf2188fdd8b1b0 2017-11-14 23:36:25 -08:00
Adam Nemet
18a588ee46 Mention callee in missed inliner remark 2017-11-14 17:24:34 -08:00