Commit Graph

1105 Commits

Author SHA1 Message Date
Vedant Kumar
f67b9cbbdd Rename CompilerInstance::ModuleManager to match D70583 (#28625)
See: https://reviews.llvm.org/D70583
2019-12-06 14:33:05 -08:00
Joe Groff
0926d2380b SIL: Sink GenericContextScope into IRGen.
All the context dependencies in SIL type lowering have been eradicated, but IRGen's
type info lowering is still context-dependent and doesn't systemically pass generic
contexts around. Sink GenericContextScope bookkeeping entirely into IRGen for now.
2019-12-02 12:20:05 -08:00
swift-ci
6996cae94c Merge remote-tracking branch 'origin/master' into master-next 2019-11-05 08:49:43 -08:00
swift-ci
d162cc1258 Merge remote-tracking branch 'origin/master' into master-next 2019-11-04 13:50:06 -08:00
Adrian Prantl
8e9b02839b Debug Info: Avoid type uniquing clashes for bound generic structs.
This patch changes the DWARF representation of bound generic struct to a nested
struct where the (sized) outer struct is anonymous and thus distinct and the
inner struct in uniqued and sizeless.

This is anologous the the previous commit that did the same thing for bound
generic enums.

rdar://problem/56521648
2019-11-04 13:36:49 -08:00
adrian-prantl
b6b0046be2 Merge pull request #28020 from adrian-prantl/56521648
Debug Info: Avoid type uniquing clashes for bound generic enums.
2019-11-04 13:36:09 -08:00
Adrian Prantl
e881168d5e Debug Info: Avoid type uniquing clashes for bound generic enums.
This patch changes the DWARF representation of bound generic enums to a nested
struct where the (sized) outer struct is anonymous and thus distinct and the
inner struct in uniqued and sizeless.

BoundGenericEnums may have different sizes depending on what they are bound to,
but still share a mangled name.

rdar://problem/56521648
2019-11-04 08:22:00 -08:00
swift-ci
0b41d02a4d Merge remote-tracking branch 'origin/master' into master-next 2019-10-31 20:49:50 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Xi Ge
64c0680686 Merge remote-tracking branch 'apple/master' into master-next 2019-10-28 10:19:36 -07:00
Joe Groff
03c7919b4a SIL: Add fields to SILFunctionType for substituted function types.
https://forums.swift.org/t/improving-the-representation-of-polymorphic-interfaces-in-sil-with-substituted-function-types/29711

This prepares SIL to be able to more accurately preserve the calling convention of
polymorphic generic interfaces by letting the type system represent "substituted function types".
We add a couple of fields to SILFunctionType to support this:

- A substitution map, accessed by `getSubstitutions()`, which maps the generic signature
  of the function to its concrete implementation. This will allow, for instance, a protocol
  witness for a requirement of type `<Self: P> (Self, ...) -> ...` for a concrete conforming
  type `Foo` to express its type as `<Self: P> (Self, ...) -> ... for <Foo>`, preserving the relation
  to the protocol interface without relying on the pile of hacks that is the `witness_method`
  protocol.

- A bool for whether the generic signature of the function is "implied" by the substitutions.
  If true, the generic signature isn't really part of the calling convention of the function.
  This will allow closure types to distinguish a closure being passed to a generic function, like
  `<T, U> in (*T, *U) -> T for <Int, String>`, from the concrete type `(*Int, *String) -> Int`,
  which will make it easier for us to differentiate the representation of those as types, for
  instance by giving them different pointer authentication discriminators to harden arm64e
  code.

This patch is currently NFC, it just introduces the new APIs and takes a first pass at updating
code to use them. Much more work will need to be done once we start exercising these new
fields.

This does bifurcate some existing APIs:

- SILFunctionType now has two accessors to get its generic signature.
  `getSubstGenericSignature` gets the generic signature that is used to apply its
  substitution map, if any. `getInvocationGenericSignature` gets the generic signature
  used to invoke the function at apply sites. These differ if the generic signature is
  implied.
- SILParameterInfo and SILResultInfo values carry the unsubstituted types of the parameters
  and results of the function. They now have two APIs to get that type. `getInterfaceType`
  returns the unsubstituted type of the generic interface, and
  `getArgumentType`/`getReturnValueType` produce the substituted type that is used at
  apply sites.
2019-10-25 13:38:51 -07:00
Arnold Schwaighofer
064d85b75a IRGen: Fix a non null terminated string error
Just use the StringRef as index to a string map. Using data() will fail
if the StringRef does not contain a null terminated string.

The problem is that we get the data of a StringRef (which is not null
terminated) to intialize a StringRef with char* which expects a null
terminated string.

Found by a ASAN bot.

rdar://56340563
2019-10-17 09:09:27 -07:00
swift-ci
71e9fc221b Merge remote-tracking branch 'origin/master' into master-next 2019-10-11 22:09:52 -07:00
Slava Pestov
6974448b1e Sema: Fold TypeAliasDecl::computeType() into validateDecl() 2019-10-10 19:55:02 -04:00
swift-ci
31004db03c Merge remote-tracking branch 'origin/master' into master-next 2019-10-03 18:29:24 -07:00
Slava Pestov
6702d38d87 Sema: Remove most calls to Decl::setValidationToChecked() 2019-10-03 17:11:45 -04:00
Mishal Shah
6b33f225eb Merge branch 'master' into master-next 2019-10-01 13:10:07 -07:00
adrian-prantl
00c64e7959 Merge pull request #27345 from adrian-prantl/16042546
Debug Info: Encode let-bindings using DW_TAG_const_type.
2019-09-27 14:39:56 -07:00
Harlan Haskins
d4247942c4 Merge remote-tracking branch 'upstream/master' into master-next 2019-09-26 20:19:25 -07:00
Harlan Haskins
e349b7b123 Merge branch 'master' into master-rebranch 2019-09-26 20:16:05 -07:00
Jordan Rose
a6dd630ca3 Eliminate Builtin.UnknownObject as an AST type (#27378)
This removes it from the AST and largely replaces it with AnyObject
at the SIL and IRGen layers. Some notes:

- Reflection still uses the notion of "unknown object" to mean an
  object with unknown refcounting. There's no real reason to make
  this different from AnyObject (an existential containing a
  single object with unknown refcounting), but this way nothing
  changes for clients of Reflection, and it's consistent with how
  native objects are represented.

- The value witness table and reflection descriptor for AnyObject
  use the mangling "BO" instead of "yXl".

- The demangler and remangler continue to support "BO" because it's
  still in use as a type encoding, even if it's not an AST-level
  Type anymore.

- Type-based alias analysis for Builtin.UnknownObject was incorrect,
  so it's a good thing we weren't using it.

- Same with enum layout. (This one assumed UnknownObject never
  referred to an Objective-C tagged pointer. That certainly wasn't how
  we were using it!)
2019-09-26 17:48:04 -07:00
Adrian Prantl
ff22da20c3 Debug Info: Encode let-bindings using DW_TAG_const_type.
This allows the debugger to distinguish constant "let" values from
mutable "var" variables.

rdar://problem/16042546
2019-09-25 08:51:05 -07:00
swift-ci
8ce5b01307 Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 15:09:47 -07:00
swift-ci
463b04648e Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-18 15:03:46 -07:00
Robert Widmann
5e34169aca Separate computing interface types and underlying types
Computing the interface type of a typealias used to push validation forward and recompute the interface type on the fly.  This was fragile and inconsistent with the way interface types are computed in the rest of the decls.  Separate these two notions, and plumb through explicit interface type computations with the same "computeType" idiom.  This will better allow us to identify the places where we have to force an interface type computation.

Also remove access to the underlying type loc.  It's now just a cache location the underlying type request will use.  Push a type repr accessor to the places that need it, and push the underlying type accessor for everywhere else.  Getting the structural type is still preferred for pre-validated computations.

This required the resetting of a number of places where we were - in many cases tacitly - asking the question "does the interface type exist".  This enables the removal of validateDeclForNameLookup
2019-09-17 08:20:55 -07:00
swift-ci
232757a0e8 Merge remote-tracking branch 'origin/master' into master-next 2019-08-27 12:49:52 -07:00
swift-ci
ffb338e8b1 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-27 12:44:34 -07:00
swift-ci
e61c1cc32c Merge pull request #26871 from adrian-prantl/49233932-pch 2019-08-27 12:36:10 -07:00
Adrian Prantl
ce37ddf332 Debug Info: Record -gmodules breadcrumbs for PCH debug info.
Produce a DWO-style skeleton CU pointing to the PCH containing the
Clang debug info for types imported from a PCH. This allows
DWARFIMporterDelegate to find the type definitions there.

<rdar://problem/49233932>
2019-08-27 09:16:53 -07:00
swift-ci
2943eb940c Merge remote-tracking branch 'origin/master' into master-next 2019-08-20 07:50:31 -07:00
swift-ci
b025c3099d Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-20 07:43:58 -07:00
Davide Italiano
4fd07ef20c [IRGenDebugInfo] Enable an assertion. 2019-08-19 14:48:52 -07:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Brent Royal-Gordon
fb20b503ba Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/ClangImporter/ClangImporter.cpp
#	test/IRGen/builtins.swift
#	test/IRGen/enum.sil
#	tools/driver/autolink_extract_main.cpp
#	utils/build-presets.ini
2019-08-08 17:07:59 -07:00
Joe Groff
d38a72c4ad Merge branch 'master' into master-next 2019-07-18 13:14:39 -07:00
Erik Eckstein
ffd7f75de3 IRGen: debug info generation for cond_fail messages.
To display a failure message in the debugger, create a function in the debug info which has the name of the failure message.
The debug location of the trap/cond_fail is then wrapped into this function and the function is declared as "inlined".
In case the debugger stops at the trap instruction, it displays the inline function, which looks like the failure message.
For example:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000100000cbf a.out`testit3(_:) [inlined] Unexpectedly found nil while unwrapping an Optional value at test.swift:14:11 [opt]
   11
   12   @inline(never)
   13   func testit(_ a: Int?) -> Int {
-> 14     return a!
   15   }
   16

This change is currently not enabled by default, but can be enabled with the option "-Xllvm -enable-trap-debug-info".
Enabling this feature needs some changes in lldb. When the lldb part is done, this option can be removed and the feature enabled by default.
2019-07-16 14:51:18 +02:00
Brent Royal-Gordon
d5a2912a26 Revert "Better runtime failure messages (not yet enabled by default)" 2019-07-15 13:42:40 -07:00
Erik Eckstein
e915300e96 IRGen: debug info generation for cond_fail messages.
To display a failure message in the debugger, create a function in the debug info which has the name of the failure message.
The debug location of the trap/cond_fail is then wrapped into this function and the function is declared as "inlined".
In case the debugger stops at the trap instruction, it displays the inline function, which looks like the failure message.
For example:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000100000cbf a.out`testit3(_:) [inlined] Unexpectedly found nil while unwrapping an Optional value at test.swift:14:11 [opt]
   11
   12   @inline(never)
   13   func testit(_ a: Int?) -> Int {
-> 14     return a!
   15   }
   16

This change is currently not enabled by default, but can be enabled with the option "-Xllvm -enable-trap-debug-info".
Enabling this feature needs some changes in lldb. When the lldb part is done, this option can be removed and the feature enabled by default.
2019-07-12 14:03:13 +02:00
swift-ci
1bf7d48111 Merge remote-tracking branch 'origin/master' into master-next 2019-06-14 08:29:18 -07:00
adrian-prantl
caabba56c7 Merge pull request #25435 from adrian-prantl/51343998
Remove a workaround in the debug info handling of zero-sized types.
2019-06-14 08:20:56 -07:00
swift-ci
41616e4a46 Merge remote-tracking branch 'origin/master' into master-next 2019-06-12 21:09:29 -07:00
Slava Pestov
198e8d1a1f AST: Introduce a new debug-only mangling for @escaping @convention(block) functions
Our mangling did not encode if an Objective-C block was escaping or
not. This is not a huge problem in practice, but for debug info we
want type reconstruction to round-trip exactly. There was a previous
workaround to paper over this specific problem.

Remove the workaround, and add a new 'XL' mangling for escaping
blocks. Since we don't actually want to break ABI compatibility,
only use the new mangling in DWARF debug info.
2019-06-12 19:10:19 -07:00
Adrian Prantl
a0463a83f1 Remove a workaround in the debug info handling of zero-sized types.
This fixes potential LLVM verifier errors in exploded variables with undefined
elments, because a few lines below the size of fragments is derived from the
size of the LLVM SSA value and the constant used in the deleted workaround is
always an i64.

rdar://problem/51343998
2019-06-12 16:48:01 -07:00
Saleem Abdulrasool
1749f3e869 IRGen: adjust for SVN r360108
`DINodeRef` no longer need `resolveType()`.
2019-05-07 12:51:13 -07:00
Joe Groff
6c779bb487 Merge pull request #24445 from jckarter/opaque-type-remote
Debugger support for opaque types.
2019-05-03 08:18:59 -07:00
Adrian Prantl
e63caa4d45 Debug Info: Mark variables without source location as artificial.
rdar://problem/50349713
2019-05-01 15:18:15 -07:00
Joe Groff
7f76ed6d62 IRGen: Render opaque types like other archetypes in debug info. 2019-04-30 13:44:59 -07:00
Nathan Lanza
f837a9eeef Fix bug where inlined scopes where being inlined twice for codeview
A workaround in codeview debuginfo generation was to declare a condfail
instruction as inlined to avoid using 0 as an artificial line location.

However, this was done without accounting for scopes that were already
legitimately inlined. So we'd end up with a condfail inlined from
function B into function A and then the IRGen for the condfail was
being given a debugloc claiming to have been inlined again. This was
causing a sitaution where we'd have debug info forfunctionA owning an
instruction which claimed it was owned by a different function.

Fix this by first checking if the `LastScope` was already inlined and,
if so, just used that scope instead.
2019-04-23 12:40:48 -07:00
adrian-prantl
f75dea49df Merge pull request #23910 from adrian-prantl/49751363
Record parseable interface imports in the debug info.
2019-04-19 14:23:57 -07:00
Joe Groff
f363a10b3b runtime interface fixup irgen 2019-04-17 14:44:40 -07:00