Commit Graph

2498 Commits

Author SHA1 Message Date
Michael Gottesman
39dbf54e19 [cast-opt] Update checked_cast_addr_br objc -> swift bridged cast optimization for ownership.
These fix assertions that we hit by even performing the optimization, some
making sure the test doesn't hit those is sufficient.
2019-05-26 18:30:21 -07:00
Michael Gottesman
ad676857ea [cast-opt] Fix miscompile when we tried to optimize take_on_success that resulted in invalid IR being emitted.
The specific problem here is that we are setting the insertion point of a
SILBuilder and not unsetting it. I fixed the problem by creating a separate
builder so the original builder stays put.

I originally came across this in my work on moving ownership stripping after the
diagnostic passes. This patch fixes it without my other changes to ease
cherry-picking to 5.1.

I also added more test coverage by expanding the test case to also handle
copy_on_success and take_always.

rdar://51093557
2019-05-24 09:58:24 -07:00
Arnold Schwaighofer
84a68e11e0 Merge pull request #25014 from aschwaighofer/fix_combine_dynamic_function_ref
SILCombine: We are not guaranteed to get a function_ref instruction here
2019-05-23 11:41:46 -07:00
Arnold Schwaighofer
4985e0f818 SILCombine: We are not guaranteed to get a function_ref instruction here
Also fix an issue in that cast optimizer and objc bridging thunks that
are marked dynamic.

Same test case tests both issues.

rdar://51068786
2019-05-23 08:39:31 -07:00
Michael Gottesman
372046cc04 [diagnose-unreachable] Ignore/eliminate end_borrows after noreturn functions.
This seems to happen more often when we strip ownership after diagnose
unreachable.
2019-05-22 20:06:18 -07:00
Andrew Trick
bdf7b2ade6 Merge pull request #24947 from atrick/fix-dynamic-exclusivity
Fix exclusivity diagnostics to be aware of [dynamically_replaceable].
2019-05-22 10:36:01 -07:00
Michael Gottesman
17213f79f1 Merge pull request #24955 from gottesmm/pr-e299d5c0fc06f6cf982d906b63ebe334df110585
[ownership] Convert SILOptimizer/cast_folding_objc_generics.swift to …
2019-05-21 12:22:37 -07:00
swift-ci
a96890c7ae Merge pull request #24929 from eeckstein/optimize-keypath 2019-05-21 11:20:29 -07:00
swift-ci
b170ad72a8 Merge pull request #24953 from gottesmm/pr-71990c28f613fe44d9bf454eeb0b89a4356c8f91 2019-05-21 10:40:51 -07:00
Erik Eckstein
da38e3ac81 SILCombine: optimize keypath instructions.
If the keypath argument of a keypath access function is a keypath literal instruction, generate the projection inline and remove the access function.
For example, replaces (simplified SIL):
   %kp = keypath ... stored_property #Foo.bar
   apply %keypath_runtime_function(%root_object, %kp, %addr)
with:
   %addr = struct_element_addr %root_object, #Foo.bar
   load/store %addr

Currently this only handles stored property patterns.

rdar://problem/36244734
2019-05-21 09:44:59 -07:00
Michael Gottesman
b48bcd9085 [ownership] Convert SILOptimizer/cast_folding_objc_generics.swift to work with ownership serializing after serialization at -Onone.
I added an extra run with the relevant flag enabled for this purpose.
2019-05-21 09:24:37 -07:00
Michael Gottesman
748bf88bbe [ownership] Convert SILOptimizer/cast_folding.swift to work with ownership and fix all issues exposed. 2019-05-21 09:07:13 -07:00
Arnold Schwaighofer
528fe42bfb Merge pull request #24923 from aschwaighofer/dynamically_replaceable_closure_fixes
Fix capture promotion and closure scope analysis' handling of dynamically_replaceable functions
2019-05-21 05:56:41 -07:00
Andrew Trick
6e3f56fa92 Fix exclusivity diagnostics to be aware of [dynamically_replaceable].
Previously, any function marked [dynamically_replaceable] that was
partially applied and captured by address would not be diagnosed.

This is a rare thing. For example:

struct S {
  var x = 0
  public mutating func testCallDynamic() {
    dynamic func bar(_ i: inout Int) {
      i = 1
      x = 2
    }
    bar(&x)
  }
}

