Commit Graph

1105 Commits

Author SHA1 Message Date
swift-ci
ebad328a4f Merge remote-tracking branch 'origin/main' into rebranch 2021-09-01 09:14:57 -07:00
Min-Yih Hsu
33ec01a60c [SIL][DebugInfo] PATCH 1/3: Add support for expr op_deref
This new SIL di-expression represents the dereference on the SSA value.
Similar to DW_OP_deref in DWARF. It is also going to replace the
existing `debug_value_addr`. Namely, replacing the following
instruction:
```
debug_value_addr %a : $*T, name "my_var"
```
with this one:
```
debug_value %a : $*T, name "my_var", expr op_deref
```
2021-08-31 09:22:25 -07:00
swift-ci
5fe1881a91 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-27 21:53:32 -07:00
Rintaro Ishizaki
49547a5378 [NFC][Basic] Import llvm::isa_and_nonnull to 'swift' namespace
Just for convenicence.

* Replace `llvm::isa_and_nonnull` with imported `isa_and_nonnull`
* Repalce some `EXPR && isa<T>(EXPR)` with `isa_and_nonnull<T>(EXPR)`
2021-08-27 11:36:21 -07:00
swift-ci
19048afbc8 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-25 07:13:51 -07:00
Slava Pestov
cda25b7eeb IRGen: Mangle DWARF types with the right generic signature
The symptom here was a crash in getConformanceAccessPath(), but the root
cause was that the ASTMangler used an incorrect generic signature when
looking up the conformance path for a type parameter.

The mangler requires a generic signature to be set to properly mangle types
containing retroactive conformances. However, DebugInfo just used the
IRGenModule's current signature, which wasn't always the same as the
signature describing the archetypes found inside the SILFunction.

Fixes rdar://problem/81683650 / https://bugs.swift.org/browse/SR-15046.
2021-08-24 21:48:19 -04:00
Adrian Prantl
c40b8f38b8 Update IRGenDebugInfo for LLVM D95617.
In https://reviews.llvm.org/D95617 LLVM stopped to emit debug values without a
location as an optimization for inlined functions. Because Swift is emitting
dbg.values(undef) for sizeless variables even at -Onone, we need to make sure
all local variables are preserved even at -Onone.

rdar://82038523
2021-08-20 12:57:23 -07:00
Min-Yih Hsu
4361da6930 Merge pull request #38942 from mshockwave/dev-dbg-var-artificial
[DebugInfo] Prevent salvaged debug vars from being marked artificial
2021-08-20 11:05:11 -07:00
Min-Yih Hsu
da5ef903bd [DebugInfo] Prevent salvaged debug vars from being marked artificial
We were using compiler-generated source location (i.e. line number
0) on `debug_value` instructions were emitted by salvage debug info.
But it turned out that IRGen will attach DW_AT_artificial on the
associated debug variables, which are hidden in debugger by default.
This patch prevent this issue by using the source location from the
just-deleted instruction for these `debug_value` instructions.

This indirectly triggered another bug where some of the LLVM
!DIExpression-s we generated are actually invalid -- more specifically,
the fragment inside is covering the whole debug variable. The reason it was
not previously caught is because LLVM verifier skips any debug variable
that is marked artificial, and all debug variables that have illegal fragment
are falling under this category. Thus, this patch also fixes this issue
by not generating the DW_OP_LLVM_fragment part if it's illegal.
2021-08-19 13:21:40 -07:00
Robert Widmann
592e90af9b Add Sugar for Variadics
We used to represent the interface type of variadic parameters directly
with ArraySliceType. This was awfully convenient for the constraint
solver since it could just canonicalize and open [T] to Array<$T>
wherever it saw a variadic parameter. However, this both destroys the
sugaring of T... and locks the representation to Array<T>. In the
interest of generalizing this in the future, introduce
VariadicSequenceType. For now, it canonicalizes to Array<T> just like
the old representation. But, as you can guess, this is a new staging
point for teaching the solver how to munge variadic generic type bindings.

