File: resilient_struct.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (123 lines) | stat: -rw-r--r-- 2,204 bytes parent folder | download
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Fixed-layout struct
@frozen 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
@frozen 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
  }
}

@frozen 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
  }
}

public class Referent {
  public init() {}
}

public struct ResilientWeakRef {
  public weak var ref: Referent?

  public init (_ r: Referent) {
    ref = r
  }
}

public struct ResilientRef {
  public var r: Referent

  public init(r: Referent) { self.r = r }
}

public struct ResilientWithInternalField {
  var x: Int
}

// Tuple parameters with resilient structs
public class Subject {}

public struct Container {
  public var s: Subject
}

public struct PairContainer {
  public var pair : (Container, Container)
}

@available(*, unavailable)
public struct UnavailableResilientInt {
  public let i: Int

  public init(i: Int) {
    self.i = i
  }
}

public struct ResilientEmptyStruct {}