Fixes <rdar://problem/50972786> Fix exclusivity diagnostics to be
aware of [dynamically_replaceable].
2019-05-20 21:46:30 -07:00
Michael Gottesman
ef1ad0613c Merge pull request #24102 from gottesmm/pr-cdde379c40f94a6fd49361a2b347388665705682
[constant-prop] When replacing uses of destructure_tuple, only RAUW i…
2019-05-20 15:15:20 -07:00
Arnold Schwaighofer
6c0baaee85 Fix closurescope analysis
rdar://50949761
2019-05-20 13:20:23 -07:00
Arnold Schwaighofer
4912e6aa85 CapturePromotion: Disable for dynamically_replaceable sil functions
rdar://50949761
2019-05-20 13:20:10 -07:00
Michael Gottesman
3b029010b9 [mandatory-inlining] When using the linear lifetime checker to insert compensating releases, if we find a double use due to a loop, do not insert an apply at that call site.
Otherwise, one will get use after frees. I added an interpreter test as wlel as
an end to end test.

rdar://50884462
2019-05-20 12:12:13 -07:00
Michael Gottesman
08c25da322 [cast-opt] Fix another code path in the cast optimizer for ownership and add an additional run of cast_folding_objc.swift with stripping ownership after serialization. 2019-05-20 00:51:26 -07:00
Michael Gottesman
35c3a0fce3 [cast-opt] Change one pathway through the cast-optimizer to use higher level constructs that are both ossa and non-ossa compatible 2019-05-18 18:32:31 -07:00
Michael Gottesman
5910829830 [constant-prop] When replacing uses of destructure_tuple, only RAUW if we actually have uses since we may not delete the actual destructure.
The specific case where this happened here is:

```
  // Worklist = [
  %0 = struct $Int (...)
  %1 = $Klass
  %2 = tuple (%0, %1)
  (%3, %4) = destructure_tuple %2
  store %3 to [trivial] %3stack
  store %4 to [init] %4stack
```

What would happen is we would visit the destructure_tuple, replace %3 with %0
but fail to propagate %4:

```
  %0 = struct $Int (...)
  %1 = $Klass
  %2 = tuple (%0, %1)
  (%3, %4) = destructure_tuple %2
  store %0 to [trivial] %3stack
  store %4 to [init] %4stack
```

This then causes the tuple to be added to the worklist. When we visit the tuple,
we see that we have a destructure_tuple that is a user of the tuple, we see that
it still has that Struct as a user despite us having constant propagated that
component of the tuple. This then causes us to add the struct back to the
worklist despite that tuple component having no uses. Then when we visit the
struct. Which causes us to visit the tuple, etc.

rdar://49947112
2019-05-18 15:26:25 -07:00
Slava Pestov
d832fb9823 SILOptimizer: Fix crash on invalid in invalid escaping captures pass
An inout capture of 'self' is not lowered as a SIL argument inside
an initializer, so add a new check to handle this case.

Fixes <rdar://problem/50412872>.
2019-05-18 00:24:13 -04:00
Erik Eckstein
71b8c5617e SILCombine: fix a miscompile in dead alloc_existential_box removal
The miscompile results in a use-after-free crash.

rdar://problem/50759056
2019-05-16 15:05:44 -07:00
Andrew Trick
868156c069 Merge pull request #24773 from atrick/fix-accessopt-slow
Add AccessEnforcementOpts fast paths.
2019-05-16 10:59:02 -07:00
Joe Groff
0be95f56bd Merge pull request #24798 from jckarter/opaque-type-check-availability
Opaque types require a newer Swift runtime.
2019-05-15 18:05:40 -07:00
Joe Groff
cec9e9e33a Opaque types require a newer Swift runtime.
Check the availability of decls that declare an opaque return type to ensure they deploy to a
runtime that supports opaque types.

rdar://problem/50731151
2019-05-15 11:39:53 -07:00
Ravi Kandhadai
9be4fef53a [SIL Optimization] Add a mandatory optimization pass for optimizing
the new os log APIs based on string interpolation.
2019-05-14 18:08:59 -07:00
ravikandhadai
f563212f03 Revert "[SIL Optimization] Add a mandatory pass for optimizing the new os log APIs based on string interpolation." 2019-05-14 15:11:05 -07:00
Andrew Trick
a9070cf6d4 Add AccessEnforcementOpts fast paths.
1. During identifyAccess, determine if there are either any
identical accesses or an accesses that aren't already marked
no_nested_storage. If there are neither, then skip the subsequent
data flow analysis.

2. In the new StorageSet, indicate whether identical storage was
seen elsewhere in the function. During dataflow, only add an access
to the out-of-scope access set if was marked as having identical
storage with another access.

