Commit Graph

13406 Commits

Author SHA1 Message Date
Slava Pestov
4bc1d03283 Runtime: Use accessor method to get TargetWitnessTable::Description 2020-03-11 19:34:10 -04:00
tbkka
46bba7aa58 Memoize the ObjCBridgeable conformance for Swift.String (#30329)
This seems to be the single most common bridge cast,
and repeated lookup seems to be a performance issue
for the common operation of bridging a string-valued
NSDictionary into Swift.  Spending a couple of static
words of memory to memoize it should be a nice perf win.

Resolves rdar://55237013
2020-03-10 20:03:57 -07:00
Mike Ash
faa2bf2698 [Reflection] Fix a dangling reference in EnumTypeInfoBuilder when creating a case with an empty TypeInfo.
While we're in there, fix a couple of DEBUG_LOG calls that didn't compile when logging is enabled.

rdar://problem/59921829
2020-03-10 15:10:08 -04:00
Konrad `ktoso` Malawski
ea6b69eabc Add missing @available marker on _getMangledTypeName 2020-03-10 14:04:47 +09:00
Konrad `ktoso` Malawski
33444489e5 Add _mangledTypeName to allow round trips T->mangledName->T 2020-03-10 12:20:08 +09:00
swift-ci
28f343df51 Merge pull request #30301 from tbkka/tbkka-remoteMirror-projectEnum 2020-03-09 15:55:01 -07:00
Michael Ilseman
4715d68890 Merge pull request #30237 from valeriyvan/RemoveRedundantZeroingStringGuts
Changes implementation of _persistCString from _StringGuts
2020-03-09 14:36:05 -07:00
Mike Ash
b80e33b514 Fix reuse of the payload area when the discriminator != 0 2020-03-09 11:58:54 -07:00
Saleem Abdulrasool
559dc2a516 WinSDK: further extend the WinSock module
Add the new `afunix.h` header to the WinSock module which was introduced
in the 10.0.17134 release.
2020-03-09 09:54:59 -07:00
swift-ci
57f54dd1a3 Merge pull request #30294 from CodaFi/order-up 2020-03-09 09:50:31 -07:00
Saleem Abdulrasool
64864c2336 Merge pull request #30288 from compnerd/winsock
WinSDK: extend the WinSock module further
2020-03-09 08:24:25 -07:00
Robert Widmann
4c74c07a01 [NFC] Squash an initialization ordering warning 2020-03-09 08:07:04 -07:00
Saleem Abdulrasool
4fcd65a411 WinSDK: extend the WinSock module further
This enables the use of `TransmitFile` more fully by adding the
Microsoft extensions to the WinSock module.
2020-03-08 13:14:24 -07:00
Dario Rexin
6dc4329398 Move SwiftSource.cmake to stdlib 2020-03-08 12:48:34 -07:00
Kuba Mracek
c0ab0c9c0a Fixup swift-reflection-test.c and swift-reflection-dump.cpp 2020-03-07 08:11:52 -08:00
Kuba (Brecka) Mracek
ab6533a40f Merge branch 'master' into mracek/arm64e 2020-03-06 15:07:01 -08:00
tbkka
0d361bd3ea Teach RemoteMirror how to project enum values (#30161)
Teach RemoteMirror how to project enum values

This adds two new functions to the SwiftRemoteMirror
facility that support inspecting enum values.

Currently, these support non-payload enums and
single-payload enums, including nested enums and
payloads with struct, tuple, and reference payloads.
In particular, it handles nested `Optional` types.

TODO: Multi-payload enums use different strategies for
encoding the cases that aren't yet supported by this
code.

Note: This relies on information from dataLayoutQuery
to correctly decode invalid pointer values that are used
to encode enums.  Existing clients will need to augment
their DLQ functions before using these new APIs.

Resolves rdar://59961527

```
/// Projects the value of an enum.
///
/// Takes the address and typeref for an enum and determines the
/// index of the currently-selected case within the enum.
///
/// Returns true iff the enum case could be successfully determined.
/// In particular, note that this code may fail for valid in-memory data
/// if the compiler is using a strategy we do not yet understand.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_projectEnumValue(SwiftReflectionContextRef ContextRef,
                                      swift_addr_t EnumAddress,
                                      swift_typeref_t EnumTypeRef,
                                      uint64_t *CaseIndex);

/// Finds information about a particular enum case.
///
/// Given an enum typeref and index of a case, returns:
/// * Typeref of the associated payload or zero if there is no payload
/// * Name of the case if known.
///
/// The Name points to a freshly-allocated C string on the heap.  You
/// are responsible for freeing the string (via `free()`) when you are finished.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_getEnumCaseTypeRef(SwiftReflectionContextRef ContextRef,
                                        swift_typeref_t EnumTypeRef,
                                        unsigned CaseIndex,
                                        char **CaseName,
                                        swift_typeref_t *PayloadTypeRef);
```


Co-authored-by: Mike Ash <mikeash@apple.com>
2020-03-06 13:17:40 -08:00
Rintaro Ishizaki
3f69d6b9dd Merge pull request #30260 from milseman/assert_san
[stdlib] Disable assertion tripping up ASAN
2020-03-06 09:32:31 -08:00
Michael Ilseman
8d5d3815a1 Merge pull request #30180 from benrimmington/se-0263-test
[SE-0263] Add test, rename API, update docs
2020-03-06 08:54:24 -08:00
Michael Ilseman
fd468d068e [stdlib] Disable assertion tripping up ASAN
We have (and important!) assertion that our claimed allocation is
complete and the breadcrumbs are falling where we expect them
to. Something about ASAN changes the allocation behavior. Temporarily
disable this assertion until I can figure how to work with ASAN here.
2020-03-06 08:43:25 -08:00
Valeriy Van
f49f6a99ba Fixes variable name 2020-03-06 06:32:53 +01:00
Michael Ilseman
79bac4e6a3 Merge pull request #30244 from milseman/string_shrink
[string] Shrink storage class sizes
2020-03-05 19:57:40 -08:00
Michael Ilseman
89f0a1280f [gardening] Remove dead comments and code 2020-03-05 16:45:04 -08:00
swift-ci
55782b2f73 Merge pull request #29436 from amartini51/master 2020-03-05 16:24:10 -08:00
Michael Ilseman
d8f25be9fa [string] Skip unnecessary self UTF-16 length in isEqual
For isEqual bridging comparisons, skip checking our own UTF-16 length when the
string we're comparing against is known to be ASCII.
2020-03-05 16:13:15 -08:00
Michael Ilseman
7ff3ecf2e5 [string] Skip unnecessary self UTF-16 length in isEqual
For isEqual bridging comparisons, skip checking our own UTF-16 length when the
string we're comparing against is known to be ASCII.
2020-03-05 16:13:15 -08:00
Michael Ilseman
0ca42e9ef7 [string] Shrink storage class sizes.
* Don't allocate breadrumbs pointer if under threshold
* Increase breadrumbs threshold
* Linear 16-byte bucketing until 128 bytes, malloc_size after
* Allow cap less than _SmallString.capacity (bridging non-ASCII)

This change decreases the amount of heap usage for moderate-length
strings (< 64 UTF-8 code units in length) and increases the amount of
spare code unit capacity available (less growth needed).

Average improvements for moderate-length strings:

* 64-bit: on average, 8 bytes saved and 4 bytes of extra capacity
* 32-bit: on average, 4 bytes saved and 6 bytes of extra capacity

Additionally, on 32-bit, large-length strings also gain an average of
6 bytes of extra spare capacity.

Details:

On 64-bit, half of moderate-length allocations will save 16 bytes
while the other half get an extra 8 bytes of spare capacity.

On 32-bit, a quarter of moderate-length allocations will save 16
bytes, and the rest get an extra 4 bytes of spare
capacity. Additionally, 32-bit string's storage class now claims its
full allocation, which is its birthright. Prior to this change, we'd
have on average 1.5 bytes of spare capacity, and now we have 7.5 bytes
of spare capacity.

Breadcrumbs threshold is increased from the super-conservative 32 to
the pretty-conservative 64. Some speed improvements are incorporated
in this change, but more are in flight. Even without those eventual
improvements, this is a worthwhile change (ASCII is still fast-pathed
and irrelevant to breadcrumbing).

For a complex real-world workload, this amounts to around a 5%
improvement to transient heap usage due to all strings and a 4%
improvement to peak heap usage due to all strings. For moderate-length
strings specifically, this gives around 11% improvement to both.
2020-03-05 16:10:23 -08:00
Saleem Abdulrasool
23c536940f Merge pull request #30145 from 3405691582/OpenBSD_Port_Stdlib_Prelim
Preliminary support for OpenBSD in the stdlib.
2020-03-05 15:15:58 -08:00
Michael Ilseman
ebe8aac848 Merge pull request #30132 from valeriyvan/RemoveRedundantZeroingStringGraphemeBreaking
Removes redundant buffer zeroing in StringGraphemeBreaking.swift by using `init(unsafeUninitializedCapacity:initializingWith:)
2020-03-05 12:22:23 -08:00
Michael Ilseman
1255e10b62 [stdlib] [gardening] Remove whitespace, document growth issue 2020-03-05 12:16:26 -08:00
Alex Martini
011a115d85 Group operators explicitly.
The '+' operator binds tighter than the '...' operator.

Fixes rdar://problem/59833804
2020-03-05 11:18:03 -08:00
Alex Martini
bc5f0153fa Match docs to current behavior.
Confirmed this change on using the swift-5.2-DEVELOPMENT-SNAPSHOT-2020-01-22-a
toolchain, Apple Swift version 5.2-dev (Swift d3f0448a4c).

Fixes rdar://problem/58717942
2020-03-05 11:17:55 -08:00
Alex Martini
c0e2f08818 Add missing backtick.
Fixes rdar://problem/58855960
2020-03-05 11:17:50 -08:00
Ben Rimmington
b11856a93c [SE-0263] Update documentation
Co-Authored-By: Nate Cook <natecook@apple.com>
2020-03-05 14:51:48 +00:00
Ben Rimmington
cf8988455f [SE-0263] Rename internal API 2020-03-05 14:51:10 +00:00
Valeriy Van
190b8a73db Changes implementation of _persistCString from _StringGuts to be in sync with implementation from stdlib 2020-03-05 15:25:45 +01:00
Mike Ash
c1faaa5267 Merge pull request #30207 from mikeash/fix-objc-name-suffixes
[Runtime] Reject suffixes on ObjC mangled class names.
2020-03-04 17:05:16 -05:00
Michael Ilseman
7876eab91b Merge pull request #30131 from valeriyvan/RemoveRedundantZeroingStringGuts
Removes redundant buffer zeroing in StringGuts.swift by using `init(unsafeUninitializedCapacity:initializingWith:)
2020-03-04 11:04:08 -08:00
Kuba (Brecka) Mracek
0d400ca310 Merge branch 'master' into mracek/arm64e 2020-03-04 09:36:25 -08:00
Mike Ash
614f4becef [Runtime] Reject suffixes on ObjC mangled class names.
The demangler tolerates arbitrary suffixes on mangled names, and parses them as a Suffix node. When looking up a class by an ObjC mangled name, we don't want such demanglings to succeed, because this will result in false positives. It's expected that NSClassFromString(someClassName + "some suffix") will fail, unless something has actually created a class with that suffix.

rdar://problem/60012296
2020-03-04 12:05:35 -05:00
swift-ci
db10388b3c Merge pull request #30194 from xwu/floating-point-conversion-oops 2020-03-03 21:35:53 -08:00
3405691582
d69912761a Ensure consistency of ordering in preprocessor conditionals.
Co-Authored-By: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2020-03-03 20:24:06 -05:00
3405691582
c787d50984 Fix typo in SwiftPrivateThreadExtras.
Co-Authored-By: Sergej Jaskiewicz <broadwaylamb@users.noreply.github.com>
2020-03-03 20:24:06 -05:00
3405691582
73bd558925 [stdlib] Modulemap for libc on OpenBSD.
Provide a separate modulemap for OpenBSD's libc, rather than try to
continue to overload the modulemap for glibc, since glibc has its own
idiosyncracies.
2020-03-03 20:23:32 -05:00
Ben Rimmington
f5fe8e376d [stdlib] StaticString documentation and tests
Co-Authored-By: Nate Cook <natecook@apple.com>
2020-03-04 00:15:07 +00:00
Xiaodi Wu
03903ae1ea [stdlib] Fix generic floating-point conversion when two representable values are equally close 2020-03-03 18:22:47 -05:00
Kuba (Brecka) Mracek
5d918e5ee1 Merge branch 'master' into mracek/arm64e 2020-03-03 08:28:01 -08:00
David Smith
eb74e71903 Merge pull request #30106 from Catfish-Man/going-public
Make String(unsafeUninitializedCapacity:initializingUTF8With:) public
2020-03-02 18:08:37 -08:00
David Smith
b9ddaa6e90 Make String(unsafeUninitializedCapacity:,initializingUTF8With:) public 2020-03-02 14:25:14 -08:00
3405691582
5847726f51 Preliminary support for OpenBSD in the stdlib.
These should hopefully all be uncontroversial, minimal changes to deal
with progressing the build to completion on OpenBSD or addressing minor
portability issues. This is not the full set of changes to get a
successful build; other portability issues will be addressed in future
commits.

Most of this is just adding the relevant clauses to the ifdefs, but of
note in this commit:

* StdlibUnittest.swift: the default conditional in _getOSVersion assumes
  an Apple platform, therefore the explicit conditional and the relevant
  enums need filling out. The default conditional should be #error, but
  we'll fix this in a different commit.

* tgmath.swift.gyb: inexplicably, OpenBSD is missing just lgammal_r.
  Tests are updated correspondingly.

* ThreadLocalStorage.h: we use the pthread implementation, so it
  seems we should typedef __swift_thread_key_t as pthread_key_t.
  However, that's also a tweak for another commit.
2020-03-01 12:50:06 -05:00