Skip to content

Commit 5ae231e

Browse files
committed
Rename getFieldNo() to getFieldIndex().
Do I really need to justify this?
1 parent 2829472 commit 5ae231e

38 files changed

+83
-84
lines changed

Diff for: include/swift/SIL/PatternMatch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ template <typename LTy> struct tupleextractoperation_ty {
406406

407407
template <typename ITy> bool match(ITy *V) {
408408
if (auto *TEI = dyn_cast<TupleExtractInst>(V)) {
409-
return TEI->getFieldNo() == index &&
409+
return TEI->getFieldIndex() == index &&
410410
L.match((ValueBase *)TEI->getOperand());
411411
}
412412

Diff for: include/swift/SIL/Projection.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ struct ProjectionIndex {
152152
}
153153
case ValueKind::StructElementAddrInst: {
154154
StructElementAddrInst *SEA = cast<StructElementAddrInst>(V);
155-
Index = SEA->getFieldNo();
155+
Index = SEA->getFieldIndex();
156156
Aggregate = SEA->getOperand();
157157
break;
158158
}
159159
case ValueKind::RefElementAddrInst: {
160160
RefElementAddrInst *REA = cast<RefElementAddrInst>(V);
161-
Index = REA->getFieldNo();
161+
Index = REA->getFieldIndex();
162162
Aggregate = REA->getOperand();
163163
break;
164164
}
@@ -177,19 +177,19 @@ struct ProjectionIndex {
177177
}
178178
case ValueKind::TupleElementAddrInst: {
179179
TupleElementAddrInst *TEA = cast<TupleElementAddrInst>(V);
180-
Index = TEA->getFieldNo();
180+
Index = TEA->getFieldIndex();
181181
Aggregate = TEA->getOperand();
182182
break;
183183
}
184184
case ValueKind::StructExtractInst: {
185185
StructExtractInst *SEA = cast<StructExtractInst>(V);
186-
Index = SEA->getFieldNo();
186+
Index = SEA->getFieldIndex();
187187
Aggregate = SEA->getOperand();
188188
break;
189189
}
190190
case ValueKind::TupleExtractInst: {
191191
TupleExtractInst *TEA = cast<TupleExtractInst>(V);
192-
Index = TEA->getFieldNo();
192+
Index = TEA->getFieldIndex();
193193
Aggregate = TEA->getOperand();
194194
break;
195195
}

Diff for: include/swift/SIL/SILCloner.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ SILCloner<ImplClass>::visitTupleExtractInst(TupleExtractInst *Inst) {
19461946
recordClonedInstruction(
19471947
Inst, getBuilder().createTupleExtract(
19481948
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
1949-
Inst->getFieldNo(), getOpType(Inst->getType())));
1949+
Inst->getFieldIndex(), getOpType(Inst->getType())));
19501950
}
19511951

19521952
template<typename ImplClass>
@@ -1956,7 +1956,7 @@ SILCloner<ImplClass>::visitTupleElementAddrInst(TupleElementAddrInst *Inst) {
19561956
recordClonedInstruction(
19571957
Inst, getBuilder().createTupleElementAddr(
19581958
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
1959-
Inst->getFieldNo(), getOpType(Inst->getType())));
1959+
Inst->getFieldIndex(), getOpType(Inst->getType())));
19601960
}
19611961

19621962
template<typename ImplClass>

Diff for: include/swift/SIL/SILInstruction.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -5715,7 +5715,7 @@ class TupleExtractInst
57155715
}
57165716

57175717
public:
5718-
unsigned getFieldNo() const {
5718+
unsigned getFieldIndex() const {
57195719
return SILInstruction::Bits.TupleExtractInst.FieldNo;
57205720
}
57215721

@@ -5747,7 +5747,7 @@ class TupleElementAddrInst
57475747
}
57485748

