Commit Graph

13406 Commits

Author SHA1 Message Date
Michael Ilseman
5ba5be3f43 [String] Speed up UTF-8 initialization from non-stdlib types
Avoid generic code paths if initializing for UTF-8 (the vast majority
of the time) from a non-stdlib type (such as Data).
2019-02-13 20:12:39 -08:00
Slava Pestov
2c015164cf Stop passing NodePointer by reference 2019-02-13 21:51:28 -05:00
Michael Ilseman
415cc8fb0c [String.Index] Deprecate encodedOffset var/init
String.Index has an encodedOffset-based initializer and computed
property that exists for serialization purposes. It was documented as
UTF-16 in the SE proposal introducing it, which was String's
underlying encoding at the time, but the dream of String even then was
to abstract away whatever encoding happend to be used.

Serialization needs an explicit encoding for serialized indices to
make sense: the offsets need to align with the view. With String
utilizing UTF-8 encoding for native contents in Swift 5, serialization
isn't necessarily the most efficient in UTF-16.

Furthermore, the majority of usage of encodedOffset in the wild is
buggy and operates under the assumption that a UTF-16 code unit was a
Swift Character, which isn't even valid if the String is known to be
all-ASCII (because CR-LF).

This change introduces a pair of semantics-preserving alternatives to
encodedOffset that explicitly call out the UTF-16 assumption. These
serve as a gentle off-ramp for current mis-uses of encodedOffset.
2019-02-13 18:42:40 -08:00
Konrad `ktoso` Malawski
f2baa7aa73 [docs][SR-9915] Compilation fix of docs snippet of type(of:)
Compilation of code sample snippets was broken due to using the same
identifier as the `type` function itself to store its result resulting
in:

```swift
func printGenericInfo<T>(_ value: T) {
    let type = type(of: value)
    print("'\(value)' of type '\(type)'")
}

// error: repl.swift:2:16: error: variable used within its own initial
// value
//    let type = type(of: value)
//               ^
```

Result:

