forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resilient_struct.swift
79 lines (64 loc) · 1.5 KB
/
resilient_struct.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Fixed-layout struct
@_fixed_layout public struct Point {
public var x: Int // read-write stored property
public let y: Int // read-only stored property
public init(x: Int, y: Int) {
self.x = x
self.y = y
}
public func method() {}
public mutating func mutantMethod() {}
}
// Resilient-layout struct
public struct Size {
public var w: Int // should have getter and setter
public let h: Int // getter only
public init(w: Int, h: Int) {
self.w = w
self.h = h
}
public func method() {}
public mutating func mutantMethod() {}
}
// Fixed-layout struct with resilient members
@_fixed_layout public struct Rectangle {
public let p: Point
public let s: Size
public let color: Int
public init(p: Point, s: Size, color: Int) {
self.p = p
self.s = s
self.color = color
}
}
// More complicated resilient structs for runtime tests
public struct ResilientBool {
public let b: Bool
public init(b: Bool) {
self.b = b
}
}
public struct ResilientInt {
public let i: Int
public init(i: Int) {
self.i = i
}
}
public struct ResilientDouble {
public let d: Double
public init(d: Double) {
self.d = d
}
}
@_fixed_layout public struct ResilientLayoutRuntimeTest {
public let b1: ResilientBool
public let i: ResilientInt
public let b2: ResilientBool
public let d: ResilientDouble
public init(b1: ResilientBool, i: ResilientInt, b2: ResilientBool, d: ResilientDouble) {
self.b1 = b1
self.i = i
self.b2 = b2
self.d = d
}
}