File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
SwiftCompilerSources/Sources/SIL Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,29 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
154
154
return idx >= 0 ? idx : nil
155
155
}
156
156
157
+ /// Returns true if this is a struct, enum or tuple and `otherType` is contained in this type - or is the same type.
158
+ public func aggregateIsOrContains( _ otherType: Type , in function: Function ) -> Bool {
159
+ if self == otherType {
160
+ return true
161
+ }
162
+ if isStruct {
163
+ guard let fields = getNominalFields ( in: function) else {
164
+ return true
165
+ }
166
+ return fields. contains { $0. aggregateIsOrContains ( otherType, in: function) }
167
+ }
168
+ if isTuple {
169
+ return tupleElements. contains { $0. aggregateIsOrContains ( otherType, in: function) }
170
+ }
171
+ if isEnum {
172
+ guard let cases = getEnumCases ( in: function) else {
173
+ return true
174
+ }
175
+ return cases. contains { $0. payload? . aggregateIsOrContains ( otherType, in: function) ?? false }
176
+ }
177
+ return false
178
+ }
179
+
157
180
// compiling bridged.getFunctionTypeWithNoEscape crashes the 5.10 Windows compiler
158
181
#if !os(Windows)
159
182
// TODO: https://github.com/apple/swift/issues/73253
You can’t perform that action at this time.
0 commit comments