Skip to content

Commit 5d7ae16

Browse files
committed
Test case for previous 3 fixes
rdar://50592605 rdar://50591831 rdar://50589978
1 parent 248de97 commit 5d7ae16

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/SILOptimizer/specialize_opaque_type_archetypes.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,64 @@ extension PA {
476476
useP(p.1(5))
477477
}
478478
}
479+
480+
public struct Foo {
481+
var id : Int = 0
482+
var p : Int64 = 1
483+
}
484+
485+
struct Test : RandomAccessCollection {
486+
struct Index : Comparable, Hashable {
487+
var identifier: AnyHashable?
488+
var offset: Int
489+
490+
static func < (lhs: Index, rhs: Index) -> Bool {
491+
return lhs.offset < rhs.offset
492+
}
493+
494+
func hash(into hasher: inout Hasher) {
495+
hasher.combine(identifier)
496+
hasher.combine(offset)
497+
}
498+
}
499+
500+
let foos: [Foo]
501+
let ids: [AnyHashable]
502+
503+
init(foos: [Foo]) {
504+
self.foos = foos
505+
self.ids = foos.map { $0.id }
506+
}
507+
508+
func _index(atOffset n: Int) -> Index {
509+
return Index(identifier: ids.isEmpty ? nil : ids[n], offset: n)
510+
}
511+
512+
var startIndex: Index {
513+
return _index(atOffset: 0)
514+
}
515+
516+
var endIndex: Index {
517+
return Index(identifier: nil, offset: ids.endIndex)
518+
}
519+
520+
func index(after i: Index) -> Index {
521+
return _index(atOffset: i.offset + 1)
522+
}
523+
524+
func index(before i: Index) -> Index {
525+
return _index(atOffset: i.offset - 1)
526+
}
527+
528+
func distance(from start: Index, to end: Index) -> Int {
529+
return end.offset - start.offset
530+
}
531+
532+
func index(_ i: Index, offsetBy n: Int) -> Index {
533+
return _index(atOffset: i.offset + n)
534+
}
535+
536+
subscript(i: Index) -> some P {
537+
return foos[i.offset].p
538+
}
539+
}

0 commit comments

Comments
 (0)