Commit Graph

39091 Commits

Author SHA1 Message Date
Erik Eckstein
93d3226790 DeadObjectElimination: handle init_existential_addr instructions.
This allows to eliminate a dead stack location which contains an existential.

rdar://problem/32272199
2020-02-18 19:23:17 +01:00
Erik Eckstein
2afa1210b0 SILCombine: remove dead unchecked_take_enum_data_addr instructions. 2020-02-18 19:23:17 +01:00
Slava Pestov
aeb894f36c Merge pull request #29898 from slavapestov/self-but-not-self
Sema: Prefer an outer type named 'Self' over the SE-0068 behavior
2020-02-18 12:32:17 -05:00
Andrew Trick
14862908ef Merge pull request #28043 from zoecarver/fix/substitution-map-composition
Devirtualize calls to protocol composition type methods
2020-02-18 09:30:07 -08:00
Pavel Yaskevich
b905113f5c [ConstraintSystem] Remove now completely obsolete CSDiag 2020-02-18 09:12:56 -08:00
Robert Widmann
3b11c2b170 [SILGen] Materialize Arguments To Property Wrapper Setters If Needed
Codegen for the assign_by_wrapper instruction emits prepared arguments
directly into the initializer or accessor functions. This means it
misses out on the CC matching code that the general apply path uses.

In this particular case, an enum value was constructed within the
resilience boundary, but passed to the setter for a wrapper property
that expected it to be in memory.

Check the calling convention before we emit the assign_by_wrapper
instruction, and materialize an address for indirect CCs as required.

resolves rdar://59071930
2020-02-18 09:10:07 -08:00
Mike Ash
2763e13a9a [Stdlib] Fix an overrelease in -[__SwiftNativeNSError description].
getDescription takes its argument at +1, but the implementation was passing the value directly. This caused the contained error value to be destroyed.

