@@ -1638,9 +1638,9 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
16381638
16391639} // end anonymous namespace
16401640
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) {
16441644 uint64_t Length;
16451645 bool isASCII = true ;
16461646 for (unsigned char c : Str) {
@@ -1666,8 +1666,12 @@ static RValue emitStringLiteral(SILGenFunction &SGF, Expr *E, StringRef Str,
16661666 SILValue UnicodeScalarValue =
16671667 SGF.B .createIntegerLiteral (E, Int32Ty,
16681668 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;
16711675 }
16721676 }
16731677
@@ -1682,20 +1686,21 @@ static RValue emitStringLiteral(SILGenFunction &SGF, Expr *E, StringRef Str,
16821686 auto Int1Ty = SILType::getBuiltinIntegerType (1 , SGF.getASTContext ());
16831687 auto *isASCIIInst = SGF.B .createIntegerLiteral (E, Int1Ty, isASCII);
16841688
1689+
16851690 ManagedValue EltsArray[] = {
16861691 ManagedValue::forUnmanaged (string),
16871692 ManagedValue::forUnmanaged (lengthInst),
16881693 ManagedValue::forUnmanaged (isASCIIInst)
16891694 };
16901695
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 () )
16951700 };
16961701
16971702 ArrayRef<ManagedValue> Elts;
1698- ArrayRef<TupleTypeElt > TypeElts;
1703+ ArrayRef<AnyFunctionType::Param > TypeElts;
16991704 switch (instEncoding) {
17001705 case StringLiteralInst::Encoding::UTF16:
17011706 Elts = llvm::makeArrayRef (EltsArray).slice (0 , 2 );
@@ -1712,9 +1717,11 @@ static RValue emitStringLiteral(SILGenFunction &SGF, Expr *E, StringRef Str,
17121717 llvm_unreachable (" these cannot be formed here" );
17131718 }
17141719
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;
17181725}
17191726
17201727// / Emit a raw apply operation, performing no additional lowering of
@@ -5410,7 +5417,7 @@ getMagicFunctionString(SILGenFunction &SGF) {
54105417// / Emit an application of the given allocating initializer.
54115418RValue SILGenFunction::emitApplyAllocatingInitializer (SILLocation loc,
54125419 ConcreteDeclRef init,
5413- RValue &&args,
5420+ PreparedArguments &&args,
54145421 Type overriddenSelfType,
54155422 SGFContext C) {
54165423 ConstructorDecl *ctor = cast<ConstructorDecl>(init.getDecl ());
@@ -5487,12 +5494,7 @@ RValue SILGenFunction::emitApplyAllocatingInitializer(SILLocation loc,
54875494 methodType);
54885495
54895496 // 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 );
54965498
54975499 // For an inheritable initializer, determine whether we'll need to adjust the
54985500 // result type.
@@ -5522,23 +5524,24 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
55225524 ConcreteDeclRef builtinInit;
55235525 ConcreteDeclRef init;
55245526 // Emit the raw, builtin literal arguments.
5525- RValue builtinLiteralArgs;
5527+ PreparedArguments builtinLiteralArgs;
55265528 if (auto stringLiteral = dyn_cast<StringLiteralExpr>(literal)) {
55275529 builtinLiteralArgs = emitStringLiteral (*this , literal,
55285530 stringLiteral->getValue (), C,
55295531 stringLiteral->getEncoding ());
55305532 builtinInit = stringLiteral->getBuiltinInitializer ();
55315533 init = stringLiteral->getInitializer ();
55325534 } else if (auto nilLiteral = dyn_cast<NilLiteralExpr>(literal)) {
5533- builtinLiteralArgs = emitEmptyTupleRValue (literal, C );
5535+ builtinLiteralArgs. emplace ({}, /* scalar */ false );
55345536 builtinInit = nilLiteral->getInitializer ();
55355537 } else if (auto booleanLiteral = dyn_cast<BooleanLiteralExpr>(literal)) {
55365538 auto i1Ty = SILType::getBuiltinIntegerType (1 , getASTContext ());
55375539 SILValue boolValue = B.createIntegerLiteral (booleanLiteral, i1Ty,
55385540 booleanLiteral->getValue ());
55395541 ManagedValue boolManaged = ManagedValue::forUnmanaged (boolValue);
55405542 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));
55425545 builtinInit = booleanLiteral->getBuiltinInitializer ();
55435546 init = booleanLiteral->getInitializer ();
55445547 } else if (auto integerLiteral = dyn_cast<IntegerLiteralExpr>(literal)) {
@@ -5548,7 +5551,8 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
55485551 SILType::getBuiltinIntegerLiteralType (getASTContext ()),
55495552 integerLiteral->getRawValue ()));
55505553 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));
55525556 builtinInit = integerLiteral->getBuiltinInitializer ();
55535557 init = integerLiteral->getInitializer ();
55545558 } else if (auto floatLiteral = dyn_cast<FloatLiteralExpr>(literal)) {
@@ -5559,7 +5563,8 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
55595563 floatLiteral->getValue ()));
55605564
55615565 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));
55635568 builtinInit = floatLiteral->getBuiltinInitializer ();
55645569 init = floatLiteral->getInitializer ();
55655570 } else {
@@ -5600,10 +5605,12 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
56005605 : ctx.SourceMgr .getLineAndColumn (Loc).second ;
56015606 }
56025607
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));
56075614 builtinInit = magicLiteral->getBuiltinInitializer ();
56085615 init = magicLiteral->getInitializer ();
56095616 break ;
@@ -5624,8 +5631,12 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
56245631 if (!init) return builtinLiteral;
56255632
56265633 // 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+
56275638 RValue result = emitApplyAllocatingInitializer (literal, init,
5628- std::move (builtinLiteral ),
5639+ std::move (args ),
56295640 literal->getType (), C);
56305641 return result;
56315642}
0 commit comments