In global load/store optimization, ensure that we remove non-local
stores from the store map when we hit instructions that can potentially
overwrite all or part of the stored value.
In the test case from this particular radar, the address being stored to
is also passed as an inout to a mutating method, and then loaded after
the mutation.
rdar://problem/20603219
Swift SVN r28053
Teach LoadStoreOpts to handle "let" variables properly. Such variables should be loaded only once and their loaded values can be reused. This is safe, because once assigned these variables cannot change their value.
Swift SVN r27915
Preparation to fix <rdar://problem/18151694> Add Builtin.checkUnique
to avoid lost Array copies.
This adds the following new builtins:
isUnique : <T> (inout T[?]) -> Int1
isUniqueOrPinned : <T> (inout T[?]) -> Int1
These builtins take an inout object reference and return a
boolean. Passing the reference inout forces the optimizer to preserve
a retain distinct from what’s required to maintain lifetime for any of
the reference's source-level copies, because the called function is
allowed to replace the reference, thereby releasing the referent.
Before this change, the API entry points for uniqueness checking
already took an inout reference. However, after full inlining, it was
possible for two source-level variables that reference the same object
to appear to be the same variable from the optimizer's perspective
because an address to the variable was longer taken at the point of
checking uniqueness. Consequently the optimizer could remove
"redundant" copies which were actually needed to implement
copy-on-write semantics. With a builtin, the variable whose reference
is being checked for uniqueness appears mutable at the level of an
individual SIL instruction.
The kind of reference count checking that Builtin.isUnique performs
depends on the argument type:
- Native object types are directly checked by reading the
strong reference count:
(Builtin.NativeObject, known native class reference)
- Objective-C object types require an additional check that the
dynamic object type uses native swift reference counting:
(Builtin.UnknownObject, unknown class reference, class existential)
- Bridged object types allow the dymanic object type check to be
bypassed based on the pointer encoding:
(Builtin.BridgeObject)
Any of the above types may also be wrapped in an optional. If the
static argument type is optional, then a null check is also performed.
Thus, isUnique only returns true for non-null, native swift object
references with a strong reference count of one.
isUniqueOrPinned has the same semantics as isUnique except that it
also returns true if the object is marked pinned regardless of the
reference count. This allows for simultaneous non-structural
modification of multiple subobjects.
In some cases, the standard library can dynamically determine that it
has a native reference even though the static type is a bridge or
unknown object. Unsafe variants of the builtin are available to allow
the additional pointer bit mask and dynamic class lookup to be
bypassed in these cases:
isUnique_native : <T> (inout T[?]) -> Int1
isUniqueOrPinned_native : <T> (inout T[?]) -> Int1
These builtins perform an implicit cast to NativeObject before
checking uniqueness. There’s no way at SIL level to cast the address
of a reference, so we need to encapsulate this operation as part of
the builtin.
Swift SVN r27887
Semantic analysis should be guaranteeing that all conformances that
show up in the AST are complete. Until that day, work around the crash
in rdar://problem/20700616 by not specializing.
Swift SVN r27886
Teach dominator based simplifications to also thread dominated edges.
The code now handles cond_br and switch_enum terminators for both value based
simplifications (where the use is dominated) and jump threading edges (the edge
is dominated).
Update simplify_cfg.sil test cases for split edges.
This also handles the test case from rdar://20390647.
Swift SVN r27843
We can't always adopt the location of the user for the integer_literal because
the user's location might be a (Implicit)ReturnLocation which is disallowed on
most instructions.
Swift SVN r27835
This commits moves the code that accesses the operands after the point where
we identify the builtins and know they have two operands.
rdar://20711757
Swift SVN r27810
emit{StrongRelease,ReleaseValue} => emit{StrongRelease,ReleaseValue}AndFold.
Then introduce a new method emit{StrongRelease,ReleaseValue} that returns a
PointerUnion containing the increment to be deleted if it exists. This obviates
the need for the callback.
Swift SVN r27804
We now produce:
t.swift:1:15: error: negative integer '-9223372036854775808' overflows when stored into unsigned type 'UInt'
var x: UInt = -0x8000_0000_0000_0000
^
Swift SVN r27797
- <rdar://problem/16306600> QoI: passing a 'let' value as an inout results in an unfriendly diagnostic
- <rdar://problem/16927246> provide a fixit to change "let" to "var" if needing to mutate a variable
We now refer to an inout argument as such, e.g.:
t.swift:7:9: error: cannot pass 'let' value 'a' as inout argument
swap(&a, &b)
^
we also produce a note with a fixit to rewrite let->var in trivial cases where mutation is
being assed for, e.g.:
t.swift:3:3: note: change 'let' to 'var' to make it mutable
let a = 42
^~~
var
The note is produced by both Sema and DI.
Swift SVN r27774
On that testcase, we now generate:
t.swift:8:22: error: integer literal '123456' overflows when stored into 'UInt8'
case tooFarByFar = 123456
^
t.swift:7:8: error: integer literal '256' overflows when stored into 'UInt8'
case twoHundredFiftySix
^
instead of spitting out some warnings with no source loc (which Xcode eats).
This patch:
- Propagates source locations for literals when synthesizing code in various places,
so we get the right diagnostic at the right spot.
- Improves the constant folding SIL Pass to print the value overflowing, which is
necessary for cases with an implicit value (like 256 above), and is general goodness
for the QoI of the diagnostic anyway.
Swift SVN r27756
This falls out of the rework I did of 'self' in initializers. We now correctly
dealloc_ref the allocated object on the failure path of a convenience init.
Swift SVN r27752
Previously, we relied on certain types not being passed in by the users of the
given function. Since I had a lot on my plate on the time and I knew it was safe
I left it in. Now I am going to be using this function in more places so it
needs to handle everything correctly.
rdar://19552593
Swift SVN r27748
This reverts commit r27739 reapplying r27722.
The test (validation/stdlib/Hashing.swift) that failed is expected to sometimes
fails.
Original message
"SimplifyCFG: Fix a bug in the jump threading code
When jump threading a block we used to propagate phi values directly into the
threaded block - instead of leaving in a copy. Because of this the SSA updater
would propagate the value feeding the copy from the next iteration.
Now when jump threading the destination block into the edge we leave in the phi
(copy) such that the SSA updater picks up value of the right iteration.
rdar://20617338"
Swift SVN r27741
When jump threading a block we used to propagate phi values directly into the
threaded block - instead of leaving in a copy. Because of this the SSA updater
would propagate the value feeding the copy from the next iteration.
Now when jump threading the destination block into the edge we leave in the phi
(copy) such that the SSA updater picks up value of the right iteration.
rdar://20617338
Swift SVN r27722
DI makes the assumption that the type of self in an initializer is always
derived from a nominal type. Now that you can put an initializer body on a
protocol, this isn't true anymore, so teach it about this.
Swift SVN r27714
fixing <rdar://problem/19664185> Pointless "always evaluates to true" warning in while true loops at the top level
Also, merge test/SILPasses/diagnose_unreachable_two_while_loops.swift into SILPasses/unreachable_code.swift.
Swift SVN r27696
Due to a small bug, redundant init-calls were only removed if the first call was inside a loop.
Now it should also work in cases without loops.
Related radar: rdar://problem/20433505
Swift SVN r27693