3. During data flow, don't track in scope conflicts for
instructions already marked [no_nested_conflict].
2019-05-14 15:09:40 -07:00
Andrew Trick
c1bda8f090 Replace AccessedStorage projection with an index.
Further simplify AccessedStorage. Shrink it to two words. Remove the
Projection abstraction and streamline the projection logic.
2019-05-14 12:44:46 -07:00
swift-ci
05808b93fb Merge pull request #24728 from atrick/simplify-accessed-storage-no-rea 2019-05-14 12:01:23 -07:00
Andrew Trick
0d3c6144ed Remove RefElementAddr field from AccessedStorage.
- code simplification critical for comprehension
- substantially improves the overhead of AccessedStorage comparison
- as a side effect improves precision of analysis in some cases

AccessedStorage is meant to be an immutable value type that identifies
a storage location with minimal representation. It is used in many global
interprocedural data structures.

The RefElementAddress instruction that it was derived from does not
contribute to the uniqueness of the storage location. It doesn't
belong here. It was being used to create a ProjectionPath, which is an
extremely inneficient way to compare access paths.

Just delete all the code related to that extra field.
2019-05-14 10:45:54 -07:00
Andrew Trick
8cc013ed3f Fix LICM debug output typo. 2019-05-14 10:45:53 -07:00
Ravi Kandhadai
b7b46622aa [SIL Optimization] Add a mandatory optimization pass for optimizing
the new os log APIs based on string interpolation.
2019-05-13 19:40:39 -07:00
swift-ci
616ec93fa2 Merge pull request #24625 from atrick/canonicalize-stores 2019-05-11 19:32:29 -07:00
Michael Gottesman
afe3114d3d [sil] Expand immutable address verification to in_guaranteed parameters.
rdar://50212579
2019-05-09 23:01:43 -07:00
Michael Gottesman
179251d167 [sil-combine] Do not perform existential type propagation on @in parameters when we have a copy of the underlying value.
Otherwise, we may get use-after-frees as in the added test.

rdar://50609145
2019-05-09 23:01:43 -07:00
Andrew Trick
320759227a Canonicalize stores in the CanonicalizeInstruction utility.
This is the complement to load canonicalization. Although store
canonicalization is not required before diagnostics, it should be
defined in the same utility.
2019-05-09 13:00:39 -07:00
Arnold Schwaighofer
9685aaff33 Test case for previous 3 fixes
rdar://50592605
    rdar://50591831
    rdar://50589978
2019-05-08 14:16:00 -07:00
Arnold Schwaighofer
dce6ca766b CastOptimizer: Fix for opaque archetypes
The fallthrough path of this function assumes failure :(.

rdar://50544445
2019-05-07 11:08:00 -07:00
Andrew Trick
c3b7c194ec Extend an exclusivity diagnostic test for nontrivial let's. 2019-05-06 17:23:08 -07:00
Andrew Trick
c3c1dc7c1d Add a CanonicalizeInstruction test case for nontrivial loads. 2019-05-06 17:23:08 -07:00
Andrew Trick
e70b7c7c2f SILGenCleanup tests. 2019-05-06 13:31:35 -07:00
Andrew Trick
f395f86039 Canonicalize loads in SILGenCleanup.
Reimplement load instruction canonicalization as part of the
CanonicalizeInstruction utility.
2019-05-06 13:31:35 -07:00
Andrew Trick
301ff8c9f0 Add a SILGenCleanup pass.
The SILGenCleanup pass runs before diagnostics to perform any
canonicalization required by diagnostics.
2019-05-06 09:36:08 -07:00
Arnold Schwaighofer
5043ed45d9 Merge pull request #24453 from aschwaighofer/fix_generic_specialization_noreturn
Fix generic specialization that can result in noreturn apply without …
2019-05-04 15:06:36 -07:00
Arnold Schwaighofer
6e3d69f7df test case for generic specialization of noreturn apply 2019-05-04 12:25:28 -07:00
Arnold Schwaighofer
0c7b8099c2 Merge pull request #24482 from aschwaighofer/fix_specialize_opaque_type_archetypes_test
Fix test case specialize_opaque_type_archetypes.swift
2019-05-03 20:40:00 -07:00
Arnold Schwaighofer
d1eaa9cded Fix test case specialize_opaque_type_archetypes.swift 2019-05-03 11:45:55 -07:00
Arnold Schwaighofer
830abc3284 Add test case with alwaysEmitIntoClient 2019-05-03 11:21:46 -07:00