Commit Graph

22380 Commits

Author SHA1 Message Date
Tim Kientzle
b685d9f87e Merge pull request #85802 from tbkka/tbkka-MutableSpanTransparency
Make some key MutableSpan APIs `transparent`
2025-12-02 21:50:31 -08:00
Tim Kientzle
1833187b76 Merge pull request #85803 from tbkka/tbkka-FPToString-unsafe
Fill in missing `unsafe` markers
2025-12-02 21:18:23 -08:00
Adrian Prantl
90f4b4fc8e [LLDB] Replace more instances of the DEBUG_LOG macro with setError
This allows LLDB to query the last error and produce more helpful
diagnostics. This is NFC for the runtime.
2025-12-02 16:32:02 -08:00
Kavon Farvardin
d6b23bb3ac Merge pull request #85635 from kavon/opaque-values/fixes-6
OpaqueValues: provide stdlib build option
2025-12-02 15:59:51 -08:00
Hamish Knight
019520b25f Merge pull request #85740 from hamishknight/out-of-place
Rework emission of EditorPlaceholderExprs
2025-12-02 23:25:40 +00:00
Doug Gregor
3c933a1f73 Move Unicode Data declarations from SwiftShims to @_extern(c)
This eliminates UnicodeData.h from the public SwiftShims. A small
part of it remains as a private header, but everything else moves
into `@_extern(c)`.
2025-12-02 15:11:53 -08:00
Tim Kientzle
f607cd9d0c Fix two other unsafe markers 2025-12-02 10:45:25 -08:00
Tim Kientzle
655c5ff76e Fill in missing unsafe markers 2025-12-02 09:56:19 -08:00
Tim Kientzle
fa7bb2ebea Make some key MutableSpan APIs transparent
These are trivial operations that:
* Should always be inlined
* Should behave like intrinsics for debugging purposes
2025-12-02 09:53:42 -08:00
Anthony Latsis
8572b7e38c Address llvm::StringSwitch deprecations in advance
There's a whole bunch of these, e.g.
- https://github.com/llvm/llvm-project/pull/163405
- https://github.com/llvm/llvm-project/pull/164276
- https://github.com/llvm/llvm-project/pull/165119
- https://github.com/llvm/llvm-project/pull/166016
- https://github.com/llvm/llvm-project/pull/166066
2025-12-02 17:13:17 +00:00
Carl Peto
dd9543f126 Merge pull request #85589 from carlpeto/eng/PR-164566321
Always show the crashed thread first
2025-12-02 15:05:52 +00:00
Carl Peto
53722a3239 Merge pull request #85483 from carlpeto/fix-backtrace-stderr-color-bug
Backtrace incorrectly picks up colour from stdout instead of stderr
2025-12-02 15:03:38 +00:00
Alastair Houghton
354b461f7f Merge pull request #85312 from al45tair/concurrency-6.3-not-6.2
[Concurrency] Change all of the StdlibDeploymentTarget 6.2s to 6.3.
2025-12-02 10:51:09 +00:00
Zev Eisenberg
a994527a23 [SE-0489] Better debugDescription for EncodingError and DecodingError (#80941)
Now accepted as
[SE-0489](https://github.com/ZevEisenberg/swift-evolution/blob/main/proposals/0489-codable-error-printing.md).

# To Do

- [x] confirm which version of Swift to use for the availability
annotations. Probably 6.3 at time of writing.

# Context

Re: [Swift forum
post](https://forums.swift.org/t/the-future-of-serialization-deserialization-apis/78585/77),
where a discussion about future serialization tools in Swift prompted
Kevin Perry to suggest that some proposed changes could actually be made
in today's stdlib.

# Summary of Changes

Conforms `EncodingError` and `DecodingError` to
`CustomDebugStringConvertible` and adds a more-readable
`debugDescription`.

# Future Directions

This is a pared-down version of some experiments I did in
[UsefulDecode](https://github.com/ZevEisenberg/UsefulDecode). The
changes in this PR are the best I could do without changing the public
interface of `DecodingError` and `EncodingError`, and without modifying
the way the `JSON`/`PropertyList` `Encoder`/`Decoder` in Foundation
generate their errors' debug descriptions.

In the above-linked
[UsefulDecode](https://github.com/ZevEisenberg/UsefulDecode) repo, when
JSON decoding fails, I go back and re-decode the JSON using
`JSONSerialization` in order to provide more context about what failed,
and why. I didn't attempt to make such a change here, but I'd like to
discuss what may be possible.

# Examples

To illustrate the effect of the changes in this PR, I removed my changes
to stdlib/public/core/Codable.swift and ran my new test cases again.
Here are the resulting diffs.

##
`test_encodingError_invalidValue_nonEmptyCodingPath_nilUnderlyingError`

### Before
`invalidValue(234, Swift.EncodingError.Context(codingPath:
[GenericCodingKey(stringValue: "first", intValue: nil),
GenericCodingKey(stringValue: "second", intValue: nil),
GenericCodingKey(stringValue: "2", intValue: 2)], debugDescription: "You
cannot do that!", underlyingError: nil))`

### After
`EncodingError.invalidValue: 234 (Int). Path: first.second[2]. Debug
description: You cannot do that!`

## `test_decodingError_valueNotFound_nilUnderlyingError`

### Before
`valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath:
[GenericCodingKey(stringValue: "0", intValue: 0),
GenericCodingKey(stringValue: "firstName", intValue: nil)],
debugDescription: "Description for debugging purposes", underlyingError:
nil))`

### After
`DecodingError.valueNotFound: Expected value of type String but found
null instead. Path: [0].firstName. Debug description: Description for
debugging purposes`

## `test_decodingError_keyNotFound_nonNilUnderlyingError`

### Before
`keyNotFound(GenericCodingKey(stringValue: "name", intValue: nil),
Swift.DecodingError.Context(codingPath: [GenericCodingKey(stringValue:
"0", intValue: 0), GenericCodingKey(stringValue: "address", intValue:
nil), GenericCodingKey(stringValue: "city", intValue: nil)],
debugDescription: "Just some info to help you out", underlyingError:
Optional(main.GenericError(name: "hey, who turned out the lights?"))))`

### After
`DecodingError.keyNotFound: Key \'name\' not found in keyed decoding
container. Path: [0].address.city. Debug description: Just some info to
help you out. Underlying error: GenericError(name: "hey, who turned out
the lights?")`

## `test_decodingError_typeMismatch_nilUnderlyingError`

### Before
`typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath:
[GenericCodingKey(stringValue: "0", intValue: 0),
GenericCodingKey(stringValue: "address", intValue: nil),
GenericCodingKey(stringValue: "city", intValue: nil),
GenericCodingKey(stringValue: "birds", intValue: nil),
GenericCodingKey(stringValue: "1", intValue: 1),
GenericCodingKey(stringValue: "name", intValue: nil)], debugDescription:
"This is where the debug description goes", underlyingError: nil))`

### After
`DecodingError.typeMismatch: expected value of type String. Path:
[0].address.city.birds[1].name. Debug description: This is where the
debug description goes`

## `test_decodingError_dataCorrupted_nonEmptyCodingPath`

### Before
`dataCorrupted(Swift.DecodingError.Context(codingPath:
[GenericCodingKey(stringValue: "first", intValue: nil),
GenericCodingKey(stringValue: "second", intValue: nil),
GenericCodingKey(stringValue: "2", intValue: 2)], debugDescription:
"There was apparently some data corruption!", underlyingError:
Optional(main.GenericError(name: "This data corruption is getting out of
hand"))))`

### After
`DecodingError.dataCorrupted: Data was corrupted. Path: first.second[2].
Debug description: There was apparently some data corruption!.
Underlying error: GenericError(name: "This data corruption is getting
out of hand")`

## `test_decodingError_valueNotFound_nonNilUnderlyingError`

### Before
`valueNotFound(Swift.Int, Swift.DecodingError.Context(codingPath:
[GenericCodingKey(stringValue: "0", intValue: 0),
GenericCodingKey(stringValue: "population", intValue: nil)],
debugDescription: "Here is the debug description for value-not-found",
underlyingError: Optional(main.GenericError(name: "these aren\\\'t the
droids you\\\'re looking for"))))`

### After
`DecodingError.valueNotFound: Expected value of type Int but found null
instead. Path: [0].population. Debug description: Here is the debug
description for value-not-found. Underlying error: GenericError(name:
"these aren\\\'t the droids you\\\'re looking for")`

##
`test_encodingError_invalidValue_emptyCodingPath_nonNilUnderlyingError`

### Before
`invalidValue(345, Swift.EncodingError.Context(codingPath: [],
debugDescription: "You cannot do that!", underlyingError:
Optional(main.GenericError(name: "You really cannot do that"))))`

### After
`EncodingError.invalidValue: 345 (Int). Debug description: You cannot do
that!. Underlying error: GenericError(name: "You really cannot do
that")`

## `test_decodingError_typeMismatch_nonNilUnderlyingError`

### Before
`typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath:
[GenericCodingKey(stringValue: "0", intValue: 0),
GenericCodingKey(stringValue: "address", intValue: nil),
GenericCodingKey(stringValue: "1", intValue: 1),
GenericCodingKey(stringValue: "street", intValue: nil)],
debugDescription: "Some debug description", underlyingError:
Optional(main.GenericError(name: "some generic error goes here"))))`

### After
`DecodingError.typeMismatch: expected value of type String. Path:
[0].address[1].street. Debug description: Some debug description.
Underlying error: GenericError(name: "some generic error goes here")`

## `test_encodingError_invalidValue_emptyCodingPath_nilUnderlyingError`

### Before
`invalidValue(123, Swift.EncodingError.Context(codingPath: [],
debugDescription: "You cannot do that!", underlyingError: nil))`

### After
`EncodingError.invalidValue: 123 (Int). Debug description: You cannot do
that!`

## `test_decodingError_keyNotFound_nilUnderlyingError`

### Before
`keyNotFound(GenericCodingKey(stringValue: "name", intValue: nil),
Swift.DecodingError.Context(codingPath: [GenericCodingKey(stringValue:
"0", intValue: 0), GenericCodingKey(stringValue: "address", intValue:
nil), GenericCodingKey(stringValue: "city", intValue: nil)],
debugDescription: "How would you describe your relationship with your
debugger?", underlyingError: nil))`

### After
`DecodingError.keyNotFound: Key \'name\' not found in keyed decoding
container. Path: [0]address.city. Debug description: How would you
describe your relationship with your debugger?`

## `test_decodingError_dataCorrupted_emptyCodingPath`

### Before
`dataCorrupted(Swift.DecodingError.Context(codingPath: [],
debugDescription: "The given data was not valid JSON", underlyingError:
Optional(main.GenericError(name: "just some data corruption"))))`

### After
`DecodingError.dataCorrupted: Data was corrupted. Debug description: The
given data was not valid JSON. Underlying error: GenericError(name:
"just some data corruption")`

##
`test_encodingError_invalidValue_nonEmptyCodingPath_nonNilUnderlyingError`

### Before
`invalidValue(456, Swift.EncodingError.Context(codingPath:
[GenericCodingKey(stringValue: "first", intValue: nil),
GenericCodingKey(stringValue: "second", intValue: nil),
GenericCodingKey(stringValue: "2", intValue: 2)], debugDescription: "You
cannot do that!", underlyingError: Optional(main.GenericError(name: "You
really cannot do that"))))`

### After
`EncodingError.invalidValue: 456 (Int). Path: first.second[2]. Debug
description: You cannot do that!. Underlying error: GenericError(name:
"You really cannot do that")`
2025-12-01 11:34:00 -05:00
Hamish Knight
3a3e8dfd5f [stdlib] Make _undefined non-public
This never should have been made public, given it's a compiler
implementation detail let's downgrade it to `@usableFromInline`.
2025-11-30 11:12:39 +00:00
Hamish Knight
ae82b29e35 Rework emission of EditorPlaceholderExprs
Rather than synthesizing a semantic expression to emit, add a compiler
intrinsic to the stdlib that is simple enough to just SILGen the
emission.
2025-11-30 11:12:39 +00:00
Danny Canter
36b6b96a72 Synchronization: Add errno to some linux lock fatalErrors
In the comments it's stated that these errnos can't really occur for
the implementation, but unfortunately they have been seen in some
scenarios. To aide in debugging, it'd be nice to at least have the
errno in the error message.
2025-11-27 15:01:19 -08:00
Rauhul Varma
ce02872adf Add Embedded Swift Cxx exception personality
Users frequently run into a missing runtime symbol for Cxx exceptions
(`_swift_exceptionPersonality`) when mixing Embedded Swift and Cxx with
exceptions enabled. This leads to a confusing an hard to debug linker
error. This commit adds an implementation of this function to the
Embedded Swift runtime which simply fatal errors if a cxx exception is
caught in a Swift frame.

Issue: rdar://164423867
Issue: #85490
2025-11-21 11:12:10 -08:00
Carl Peto
ddc8c2b14d [Backtrace] show the crashed thread first in standard crash logs
It can be hard to find the crashed thread. This always shows it first, before
any other threads.

rdar://164566321
2025-11-21 16:23:03 +00:00
Carl Peto
95d6d4384c [Backtracing] Fix color=tty to check the actual output.
The `color=tty` setting was checking `stdout` to see if it was a TTY, but
we may be using `stderr`, in which case it's easy to end up with coloured
output in a file we're redirecting to.  Fix it to check the selected
output instead.

rdar://164624364
2025-11-21 11:50:32 +00:00
Arnold Schwaighofer
1b6da50ed9 Merge pull request #85602 from aschwaighofer/wip_embedded_exit_cast
[embedded] Implement swift_dynamicCast suport for casts from existential to concrete type
2025-11-20 21:01:41 -05:00
Kavon Farvardin
54e71d086a OpaqueValues: provide stdlib build option
Should allow testing with preset:
```
extra-cmake-options=-DSWIFT_STDLIB_EXTRA_SWIFT_COMPILE_FLAGS=TRUE
```
2025-11-20 14:27:48 -08:00
Egor Zhdan
6b118aca0d Merge pull request #85488 from CrazyFanFan/optimization/cxx_set_contains
Optimize `contains` method implementation in `CxxSet`
2025-11-20 12:03:52 +00:00
Kavon Farvardin
f8a31c6c9d Merge pull request #85573 from kavon/document-escapable
Doc: add explainer for `Escapable`
2025-11-20 01:49:23 -08:00
Bryce Wilson
b30f63530a [Concurrency] Set thread base priority when running escalated Tasks (#84895) 2025-11-20 09:58:08 +09:00
Arnold Schwaighofer
3cff05d540 [embedded] Implement swift_dynamicCast suport for casts from existential to concrete type 2025-11-19 14:41:37 -08:00
Kavon Farvardin
7e9608cccc Doc: small fixes for Escapable explainer
Thanks to a review from @amartini51

Co-authored-by: Alex Martini <amartini@apple.com>
2025-11-18 15:14:38 -08:00
Kavon Farvardin
55eaed524e Doc: add explainer for Escapable
resolves rdar://146331729
2025-11-18 14:36:29 -08:00
Dario Rexin
0502f0db57 Revert "[Runtime] Don't use write back in EIC retain/release" 2025-11-18 12:19:24 -08:00
Arnold Schwaighofer
17447a3378 Merge pull request #85551 from aschwaighofer/wip_embedded_exit
Preliminary support for existential in embedded Swift
2025-11-18 15:10:40 -05:00
Dave Lee
b6b477de58 [Debug] Add pointer based stringForPrintObject (#84742)
Adds an overload of `_DebuggerSupport.stringForPrintObject` which takes a pointer and mangled typename as arguments. This will be used to improve performance and resilience of `po` in lldb.

The pointer and mangled typename are used to construct an `Any` value, which is then passed into the primary implementation of `stringForPrintObject`.

This allows calling `stringForPrintObject` without having to first construct a context that contains all necessary Swift modules. This will improve speed, and also resilience when modules cannot be loaded for whatever reason.

rdar://158968103
2025-11-18 09:32:28 -08:00
AZero13
5c6f34163b Fix copy-paste error of calculation of suspending time in Clock.cpp (#85545)
We should be assigning the value to suspension, not continuous!
2025-11-17 22:11:35 -08:00
Tim Kientzle
a271eb2bb7 Merge pull request #85544 from tbkka/tbkka-Issue85539
Properly initialize buffer when called via legacy ABI
2025-11-17 19:50:07 -08:00
Arnold Schwaighofer
02d7fe5110 Document the difference of embedded swift's swift_allocBox 2025-11-17 12:48:48 -08:00
Arnold Schwaighofer
62ac48a17e Complete support for outline existential storage
... or so I believe
2025-11-17 12:48:45 -08:00
Arnold Schwaighofer
eda5eadfd4 Start outline storage support: Add swift_allocBox/deallocBox
Code using the outline heap storage path will crash and burn because
support is incomplete. But at least inline storage existential
inhabitants should compile and run.
2025-11-17 12:46:35 -08:00
Tim Kientzle
f65358521f Properly initialize buffer when called via legacy ABI
Resolves #85539
2025-11-17 10:56:10 -08:00
Jonathan Grynspan
431d2d857c Fix typos 2025-11-17 10:33:33 -05:00
Jonathan Grynspan
72f9fcb9b7 OpenBSD fixes 2025-11-17 09:01:29 -05:00
Jonathan Grynspan
bbfb61ee74 Don't use a stored property on Darwin so that we can AEIC (doesn't look like the combination works) 2025-11-17 08:51:27 -05:00
Alastair Houghton
40cee72e5a Merge pull request #85350 from aeu/fix-readlink-null-termination
Fix missing null terminator in runtime path resolution on Linux
2025-11-17 10:25:39 +00:00
Jonathan Grynspan
4d44571604 Fix inferred return type 2025-11-16 21:16:36 -05:00
Jonathan Grynspan
7cb77e048a Fix Darwin typos 2025-11-16 15:10:41 -05:00
Jonathan Grynspan
dd7524b592 Merge branch 'main' into jgrynspan/executablePath 2025-11-16 15:09:27 -05:00
0xpablo
c4588cb91d Add DirectX.Direct2D module to winsdk_um.modulemap 2025-11-16 19:55:05 +01:00
Jonathan Grynspan
ed300126bc Fix bugs 2025-11-14 15:51:34 -05:00
Jonathan Grynspan
f3f2043bc7 Fix Linux bounds check 2025-11-14 13:07:49 -05:00
Jonathan Grynspan
65eee8c6af Fix unbalanced squigglies 2025-11-14 12:20:04 -05:00
Jonathan Grynspan
0124287c94 Extra include 2025-11-14 09:37:09 -05:00
Jonathan Grynspan
882550af96 Fix OpenBSD 2025-11-14 09:36:26 -05:00