Commit Graph

139 Commits

Author SHA1 Message Date
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
Mike Ash
c38f613aec [Stdlib] Remove a / from the comment describing the ObjC runtime name for AnyKeyPath.
With three /'s, it got interpreted as documentation, which it definitely is not meant to be.
2019-03-13 13:59:53 -04:00
Andrew Trick
3da2cc9e06 Clarify comments. 2019-03-07 13:48:41 -08:00
Andrew Trick
f4c7d4611f Change the algorithm for the AccessEnforcementDom pass.
This adds a mostly flow-insensitive analysis that runs before the
dominator-based transformations. The analysis is simple and efficient
because it only needs to track data flow of currently in-scope
accesses. The original dominator tree walk remains simple, but it now
checks the flow insensitive analysis information to determine general
correctness. This is now correct in the presence of all kinds of nested
static and dynamic nested accesses, call sites, coroutines, etc.

This is a better compromise than:

(a) disabling the pass and taking a major performance loss.

(b) converting the pass itself to full-fledged data flow driven
optimization, which would be more optimal because it could remove
accesses when nesting is involved, but would be much more expensive
and complicated, and there's no indication that it's useful.

The new approach is also simpler than adding more complexity to
independently handle to each of many issues:

- Nested reads followed by a modify without a false conflict.
- Reads nested within a function call without a false conflict.
- Conflicts nested within a function call without dropping enforcement.
- Accesses within a generalized accessor.
- Conservative treatment of invalid storage locations.
- Conservative treatment of unknown apply callee.
- General analysis invalidation.

Some of these issues also needed to be considered in the
LoopDominatingAccess sub-pass. Rather than fix that sub-pass, I just
integrated it into the main pass. This is a simplification, is more
efficient, and also handles nested loops without creating more
redundant accesses. It is also generalized to:
- hoist non-uniquely identified accesses.
- Avoid unnecessarily promoting accesses inside the loop.

With this approach we can remove the scary warnings and caveats in the
comments.

While doing this I also took the opportunity to eliminate quadratic
behavior, make the domtree walk non-recursive, and eliminate cutoff
thresholds.

Note that simple nested dynamic reads to identical storage could very
easily be removed via separate logic, but it does not fit with the
dominator-based algorithm. For example, during the analysis phase, we
could simply mark the "fully nested" read scopes, then convert them to
[static] right after the analysis, removing them from the result
map. I didn't do this because I don't know if it happens in practice.
2019-03-07 12:39:53 -08:00
Joe Groff
9669c3a703 KeyPaths: Don't relative-reference selector refs.
ld64 doesn't like this. Instead, generate a stub function to grab the instantiated selector. Fixes rdar://problem/47184763.
2019-01-10 14:32:50 -08:00
Joe Groff
e30c86769a KeyPath: Allow existing context descriptors to be used as generic environment.
If a key path literal appears in a generic context with an existing context descriptor, this will allow us to
save some code size by not having to emit a separate GenericEnvironment descriptor.
2018-12-11 09:05:47 -08:00
Mike Ash
6b9480252e [Stdlib] Change AnyKeyPath to use @_objcRuntimeName attribute for its rename.
rdar://problem/46546165
2018-12-10 10:35:37 -05:00
Mike Ash
a49e2ddde7 [Stdlib] Rename AnyKeyPath's ObjC name and _VaListBuilder to avoid conflicts with older stdlibs.
rdar://problem/46546165
2018-12-10 10:17:52 -05:00
Mike Ash
01b840a488 [Stdlib] Ensure key paths allocate space for the terminating NUL.
rdar://problem/46457346 SR-9404
2018-12-04 14:53:03 -05:00
Doug Gregor
cc2ee165a1 [ABI] Use generic environment to handle mangled generic keypath types.
Always use mangled type names to represent type metadata in keypath patterns.
For generic types, use the generic environment to pull substituted types
from the instantiation arguments.

Finishes the type metadata part of rdar://problem/38038799.
2018-11-16 10:13:07 -08:00
Doug Gregor
f759296cc8 [Keypaths] Encode generic environment in the key-path pattern.
Extend the key-path pattern with a representation of the generic environment
of the key-path, which includes the generic parameters and generic
requirements of the environment.
2018-11-16 10:13:06 -08:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
swift-ci
126f9d7773 Merge pull request #20610 from DougGregor/abi-symbolic-accessor-ref-2-byte 2018-11-15 17:30:19 -08:00
Doug Gregor
723b56e64f [Standard library] Simplify _getTypeByMangledName.
Simplify the signature of the internal _getTypeByMangledName() used by the
standard library to what we actually (currently) use. Drop it as a
compatibility override, because it’s not a useful place to introduce
customization.
2018-11-15 16:10:11 -08:00
Doug Gregor
3eb171d814 [ABI] Ensure that symbolic references to accessor functions are 2-byte aligned
When we emit "false" symbolic references to accesors for conformances or
type metadata, ensure that we end up with two-byte-aligned symbolic
references. This addresses a problem with ARM+Thumb compilation where the
low bit wasn't getting set for Thumb code.

