Commit Graph

1804 Commits

Author SHA1 Message Date
Augusto Noronha
0f0552886e Merge pull request #83557 from augusto2112/6.2-fix-opaque-infinite-rec
[DebugInfo] Fix infinite recursion when opaque return type is defined inside function returning it
2025-08-06 12:00:30 -07:00
Augusto Noronha
7b46d41823 [DebugInfo] Fix infinite recursion when opaque return type is defined
inside function returning it

A stack overflow would happen when the compiler tried emitting debug
info for a function whose opaque return type was declared inside the
function itself. This fixes the issue by emitting a forward declaration
for the function before emitting it.

rdar://150313956

(cherry picked from commit c03831f70d)
2025-08-05 17:36:28 -07:00
Hamish Knight
a8cea97b4b Merge pull request #82988 from hamishknight/enable-inlinearray-sugar-6.2
[6.2] Enable InlineArray type sugar
2025-08-05 22:21:05 +01:00
Shubham Sandeep Rastogi
87925d5c37 Revert "Set the Compilation directory when generating the Skeleton CU"
This reverts commit b286b1c3a5.

Reverted because fix for rdar://131726681 broke rdar://154247270

Reverting and will try to fix properly later.

We will not land this in 6.2

(cherry picked from commit 5b4fdd6e62)
2025-07-24 11:02:31 -07:00
Hamish Knight
f807cbe30e Enable InlineArray type sugar
Promote it from an experimental feature.

rdar://155607927
2025-07-11 13:26:24 +01:00
Slava Pestov
7ed5d2bfc2 ASTDemangler: Round-trip @isolated @sil_implicit_leading_param parameter attributes
We sometimes mangle SILFunctionTypes when generating debug info
for reabstraction thunks, and these can have various exotic
parameter and result attributes. Two recent additions were
never plumbed through the mangler, causing assertion failures
when emitting debug info.

Fixes rdar://153730847.
2025-06-26 15:00:44 -04:00
Hamish Knight
f1c37f4e7d Change InlineArray sugar separator x -> of 2025-05-30 22:06:29 +01:00
Shubham Sandeep Rastogi
bc7e9531f2 Merge pull request #81753 from rastogishubham/CompDir6.2
[6.2] Set the Compilation directory when generating the Skeleton CU
2025-05-28 10:06:33 -07:00
Shubham Sandeep Rastogi
de425be15b Set the Compilation directory when generating the Skeleton CU
When creating a skeleton Compile Unit, the DIFile passed
in, it always uses the include path. This leads to the DW_AT_comp_dir
being wrong, if the -file-compilation-dir option is passed, we need to
use the remapped compilation dir passed in to the DIFile instead.

This patch fixes that problem.