rdar://problem/59512630
2020-02-18 11:30:03 -05:00
eeckstein
60565d5b7e Merge pull request #29903 from eeckstein/enable-runtime-messages
Enable better runtime failure messages
2020-02-18 14:15:39 +01:00
swift-ci
bb20a87b2b Merge pull request #29871 from swiftwasm/swiftwasm-stdlib-tests 2020-02-18 04:19:33 -08:00
Erik Eckstein
56ecb8fc9b Enable better runtime failure messages
The implementation was done quite a while ago.
Now, that we have support in lldb (https://github.com/apple/llvm-project/pull/773), we can enable it by default in the compiler.

LLDB now shows the runtime failure reason, for example:

* thread #1, queue = 'com.apple.main-thread', stop reason = Swift runtime failure: arithmetic overflow
    frame #1: 0x0000000100000f0d a.out`testit(a=127) at trap_message.swift:4
   1
   2   	@inline(never)
   3   	func testit(_ a: Int8) -> Int8 {
-> 4   	  return a + 1
   5   	}
   6

For details, see https://github.com/apple/swift/pull/25978

rdar://problem/51278690
2020-02-18 12:03:57 +01:00
Suyash Srijan
c435646825 [GSB] Delay mapping an invalid subject type to an error type (#29813) 2020-02-18 07:35:42 +00:00
Michael Gottesman
fefd027eb2 [semantic-arc-opts] Convert @owned -> @guaranteed args of transforming terminators when fed by load [copy], copy_value.
This extends the (copy (guaranteed x)) -> (guaranteed x) optimization to handle
transforming terminator arguments. This will begin to enable us to eliminate RC ops
around optionals or casts.

I still need to add support for eliminating copies that forward through br args and phis.

<rdar://problem/56720436>
<rdar://problem/56720519>
2020-02-17 20:29:10 -08:00
Owen Voorhees
d8bc35bc0a Merge pull request #29895 from mdiep/remove-backticks-in-diagnostics
Use single quotes instead of backticks in diagnostics
2020-02-17 19:32:13 -08:00
Slava Pestov
eaee6faa00 Sema: Prefer an outer type named 'Self' over the SE-0068 behavior
This fixes a recent source break. We need to perform the normal
unqualified lookup before we handle the special case of 'Self',
because there might be a type named Self defined in an outer
context.

Fixes <https://bugs.swift.org/browse/SR-12133> / <rdar://problem/59216636>
2020-02-17 22:24:40 -05:00
Michael Gottesman
8626cc4644 Merge pull request #29875 from gottesmm/pr-a905499d41ad40cb3a8a3deb651d2dd2fc3f8ad6
[ownership] Implement movable guaranteed scopes in ossa.
2020-02-17 19:03:59 -08:00
Matt Diephouse
a3486409c4 Use single quotes instead of backticks in diagnostics 2020-02-17 20:04:33 -05:00
Daniel Rodríguez Troitiño
02713705c8 [android][test] Mark sil_combine_alloc_stack as executable.
The Android CI machines cannot execute the test in the target devices. Marking the test as executable makes the test filtering know that this test needs to be executed in the target device.
2020-02-17 16:37:58 -08:00
Ashley Garland
be77d57121 SymbolGraph: Serialize decl and raw comment locations
- Add DocRangesLayout to the `.swiftsourceinfo`.
  This is a blob containing an array of `SingleRawComment`
  source locations.

- Add DocLocWriter for serializing `SingleRawComment` locs into the
  `DocLocsLayout` buffer.
  Serialize start line, start column, and length of `SingleRawComment`
  pieces in `.swiftsourceinfo`

- Read doc locs when loading basic declaration locs from a ModuleFile.
  - Load `DOC_LOCS` blob into ModuleFile::DocLocsData
  - Reconstitute RawComment ranges when available from .swiftsourceinfo

- Allow requesting serialized raw comment if available

rdar://problem/58339492
2020-02-17 16:20:59 -08:00
Pavel Yaskevich
15036bcead [ConstraintSystem] Fix unwrap optional base fix to preserve l-valueness of a member type 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
ca91a1bee0 [ConstraintSystem] Detect and diagnose OoO arguments in call to binary functions/operators
Identify problems like:

```swift
func foo(_ x: Int, _ y: String) {}

func bar(a: Int, b: String) {
  foo(b, a) // Instead of `foo(a, b)`
}
```

Where arguments are out-of-order and repair it by using OoO fix on the
parent locator.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
df21cbf85c [ConstraintSystem] Ignore attempt to bind type var to dependent member with incorrect base
Just like in cases where both sides are dependent member types
with resolved base that can't be simplified to a concrete type
let's ignore this mismatch and mark affected type variable as a hole
because something else has to be fixed already for this to happen.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
79b757d3cd [ConstraintSystem] Detect and diagnose mismatches in single parameter function conversions
When there is a conversion from e.g. `(A) -> Void` to `(B) -> Void`
matching between `A` and `B` is going to have a special locator which
doesn't end in `TupleElement`, so `repairFailures` has to account
for that and fix it just like regular argument mismatch.

Resolves: rdar://problem/59066040
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
f6b7df161c [ConstraintSystem] Increase impact of a missing conformance related to stdlib type
Prioritize type mismatches over conformance failures when stdlib
types are involved because it wouldn't be appropriate to suggest
to add such a conformance, so the problem is most likely related
to something else e.g. other overload choice has a better fix.

Consider following example:

```swift
struct S {
  init(_: Double) {}
  init<T: BinaryInteger>(_: T) {}
}

_ = S(Double("0"))
```

In cases like that it's better to prefer failable initializer
which takes a `String` and returns `Double?` and diagnose a
problem related to missing optional unwrap instead of missing
conformances related to a `String` argument of other `Double`
initializer just because it returns a concrete type.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
bb656e120d [CSFix] Teach getStructuralTypeContext about tuple initialization calls 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
0a8de8bda8 [ConstraintSystem] Allow simplifyRestrictedConstraintImpl to diagnose contextual failures with optionals
Since `simplifyRestrictedConstraintImpl` has both parent types and
does nested type matching it's a good place to diagnose top-level
contextual problems like mismatches in underlying types of optionals.
2020-02-17 16:09:11 -08:00
Nathan Hawes
0516c3b74f Merge pull request #29857 from nathawes/avoid-mangling-in-document-structure-request
[SourceKit] Don't report the ObjC runtime name without @objc(Name)
2020-02-17 15:27:26 -08:00
nate-chandler
de660ceea4 Merge pull request #29885 from nate-chandler/generic-metadata-prespecialization-components/stdlib-on
[metadata prespecialization] Always on for stdlib.
2020-02-17 15:04:59 -08:00
Suyash Srijan
d62411535b [CSSimplify] Guard against null locator in isSelfRecursiveKeyPathDynamicMemberLookup (#29886) 2020-02-17 21:28:44 +00:00
Nate Chandler
4475f43ba0 [metadata prespecialization] Always on for stdlib.
Regardless of any flags, the stdlib will have its generic metadata
prespecialized.

Temporarily reintroduced the flag to enable the feature flag while
preserving the flag to disable it and changed the default back to off
for the moment.
2020-02-17 11:53:27 -08:00
Erik Eckstein
a89340c7b3 SILCombine: fix a miscompile in the alloc_stack optimization which causes a use-after-free.
A "copy_addr [take] %src to [initialization] %alloc_stack" is replaced by a "destroy_addr %src" if the alloc_stack is otherwise dead.
This is okay as long as the "moved" object is kept alive otherwise.
This can break if a retain of %src is moved after the copy_addr. It cannot happen with OSSA.
So as soon as we have OSSA, we can remove the check again.

rdar://problem/59509229
2020-02-17 16:04:40 +01:00
Mike Ash
57a3df5da9 Merge pull request #29848 from mikeash/eagerly-realize-empty-singletons
[Stdlib] Eagerly realize EmptyDictionarySingleton and EmptySetSingleton.
2020-02-17 09:56:19 -05:00
Michael Gottesman
d66d329567 [diagnose-unreachable] Adjust test cases for movable guaranteed phis.
The main change is that we do not eliminate end_borrows when propagating
guaranteed phis. This is because phis now forward guaranteed ownership like
owned ownership and since we only eliminate these arguments if all incomign
values to the argument is the same (providing dominance).
2020-02-17 00:29:49 -08:00
Michael Gottesman
1fb56db502 [ownership] Implement movable guaranteed scopes in ossa.
This patch implements movable guaranteed scopes in ossa. This pattern is
currently not generated anywhere in the compiler, but my hope is to begin
emitting these in SemanticARCOpts. The idea is that these model true phi nodes
and thus can be used to fuse multiple guaranteed scopes into one using br
instructions. This is treated similarly to how owned instructions are forwarded
through /all/ terminators. This will enable us to use the SILSSAUpdater with
guaranteed arguments as well as enable the expression of sets of borrow scopes
that minimally jointly-dominate a guaranteed argument. This will enable us to
express +0 merge points like the following:

```
bb1:
  %0a = begin_borrow %0 : $Klass
  br bb3(%0a : $Klass)

bb2:
  %1a = load_borrow %1 : $*Klass
  br bb3(%1a : $Klass)

bb3(%2 : @guaranteed $Klass)
  ...
  end_borrow %2 : $Klass
```

I describe below what the semantics of guaranteed block arguments were
previously, what they are now, and a little bit of interesting things from a
semantic perspective around implicit sub-scope users.

Before this patch in ossa, guaranteed block arguments had two different sets of
semantics:

1. Given a checked_cast_br or a switch_enum, the guaranteed block argument was
   treated like a forwarding instruction. As such, the guaranteed argument's did
   not require an end_borrow and its uses were validated as part of the use list
   of the switch_enum/checked_cast_br operand's borrow introducer. It also was
   not classified as a BorrowScopeValueIntroducer since it was not introducing a
   new scope.

2. Given any other predecessor terminator, we treated the guaranteed argument as
   a complete sub-scope of its incoming values. Thus we required the guaranteed
   argument to have its lifetime eneded by an end_borrow and that all incoming
   values of the guaranteed argument to come from a borrow introducer whose set
   of jointly post-dominating end_borrows also jointly post-dominates the set of
   end_borrows associated with the guaranteed argument itself. Consider the
   following example:

```
bb0:
  %1 = begin_borrow %foo : $Foo   // (1)
  %2 = begin_borrow %foo2 : $Foo2 // (2)
  cond_br ..., bb1, bb2

bb1:
  br bb3(%1 : $Foo)

bb2:
  br bb3(%2 : $Foo)

bb3(%3 : @guaranteed $Foo)
  ...
  end_borrow %3 : $Foo            // (3)
  end_borrow %2 : $Foo            // (4)
  end_borrow %1 : $Foo            // (5)
  ...
```

Notice how due to SSA, (1) and (2) must dominate (4) and (5) and thus must
dominate bb3, preventing the borrows from existing within bb1, bb2.

This dominance property is actively harmful to expressivity in SIL since it
means that guaranteed arguments can not be used to express (without contortion)
sil code patterns where an argument is jointly-dominated by a minimal set of
guaranteed incoming values. For instance, consider the following SIL example:

```
bb0:
  cond_br ..., bb1, bb2

bb1:
  %0 = load [copy] %globalAddr : $Foo
  br bb3(%0 : $Foo)

bb2:
  %1 = copy_value %guaranteedFunctionArg : $Foo
  br bb3(%1 : $Foo):

bb3(%2 : @owned $Foo):
  apply %useFoo(%2)
  destroy_value %2 : $Foo
```

As a quick proof: Assume the previous rules for guaranteed arguments. Then to
promote the load [copy] -> load_borrow and the copy_value to a begin_borrow, we
would need to place an end_borrow in bb3. But neither bb1 or bb2 dominates bb3,
so we would violate SSA dominance rules.

To enable SIL to express this pattern, we introduce a third rule for terminator
in ossa that applies only to branch insts. All other branches that obeyed the
previous rules (cond_br), still follow the old rule. This is not on purpose, I
am just being incremental and changing things as I need to. Specifically,
guaranteed arguments whose incoming values are defined by branch instructions
now act as a move on guaranteed values. The intuition here is that these
arguments are acting as true phis in an SSA sense and thus are just new names
for the incoming values. This implies since it is just a new name (not a
semantic change) that the guaranteed incoming value's guaranteed scopes should
be fused into one scope. The natural way to model this is by treating branch
insts as consuming guaranteed values. This then lets us express the example
above without using copies as follows:

```
bb0:
  cond_br ..., bb1, bb2

bb1:
  %0 = load_borrow %globalAddr : $Foo
  br bb3(%0 : $Foo) // consumes %0 and acts as %0's end_borrow.

bb2:
  // We need to introduce a new begin_borrow here since function
  // arguments are required to never be consumed.
  %1 = begin_borrow %guaranteedFunctionArg : $Foo
  br bb3(%1 : $Foo) // consumes %1 and acts as %1's end_borrow

// %2 continues the guaranteed scope of %0, %1. This time fused with one name.
bb3(%2 : @guaranteed $Foo):
  apply %useFoo(%2)
  // End the lifetime of %2 (which implicitly ends the lifetime of %0, %1).
  end_borrow %2 : $Foo
  ...
```

The main complication for users is that now when attempting to discover the set
of implicit users on an owned or guaranteed value caused by their usage as an
argument of a borrow introducer like begin_borrow. For those who are unaware, a
begin_borrow places an implicit requirement on its parent value that the parent
value is alive for the entire part of the CFG where this begin_borrow is
live. Previously, one could just look for the end_borrows of the
begin_borrow. Now one must additionally look for consuming branch insts. This is
because the original value that is being borrowed from must be alive over the
entire web of guaranteed values. That is the entire web of guaranteed values act
as a liveness requirement on the begin_borrow's operand.

The way this is implemented is given a use that we are validating, if the use is
a BorrowScopeOperand (1), we see if the borrow scope operand consumes the given
guaranteed scope and forwards it into a borrow scope introducer. If so, we add
the list of consuming uses of the borrow scope introducer to the worklist to
visit and then iterate.

In order to avoid working with cycles, for now, the ownership verifier bans
liveness requiring uses that have cycles in them. This still allows us to have
loop carried guaranteed values.

(1) A BorrowScopeOperand is a concept that represents an operand to a SIL
instruction that begins a guaranteed scope of some sort. All BorrowScopeOperand
are thus at a minimum able to compute a compile time the static region in which
they implicitly use their operands. NOTE: We do not require the scope to be
represented as a SILValue in the same function.

We achieve some nice benefit by introducing this. Specifically:

1. We can optimize the pattern I mentioned above. This is a common pattern in
   many frameworks that want to return a default object if a computation fails
   (with the default object usually being some sort of global or static
   var). This will let us optimize that case when the global is a let global.

2. The SSA Updater can now be used with guaranteed values without needing to
   introduce extra copies. This will enable predictable mem opts to introduce
   less copies and for semantic arc opts to optimize the remaining copies that
   PMO exposes but does not insert itself.

rdar://56720519
2020-02-17 00:29:49 -08:00
Saleem Abdulrasool
379137f6f1 build: use _add_swift_target_library_single
This library is meant to run on the platform where the testing occurs,
requiring bits to run.  This makes this library a target library.
2020-02-16 13:56:06 -08:00
Saleem Abdulrasool
39d6e98b9b build: remove DONT_EMBED_BITCODE from _add_swift_host_library_single 2020-02-16 13:53:37 -08:00
Saleem Abdulrasool
9c3ec0eae4 build: remove NOSWIFTRT from _add_swift_host_library_single 2020-02-16 13:53:37 -08:00
Max Desiatov
88ad780419 Fix a few tests for WASI 2020-02-16 21:16:01 +00:00
Pavel Yaskevich
4b2b436033 Merge pull request #29845 from omochi/trailing-closure-position
[ConstraintSystem] Accept trailing closure if multiple defaulted parameters after last function parameter
2020-02-15 19:50:08 -08:00
Jonathan Keller
1feead804b [SILOptimizer] fix KeyPathProjector memory management
I was inconsistently providing initialized or uninitialized memory
to the callback when projecting a settable address, depending on
component type. We should always provide an uninitialized address.
2020-02-15 15:10:25 -08:00
omochimetaru
252e82ff7b [ConstrainySystem] Accept trailing closure if multiple...
defaulted parameters are after last function parameter
2020-02-16 07:48:39 +09:00
Suyash Srijan
a0d3542d08 [Typechecker] Covariant subscript check must also take into consideration that there may be a type mismatch (#29828) 2020-02-15 12:52:53 +00:00
eeckstein
c3be957bd1 Merge pull request #29844 from eeckstein/test-for-irgen-crash
add a test for an IRGen crash
2020-02-15 10:12:11 +01:00
Lang Hames
7a0754b127 [Immediate] Switch immediate mode from MCJIT to LLJIT.
LLJIT is a simple LLVM IR JIT. Its interface is similar to MCJIT, but its
implementation is based on LLVM's newer ORC APIs. This initial patch does not
make use of any of LLJIT/ORC's advanced features, but will provide better
diagnostics when JIT'd code fails to link. Once LLJIT has proven usable in
this basic configuration we can start experimenting with more advanced
features, including lazy compilation.
2020-02-14 17:59:23 -08:00
Holly Borla
c0d936ec8d [Sema] Implement type checking for the typeEraser attribute. 2020-02-14 17:47:23 -08:00
Michael Gottesman
17082f342f [ownership] Split out the gathering of users of non-guaranteed values into its own helper function.
This enables me to simplify the code by not using the worklist for
non-guaranteed values (where it is not necessary). I think the non-guaranteed
value handling snuck in over time. I don't think in the non-guaranteed case we
/ever/ used the actual worklist functionality.

This also enabled me to safely, algebraically eliminate unnecessary variables
making the code easier to read (since less indirection).
2020-02-14 14:57:25 -08:00
nate-chandler
c14a2eea94 Merge pull request #29834 from nate-chandler/generic-metadata-prespecialization-components/linkonceodr
[metadata prespecialization] Specify linkage to be shared.
2020-02-14 14:23:02 -08:00
Dan Zheng
b4e0385080 [AutoDiff] NFC: make FileCheck test work on master and tensorflow. (#29839)
This is necessary because the `Differentiable` protocol exists in stdlib core
on `tensorflow` branch but in the `_Differentiation` module on `master` branch.

The robust solution is to add auto-import `_Differentiation` logic to `tensorflow`.
2020-02-14 12:25:13 -08:00
Nathan Hawes
2420b6d28b [SourceKit] Don't report the ObjC runtime name without @objc(Name)
We used to compute the mangled name in other cases, but document structure is
a syntactic request and can't guarantee that the class/protocol we're getting
the mangled name of is valid in any way so it often breaks assumptions in the
mangler and causes it to crash. It's not clear if the runtime_name is actually
being used anymore, so this change restricts reporting it to just the cases
where we don't need to mangle.

rdar://problem/40956377
2020-02-14 11:40:09 -08:00
Nate Chandler
d44247a0ed [metadata prespecialization] Specify linkage to be shared.
Prespecialized metadata may be requested in multiple modules and those
definitions must be deduplicated when statically linking those modules
together.

Here, the SILLinkage for prespecialized metadata is specified to be
Shared.  Consequently, the IRLinkage's Linkage for this record is made
to be LinkOnceODRLinkage.

rdar://problem/56997414
2020-02-14 09:29:53 -08:00
Mike Ash
440d2799f7 [Stdlib] Eagerly realize EmptyDictionarySingleton and EmptySetSingleton.
These objects can escape into ObjC without their class being realized first, which can cause a crash if the unrealized class gets passed into the ObjC runtime.

rdar://problem/59295395
2020-02-14 11:57:52 -05:00