Commit Graph

58361 Commits

Author SHA1 Message Date
Erik Eckstein
d282eaaee1 Demangler: print substitutions in Demangler::dump()
For better debugging of the demangler.
2020-03-03 11:25:07 +01:00
eeckstein
0dd3c7ce79 Merge pull request #30156 from eeckstein/global-opt-fix
GlobalOpt: handle access markers correctly.
2020-03-03 11:23:25 +01:00
Dmitri Gribenko
e83f58ffba Merge pull request #30028 from martinboehme/verify-fix
If `-verify` mode saw unexpected diagnostics, print diagnostics from all files.
2020-03-03 10:09:45 +01:00
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
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
Hamish Knight
9fcda110df [CS] Another post CSDiag cleanup (#30168)
[CS] Another post CSDiag cleanup
2020-03-02 17:07:18 -08:00
Robert Widmann
6ccba70bb3 [Incremental] Introducing: DependencyVerifier
The DependencyVerifier is a DiagnosticVerifier-alike utility that takes annotations in user code and transforms them into a set of expectations. Those expectations are met by corresponding "obligations", which are constructed by reading the contents of the referenced name tracker associated with the source files for each of the primary inputs to a frontend job. The verifier will then pair off expectations and obligations, and ensure that any remaining unpaired obligations are diagnosed as failures.

This tool will not only ensure the correctness of the referenced name tracker's output, it will provide us with tests that ensure its output is stable, and give us the confidence to replace it with an evaluator-based tracking scheme in the future.

Resolves rdar://59773883
2020-03-02 16:45:37 -08:00
Robert Widmann
d3edb5b15a [Incremental] Plumb -verify-incremental-dependencies Through The Frontend and Driver
When enabled at the driver level, the frontends will inherit the flag. For each frontend that recieves this option, all primaries will have their reference dependencies validated.
2020-03-02 16:45:37 -08:00
Robert Widmann
101dd2d9f7 Merge pull request #30167 from davidungar/ref-name-tracker-factor-3-2-20
[NFC, Incremental] Factor used Decl enumeration in preparation for dependency verifier
2020-03-02 16:45:28 -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
39d988da9c [CS] Remove ReturnAllDiscoveredSolutions flag
This is now no longer used.
2020-03-02 14:50:16 -08:00
Hamish Knight
6e616cdef0 [CS] Remove an unused function
This was previously used by CSDiag, which is now
gone.
2020-03-02 14:50:16 -08:00
David Ungar
85d70b59de Move use enumeration to ReferencedNameTracker 2020-03-02 14:39:47 -08:00
David Ungar
d5047ee208 Use isPrivateToEnclosingFile 2020-03-02 14:28:43 -08:00
David Ungar
f6f086ff85 Add Decl::isPrivateToEnclosingFile 2020-03-02 14:23:47 -08:00
Hamish Knight
ea16419476 [Parse] Check the SourceFile for warning suppression
Move the logic for warning suppression out of the
frontend and into `parseIntoSourceFile`.
2020-03-02 14:12:37 -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
Hamish Knight
2724cf6f65 [Parse] Check the SourceFile to see if bodies can be delayed
Remove the `DelayBodyParsing` flag from the parser
and instead query the source file.
2020-03-02 14:12:37 -08:00
Hamish Knight
2ec619caf7 [AST] Add a few parsing flags to SourceFile
Add flags for whether delayed body parsing or #if
condition evaluation is disabled, as well as
whether warnings should be suppressed. Then pass
down these flags from the frontend.

This is in preparation for the requestification of
source file parsing where the SourceFile will need
to be able to parse itself on demand.
2020-03-02 14:12:37 -08:00
Hamish Knight
a9870ac787 Merge pull request #29741 from hamishknight/moving-states
Move PersistentParserState onto SourceFile
2020-03-02 14:11:06 -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
Hamish Knight
d77cae6720 Move PersistentParserState onto SourceFile
Move the global PersistentParserState from
the CompilerInstance to the source file that code
completion is operating on, only hooking up the
state when it's needed. This will help make it
easier to requestify source file parsing.
2020-03-02 11:22:44 -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
Pavel Yaskevich
d5944ffa76 [ConstraintLocator] NFC: Introduce a way to determine whether locator points directly to a specific expression 2020-03-02 10:15:00 -08:00
Erik Eckstein
370082babe GlobalOpt: handle access markers correctly.
rdar://problem/59345288
2020-03-02 18:18:30 +01:00
Pavel Yaskevich
9db7144bbc [CSDiagnostics] Handle try? contextual mismatch directly
It detends on a situation whether try? would get a type inferred
so the mismatch is against a contextual type, or contextual type
would be used as a type of `try?` and fail comparsion with inner
expression type. In either case the mismatch is contextual.
2020-03-02 09:02:56 -08:00
Pavel Yaskevich
d1a11cd1f2 [ConstraintLocator] Add an accessor to check whether locator points directly at try? 2020-03-02 09:02:24 -08:00
Doug Gregor
13b200ddd5 [Constraint system] Generalize saved ASTNode -> solution target mapping.
We are currently only using the “solution targets” map for statement
conditions, but we will need it for more entities soon. Start generalizing
now.
2020-03-02 08:43:55 -08:00
Martin Boehme
f81ef9cf1e Prepend "diagnostic produced by Clang:" to Clang diagnostics. 2020-03-02 14:56:42 +01:00
Martin Boehme
45503abcdf Move struct Result directly above verifyFile(). 2020-03-02 14:56:42 +01:00
Martin Boehme
c164fca37b If -verify mode saw unexpected diagnostics, print diagnostics from all files.
As an example of how this is useful, consider the case where
ClangImporter fails with

  "unexpected error produced: could not build C module 'ctypes'"

It would be useful to know what the underlying Clang error was that
caused building the module to fail, but so far, `-verify` mode would not
output that; to get the error, it would be necessary to run the compiler
invocation again without `-verify`.

This change causes any remaining diagnostics that weren't in the input file
to be output if there were unexpected diagnostics in `-verify` mode.

I haven't added any tests for this because I didn't find a place that
contains tests for the `-verify` functionality itself (as opposed to
tests that use `-verify` mode). I think the large number of tests that
run with `-verify` should at least ensure, however, that this change
does not regress anything.
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
b58ea4bb37 Merge pull request #30151 from gottesmm/pr-5d7a1ea2d4ae11d647fceb405a4c2307150f7b06
[ownership] Create a single introducer version of getUnderlyingBorrowIntroducingValues and rename it to getAllBorrowIntroducingValues(...).
2020-03-02 00:29:34 -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
Michael Gottesman
5adc47173e [semantic-arc-opts] Shrink size of arrays in LiveRange.
I looked when building the stdlib/overlays and the vast majority of uses were < 2 for all
of these values, so it makes sense to shrink them.

Part of the reason I am doing this is that I think the pass is starting to
coalesce a little bit and also I want to start optimizing owned phi arguments so
I am going to need to start storing these. I don't want to be storing such large
small arrays in any data structure anywhere.
2020-03-01 17:36:14 -08:00
Michael Gottesman
6e5f036bda [ownership] Create a single introducer version of getUnderlyingBorrowIntroducingValues and rename it to getAllBorrowIntroducingValues(...).
I also added a comment to getAllBorrowIntroducingValues(...) that explained the
situations where one could have multiple borrow introducing values:

1. True phi arguments.
2. Aggregate forming instructions.
2020-03-01 17:30:53 -08:00
Saleem Abdulrasool
3ba1f391af Merge pull request #30147 from compnerd/debug-dump
LLVMPasses: mark the dump as debug code
2020-03-01 10:07:38 -08:00
David Ungar
72032493f9 Fix and test for extension body 2020-02-29 23:19:09 -08:00
Saleem Abdulrasool
71e8f866bb LLVMPasses: mark the dump as debug code
This limits the dumping of the variables to the debug build since
`llvm::Value::dump` is only available in debug builds of LLVM.
2020-02-29 20:47:20 -08:00
Holly Borla
e615c1ca16 Merge pull request #30137 from hborla/bump-module-format-version
[Serialization] Bump the module format version number for serialization of typeEraser
2020-02-28 19:14:19 -08:00
swift-ci
7770ba8c72 Merge pull request #30138 from atrick/fix-build-warning 2020-02-28 18:28:05 -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