Skip to content

Commit 241b4f9

Browse files
authored
Merge pull request #11983 from jckarter/key-path-fixes
Key path fixes
2 parents 0ebee3f + 158ec12 commit 241b4f9

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lib/IRGen/GenKeyPath.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ getAccessorForComputedComponent(IRGenModule &IGM,
111111
return accessorFn;
112112
}
113113

114-
auto accessorFnTy = accessorFn->getType()->getPointerElementType();
114+
auto accessorFnTy = cast<llvm::FunctionType>(
115+
accessorFn->getType()->getPointerElementType());;
115116

116117
// Otherwise, we need a thunk to unmarshal the generic environment from the
117118
// argument area. It'd be nice to have a good way to represent this
@@ -140,7 +141,7 @@ getAccessorForComputedComponent(IRGenModule &IGM,
140141

141142
SmallVector<llvm::Type *, 4> thunkParams;
142143
for (unsigned i = 0; i < numArgsToForward; ++i)
143-
thunkParams.push_back(accessorFnTy->getFunctionParamType(i));
144+
thunkParams.push_back(accessorFnTy->getParamType(i));
144145

145146
switch (whichAccessor) {
146147
case Getter:
@@ -153,7 +154,8 @@ getAccessorForComputedComponent(IRGenModule &IGM,
153154
}
154155
thunkParams.push_back(IGM.SizeTy);
155156

156-
auto thunkType = llvm::FunctionType::get(IGM.VoidTy, thunkParams,
157+
auto thunkType = llvm::FunctionType::get(accessorFnTy->getReturnType(),
158+
thunkParams,
157159
/*vararg*/ false);
158160

159161
auto accessorThunk = llvm::Function::Create(thunkType,
@@ -228,9 +230,12 @@ getAccessorForComputedComponent(IRGenModule &IGM,
228230
forwardedArgs);
229231
auto fnPtr = FunctionPointer::forDirect(IGM, accessorFn,
230232
accessor->getLoweredFunctionType());
231-
IGF.Builder.CreateCall(fnPtr, forwardedArgs.claimAll());
233+
auto call = IGF.Builder.CreateCall(fnPtr, forwardedArgs.claimAll());
232234

233-
IGF.Builder.CreateRetVoid();
235+
if (call->getType()->isVoidTy())
236+
IGF.Builder.CreateRetVoid();
237+
else
238+
IGF.Builder.CreateRet(call);
234239
}
235240

236241
return accessorThunk;

lib/SIL/SILInstructions.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,18 +2045,19 @@ forEachRefcountableReference(const KeyPathPatternComponent &component,
20452045
switch (component.getComputedPropertyId().getKind()) {
20462046
case KeyPathPatternComponent::ComputedPropertyId::DeclRef:
20472047
// Mark the vtable entry as used somehow?
2048-
return;
2048+
break;
20492049
case KeyPathPatternComponent::ComputedPropertyId::Function:
20502050
forFunction(component.getComputedPropertyId().getFunction());
2051-
return;
2051+
break;
20522052
case KeyPathPatternComponent::ComputedPropertyId::Property:
2053-
return;
2053+
break;
20542054
}
20552055

20562056
if (auto equals = component.getComputedPropertyIndexEquals())
20572057
forFunction(equals);
20582058
if (auto hash = component.getComputedPropertyIndexHash())
20592059
forFunction(hash);
2060+
return;
20602061
}
20612062
}
20622063

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ class FunctionLivenessComputation {
223223
case KeyPathPatternComponent::ComputedPropertyId::Property:
224224
break;
225225
}
226+
227+
if (auto equals = component.getComputedPropertyIndexEquals())
228+
ensureAlive(equals);
229+
if (auto hash = component.getComputedPropertyIndexHash())
230+
ensureAlive(hash);
231+
226232
continue;
227233
}
228234
case KeyPathPatternComponent::Kind::StoredProperty:

0 commit comments

Comments
 (0)