Fixes rdar://problem/46067353.
2018-11-15 14:51:55 -08:00
Doug Gregor
7b8bbcd473 [Keypaths] Start using mangled type names for non-dependent types.
When a type in keypath metadata is non-dependent, use a mangled type name
rather than a symbolic reference to an accessor function.

Part of rdar://problem/38038799.
2018-11-12 21:15:20 -08:00
Doug Gregor
b192cedf8d [Keypaths] Use mangled names to reference type and witness table accessors.
Switch key path metadata over to mangled names for each of the places it
refers to either a type metadata accessor or a witness table accessor. For
now, the mangled name is a symbolic reference to the existing accessors.

Part of rdar://problem/38038799.
2018-11-12 21:15:20 -08:00
John McCall
3e5165d1ab Change the compiler ABI of keypaths.
Previously, the stdlib provided:

- getters for AnyKeyPath and PartialKeyPath, which have remained;

- a getter for KeyPath, which still exists alongside a new read
  coroutine; and

- a pair of owned mutable addressors that provided modify-like behavior
  for WritableKeyPath and ReferenceWritableKeyPath, which have been
  replaced with modify coroutines and augmented with dedicated setters.

SILGen then uses the most efficient accessor available for the access
it's been asked to do: for example, if it's been asked to produce a
borrowed r-value, it uses the read accessor.

Providing a broad spectrum of accessor functions here seems acceptable
because the code-size hit is fixed-size: we don't need to generate
extra code per storage declaration to support more alternatives for
key paths.

Note that this is just the compiler ABI; the implementation is still
basically what it was.  That means the implementation of the setters
and the read accessor is pretty far from optimal.  But we can improve
the implementation later; we can't improve the ABI.

The coroutine accessors have to be implemented in C++ and used via
hand-rolled declarations in SILGen because it's not currently possible
to declare independent coroutine accessors in Swift.
2018-11-10 02:08:04 -05:00
John McCall
09cfb81571 Fix a bug with key paths that could lead to exclusivity crashes. 2018-11-10 02:08:04 -05:00
Joe Groff
65a4531467 IRGen/Runtime: Make key path pattern format true-const.
Use relative references instead of pointers so that the pattern can be true-const. Instead of trying
to instantiate a constant key path literal in-place, point to a cache variable that we can store
a pointer to the shared instance into when instantiated. Now that the pattern format has diverged
significantly from the instance format, simplify and refactor the instantiation code using a walker
for the pattern format instead of trying to reuse the code for working with instantiated instances.
rdar://problem/42674576
2018-11-05 12:30:49 -08:00
Joe Shajrawi
b5508f5488 [Exclusivity] Remove dominated access checks with no nested conflict:
Simplification of the code (bail on unpaired accesses) + change the implementation so we can avoid quadratic behavior
2018-10-26 11:19:21 -07:00
Joe Shajrawi
63b50f65a4 [Exclusivity] Remove dominated access checks with no nested conflict.
General case:

—
begin_access A (may or may not have no_nested_conflict)
load/store
end_access

apply // may have a scoped access that conflicts with A

begin_access A [no_nested_conflict]
load/store
end_access A
—

The second access scope does not need to be emitted.

NOTE: KeyPath access must be identified at the top-level, non-inlinable stdlib entry point.
As such, The sodlib entry pointed is annotated by a new @_semantics that is equivalent to inline(never)
2018-10-25 15:21:06 -07:00
Mike Ash
f4db1dd7a4 Merge pull request #19614 from mikeash/no-internal-export
[Stdlib] Change SWIFT_RUNTIME_STDLIB_INTERNAL to not export the symbol.
2018-10-05 09:26:03 -04:00
Ben Cohen
6cc6f4f182 Underscore @usableFromInlinable symbols (#19686) 2018-10-03 12:01:28 -07:00
Mike Ash
e18e03171f [Stdlib] Change SWIFT_RUNTIME_STDLIB_INTERNAL to not export the symbol.
The functions in LibcShims are used externally, some directly and some through @inlineable functions. These are changed to SWIFT_RUNTIME_STDLIB_SPI to better match their actual usage. Their names are also changed to add "_swift" to the front to match our naming conventions.

Three functions from SwiftObject.mm are changed to SPI and get a _swift prefix.

A few other support functions are also changed to SPI. They already had a prefix and look like they were meant to be SPI anyway. It was just hard to notice any mixup when they were #defined to the same thing.

rdar://problem/35863717
2018-10-03 09:55:33 -04:00