@@ -2045,38 +2045,48 @@ static ManagedValue visitRecNonInOutBase(SILGenLValue &SGL, Expr *e,
2045
2045
AccessKind accessKind,
2046
2046
LValueOptions options,
2047
2047
AbstractionPattern orig) {
2048
- SGFContext ctx;
2049
2048
auto &SGF = SGL.SGF ;
2050
2049
2051
- if (auto *DRE = dyn_cast<DeclRefExpr>(e)) {
2050
+ // For an rvalue base, apply the reabstraction (if any) eagerly, since
2051
+ // there's no need for writeback.
2052
+ if (orig.isValid ()) {
2053
+ return SGF.emitRValueAsOrig (
2054
+ e, orig, SGF.getTypeLowering (orig, e->getType ()->getRValueType ()));
2055
+ }
2056
+
2057
+ // Ok, at this point we know that re-abstraction is not required.
2058
+ SGFContext ctx;
2059
+
2060
+ if (auto *dre = dyn_cast<DeclRefExpr>(e)) {
2052
2061
// Any reference to "self" can be done at +0 so long as it is a direct
2053
2062
// access, since we know it is guaranteed.
2054
2063
//
2055
2064
// TODO: it would be great to factor this even lower into SILGen to the
2056
2065
// point where we can see that the parameter is +0 guaranteed. Note that
2057
2066
// this handles the case in initializers where there is actually a stack
2058
2067
// allocation for it as well.
2059
- if (isa<ParamDecl>(DRE ->getDecl ()) &&
2060
- DRE ->getDecl ()->getFullName () == SGF.getASTContext ().Id_self &&
2061
- DRE ->getDecl ()->isImplicit ()) {
2068
+ if (isa<ParamDecl>(dre ->getDecl ()) &&
2069
+ dre ->getDecl ()->getFullName () == SGF.getASTContext ().Id_self &&
2070
+ dre ->getDecl ()->isImplicit ()) {
2062
2071
ctx = SGFContext::AllowGuaranteedPlusZero;
2063
2072
if (SGF.SelfInitDelegationState != SILGenFunction::NormalSelf) {
2064
2073
// This needs to be inlined since there is a Formal Evaluation Scope
2065
2074
// in emitRValueForDecl that causing any borrow for this LValue to be
2066
2075
// popped too soon.
2067
- auto *vd = cast<ParamDecl>(DRE ->getDecl ());
2076
+ auto *vd = cast<ParamDecl>(dre ->getDecl ());
2068
2077
ManagedValue selfLValue =
2069
- SGF.emitLValueForDecl (DRE, vd, DRE->getType ()->getCanonicalType (),
2070
- AccessKind::Read, DRE->getAccessSemantics ());
2071
- return SGF
2072
- .emitFormalEvaluationRValueForSelfInDelegationInit (
2073
- e, DRE->getType ()->getCanonicalType (),
2074
- selfLValue.getLValueAddress (), ctx)
2075
- .getAsSingleValue (SGF, e);
2078
+ SGF.emitLValueForDecl (dre, vd, dre->getType ()->getCanonicalType (),
2079
+ AccessKind::Read, dre->getAccessSemantics ());
2080
+ selfLValue = SGF.emitFormalEvaluationRValueForSelfInDelegationInit (
2081
+ e, dre->getType ()->getCanonicalType (),
2082
+ selfLValue.getLValueAddress (), ctx)
2083
+ .getAsSingleValue (SGF, e);
2084
+
2085
+ return selfLValue;
2076
2086
}
2077
2087
}
2078
2088
2079
- if (auto *VD = dyn_cast<VarDecl>(DRE ->getDecl ())) {
2089
+ if (auto *VD = dyn_cast<VarDecl>(dre ->getDecl ())) {
2080
2090
// All let values are guaranteed to be held alive across their lifetime,
2081
2091
// and won't change once initialized. Any loaded value is good for the
2082
2092
// duration of this expression evaluation.
@@ -2090,14 +2100,6 @@ static ManagedValue visitRecNonInOutBase(SILGenLValue &SGL, Expr *e,
2090
2100
ctx = SGFContext::AllowGuaranteedPlusZero;
2091
2101
}
2092
2102
2093
- // For an rvalue base, apply the reabstraction (if any) eagerly, since
2094
- // there's no need for writeback.
2095
- if (orig.isValid ()) {
2096
- return SGF.emitRValueAsOrig (
2097
- e, orig, SGF.getTypeLowering (orig, e->getType ()->getRValueType ()));
2098
- }
2099
-
2100
- // Otherwise, just go through normal emission.
2101
2103
return SGF.emitRValueAsSingleValue (e, ctx);
2102
2104
}
2103
2105
0 commit comments