Skip to content

Commit a823e48

Browse files
authored
Merge pull request #23650 from slavapestov/kill-scalar-prepared-arguments
SILGen: Kill "scalar" PreparedArguments
2 parents e7aee37 + 1417647 commit a823e48

13 files changed

+337
-381
lines changed

lib/SILGen/ASTVisitor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class ASTVisitor : public swift::ASTVisitor<ImplClass,
5757
}
5858

5959
ExprRetTy visitVarargExpansionExpr(VarargExpansionExpr *E, Args... AA) {
60-
llvm_unreachable("vararg expansion should not appear in this position");
60+
return static_cast<ImplClass*>(this)->visit(E->getSubExpr(),
61+
std::forward<Args>(AA)...);
6162
}
6263

6364
ExprRetTy visitIdentityExpr(IdentityExpr *E, Args...AA) {

lib/SILGen/ArgumentSource.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,6 @@ RValue &ArgumentSource::peekRValue() & {
2727
return Storage.get<RValueStorage>(StoredKind).Value;
2828
}
2929

30-
bool ArgumentSource::isShuffle() const {
31-
switch (StoredKind) {
32-
case Kind::Invalid:
33-
llvm_unreachable("argument source is invalid");
34-
case Kind::RValue:
35-
case Kind::LValue:
36-
return false;
37-
case Kind::Expr:
38-
return isa<ArgumentShuffleExpr>(asKnownExpr());
39-
}
40-
llvm_unreachable("bad kind");
41-
}
42-
4330
RValue ArgumentSource::getAsRValue(SILGenFunction &SGF, SGFContext C) && {
4431
switch (StoredKind) {
4532
case Kind::Invalid:
@@ -261,17 +248,30 @@ void ArgumentSource::dump(raw_ostream &out, unsigned indent) const {
261248
llvm_unreachable("bad kind");
262249
}
263250

264-
void PreparedArguments::emplaceEmptyArgumentList(SILGenFunction &SGF) {
265-
emplace({}, /*scalar*/ false);
266-
assert(isValid());
251+
PreparedArguments::PreparedArguments(
252+
ArrayRef<AnyFunctionType::Param> params,
253+
Expr *arg) : PreparedArguments(params) {
254+
if (isa<ArgumentShuffleExpr>(arg)) {
255+
IsScalar = true;
256+
addArbitrary(arg);
257+
} else if (auto *PE = dyn_cast<ParenExpr>(arg))
258+
addArbitrary(PE->getSubExpr());
259+
else if (auto *TE = dyn_cast<TupleExpr>(arg)) {
260+
for (auto *elt : TE->getElements())
261+
addArbitrary(elt);
262+
} else {
263+
// FIXME: All ApplyExprs should have a ParenExpr or TupleExpr as their argument
264+
addArbitrary(arg);
265+
}
267266
}
268267

269268
PreparedArguments
270269
PreparedArguments::copy(SILGenFunction &SGF, SILLocation loc) const {
271270
if (isNull()) return PreparedArguments();
272271

273272
assert(isValid());
274-
PreparedArguments result(getParams(), isScalar());
273+
PreparedArguments result(getParams());
274+
result.IsScalar = isScalar();
275275
for (auto &elt : Arguments) {
276276
assert(elt.isRValue());
277277
result.add(elt.getKnownRValueLocation(),
@@ -319,7 +319,8 @@ PreparedArguments PreparedArguments::copyForDiagnostics() const {
319319
return PreparedArguments();
320320

321321
assert(isValid());
322-
PreparedArguments result(getParams(), isScalar());
322+
PreparedArguments result(getParams());
323+
result.IsScalar = isScalar();
323324
for (auto &arg : Arguments) {
324325
result.Arguments.push_back(arg.copyForDiagnostics());
325326
}

lib/SILGen/ArgumentSource.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ class ArgumentSource {
240240
AbstractionPattern origFormalType,
241241
SILType expectedType = SILType()) &&;
242242

243-
/// Whether this argument source is an ArgumentShuffleExpr.
244-
bool isShuffle() const;
245-
246243
bool isObviouslyEqual(const ArgumentSource &other) const;
247244

248245
ArgumentSource copyForDiagnostics() const;
@@ -268,11 +265,14 @@ class PreparedArguments {
268265
unsigned IsNull : 1;
269266
public:
270267
PreparedArguments() : IsScalar(false), IsNull(true) {}
271-
PreparedArguments(ArrayRef<AnyFunctionType::Param> params, bool isScalar)
272-
: IsNull(true) {
273-
emplace(params, isScalar);
268+
explicit PreparedArguments(ArrayRef<AnyFunctionType::Param> params)
269+
: IsScalar(false), IsNull(true) {
270+
emplace(params);
274271
}
275272

273+
// Decompse an argument list expression.
274+
PreparedArguments(ArrayRef<AnyFunctionType::Param> params, Expr *arg);
275+
276276
// Move-only.
277277
PreparedArguments(const PreparedArguments &) = delete;
278278
PreparedArguments &operator=(const PreparedArguments &) = delete;
@@ -320,16 +320,13 @@ class PreparedArguments {
320320
}
321321

322322
/// Emplace a (probably incomplete) argument list.
323-
void emplace(ArrayRef<AnyFunctionType::Param> params, bool isScalar) {
323+
void emplace(ArrayRef<AnyFunctionType::Param> params) {
324324
assert(isNull());
325325
Params.append(params.begin(), params.end());
326-
IsScalar = isScalar;
326+
IsScalar = false;
327327
IsNull = false;
328328
}
329329

330-
/// Emplace an empty argument list.
331-
void emplaceEmptyArgumentList(SILGenFunction &SGF);
332-
333330
/// Add an emitted r-value argument to this argument list.
334331
void add(SILLocation loc, RValue &&arg) {
335332
assert(!isNull());

0 commit comments

Comments
 (0)