Commit Graph

396 Commits

Author SHA1 Message Date
Michael Gottesman
56ab120ed4 [silgen] Eliminate unnecessary code.
This is really old code that I put in when I was still understanding
SILGenPattern. If we are emitting code in ownership form we will never have a
TakeOnSuccess consumption kind, so we should not forward in that case
"automagically".

rdar://29791263
2018-10-11 15:54:02 -07:00
Michael Gottesman
ac92166e49 [silgen] Add support for BorrowAlways, eliminate some bogus asserts, and only use BorrowAlways with objects.
The reason why the asserts were bogus is that even with SILOwnership enabled, we
will use the old pattern to emit address only code. In that case, the asserts
will fire on good behavior.

I also fixed a latent bug where when ownership was enabled we were treating
address only values like objects. Found via inspection.

rdar://29791263
2018-10-11 15:54:02 -07:00
Michael Gottesman
62b5110357 [sil] Add a new CastConsumptionKind called BorrowAlways.
This means that:

1. SILGenPattern always borrows the object before it emits a case.
2. Any cast with this cast has a +0 result.

NOTE: That one can not use this with address types (so we assert if you
pass this checked_cast_addr_br).
NOTE: Once we have opaque values, checked_cast_br of a guaranteed value will
lower to a copy + checked_cast_addr_br (assuming the operation is a consuming
cast). To make sure this does not become a problem in terms of performance, we
will need a pass that can transform SILGenPattern +0 cases to +1 cases. This is
something that we have talked about in the past and I think it is reasonable to
implement.

This is an incremental commit towards fixing SILGenPattern for ownership.

rdar://29791263
2018-10-10 21:02:58 -07:00
Michael Gottesman
dbb3ba79ea [silgen] Change silgen pattern to use destructure_tuple instead of borrow + tuple_extract + copy.
rdar://29791263
2018-10-03 16:08:19 -07:00
Michael Gottesman
4030d40c53 [silgen] Eliminate last use of emitCheckedCastBranchOld and delete dead code.
rdar://29791263
2018-10-02 13:51:14 -07:00
Michael Gottesman
d57a88af0d [gardening] Rename references to SILPHIArgument => SILPhiArgument. 2018-09-25 22:23:34 -07:00
gregomni
ff04fbdae8 Fix name lookup and parser so that where clauses decl refs in case statements correctly bind to the current pattern instead of always to the first pattern. Thus the hacky var decl juggling in where clauses in SILGen can be deleted. 2018-08-28 19:18:56 -07:00
gregomni
2a0c44edb1 NFC: Code clean up, in large part combining methods that only have single callers/callees and simplifying. 2018-08-28 19:18:32 -07:00
Robert Widmann
2fb5afb755 Remove the @_downgrade_exhaustivity_check hack
This hack was only needed for Swift 3 mode in a narrow case.  Flush it out of the compiler so we can simplify the space engine.
2018-08-24 10:54:43 -07:00
John McCall
512e55683e Make it easy to create a SILBasicBlock immediately before a target block.
Also, make "after" requests explicit in the API.
2018-08-18 12:36:36 -04:00
Jordan Rose
ec8aa9f014 Add EnumDecl::isEffectivelyExhaustive, and use it consistently
...rather than copying the same check around all over the place.
2018-07-31 19:01:00 -07:00
Bob Wilson
8e330ee344 NFC: Fix indentation around the newly renamed LLVM_DEBUG macro.
Jordan used a sed command to rename DEBUG to LLVM_DEBUG. That caused some
lines to wrap and messed up indentiation for multi-line arguments.
2018-07-21 00:56:18 -07:00
Jordan Rose
cefb0b62ba Replace old DEBUG macro with new LLVM_DEBUG
...using a sed command provided by Vedant:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-07-20 14:37:26 -07:00
Ellis Hoag
8200916129 Fix debug locations to work well with CodeView
Summary:
There are a few problems with how Swift currently emits location
information for CodeView.

1. WinDbg does not work well with column information so all column
locations must be set to zero.

2. Some instructions, e.g., ``a + b``,  will emit ``@llvm.trap()``
and ``unreachable``. Those instructions should have artificial
locations, i.e., they should have a line location of zero.

