Skip to content

Commit 2fa0bf8

Browse files
committed
SILGen: Simplify instance variables of Callee class, NFC
1 parent 9025cf8 commit 2fa0bf8

File tree

1 file changed

+30
-35
lines changed

1 file changed

+30
-35
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,9 @@ class Callee {
256256
private:
257257
union {
258258
ManagedValue IndirectValue;
259-
SILDeclRef StandaloneFunction;
260-
struct {
261-
SILValue SelfValue;
262-
SILDeclRef MethodName;
263-
} Method;
259+
SILDeclRef Constant;
264260
};
261+
SILValue SelfValue;
265262
ArrayRef<Substitution> Substitutions;
266263
CanType OrigFormalOldType;
267264
CanType OrigFormalInterfaceType;
@@ -304,7 +301,7 @@ class Callee {
304301
Callee(SILGenFunction &gen, SILDeclRef standaloneFunction,
305302
CanAnyFunctionType substFormalType,
306303
SILLocation l)
307-
: kind(Kind::StandaloneFunction), StandaloneFunction(standaloneFunction),
304+
: kind(Kind::StandaloneFunction), Constant(standaloneFunction),
308305
OrigFormalOldType(getConstantFormalType(gen, SILValue(),
309306
standaloneFunction)),
310307
OrigFormalInterfaceType(getConstantFormalInterfaceType(gen, SILValue(),
@@ -320,7 +317,7 @@ class Callee {
320317
SILDeclRef methodName,
321318
CanAnyFunctionType substFormalType,
322319
SILLocation l)
323-
: kind(methodKind), Method{selfValue, methodName},
320+
: kind(methodKind), Constant(methodName), SelfValue(selfValue),
324321
OrigFormalOldType(getConstantFormalType(gen, selfValue, methodName)),
325322
OrigFormalInterfaceType(getConstantFormalInterfaceType(gen, selfValue,
326323
methodName)),
@@ -437,9 +434,9 @@ class Callee {
437434

438435
// Replace it with the dynamic self type.
439436
OrigFormalOldType = OrigFormalInterfaceType
440-
= getDynamicMethodFormalType(SGM, Method.SelfValue,
441-
Method.MethodName.getDecl(),
442-
Method.MethodName, methodType);
437+
= getDynamicMethodFormalType(SGM, SelfValue,
438+
Constant.getDecl(),
439+
Constant, methodType);
443440

444441
// Add a self clause to the substituted type.
445442
auto origFormalType = cast<AnyFunctionType>(OrigFormalOldType);
@@ -533,13 +530,11 @@ class Callee {
533530
return 0;
534531

535532
case Kind::StandaloneFunction:
536-
return StandaloneFunction.uncurryLevel;
537-
538533
case Kind::ClassMethod:
539534
case Kind::SuperMethod:
540535
case Kind::WitnessMethod:
541536
case Kind::DynamicMethod:
542-
return Method.MethodName.uncurryLevel;
537+
return Constant.uncurryLevel;
543538
}
544539
}
545540

@@ -559,14 +554,14 @@ class Callee {
559554
break;
560555

561556
case Kind::StandaloneFunction: {
562-
assert(level <= StandaloneFunction.uncurryLevel
557+
assert(level <= Constant.uncurryLevel
563558
&& "uncurrying past natural uncurry level of standalone function");
564-
constant = StandaloneFunction.atUncurryLevel(level);
559+
constant = Constant.atUncurryLevel(level);
565560

566561
// If we're currying a direct reference to a class-dispatched method,
567562
// make sure we emit the right set of thunks.
568-
if (constant->isCurried && StandaloneFunction.hasDecl())
569-
if (auto func = StandaloneFunction.getAbstractFunctionDecl())
563+
if (constant->isCurried && Constant.hasDecl())
564+
if (auto func = Constant.getAbstractFunctionDecl())
570565
if (gen.getMethodDispatch(func) == MethodDispatch::Class)
571566
constant = constant->asDirectReference(true);
572567

@@ -576,21 +571,21 @@ class Callee {
576571
break;
577572
}
578573
case Kind::ClassMethod: {
579-
assert(level <= Method.MethodName.uncurryLevel
574+
assert(level <= Constant.uncurryLevel
580575
&& "uncurrying past natural uncurry level of method");
581-
constant = Method.MethodName.atUncurryLevel(level);
576+
constant = Constant.atUncurryLevel(level);
582577
constantInfo = gen.getConstantInfo(*constant);
583578

584579
// If the call is curried, emit a direct call to the curry thunk.
585-
if (level < Method.MethodName.uncurryLevel) {
580+
if (level < Constant.uncurryLevel) {
586581
SILValue ref = gen.emitGlobalFunctionRef(Loc, *constant, constantInfo);
587582
mv = ManagedValue::forUnmanaged(ref);
588583
break;
589584
}
590585

591586
// Otherwise, do the dynamic dispatch inline.
592587
SILValue methodVal = gen.B.createClassMethod(Loc,
593-
Method.SelfValue,
588+
SelfValue,
594589
*constant,
595590
/*volatile*/
596591
constant->isForeign);
@@ -599,15 +594,15 @@ class Callee {
599594
break;
600595
}
601596
case Kind::SuperMethod: {
602-
assert(level <= Method.MethodName.uncurryLevel
597+
assert(level <= Constant.uncurryLevel
603598
&& "uncurrying past natural uncurry level of method");
604599
assert(level >= 1
605600
&& "currying 'self' of super method dispatch not yet supported");
606601

607-
constant = Method.MethodName.atUncurryLevel(level);
602+
constant = Constant.atUncurryLevel(level);
608603
constantInfo = gen.getConstantInfo(*constant);
609604
SILValue methodVal = gen.B.createSuperMethod(Loc,
610-
Method.SelfValue,
605+
SelfValue,
611606
*constant,
612607
constantInfo.getSILType(),
613608
/*volatile*/
@@ -617,13 +612,13 @@ class Callee {
617612
break;
618613
}
619614
case Kind::WitnessMethod: {
620-
assert(level <= Method.MethodName.uncurryLevel
615+
assert(level <= Constant.uncurryLevel
621616
&& "uncurrying past natural uncurry level of method");
622-
constant = Method.MethodName.atUncurryLevel(level);
617+
constant = Constant.atUncurryLevel(level);
623618
constantInfo = gen.getConstantInfo(*constant);
624619

625620
// If the call is curried, emit a direct call to the curry thunk.
626-
if (level < Method.MethodName.uncurryLevel) {
621+
if (level < Constant.uncurryLevel) {
627622
SILValue ref = gen.emitGlobalFunctionRef(Loc, *constant, constantInfo);
628623
mv = ManagedValue::forUnmanaged(ref);
629624
break;
@@ -636,7 +631,7 @@ class Callee {
636631
// existential type.
637632
SILValue OpenedExistential;
638633
if (!archetype->getOpenedExistentialType().isNull())
639-
OpenedExistential = Method.SelfValue;
634+
OpenedExistential = SelfValue;
640635

641636
SILValue fn = gen.B.createWitnessMethod(Loc,
642637
archetype,
@@ -651,20 +646,20 @@ class Callee {
651646
case Kind::DynamicMethod: {
652647
assert(level >= 1
653648
&& "currying 'self' of dynamic method dispatch not yet supported");
654-
assert(level <= Method.MethodName.uncurryLevel
649+
assert(level <= Constant.uncurryLevel
655650
&& "uncurrying past natural uncurry level of method");
656651

657-
auto constant = Method.MethodName.atUncurryLevel(level);
652+
auto constant = Constant.atUncurryLevel(level);
658653
constantInfo = gen.getConstantInfo(constant);
659654

660655
auto closureType =
661656
replaceSelfTypeForDynamicLookup(gen.getASTContext(),
662657
constantInfo.SILFnType,
663-
Method.SelfValue.getType().getSwiftRValueType(),
664-
Method.MethodName);
658+
SelfValue.getType().getSwiftRValueType(),
659+
Constant);
665660

666661
SILValue fn = gen.B.createDynamicMethod(Loc,
667-
Method.SelfValue,
662+
SelfValue,
668663
constant,
669664
SILType::getPrimitiveObjectType(closureType),
670665
/*volatile*/ constant.isForeign);
@@ -692,7 +687,7 @@ class Callee {
692687
}
693688

694689
SILDeclRef getMethodName() const {
695-
return Method.MethodName;
690+
return Constant;
696691
}
697692

698693
/// Return a specialized emission function if this is a function with a known
@@ -706,7 +701,7 @@ class Callee {
706701

707702
switch (kind) {
708703
case Kind::StandaloneFunction: {
709-
return SpecializedEmitter::forDecl(SGM, StandaloneFunction);
704+
return SpecializedEmitter::forDecl(SGM, Constant);
710705
}
711706
case Kind::SuperMethod: {
712707
return SpecializedEmitter(emitPartialSuperMethod);

0 commit comments

Comments
 (0)