Skip to content

Commit 50b1bae

Browse files
committed
SILGen: Tidy up some code
1 parent e9bd15f commit 50b1bae

File tree

3 files changed

+14
-33
lines changed

3 files changed

+14
-33
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4507,8 +4507,6 @@ CallEmission::applyEnumElementConstructor(SGFContext C) {
45074507
// correctly.
45084508
firstLevelResult.formalType = callee.getSubstFormalType();
45094509
auto origFormalType = callee.getOrigFormalType();
4510-
auto substFnType =
4511-
SGF.getSILFunctionType(origFormalType, firstLevelResult.formalType);
45124510

45134511
// We have a fully-applied enum element constructor: open-code the
45144512
// construction.
@@ -4539,8 +4537,6 @@ CallEmission::applyEnumElementConstructor(SGFContext C) {
45394537
assert(uncurriedSites.size() == 1);
45404538
}
45414539

4542-
assert(substFnType->getNumResults() == 1);
4543-
(void)substFnType;
45444540
ManagedValue resultMV = SGF.emitInjectEnum(
45454541
uncurriedLoc, std::move(payload),
45464542
SGF.getLoweredType(formalResultType),

lib/SILGen/SILGenBridging.cpp

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -333,26 +333,15 @@ static ManagedValue emitManagedParameter(SILGenFunction &SGF, SILLocation loc,
333333
llvm_unreachable("bad convention");
334334
}
335335

336-
static void expandTupleTypes(CanType type, SmallVectorImpl<CanType> &results) {
337-
if (auto tuple = dyn_cast<TupleType>(type)) {
338-
for (auto eltType : tuple.getElementTypes())
339-
expandTupleTypes(eltType, results);
340-
} else {
341-
results.push_back(type);
342-
}
343-
}
344-
345-
/// Recursively expand all the tuples in the given parameter list.
346-
/// Callers assume that the resulting array will line up with the
347-
/// SILFunctionType's parameter list, which is true as along as there
348-
/// aren't any indirectly-passed tuples; we should be safe from that
349-
/// here in the bridging code.
336+
/// Get the type of each parameter, filtering out empty tuples.
350337
static SmallVector<CanType, 8>
351-
expandTupleTypes(AnyFunctionType::CanParamArrayRef params) {
338+
getParameterTypes(AnyFunctionType::CanParamArrayRef params) {
352339
SmallVector<CanType, 8> results;
353340
for (auto param : params) {
354341
assert(!param.isInOut() && !param.isVariadic());
355-
expandTupleTypes(param.getPlainType(), results);
342+
if (param.getPlainType()->isVoid())
343+
continue;
344+
results.push_back(param.getPlainType());
356345
}
357346
return results;
358347
}
@@ -403,8 +392,8 @@ static void buildFuncToBlockInvokeBody(SILGenFunction &SGF,
403392
assert(blockTy->getParameters().size() == funcTy->getParameters().size()
404393
&& "block and function types don't match");
405394

406-
auto nativeParamTypes = expandTupleTypes(formalFuncType.getParams());
407-
auto bridgedParamTypes = expandTupleTypes(formalBlockType.getParams());
395+
auto nativeParamTypes = getParameterTypes(formalFuncType.getParams());
396+
auto bridgedParamTypes = getParameterTypes(formalBlockType.getParams());
408397

409398
SmallVector<ManagedValue, 4> args;
410399
for (unsigned i : indices(funcTy->getParameters())) {
@@ -839,8 +828,8 @@ static void buildBlockToFuncThunkBody(SILGenFunction &SGF,
839828
}
840829
}
841830

842-
auto formalBlockParams = expandTupleTypes(formalBlockTy.getParams());
843-
auto formalFuncParams = expandTupleTypes(formalFuncTy.getParams());
831+
auto formalBlockParams = getParameterTypes(formalBlockTy.getParams());
832+
auto formalFuncParams = getParameterTypes(formalFuncTy.getParams());
844833
assert(formalBlockParams.size() == blockTy->getNumParameters());
845834
assert(formalFuncParams.size() == funcTy->getNumParameters());
846835

@@ -1297,10 +1286,10 @@ static SILFunctionType *emitObjCThunkArguments(SILGenFunction &SGF,
12971286
assert(objcFnTy->getNumIndirectFormalResults() == 0
12981287
&& "Objective-C methods cannot have indirect results");
12991288

1300-
auto bridgedFormalTypes = expandTupleTypes(objcFormalFnTy.getParams());
1289+
auto bridgedFormalTypes = getParameterTypes(objcFormalFnTy.getParams());
13011290
bridgedFormalResultTy = objcFormalFnTy.getResult();
13021291

1303-
auto nativeFormalTypes = expandTupleTypes(swiftFormalFnTy.getParams());
1292+
auto nativeFormalTypes = getParameterTypes(swiftFormalFnTy.getParams());
13041293
nativeFormalResultTy = swiftFormalFnTy.getResult();
13051294

13061295
// Emit the other arguments, taking ownership of arguments if necessary.
@@ -1697,9 +1686,9 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
16971686

16981687
{
16991688
auto foreignFormalParams =
1700-
expandTupleTypes(foreignCI.LoweredType.getParams());
1689+
getParameterTypes(foreignCI.LoweredType.getParams());
17011690
auto nativeFormalParams =
1702-
expandTupleTypes(nativeCI.LoweredType.getParams());
1691+
getParameterTypes(nativeCI.LoweredType.getParams());
17031692

17041693
for (unsigned nativeParamIndex : indices(params)) {
17051694
// Bring the parameter to +1.

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -856,11 +856,7 @@ emitRValueForDecl(SILLocation loc, ConcreteDeclRef declRef, Type ncRefType,
856856

857857
// If this is a decl that we have an lvalue for, produce and return it.
858858
ValueDecl *decl = declRef.getDecl();
859-
860-
if (!ncRefType) {
861-
ncRefType = decl->getInnermostDeclContext()->mapTypeIntoContext(
862-
decl->getInterfaceType());
863-
}
859+
864860
CanType refType = ncRefType->getCanonicalType();
865861

866862
// If this is a reference to a module, produce an undef value. The

0 commit comments

Comments
 (0)