3. Some instructions, e.g., ``a / b``, will emit ``unreachable``
sandwiched between other code for that instruction. This makes
WinDbg confused and it cannot decide which set of instructions
to break on. Those instructions should have the same line location
as the others.

4. There are several prologue instructions with artificial line
locations that create breaks in the linetables. Those instructions
should have valid line locations, usually at the start of the
function.

5. Case bodies have cleanup instructions with artificial line
locations unless it has a ``do`` block. Those locations should
be the last line in the case block.

Test Plan:
test/DebugInfo/basic.swift
test/DebugInfo/columns.swift
test/DebugInfo/linetable-codeview.swift
test/DebugInfo/line-directive-codeview.swift
2018-07-18 09:54:19 -07:00
Slava Pestov
d8fc9decf9 AST: Remove GenericSignature::getSubstitutionMap() 2018-05-28 19:45:28 -07:00
Doug Gregor
ef020c74aa Eliminate all vestiges of Substitution and SubstitutionList.
Introduced during the bring-up of the generics system in July, 2012,
Substitution (and SubstitutionList) has been completely superseded by
SubstitutionMap. R.I.P.
2018-05-11 21:43:40 -07:00
Doug Gregor
467456ea3f [SILGen] Get keypath emission logic off Substitution. 2018-05-11 17:37:27 -07:00
Doug Gregor
921d41ca10 [SILGen] Eliminate emitApplyOfLibraryIntrinsic() for SubstitutionList.
There was only one caller; update it to use the SubstitutionMap version.
2018-05-11 17:37:26 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Doug Gregor
48214d4114 Revert "[NFC] Remove unused/unnecessary variable."
This reverts commit 411609a4e3.
2018-05-03 08:40:22 -07:00
Doug Gregor
d2cf60c465 Revert "[SIL] Replace more SubstitutionLists with SubstitutionMap" 2018-05-03 08:35:20 -07:00
Doug Gregor
dc44d97e9c Revert "[NFC] Remove unused/unnecessary variable."
This reverts commit 411609a4e3. I just added
code to use this "unused" variable.
2018-05-03 00:06:23 -07:00
Doug Gregor
9c5a222b95 Merge pull request #16291 from DougGregor/ast-use-substitution-map
[AST] Store SubstitutionMaps in the AST rather than Substitution lists.
2018-05-02 23:52:18 -07:00
Doug Gregor
2c580e247e [SILGen] Use the SubstitutionMap form of emitApplyOfLibraryIntrinsic(). 2018-05-02 13:39:22 -07:00
Huon Wilson
411609a4e3 [NFC] Remove unused/unnecessary variable. 2018-05-02 09:56:12 +10:00
Jordan Rose
9be6519f5a [SILGen] Show a message when an unexpected enum value is switched on (#15614)
Builds on 36eae9d4f6 to emit a message instead of just trapping
when a switch over a non-frozen enum ends up not matching anything.
If the enum is known to be an @objc enum, the message is

  unexpected enum case 'MyEnum(rawValue: -42)'

and if it's anything else (a Swift enum, a tuple containing enums,
whatever), it's a more opaque

  unexpected enum case while switching on value of type 'MyEnum'

The reason for this is to avoid calling String(describing:) or
String(reflecting:) an arbitrary value when the enum might conform to
CustomStringConvertible and therefore /itself/ have a switch that's
going to fall off the end. By handling plain @objc enums (using a
bitcast), we've at least covered the 90% case.

rdar://problem/37728359
2018-04-03 11:21:36 -07:00
Jordan Rose
7987cdc0b8 SILGenPattern: Remove the formal/actual element distinction
This used to model the difference between Optional.some and IUO.some,
but that's gone now!

No functionality change.
2018-03-27 14:43:18 -07:00
Jordan Rose
efe9d518fa SILGenPattern: Wrap up four out-parameters in a single struct
No functionality change.
2018-03-27 14:43:17 -07:00
Michael Gottesman
5f1e1c6b83 [silgenpattern] When emitting a switch_enum with ownership, pass in the PGO data.
This is tested by the pgo_switchenum test with +0 enabled that I am going to
commit in a bit.

rdar://34222540
2018-03-15 17:17:02 -07:00
Mark Lacey
1dec7cc70e Remove SILGenModule::getLoweredEnumElementDecl.
This became a no-op at some point during the IUO work.
2018-03-14 23:59:26 -07:00
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