Commit Graph

163 Commits

Author SHA1 Message Date
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
Yuta Saito
ed7ab2a5a3 [Wasm][KeyPath] Resolve absolute function pointer as identity
Emit and resolve idValue of KeyPath as an absolute pointer if relative
function pointer is turned-off on Wasm target.
The existing ABI can't distinguish an idValue between function pointer
or data pointer in use-site at compile-time and also at runtime. So this
patch adds a new id resolution scheme `ResolvedAbsolute` to distinguish
them at runtime properly.
2022-04-02 16:25:23 +00:00
Yuta Saito
8c598e98f7 [Wasm][Runtime] Interpret absolute function pointer in runtime structures
When SWIFT_COMPACT_ABSOLUTE_FUNCTION_POINTER is enabled, relative direct
pointers whose pointees are functions will be turned into absolute
pointer at compile-time.
2022-04-02 04:32:41 +00:00
Butta
7b2256f97b [android] Move the string and other tags in pointers to the second byte because Android enabled memory tagging
Starting with Android 11, AArch64 placed a tag in the top byte of pointers to
allocations, which has been slowly rolling out to more devices and collides
with Swift's tags. Moving these tags to the second byte works around this
problem.
2022-04-02 08:50:54 +05:30
Karoy Lorentey
dd40ff2929 [stdlib][NFC] Put stored properties & primary initializers before other members in struct declarations 2021-10-05 22:01:35 -07:00
Alex Martini
d7ac2123d8 Keep doc comment before declaration.
Because the attribute is part of the declaration, putting a doc comment
between the attribute and "public" ends up with the comment in the
middle of the declaration.  This results in SourceKit skipping over the
comment, and the docs not being shown.

Fixes <rdar://problem/58716408>.
2021-02-17 14:51:58 -08:00
Mike Ash
a84a3a8f23 [Stdlib] Fix _swift_modifyAtWritableKeyPath_impl to check for ReferenceWritableKeyPaths.
Call through to _swift_modifyAtReferenceWritableKeyPath_impl in that case. This fixes an assertion failure (or worse) when upcasting a ReferenceWritableKeyPath and then using subscript(keyPath:) to modify a value with it.

rdar://74191390
2021-02-11 13:58:34 -05:00
Doug Gregor
1a1f79c0de Introduce safety checkin for ConcurrentValue conformance.
Introduce checking of ConcurrentValue conformances:
- For structs, check that each stored property conforms to ConcurrentValue
- For enums, check that each associated value conforms to ConcurrentValue
- For classes, check that each stored property is immutable and conforms
  to ConcurrentValue

Because all of the stored properties / associated values need to be
visible for this check to work, limit ConcurrentValue conformances to
be in the same source file as the type definition.

This checking can be disabled by conforming to a new marker protocol,
UnsafeConcurrentValue, that refines ConcurrentValue.
UnsafeConcurrentValue otherwise his no specific meaning. This allows
both "I know what I'm doing" for types that manage concurrent access
themselves as well as enabling retroactive conformance, both of which
are fundamentally unsafe but also quite necessary.

The bulk of this change ended up being to the standard library, because
all conformances of standard library types to the ConcurrentValue
protocol needed to be sunk down into the standard library so they
would benefit from the checking above. There were numerous little
mistakes in the initial pass through the stsandard library types that
have now been corrected.
2021-02-04 03:45:09 -08:00
Matt Zanchelli
be13b470aa Fix typos
becuase -> because
preceeds -> precedes
initalizer -> initializer
intialize -> initialize
libary -> library
notfication -> notification
reciever -> receiver
collecton -> collection
exlcusive -> exclusive
techincal -> technical
compatability -> compatibility
setps -> steps
accomodate -> accommodate
brakcet -> bracket
fraciton -> fraction
programm -> program
concequently -> consequently
ecoding -> encoding
timeIntervalforSelfEnd -> timeIntervalForSelfEnd
2020-12-21 18:44:03 -05:00
Parker Schuh
4e39e59a8a Add a field reflection function that constructs keypaths. (#34815)
While the existing _forEachField in ReflectionMirror.swift
already gives the offsets and types for each field, this isn't
enough information to construct a keypath for that field in
order to modify it.

For reference, this should be sufficent to implement the features
described here: (https://forums.swift.org/t/storedpropertyiterable/19218/62)
purely at runtime without any derived conformances for many types.

Note: Since there isn't enough reflection information for
`.mutatingGetSet` fields, this means that we're not able to support
reflecting certain types of fields (functions, nonfinal class fields,
etc). Whether this is an error or not is controlled by the `.ignoreUnknown`
option.
2020-11-30 09:17:23 -08:00
Mike Ash
ee8480fe71 [Stdlib] Fix swift_setAtWritableKeyPath to check for ReferenceWritableKeyPaths.
Call through to swift_setAtReferenceWritableKeyPath in that case. This fixes an assertion failure (or worse) when upcasting a ReferenceWritableKeyPath and then using subscript(keyPath:) to write a value with it.

rdar://problem/70609888
2020-11-13 13:00:16 -05:00
Yuta Saito
dcdf66832b [stdlib] Resolve relative address in consistent way 2020-11-09 11:25:41 +09:00
Joe Groff
be8674ea73 Make an internal KeyPath helper final.
And remove an unnecessary override, so that further work will allow this method not to need a
vtable entry.
2020-05-28 18:19:03 -07:00
Joe Groff
c5863ac0f3 SILOptimizer: Constant fold the _kvcKeyPathString of literal key paths.
Eliminate the intermediate key path object when a literal key path is passed to a function that
just wants its KVC string to pass down to an ObjC API.
2020-05-07 13:33:01 -07:00
Xiaodi Wu
90c6c491d9 [gardening] Silence a warning about unused value 2020-03-14 10:33:45 -04:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Karoy Lorentey
d83a4257f0 [stdlib] Don’t use assert() in the stdlib
assert() is designed to be used in user code only; the equivalent stdlib function is called _internalInvariant().

rdar://57101013
2019-12-11 19:23:46 -08:00
Greg Titus
dd4c6053a7 Warning fixes for core stdlib. 2019-08-15 10:14:50 -07:00
Paul Hudson
06f82a53b5 Replaced the majority of ' : ' with ': '. 2019-07-18 20:46:07 +01:00
Lei Zhang
6ac15e9348 Fix for KeyPathMultiModule test failure 2019-06-24 16:17:39 -04:00
Sho Ikeda
a35c9f0c60 [gardening] Use Collection.isEmpty over Collection.count 2019-05-26 09:35:20 +09:00
Joe Groff
05dfec0cda Push the conformance accessor hack down into getTypeByMangledName. 2019-04-17 14:44:40 -07:00
Mike Ash
48f9ac9de5 [Stdlib] Reconstitute the documentation part of the comment on AnyKeyPath. 2019-03-13 15:56:00 -04:00