Skip to content

Commit aab138d

Browse files
committed
Barebone implementation of TupleElement in SIL
1 parent 834ef2c commit aab138d

File tree

8 files changed

+54
-1
lines changed

8 files changed

+54
-1
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,7 @@ class KeyPathPatternComponent {
24002400
OptionalChain,
24012401
OptionalForce,
24022402
OptionalWrap,
2403+
TupleElement,
24032404
};
24042405

24052406
// Description of a captured index value and its Hashable conformance for a
@@ -2423,6 +2424,7 @@ class KeyPathPatternComponent {
24232424
static unsigned getPackedKind(Kind k) {
24242425
switch (k) {
24252426
case Kind::StoredProperty:
2427+
case Kind::TupleElement:
24262428
return PackedStored;
24272429
case Kind::GettableProperty:
24282430
case Kind::SettableProperty:
@@ -2518,6 +2520,7 @@ class KeyPathPatternComponent {
25182520
case Kind::OptionalChain:
25192521
case Kind::OptionalForce:
25202522
case Kind::OptionalWrap:
2523+
case Kind::TupleElement:
25212524
llvm_unreachable("not a stored property");
25222525
}
25232526
llvm_unreachable("unhandled kind");
@@ -2529,6 +2532,7 @@ class KeyPathPatternComponent {
25292532
case Kind::OptionalChain:
25302533
case Kind::OptionalForce:
25312534
case Kind::OptionalWrap:
2535+
case Kind::TupleElement:
25322536
llvm_unreachable("not a computed property");
25332537
case Kind::GettableProperty:
25342538
case Kind::SettableProperty:
@@ -2544,6 +2548,7 @@ class KeyPathPatternComponent {
25442548
case Kind::OptionalChain:
25452549
case Kind::OptionalForce:
25462550
case Kind::OptionalWrap:
2551+
case Kind::TupleElement:
25472552
llvm_unreachable("not a computed property");
25482553
case Kind::GettableProperty:
25492554
case Kind::SettableProperty:
@@ -2559,6 +2564,7 @@ class KeyPathPatternComponent {
25592564
case Kind::OptionalChain:
25602565
case Kind::OptionalForce:
25612566
case Kind::OptionalWrap:
2567+
case Kind::TupleElement:
25622568
llvm_unreachable("not a settable computed property");
25632569
case Kind::SettableProperty:
25642570
return SetterAndIdKind.getPointer();
@@ -2572,6 +2578,7 @@ class KeyPathPatternComponent {
25722578
case Kind::OptionalChain:
25732579
case Kind::OptionalForce:
25742580
case Kind::OptionalWrap:
2581+
case Kind::TupleElement:
25752582
return {};
25762583
case Kind::GettableProperty:
25772584
case Kind::SettableProperty:
@@ -2586,6 +2593,7 @@ class KeyPathPatternComponent {
25862593
case Kind::OptionalChain:
25872594
case Kind::OptionalForce:
25882595
case Kind::OptionalWrap:
2596+
case Kind::TupleElement:
25892597
llvm_unreachable("not a computed property");
25902598
case Kind::GettableProperty:
25912599
case Kind::SettableProperty:
@@ -2599,6 +2607,7 @@ class KeyPathPatternComponent {
25992607
case Kind::OptionalChain:
26002608
case Kind::OptionalForce:
26012609
case Kind::OptionalWrap:
2610+
case Kind::TupleElement:
26022611
llvm_unreachable("not a computed property");
26032612
case Kind::GettableProperty:
26042613
case Kind::SettableProperty:
@@ -2620,6 +2629,7 @@ class KeyPathPatternComponent {
26202629
case Kind::OptionalChain:
26212630
case Kind::OptionalForce:
26222631
case Kind::OptionalWrap:
2632+
case Kind::TupleElement:
26232633
llvm_unreachable("not a computed property");
26242634
case Kind::GettableProperty:
26252635
case Kind::SettableProperty:
@@ -2634,13 +2644,29 @@ class KeyPathPatternComponent {
26342644
case Kind::OptionalChain:
26352645
case Kind::OptionalForce:
26362646
case Kind::OptionalWrap:
2647+
case Kind::TupleElement:
26372648
llvm_unreachable("not a computed property");
26382649
case Kind::GettableProperty:
26392650
case Kind::SettableProperty:
26402651
return ExternalSubstitutions;
26412652
}
26422653
llvm_unreachable("unhandled kind");
26432654
}
2655+
2656+
unsigned getTupleIndex() const {
2657+
switch (getKind()) {
2658+
case Kind::StoredProperty:
2659+
case Kind::OptionalChain:
2660+
case Kind::OptionalForce:
2661+
case Kind::OptionalWrap:
2662+
case Kind::GettableProperty:
2663+
case Kind::SettableProperty:
2664+
llvm_unreachable("not a tuple element");
2665+
case Kind::TupleElement:
2666+
llvm_unreachable("[technicated]");
2667+
}
2668+
llvm_unreachable("unhandled kind");
2669+
}
26442670

26452671
static KeyPathPatternComponent
26462672
forComputedGettableProperty(ComputedPropertyId identifier,
@@ -2688,6 +2714,7 @@ class KeyPathPatternComponent {
26882714
case Kind::StoredProperty:
26892715
case Kind::GettableProperty:
26902716
case Kind::SettableProperty:
2717+
case Kind::TupleElement:
26912718
llvm_unreachable("not an optional kind");
26922719
}
26932720
return KeyPathPatternComponent(kind, ty);

lib/IRGen/GenKeyPath.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,9 @@ emitKeyPathComponent(IRGenModule &IGM,
11051105
case KeyPathPatternComponent::Kind::OptionalWrap:
11061106
fields.addInt32(KeyPathComponentHeader::forOptionalWrap().getData());
11071107
break;
1108+
case KeyPathPatternComponent::Kind::TupleElement:
1109+
llvm_unreachable("[technicated]");
1110+
break;
11081111
}
11091112
}
11101113

@@ -1198,6 +1201,7 @@ IRGenModule::getAddrOfKeyPathPattern(KeyPathPattern *pattern,
11981201
case KeyPathPatternComponent::Kind::OptionalChain:
11991202
case KeyPathPatternComponent::Kind::OptionalForce:
12001203
case KeyPathPatternComponent::Kind::OptionalWrap:
1204+
case KeyPathPatternComponent::Kind::TupleElement:
12011205
break;
12021206
}
12031207
}

lib/SIL/SILInstructions.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,7 @@ bool KeyPathPatternComponent::isComputedSettablePropertyMutating() const {
20312031
case Kind::OptionalChain:
20322032
case Kind::OptionalWrap:
20332033
case Kind::OptionalForce:
2034+
case Kind::TupleElement:
20342035
llvm_unreachable("not a settable computed property");
20352036
case Kind::SettableProperty: {
20362037
auto setter = getComputedPropertySetter();
@@ -2049,6 +2050,7 @@ forEachRefcountableReference(const KeyPathPatternComponent &component,
20492050
case KeyPathPatternComponent::Kind::OptionalChain:
20502051
case KeyPathPatternComponent::Kind::OptionalWrap:
20512052
case KeyPathPatternComponent::Kind::OptionalForce:
2053+
case KeyPathPatternComponent::Kind::TupleElement:
20522054
return;
20532055
case KeyPathPatternComponent::Kind::SettableProperty:
20542056
forFunction(component.getComputedPropertySetter());
@@ -2105,6 +2107,7 @@ KeyPathPattern::get(SILModule &M, CanGenericSignature signature,
21052107
case KeyPathPatternComponent::Kind::OptionalChain:
21062108
case KeyPathPatternComponent::Kind::OptionalWrap:
21072109
case KeyPathPatternComponent::Kind::OptionalForce:
2110+
case KeyPathPatternComponent::Kind::TupleElement:
21082111
break;
21092112

21102113
case KeyPathPatternComponent::Kind::GettableProperty:
@@ -2184,7 +2187,11 @@ void KeyPathPattern::Profile(llvm::FoldingSetNodeID &ID,
21842187
case KeyPathPatternComponent::Kind::StoredProperty:
21852188
ID.AddPointer(component.getStoredPropertyDecl());
21862189
break;
2187-
2190+
2191+
case KeyPathPatternComponent::Kind::TupleElement:
2192+
ID.AddInteger(component.getTupleIndex());
2193+
break;
2194+
21882195
case KeyPathPatternComponent::Kind::SettableProperty:
21892196
ID.AddPointer(component.getComputedPropertySetter());
21902197
LLVM_FALLTHROUGH;

lib/SIL/SILPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,11 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
21322132
*this << component.getComponentType();
21332133
break;
21342134
}
2135+
case KeyPathPatternComponent::Kind::TupleElement: {
2136+
*this << "tuple_element #" << component.getTupleIndex();
2137+
*this << " : $" << component.getComponentType();
2138+
break;
2139+
}
21352140
}
21362141
}
21372142
};

lib/SIL/SILVerifier.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ void verifyKeyPathComponent(SILModule &M,
384384
"wrapping component should wrap optional");
385385
break;
386386
}
387+
case KeyPathPatternComponent::Kind::TupleElement: {
388+
llvm_unreachable("[technicated]");
389+
break;
390+
}
387391
}
388392

389393
baseTy = componentTy;
@@ -4259,6 +4263,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
42594263
case KeyPathPatternComponent::Kind::OptionalChain:
42604264
case KeyPathPatternComponent::Kind::OptionalWrap:
42614265
case KeyPathPatternComponent::Kind::OptionalForce:
4266+
case KeyPathPatternComponent::Kind::TupleElement:
42624267
hasIndices = false;
42634268
break;
42644269
}

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class FunctionLivenessComputation {
235235
case KeyPathPatternComponent::Kind::OptionalChain:
236236
case KeyPathPatternComponent::Kind::OptionalForce:
237237
case KeyPathPatternComponent::Kind::OptionalWrap:
238+
case KeyPathPatternComponent::Kind::TupleElement:
238239
break;
239240
}
240241
}

lib/SILOptimizer/Transforms/AccessEnforcementWMO.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ void GlobalAccessRemoval::visitInstruction(SILInstruction *I) {
189189
case KeyPathPatternComponent::Kind::OptionalChain:
190190
case KeyPathPatternComponent::Kind::OptionalForce:
191191
case KeyPathPatternComponent::Kind::OptionalWrap:
192+
case KeyPathPatternComponent::Kind::TupleElement:
192193
break;
193194
}
194195
}

lib/Serialization/SerializeSIL.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,9 @@ SILSerializer::writeKeyPathPatternComponent(
684684
case KeyPathPatternComponent::Kind::OptionalWrap:
685685
handleComponentCommon(KeyPathComponentKindEncoding::OptionalWrap);
686686
break;
687+
case KeyPathPatternComponent::Kind::TupleElement:
688+
llvm_unreachable("[technicated]");
689+
break;
687690
}
688691
}
689692

0 commit comments

Comments
 (0)