Skip to content

Commit e3e4b40

Browse files
committed
moved get mangled name to CRuntime
1 parent 464e60a commit e3e4b40

File tree

7 files changed

+1284
-855
lines changed

7 files changed

+1284
-855
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// swift-tools-version:4.2
1+
// swift-tools-version:5.0
22
import PackageDescription
33
let package = Package(
44
name: "Runtime",
55
products: [
66
.library(
77
name: "Runtime",
8-
targets: ["Runtime"])
8+
targets: ["Runtime"])
99
],
1010
dependencies: [
11-
.package(url: "https://github.com/wickwirew/CRuntime.git", from: "1.0.0")
11+
.package(url: "https://github.com/wickwirew/CRuntime.git", from: "2.0.1")
1212
],
1313
targets: [
1414
.target(
@@ -18,5 +18,5 @@ let package = Package(
1818
name: "RuntimeTests",
1919
dependencies: ["Runtime"])
2020
],
21-
swiftLanguageVersions: [.v4_2]
21+
swiftLanguageVersions: [.v5]
2222
)

Runtime.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Pod::Spec.new do |s|
33
s.name = "Runtime"
4-
s.version = "0.7.1"
4+
s.version = "2.0.0"
55
s.summary = "Runtime"
66
s.description = <<-DESC
77
Runtime abilities for native swift objects.
@@ -10,6 +10,6 @@ Pod::Spec.new do |s|
1010
s.license = "MIT"
1111
s.author = { "Wesley Wickwire" => "[email protected]" }
1212
s.platform = :ios, "9.0"
13-
s.source = { :git => "https://github.com/wickwirew/Runtime.git", :tag => "0.7.1" }
13+
s.source = { :git => "https://github.com/wickwirew/Runtime.git", :tag => s.version }
1414
s.source_files = 'Runtime/**/*.swift'
1515
end

Runtime.xcodeproj/project.pbxproj

Lines changed: 1261 additions & 807 deletions
Large diffs are not rendered by default.

Sources/Runtime/Layouts/FieldDescriptor.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23+
import CRuntime
24+
2325
/// https://github.com/apple/swift/blob/f2c42509628bed66bf5b8ee02fae778a2ba747a1/include/swift/Reflection/Records.h#L160
2426
struct FieldDescriptor {
2527

@@ -38,7 +40,7 @@ struct FieldDescriptor {
3840
struct FieldRecord {
3941

4042
var fieldRecordFlags: Int32
41-
var _mangledTypeName: RelativePointer<Int32, UInt8>
43+
var _mangledTypeName: RelativePointer<Int32, Int8>
4244
var _fieldName: RelativePointer<Int32, UInt8>
4345

4446
var isVar: Bool {
@@ -56,15 +58,17 @@ struct FieldRecord {
5658
mutating func type(genericContext: UnsafeRawPointer?,
5759
genericArguments: UnsafeRawPointer?) -> Any.Type {
5860
let typeName = _mangledTypeName.advanced()
59-
return _getTypeByMangledNameInContext(
61+
let metadataPtr = swift_getTypeByMangledNameInContext(
6062
typeName,
6163
getSymbolicMangledNameLength(typeName),
62-
genericContext: genericContext,
63-
genericArguments: genericArguments
64+
genericContext,
65+
genericArguments?.assumingMemoryBound(to: Optional<UnsafeRawPointer>.self)
6466
)!
67+
68+
return unsafeBitCast(metadataPtr, to: Any.Type.self)
6569
}
6670

67-
func getSymbolicMangledNameLength(_ base: UnsafeRawPointer) -> Int {
71+
func getSymbolicMangledNameLength(_ base: UnsafeRawPointer) -> Int32 {
6872
var end = base
6973
while let current = Optional(end.load(as: UInt8.self)), current != 0 {
7074
end += 1
@@ -75,7 +79,7 @@ struct FieldRecord {
7579
}
7680
}
7781

78-
return end - base
82+
return Int32(end - base)
7983
}
8084
}
8185

Sources/Runtime/Utilities/GetFieldAt.swift

Lines changed: 0 additions & 32 deletions
This file was deleted.

Tests/RuntimeTests/MetadataTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ class MetadataTests: XCTestCase {
6060

6161
func testGenericStruct() {
6262
struct A<B, C, D, E, F, G, H> { let b: B }
63-
var md = StructMetadata(type: A<Int, Int, Int, Int, Int, Int, Int>.self)
63+
var md = StructMetadata(type: A<Int, String, Bool, Int, Int, Int, Int>.self)
6464
var args = md.genericArguments()
6565
let props = md.properties()
6666
XCTAssert(args.count == 7)
67-
XCTAssert(args[1] == Int.self)
67+
XCTAssert(args[0] == Int.self)
68+
XCTAssert(args[1] == String.self)
69+
XCTAssert(args[2] == Bool.self)
70+
XCTAssert(args[3] == Int.self)
6871
XCTAssert(props.count == 1)
6972
XCTAssert(props[0].type == Int.self)
7073
}

0 commit comments

Comments
 (0)