rdar://81628287
2021-08-06 12:51:39 -07:00
Min-Yih Hsu
9a8f2ed642 [SILOptimizer][DebugInfo] Preliminary support for DIExpression in SROA and Mem2Reg
SROA and Mem2Reg now can leverage DIExpression -- op_fragment, more
specifically -- to generate correct debug info for optimized SIL. Some
important highlights:
 - The new swift::salvageDebugInfo, similar to llvm::salvageDebugInfo,
   tries to restore / transfer debug info from a deleted instruction.
   Currently I only implemented this for store instruction whose
   destination is an alloc_stack value.
 - Since we now have source-variable-specific SIL location inside a
   `debug_value` instruction (and its friends), this patch teaches
   SILCloner and SILInliner to remap the debug scope there in addition
   to debug scope of the instruction.
 - DCE now does not remove `debug_value` instruction whose associating
   with a function argument SSA value that is not used elsewhere. Since
   that SSA value will not disappear so we should keep the debug info.
2021-08-05 17:27:45 -07:00
Min-Yih Hsu
2bb6498731 [SIL][DebugInfo] Bring advanced debug info to alloc_stack
The `alloc_stack` instruction now can carry advanced debug info like
source-variable-specific SIL location, type, and SIL DIExpression.
2021-08-04 12:56:25 -07:00
Min-Yih Hsu
5a42c27826 Merge pull request #38378 from mshockwave/dev-sil-diexpression
[DebugInfo] Adding DIExpression into SIL
2021-07-22 13:19:24 -07:00
Min-Yih Hsu
b363bbdd78 [IRGen][Patch 2/2] Add IRGen support for SIL DIExpression
This patch is primarily doing two things:
 - Teach IRGen for some of the instructions to generate debug info based
   on SILDebugVariable rather than AST node, which is not always
   available when reading from SIL.
 - Generate corresponding `llvm.dbg.*` intrinsics and `!DIExpression`
   from the newly added SIL DIExpression.
2021-07-21 09:26:51 -07:00
Hamish Knight
d4c25f55c2 [AST] Reject GenericFunctionType in TypeBase::getTypeOfMember
Remove the default argument for the `memberType`
parameter and enforce that GenericFunctionType is
not passed. Also add a defaulted overload for the
property case, as they should never have a
GenericFunctionType interface type.
2021-07-20 14:11:31 +01:00
Min-Yih Hsu
2d35d31290 [IRGen][DebugInfo] Use attached SILLocation for generating var debug loc
Currently IRGen requires the AST node of a variable declaration to
generate debug location. However, this will fail if the input is SIL due
to the lack of AST reconstruction. Plus, it's unnecessary since we can
just use the `SILLocation` attached on `debug_value` (and its friends) SIL
instruction to generate the correct LLVM debug metadata.

Resolves SR-14868
2021-07-06 09:40:53 -07:00
Min-Yih Hsu
8f3100a80b [IRGen] Correctly decode SILLocation w/ FilenameAndLocation storage
IRGen tried to decode various types of `SILLocation` into
`FilenameAndLocation` object. But it couldn't handle the case where
`SILLocation` already uses `FilenameAndLocationKind` storage kind. This
patch fixes this issue.

Resolves SR-14856
2021-06-29 14:29:05 -07:00
Adrian Prantl
946e8ef21c Fix a debug info regression introduced with async support.
This patch removes a heuristic to promote all debug intrinsics pointing into
allocas to llvm.dbg.declare() intrinsics and instead more accurate classifies
variables in async contexts by adding the missing cases alloc_box and
alloc_stack cases.

rdar://78977132
2021-06-09 11:42:45 -07:00
Adrian Prantl
3567b9f885 Refactor getSizeOfBasicType to take CompletedDebugTypeInfo (NFC)
(cherry picked from commit a5533fc056)
2021-05-24 17:38:58 -07:00
Adrian Prantl
57b1664f92 Debug Info: Distinguish between types of unknown size and types with size=0.
DebugInfoTypes didn't properly distinguish between types with an unknown size
and used 0 as the default value. This can cause types to show up in DWARF with a
size of 0, which will prevent LLDB from looking at the type further. In
practice, this meant that many resilient types (for example, SwiftUI Views)
couldn't be displayed in the debugger and just showed up as empty.

This patch does three things:

0. Make size in DebugTypeInfo optional.
1. Introduce CompletedDebugTypeInfo, a subclass of DebugTypeInfo where
   size is guaranteed to be non-empty.
2. Change some APIs that only make sense with a size to use
   CompletedDebugTypeInfo. This caused some churn because I needed to refactor
	 the get*Elements() functions back into their callers to facilitate the new
	 early-exit path. These functions are only called when compiling with
	 -gdwarf-types.
3. Change createOpaqueStructWithSizedContainer() to create a size-less forward
   declaration instead of a zero-sized type for the inner type.

rdar://76973844
(cherry picked from commit b8e6eebdbc)
2021-05-20 13:48:47 -07:00
Adrian Prantl
a6304c5168 Update the correct size of Builting.Executor, it is now 2 pointers.
Fixes an assertion while building the Concurrency module.
2021-04-30 17:08:35 -07:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
John McCall
0f152af85f Add a Builtin.Executor type to abstract executor references. 2021-03-28 04:31:49 -04:00
Arnold Schwaighofer
5b4e0566b9 [IRGen] Fix debug info for direct arguments/return values
Emit shadow copies in async functions and emit a load to get the value.
2021-03-17 07:41:10 -07:00
Adrian Prantl
3401f8ab93 Support local variables in virtual async backtraces.
rdar://75012612
2021-03-10 17:52:20 -08:00
Adrian Prantl
c2dc87cd6b Debug info support for let await result variables. 2021-02-24 12:55:24 -08:00
Holly Borla
11028350a7 Merge pull request #35589 from Jumhyn/placeholder-types
[AST, Sema] Replace HoleType with PlaceholderType
2021-02-22 08:35:37 -08:00
Adrian Prantl
582bbbdbd9 Add debug info support for direct async arguments.
rdar://74460135
2021-02-19 15:48:59 -08:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
d78d95ef0d [AST] Introduce PlaceholderType and ThePlaceholderType singleton 2021-02-16 22:59:18 -05:00
Adrian Prantl
b3f5ac3281 Add debug info support for boxed arguments in async functions.
Usually debug info only ever describes the *result* of a projectBox
call. To display a boxed parameter of an async continuation object,
however, the debug info can only describe the box itself and thus also
needs to emit a box type for it so the debugger knows to call into
Remote Mirrors to unbox the value.

SR-14059
rdar://problem/73358988
2021-02-03 14:40:36 -08:00
Adrian Prantl
730af40841 Recover from an incorrect merge conflict resolution 2021-01-29 16:27:03 -08:00
Adrian Prantl
a9f05c8c30 Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
	lib/IRGen/IRGenDebugInfo.cpp
2021-01-29 16:17:10 -08:00
Erik Eckstein
462e58d3cb SILLocation: a big refactoring and reducing its size from 3 to 2 words
My goal was to reduce the size of SILLocation. It now contains only of a storage union, which is basically a pointer and a bitfield containing the Kind, StorageKind and flags. By far, most locations are only single pointers to an AST node. For the few cases where more data needs to be stored, this data is allocated separately: with the SILModule's bump pointer allocator.

While working on this, I couldn't resist to do a major refactoring to simplify the code:

* removed unused stuff
* The term "DebugLoc" was used for 3 completely different things:
    - for `struct SILLocation::DebugLoc` -> renamed it to `FilePosition`
    - for `hasDebugLoc()`/`getDebugSourceLoc()` -> renamed it to `hasASTNodeForDebugging()`/`getSourceLocForDebugging()`
    - for `class SILDebugLocation` -> kept it as it is (though, `SILScopedLocation` would be a better name, IMO)
* made SILLocation more "functional", i.e. replaced some setters with corresponding constructors
* replaced the hand-written bitfield `KindData` with C bitfields
* updated and improved comments
2021-01-29 20:28:21 +01:00
swift-ci
601af1352a Merge remote-tracking branch 'origin/main' into rebranch 2021-01-27 15:32:37 -08:00
Nate Chandler
e21550ad90 [SILGen] Enable alternative entry point name.
Previously, the name of the entry point function was always main.  Here,
a new frontend flag is added to enable an arbitrary name to be
specified.

