Commit Graph

43616 Commits

Author SHA1 Message Date
Michael Gottesman
f67c52ee1a [ownership] ref_to_* and *_to_ref produce values with OwnershipKind::Unowned so should be treated as PointerEscapes.
These instructions model a conversion in between ownership kinds without the result actually being owned by anything. As a result:

1. From an operand perspective, the instruction is treated like a pointer escape.
2. From a value perspective, the instruction returns a value with
   OwnershipKind::Unowned (to force the value to be copied before it can be used
   in an owned or guaranteed way) and

Example:

```
sil @example : $@convention(thin) (@owned Klass) -> @owned @sil_unowned Klass {
bb0(%0 : @owned $Klass):
  // Note that the ref_to_unowned does not consume %0 but instead converts %0
  // from a "strong" value to a "safe unowned" value. A "safe unowned" value is
  // a value that corresponds to an 'unowned' value at the Swift level that use
  // unowned reference counting. At the SIL level these values can be recognized
  // by their types having the type attribute @sil_unowned. We have not
  // incremented the unowned ref count of %1 so we must treat %1 as unowned.
  %1 = ref_to_unowned %0 : $Klass
  // Then before we can use %2 in any way as a "safe unowned" value we need to
  // bump its unowned ref count by making a copy of the value. %2 will be a
  // "safe unowned" value with OwnershipKind::Owned ensuring that we decrement
  // the unowned ref count and do not leak said ref count.
  %2 = copy_value %1 : $@sil_unowned $Klass
  // Then since the original ref_to_unowned did not consume %0, we need to
  // destroy it here.
  destroy_value %0 : $Klass
  // And then return out OwnershipKind::Owned @sil_unowned Klass.
  return %2 : $@sil_unowned $Klass
}
```
2021-01-04 15:37:57 -08:00
Andrew Trick
3a1c8fdd8b Merge pull request #35248 from atrick/fix-operandownership
OperandOwnership fixes required for CanonicalOSSA
2021-01-04 15:06:12 -08:00
Doug Gregor
79c4e3c64f Merge pull request #35214 from DougGregor/await-try-to-try-await
[Concurrency] `await try` -> `try await`
2021-01-04 10:52:21 -08:00
Andrew Trick
4678567700 Fix a bunch of test cases with illegal OSSA
Borrowing an unowned value is illegal.
2021-01-01 21:20:23 -08:00
Andrew Trick
5b37728f2a Fix OSSA in SILGenFunction::emitIVarDestroyer
It is illegal to borrow an unowned value. Unowned values are only
allowed to have specific instantaneous uses.

In this case, an unchecked conversion is valid because there is an
assumption that within a destructor, self is guaranteed.
2021-01-01 19:22:19 -08:00
Andrew Trick
bc01d97da6 Add a begin_borrow canonicalization test case.
Canonicalization should be able to convert a nested borrow to a
borrow. In this case, the coroutine was a nested borrow and becomes a
borrow.
2021-01-01 19:22:19 -08:00
Andrew Trick
cead6a5122 Add an OptimizedMandatoryCombine pass variant.
It's against the principles of pass design to check the driver mode
within the pass. A pass always needs to do the same thing regardless
of where it runs in the pass pipeline. It also needs to be possible to
test passes in isolation.
2021-01-01 19:22:19 -08:00
Mishal Shah
949b0c0cc3 Merge pull request #35217 from dan-zheng/autodiff-testing
[AutoDiff] Disable flaky test on Linux.
2020-12-23 15:56:09 -08:00
Dan Zheng
f2de54678b [AutoDiff] Disable flaky test on Linux.
Disable test that occasionally flake on Linux.

SR-13021 tracks re-enabling related failing AutoDiff tests.
2020-12-23 18:54:04 -05:00
Mishal Shah
f588e2a3ce Disable subclass_existentials.swift test because it's failing on Ubuntu 20.04, 18.04 and CentOS 8 2020-12-23 15:30:40 -08:00
Doug Gregor
3c38ffe0ea [Concurrency] await try -> try await
The `try await` ordering is both easier to read and indicates the order
of operations better, because the suspension point occurs first and
then one can observe a thrown error.
2020-12-23 13:21:59 -08:00
Meghana Gupta
b99533aced Merge pull request #34895 from meg-gupta/cseossa
Enable CSE on OSSA
2020-12-23 09:58:46 -08:00
Xi Ge
2497273e53 Merge pull request #35213 from nkcsgexi/72627921
test: xfail SILOptimizer/semantic-arc-opt-unchecked-ownership-conversion.sil
2020-12-23 09:52:24 -08:00
Xi Ge
b27b97ca75 test: xfail SILOptimizer/semantic-arc-opt-unchecked-ownership-conversion.sil
rdar://72627921
2020-12-23 09:51:05 -08:00
Mishal Shah
2d9bb447e9 Merge pull request #35209 from rintaro/rdar72627583-disable
[Tests] Disable a failing test case
2020-12-23 09:38:56 -08:00
Rintaro Ishizaki
8f8846342f [Tests] Disable a failing test case
While investigating

