@@ -23,6 +23,9 @@ sil public_external @printGenericTypeAndWord : $@convention(thin) <T> (@thick T.
23
23
protocol P {
24
24
static func static_member_fn()
25
25
}
26
+ protocol PA {
27
+ associatedtype A
28
+ }
26
29
27
30
struct A : P {
28
31
static func static_member_fn()
@@ -49,6 +52,13 @@ struct G : P {
49
52
struct GenFwdP<T : P> : P {
50
53
static func static_member_fn()
51
54
}
55
+ struct GenAssocPA<T> : PA {
56
+ typealias A = T
57
+ }
58
+
59
+ sil_witness_table <T : P> GenAssocPA<T>: PA module main {
60
+ associated_type A : T
61
+ }
52
62
53
63
sil private @A_static_member_fn : $@convention(witness_method: P) (@thick A.Type) -> () {
54
64
bb0(%0 : $@thick A.Type):
@@ -385,6 +395,143 @@ bb0(%argc : $Int32, %argv : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<
385
395
apply %wrap_in_GenFwdP<Pack{A, B, C, D, E, F}>(%5) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
386
396
387
397
398
+ /// Expect the following:
399
+ /// GenAssocPA<GenFwdP<INNER>> // from extract_associatedtype_with_conformance's call to printGenericType
400
+ /// GenFwdP<INNER> // from GenFwdP_static_member_fn's call to printGenericType
401
+ /// INNER // from INNER::static_member_fn's call to printGenericTypeAndWord
402
+ /// INNER.INDEX // from INNER::static_member_fn's call to printGenericTypeAndWord
403
+ %extract_associatedtype_with_conformance = function_ref @extract_associatedtype_with_conformance : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
404
+ // U_1 -> {A, B, C, D, E, F}
405
+ // --0---> ^
406
+ // CHECK: GenAssocPA<GenFwdP<A>>
407
+ // CHECK: GenFwdP<A>
408
+ // CHECK: A
409
+ // CHECK: 0
410
+ apply %extract_associatedtype_with_conformance<Pack{A, B, C, D, E, F}>(%0) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
411
+ // U_1 -> {A, B, C, D, E, F}
412
+ // ----1----> ^
413
+ // CHECK: GenAssocPA<GenFwdP<B>>
414
+ // CHECK: GenFwdP<B>
415
+ // CHECK: B
416
+ // CHECK: 1
417
+ apply %extract_associatedtype_with_conformance<Pack{A, B, C, D, E, F}>(%1) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
418
+ // U_1 -> {A, B, C, D, E, F}
419
+ // -----2------> ^
420
+ // CHECK: GenAssocPA<GenFwdP<C>>
421
+ // CHECK: GenFwdP<C>
422
+ // CHECK: C
423
+ // CHECK: 2
424
+ apply %extract_associatedtype_with_conformance<Pack{A, B, C, D, E, F}>(%2) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
425
+ // U_1 -> {A, B, C, D, E, F}
426
+ // -------3-------> ^
427
+ // CHECK: GenAssocPA<GenFwdP<D>>
428
+ // CHECK: GenFwdP<D>
429
+ // CHECK: D
430
+ // CHECK: 3
431
+ apply %extract_associatedtype_with_conformance<Pack{A, B, C, D, E, F}>(%3) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
432
+ // U_1 -> {A, B, C, D, E, F}
433
+ // --------4---------> ^
434
+ // CHECK: GenAssocPA<GenFwdP<E>>
435
+ // CHECK: GenFwdP<E>
436
+ // CHECK: E
437
+ // CHECK: 4
438
+ apply %extract_associatedtype_with_conformance<Pack{A, B, C, D, E, F}>(%4) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
439
+ // U_1 -> {A, B, C, D, E, F}
440
+ // ----------5----------> ^
441
+ // CHECK: GenAssocPA<GenFwdP<F>>
442
+ // CHECK: GenFwdP<F>
443
+ // CHECK: F
444
+ // CHECK: 5
445
+ apply %extract_associatedtype_with_conformance<Pack{A, B, C, D, E, F}>(%5) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
446
+
447
+
448
+ /// Expect the following:
449
+ /// GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<INNER>>>> // from extract_associatedtype_with_conformance2's call to printGenericType
450
+ /// GenFwdP<INNER> // from GenFwdP_static_member_fn's call to printGenericType
451
+ /// INNER // from INNER::static_member_fn's call to printGenericTypeAndWord
452
+ /// INNER.INDEX // from INNER::static_member_fn's call to printGenericTypeAndWord
453
+ /// It occurs for both U_1 and U_2.
454
+ %extract_associatedtype_with_conformance2 = function_ref @extract_associatedtype_with_conformance2 : $@convention(thin) <T_1... : P, Tee : P, T_2... : P where (repeat (each T_1, each T_2)) : Any> (Builtin.Word) -> ()
455
+ // U_1 -> {A, B, C, A, B, C}
456
+ // --0---> ^
457
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<A>>>>
458
+ // CHECK: GenFwdP<A>
459
+ // CHECK: A
460
+ // CHECK: 0
461
+ // U_2 -> {E, F, G, E, F, G}
462
+ // --0---> ^
463
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<E>>>>
464
+ // CHECK: GenFwdP<E>
465
+ // CHECK: E
466
+ // CHECK: 4
467
+ apply %extract_associatedtype_with_conformance2<Pack{A, B, C}, D, Pack{E, F, G}>(%0) : $@convention(thin) <T_1... : P, Tee : P, T_2... : P where (repeat (each T_1, each T_2)) : Any> (Builtin.Word) -> ()
468
+ // U_1 -> {A, B, C, A, B, C}
469
+ // ----1----> ^
470
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<B>>>>
471
+ // CHECK: GenFwdP<B>
472
+ // CHECK: B
473
+ // CHECK: 1
474
+ // U_2 -> {E, F, G, E, F, G}
475
+ // ----1----> ^
476
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<F>>>>
477
+ // CHECK: GenFwdP<F>
478
+ // CHECK: F
479
+ // CHECK: 5
480
+ apply %extract_associatedtype_with_conformance2<Pack{A, B, C}, D, Pack{E, F, G}>(%1) : $@convention(thin) <T_1... : P, Tee : P, T_2... : P where (repeat (each T_1, each T_2)) : Any> (Builtin.Word) -> ()
481
+ // U_1 -> {A, B, C, A, B, C}
482
+ // -----2------> ^
483
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<C>>>>
484
+ // CHECK: GenFwdP<C>
485
+ // CHECK: C
486
+ // CHECK: 2
487
+ // U_2 -> {E, F, G, E, F, G}
488
+ // -----2------> ^
489
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<G>>>>
490
+ // CHECK: GenFwdP<G>
491
+ // CHECK: G
492
+ // CHECK: 6
493
+ apply %extract_associatedtype_with_conformance2<Pack{A, B, C}, D, Pack{E, F, G}>(%2) : $@convention(thin) <T_1... : P, Tee : P, T_2... : P where (repeat (each T_1, each T_2)) : Any> (Builtin.Word) -> ()
494
+ // U_1 -> {A, B, C, A, B, C}
495
+ // -------3-------> ^
496
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<A>>>>
497
+ // CHECK: GenFwdP<A>
498
+ // CHECK: A
499
+ // CHECK: 0
500
+ // U_2 -> {E, F, G, E, F, G}
501
+ // -------3-------> ^
502
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<E>>>>
503
+ // CHECK: GenFwdP<E>
504
+ // CHECK: E
505
+ // CHECK: 4
506
+ apply %extract_associatedtype_with_conformance2<Pack{A, B, C}, D, Pack{E, F, G}>(%3) : $@convention(thin) <T_1... : P, Tee : P, T_2... : P where (repeat (each T_1, each T_2)) : Any> (Builtin.Word) -> ()
507
+ // U_1 -> {A, B, C, A, B, C}
508
+ // --------4---------> ^
509
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<B>>>>
510
+ // CHECK: GenFwdP<B>
511
+ // CHECK: B
512
+ // CHECK: 1
513
+ // U_2 -> {E, F, G, E, F, G}
514
+ // --------4---------> ^
515
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<F>>>>
516
+ // CHECK: GenFwdP<F>
517
+ // CHECK: F
518
+ // CHECK: 5
519
+ apply %extract_associatedtype_with_conformance2<Pack{A, B, C}, D, Pack{E, F, G}>(%4) : $@convention(thin) <T_1... : P, Tee : P, T_2... : P where (repeat (each T_1, each T_2)) : Any> (Builtin.Word) -> ()
520
+ // U_1 -> {A, B, C, A, B, C}
521
+ // ----------5----------> ^
522
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<C>>>>
523
+ // CHECK: GenFwdP<C>
524
+ // CHECK: C
525
+ // CHECK: 2
526
+ // U_2 -> {E, F, G, E, F, G}
527
+ // ----------5----------> ^
528
+ // CHECK: GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<G>>>>
529
+ // CHECK: GenFwdP<G>
530
+ // CHECK: G
531
+ // CHECK: 6
532
+ apply %extract_associatedtype_with_conformance2<Pack{A, B, C}, D, Pack{E, F, G}>(%5) : $@convention(thin) <T_1... : P, Tee : P, T_2... : P where (repeat (each T_1, each T_2)) : Any> (Builtin.Word) -> ()
533
+
534
+
388
535
%outb = integer_literal $Builtin.Int32, 0
389
536
%out = struct $Int32 (%outb : $Builtin.Int32)
390
537
return %out : $Int32
@@ -471,3 +618,54 @@ entry(%intIndex : $Builtin.Word):
471
618
%t = tuple ()
472
619
return %t : $()
473
620
}
621
+
622
+ sil @unwrap_from_PA : $<T_1... : PA where each T_1.A : P> (Builtin.Word) -> () {
623
+ entry(%intIndex : $Builtin.Word):
624
+ %direct_access_from_parameter_with_conformance = function_ref @direct_access_from_parameter_with_conformance : $@convention(thin) <T_1...: P> (Builtin.Word) -> ()
625
+ apply %direct_access_from_parameter_with_conformance<Pack{repeat GenFwdP<each T_1.A>}>(%intIndex) : $@convention(thin) <T_1...: P> (Builtin.Word) -> ()
626
+ %t = tuple ()
627
+ return %t : $()
628
+ }
629
+
630
+ sil @extract_associatedtype_with_conformance : $<T_1... : P> (Builtin.Word) -> () {
631
+ entry(%intIndex : $Builtin.Word):
632
+ %innerIndex = dynamic_pack_index %intIndex of $Pack{repeat each T_1}
633
+ %token = open_pack_element %innerIndex of <U_1... : PA where each U_1.A : P> at <Pack{repeat GenAssocPA<GenFwdP<each T_1>>}>, shape $U_1, uuid "01234567-89AB-CDEF-0123-000000000005"
634
+ %metatype_1 = metatype $@thick (@pack_element("01234567-89AB-CDEF-0123-000000000005") U_1).Type
635
+ %printGenericType = function_ref @printGenericType : $@convention(thin) <T> (@thick T.Type) -> ()
636
+ apply %printGenericType<(@pack_element("01234567-89AB-CDEF-0123-000000000005") U_1)>(%metatype_1) : $@convention(thin) <T> (@thick T.Type) -> ()
637
+ %static_member_fn = witness_method $(@pack_element("01234567-89AB-CDEF-0123-000000000005") U_1).A, #P.static_member_fn : <Self where Self : P> (Self.Type) -> () -> () : $@convention(witness_method: P) <T where T : P> (@thick T.Type) -> ()
638
+ %metatype_2 = metatype $@thick (@pack_element("01234567-89AB-CDEF-0123-000000000005") U_1).A.Type
639
+ apply %static_member_fn<(@pack_element("01234567-89AB-CDEF-0123-000000000005") U_1).A>(%metatype_2) : $@convention(witness_method: P) <T where T : P> (@thick T.Type) -> ()
640
+ %t = tuple ()
641
+ return %t : $()
642
+ }
643
+
644
+ // Nested associatedtypes.
645
+ sil @extract_associatedtype_with_conformance2 : $<T_1... : P, Tee : P, T_2... : P where (repeat (each T_1, each T_2)) : Any> (Builtin.Word) -> () {
646
+ entry(%intIndex : $Builtin.Word):
647
+ %innerIndex = dynamic_pack_index %intIndex of $Pack{repeat GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<each T_1>>>>, repeat GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<each T_1>>>>}
648
+ %token = open_pack_element %innerIndex
649
+ of <U_1... : PA, Ewe : PA, U_2... : PA where each U_1.A : PA, each U_1.A.A : PA, each U_1.A.A.A : P, Ewe.A : PA, Ewe.A.A : PA, Ewe.A.A.A : P, each U_2.A : PA, each U_2.A.A : PA, each U_2.A.A.A : P, (repeat (each U_1, each U_2)): Any>
650
+ at <
651
+ Pack{repeat GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<each T_1>>>>, repeat GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<each T_1>>>>},
652
+ GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<Tee>>>>,
653
+ Pack{repeat GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<each T_2>>>>, repeat GenAssocPA<GenAssocPA<GenAssocPA<GenFwdP<each T_2>>>>}>
654
+ , shape $U_1
655
+ , uuid "01234567-89AB-CDEF-0123-000000000004"
656
+ %metatype_1 = metatype $@thick (@pack_element("01234567-89AB-CDEF-0123-000000000004") U_1).Type
657
+ %printGenericType = function_ref @printGenericType : $@convention(thin) <T> (@thick T.Type) -> ()
658
+ apply %printGenericType<(@pack_element("01234567-89AB-CDEF-0123-000000000004") U_1)>(%metatype_1) : $@convention(thin) <T> (@thick T.Type) -> ()
659
+ %static_member_fn_1 = witness_method $(@pack_element("01234567-89AB-CDEF-0123-000000000004") U_1).A.A.A, #P.static_member_fn : <Self where Self : P> (Self.Type) -> () -> () : $@convention(witness_method: P) <T where T : P> (@thick T.Type) -> ()
660
+ %metatype_12 = metatype $@thick (@pack_element("01234567-89AB-CDEF-0123-000000000004") U_1).A.A.A.Type
661
+ apply %static_member_fn_1<(@pack_element("01234567-89AB-CDEF-0123-000000000004") U_1).A.A.A>(%metatype_12) : $@convention(witness_method: P) <T where T : P> (@thick T.Type) -> ()
662
+
663
+ %metatype_2 = metatype $@thick (@pack_element("01234567-89AB-CDEF-0123-000000000004") U_2).Type
664
+ apply %printGenericType<(@pack_element("01234567-89AB-CDEF-0123-000000000004") U_2)>(%metatype_2) : $@convention(thin) <T> (@thick T.Type) -> ()
665
+ %static_member_fn_2 = witness_method $(@pack_element("01234567-89AB-CDEF-0123-000000000004") U_2).A.A.A, #P.static_member_fn : <Self where Self : P> (Self.Type) -> () -> () : $@convention(witness_method: P) <T where T : P> (@thick T.Type) -> ()
666
+ %metatype_22 = metatype $@thick (@pack_element("01234567-89AB-CDEF-0123-000000000004") U_2).A.A.A.Type
667
+ apply %static_member_fn_2<(@pack_element("01234567-89AB-CDEF-0123-000000000004") U_2).A.A.A>(%metatype_22) : $@convention(witness_method: P) <T where T : P> (@thick T.Type) -> ()
668
+
669
+ %t = tuple ()
670
+ return %t : $()
671
+ }
0 commit comments