(cherry picked from commit b286b1c3a5)
2025-05-23 14:43:57 -07:00
Slava Pestov
447a1b173b ASTDemangler: Add support for constrained existential compositions 2025-05-23 14:20:35 -04:00
Augusto Noronha
6abbc0d754 [DebugInfo] Use underlying type of global variables with opaque type
rdar://144881938
2025-03-31 15:52:09 -07:00
Hamish Knight
f8ab391737 Introduce type sugar for InlineArray (#80087)
* [CS] Decline to handle InlineArray in shrink

Previously we would try the contextual type `(<int>, <element>)`,
which is wrong. Given we want to eliminate shrink, let's just bail.

* [Sema] Sink `ValueMatchVisitor` into `applyUnboundGenericArguments`

Make sure it's called for sugar code paths too. Also let's just always
run it since it should be a pretty cheap check.

* [Sema] Diagnose passing integer to non-integer type parameter

This was previously missed, though would have been diagnosed later
as a requirement failure.

* [Parse] Split up `canParseType` 

While here, address the FIXME in `canParseTypeSimpleOrComposition`
and only check to see if we can parse a type-simple, including
`each`, `some`, and `any` for better recovery.

* Introduce type sugar for InlineArray

Parse e.g `[3 x Int]` as type sugar for InlineArray. Gated behind
an experimental feature flag for now.
2025-03-23 15:31:37 -07:00
Shubham Sandeep Rastogi
6f09b80aaa Merge pull request #79833 from rastogishubham/FixHopToExe
[DebugInfo] Use Stmt EndLoc if SILLocation passed in is the Stmt EndLoc.
2025-03-19 12:02:28 -07:00
Adrian Prantl
851470f476 [Debug Info] Do not emit children of bound generic types
This reverts the problematic parts of
fcbebc51c7 which had caused a lot of
unintended fallout, while preserving the actual feature supported by
the patch.

Before that patch (fcbeb), and after this one, we don't emit members
of specialized bound generic types, because these can be reconstructed
by substituting the "template parameters" in the unspecialized
type. This patch carves out an exception for inline arrays, because
DWARF has special support for arrays, which allows debuggers to reason
about them without needing special support.

rdar://146326633
2025-03-18 17:07:08 -07:00
Shubham Sandeep Rastogi
7a6070e79c [DebugInfo] Use Stmt EndLoc if SILLocation passed in is the Stmt EndLoc.
When creating an ExtendedASTNodeLoc from a SILLocation, if the
SILLocation passed in belongs to a swift::Stmt, we only ever use the
Stmt's StartLoc for the SourceLocation. If the SILLocation passed in,
has a SourceLocation that matches the EndLoc of the Stmt, we should
correctly set the primary ASTNodeTy PointerUnion's integer to 1, to
denote that the SourceLocation dervied from the Stmt points to the
EndLoc.
2025-03-13 12:39:32 -07:00
Adrian Prantl
6e9faa1303 Merge pull request #79929 from adrian-prantl/146688269
[Debug Info] Prevent infinite recursion when emitting debug info
2025-03-13 08:47:00 -07:00
Adrian Prantl
34cda58239 [Debug Info] Prevent infinite recursion when emitting debug info
for recursive classes. This is achieved by treating types created with
DebugTypeInfo::createFrowardDecl() as unconditional forward
declarations when emitting debug info instead of applying a heuristic
to determine this.

rdar://146688269
2025-03-12 11:07:26 -07:00
Rintaro Ishizaki
7e6d4d3cb5 [Tests] Mark 2 tests require 'embedded_stdlib'
These tests require Embedded stdlib:

  DebugInfo/value-generics-embedded.swift
  Macros/macro_unique_name_embedded.swift
2025-03-11 13:25:30 -07:00
Alejandro Alonso
d0513a7aec Merge pull request #79665 from Azoy/value-generics-no-more-experiment
[AST] Make ValueGenerics feature always available
2025-03-10 15:14:34 -07:00
Slava Pestov
a03b8ee6aa AST: Allow mangling LocatableType in DWARF mode
Fixes rdar://problem/145954323.
2025-03-04 22:00:44 -05:00
Alejandro Alonso
c1bb143648 Make ValueGenerics feature always available 2025-02-27 10:03:37 -08:00
Shubham Sandeep Rastogi
c2c5eb1334 [DebugInfo]Generate call-site information in swift
This patch adds support for emitting the flag
llvm::DINode::FlagAllCallsDescribed when generating LLVM IR from the
Swift compiler to get call-site information for swift source code.
2025-02-26 14:28:45 -08:00
Shubham Sandeep Rastogi
52a5ed8646 Pass correct SubExpr as source location when emitting Load of LValue.
When emitting an LValue of a LoadExpr during SILGen, the Expression
passed as a SILLocation for the LValue was the parent LoadExpr instead
of the SubExpr that contains the LValue for the load. This leads to
the SILLocation to be marked as implicit, because a LoadExpr is always
an implicit expression.

An implicit SILLocation is not emitted when doing IRGen as it is
considered to be hidden from debug info and thus we lose the debug
location for the LValue of a LoadExpr.

This patch fixes this issue.
2025-02-21 09:16:30 -08:00
Shubham Sandeep Rastogi
092068340e Add option -sil-print-debuginfo-verbose
The option -sil-print-debuginfo-verbose will print the values of the
fields, implicit, and autoGenerated for a SILLocation, as well as
whether the SILLocation is considered hidden from debug information
by calling SILLocation::isHiddenFromDebugInfo()
2025-02-20 13:26:35 -08:00
Adrian Prantl
fcbebc51c7 [Debug Info] Emit -gdwarf-types debug info for Builtin.FixedArray<>
This commit also changes how specialized types are being emitted. Previously we
would not emitthe detailed member information in the specialized type itself,
and instead rely on the fact that it was present in the unspecialized type,
however, this wold prevent us from emitting any bound generic members, so we're
now emitting the members in both variants of the type.

This uncovered a with type aliases that this commit also addresses: Because we
don't canonicalize types prior to caching in order to preserve type sugar,
alternative representations of recursive types (with one or more levels of
recursion unfolded) could create potential infinite chains of types. This is
addressed by checking whether a sugared type has an already emitted canonical
representation first, and if yes, creating a typedef node pointing directly to
it.

The donwside of doing this is that it can lead to the disappearnce of type
aliases definitions when they are used as parameters in bound generic
types. However, we still preserve that a type was `MyClass<MyAlias>`. We just
might have a typedef pointing director from `MyClass<MyAlias>` ->
`MyClass<CanonicalType>`.

rdar://144315592
2025-02-14 12:19:58 -08:00
Alejandro Alonso
e4fb1f6761 Rename Slab to InlineArray 2025-02-11 10:26:44 -08:00
Erik Eckstein
ba4081ee76 Optimizer: replace PredictableMemoryAccessOptimizations with MandatoryRedundantLoadElimination in the pass pipeline
PredictableMemoryAccessOptimizations has become unmaintainable as-is.
RedundantLoadElimination does (almost) the same thing as PredictableMemoryAccessOptimizations.
It's not as powerful but good enough because PredictableMemoryAccessOptimizations is actually only needed for promoting integer values for mandatory constant propagation.
And most importantly: RedundantLoadElimination does not insert additional copies which was a big problem in PredictableMemoryAccessOptimizations.

Fixes rdar://142814676
2025-02-07 11:30:35 +01:00
Adrian Prantl
85faa52009 Merge pull request #79085 from adrian-prantl/143833326
[Debug info] Emit bound generic class type parameters when emitting A…
2025-02-03 10:04:28 -08:00
Arnold Schwaighofer
c95c45201e Merge pull request #78996 from aschwaighofer/checked_cast_br_nightmares
SIL: Update formal source type in SimplifyRefCasts when possible
2025-02-02 08:27:01 -08:00
Adrian Prantl
91b6162f25 [Debug info] Emit bound generic class type parameters when emitting AST types
This relands commit 45d4648bdb while ensuring that
sanityCheckCachedType uses the exact same condition (now factored into a helper
function) as createType() to determine whether a type is sized or not.

rdar://143833326
2025-02-01 10:07:45 -08:00
Adrian Prantl
45d4648bdb Revert "[Debug info] Emit bound generic class type parameters when emitting AST types"
This reverts commit f2132890db
it triggers the debug info sanity check when running the source compatibility testsuite.
2025-01-30 17:27:39 -08:00
Arnold Schwaighofer
0fe3cf0096 SIL: Update formal source type in SimplifyRefCasts when possible
We use the formal source type do decide whether a checked_cast_br is
known to succeed/fail. If we don't update it we loose that optimization

That is:

```
  checked_cast_br AnyObject in %2 : X to X, bb1, bb2
```

Will not be simplified even though the operand and the destintation type
matches.
2025-01-29 09:07:21 -08:00
Adrian Prantl
f2132890db [Debug info] Emit bound generic class type parameters when emitting AST types
This ensures that debug info for these types is emitted even if this is the only
way they are references in the input program.

rdar://143595521
2025-01-28 17:39:18 -08:00
Adrian Prantl
e70a3443e9 [Debug Info] Remove the mostly unused FragmentType from DebugTypeInfo
This cleanup allows for more consistent debug info emission since we depend less
on IRGen magic to emit debug info for types.
2025-01-27 17:28:10 -08:00
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
Daniil Kovalev
e89abf84c9 [DebugInfo] Enable debug_scope_distinct.swift test (#78383)
It was previously disabled in https://github.com/swiftlang/swift/pull/73373
2025-01-13 16:16:05 -08:00
Alejandro Alonso
4c5a13a63e Moar test fixes 2025-01-10 17:52:50 -08:00
Alejandro Alonso
cedea94b4c Test fixes and review feedback 2025-01-09 15:54:54 -08:00
Alejandro Alonso
f76d841540 Rename to Slab 2025-01-09 10:39:45 -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
Shubham Sandeep Rastogi
1dd1925716 Merge pull request #78281 from rastogishubham/FixDropped
Fix test failure on non-darwin bots
2024-12-19 18:02:46 -08:00
Shubham Sandeep Rastogi
ac131df34f Fix test failure on non-darwin bots
Removed the --target option on the sil-opt command invocation.
2024-12-19 11:18:07 -08:00
Augusto Noronha
dccc52d07e Merge pull request #78104 from augusto2112/orig-defined-in
[DebugInfo] Fix handling of @_originallyDefinedIn types
2024-12-18 13:38:55 -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
Hamish Knight
a1f2f6a78c [test] Disable dropped-var.sil
rdar://141272451
2024-12-16 11:49:22 +00:00
Shubham Sandeep Rastogi
c689aaf947 Add target triple to dropped-var.sil test. 2024-12-12 13:58:19 -08:00
Shubham Sandeep Rastogi
5fb3578d70 Merge pull request #77951 from rastogishubham/LostVarsFalse
Add false positive detection to sil lost variables
2024-12-10 19:23:05 -08:00
Slava Pestov
302b163edc AST: Optimize TypeAliasType representation 2024-12-06 17:39:55 -05:00
Shubham Sandeep Rastogi
86e87c2a45 Add false positive detection to sil lost variables
This patch adds false positive detection to sil-stats-lost-variables.
We will now only detect a debug_value as lost if there is a real
instruction which belongs to the same scope or a child scope of the
scope of the debug_value and if they are both inline at the same
location.

//a
2024-12-05 11:52:40 -08:00