Skip to content

Commit 2ea1c5c

Browse files
committed
Use IGM.getMaximalTypeExpansionContext() in more places
1 parent 74d1478 commit 2ea1c5c

File tree

8 files changed

+39
-50
lines changed

8 files changed

+39
-50
lines changed

lib/IRGen/GenClass.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -501,21 +501,20 @@ Address IRGenFunction::emitByteOffsetGEP(llvm::Value *base,
501501
}
502502

503503
/// Emit a field l-value by applying the given offset to the given base.
504-
static OwnedAddress emitAddressAtOffset(TypeExpansionContext context,
505-
IRGenFunction &IGF, SILType baseType,
504+
static OwnedAddress emitAddressAtOffset(IRGenFunction &IGF, SILType baseType,
506505
llvm::Value *base, llvm::Value *offset,
507506
VarDecl *field) {
508-
auto &fieldTI = IGF.getTypeInfo(
509-
baseType.getFieldType(field, IGF.getSILModule(), context));
507+
auto &fieldTI = IGF.getTypeInfo(baseType.getFieldType(
508+
field, IGF.getSILModule(), IGF.IGM.getMaximalTypeExpansionContext()));
510509
auto addr = IGF.emitByteOffsetGEP(base, offset, fieldTI,
511510
base->getName() + "." + field->getName().str());
512511
return OwnedAddress(addr, base);
513512
}
514513

515514
llvm::Constant *irgen::tryEmitConstantClassFragilePhysicalMemberOffset(
516-
TypeExpansionContext context, IRGenModule &IGM, SILType baseType,
517-
VarDecl *field) {
518-
auto fieldType = baseType.getFieldType(field, IGM.getSILModule(), context);
515+
IRGenModule &IGM, SILType baseType, VarDecl *field) {
516+
auto fieldType = baseType.getFieldType(field, IGM.getSILModule(),
517+
IGM.getMaximalTypeExpansionContext());
519518
// If the field is empty, its address doesn't matter.
520519
auto &fieldTI = IGM.getTypeInfo(fieldType);
521520
if (fieldTI.isKnownEmpty(ResilienceExpansion::Maximal)) {
@@ -571,9 +570,11 @@ irgen::getClassLayoutWithTailElems(IRGenModule &IGM, SILType classType,
571570
return ClassTI.createLayoutWithTailElems(IGM, classType, tailTypes);
572571
}
573572

574-
OwnedAddress irgen::projectPhysicalClassMemberAddress(
575-
TypeExpansionContext context, IRGenFunction &IGF, llvm::Value *base,
576-
SILType baseType, SILType fieldType, VarDecl *field) {
573+
OwnedAddress irgen::projectPhysicalClassMemberAddress(IRGenFunction &IGF,
574+
llvm::Value *base,
575+
SILType baseType,
576+
SILType fieldType,
577+
VarDecl *field) {
577578
// If the field is empty, its address doesn't matter.
578579
auto &fieldTI = IGF.getTypeInfo(fieldType);
579580
if (fieldTI.isKnownEmpty(ResilienceExpansion::Maximal)) {
@@ -603,13 +604,13 @@ OwnedAddress irgen::projectPhysicalClassMemberAddress(
603604
case FieldAccess::NonConstantDirect: {
604605
Address offsetA = IGF.IGM.getAddrOfFieldOffset(field, NotForDefinition);
605606
auto offset = IGF.Builder.CreateLoad(offsetA, "offset");
606-
return emitAddressAtOffset(context, IGF, baseType, base, offset, field);
607+
return emitAddressAtOffset(IGF, baseType, base, offset, field);
607608
}
608609

609610
case FieldAccess::ConstantIndirect: {
610611
auto metadata = emitHeapMetadataRefForHeapObject(IGF, base, baseType);
611612
auto offset = emitClassFieldOffset(IGF, baseClass, field, metadata);
612-
return emitAddressAtOffset(context, IGF, baseType, base, offset, field);
613+
return emitAddressAtOffset(IGF, baseType, base, offset, field);
613614
}
614615
}
615616
llvm_unreachable("bad field-access strategy");

lib/IRGen/GenClass.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace irgen {
5252
enum class FieldAccess : uint8_t;
5353

5454
OwnedAddress projectPhysicalClassMemberAddress(
55-
TypeExpansionContext context, IRGenFunction &IGF, llvm::Value *base,
55+
IRGenFunction &IGF, llvm::Value *base,
5656
SILType baseType, SILType fieldType, VarDecl *field);
5757

5858
/// Return a strategy for accessing the given stored class property.
@@ -179,8 +179,7 @@ namespace irgen {
179179
/// Emit the constant fragile offset of the given property inside an instance
180180
/// of the class.
181181
llvm::Constant *tryEmitConstantClassFragilePhysicalMemberOffset(
182-
TypeExpansionContext context, IRGenModule &IGM, SILType baseType,
183-
VarDecl *field);
182+
IRGenModule &IGM, SILType baseType, VarDecl *field);
184183

185184
FieldAccess getClassFieldAccess(IRGenModule &IGM,
186185
SILType baseType,

lib/IRGen/GenKeyPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ emitKeyPathComponent(IRGenModule &IGM,
791791
case FieldAccess::ConstantDirect: {
792792
// Known constant fixed offset.
793793
auto offset = tryEmitConstantClassFragilePhysicalMemberOffset(
794-
TypeExpansionContext::minimal(), IGM, loweredClassTy, property);
794+
IGM, loweredClassTy, property);
795795
assert(offset && "no constant offset for ConstantDirect field?!");
796796
addFixedOffset(/*struct*/ false, property->isLet(), offset);
797797
break;

lib/IRGen/GenProto.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,11 +3185,9 @@ void irgen::expandTrailingWitnessSignature(IRGenModule &IGM,
31853185
out.push_back(IGM.WitnessTablePtrTy);
31863186
}
31873187

3188-
FunctionPointer
3189-
irgen::emitWitnessMethodValue(TypeExpansionContext expansionContext,
3190-
IRGenFunction &IGF,
3191-
llvm::Value *wtable,
3192-
SILDeclRef member) {
3188+
FunctionPointer irgen::emitWitnessMethodValue(IRGenFunction &IGF,
3189+
llvm::Value *wtable,
3190+
SILDeclRef member) {
31933191
auto *fn = cast<AbstractFunctionDecl>(member.getDecl());
31943192
auto proto = cast<ProtocolDecl>(fn->getDeclContext());
31953193

@@ -3202,8 +3200,8 @@ irgen::emitWitnessMethodValue(TypeExpansionContext expansionContext,
32023200
emitInvariantLoadOfOpaqueWitness(IGF, wtable,
32033201
index.forProtocolWitnessTable());
32043202

3205-
auto fnType =
3206-
IGF.IGM.getSILTypes().getConstantFunctionType(expansionContext, member);
3203+
auto fnType = IGF.IGM.getSILTypes().getConstantFunctionType(
3204+
IGF.IGM.getMaximalTypeExpansionContext(), member);
32073205
Signature signature = IGF.IGM.getSignature(fnType);
32083206
witnessFnPtr = IGF.Builder.CreateBitCast(witnessFnPtr,
32093207
signature.getType()->getPointerTo());
@@ -3212,13 +3210,12 @@ irgen::emitWitnessMethodValue(TypeExpansionContext expansionContext,
32123210
}
32133211

32143212
FunctionPointer irgen::emitWitnessMethodValue(
3215-
TypeExpansionContext expansionContext, IRGenFunction &IGF, CanType baseTy,
3216-
llvm::Value **baseMetadataCache, SILDeclRef member,
3217-
ProtocolConformanceRef conformance) {
3213+
IRGenFunction &IGF, CanType baseTy, llvm::Value **baseMetadataCache,
3214+
SILDeclRef member, ProtocolConformanceRef conformance) {
32183215
llvm::Value *wtable = emitWitnessTableRef(IGF, baseTy, baseMetadataCache,
32193216
conformance);
32203217

3221-
return emitWitnessMethodValue(expansionContext, IGF, wtable, member);
3218+
return emitWitnessMethodValue(IGF, wtable, member);
32223219
}
32233220

32243221
llvm::Value *irgen::computeResilientWitnessTableIndex(

lib/IRGen/GenProto.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,13 @@ namespace irgen {
5858

5959
/// Extract the method pointer from the given witness table
6060
/// as a function value.
61-
FunctionPointer emitWitnessMethodValue(TypeExpansionContext context,
62-
IRGenFunction &IGF,
61+
FunctionPointer emitWitnessMethodValue(IRGenFunction &IGF,
6362
llvm::Value *wtable,
6463
SILDeclRef member);
6564

6665
/// Extract the method pointer from an archetype's witness table
6766
/// as a function value.
68-
FunctionPointer emitWitnessMethodValue(TypeExpansionContext context,
69-
IRGenFunction &IGF, CanType baseTy,
67+
FunctionPointer emitWitnessMethodValue(IRGenFunction &IGF, CanType baseTy,
7068
llvm::Value **baseMetadataCache,
7169
SILDeclRef member,
7270
ProtocolConformanceRef conformance);

lib/IRGen/GenThunk.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ using namespace irgen;
3636

3737
/// Find the entry point for a method dispatch thunk.
3838
llvm::Function *
39-
IRGenModule::getAddrOfDispatchThunk(TypeExpansionContext context,
40-
SILDeclRef declRef,
39+
IRGenModule::getAddrOfDispatchThunk(SILDeclRef declRef,
4140
ForDefinition_t forDefinition) {
4241
LinkEntity entity = LinkEntity::forDispatchThunk(declRef);
4342

@@ -47,7 +46,8 @@ IRGenModule::getAddrOfDispatchThunk(TypeExpansionContext context,
4746
return entry;
4847
}
4948

50-
auto fnType = getSILModule().Types.getConstantFunctionType(context, declRef);
49+
auto fnType = getSILModule().Types.getConstantFunctionType(
50+
getMaximalTypeExpansionContext(), declRef);
5151
Signature signature = getSignature(fnType);
5252
LinkInfo link = LinkInfo::get(*this, entity, forDefinition);
5353

@@ -56,7 +56,7 @@ IRGenModule::getAddrOfDispatchThunk(TypeExpansionContext context,
5656
}
5757

5858
static FunctionPointer lookupMethod(IRGenFunction &IGF, SILDeclRef declRef) {
59-
auto expansionContext = TypeExpansionContext::minimal();
59+
auto expansionContext = IGF.IGM.getMaximalTypeExpansionContext();
6060
auto *decl = cast<AbstractFunctionDecl>(declRef.getDecl());
6161

6262
// Protocol case.
@@ -65,7 +65,7 @@ static FunctionPointer lookupMethod(IRGenFunction &IGF, SILDeclRef declRef) {
6565
llvm::Value *wtable = (IGF.CurFn->arg_end() - 1);
6666

6767
// Find the witness we're interested in.
68-
return emitWitnessMethodValue(expansionContext, IGF, wtable, declRef);
68+
return emitWitnessMethodValue(IGF, wtable, declRef);
6969
}
7070

7171
// Class case.
@@ -99,8 +99,7 @@ static FunctionPointer lookupMethod(IRGenFunction &IGF, SILDeclRef declRef) {
9999
}
100100

101101
void IRGenModule::emitDispatchThunk(SILDeclRef declRef) {
102-
auto *f = getAddrOfDispatchThunk(TypeExpansionContext::minimal(), declRef,
103-
ForDefinition);
102+
auto *f = getAddrOfDispatchThunk(declRef, ForDefinition);
104103

105104
IRGenFunction IGF(*this, f);
106105

lib/IRGen/IRGenModule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,7 @@ private: \
12561256
/// Cast the given constant to i8*.
12571257
llvm::Constant *getOpaquePtr(llvm::Constant *pointer);
12581258

1259-
llvm::Function *getAddrOfDispatchThunk(TypeExpansionContext context,
1260-
SILDeclRef declRef,
1259+
llvm::Function *getAddrOfDispatchThunk(SILDeclRef declRef,
12611260
ForDefinition_t forDefinition);
12621261
void emitDispatchThunk(SILDeclRef declRef);
12631262

lib/IRGen/IRGenSIL.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,9 +3623,8 @@ void IRGenSILFunction::visitRefElementAddrInst(swift::RefElementAddrInst *i) {
36233623
llvm::Value *value = base.claimNext();
36243624

36253625
SILType baseTy = i->getOperand()->getType();
3626-
Address field = projectPhysicalClassMemberAddress(
3627-
TypeExpansionContext(*i->getFunction()), *this, value,
3628-
baseTy, i->getType(), i->getField())
3626+
Address field = projectPhysicalClassMemberAddress(*this, value, baseTy,
3627+
i->getType(), i->getField())
36293628
.getAddress();
36303629
setLoweredAddress(i, field);
36313630
}
@@ -5468,8 +5467,7 @@ void IRGenSILFunction::visitWitnessMethodInst(swift::WitnessMethodInst *i) {
54685467

54695468
if (IGM.isResilient(conformance.getRequirement(),
54705469
ResilienceExpansion::Maximal)) {
5471-
auto *fnPtr = IGM.getAddrOfDispatchThunk(
5472-
IGM.getMaximalTypeExpansionContext(), member, NotForDefinition);
5470+
auto *fnPtr = IGM.getAddrOfDispatchThunk(member, NotForDefinition);
54735471
auto fnType = IGM.getSILTypes().getConstantFunctionType(
54745472
IGM.getMaximalTypeExpansionContext(), member);
54755473
auto sig = IGM.getSignature(fnType);
@@ -5482,9 +5480,8 @@ void IRGenSILFunction::visitWitnessMethodInst(swift::WitnessMethodInst *i) {
54825480
// It would be nice if this weren't discarded.
54835481
llvm::Value *baseMetadataCache = nullptr;
54845482

5485-
auto fn =
5486-
emitWitnessMethodValue(TypeExpansionContext(*i->getFunction()), *this,
5487-
baseTy, &baseMetadataCache, member, conformance);
5483+
auto fn = emitWitnessMethodValue(*this, baseTy, &baseMetadataCache, member,
5484+
conformance);
54885485

54895486
setLoweredFunctionPointer(i, fn);
54905487
}
@@ -5668,8 +5665,7 @@ void IRGenSILFunction::visitClassMethodInst(swift::ClassMethodInst *i) {
56685665
auto *classDecl = cast<ClassDecl>(method.getDecl()->getDeclContext());
56695666
if (IGM.hasResilientMetadata(classDecl,
56705667
ResilienceExpansion::Maximal)) {
5671-
auto *fnPtr = IGM.getAddrOfDispatchThunk(TypeExpansionContext(*CurSILFn),
5672-
method, NotForDefinition);
5668+
auto *fnPtr = IGM.getAddrOfDispatchThunk(method, NotForDefinition);
56735669
auto sig = IGM.getSignature(methodType);
56745670
FunctionPointer fn(fnPtr, sig);
56755671

0 commit comments

Comments
 (0)