Commit Graph

39091 Commits

Author SHA1 Message Date
Pavel Yaskevich
f7b264583d [Diagnostic] Don't fix partial mismatch for sub-types associated with optional conversion
If mismatch detected by `repairFailures` is related to a complex
wrapped value of optional type formed from optional-to-optional
or value-to-optional conversion let's not try to fix it directly
but let `simplifyRestrictedConstraintImpl` record a top-level fix
for more context.

Resolves: rdar://problem/59703585
2020-03-03 00:24:34 -08:00
Michael Gottesman
ae2bef9f1e Merge pull request #30069 from gottesmm/pr-cdc5d32f1a5317b8716c016a0e72f9ee40eae4dd
[semantic-arc] Change StorageGuaranteesLoadVisitor::visitClassAccess to find borrow scope introducers using utilities from OwnershipUtils.h.
2020-03-02 22:58:01 -08:00
Robert Widmann
f142eedd52 Merge pull request #30171 from CodaFi/object-permanence
[Sema] Don't Emit @objc Fixits Into Extant Modules
2020-03-02 20:08:36 -08:00
Xi Ge
407f2b4047 Merge pull request #30163 from nkcsgexi/remove-assert-decl
ABI checker: remove assert-only decls from the generated stdlib ABI baseline
2020-03-02 19:30:52 -08:00
Francis Visoiu Mistrih
e724ebab6b [Remarks] Add a specialized RemarkStreamer for SIL remarks
This allows the usage of the whole remark infrastructure developed in
LLVM, which includes a new binary format, metadata in object files, etc.

This gets rid of the YAMLTraits-based remark serialization and does the
plumbing for hooking to LLVM's main remark streamer.

For more about the idea behind LLVM's main remark streamer, see the
docs/Remarks.rst changes in https://reviews.llvm.org/D73676.

The flags are now:

* -save-optimization-record: enable remarks, defaults to YAML
* -save-optimization-record=<format>: enable remarks, use <format> for
serialization
* -save-optimization-record-passes <regex>: only serialize passes that
match <regex>.

The YAMLTraits in swift had a different `flow` setting for the debug
location, resulting in some test changes.
2020-03-02 18:33:20 -08:00
Doug Gregor
4b43573693 [Constraint system] Implement switch support for function builders.
Implement support for switch statements within function builders. Cases can
perform arbitrary pattern matches, e.g.,

    tuplify(true) { c in
      "testSwitchCombined"
      switch e {
      case .a:
        "a"
      case .b(let i, _?), .b(let i, nil):
        i + 17
      }
    }

subject to the normal rules of switch statements. Cases within function
builders cannot, however, include “fallthrough” statements, because those
(like “break” and “continue”) are control flow.

The translation of performed for `switch` statements is similar to that of
`if` statements, using `buildEither(first:)` and `buildEither(second:)` on
the function builder type.

This is the bulk of switch support, tracked by rdar://problem/50426203.
2020-03-02 17:25:25 -08:00
AG
2e70d45afd Merge pull request #30140 from bitjammer/acgarland/rdar-59841727-sg-granular-kinds
SymbolGraph: Add more granular kinds
2020-03-02 17:15:37 -08:00
Robert Widmann
011c14d61c [Hack] Windows Doesn't Support Globstar 'find' 2020-03-02 16:45:37 -08:00
Robert Widmann
2bd112d653 [Incremental] Rudimentary Tests for Verified Dependencies 2020-03-02 16:45:37 -08:00
Robert Widmann
3c9b592b8b [Incremental] Add a utility for generating simple output file maps 2020-03-02 16:45:37 -08:00
Ben Langmuir
5f3a1a397b [cursorinfo] Avoid use of null raw value in enum element decl
SR-12283
rdar://59857568
2020-03-02 16:29:17 -08:00
Robert Widmann
a1397a8c60 [Sema] Don't Emit @objc Fixits Into Extant Modules
Overlays are specifically allowed to do magic things that regular Swift
modules are not. In this case, the UIImage and NSImage overlays have
extensions that allow them to conform to `_ExpressibleByImageLiteral`.
This, unfortunately, means that subclassing these classes with the
overlays present is impossible as one must override the required
initializers, but one cannot override these initializers since they are
declared in an extension.