rdar://problem/72627583
2020-12-23 09:36:44 -08:00
Kavon Farvardin
179474e185 Merge pull request #35153 from kavon/warn-unqualified-await
[concurrency] warn about future reservation of 'await' as contextual keyword
2020-12-23 09:20:18 -08:00
Dan Zheng
07f632acaa [AutoDiff] NFC: document test suite. (#35194)
Add README files explaining the differentiable programming test suite.

Add lit.local.cfg files so individual tests do not need to add
`REQUIRES: asserts` in these directories:

- test/AutoDiff/compiler_crashers
- test/AutoDiff/compiler_crashers_fixed

Motivation: it is important for compiler crasher tests to require assertions
enabled, because many of these tests crash on compiler assertions.
2020-12-23 07:19:19 -05:00
Doug Gregor
dbcf7fe1bf Merge pull request #35203 from DougGregor/concurrency-better-data-race-checking
[Concurrency] Improve data-race detection for locals and globals
2020-12-22 23:32:22 -08:00
Meghana Gupta
42c031985c Enable CSE on OSSA 2020-12-22 23:20:06 -08:00
Michael Gottesman
e1a616f1d4 Merge pull request #35198 from gottesmm/pr-0d922ed7f7078d21e2bbfc5273730703a61d7c08
[sil-combine] Update RefToRawPointer simplifications for ossa.
2020-12-22 21:28:24 -08:00
Michael Gottesman
890b202e57 Merge pull request #35201 from gottesmm/pr-2eaac17ecf4cc7ea6dd806b11049581c9e4ca1d4
[sil-combine] Update unchecked_ref_cast_addr -> unchecked_ref_cast given loadable types for OSSA.
2020-12-22 21:28:07 -08:00
Zoe Carver
a304967453 Merge pull request #35197 from zoecarver/cxx/forward-declared-subdecl
[cxx-interop] Fix forward declared nested structs.
2020-12-22 20:32:45 -08:00
Michael Gottesman
0d2047a359 [sil-combine] Update RefToRawPointer simplifications for ossa.
These are always safe in OSSA since what we are doing here is hoisting the
ref_to_raw_pointer up the def-use chain without deleting any instructions unless
we know that they do not have any uses (in a strict sense so destroy_value is
considered a use). E.x.:

```
%0 = ...
%1 = unchecked_ref_cast %0
%2 = ref_to_raw_pointer %1
```

->

```
%0 = ...
%1 = unchecked_ref_cast %0
%2 = ref_to_raw_pointer %0
```

Notice, how we are actually not changing %1 at all. Instead we are just moving
an instantaneous use earlier. One thing that is important to realize is that
this /does/ cause us to need to put the ref_to_raw_pointer at the insert
location of %0 since %0's lifetime ends at the unchecked_ref_cast if the value
is owned.

NOTE: I also identified the tests from sil_combine.sil that had to do with these
simplifications and extracted them into sil_combine_casts.sil and did the
ossa/non-ossa tests side by side. I am trying to fix up the SILCombine tests as
I update stuff, so if I find opportunities to move tests into a more descriptive
sub-file, I am going to do so.

As an aside, to make it easier to transition SILCombine away from using a
central builder, I added a withBuilder method that creates a new SILBuilder at a
requested insertPt and uses the same context as the main builder of
SILCombine. It also through the usage of auto makes really concise pieces of
code. Today to do this just using builder, we would do:

```
SILBuilderWithScope builder(insertPt, Builder);
builder.createInst1(insertPt->getLoc(), ...);
builder.createInst2(insertPt->getLoc(), ...);
builder.createInst3(insertPt->getLoc(), ...);
auto *finalValue = builder.createInst4(insertPt->getLoc(), ...);
```

Thats a lot of typing and wastes a really commonly used temp name (builder) in
the local scope! Instead, using this API, one can write:

auto *finalValue = withBuilder(insertPt, [&](auto &b, auto l) {
  b.createInst1(l, ...);
  b.createInst2(l, ...);
  b.createInst3(l, ...);
  return b.createInst4(l, ...);
});

There is significantly less to type and auto handles the types for us. The
withBuilder construct is just syntactic since we always inline it.
2020-12-22 17:25:47 -08:00
Doug Gregor
f70e9213df [Concurrency] Improve data-race detection for locals and globals
Improve data-race detection for local variables and global/static variables
* Only diagnose these cases at all, not (e.g.) class instance members
* For local functions, they run concurrently if they were referenced somewhere
  that runs concurrently

The latter required moving checking of both actor isolation and effects
for local functions to the point at which their enclosing (non-local)
functions are checked, because we need to reason about the
type-checked bodies of local functions.
2020-12-22 16:39:02 -08:00
Michael Gottesman
6f3e88013e [sil-combine] Update unchecked_ref_cast_addr -> unchecked_ref_cast given loadable types for OSSA.
This involves just performing a load [take] + unchecked_ref_cast + store [init].

The test is ported from sil_combine_cast_foldings.sil
2020-12-22 16:34:43 -08:00
Kavon Farvardin
fa0c01ff65 add regression test for unescape await warning 2020-12-22 15:46:30 -08:00
David Ungar
e1f35f676d Merge pull request #35189 from davidungar/xf
[Incremental, swift-driver] Supply ready-made .swiftdeps files so that an actual compilation isn't needed.
2020-12-22 15:00:54 -08:00
zoecarver
8746d046a1 [cxx-interop] Define implict constructor on the definition.
Make sure that we define a C++ record's implicit constructor on the
record's definition, not just on a declaration.
2020-12-22 13:32:15 -08:00
zoecarver
7ac1b8121e [cxx-interop] Skip forward-declared nested structs.
This prevents us from accidentially adding the same sub-type twice.
2020-12-22 13:23:12 -08:00
Evan
698a0a3bed Merge pull request #35193 from etcwilde/ewilde/there-is-no-try-on-main-only-do
Adding implicit try-expr to throwing main
2020-12-22 13:16:40 -08:00
David Ungar
ff2e1af056 Use yaml files and convert them. 2020-12-22 10:35:31 -08:00
Evan Wilde
efb50e1392 Adding implicit try-expr to throwing main
Synthesizing the body of a throwing main didn't take into account the
implicit try. We were creating one, then just leaving it off. This patch
actually passes the modified AST branch through to the emitted return
statement, rather than just keeping the call.

As a separate note, I hit an assert saying that a source range must
either be completely invalid or completely valid when just passing the
invalid SourceLoc to the TryExpr. I've changed it to just take the
SourceLoc from the implicit CallExpr, which should be the same as the
invalid SourceLoc, but seems to inherit it from another place.
2020-12-22 10:15:13 -08:00
Ben Langmuir
6220644f78 Merge pull request #34978 from buttaface/linker-target
[Driver] Remove redundant clang '-target' flag that wasn't being used
2020-12-22 09:05:48 -08:00
David Ungar
8fa8decf23 Supply ready-made .swiftdeps files so that an actual compilation isn't needed. 2020-12-21 19:40:16 -08:00
Michael Gottesman
d3d1f8d22d Merge pull request #35184 from gottesmm/pr-e067733b5acddbafbf2e52d8d9994aa8d7b3dac5
[sil-combine] Add sil_combine_ prefix to a test that is a sil-combine test.
2020-12-21 18:18:02 -08:00
Michael Gottesman
75814e9a7f Merge pull request #35182 from gottesmm/pr-c252916df0109f89d79567d71f8772ba7a2fdb73
[sil-combine] Enable dead alloc_ref elim for ossa.
2020-12-21 15:32:47 -08:00
Michael Gottesman
f4722d20e8 Merge pull request #35181 from gottesmm/pr-6e15491b7d27fb108c6854ea1dfde8a758972512
[sil-combine] Enable convert_escape_to_no_escape -> thin_to_thick_function for ossa.
2020-12-21 15:32:14 -08:00
Michael Gottesman
79215a4952 [sil-combine] Add sil_combine_ prefix to a test that is a sil-combine test. 2020-12-21 13:40:38 -08:00
Michael Gottesman
5720d30c9a [sil-combine] Enable convert_escape_to_no_escape -> thin_to_thick_function for ossa.
Also begin a test file for casts specifically.
2020-12-21 13:10:40 -08:00
Michael Gottesman
04ffcafaa5 [sil-combine] Enable dead alloc_ref elim for ossa.
It was just looking for an alloc_ref that only has dealloc_ref,
set_deallocating, fix_lifetime users.
2020-12-21 13:07:00 -08:00
David Ungar
49de1ea27b XFAIL bindings-build-record.swift 2020-12-21 10:42:09 -08:00
Xi Ge
f8d8a64e30 test: xfail Driver/Dependencies/bindings-build-record.swift
rdar://72550007
2020-12-21 07:19:07 -08:00
Michael Gottesman
061632edef [sil-combine] Update fix_lifetime opts for ownership
The one opt we perform here is that we promote fix_lifetime on loadable
alloc_stack addresses to fix_lifetimes on objects by loading the underlying
value and putting the fix lifetime upon it.
2020-12-20 21:22:19 -08:00
David Ungar
e328fb3d97 Merge pull request #35171 from davidungar/fixing-tests4
[Incremental Swift Driver] Generalize Driver/Dependencies tests
2020-12-20 17:54:26 -08:00
Robert Widmann
5fc9b9104b Merge pull request #35170 from hamishknight/request-denied
[ASTDumper] Don't call isFinal()
2020-12-20 14:50:51 -08:00
David Ungar
50d2d4f87c Swift-driver does not even start compiling files modified during build 2020-12-20 10:14:41 -08:00
David Ungar
862243b0c5 Update bindings-build-record.swift 2020-12-20 10:13:51 -08:00
David Ungar
0cd3f98c1a swift-driver cannot reasonably include condition in print-bindings 2020-12-20 10:12:40 -08:00
David Ungar
3991e24daf Account for swift-driver checking all outputs. 2020-12-20 10:12:10 -08:00