- Snippets are more copy&paste friendly.
- Resolves https://bugs.swift.org/browse/SR-9915
2019-02-14 11:29:06 +09:00
Slava Pestov
d0c7b1547e ASTMangler: Mangle sugared types for the debugger
Fixes <rdar://problem/48004306>.
2019-02-13 19:17:25 -05:00
Saleem Abdulrasool
b2e8090feb Merge pull request #22586 from compnerd/point-me-to-a-fix
SwiftPrivateThreadExtras: fix casting due to API changes
2019-02-13 14:51:03 -08:00
Philippe Hausler
1fe1b86556 Add a safe API for NSValue and migrate NSValue value fetching to the size variants for validation (#22265) 2019-02-13 14:14:41 -08:00
Saleem Abdulrasool
59371dba24 SwiftPrivateThreadExtras: fix casting due to API changes
The recent changes to the UnsafemutablePointer prevented the "abuse" of
the type for casting.  Switch to `unsafeBitCast`.  This should repair
the Windows build.
2019-02-13 08:13:47 -08:00
swift-ci
e83974d4f6 Merge pull request #22581 from compnerd/sockets 2019-02-12 23:59:27 -08:00
Saleem Abdulrasool
cde0c32919 Windows: add some WinSock2 constants
This is the bare minimum of the WinSock2 constants that are needed for
the Foundation port to Windows which uses the socket APIs for
`-[NSTask run]` internal signalling.
2019-02-12 23:01:18 -08:00
swift-ci
aead660d91 Merge pull request #22147 from ravikandhadai/consteval-string-append 2019-02-12 16:11:41 -08:00
Andrew Trick
c90838a055 Merge pull request #22541 from atrick/speedup-array-init
Fix performance of array initialization from a generic sequence.
2019-02-12 12:45:30 -08:00
Ben Cohen
f15892c1a8 Merge pull request #22288 from airspeedswift/safe-conversion
[stdlib] Remove overly-permissive UnsafePointer init
2019-02-12 11:47:06 -08:00
swift-ci
498b72270b Merge pull request #22527 from Catfish-Man/literally-empty 2019-02-11 22:35:33 -08:00
Andrew Trick
638c3ea21c Merge pull request #22521 from atrick/fix-nil-buffer
Fix crashes in Unsafe[Raw]BufferPointer with nil baseAddress.
2019-02-11 22:00:43 -08:00
Andrew Trick
6d3397337d Fix performance of array initialization from a generic sequence.
This fixes a major perform bug involving array initialization from any
contiguously stored collection.	 This is not a recent regression. This fix
results in a 10,000X speedup (that's 4 zeros) for this code path:

func initializeFromSlice(_ a: [Int]) -> [Int] {
  return Array<Int>(a[...])
}

A benchmark is included.
2019-02-11 19:41:45 -08:00
Slava Pestov
c8effd26b3 Merge pull request #22408 from slavapestov/always-use-legacy-layouts
Always use legacy layouts
2019-02-11 19:10:02 -05:00
David Smith
bf32e78737 Make bridged empty NSDictionary and NSSet instances bridge to the empty singletons 2019-02-11 15:54:19 -08:00
David Smith
bf09c28b39 Make empty set literals use the singleton 2019-02-11 15:45:16 -08:00
David Smith
2a9aa16b3f Make empty dictionary literals use the singleton 2019-02-11 15:38:22 -08:00
Andrew Trick
28a529ceed Fix crashes in Unsafe[Raw]BufferPointer with nil baseAddress.
This fix updates various initializers to handle incoming empty buffers
that happen to have a nil base. They should simply create another
buffer with nil base rather than crashing!

It is valid for an Unsafe[Raw]BufferPointer can have a nil base
address. This allows round-tripping with C code that takes a
pointer/length pair and uses `0` as the pointer value.

The original design wrongly assumed that we would use a sentinel value
for empty buffers and was never updated for or tested with the current
design.

Fixes <rdar://problem/47946984> Regression in Foundation.Data's
UnsafeBufferPointer constructor.
2019-02-11 13:38:48 -08:00
Ben Cohen
0f339d3663 Merge branch 'master' into safe-conversion 2019-02-11 12:58:51 -08:00
Maxim Moiseev
d904d25fef Accelerate overlay does not seem to need -parse-stdlib 2019-02-11 10:50:16 -08:00
Nathan Lanza
4627ee72cc Fix swiftSwiftOnoneSupport.lib not being generated on windows debugbuilds 2019-02-08 17:54:21 -08:00
Slava Pestov
9f80a9cff0 Copy legacy layouts to stdlib build directory
This adds a new copy-legacy-layouts-${platform}-${arch} target for each
platform and architecture that the standard library is built for.

If the platform and architecture has a corresponding layout file in
stdlib/public/legacy_layouts/${platform}/layouts-${arch}.yaml, the
target copies this file to the build directory; otherwise, it does
nothing.

When building Swift code, the subroutines in SwiftSource.cmake add a
dependency on this target from each Swift code target.

Finally, we ensure that the YAML files are copied into the toolchain
package when building a toolchain.
2019-02-08 14:22:00 -05:00
Max Moiseev
093d48358d Merge pull request #22464 from moiseev/os-log-buffer-fix
[overlay] Size the os_log pack buffer appropriately
2019-02-08 10:11:40 -08:00
Saleem Abdulrasool
24dab81381 Merge pull request #22428 from drodriguez/fix-android-host-compiler-usage
[cmake] Recover original CMAKE_C/CXX_COMPILER after changing them.
2019-02-07 17:38:40 -08:00
Michael Ilseman
8dcfac6e87 Merge pull request #22168 from benrimmington/sr-6127
[stdlib] Fix memory leaks in readLine()
2019-02-07 14:25:22 -08:00
Maxim Moiseev
caac1bf850 [overlay] Size the os_log pack buffer appropriately
Fixes: rdar://problem/31799909
2019-02-07 14:19:07 -08:00
Michael Ilseman
9bc5bd26e4 Merge pull request #22417 from milseman/null_and_void
[String] Fix crash when given null UBP
2019-02-07 10:46:01 -08:00
John McCall
f143db7942 Merge pull request #22409 from rjmccall/init-class-metadata-dependencies-compiler
Fix a race condition with the initialization of class metadata
2019-02-07 12:59:39 -05:00
swift-ci
998d9c4b1e Merge pull request #22430 from milseman/whoops 2019-02-06 18:06:26 -08:00
Andrew Trick
fa952d3986 Merge pull request #22338 from atrick/speedup-ubp-subscript
Remove useless optional unwrap from Unsafe[Raw]BufferPointer subscript.
2019-02-06 15:29:00 -08:00
Michael Ilseman
a742a62c18 [String] Use the new value in utf8 setter.
ð
2019-02-06 15:11:17 -08:00
Michael Ilseman
877a20ead0 [String] Fix crash when given null UBP 2019-02-06 14:44:01 -08:00
Daniel Rodríguez Troitiño
fe82b3e012 [cmake] Recover original CMAKE_C/CXX_COMPILER after changing them.
Seems that the change in the two variables was spilling into the other
target of the file, but returning it back to the original values seems
to avoid that issue.

This should unbreak the Android CI build. In it, the Linux static
library was changing to the host compiler, and that compiler was being
used for the Android runtime library, which would have never compile
that way (since the host compiler in CI is an old-ish Clang without the
necessary argument).
2019-02-06 14:43:48 -08:00
John McCall
79d15816c4 Fix a race condition with the initialization of class metadata.
In our initial approach for resolving metadata dependency cycles with classes, non-transitively complete superclass metadata was fetched by the subclass's metadata completion function and passed to `swift_initClassMetadata`. That could mean generating quite a lot of code in the completion function, and so we fairly recently changed it so that `swift_initClassMetadata` instead fetched the superclass metadata via a demangling. Unfortunately, the metadata demangler only fetches _abstract_ metadata by default, and class metadata cannot be considered even non-transitively complete when its superclass reference not at that stage.  If the superclass metadata is being completed on one thread, and a subclass is being completed on another, and the subclass installs the incomplete superclass metadata in its superclass field and attempts to register the subclass with the Objective-C runtime, the runtime may crash reading the incompletely-initialized superclass.

The proper fix is to make `swift_initClassMetadata` fetch non-transitively complete metadata for the superclass, delaying completion if that metadata is unavailable. Unfortunately, that can't actually be implemented on top of `swift_initClassMetadata` because that function has no means of reporting an unsatisfied dependency to its caller, and we can no longer simply change its signature without worrying about a small of internal code that might still be using it. We cannot simply perform a blocking metadata request in `swift_initClassMetadata` because it is deeply problematic to block within a metadata completion function. The solution is therefore to add a `swift_initClassMetadata2` which has the ability to report unsatisfied dependencies. That was done in #22386; this patch builds on that by teaching the compiler to generate code to actually use it. It is therefore not safe to use this patch if you might be running on an OS that only provides the old runtime function, but that should be a temporary Apple-internal problem.

Fixes rdar://47549859.
2019-02-05 23:28:57 -05:00
John McCall
3d50622223 Fix a bug with demangling reference storage that I just introduced.
Somehow this only broke tests on the 5.0 branch.
2019-02-05 23:26:33 -05:00
John McCall
2e252e174e Merge pull request #22386 from rjmccall/init-class-metadata-depedencies-runtime
Add new runtime functions for handling dependencies when initializing class metadata
2019-02-05 19:08:01 -05:00
Scott Perry
45522918ec Header docs for internal methods validateChanges(_:) and init(validatedChanges:) 2019-02-05 14:34:27 -08:00
Michael Gottesman
0cd01eb9e1 Merge pull request #22385 from gottesmm/pr-af26f08a0904c49030b0c365d8e3e69d15e79833
[cmake] Rather than using CMAKE_{C,CXX}_COMPILER and CMAKE_{C,CXX}_CO…
2019-02-05 14:28:08 -08:00
John McCall
a074bc2ed4 Add new APIs for init/updateClassMetadata that can report dependencies. 2019-02-05 16:44:56 -05:00
Michael Ilseman
d376a0f9c9 Merge pull request #21077 from linux-on-ibm-z/s390x-smallstring-v2
[string] Fix string implementation for big endian platforms
2019-02-05 13:36:05 -08:00
Michael Gottesman
f13b8eb10b [cmake] Rather than using CMAKE_{C,CXX}_COMPILER and CMAKE_{C,CXX}_COMPILER_ARG1 for distcc, use CMAKE_{C,CXX}_COMPILER_LAUNCHER.
This is a cleaner, more principled way of adding "compiler launcher" support and
ensures that cmake understands that distcc is not the "actual" compiler.

This ensures that when we compile SwiftRemoteMirrors for the host, we do not try
to compile using distcc without needing to reset CMAKE_{C,CXX}_COMPILER_ARG1
(which is unset when compiling things in the stdlib).
2019-02-05 13:22:53 -08:00
John McCall
d07efd37e0 Requestify the mangling-to-metadata APIs.
Note that I've called out a couple of suspicious places where we
are requesting abstract metadata for superclasses but probably
need to be requesting something more complete.
2019-02-05 16:20:48 -05:00
John McCall
de4564877a Separate CC attrs in the compatibility-override macro; NFC. 2019-02-05 16:20:48 -05:00
Ben Rimmington
7c65c14df7 [stdlib] Fix memory leaks in readLine()
<https://bugs.swift.org/browse/SR-6127>
2019-02-05 03:43:00 +00:00
swift-ci
0007eafb49 Merge pull request #22255 from compnerd/where-are-thou-implib 2019-02-04 19:14:05 -08:00
Scott Perry
b7f36c3399 Include renamed CollectionDifference.swift 2019-02-04 15:37:22 -08:00
Saleem Abdulrasool
0a1abdccfc build: attempt to repair Windows debug builds
The debug build of the standard library on Windows does not generate the
import library for SwiftOnoneSupport which prevents the build of debug
programs against the debug runtime.  Because the linker must find the
import library in order to satisfy the forced link that we emit for the
link against the SwiftOnoneSupport library, without this, the build is
not usable.  Furthermore, this requires a debug build of the runtime
since in the optimized build, the interfaces that this library provides
are not provided by swiftCore and this supplements the library to allow
building the debug program.
2019-02-04 15:13:46 -08:00