While we cannot correct the overlays without breaking ABI, we can at
least make sure we don't attempt to stick @objc into them when users
have a go at subclassing these classes.

Resolves rdar://59610201
2020-03-02 16:27:06 -08:00
Hamish Knight
f56b061407 [Parse] Check the SourceFile for #if evaluation
Remove the `EvaluateConditionals` flags from the
parser, and instead query the source file.

This commit also changes ParserUnit such that it
doesn't evaluate #if conditions by default, as
none of its clients appear to require it. The
only client that wasn't explicitly disabling #if
evaluation and is processing the resulting AST is
swift-indent, so this commit also adds a test to
ensure it continues to work correctly with #if
decls.
2020-03-02 14:12:37 -08:00
Xi Ge
0aea09fa14 ABI checker: remove assert-only decls from the generated stdlib ABI baseline
rdar://59772479
2020-03-02 14:01:53 -08:00
Pavel Yaskevich
b5cb81bd0a Merge pull request #30160 from xedin/rdar-59773317
[ConstraintSystem] Don't record general contextual mismatch if there are restrictions present
2020-03-02 13:11:32 -08:00
Ashley Garland
72715eaf71 SymbolGraph: Add more granular kinds
This is necessary to disambiguate some symbols with the same path components
and makes the data clearer to debug.

rdar://problem/59841727
2020-03-02 12:34:03 -08:00
Pavel Yaskevich
0cd44a83a7 [ConstraintSystem] Don't record general contextual mismatch if there are restrictions present
If there are any conversion restrictions present while trying to repair
failures related to contextual type, let's give `simplifyRestrictedConstraintImpl`
a chance to run and fix the problem.

Resolves: rdar://problem/59773317
2020-03-02 11:07:31 -08:00
Erik Eckstein
370082babe GlobalOpt: handle access markers correctly.
rdar://problem/59345288
2020-03-02 18:18:30 +01:00
Martin Boehme
f81ef9cf1e Prepend "diagnostic produced by Clang:" to Clang diagnostics. 2020-03-02 14:56:42 +01:00
Martin Boehme
323721b5d1 Fix verify-broken-c-module to work on macOS.
Shorten expected error message so that it doesn't expect "C module" (and
breaks if presented with "Objective-C module").
2020-03-02 14:56:42 +01:00
Martin Boehme
f51f632c43 Use "not" instead of "set +o pipefail"; improve "broken" header.
A header shouldn't contain a function body unless the function is
inline. Following gribozavr's suggestion, I'm using the easier solution
of omitting the semicolon from the function prototype.

(In response to review comments.)
2020-03-02 14:56:42 +01:00
Martin Boehme
ca9df83fef Add tests for -verify mode. 2020-03-02 14:56:42 +01:00
Michael Gottesman
962b4ed633 [semantic-arc] Change StorageGuaranteesLoadVisitor::visitClassAccess to find borrow scope introducers using utilities from OwnershipUtils.h.
I added a new API into OwnershipUtils called
getSingleBorrowIntroducingValue. This API returns a single
BorrowScopeIntroducingValue for a passed in guaranteed value. If we can not find
such a BorrowScopeIntroducingValue or we find multiple such, we return None.

Using that, I refactored StorageGuaranteesLoadVisitor::visitClassAccess(...) to
use this new API which should make it significantly more robust since the
routine uses the definitions of "guaranteed forwarding" that the ownership
verifier uses when it verifies meaning that we can rely on the routine to be
exhaustive and correct. This means that we now promote load [copy] ->
load_borrow even if our borrow scope introducer feeds through a switch_enum or
checked_cast_br result (the main reason I looked into this change).

