@@ -4491,29 +4491,23 @@ DeclRefExpr *getInteropStaticCastDeclRefExpr(ASTContext &ctx,
4491
4491
// %2 = __swift_interopStaticCast<UnsafeMutablePointer<Base>?>(%1)
4492
4492
// %3 = %2!
4493
4493
// return %3.pointee
4494
- MemberRefExpr *getInOutSelfInteropStaticCast (FuncDecl *funcDecl,
4495
- NominalTypeDecl *baseStruct,
4496
- NominalTypeDecl *derivedStruct) {
4494
+ MemberRefExpr *getSelfInteropStaticCast (FuncDecl *funcDecl,
4495
+ NominalTypeDecl *baseStruct,
4496
+ NominalTypeDecl *derivedStruct) {
4497
4497
auto &ctx = funcDecl->getASTContext ();
4498
4498
4499
- auto inoutSelf = [&ctx](FuncDecl *funcDecl) {
4500
- auto inoutSelfDecl = funcDecl->getImplicitSelfDecl ();
4499
+ auto mutableSelf = [&ctx](FuncDecl *funcDecl) {
4500
+ auto selfDecl = funcDecl->getImplicitSelfDecl ();
4501
4501
4502
- auto inoutSelfRef =
4503
- new (ctx) DeclRefExpr (inoutSelfDecl , DeclNameLoc (), /* implicit*/ true );
4504
- inoutSelfRef ->setType (LValueType::get (inoutSelfDecl ->getInterfaceType ()));
4502
+ auto selfRef =
4503
+ new (ctx) DeclRefExpr (selfDecl , DeclNameLoc (), /* implicit*/ true );
4504
+ selfRef ->setType (LValueType::get (selfDecl ->getInterfaceType ()));
4505
4505
4506
- auto inoutSelf = new (ctx) InOutExpr (
4507
- SourceLoc (), inoutSelfRef,
4508
- funcDecl->mapTypeIntoContext (inoutSelfDecl->getValueInterfaceType ()),
4509
- /* implicit*/ true );
4510
- inoutSelf->setType (InOutType::get (inoutSelfDecl->getInterfaceType ()));
4511
-
4512
- return inoutSelf;
4506
+ return selfRef;
4513
4507
}(funcDecl);
4514
4508
4515
4509
auto createCallToBuiltin = [&](Identifier name, ArrayRef<Type> substTypes,
4516
- Expr * arg) {
4510
+ Argument arg) {
4517
4511
auto builtinFn = cast<FuncDecl>(getBuiltinValueDecl (ctx, name));
4518
4512
auto substMap =
4519
4513
SubstitutionMap::get (builtinFn->getGenericSignature (), substTypes,
@@ -4526,22 +4520,23 @@ MemberRefExpr *getInOutSelfInteropStaticCast(FuncDecl *funcDecl,
4526
4520
if (auto genericFnType = dyn_cast<GenericFunctionType>(fnType.getPointer ()))
4527
4521
fnType = genericFnType->substGenericArgs (substMap);
4528
4522
builtinFnRefExpr->setType (fnType);
4529
- auto *argList = ArgumentList::forImplicitUnlabeled (ctx, {arg});
4523
+ auto *argList = ArgumentList::createImplicit (ctx, {arg});
4530
4524
auto callExpr = CallExpr::create (ctx, builtinFnRefExpr, argList, /* implicit*/ true );
4531
4525
callExpr->setThrows (false );
4532
4526
return callExpr;
4533
4527
};
4534
4528
4535
- auto rawSelfPointer =
4536
- createCallToBuiltin ( ctx.getIdentifier (" addressof" ),
4537
- {derivedStruct-> getSelfInterfaceType ()}, inoutSelf );
4529
+ auto rawSelfPointer = createCallToBuiltin (
4530
+ ctx.getIdentifier (" addressof" ), {derivedStruct-> getSelfInterfaceType ()} ,
4531
+ Argument::implicitInOut (ctx, mutableSelf) );
4538
4532
rawSelfPointer->setType (ctx.TheRawPointerType );
4539
4533
4540
4534
auto derivedPtrType = derivedStruct->getSelfInterfaceType ()->wrapInPointer (
4541
4535
PTK_UnsafeMutablePointer);
4542
- auto selfPointer = createCallToBuiltin (
4543
- ctx.getIdentifier (" reinterpretCast" ),
4544
- {ctx.TheRawPointerType , derivedPtrType}, rawSelfPointer);
4536
+ auto selfPointer =
4537
+ createCallToBuiltin (ctx.getIdentifier (" reinterpretCast" ),
4538
+ {ctx.TheRawPointerType , derivedPtrType},
4539
+ Argument::unlabeled (rawSelfPointer));
4545
4540
selfPointer->setType (derivedPtrType);
4546
4541
4547
4542
auto staticCastRefExpr = getInteropStaticCastDeclRefExpr (
@@ -4601,14 +4596,11 @@ synthesizeBaseClassMethodBody(AbstractFunctionDecl *afd, void *context) {
4601
4596
forwardingParams.push_back (paramRefExpr);
4602
4597
}
4603
4598
4604
- Expr *casted = nullptr ;
4605
- if (funcDecl->isMutating ()) {
4606
- auto pointeeMemberRefExpr =
4607
- getInOutSelfInteropStaticCast (funcDecl, baseStruct, derivedStruct);
4608
- casted = new (ctx) InOutExpr (SourceLoc (), pointeeMemberRefExpr, baseType,
4609
- /* implicit*/ true );
4610
- casted->setType (InOutType::get (baseType));
4611
- } else {
4599
+ Argument casted = [&]() {
4600
+ if (funcDecl->isMutating ()) {
4601
+ return Argument::implicitInOut (
4602
+ ctx, getSelfInteropStaticCast (funcDecl, baseStruct, derivedStruct));
4603
+ }
4612
4604
auto *selfDecl = funcDecl->getImplicitSelfDecl ();
4613
4605
auto selfExpr = new (ctx) DeclRefExpr (selfDecl, DeclNameLoc (),
4614
4606
/* implicit*/ true );
@@ -4622,8 +4614,8 @@ synthesizeBaseClassMethodBody(AbstractFunctionDecl *afd, void *context) {
4622
4614
auto castedCall = CallExpr::createImplicit (ctx, staticCastRefExpr, argList);
4623
4615
castedCall->setType (baseType);
4624
4616
castedCall->setThrows (false );
4625
- casted = castedCall;
4626
- }
4617
+ return Argument::unlabeled ( castedCall) ;
4618
+ }();
4627
4619
4628
4620
auto *baseMemberExpr =
4629
4621
new (ctx) DeclRefExpr (ConcreteDeclRef (baseMember), DeclNameLoc (),
@@ -4727,7 +4719,7 @@ synthesizeBaseClassFieldSetterBody(AbstractFunctionDecl *afd, void *context) {
4727
4719
cast<NominalTypeDecl>(setterDecl->getDeclContext ()->getAsDecl ());
4728
4720
4729
4721
auto *pointeePropertyRefExpr =
4730
- getInOutSelfInteropStaticCast (setterDecl, baseStruct, derivedStruct);
4722
+ getSelfInteropStaticCast (setterDecl, baseStruct, derivedStruct);
4731
4723
4732
4724
Expr *storedRef = nullptr ;
4733
4725
if (auto subscript = dyn_cast<SubscriptDecl>(baseClassVar)) {
@@ -5442,7 +5434,7 @@ static ValueDecl *rewriteIntegerTypes(SubstitutionMap subst, ValueDecl *oldDecl,
5442
5434
return newDecl;
5443
5435
}
5444
5436
5445
- static Expr * createSelfExpr (FuncDecl *fnDecl) {
5437
+ static Argument createSelfArg (FuncDecl *fnDecl) {
5446
5438
ASTContext &ctx = fnDecl->getASTContext ();
5447
5439
5448
5440
auto selfDecl = fnDecl->getImplicitSelfDecl ();
@@ -5451,16 +5443,10 @@ static Expr *createSelfExpr(FuncDecl *fnDecl) {
5451
5443
5452
5444
if (!fnDecl->isMutating ()) {
5453
5445
selfRefExpr->setType (selfDecl->getInterfaceType ());
5454
- return selfRefExpr;
5446
+ return Argument::unlabeled ( selfRefExpr) ;
5455
5447
}
5456
5448
selfRefExpr->setType (LValueType::get (selfDecl->getInterfaceType ()));
5457
-
5458
- auto inoutSelfExpr = new (ctx) InOutExpr (
5459
- SourceLoc (), selfRefExpr,
5460
- fnDecl->mapTypeIntoContext (selfDecl->getValueInterfaceType ()),
5461
- /* isImplicit*/ true );
5462
- inoutSelfExpr->setType (InOutType::get (selfDecl->getInterfaceType ()));
5463
- return inoutSelfExpr;
5449
+ return Argument::implicitInOut (ctx, selfRefExpr);
5464
5450
}
5465
5451
5466
5452
// Synthesize a thunk body for the function created in
@@ -5481,30 +5467,30 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
5481
5467
paramIndex++;
5482
5468
continue ;
5483
5469
}
5470
+ auto paramTy = param->getType ();
5471
+ auto isInOut = param->isInOut ();
5472
+ auto specParamTy =
5473
+ specializedFuncDecl->getParameters ()->get (paramIndex)->getType ();
5484
5474
5485
5475
Expr *paramRefExpr = new (ctx) DeclRefExpr (param, DeclNameLoc (),
5486
5476
/* Implicit=*/ true );
5487
- paramRefExpr->setType (param->getType ());
5488
-
5489
- if (param->isInOut ()) {
5490
- paramRefExpr->setType (LValueType::get (param->getType ()));
5491
-
5492
- paramRefExpr = new (ctx) InOutExpr (
5493
- SourceLoc (), paramRefExpr, param->getType (), /* isImplicit*/ true );
5494
- paramRefExpr->setType (InOutType::get (param->getType ()));
5495
- }
5496
-
5497
- auto specParamTy = specializedFuncDecl->getParameters ()->get (paramIndex)->getType ();
5477
+ paramRefExpr->setType (isInOut ? LValueType::get (paramTy) : paramTy);
5498
5478
5499
- Expr *argExpr = nullptr ;
5500
- if (specParamTy->isEqual (param->getType ())) {
5501
- argExpr = paramRefExpr;
5502
- } else {
5503
- argExpr = ForcedCheckedCastExpr::createImplicit (ctx, paramRefExpr,
5504
- specParamTy);
5505
- }
5506
-
5507
- forwardingParams.push_back (Argument (SourceLoc (), Identifier (), argExpr));
5479
+ Argument arg = [&]() {
5480
+ if (isInOut) {
5481
+ assert (specParamTy->isEqual (paramTy));
5482
+ return Argument::implicitInOut (ctx, paramRefExpr);
5483
+ }
5484
+ Expr *argExpr = nullptr ;
5485
+ if (specParamTy->isEqual (paramTy)) {
5486
+ argExpr = paramRefExpr;
5487
+ } else {
5488
+ argExpr = ForcedCheckedCastExpr::createImplicit (ctx, paramRefExpr,
5489
+ specParamTy);
5490
+ }
5491
+ return Argument::unlabeled (argExpr);
5492
+ }();
5493
+ forwardingParams.push_back (arg);
5508
5494
paramIndex++;
5509
5495
}
5510
5496
@@ -5513,8 +5499,9 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
5513
5499
specializedFuncDeclRef->setType (specializedFuncDecl->getInterfaceType ());
5514
5500
5515
5501
if (specializedFuncDecl->isInstanceMember ()) {
5516
- auto selfExpr = createSelfExpr (thunkDecl);
5517
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfExpr);
5502
+ auto selfArg = createSelfArg (thunkDecl);
5503
+ auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef,
5504
+ SourceLoc (), selfArg);
5518
5505
memberCall->setThrows (false );
5519
5506
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5520
5507
specializedFuncDeclRef = memberCall;
@@ -5523,7 +5510,9 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
5523
5510
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5524
5511
auto selfType = cast<NominalTypeDecl>(thunkDecl->getDeclContext ()->getAsDecl ())->getDeclaredInterfaceType ();
5525
5512
auto selfTypeExpr = TypeExpr::createImplicit (selfType, ctx);
5526
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfTypeExpr);
5513
+ auto *memberCall =
5514
+ DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (),
5515
+ Argument::unlabeled (selfTypeExpr));
5527
5516
memberCall->setThrows (false );
5528
5517
specializedFuncDeclRef = memberCall;
5529
5518
specializedFuncDeclRef->setType (resultType);
@@ -5623,28 +5612,26 @@ synthesizeForwardingThunkBody(AbstractFunctionDecl *afd, void *context) {
5623
5612
if (isa<MetatypeType>(param->getType ().getPointer ())) {
5624
5613
continue ;
5625
5614
}
5615
+ auto paramTy = param->getType ();
5616
+ auto isInOut = param->isInOut ();
5617
+
5626
5618
Expr *paramRefExpr = new (ctx) DeclRefExpr (param, DeclNameLoc (),
5627
5619
/* Implicit=*/ true );
5628
- paramRefExpr->setType (param->getType ());
5629
-
5630
- if (param->isInOut ()) {
5631
- paramRefExpr->setType (LValueType::get (param->getType ()));
5632
-
5633
- paramRefExpr = new (ctx) InOutExpr (
5634
- SourceLoc (), paramRefExpr, param->getType (), /* isImplicit*/ true );
5635
- paramRefExpr->setType (InOutType::get (param->getType ()));
5636
- }
5620
+ paramRefExpr->setType (isInOut ? LValueType::get (paramTy) : paramTy);
5637
5621
5638
- forwardingParams.push_back (Argument (SourceLoc (), Identifier (), paramRefExpr));
5622
+ auto arg = isInOut ? Argument::implicitInOut (ctx, paramRefExpr)
5623
+ : Argument::unlabeled (paramRefExpr);
5624
+ forwardingParams.push_back (arg);
5639
5625
}
5640
5626
5641
5627
Expr *specializedFuncDeclRef = new (ctx) DeclRefExpr (ConcreteDeclRef (specializedFuncDecl),
5642
5628
DeclNameLoc (), true );
5643
5629
specializedFuncDeclRef->setType (specializedFuncDecl->getInterfaceType ());
5644
5630
5645
5631
if (specializedFuncDecl->isInstanceMember ()) {
5646
- auto selfExpr = createSelfExpr (thunkDecl);
5647
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfExpr);
5632
+ auto selfArg = createSelfArg (thunkDecl);
5633
+ auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef,
5634
+ SourceLoc (), selfArg);
5648
5635
memberCall->setThrows (false );
5649
5636
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5650
5637
specializedFuncDeclRef = memberCall;
@@ -5653,7 +5640,9 @@ synthesizeForwardingThunkBody(AbstractFunctionDecl *afd, void *context) {
5653
5640
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5654
5641
auto selfType = cast<NominalTypeDecl>(thunkDecl->getDeclContext ()->getAsDecl ())->getDeclaredInterfaceType ();
5655
5642
auto selfTypeExpr = TypeExpr::createImplicit (selfType, ctx);
5656
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfTypeExpr);
5643
+ auto *memberCall =
5644
+ DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (),
5645
+ Argument::unlabeled (selfTypeExpr));
5657
5646
memberCall->setThrows (false );
5658
5647
specializedFuncDeclRef = memberCall;
5659
5648
specializedFuncDeclRef->setType (resultType);
0 commit comments