rdar://58275758
2021-01-26 10:43:33 -08:00
swift-ci
eb13f804ff Merge remote-tracking branch 'origin/main' into rebranch 2021-01-19 20:52:19 -08:00
Slava Pestov
4c72128372 IRGen: Plumb through a GenericSignature when mangling types for debug info
The generic signature isn't used for a whole lot, so this all mostly
worked before; the test case I have hits the code path for mangling
a retroactive conformance.

Fixes <https://bugs.swift.org/browse/SR-14016> / <rdar://problem/72865083>.
2021-01-19 17:25:28 -05:00
Adrian Prantl
e19eb67bf4 Adapt to upstream changes in 41c3b271399229976d9885233db79ebbbe0383c6
DebugLoc has been replaced with DILocation.
2020-12-16 14:59:40 -08:00
John McCall
d68d406dae Merge pull request #35094 from rjmccall/actor-dynamic-layout
Do dynamic layout of generic/resilient default actors properly
2020-12-16 01:05:00 -05:00
John McCall
bad16fd105 Do dynamic layout of generic/resilient default actors properly.
Since these types have an implicit stored property, this requires
adding an abstraction over fields to IRGen, at least throughout
the class code.  In some ways I think this significantly improves
the code, especially in how we approach missing members.

Fixes rdar://72202671.
2020-12-15 20:10:46 -05:00
Adrian Prantl
0e6a0b84d1 Add debug info support for function arguments in async functions.
This commit depends on changes to the coroutine-splitting pass in LLVM.  Shadow
copies are also turned off for async function arguments, because they make it
impossible to track debug info during coroutine splitting. Instead we are
relying on LLVM's CoroSplit.cpp to emit shadow copies. The Swift frontend gives
CoroSplit license to move do this by describing the arguments using a
dbg.declare intrinsic, even though it points to chain of load/GEP/bitcase
instructions into the Swift context function argument.

rdar://71866936
2020-12-11 16:59:09 -08:00
John McCall
ee0bb0a2d5 Freeze PartialAsyncTask as a Job*.
Also fix the extra inhabitants of Builtin.RawUnsafeContinuation
and try to make adding types like this a little less boiler-plate
in the future.
2020-12-04 01:06:29 -05:00
Slava Pestov
1a89813bf5 AST: Introduce Builtin.RawUnsafeContinuation type
This is otherwise identical to Builtin.RawPointer, but has the spare
bits of a heap object pointer.
2020-12-01 20:03:22 -05:00
Brent Royal-Gordon
b440ab7331 [NFC] Move several types/functions to Import.h
To help consolidate our various types describing imports, this commit moves the following types and methods to Import.h:

* ImplicitImports
* ImplicitStdlibKind
* ImplicitImportInfo
* ModuleDecl::ImportedModule
* ModuleDecl::OrderImportedModules (as ImportedModule::Order)
* ModuleDecl::removeDuplicateImports() (as ImportedModule::removeDuplicates())
* SourceFile::ImportFlags
* SourceFile::ImportOptions
* SourceFile::ImportedModuleDesc

This commit is large and intentionally kept mechanical—nothing interesting to see here.
2020-10-09 18:57:07 -07:00
adrian-prantl
e7871c5584 Merge pull request #34037 from adrian-prantl/69393097
Store Clang module imports in addition to Swift overlay.
2020-09-24 08:39:55 -07:00
Varun Gandhi
734b8a2533 Merge pull request #33986 from varungandhi-apple/vg-import-filter-cleanup
[NFC] Clarify import filtering logic and naming.
2020-09-23 18:23:11 -07:00
Adrian Prantl
ba4c82d87e Store Clang module imports in addition to Swift overlay.
This helps the debugger resolve types in the underlying Clang module.

<rdar://problem/69393097>
2020-09-23 13:53:55 -07:00
Varun Gandhi
d3369f7711 [NFC] Rename ImportFilterKind cases to be clearer. 2020-09-23 12:50:20 -07:00
Varun Gandhi
7b967a8030 Merge pull request #33085 from varungandhi-apple/vg-clang-types-in-sil-retry
Propagate Clang function types through SIL
2020-09-22 08:48:34 -07:00