To create getSingleBorrowIntroducingValue, I refactored
getUnderlyingBorrowIntroucingValues to use a generator to find all of its
underlying values. Then in getSingleBorrowIntroducingValue, I just made it so
that we call the generator 1-2 times (as appropriate) to implement this query.
2020-03-02 00:35:41 -08:00
Michael Gottesman
926f105413 Merge pull request #30087 from gottesmm/pr-7d5f0d45e4677ebbd92aeb1e261ab388a4ca5756
[ownership] Add simple support for concatenating together simple live ranges
2020-03-02 00:28:33 -08:00
Michael Gottesman
bdf6143df5 [ownership] Add simple support for concatenating together simple live ranges that do not need LiveRange analysis.
Specifically, this PR adds support for optimizing simple cases where we do not
need to compute LiveRanges with the idea of first doing simple transforms that
involve small numbers of instructions first. With that in mind, we only optimize
cases where our copy_value has a single consuming user and our owned value has a
single destroy_value. To understand the transform here, consider the following
SIL:

```
  %0 = ...
  %1 = copy_value %0                 (1)
  apply %guaranteedUser(%0)          (2)
  destroy_value %0                   (3)
  apply %cviConsumer(%1)             (4)
```

We want to eliminate (2) and (3), effectively joining the lifetimes of %0 and
%1, transforming the code to:

```
  %0 = ...
  apply %guaranteedUser(%0)          (2)
  apply %cviConsumer(%0)             (4)
```

Easily, we can always do this transform in this case since we know that %0's
lifetime ends strictly before the end of %1's due to (3) being before (4). This
means that any uses that require liveness of %0 must be before (4) and thus no
use-after-frees can result from removing (3) since we are not shrinking the
underlying object's lifetime. Lets consider a different case where (3) and (4)
are swapped.

```
  %0 = ...
  %1 = copy_value %0                 (1)
  apply %guaranteedUser(%0)          (2)
  apply %cviConsumer(%1)             (4)
  destroy_value %0                   (3)
```

In this case, since there aren't any liveness requiring uses of %0 in between
(4) and (3), we can still perform our transform. But what if there was a
liveness requiring user in between (4) and (3). To analyze this, lets swap (2)
and (4), yielding:

```
  %0 = ...
  %1 = copy_value %0                 (1)
  apply %cviConsumer(%1)             (4)
  apply %guaranteedUser(%0)          (2)
  destroy_value %0                   (3)
```

In this case, if we were to perform our transform, we would get a use-after-free
due do the transform shrinking the lifetime of the underlying object here from
ending at (3) to ending at (4):

```
  %0 = ...
  apply %cviConsumer(%1)             (4)
  apply %guaranteedUser(%0)          (2) // *kaboom*
```

So clearly, if (3) is after (4), clearly, we need to know that there aren't any
liveness requiring uses in between them to be able to perform this
optimization. But is this enough? Turns out no. There are two further issues
that we must consider:

1. If (4) is forwards owned ownership, it is not truly "consuming" the
underlying value in the sense of actually destroying the underlying value. This
can be worked with by using the LiveRange abstraction. That being said, this PR
is meant to contain simple transforms that do not need to use LiveRange. So, we
bail if we see a forwarding instruction.

2. At the current time, we may not be able to find all normal uses since all of
the instructions that are interior pointer constructs (e.x.: project_box) have
not been required yet to always be guarded by borrows (the eventual end
state). Thus we can not shrink lifetimes in general safely until that piece of
work is done.

Given all of those constraints, we only handle cases here where (3) is strictly
before (4) so we know 100% we are not shrinking any lifetimes. This effectively
is causing our correctness to rely on SILGen properly scoping lifetimes. Once
all interior pointers are properly guarded, we will be able to be more
aggressive here.

