@@ -1638,9 +1638,9 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1638
1638
1639
1639
} // end anonymous namespace
1640
1640
1641
- static RValue emitStringLiteral (SILGenFunction &SGF, Expr *E, StringRef Str ,
1642
- SGFContext C,
1643
- StringLiteralExpr::Encoding encoding) {
1641
+ static PreparedArguments emitStringLiteral (SILGenFunction &SGF, Expr *E,
1642
+ StringRef Str, SGFContext C,
1643
+ StringLiteralExpr::Encoding encoding) {
1644
1644
uint64_t Length;
1645
1645
bool isASCII = true ;
1646
1646
for (unsigned char c : Str) {
@@ -1666,8 +1666,12 @@ static RValue emitStringLiteral(SILGenFunction &SGF, Expr *E, StringRef Str,
1666
1666
SILValue UnicodeScalarValue =
1667
1667
SGF.B .createIntegerLiteral (E, Int32Ty,
1668
1668
unicode::extractFirstUnicodeScalar (Str));
1669
- return RValue (SGF, E, Int32Ty.getASTType (),
1670
- ManagedValue::forUnmanaged (UnicodeScalarValue));
1669
+
1670
+ AnyFunctionType::Param param (Int32Ty.getASTType ());
1671
+ PreparedArguments args ({param}, /* scalar*/ false );
1672
+ args.add (E, RValue (SGF, E, Int32Ty.getASTType (),
1673
+ ManagedValue::forUnmanaged (UnicodeScalarValue)));
1674
+ return args;
1671
1675
}
1672
1676
}
1673
1677
@@ -1682,20 +1686,21 @@ static RValue emitStringLiteral(SILGenFunction &SGF, Expr *E, StringRef Str,
1682
1686
auto Int1Ty = SILType::getBuiltinIntegerType (1 , SGF.getASTContext ());
1683
1687
auto *isASCIIInst = SGF.B .createIntegerLiteral (E, Int1Ty, isASCII);
1684
1688
1689
+
1685
1690
ManagedValue EltsArray[] = {
1686
1691
ManagedValue::forUnmanaged (string),
1687
1692
ManagedValue::forUnmanaged (lengthInst),
1688
1693
ManagedValue::forUnmanaged (isASCIIInst)
1689
1694
};
1690
1695
1691
- TupleTypeElt TypeEltsArray[] = {
1692
- EltsArray[0 ].getType ().getASTType (),
1693
- EltsArray[1 ].getType ().getASTType (),
1694
- EltsArray[2 ].getType ().getASTType ()
1696
+ AnyFunctionType::Param TypeEltsArray[] = {
1697
+ AnyFunctionType::Param ( EltsArray[0 ].getType ().getASTType () ),
1698
+ AnyFunctionType::Param ( EltsArray[1 ].getType ().getASTType () ),
1699
+ AnyFunctionType::Param ( EltsArray[2 ].getType ().getASTType () )
1695
1700
};
1696
1701
1697
1702
ArrayRef<ManagedValue> Elts;
1698
- ArrayRef<TupleTypeElt > TypeElts;
1703
+ ArrayRef<AnyFunctionType::Param > TypeElts;
1699
1704
switch (instEncoding) {
1700
1705
case StringLiteralInst::Encoding::UTF16:
1701
1706
Elts = llvm::makeArrayRef (EltsArray).slice (0 , 2 );
@@ -1712,9 +1717,11 @@ static RValue emitStringLiteral(SILGenFunction &SGF, Expr *E, StringRef Str,
1712
1717
llvm_unreachable (" these cannot be formed here" );
1713
1718
}
1714
1719
1715
- CanType ty =
1716
- TupleType::get (TypeElts, SGF.getASTContext ())->getCanonicalType ();
1717
- return RValue (SGF, Elts, ty);
1720
+ PreparedArguments args (TypeElts, /* scalar*/ false );
1721
+ for (unsigned i = 0 , e = Elts.size (); i != e; ++i) {
1722
+ args.add (E, RValue (SGF, Elts[i], CanType (TypeElts[i].getPlainType ())));
1723
+ }
1724
+ return args;
1718
1725
}
1719
1726
1720
1727
// / Emit a raw apply operation, performing no additional lowering of
@@ -5410,7 +5417,7 @@ getMagicFunctionString(SILGenFunction &SGF) {
5410
5417
// / Emit an application of the given allocating initializer.
5411
5418
RValue SILGenFunction::emitApplyAllocatingInitializer (SILLocation loc,
5412
5419
ConcreteDeclRef init,
5413
- RValue &&args,
5420
+ PreparedArguments &&args,
5414
5421
Type overriddenSelfType,
5415
5422
SGFContext C) {
5416
5423
ConstructorDecl *ctor = cast<ConstructorDecl>(init.getDecl ());
@@ -5487,12 +5494,7 @@ RValue SILGenFunction::emitApplyAllocatingInitializer(SILLocation loc,
5487
5494
methodType);
5488
5495
5489
5496
// Arguments.
5490
-
5491
- // FIXME: Rework this so that scalar=false.
5492
- PreparedArguments preparedArgs (methodType->getParams (), /* scalar*/ true );
5493
- preparedArgs.addArbitrary (ArgumentSource (loc, std::move (args)));
5494
-
5495
- emission.addCallSite (loc, std::move (preparedArgs), resultType, /* throws*/ false );
5497
+ emission.addCallSite (loc, std::move (args), resultType, /* throws*/ false );
5496
5498
5497
5499
// For an inheritable initializer, determine whether we'll need to adjust the
5498
5500
// result type.
@@ -5522,23 +5524,24 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
5522
5524
ConcreteDeclRef builtinInit;
5523
5525
ConcreteDeclRef init;
5524
5526
// Emit the raw, builtin literal arguments.
5525
- RValue builtinLiteralArgs;
5527
+ PreparedArguments builtinLiteralArgs;
5526
5528
if (auto stringLiteral = dyn_cast<StringLiteralExpr>(literal)) {
5527
5529
builtinLiteralArgs = emitStringLiteral (*this , literal,
5528
5530
stringLiteral->getValue (), C,
5529
5531
stringLiteral->getEncoding ());
5530
5532
builtinInit = stringLiteral->getBuiltinInitializer ();
5531
5533
init = stringLiteral->getInitializer ();
5532
5534
} else if (auto nilLiteral = dyn_cast<NilLiteralExpr>(literal)) {
5533
- builtinLiteralArgs = emitEmptyTupleRValue (literal, C );
5535
+ builtinLiteralArgs. emplace ({}, /* scalar */ false );
5534
5536
builtinInit = nilLiteral->getInitializer ();
5535
5537
} else if (auto booleanLiteral = dyn_cast<BooleanLiteralExpr>(literal)) {
5536
5538
auto i1Ty = SILType::getBuiltinIntegerType (1 , getASTContext ());
5537
5539
SILValue boolValue = B.createIntegerLiteral (booleanLiteral, i1Ty,
5538
5540
booleanLiteral->getValue ());
5539
5541
ManagedValue boolManaged = ManagedValue::forUnmanaged (boolValue);
5540
5542
CanType ty = boolManaged.getType ().getASTType ()->getCanonicalType ();
5541
- builtinLiteralArgs = RValue (*this , {boolManaged}, ty);
5543
+ builtinLiteralArgs.emplace (AnyFunctionType::Param (ty), /* scalar*/ false );
5544
+ builtinLiteralArgs.add (literal, RValue (*this , {boolManaged}, ty));
5542
5545
builtinInit = booleanLiteral->getBuiltinInitializer ();
5543
5546
init = booleanLiteral->getInitializer ();
5544
5547
} else if (auto integerLiteral = dyn_cast<IntegerLiteralExpr>(literal)) {
@@ -5548,7 +5551,8 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
5548
5551
SILType::getBuiltinIntegerLiteralType (getASTContext ()),
5549
5552
integerLiteral->getRawValue ()));
5550
5553
CanType ty = integerManaged.getType ().getASTType ();
5551
- builtinLiteralArgs = RValue (*this , {integerManaged}, ty);
5554
+ builtinLiteralArgs.emplace (AnyFunctionType::Param (ty), /* scalar*/ false );
5555
+ builtinLiteralArgs.add (literal, RValue (*this , {integerManaged}, ty));
5552
5556
builtinInit = integerLiteral->getBuiltinInitializer ();
5553
5557
init = integerLiteral->getInitializer ();
5554
5558
} else if (auto floatLiteral = dyn_cast<FloatLiteralExpr>(literal)) {
@@ -5559,7 +5563,8 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
5559
5563
floatLiteral->getValue ()));
5560
5564
5561
5565
CanType ty = floatManaged.getType ().getASTType ();
5562
- builtinLiteralArgs = RValue (*this , {floatManaged}, ty);
5566
+ builtinLiteralArgs.emplace (AnyFunctionType::Param (ty), /* scalar*/ false );
5567
+ builtinLiteralArgs.add (literal, RValue (*this , {floatManaged}, ty));
5563
5568
builtinInit = floatLiteral->getBuiltinInitializer ();
5564
5569
init = floatLiteral->getInitializer ();
5565
5570
} else {
@@ -5600,10 +5605,12 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
5600
5605
: ctx.SourceMgr .getLineAndColumn (Loc).second ;
5601
5606
}
5602
5607
5603
- auto Ty = SILType::getBuiltinIntegerLiteralType (ctx);
5604
- SILValue V = B.createIntegerLiteral (literal, Ty, Value);
5605
- builtinLiteralArgs = RValue (*this , {ManagedValue::forUnmanaged (V)},
5606
- Ty.getASTType ()->getCanonicalType ());
5608
+ auto silTy = SILType::getBuiltinIntegerLiteralType (ctx);
5609
+ auto ty = silTy.getASTType ();
5610
+ SILValue integer = B.createIntegerLiteral (literal, silTy, Value);
5611
+ ManagedValue integerManaged = ManagedValue::forUnmanaged (integer);
5612
+ builtinLiteralArgs.emplace (AnyFunctionType::Param (ty), /* scalar*/ false );
5613
+ builtinLiteralArgs.add (literal, RValue (*this , {integerManaged}, ty));
5607
5614
builtinInit = magicLiteral->getBuiltinInitializer ();
5608
5615
init = magicLiteral->getInitializer ();
5609
5616
break ;
@@ -5624,8 +5631,12 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
5624
5631
if (!init) return builtinLiteral;
5625
5632
5626
5633
// Otherwise, perform the second initialization step.
5634
+ auto ty = builtinLiteral.getType ();
5635
+ PreparedArguments args (AnyFunctionType::Param (ty), /* scalar*/ false );
5636
+ args.add (literal, std::move (builtinLiteral));
5637
+
5627
5638
RValue result = emitApplyAllocatingInitializer (literal, init,
5628
- std::move (builtinLiteral ),
5639
+ std::move (args ),
5629
5640
literal->getType (), C);
5630
5641
return result;
5631
5642
}
0 commit comments