Commit Graph

216 Commits

Author SHA1 Message Date
Vedant Kumar f9372fdb62 [DebugInfo] Improve stepping behavior for switch case stmts
Assign the location of a switch statement's subject expression to all of
its case statements.

This improves the debugger's stepping behavior in switch statements.
Stepping into a switch now goes directly to the first matching case
(possibly one with a `where` clause that may or may not match). It's
still possible to set breakpoints within `where` clauses.

rdar://35628672
2018-03-12 15:21:46 -07:00
Jordan Rose 49e71c9415 [SILGen] Minor improvements to generateEnumCaseBlocks
Noticed by MichaelG while reviewing my changes in the previous commit.
No intended functionality change.
2018-02-21 10:35:04 -08:00
Jordan Rose 36eae9d4f6 [SILGen] Generate a trap for unexpected cases in all @objc enums
(both C enums and Swift enums declared @objc), because of the
"feature" in C of treating a value not declared as a case as a valid
value of an enum.  No more undefined behavior here!

This bit can go in separately from all the work on exhaustive/frozen
enums, which is still being discussed and will come later.

rdar://problem/20420436
2018-02-21 10:34:59 -08:00
Jordan Rose d782f467b0 [SILGen] Factor out the generation of blocks for switching on an enum
This code is shared between emitEnumElementDispatch and
emitEnumElementDispatchWithOwnership. Eventually the former will go
away, but for now there's no need to have both copies (which really
are the same).

No intended functionality change.
2018-02-21 10:34:59 -08:00
Andrew Trick 00b5a9db79 Emit unenforced access markers in SILGen for accesses to local temporaries.
These accesses can't be recognized as obviously local temporaries in the
verification pass, so the only way to exhaustively verify exclusivity is by
added unenforced markers.

SILGen currently only emits unenforced markers under -verify-exlcusivity. Once
opaque values is the only supported SILGen mode, then we should turn the markers
on by default (SILGen should not have different modes of operation).
2018-02-15 11:26:54 -08:00
Michael Gottesman 0747beabe0 [+0-normal-args] Use ManagedValues instead of SILValues in PatternMatchEmission::emitSharedCaseBlocks().
This commit hoists the creation of ManagedValues earlier in the function. This
ensures that the SILValues are never separated from their cleanups and allow us
to pass ManagedValues that have proper cleanups to the forwardInto/assignInto
API that is used herethe values into memory at +1. Previously, we would just drop the
cleanup and forward the non-trivial value into memory without a cleanup,
breaking invariants. Since it is just moving things earlier this is a pure /NFC/
change.

As an extra benefit, this updates the code to use more modern SILGen.

rdar://34222540
2018-02-14 09:40:33 -08:00
Mark Lacey 7f805ba2bc Replace classifyAsOptionalType with isOptionalDecl. 2018-02-05 23:59:00 -08:00
Mark Lacey 2008674495 Make ImplicitlyUnwrappedOptional<T> an unavailable typealias.
Also remove the decl from the known decls and remove a
bunch of code referencing that decl as well as a bunch of other
random things including deserialization support.

This includes removing some specialized diagnostics code that
matched the identifier ImplicitlyUnwrappedOptional, and tweaking
diagnostics for various modes and various issues.

Fixes most of rdar://problem/37121121, among other things.
2018-02-02 08:35:53 -08:00
gregomni 0c3c0fd59b Support for fallthrough into cases with pattern variables. 2018-01-20 11:10:00 -08:00
Slava Pestov 94ca715020 Merge pull request #13988 from slavapestov/address-only-switch
SILGen: Support multiple-entry case blocks with address-only bindings
2018-01-17 23:35:09 -08:00
Slava Pestov f5f715f8ff SILGen: Support multiple-entry case blocks with address-only bindings
Fixes <rdar://problem/30870493>, <https://bugs.swift.org/browse/SR-4163>.
2018-01-17 21:02:08 -08:00
Slava Pestov e6a984d5b7 SILGen: Move some code around in pattern emission 2018-01-17 21:02:08 -08:00
Slava Pestov aa43c26527 SILGen: Split up Emission.getSharedCaseBlockDest() 2018-01-17 21:02:08 -08:00
Slava Pestov c28617090d SILGen: Use the right resilience expansion 2018-01-17 21:02:08 -08:00
Adrian Prantl c74ae5f375 Remove the redundant SILLocation::getCompilerGenerated interface (NFC) 2018-01-17 11:09:23 -08:00
Pavel Yaskevich 7034ef92b6 Revert "Stricter enforcement of the "large space" heuristic" 2018-01-14 19:37:44 -08:00
Vedant Kumar b27ed065b6 [DebugInfo] Avoid applying a misleading cleanup loc in case blocks
Switch cases without a trailing curly brace have ambiguous cleanup
locations. Here's what the current stepping behavior looks like:

  switch x {
    case ...:
      if true { foo() } // Step
      else    { bar() } // Step
  }