With that in mind, we perform this transform given the following conditions
noting that this pattern often times comes up around return values:

1. If the consuming user is a return inst. In such a case, we know that the
   destroy_value must be before the actual return inst.

2. If the consuming user is in the exit block and the destroy_value is not.

3. If the consuming user and destroy_value are in the same block and the
   consuming user is strictly later in that block than the destroy_value.

In all of these cases, we are able to optimize without the need for LiveRanges.
I am going to add support for this in a subsequent commit.
2020-03-01 19:59:54 -08:00
John McCall
9df969a627 Mangle coroutine information when mangling SILFunctionTypes. 2020-03-01 22:40:43 -05:00
3405691582
5847726f51 Preliminary support for OpenBSD in the stdlib.
These should hopefully all be uncontroversial, minimal changes to deal
with progressing the build to completion on OpenBSD or addressing minor
portability issues. This is not the full set of changes to get a
successful build; other portability issues will be addressed in future
commits.

Most of this is just adding the relevant clauses to the ifdefs, but of
note in this commit:

* StdlibUnittest.swift: the default conditional in _getOSVersion assumes
  an Apple platform, therefore the explicit conditional and the relevant
  enums need filling out. The default conditional should be #error, but
  we'll fix this in a different commit.

* tgmath.swift.gyb: inexplicably, OpenBSD is missing just lgammal_r.
  Tests are updated correspondingly.

* ThreadLocalStorage.h: we use the pthread implementation, so it
  seems we should typedef __swift_thread_key_t as pthread_key_t.
  However, that's also a tweak for another commit.
