Commit Graph

1105 Commits

Author SHA1 Message Date
Augusto Noronha
aa6b5c2b63 [DebugInfo] Fix recursively generating debug info for same type
Debug Info generation already has a check to stop it from generating
debug info for a type with the same mangled name. However, most of the
code paths in debug info generation would not add the mangled name to
the cache while generation was not done. This patch fixes that so types
that are in-flight don't have their debug info generated twice.

rdar://142500619
2025-01-17 15:00:03 -08:00
Alejandro Alonso
6ffaf4befc Don't ask for TypeInfo of IntegerType when generating debug info for generic args 2025-01-08 10:37:13 -08:00
Augusto Noronha
d75bde3852 [DebugInfo] Fix debug info round tripping of types inside functions
Types with @_originallyDefinedIn cannot be round tripped,

Types declared inside functions have their mangling affected by the
function signature. If the generic signature mentions an
@_originallyDefinedIn type, the type inside the function cannot be round
tripped either.

This commit disables round tripping for this scenario.
2024-12-20 14:13:17 -08:00
Augusto Noronha
72b0120b43 [DebugInfo] Fix handling of @_originallyDefinedIn types
Emit an imported declaration for @_originallyDefinedIn under the
real module that these types live in.

This patch also changes the mangling for the debugger to respect
@_originallyDefinedIn, and fixes a bug where @_originallyDefinedIn
that should be ignored was still being used when mangling.

rdar://137146961
2024-12-16 10:28:18 -08:00
Kuba (Brecka) Mracek
8792efedf0 Merge pull request #77115 from kubamracek/embedded-mangling-prefix
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e
2024-12-03 08:10:49 -08:00
Kuba Mracek
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Pavel Yaskevich
0fe4cea7d7 [AST] Introduce a new type that has associated location in source
This type is intended to be used to wrap compiler synthesized nodes
(i.e. variables) to make it easier for diagnostic to diagnose precise
failure locations.

Consider the situation like:

```
protocol P {}

extension Array: P where Element: P {}

func test<T: P>() -> T {
  $_a = ...
  $_b = ...
  return [$_a, $_b]
}
```

This is a common pattern with result builders.

In this case if one of the elements don't conform to `P` the best
user experience would be to attach diagnostic to the element otherwise
the developers would have to figure out where in result expression
the error occured before attempting to fix it.
2024-11-21 11:01:13 -08:00
Felipe de Azevedo Piovezan
3dfee33174 Merge pull request #77655 from felipepiovezan/felipe/fix_code_gen_debug_info
[DebugInfo] Change lowering of SIL instructions to use line 0 when appropriate
2024-11-18 16:31:11 -08:00
Felipe de Azevedo Piovezan
f7f869c88d [DebugInfo] Don't inherit debug location of previous instruction
Prior to this commit, when lowering SIL instructions that should are
"hidden" for the purposes of debugging, the compiler just attaches the
location of the previous instruction in the name of keeping a simpler
line table.

However, this is wrong for many reasons. One such reason is this: at the
start of a basic block, inheriting the previous debug location will
almost certainly cause the instruction to have a random location in the
code, as it will depend on whatever BB was visited previously.

Other examples can be seen in the tests affect by this commit, which
changes lowering to use Line 0 instead of the line number of the
previous instruction.

CodeView doesn't handle line 0 the same way DWARF does, so this commit
preserves the old behavior for the CodeView path.

The test changes here are effectively undoing some of the diffs from
158772c2ab.

rdar://139826231&110187845
2024-11-18 10:23:41 -08:00
Felipe de Azevedo Piovezan
9758099e91 [NFC][DebugInfo] Factor out CodeView code into its own function
CodeView has its own needs / limitations for representing line 0.
However, this is adding control flow complexities that make changing the
underlying logic complicated for both cases. Furthermore, the
limitations above may be temporary if we change LLVM's backend; by
having a separate function, we can, in the future, easily unify the code
paths in the future by deleting the function.
2024-11-15 14:20:27 -08:00
Felipe de Azevedo Piovezan
e9fbb17f09 [NFC][DebugInfo] Factor out debug location code
This patch moves, into its own function, the code computing a
`FileAndLocation` for the instruction being lowered (SIL>LLVM IR).
Control flows is simplified as a result.
2024-11-15 14:20:27 -08:00
Doug Gregor
24a12ebc34 Renable GeneratedSourceInfo::Attribute to GeneratedSourceInfo::AttributeFromClang 2024-11-15 09:02:49 -08:00
Doug Gregor
aa4c548c0f Clang importer: switch swift_attr attribute text cache over to be module-sensitive
We need different buffers for each imported module that has swift_attr attributes,
so cache them appropriately.
2024-11-13 21:19:39 -08:00
Doug Gregor
989c73d014 Ensure that buffers containing Clang swift_attr attributes are parsed as attributes
Previously, they were being parsed as top-level code, which would cause
errors because there are no definitions. Introduce a new
GeneratedSourceInfo kind to mark the purpose of these buffers so the
parser can handle them appropriately.
2024-11-13 21:19:37 -08:00
Augusto Noronha
3f8ffaa46c Merge pull request #77176 from augusto2112/spare-bits-debug-2
[DebugInfo] Stop emitting spare bits mask in debug info
2024-11-06 15:46:20 -08:00
Kavon Farvardin
86601fcbbf Merge pull request #76532 from kavon/samplepgo
Add support for SamplePGO
2024-11-01 17:52:52 -07:00
Augusto Noronha
459c7fdc7b [DebugInfo] Stop emitting spare bits mask in debug info
We're now able to calculate the spare bits mask from other information.
Stop emitting it in debug info.
2024-11-01 15:51:59 -07:00
Kavon Farvardin
19e593bc07 PGO: new -debug-info-for-profiling frontend flag
This achieves the same as clang's `-fdebug-info-for-profiling`, which
emits DWARF discriminators to aid in narrowing-down which basic block
corresponds to a particular instruction address. This is particularly
useful for sampling-based profiling.

