Commit Graph

185 Commits

Author SHA1 Message Date
Evan Wilde
ddaf003c56 Get stdlib building again
PR 79186 (https://github.com/swiftlang/swift/pull/79186) moved one of
the mandatory passes from the C++ implementation to the Swift
implementation resulting in a compiler that is unable to build the
standard library. The pass used to ensure that inaccessible control-flow
positions after an infinite loop was marked with `unreachable` in SIL.
Since the pass is no longer running, any function that returns a value
that also has an infinite loop internally must place a fatalError after
the infinite loop or it will fail to compile as the compiler will
determine that the function does not return from all control flow paths
even though some of the paths are unreachable.
2025-03-06 13:32:54 -08:00
Guillaume Lessard
fab65890fb [stdlib] remove now-unnecessary unsafe annotations 2025-03-01 20:29:11 -08:00
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Alejandro Alonso
f38e84cfe1 Pass buffer to _projectReadOnly and fix appends 2025-02-05 14:33:30 -08:00
Alejandro Alonso
90bd2a008e Add maxSize helper to buffer and fix reroot 2025-02-04 16:21:09 -08:00
Alejandro Alonso
edee13a612 Take the leaf type into account for max size 2025-02-04 15:16:40 -08:00
Alejandro Alonso
59c53b72f0 Don't do the kvc stored offset optimization on 16 bit platforms 2025-02-04 15:16:40 -08:00
Alejandro Alonso
02401d4bb0 Remove some workarounds 2025-02-04 15:16:39 -08:00
Alejandro Alonso
581376e86e Move variable into closure 2025-02-04 15:16:39 -08:00
Alejandro Alonso
25a4bbe549 Check maxSize on finish 2025-02-04 15:16:39 -08:00
Alejandro Alonso
6fdb684fd2 Optimization for single component and fix tests 2025-02-04 15:16:39 -08:00
Alejandro Alonso
00ace6695f Round up sizeWithMaxSize 2025-02-04 15:16:38 -08:00
Alejandro Alonso
4733da2744 Performance improvements for reading keypaths 2025-02-04 15:16:36 -08:00
Amritpan Kaur
1c494c4d89 [StdLib] Handle nil property descriptors. 2024-09-25 12:54:52 -07:00
nate-chandler
bcd08c0c9a Merge pull request #73235 from nate-chandler/bitwise-copyable/enable
[BitwiseCopyable] Promote to feature.
2024-05-04 10:16:40 -07:00
Kuba Mracek
1d48f28d84 [KeyPath] Fix regression in == on keypaths 2024-04-30 12:50:03 -07:00
Nate Chandler
b1fbe4ea91 [BitwiseCopyable] Remove underscore. 2024-04-25 11:44:15 -07:00
Joe Groff
02e1f2ea15 IRGen: Fix key path generic environment marshalling for external property descriptors.
The layout of a computed key path component carries an argument buffer for captures, which has
the following layout:

```
---
captured values (subscript indices)
---
generic arguments
---
```

When we reference an externally-defined public property or subscript from a key path, and the
external declaration has a property descriptor, then the generic arguments for the external
declaration get appended to the end of this buffer, giving:

```
---
captured values (subscript indices)
---
generic arguments
---
external property's generic arguments
---
```

The convention for key path accessors to bind their generic environment is thus to unpack them
from the end of the argument buffer, so that the external keypath's accessors can find the
arguments to bind the external generic environment while still allowing the enclosing key path
to save the original captured generic environment (which may be necessary to capture the
appropriate conditional and/or retroactive `Equatable` and `Hashable` conformances for
subscript indices).

However, our code generation for binding the generic arguments out of the argument buffer
contained a flawed optimization: for a property, we know there are never any captured values,
so I had assumed that the generic parameters could always be bound from the beginning of the
argument buffer, assuming that the generic parameters make up the totality of the buffer. This
falls over for external property descriptor references when the key path itself captures a
generic environment, since the external property's expected generic environment appears after
the key path's original generic environment. We can fix this by removing the conditional
entirely, and always adjusting the offset we load the generic environment from to look at the
end of the buffer. Fixes rdar://125886333.
2024-04-25 10:36:13 -07:00
Alejandro Alonso
e71a55eb19 Print a special message when we fail getting a keypath value 2024-04-03 15:35:55 -07:00
Kuba Mracek
b642d771be [embedded] Compile-time (literal) KeyPaths for Embedded Swift
Enable KeyPath/AnyKeyPath/PartialKeyPath/WritableKeyPath in Embedded Swift, but
for compile-time use only:

- Add keypath optimizations into the mandatory optimizations pipeline
- Allow keypath optimizations to look through begin_borrow, to make them work
  even in OSSA.
- If a use of a KeyPath doesn't optimize away, diagnose in PerformanceDiagnostics
- Make UnsafePointer.pointer(to:) transparent to allow the keypath optimization
  to happen in the callers of UnsafePointer.pointer(to:).
2024-03-20 15:35:46 -07:00
Nate Chandler
5a2d1621ec [KeyPath] Restrict push and pop to BitwiseCopyable
Promotes the runtime isPOD check to a compile time constraint.
2024-02-14 13:02:09 -08:00
Guillaume Lessard
0c916f507d [stdlib] replace uses of String(validatingUTF8:)
- use the new name `String(validatingCString:)`
2023-09-11 14:17:05 -07:00
Alejandro Alonso
141fa804b1 Make _createOffsetBasedKeyPath and _rerootKeyPath only available with reflection 2023-06-26 23:09:39 -07:00
Alejandro Alonso
d9d26eec9d Add support for classes in _createOffsetBasedKeyPath 2023-06-22 14:07:41 -07:00
Alejandro Alonso
3360e41c9c Add SPI to reroot a keypath for a given superclass 2023-04-24 17:15:28 -07:00
Alejandro Alonso
e9c0b32497 Remove class support 2023-04-04 09:54:09 -07:00
Alejandro Alonso
3522a338a2 Create function to create an offset based keypath at runtime 2023-04-04 09:44:18 -07:00
Mike Ash
1f8acac3d4 [Runtime] Fix key paths on 32-bit with KVC string pointers in the top half of memory.
Key paths can store an offset or a pointer in the same field. On 32-bit, the field is considered to be an offset when it's less than the 4kB zero page, and a pointer otherwise.

The check uses a signed comparison, so pointers in the top half of memory would look like negative offsets. Add a check that the offset is zero or positive to avoid this.

rdar://103886537
2023-01-30 13:05:48 -05:00
Mike Ash
47d02db6ff Merge pull request #62528 from mikeash/self-keypath-debug-description
[Runtime] Fix debugDescription of .self keypaths.
2022-12-13 16:24:57 -05:00
Jonathan Grynspan
26fc627ad0 Fix a use-after-free bug on Win32 when calling lookupSymbol() (#62484) 2022-12-13 09:04:34 -05:00
Mike Ash
f440432891 [Runtime] Fix debugDescription of .self keypaths.
AnyKeyPath's debugDescription assumes there's always at least one component, but `\Type.self` produces an empty keypath. Special-case the empty case to display a `.self` component.

rdar://103237845
2022-12-12 14:34:22 -05:00
Martin Cwikla
bc4b38d747 Removed an unnecessary disabling of isPureStruct.
This would have prevented explicitly specified KeyPaths through pure structs, e.g., \A.b.c, from taking the optimized path.
2022-10-31 14:43:44 -06:00
Martin Cwikla
92d7cf5725 Revised _tryToAppendKeyPaths(). Removed two instances of isPureStruct.append() that weren't needed. 2022-10-26 11:05:02 -06:00
Martin Cwikla
21f175ae3c Added missing instances of pureStruct information propagation.
This means we no longer need to check for empty KeyPath Walker results.
2022-10-24 17:43:00 -06:00
Martin Cwikla
a6a2f509b3 Use Int(bitPattern) rather than distance(to) to compute the offset. 2022-10-20 14:26:35 -06:00
Martin Cwikla
4fb2f9e15e Modified storage of valid offsets in assignOffsetToStorage() and getOffsetFromStorage().
Got rid of isTuple(). Moved determination of pure struct KeyPaths into _instantiateKeyPathBuffer.
2022-10-20 14:26:35 -06:00
Martin Cwikla
d2912dca75 Fixed .unresolvedFieldOffset should count as an optimized offset. Restored optimization for KeyPath writes. 2022-10-20 14:25:40 -06:00
Martin Cwikla
2d5086c085 Fixed the failing unit tests in capture_propagate_keypath.swift.
Revisited formatting. Pulled in changes from the past four weeks.
2022-10-20 14:25:39 -06:00
Martin Cwikla
afebae5694 Moved computation of offset for pureStructKeyPaths into KeyPathPatternVisitors.
Next expected commit: Move information stored in _pureStructValueOffset to _kvcKeyPathStringPtr (or similar).
2022-10-20 14:25:39 -06:00
Martin Cwikla
353eb9ffd5 KeyPath offset tests were breaking on Ubuntu 20.04. It's possible _storedInlineOffset wasn't factored out correctly. 2022-10-20 14:25:39 -06:00
Martin Cwikla
5efc87c67e ABI stability fix: isPureStructKeyPath should be internal. 2022-10-20 14:25:39 -06:00
Martin Cwikla
9fb8f598eb Clarified a comment in isTuple(). 2022-10-20 14:25:38 -06:00
Martin Cwikla
ebdd00c071 Proposed design for skipping of KeyPath projections across trivially-typed memory. 2022-10-20 14:25:38 -06:00
Ben Pious
57d82317c1 Add CustomDebugDescription conformance to AnyKeyPath (#60133)
* initial

* it works

demangling mostly works

fix dots

printing works

add tests

add conformance to AnyKeyPath

implement SPI

subscripts fully work

comments

use cross platform image inspection

remove unnecessary comment

fix

fix issues

add conditional conformance

add types

try to fix the api-digester test

cr feedback: move impls behind flag, remove addChain(), switch statement, fallthrough instead of if-elses, move import

cr feedback: refactor switch statement

fix #ifdef

reindent, cr feedback: removes manual memory management

fix missing whitespace

fix typo

fix indentation issues

switch to regexes

checks should test in on all platforms

print types in subscripts

add test for empty subscript

Update test/api-digester/stability-stdlib-abi-without-asserts.test

Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>

add commas

fix failing test

fix stdlib annotation

cr feedback: remove global, refactor ifdef

cr feedback: switch back to manual memory management

switch to 5.8 macro

add new weakly linked functions to the allowlist

fix one more failing test

more cr feedback

more cr feedback

* fix invisible unicode
2022-09-13 09:23:32 -07:00
Erik Eckstein
5eff9066cc stdlib: use _withUnprotected... functions instead of Builtin.unprotectedAddressOf 2022-09-08 08:42:25 +02:00
Erik Eckstein
0f8dd3a551 stdlib: opt out of stack protection in places where there can't be buffer overflows.
We trust the internal implementation of the stdlib to not cause any unintentional buffer overflows.
In such cases we can use the "unprotected" address-to-pointer conversions.
This avoids inserting stack protections where it's not needed.
2022-09-08 08:42:25 +02:00
Alex Martini
bfba8d17ea Fix link markup.
Co-authored-by: Ben Rimmington <me@benrimmington.com>
2022-08-08 15:40:47 -07:00
Alex Martini
deed208b7b Add an example and cross reference to TSPL.
Fixes <rdar://79689446>
2022-06-30 12:34:47 -07:00
swift-ci
4184a0bb57 Merge pull request #42096 from kateinoigakukun/pr-24e8c53c23a06f91bc290068f3209e095a88bdcf
[Wasm][KeyPath] Resolve absolute function pointer as identity
2022-04-19 21:08:45 -07:00
Michael Gottesman
5c8bd3266e Merge pull request #40779 from buttaface/android-tag
[android] Move the string and other tags in pointers to the second byte because Android enabled memory tagging
2022-04-04 13:06:43 -07:00