The second step can be misleading, because users might think that the
else branch is taken.

rdar://35628620
2018-01-12 17:19:45 -08:00
Slava Pestov 9ff97367df AST: Rename hasFixedLayout() to isResilient() and flip polarity
In IRGen we call this isResilient() already in IRGen, and it's
more consistent to call it the same thing everywhere.
2018-01-11 21:57:42 -08:00
Vedant Kumar dd560d2aa6 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-05 17:20:20 -08:00
Vedant Kumar cccee1df03 Revert "[Coverage] Refactor SIL generation for profiling" 2018-01-03 21:57:49 -08:00
Vedant Kumar aba9d53736 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-03 11:18:40 -08:00
Robert Widmann 43f06afef2 Defer analysis of large switch bodies
This presents a regression in diagnostic quality that is definitely
worth it not to lie to SILGen about whether a switch is covered or not.

At the same time, disable SIL’s unreachable diagnostic for ‘default’
clauses which would previously cause a warning to be emitted if the
default was proven to be unreachable.  This analysis is incomplete
anyways and can be done by Sema in the future if we desire.
2017-12-13 16:22:48 -05:00
Slava Pestov 9de7a21e8e SILGen: Use SILFunction's resilience expansion when evaluating enum exhaustiveness
This will likely become obsolete once @jrose-apple's exhaustive enum work
lands, but I want to use the new resilience expansion in at least a couple
of places to test the functionality.
2017-11-10 17:21:17 -08:00
Joe Shajrawi 75939510cd PGO: Use ProfileCounter instead of Optional<uint64_t> to hold profile counts 2017-09-26 13:34:46 -07:00
Joe Shajrawi f4e6bb3725 PGO: add support for checked_cast__br 2017-09-26 11:14:55 -07:00
Joe Shajrawi 2c03144436 Add support for function_entry_count Profile counter 2017-09-26 11:10:52 -07:00
Joe Shajrawi 2cba745df8 PGO: Add support for switch-case statements + initial support for building switch and/or select SIL Instructions with profile count 2017-09-26 11:10:51 -07:00
Robert Widmann 3292e6bc99 Lower Never-typed patterns to unreachable
Cuts off a crash in SILGen for switches over uninhabited types.
We can take this a step further and extend the definition of
"uninhabited" to product types with uninhabited components.
2017-07-17 18:59:15 -07:00
Michael Gottesman be87297179 [silgenpattern] Perform a copy if we have a borrowed cast operand, before we store it.
Sometimes in SILGenPattern, we need use an indirect cast on object that does
not require re-abstraction as an optimization. A notable case where this happens
are various casts related to NSError. In such a case, if we have a borrowed cast
operand, perform a copy before the store to preserve semantic sil invariants.

rdar://31880847
2017-07-08 21:56:20 -07:00
Michael Gottesman 7b1eea6477 [silgenpattern] Gardening. Added some asserts, comments, reformulated some small control flow. NFC. 2017-07-04 21:04:24 -07:00
Michael Gottesman cf5d3fea89 [silgenpattern] Add some TODO. NFC. 2017-07-04 20:54:22 -07:00
Robert Widmann a2a01cf8e8 Remove some uses of setLet 2017-06-28 15:59:56 -07:00
Robert Widmann d07eb71d9c Merge pull request #9457 from rintaro/parse-ifconfig-switchcase
[Parse] Allow #if to guard switch case clauses
2017-06-28 10:18:37 -07:00
Huon Wilson 4e3a010d22 [SILGen] Update the maximum value in a find-index-with-largest-value loop.
This is a loop that attempts to find the index of something with the longest
prefix, but wasn't actually saving the new longest length when finding something
with a longer length, meaning the loop always chose the last index. The update was
accidentally lost in f40e9ef0ae.
2017-06-22 12:48:55 -07:00
Rintaro Ishizaki 5d478bdb3b [Parse] Allow #if to guard switch case clauses
Resolves:
https://bugs.swift.org/browse/SR-4196
https://bugs.swift.org/browse/SR-2
2017-06-17 10:03:03 +09:00
Michael Gottesman bf71ec8599 [silgen] Error nicely on multiple pattern cases with address only patterns.
We silently miscompiled previously the following code:

     protocol Gesture {}
     struct Foo {}
     struct Bar {}
     enum FooOrBar {
       case foo(Foo)
       case bar(Bar)
     }

     func main(_ f : FooOrBar) {
       switch f {
       case .foo(let data as Gesture),
            .bar(let data as Gesture):
         ...
       }
       ...
     }