rdar://135443278
2024-11-01 11:59:54 -07:00
Hamish Knight
2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00
Augusto Noronha
da690d6153 [DebugInfo] Handle types with @_originallyDefinedIn in DebugInfo
When processing a nominal type that has the @_originallyDefinedIn attribute,
IRGenDebugInfo emits a forward declaration of the type as a child
of the original module, and the type with a specification pointing to
the forward declaration. We do this so LLDB has enough information to
both find the type in reflection metadata (the parent module name) and
find it in the swiftmodule (the module name in the type mangled name).

rdar://137146961
2024-10-29 17:46:45 -07:00
Ben Barham
746517c9f2 Merge remote-tracking branch 'origin/main' into manually-merge-main-to-rebranch
Conflicts:
  - `test/IRGen/has_symbol.swift` test updates in rebranch. The new test
    will fail, will fix in the next commit.
2024-10-24 14:20:17 -07:00
Joe Groff
a184782a38 Introduce a Builtin.FixedArray type.
`Builtin.FixedArray<let N: Int, T: ~Copyable & ~Escapable>` has the layout of `N` elements of type `T` laid out
sequentially in memory (with the tail padding of every element occupied by the array). This provides a primitive
on which the standard library `Vector` type can be built.
2024-10-22 16:21:45 -07:00
Ben Barham
2523660d3b Revert "[DebugInfo] Stop emitting spare bits mask in debug info" 2024-10-21 14:23:04 -07:00
Augusto Noronha
7443fc1c6f [DebugInfo] Stop emitting spare bits mask in debug info
We're now able to calculate the spare bits mask from other information.
Stop emitting it in debug info.
2024-10-15 16:18:43 -07:00
swift-ci
e5f97d79c5 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-30 07:15:01 -07:00
nate-chandler
ba8f8ea282 Merge pull request #76526 from nate-chandler/general-coro/20240906/1
[CoroutineAccessors] Initial framing.
2024-09-30 07:04:04 -07:00
swift-ci
54d8c9feb0 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-29 14:55:02 -07:00
Hamish Knight
91ae5d6345 [AST] NFC: Rename getArgumentInterfaceType -> getPayloadInterfaceType
IMO this is a slightly clearer name, many of its
uses already use the term "payload".
2024-09-29 17:05:14 +01:00
Nate Chandler
091368ba21 [CoroutineAccessors] Added read.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
98a2e6a7df [CoroutineAccessors] Added modify.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
swift-ci
da55e84c74 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-05 15:35:33 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
swift-ci
e27edcada1 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-21 16:49:14 -07:00
Slava Pestov
863afad0a2 Merge pull request #75947 from slavapestov/type-subst-rework-2
Type::subst() rework, part 2
2024-08-21 19:31:08 -04:00
Slava Pestov
bbea8ec1a2 AST: Use TypeTransform::transformSubMap() to transform SILBoxType 2024-08-21 13:21:48 -04:00
swift-ci
9db9710585 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-21 09:56:52 -07:00
Augusto Noronha
1b2c13b12e Merge pull request #75920 from ellishg/debug-info-verify
[IRGen][DebugInfo] Emit declarations for CFunctionPointer reps
2024-08-21 09:43:08 -07:00
swift-ci
a5ec343a08 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-17 06:14:34 -07:00
Ellis Hoag
7c19ca2fbc [IRGen][DebugInfo] Emit declarations for CFunctionPointer reps 2024-08-15 16:35:18 -07:00
Slava Pestov
b601c294ac AST: Replace remaining uses of Type::transform() with transformRec() 2024-08-12 16:05:43 -04:00
swift-ci
b7921a8232 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-06 14:34:09 -07:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
swift-ci
847f915d2e Merge remote-tracking branch 'origin/main' into rebranch 2024-06-22 07:14:46 -07:00
Adrian Prantl
c9f5af5617 Fix a regression that caused the compiler to drop the path names of generated
macro expansion source code when emitting DWARF 4 or earlier.

rdar://126688061
2024-06-21 18:58:11 -07:00
Xi Ge
736ccef626 Merge remote-tracking branch 'apple/main' into rebranch 2024-06-20 15:16:55 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Hamish Knight
782ae72efd Merge branch 'main' into merge-rebranch 2024-05-23 20:03:52 +01:00
Emil Pedersen
5606fbc1d6 [IRGenDebugInfo] Disable usage of dbg.declare in optimized code
Except for the async context, where it is needed (arguments
within an async function).

We don't support dbg.declare in optimized code, as variables can
be moved by SIL optimization passes. If a partial store is
eliminated, we want a dbg.value on the allocation, and another
dbg.value with a fragment in place of the partial store.

rdar://128155050
2024-05-22 09:35:37 -07:00
Emil Pedersen
2726d8318c [IRGenDebugInfo] Allow multiple dbg.declare on an alloca
This is unnecessarily dropping debug info, as there is currently
no assertion in LLVM. The sharing of stack slot can happen
because of AllocStackHoisting, which is run at -Onone too.
2024-05-20 16:55:22 -07:00