diff --git a/lib/Markup/Markup.cpp b/lib/Markup/Markup.cpp index 985e526116191..b49e2a5b98ad1 100644 --- a/lib/Markup/Markup.cpp +++ b/lib/Markup/Markup.cpp @@ -16,7 +16,6 @@ #include "swift/Markup/LineList.h" #include "swift/Markup/Markup.h" #include "cmark.h" -#include "node.h" using namespace llvm; using namespace markup; @@ -60,15 +59,7 @@ StringRef getLiteralContent(MarkupContext &MC, LineList &LL, cmark_node *Node) { // its parent. auto Literal = cmark_node_get_literal(Node); assert(Literal != nullptr); - size_t Length = 0; - switch (cmark_node_get_type(Node)) { - case CMARK_NODE_CODE_BLOCK: - Length = Node->as.code.literal.len; - break; - default: - Length = Node->as.literal.len; - } - return MC.allocateCopy(StringRef(Literal, Length)); + return MC.allocateCopy(StringRef(Literal)); } ParseResult diff --git a/stdlib/public/core/ArrayBuffer.swift b/stdlib/public/core/ArrayBuffer.swift index 1f7426cf1878e..9ad723f948180 100644 --- a/stdlib/public/core/ArrayBuffer.swift +++ b/stdlib/public/core/ArrayBuffer.swift @@ -244,32 +244,31 @@ extension _ArrayBuffer { return _native[subRange] } - // Look for contiguous storage in the NSArray let nonNative = self._nonNative let cocoa = _CocoaArrayWrapper(nonNative) - let cocoaStorageBaseAddress = cocoa.contiguousStorage(self.indices) - if cocoaStorageBaseAddress != nil { + // Look for contiguous storage in the NSArray + if let cocoaStorageBaseAddress = cocoa.contiguousStorage(self.indices) { return _SliceBuffer( owner: nonNative, subscriptBaseAddress: UnsafeMutablePointer(cocoaStorageBaseAddress), indices: subRange, hasNativeBuffer: false) + } else { + // No contiguous storage found; we must allocate + let subRangeCount = subRange.count + let result = _ContiguousArrayBuffer( + count: subRangeCount, minimumCapacity: 0) + + // Tell Cocoa to copy the objects into our storage + cocoa.buffer.getObjects( + UnsafeMutablePointer(result.firstElementAddress), + range: _SwiftNSRange( + location: subRange.startIndex, + length: subRangeCount)) + + return _SliceBuffer(result, shiftedToStartIndex: subRange.startIndex) } - - // No contiguous storage found; we must allocate - let subRangeCount = subRange.count - let result = _ContiguousArrayBuffer( - count: subRangeCount, minimumCapacity: 0) - - // Tell Cocoa to copy the objects into our storage - cocoa.buffer.getObjects( - UnsafeMutablePointer(result.firstElementAddress), - range: _SwiftNSRange( - location: subRange.startIndex, - length: subRangeCount)) - - return _SliceBuffer(result, shiftedToStartIndex: subRange.startIndex) } set { fatalError("not implemented") diff --git a/stdlib/public/core/Collection.swift b/stdlib/public/core/Collection.swift index ecee5d30fe368..6d342debdf1bd 100644 --- a/stdlib/public/core/Collection.swift +++ b/stdlib/public/core/Collection.swift @@ -584,19 +584,18 @@ extension SequenceType // A fast implementation for when you are backed by a contiguous array. public func _initializeTo(ptr: UnsafeMutablePointer) -> UnsafeMutablePointer { - let s = self._baseAddressIfContiguous - if s != nil { - let count = self.count - ptr.initializeFrom(s, count: count) - _fixLifetime(self._owner) - return ptr + count - } else { - var p = ptr - for x in self { - p++.initialize(x) + if let s = self._baseAddressIfContiguous { + let count = self.count + ptr.initializeFrom(s, count: count) + _fixLifetime(self._owner) + return ptr + count + } else { + var p = ptr + for x in self { + p++.initialize(x) + } + return p } - return p - } } } diff --git a/stdlib/public/core/Misc.swift b/stdlib/public/core/Misc.swift index 51ad4203b7064..6a2eb92828522 100644 --- a/stdlib/public/core/Misc.swift +++ b/stdlib/public/core/Misc.swift @@ -83,6 +83,30 @@ func _typeName(type: Any.Type, qualified: Bool = true) -> String { input: UnsafeBufferPointer(start: stringPtr, count: count)) } +@warn_unused_result +@_silgen_name("swift_stdlib_demangleName") +func _stdlib_demangleNameImpl( + mangledName: UnsafePointer, + _ mangledNameLength: UInt, + _ demangledName: UnsafeMutablePointer) + +// NB: This function is not used directly in the Swift codebase, but is +// exported for Xcode support. Please coordinate before changing. +@warn_unused_result +public // @testable +func _stdlib_demangleName(mangledName: String) -> String { + let mangledNameUTF8 = Array(mangledName.utf8) + return mangledNameUTF8.withUnsafeBufferPointer { + (mangledNameUTF8) in + let (_, demangledName) = _withUninitializedString { + _stdlib_demangleNameImpl( + mangledNameUTF8.baseAddress, UInt(mangledNameUTF8.endIndex), + $0) + } + return demangledName + } +} + /// Returns `floor(log(x))`. This equals to the position of the most /// significant non-zero bit, or 63 - number-of-zeros before it. /// diff --git a/stdlib/public/core/Runtime.swift.gyb b/stdlib/public/core/Runtime.swift.gyb index 8674560244cfa..89ac1d56a0d28 100644 --- a/stdlib/public/core/Runtime.swift.gyb +++ b/stdlib/public/core/Runtime.swift.gyb @@ -247,12 +247,11 @@ public // @testable func _stdlib_atomicLoadARCRef( object target: UnsafeMutablePointer ) -> AnyObject? { - let result = _swift_stdlib_atomicLoadPtrImpl( - object: UnsafeMutablePointer(target)) - if result != nil { - return Unmanaged.fromOpaque(result).takeUnretainedValue() + guard let result = _swift_stdlib_atomicLoadPtrImpl( + object: UnsafeMutablePointer(target)) { + return nil } - return nil + return Unmanaged.fromOpaque(result).takeUnretainedValue() } % for operation in [ 'Add', 'And', 'Or', 'Xor' ]: diff --git a/stdlib/public/runtime/Reflection.mm b/stdlib/public/runtime/Reflection.mm index 245a0938cf2f4..dcc722a6f4bb6 100644 --- a/stdlib/public/runtime/Reflection.mm +++ b/stdlib/public/runtime/Reflection.mm @@ -1264,3 +1264,17 @@ static Mirror ObjC_getMirrorForSuperclass(Class sup, T->vw_destroy(value); return MirrorReturn(result); } + +// NB: This function is not used directly in the Swift codebase, but is +// exported for Xcode support. Please coordinate before changing. +extern "C" void swift_stdlib_demangleName(const char *mangledName, + size_t mangledNameLength, + String *demangledName) { + auto options = Demangle::DemangleOptions(); + options.DisplayDebuggerGeneratedModule = false; + auto result = + Demangle::demangleSymbolAsString(mangledName, + mangledNameLength, + options); + new (demangledName) String(result.data(), result.size()); +} diff --git a/test/1_stdlib/Runtime.swift b/test/1_stdlib/Runtime.swift index 3c4dfd450ce8d..2c78916f78581 100644 --- a/test/1_stdlib/Runtime.swift +++ b/test/1_stdlib/Runtime.swift @@ -665,6 +665,16 @@ Runtime.test("typeName") { expectEqual("protocol<>.Protocol", _typeName(a.dynamicType)) } +Runtime.test("demangleName") { + expectEqual("", _stdlib_demangleName("")) + expectEqual("abc", _stdlib_demangleName("abc")) + expectEqual("\0", _stdlib_demangleName("\0")) + expectEqual("Swift.Double", _stdlib_demangleName("_TtSd")) + expectEqual("x.a : x.Foo, x.Foo>, x.Foo, x.Foo>>", + _stdlib_demangleName("_Tv1x1aGCS_3FooGS0_GS0_SiSi_GS0_SiSi__GS0_GS0_SiSi_GS0_SiSi___")) + expectEqual("Foobar", _stdlib_demangleName("_TtC13__lldb_expr_46Foobar")) +} + Runtime.test("_stdlib_atomicCompareExchangeStrongPtr") { typealias IntPtr = UnsafeMutablePointer var origP1 = IntPtr(bitPattern: 0x10101010) diff --git a/test/Driver/environment.swift b/test/Driver/environment.swift index 04938cf1a5226..b891e1a6a07da 100644 --- a/test/Driver/environment.swift +++ b/test/Driver/environment.swift @@ -1,4 +1,5 @@ // FIXME: This is failing on some of Apple's internal CI. +// FIXME: Fix test/Driver/{environment.swift,options-interpreter.swift} // REQUIRES: disabled // RUN: %swift_driver -target x86_64-apple-macosx10.9 -L/foo/ -driver-use-frontend-path %S/Inputs/print-var.sh %s DYLD_LIBRARY_PATH | FileCheck %s diff --git a/test/Driver/options-interpreter.swift b/test/Driver/options-interpreter.swift index 690c7e8f3cde6..d7cd351b40b50 100644 --- a/test/Driver/options-interpreter.swift +++ b/test/Driver/options-interpreter.swift @@ -1,4 +1,5 @@ // FIXME: This is failing on some of Apple's internal CI. +// FIXME: Fix test/Driver/{environment.swift,options-interpreter.swift} // REQUIRES: disabled // RUN: not %swift_driver -deprecated-integrated-repl -emit-module 2>&1 | FileCheck -check-prefix=IMMEDIATE_NO_MODULE %s