Skip to content

Commit 0975c16

Browse files
committed
SILGen: Remove RValue::rewriteType()
1 parent e7d2dcc commit 0975c16

File tree

3 files changed

+4
-69
lines changed

3 files changed

+4
-69
lines changed

lib/SILGen/RValue.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -308,42 +308,6 @@ class RValue {
308308
/// be returned. Otherwise, an object will be returned. So this is a
309309
/// convenient way to determine if an RValue needs an address.
310310
SILType getLoweredImplodedTupleType(SILGenFunction &SGF) const &;
311-
312-
/// Rewrite the type of this r-value.
313-
void rewriteType(CanType newType) & {
314-
#ifndef NDEBUG
315-
static const auto areSimilarTypes = [](CanType l, CanType r) {
316-
if (l == r) return true;
317-
318-
// Allow function types to disagree about 'noescape'.
319-
if (auto lf = dyn_cast<FunctionType>(l)) {
320-
if (auto rf = dyn_cast<FunctionType>(r)) {
321-
auto lParams = lf.getParams();
322-
auto rParams = rf.getParams();
323-
return AnyFunctionType::equalParams(lParams, rParams) &&
324-
lf.getResult() == rf.getResult() &&
325-
lf->getExtInfo().withNoEscape(false) ==
326-
rf->getExtInfo().withNoEscape(false);
327-
}
328-
}
329-
return false;
330-
};
331-
332-
static const auto isSingleElementTuple = [](CanType type, CanType eltType) {
333-
if (auto tupleType = dyn_cast<TupleType>(type)) {
334-
return tupleType->getNumElements() == 1 &&
335-
areSimilarTypes(tupleType.getElementType(0), eltType);
336-
}
337-
return false;
338-
};
339-
340-
// We only allow a very modest set of changes to a type.
341-
assert(areSimilarTypes(newType, type) ||
342-
isSingleElementTuple(newType, type) ||
343-
isSingleElementTuple(type, newType));
344-
#endif
345-
type = newType;
346-
}
347311

348312
/// Emit an equivalent value with independent ownership.
349313
RValue copy(SILGenFunction &SGF, SILLocation loc) const &;

lib/SILGen/SILGenApply.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5635,20 +5635,7 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
56355635
}
56365636
}
56375637

5638-
// Helper routine to add an argument label if we need one.
5639-
auto relabelArgument = [&](ConcreteDeclRef callee, RValue &arg) {
5640-
auto name = callee.getDecl()->getFullName();
5641-
auto argLabels = name.getArgumentNames();
5642-
if (argLabels.size() == 1 && !argLabels[0].empty() &&
5643-
!isa<TupleType>(arg.getType())) {
5644-
Type newType = TupleType::get({TupleTypeElt(arg.getType(), argLabels[0])},
5645-
getASTContext());
5646-
arg.rewriteType(newType->getCanonicalType());
5647-
}
5648-
};
5649-
56505638
// Call the builtin initializer.
5651-
relabelArgument(builtinInit, builtinLiteralArgs);
56525639
RValue builtinLiteral =
56535640
emitApplyAllocatingInitializer(literal, builtinInit,
56545641
std::move(builtinLiteralArgs),
@@ -5659,7 +5646,6 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
56595646
if (!init) return builtinLiteral;
56605647

56615648
// Otherwise, perform the second initialization step.
5662-
relabelArgument(init, builtinLiteral);
56635649
RValue result = emitApplyAllocatingInitializer(literal, init,
56645650
std::move(builtinLiteral),
56655651
literal->getType(), C);
@@ -6189,14 +6175,9 @@ void SILGenFunction::emitSetAccessor(SILLocation loc, SILDeclRef set,
61896175
values.addArbitrary(std::move(setValue));
61906176

61916177
if (!subscriptIndices.isNull()) {
6192-
unsigned paramIndex = 1;
61936178
for (auto &component : std::move(subscriptIndices).getSources()) {
6194-
auto param = accessType.getParams()[paramIndex++];
6195-
auto paramType = param.getParameterType();
6196-
61976179
auto argLoc = component.getKnownRValueLocation();
61986180
RValue &&arg = std::move(component).asKnownRValue(*this);
6199-
arg.rewriteType(paramType);
62006181
values.add(argLoc, std::move(arg));
62016182
}
62026183
}

lib/SILGen/SILGenExpr.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,13 +3656,11 @@ visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *E, SGFContext C) {
36563656
RValue RValueEmitter::visitArrayExpr(ArrayExpr *E, SGFContext C) {
36573657
auto loc = SILLocation(E);
36583658
ArgumentScope scope(SGF, loc);
3659-
auto init = E->getInitializer();
3660-
auto *decl = dyn_cast<AbstractFunctionDecl>(init.getDecl());
3661-
Type elementType = E->getElementType();
3662-
ArrayRef<Identifier> argLabels = decl->getFullName().getArgumentNames();
3659+
3660+
CanType elementType = E->getElementType()->getCanonicalType();
36633661
CanType arrayTy = ArraySliceType::get(elementType)->getCanonicalType();
36643662
VarargsInfo varargsInfo =
3665-
emitBeginVarargs(SGF, loc, elementType->getCanonicalType(), arrayTy,
3663+
emitBeginVarargs(SGF, loc, elementType, arrayTy,
36663664
E->getNumElements(), {});
36673665

36683666
for (unsigned index : range(E->getNumElements())) {
@@ -3686,17 +3684,9 @@ RValue RValueEmitter::visitArrayExpr(ArrayExpr *E, SGFContext C) {
36863684

36873685
arg = scope.popPreservingValue(std::move(arg));
36883686

3689-
// Add an argument label for init(arrayLiteral: T...) as the above tuple is of
3690-
// the form (T...) with no label.
3691-
assert(argLabels.size() == 1 && !argLabels[0].empty() &&
3692-
!isa<TupleType>(arg.getType()));
3693-
Type newType = TupleType::get({TupleTypeElt(arg.getType(), argLabels[0])},
3694-
SGF.getASTContext());
3695-
arg.rewriteType(newType->getCanonicalType());
3696-
36973687
// Call the builtin initializer.
36983688
return SGF.emitApplyAllocatingInitializer(
3699-
loc, init, std::move(arg), E->getType(), C);
3689+
loc, E->getInitializer(), std::move(arg), E->getType(), C);
37003690
}
37013691

37023692
RValue RValueEmitter::visitDictionaryExpr(DictionaryExpr *E, SGFContext C) {

0 commit comments

Comments
 (0)