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 {
154154 return idx >= 0 ? idx : nil
155155 }
156156
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+
157180// compiling bridged.getFunctionTypeWithNoEscape crashes the 5.10 Windows compiler
158181#if !os(Windows)
159182 // TODO: https://github.com/apple/swift/issues/73253
You can’t perform that action at this time.
0 commit comments