2020-03-01 12:50:06 -05:00
David Ungar
72032493f9 Fix and test for extension body 2020-02-29 23:19:09 -08:00
David Ungar
ff1398ef0a Merge pull request #30143 from davidungar/just-tests-2-29
[NFC, Incremental] Add class, enum, protocol tests for type-fingerprints
2020-02-29 13:16:08 -08:00
David Ungar
fb2e0e7d13 Add class, enum, protocol tests for type-fingerprints and put in separate directory 2020-02-29 10:52:20 -08:00
Owen Voorhees
f0eb312594 Merge pull request #30116 from owenv/property-wrapper-note
[Diagnostics] Tweak @propertyWrapper diagnostic wording and add an educational note
2020-02-29 09:39:18 -08:00
Robert Widmann
bd30df994b Merge pull request #30083 from 3405691582/OpenBSD_Port_BasicDriver
Swift Basic/Driver recognizes OpenBSD.
2020-02-28 17:00:37 -08:00
Rintaro Ishizaki
78d0f6aa4a [CodeCompletion] Primarily use getPossibleCallees() for call signature completion
instead of the pre-typechecked type and the referenced decl in the AST
so that we can suggests all overloads even if it happen to be
typechecked to a method. For example

    struct MyType {
      func foo() {}
      func foo(_ int: Int) {}
      func foo(name: String, value: String) {}
    }
    func test(val: MyType) {
      value.foo(#^COMPLETE^#)
    }

In this case, the call is typechecked to 'MyType.foo(_:)', but we want
to suggest all overloads.

rdar://problem/59285399
2020-02-28 16:44:03 -08:00
Owen Voorhees
05e6364d39 Merge pull request #30125 from benlangmuir/win-path
Update test for Windows path
2020-02-28 16:41:47 -08:00
Michael Gottesman
c4fe3c225b Merge pull request #30088 from gottesmm/pr-3e6f27334eea2b48b5d8768445143250d4fa13d4
[temp-rvalue] Handle promoting alloc_stack that are destroyed via a load [take] in ossa.
2020-02-28 15:23:54 -08:00
Suyash Srijan
956e918476 [CSSimplify] Move property wrapper fix check after check for conversion restrictions (#30129) 2020-02-28 23:16:32 +00:00
Joe Groff
4abb548adb IRGen: Invoke objc_opt_self directly when available.
We don't need swift_getInitializedObjCClass on new enough Apple OSes because
the ObjC runtime provides an equivalent call for us.
2020-02-28 10:36:42 -08:00
Holly Borla
87bb7755c2 Merge pull request #30101 from hborla/dynamic-replacement-type-erasure
[Sema] Implement type erasure for dynamic replacement.
2020-02-28 09:37:33 -08:00
Ben Langmuir
1b3d1cecdb Allow repeated separators 2020-02-28 09:34:53 -08:00
Ben Langmuir
eec814fa4f Update test for Windows path 2020-02-28 08:48:48 -08:00
David Ungar
b8603566fd Merge pull request #30123 from davidungar/fix-overly-conservative-fingerprint-bug
[Incremental] Fix overly conservative fingerprint bug & fix tests.
2020-02-28 01:31:38 -08:00
Pavel Yaskevich
c0b9394c42 Merge pull request #30113 from xedin/rdar-54580247
[CSBindings] Open collection before binding parameter only if origina…
2020-02-28 00:01:27 -08:00
David Ungar
d09c906553 Fix overly conservative fingerprint bug & fix tests. 2020-02-27 23:38:03 -08:00
Saleem Abdulrasool
136e6c42a6 Merge pull request #30118 from compnerd/30058
test: loosen the overly-restrictive test
2020-02-27 23:05:06 -08:00
Doug Gregor
3d9f753f87 Merge pull request #30111 from DougGregor/pattern-implicit-some-harder
[Constraint system] Handle implicit "some" patterns implicitly, better.
2020-02-27 20:57:29 -08:00
Saleem Abdulrasool
40e91a8528 test: loosen the overly-restrictive test
The types may be emitted in a different order.  Be more permissive about
ordering.
2020-02-27 20:55:33 -08:00
Owen Voorhees
c75a363e1c Tweak @propertyWrapper diagnostics and add an educational note 2020-02-27 20:28:28 -08:00
Slava Pestov
ea9806d490 Merge pull request #30097 from slavapestov/sr-75-super-method
Sema: Diagnose unbound method references on 'super.'
2020-02-27 23:06:33 -05:00
Andrew Trick
631555aa01 Merge pull request #29738 from zoecarver/ossa/let-prop-opt
[ownership] update let properties opts to support ossa
2020-02-27 18:32:02 -08:00
Michael Gottesman
3a725c3217 [temp-rvalue] Handle promoting alloc_stack that are destroyed via a load [take] in ossa.
There are a few interesting things here:

1. All of this code is conditionalized implicitly on ossa by us checking for
load [take]. If we are in non-ossa, then we will have unqualified loads and this
code path will be skipped. I left in the old test that made sure we did not
support this in non-ossa code for this purpose.

2. We treat the load [take] like a destroy_addr. Thus the current method of
providing safety via using lifetime analysis to show all "destroys" form a
minimal post-dominating set for the copy_addr.

3. We do not allow for load [take] on sub-element initializations. The reason
why is that SILGen initializes temporaries completely in memory and generally
destroys addresses completely as well. Given that is the pattern we are looking
for, we just reduce the state space by banning this pattern.

4. If we have a copy_addr [init], then we not only change the load [take] to
have the original source address as an argument, but we also change the load
[take] to a load [copy] so we don't lose the +1. Additionally, we have to hoist
the load [copy] to the copy_addr [init] site to ensure that we do not insert a
use-after-free from the retain happening too late.

I am doing this to clean up some simple temp rvalue patterns in SIL before
semantic arc opts runs. This ensures that we are more likely to have a load
operation come from a more meaningful semantic entity (for instance a let field
of a guaranteed class) and thus allow us to convert a load [copy] to a
load_borrow.

I am also going to add support in subsequent commits for eliminating alloc_stack
that are stored into as well (another pattern I am seeing).
2020-02-27 17:09:37 -08:00