This was because the multiple pattern per case code never implemented support
for address only types.

Now instead of miscompiling such programs, we do the following:

1. We emit an error.
2. When we construct the arguments for the named bindings, we just skip the
address only types. Everything else is normal.
3. In the case block, we use a SILUndef for the address only value.

This ensures that we preserve as many other diagnostics as possible.

rdar://32525952

P.S. As an additional benefit, this eliminates a source of address phi nodes
from SILGen.
2017-06-02 20:35:09 -07:00
Robert Widmann 3b202c18d8 Use 'hasAssociatedValues'
Use 'hasAssociatedValues' instead of computing and discarding the
interface type of an enum element decl.  This change has specifically not
been made in conditions that use the presence or absence of the
interface type, only conditions that depend on the presence or absence
of associated values in the enum element decl.
2017-05-22 09:54:47 -07:00
Robert Widmann ede48cd58f [NFC] Minor cleanup in patterns
Some things noticed by inspection:

- Old spelling of Optional.some
- pattern dump was using the wrong iterator variable and would crash
- addColumns is never used because the row matrix doesn’t expand tuples
2017-04-25 00:34:10 -04:00
Joe Groff dfdece2ab6 SILGen: Push 'usingImplicitVariablesForPattern' hack into 'where' clause expr evaluation.
We swapped the pattern variables at the wrong level, leaving them bound incorrectly on the cleanup path through a failed 'where' clause check. Fixes rdar://problem/31539726.
2017-04-14 11:58:38 -07:00
Greg Titus b9ecde5fc7 If a shared case block dest got created before it's case's pattern vars were
initialized, the block arg could get created with the type from an outer scope.
2017-04-01 09:20:15 -07:00
Michael Gottesman 56adc0cdb2 [silgen] Make emitTupleDispatchWithOwnership use proper ownership.
rdar://31145255
2017-03-27 16:41:54 -07:00
Michael Gottesman 26b0b72390 [silgen] Eliminate address handling code from emitTupleDispatchWithOwnership. 2017-03-27 16:34:56 -07:00
Michael Gottesman b69497886c [silgen] Hoist specialization code in emitTupleDispatch so that it does not cause the SIL emission code to be split. 2017-03-27 16:33:38 -07:00
Michael Gottesman 631d20f701 [gardening] Rename two instances of gen => SGF. 2017-03-27 16:31:13 -07:00
Michael Gottesman 022cb547e2 [silgen] Extract out tuple pattern emission for objects whenownership is enabled into its own method. 2017-03-27 16:28:56 -07:00
Michael Gottesman eaa229b9f8 [semantic-sil] Make emitEnumElementDispatchWithOwnership conform to ownership.
This means inserting an eager copy on the switch operand, eliminating the
unforwarding, and destroying the copy in the default case as well as the normal
cases.

I did not refactor this code to use the switch enum builder, but at some point
it should be refactored as such.
2017-03-27 13:33:11 -07:00
Michael Gottesman ba1e9f76d8 [silgen] Copy the body of emitEnumElementDispatch to emitEnumElementDispatchWithOwnership.
The reason I am doing this is that I am going to in the next couple of commits
change enum element dispatch to with or without semantic SIL use proper
ownership.

In this commit, I just did the copy and eliminated any parts of the code that
were predicated on having an address.
2017-03-27 10:28:08 -07:00
Michael Gottesman 43a851736c [silgen] When compiling with sil-ownership use borrows+CopyOnSuccess instead of TakeOnSuccess.
This is NFC since all changes are behind a flag. I took a look at the codegen
when this is enabled. It looks pretty optimizable for a -Onone ARC pass. Until I
have that pass though I need this behind a flag.

Basically you see a lot of this pattern:

%0 = begin_borrow %foo
%1 = copy_value %0
...
bb1:
  %2 = begin_borrow %1
  %3 = copy_value %2
  ...
  destroy_value %3
  end_borrow %2 from %1
  destroy_value %1
  end_borrow %0 from %foo
  ...

bb2:
  destroy_value %1
  end_borrow %0 from %foo
  ...

This is really easy to optimize since one can easily see that all of %1's users
are borrows or a final destroy.

rdar://31145255
2017-03-26 15:30:15 -07:00
John McCall 897f5ab7c5 Restore CanType-based micro-optimizations.
This reverts commit 5036806e5a.
However, it preserves a pair of changes to the SIL optimizer
relating to walking through optional types.
2017-03-14 11:38:11 -04:00
Slava Pestov 5036806e5a AST: Remove some unnecessary getCanonicalType() calls 2017-03-13 02:24:36 -07:00