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
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
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
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.
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
The bug was introduced recently:
commit ac8a48b2
Date: Fri Oct 6 12:34:14 2017 -0700
Fixes <rdar://35800315> (crash using freed OpenedArchetypesTracker).
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.
We can just !SILFunction::hasQualifiedOwnership(). Plus as Andy pointed out,
even ignoring the functional aspects, having APIs with names this close can
create confusion.
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>.
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.
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
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.
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>