57495749
public:
5750-
unsigned getFieldNo() const {
5750+
unsigned getFieldIndex() const {
57515751
return SILInstruction::Bits.TupleElementAddrInst.FieldNo;
57525752
}
57535753

@@ -5811,8 +5811,7 @@ class FieldIndexCacheBase : public SingleValueInstruction {
58115811

58125812
VarDecl *getField() const { return field; }
58135813

5814-
// FIXME: this should be called getFieldIndex().
5815-
unsigned getFieldNo() const {
5814+
unsigned getFieldIndex() const {
58165815
unsigned idx = SILInstruction::Bits.FieldIndexCacheBase.FieldIndex;
58175816
if (idx != InvalidFieldIndex)
58185817
return idx;

Diff for: lib/IRGen/IRGenSIL.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3787,7 +3787,7 @@ void IRGenSILFunction::visitTupleExtractInst(swift::TupleExtractInst *i) {
37873787
projectTupleElementFromExplosion(*this,
37883788
baseType,
37893789
fullTuple,
3790-
i->getFieldNo(),
3790+
i->getFieldIndex(),
37913791
output);
37923792
(void)fullTuple.claimAll();
37933793
setLoweredExplosion(i, output);
@@ -3799,7 +3799,7 @@ void IRGenSILFunction::visitTupleElementAddrInst(swift::TupleElementAddrInst *i)
37993799
SILType baseType = i->getOperand()->getType();
38003800

38013801
Address field = projectTupleElementAddress(*this, base, baseType,
3802-
i->getFieldNo());
3802+
i->getFieldIndex());
38033803
setLoweredAddress(i, field);
38043804
}
38053805

Diff for: lib/SIL/IR/SILGlobalVariable.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ BuiltinInst *SILGlobalVariable::getOffsetSubtract(const TupleExtractInst *TE,
8585
// Match the pattern:
8686
// tuple_extract(usub_with_overflow(x, integer_literal, integer_literal 0), 0)
8787

88-
if (TE->getFieldNo() != 0)
88+
if (TE->getFieldIndex() != 0)
8989
return nullptr;
9090

9191
auto *BI = dyn_cast<BuiltinInst>(TE->getOperand());

Diff for: lib/SIL/IR/SILInstruction.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ namespace {
579579
auto *X = cast<TupleExtractInst>(LHS);
580580
if (X->getTupleType() != RHS->getTupleType())
581581
return false;
582-
if (X->getFieldNo() != RHS->getFieldNo())
582+
if (X->getFieldIndex() != RHS->getFieldIndex())
583583
return false;
584584
return true;
585585
}
@@ -590,7 +590,7 @@ namespace {
590590
auto *X = cast<TupleElementAddrInst>(LHS);
591591
if (X->getTupleType() != RHS->getTupleType())
592592
return false;
593-
if (X->getFieldNo() != RHS->getFieldNo())
593+
if (X->getFieldIndex() != RHS->getFieldIndex())
594594
return false;
595595
return true;
596596
}

Diff for: lib/SIL/IR/SILInstructions.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ bool TupleExtractInst::isTrivialEltOfOneRCIDTuple() const {
12581258
// parent tuple has only one non-trivial field.
12591259
bool FoundNonTrivialField = false;
12601260
SILType OpTy = getOperand()->getType();
1261-
unsigned FieldNo = getFieldNo();
1261+
unsigned FieldNo = getFieldIndex();
12621262

12631263
// For each element index of the tuple...
12641264
for (unsigned i = 0, e = getNumTupleElts(); i != e; ++i) {
@@ -1300,7 +1300,7 @@ bool TupleExtractInst::isEltOnlyNonTrivialElt() const {
13001300
// Ok, we know that the elt we are extracting is non-trivial. Make sure that
13011301
// we have no other non-trivial elts.
13021302
SILType OpTy = getOperand()->getType();
1303-
unsigned FieldNo = getFieldNo();
1303+
unsigned FieldNo = getFieldIndex();
13041304

13051305
// For each element index of the tuple...
13061306
for (unsigned i = 0, e = getNumTupleElts(); i != e; ++i) {
@@ -1348,7 +1348,7 @@ VarDecl *swift::getIndexedField(NominalTypeDecl *decl, unsigned index) {
13481348
if (auto *classDecl = dyn_cast<ClassDecl>(decl)) {
13491349
for (auto *superDecl = classDecl->getSuperclassDecl(); superDecl != nullptr;
13501350
superDecl = superDecl->getSuperclassDecl()) {
1351-
assert(index > superDecl->getStoredProperties().size()
1351+
assert(index >= superDecl->getStoredProperties().size()
13521352
&& "field index cannot refer to a superclass field");
13531353
index -= superDecl->getStoredProperties().size();
13541354
}
@@ -1357,7 +1357,7 @@ VarDecl *swift::getIndexedField(NominalTypeDecl *decl, unsigned index) {
13571357
}
13581358

13591359
unsigned FieldIndexCacheBase::cacheFieldIndex() {
1360-
unsigned index = getFieldIndex(getParentDecl(), getField());
1360+
unsigned index = ::getFieldIndex(getParentDecl(), getField());
13611361
SILInstruction::Bits.FieldIndexCacheBase.FieldIndex = index;
13621362
return index;
13631363
}

Diff for: lib/SIL/IR/SILPrinter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1774,11 +1774,11 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17741774
}
17751775

17761776
void visitTupleExtractInst(TupleExtractInst *EI) {
1777-
*this << getIDAndType(EI->getOperand()) << ", " << EI->getFieldNo();
1777+
*this << getIDAndType(EI->getOperand()) << ", " << EI->getFieldIndex();
17781778
}
17791779

17801780
void visitTupleElementAddrInst(TupleElementAddrInst *EI) {
1781-
*this << getIDAndType(EI->getOperand()) << ", " << EI->getFieldNo();
1781+
*this << getIDAndType(EI->getOperand()) << ", " << EI->getFieldIndex();
17821782
}
17831783
void visitStructExtractInst(StructExtractInst *EI) {
17841784
*this << getIDAndType(EI->getOperand()) << ", #";

Diff for: lib/SIL/Utils/MemAccessUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ AccessedStorage::AccessedStorage(SILValue base, Kind kind) {
118118
// conservative given that classes are not "uniquely identified".
119119
auto *REA = cast<RefElementAddrInst>(base);
120120
value = stripBorrow(REA->getOperand());
121-
setElementIndex(REA->getFieldNo());
121+
setElementIndex(REA->getFieldIndex());
122122
break;
123123
}
124124
case Tail: {

Diff for: lib/SIL/Utils/Projection.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,23 @@ Projection::Projection(SingleValueInstruction *I) : Value() {
7070
return;
7171
case SILInstructionKind::StructElementAddrInst: {
7272
auto *SEAI = cast<StructElementAddrInst>(I);
73-
Value = ValueTy(ProjectionKind::Struct, SEAI->getFieldNo());
73+
Value = ValueTy(ProjectionKind::Struct, SEAI->getFieldIndex());
7474
assert(getKind() == ProjectionKind::Struct);
75-
assert(getIndex() == SEAI->getFieldNo());
75+
assert(getIndex() == SEAI->getFieldIndex());
7676
break;
7777
}
7878
case SILInstructionKind::StructExtractInst: {
7979
auto *SEI = cast<StructExtractInst>(I);
80-
Value = ValueTy(ProjectionKind::Struct, SEI->getFieldNo());
80+
Value = ValueTy(ProjectionKind::Struct, SEI->getFieldIndex());
8181
assert(getKind() == ProjectionKind::Struct);
82-
assert(getIndex() == SEI->getFieldNo());
82+
assert(getIndex() == SEI->getFieldIndex());
8383
break;
8484
}
8585
case SILInstructionKind::RefElementAddrInst: {
8686
auto *REAI = cast<RefElementAddrInst>(I);
87-
Value = ValueTy(ProjectionKind::Class, REAI->getFieldNo());
87+
Value = ValueTy(ProjectionKind::Class, REAI->getFieldIndex());
8888
assert(getKind() == ProjectionKind::Class);
89-
assert(getIndex() == REAI->getFieldNo());
89+
assert(getIndex() == REAI->getFieldIndex());
9090
break;
9191
}
9292
case SILInstructionKind::RefTailAddrInst: {
@@ -106,16 +106,16 @@ Projection::Projection(SingleValueInstruction *I) : Value() {
106106
}
107107
case SILInstructionKind::TupleExtractInst: {
108108
auto *TEI = cast<TupleExtractInst>(I);
109-
Value = ValueTy(ProjectionKind::Tuple, TEI->getFieldNo());
109+
Value = ValueTy(ProjectionKind::Tuple, TEI->getFieldIndex());
110110
assert(getKind() == ProjectionKind::Tuple);
111-
assert(getIndex() == TEI->getFieldNo());
111+
assert(getIndex() == TEI->getFieldIndex());
112112
break;
113113
}
114114
case SILInstructionKind::TupleElementAddrInst: {
115115
auto *TEAI = cast<TupleElementAddrInst>(I);
116-
Value = ValueTy(ProjectionKind::Tuple, TEAI->getFieldNo());
116+
Value = ValueTy(ProjectionKind::Tuple, TEAI->getFieldIndex());
117117
assert(getKind() == ProjectionKind::Tuple);
118-
assert(getIndex() == TEAI->getFieldNo());
118+
assert(getIndex() == TEAI->getFieldIndex());
119119
break;
120120
}
121121
case SILInstructionKind::UncheckedEnumDataInst: {

Diff for: lib/SIL/Verifier/MemoryLifetime.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ bool MemoryLocations::analyzeLocationUsesRecursively(SILValue V, unsigned locIdx
261261
switch (user->getKind()) {
262262
case SILInstructionKind::StructElementAddrInst: {
263263
auto SEAI = cast<StructElementAddrInst>(user);
264-
if (!analyzeAddrProjection(SEAI, locIdx, SEAI->getFieldNo(),
264+
if (!analyzeAddrProjection(SEAI, locIdx, SEAI->getFieldIndex(),
265265
collectedVals, subLocationMap))
266266
return false;
267267
break;
268268
}
269269
case SILInstructionKind::TupleElementAddrInst: {
270270
auto *TEAI = cast<TupleElementAddrInst>(user);
271-
if (!analyzeAddrProjection(TEAI, locIdx, TEAI->getFieldNo(),
271+
if (!analyzeAddrProjection(TEAI, locIdx, TEAI->getFieldIndex(),
272272
collectedVals, subLocationMap))
273273
return false;
274274
break;

Diff for: lib/SIL/Verifier/SILVerifier.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2747,11 +2747,11 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
27472747
require(EI->getType().isObject(),
27482748
"result of tuple_extract must be object");
27492749

2750-
require(EI->getFieldNo() < operandTy->getNumElements(),
2750+
require(EI->getFieldIndex() < operandTy->getNumElements(),
27512751
"invalid field index for tuple_extract instruction");
27522752
if (EI->getModule().getStage() != SILStage::Lowered) {
27532753
requireSameType(EI->getType().getASTType(),
2754-
operandTy.getElementType(EI->getFieldNo()),
2754+
operandTy.getElementType(EI->getFieldIndex()),
27552755
"type of tuple_extract does not match type of element");
27562756
}
27572757
}
@@ -2793,12 +2793,12 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
27932793
"must derive tuple_element_addr from tuple");
27942794

27952795
ArrayRef<TupleTypeElt> fields = operandTy.castTo<TupleType>()->getElements();
2796-
require(EI->getFieldNo() < fields.size(),
2796+
require(EI->getFieldIndex() < fields.size(),
27972797
"invalid field index for element_addr instruction");
27982798
if (EI->getModule().getStage() != SILStage::Lowered) {
27992799
requireSameType(
28002800
EI->getType().getASTType(),
2801-
CanType(fields[EI->getFieldNo()].getType()),
2801+
CanType(fields[EI->getFieldIndex()].getType()),
28022802
"type of tuple_element_addr does not match type of element");
28032803
}
28042804
}
@@ -2856,7 +2856,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
28562856
loweredFieldTy, EI->getType(),
28572857
"result of ref_element_addr does not match type of field");
28582858
}
2859-
EI->getFieldNo(); // Make sure we can access the field without crashing.
2859+
EI->getFieldIndex(); // Make sure we can access the field without crashing.
28602860
}
28612861

28622862
void checkRefTailAddrInst(RefTailAddrInst *RTAI) {

Diff for: lib/SILOptimizer/Analysis/ARCAnalysis.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1084,11 +1084,11 @@ swift::getSingleUnsafeGuaranteedValueResult(BuiltinInst *BI) {
10841084
if (!TE || TE->getOperand() != BI)
10851085
return Failed;
10861086

1087-
if (TE->getFieldNo() == 0 && !GuaranteedValue) {
1087+
if (TE->getFieldIndex() == 0 && !GuaranteedValue) {
10881088
GuaranteedValue = TE;
10891089
continue;
10901090
}
1091-
if (TE->getFieldNo() == 1 && !Token) {
1091+
if (TE->getFieldIndex() == 1 && !Token) {
10921092
Token = TE;
10931093
continue;
10941094
}

Diff for: lib/SILOptimizer/Analysis/AccessSummaryAnalysis.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,13 @@ getSingleAddressProjectionUser(SingleValueInstruction *I) {
506506
switch (User->getKind()) {
507507
case SILInstructionKind::StructElementAddrInst: {
508508
auto inst = cast<StructElementAddrInst>(User);
509-
ProjectionIndex = inst->getFieldNo();
509+
ProjectionIndex = inst->getFieldIndex();
510510
SingleUser = inst;
511511
break;
512512
}
513513
case SILInstructionKind::TupleElementAddrInst: {
514514
auto inst = cast<TupleElementAddrInst>(User);
515-
ProjectionIndex = inst->getFieldNo();
515+
ProjectionIndex = inst->getFieldIndex();
516516
SingleUser = inst;
517517
break;
518518
}

Diff for: lib/SILOptimizer/Analysis/ArraySemantic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ static SILValue getArrayUninitializedInitResult(ArraySemanticsCall arrayCall,
672672
auto *tupleElt = dyn_cast<TupleExtractInst>(op->getUser());
673673
if (!tupleElt)
674674
return SILValue();
675-
if (tupleElt->getFieldNo() != tupleElementIndex)
675+
if (tupleElt->getFieldIndex() != tupleElementIndex)
676676
continue;
677677
tupleExtractInst = tupleElt;
678678
break;

Diff for: lib/SILOptimizer/Analysis/EscapeAnalysis.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1871,11 +1871,11 @@ EscapeAnalysis::canOptimizeArrayUninitializedCall(ApplyInst *ai) {
18711871
// uses must be mapped to ConnectionGraph nodes by the client of this API.
18721872
for (Operand *use : getNonDebugUses(ai)) {
18731873
if (auto *tei = dyn_cast<TupleExtractInst>(use->getUser())) {
1874-
if (tei->getFieldNo() == 0 && !call.arrayStruct) {
1874+
if (tei->getFieldIndex() == 0 && !call.arrayStruct) {
18751875
call.arrayStruct = tei;
18761876
continue;
18771877
}
1878-
if (tei->getFieldNo() == 1 && !call.arrayElementPtr) {
1878+
if (tei->getFieldIndex() == 1 && !call.arrayElementPtr) {
18791879
call.arrayElementPtr = tei;
18801880
continue;
18811881
}

Diff for: lib/SILOptimizer/Analysis/SimplifyInstruction.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ SILValue InstSimplifier::visitStructInst(StructInst *SI) {
9797
return SILValue();
9898

9999
// And the order of the field must be identical to the construction order.
100-
if (Ex->getFieldNo() != i)
100+
if (Ex->getFieldIndex() != i)
101101
return SILValue();
102102
}
103103

@@ -132,7 +132,7 @@ SILValue InstSimplifier::visitTupleInst(TupleInst *TI) {
132132
return SILValue();
133133

134134
// And the order of the field must be identical to the construction order.
135-
if (Ex->getFieldNo() != i)
135+
if (Ex->getFieldIndex() != i)
136136
return SILValue();
137137
}
138138

@@ -145,11 +145,11 @@ SILValue InstSimplifier::visitTupleInst(TupleInst *TI) {
145145
SILValue InstSimplifier::visitTupleExtractInst(TupleExtractInst *TEI) {
146146
// tuple_extract(tuple(x, y), 0) -> x
147147
if (auto *TheTuple = dyn_cast<TupleInst>(TEI->getOperand()))
148-
return TheTuple->getElement(TEI->getFieldNo());
148+
return TheTuple->getElement(TEI->getFieldIndex());
149149

150150
// tuple_extract(apply([add|sub|...]overflow(x,y)), 0) -> x
151151
// tuple_extract(apply(checked_trunc(ext(x))), 0) -> x
152-
if (TEI->getFieldNo() == 0)
152+
if (TEI->getFieldIndex() == 0)
153153
if (auto *BI = dyn_cast<BuiltinInst>(TEI->getOperand()))
154154
return simplifyOverflowBuiltin(BI);
155155

Diff for: lib/SILOptimizer/Analysis/ValueTracking.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ IsZeroKind swift::isZeroValue(SILValue Value) {
136136
if (auto *T = dyn_cast<TupleExtractInst>(Value)) {
137137
// Make sure we are extracting the number value and not
138138
// the overflow flag.
139-
if (T->getFieldNo() != 0)
139+
if (T->getFieldIndex() != 0)
140140
return IsZeroKind::Unknown;
141141

142142
auto *BI = dyn_cast<BuiltinInst>(T->getOperand());

0 commit comments

Comments
 (0)