Commit Graph

384 Commits

Author SHA1 Message Date
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
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