@@ -4444,29 +4444,23 @@ DeclRefExpr *getInteropStaticCastDeclRefExpr(ASTContext &ctx,
4444
4444
// %2 = __swift_interopStaticCast<UnsafeMutablePointer<Base>?>(%1)
4445
4445
// %3 = %2!
4446
4446
// return %3.pointee
4447
- MemberRefExpr *getInOutSelfInteropStaticCast (FuncDecl *funcDecl,
4448
- NominalTypeDecl *baseStruct,
4449
- NominalTypeDecl *derivedStruct) {
4447
+ MemberRefExpr *getSelfInteropStaticCast (FuncDecl *funcDecl,
4448
+ NominalTypeDecl *baseStruct,
4449
+ NominalTypeDecl *derivedStruct) {
4450
4450
auto &ctx = funcDecl->getASTContext ();
4451
4451
4452
- auto inoutSelf = [&ctx](FuncDecl *funcDecl) {
4453
- auto inoutSelfDecl = funcDecl->getImplicitSelfDecl ();
4452
+ auto mutableSelf = [&ctx](FuncDecl *funcDecl) {
4453
+ auto selfDecl = funcDecl->getImplicitSelfDecl ();
4454
4454
4455
- auto inoutSelfRef =
4456
- new (ctx) DeclRefExpr (inoutSelfDecl , DeclNameLoc (), /* implicit*/ true );
4457
- inoutSelfRef ->setType (LValueType::get (inoutSelfDecl ->getInterfaceType ()));
4455
+ auto selfRef =
4456
+ new (ctx) DeclRefExpr (selfDecl , DeclNameLoc (), /* implicit*/ true );
4457
+ selfRef ->setType (LValueType::get (selfDecl ->getInterfaceType ()));
4458
4458
4459
- auto inoutSelf = new (ctx) InOutExpr (
4460
- SourceLoc (), inoutSelfRef,
4461
- funcDecl->mapTypeIntoContext (inoutSelfDecl->getValueInterfaceType ()),
4462
- /* implicit*/ true );
4463
- inoutSelf->setType (InOutType::get (inoutSelfDecl->getInterfaceType ()));
4464
-
4465
- return inoutSelf;
4459
+ return selfRef;
4466
4460
}(funcDecl);
4467
4461
4468
4462
auto createCallToBuiltin = [&](Identifier name, ArrayRef<Type> substTypes,
4469
- Expr * arg) {
4463
+ Argument arg) {
4470
4464
auto builtinFn = cast<FuncDecl>(getBuiltinValueDecl (ctx, name));
4471
4465
auto substMap =
4472
4466
SubstitutionMap::get (builtinFn->getGenericSignature (), substTypes,
@@ -4479,22 +4473,23 @@ MemberRefExpr *getInOutSelfInteropStaticCast(FuncDecl *funcDecl,
4479
4473
if (auto genericFnType = dyn_cast<GenericFunctionType>(fnType.getPointer ()))
4480
4474
fnType = genericFnType->substGenericArgs (substMap);
4481
4475
builtinFnRefExpr->setType (fnType);
4482
- auto *argList = ArgumentList::forImplicitUnlabeled (ctx, {arg});
4476
+ auto *argList = ArgumentList::createImplicit (ctx, {arg});
4483
4477
auto callExpr = CallExpr::create (ctx, builtinFnRefExpr, argList, /* implicit*/ true );
4484
4478
callExpr->setThrows (false );
4485
4479
return callExpr;
4486
4480
};
4487
4481
4488
- auto rawSelfPointer =
4489
- createCallToBuiltin ( ctx.getIdentifier (" addressof" ),
4490
- {derivedStruct-> getSelfInterfaceType ()}, inoutSelf );
4482
+ auto rawSelfPointer = createCallToBuiltin (
4483
+ ctx.getIdentifier (" addressof" ), {derivedStruct-> getSelfInterfaceType ()} ,
4484
+ Argument::implicitInOut (ctx, mutableSelf) );
4491
4485
rawSelfPointer->setType (ctx.TheRawPointerType );
4492
4486
4493
4487
auto derivedPtrType = derivedStruct->getSelfInterfaceType ()->wrapInPointer (
4494
4488
PTK_UnsafeMutablePointer);
4495
- auto selfPointer = createCallToBuiltin (
4496
- ctx.getIdentifier (" reinterpretCast" ),
4497
- {ctx.TheRawPointerType , derivedPtrType}, rawSelfPointer);
4489
+ auto selfPointer =
4490
+ createCallToBuiltin (ctx.getIdentifier (" reinterpretCast" ),
4491
+ {ctx.TheRawPointerType , derivedPtrType},
4492
+ Argument::unlabeled (rawSelfPointer));
4498
4493
selfPointer->setType (derivedPtrType);
4499
4494
4500
4495
auto staticCastRefExpr = getInteropStaticCastDeclRefExpr (
@@ -4554,14 +4549,11 @@ synthesizeBaseClassMethodBody(AbstractFunctionDecl *afd, void *context) {
4554
4549
forwardingParams.push_back (paramRefExpr);
4555
4550
}
4556
4551
4557
- Expr *casted = nullptr ;
4558
- if (funcDecl->isMutating ()) {
4559
- auto pointeeMemberRefExpr =
4560
- getInOutSelfInteropStaticCast (funcDecl, baseStruct, derivedStruct);
4561
- casted = new (ctx) InOutExpr (SourceLoc (), pointeeMemberRefExpr, baseType,
4562
- /* implicit*/ true );
4563
- casted->setType (InOutType::get (baseType));
4564
- } else {
4552
+ Argument casted = [&]() {
4553
+ if (funcDecl->isMutating ()) {
4554
+ return Argument::implicitInOut (
4555
+ ctx, getSelfInteropStaticCast (funcDecl, baseStruct, derivedStruct));
4556
+ }
4565
4557
auto *selfDecl = funcDecl->getImplicitSelfDecl ();
4566
4558
auto selfExpr = new (ctx) DeclRefExpr (selfDecl, DeclNameLoc (),
4567
4559
/* implicit*/ true );
@@ -4575,8 +4567,8 @@ synthesizeBaseClassMethodBody(AbstractFunctionDecl *afd, void *context) {
4575
4567
auto castedCall = CallExpr::createImplicit (ctx, staticCastRefExpr, argList);
4576
4568
castedCall->setType (baseType);
4577
4569
castedCall->setThrows (false );
4578
- casted = castedCall;
4579
- }
4570
+ return Argument::unlabeled ( castedCall) ;
4571
+ }();
4580
4572
4581
4573
auto *baseMemberExpr =
4582
4574
new (ctx) DeclRefExpr (ConcreteDeclRef (baseMember), DeclNameLoc (),
@@ -4680,7 +4672,7 @@ synthesizeBaseClassFieldSetterBody(AbstractFunctionDecl *afd, void *context) {
4680
4672
cast<NominalTypeDecl>(setterDecl->getDeclContext ()->getAsDecl ());
4681
4673
4682
4674
auto *pointeePropertyRefExpr =
4683
- getInOutSelfInteropStaticCast (setterDecl, baseStruct, derivedStruct);
4675
+ getSelfInteropStaticCast (setterDecl, baseStruct, derivedStruct);
4684
4676
4685
4677
Expr *storedRef = nullptr ;
4686
4678
if (auto subscript = dyn_cast<SubscriptDecl>(baseClassVar)) {
@@ -5395,7 +5387,7 @@ static ValueDecl *rewriteIntegerTypes(SubstitutionMap subst, ValueDecl *oldDecl,
5395
5387
return newDecl;
5396
5388
}
5397
5389
5398
- static Expr * createSelfExpr (FuncDecl *fnDecl) {
5390
+ static Argument createSelfArg (FuncDecl *fnDecl) {
5399
5391
ASTContext &ctx = fnDecl->getASTContext ();
5400
5392
5401
5393
auto selfDecl = fnDecl->getImplicitSelfDecl ();
@@ -5404,16 +5396,10 @@ static Expr *createSelfExpr(FuncDecl *fnDecl) {
5404
5396
5405
5397
if (!fnDecl->isMutating ()) {
5406
5398
selfRefExpr->setType (selfDecl->getInterfaceType ());
5407
- return selfRefExpr;
5399
+ return Argument::unlabeled ( selfRefExpr) ;
5408
5400
}
5409
5401
selfRefExpr->setType (LValueType::get (selfDecl->getInterfaceType ()));
5410
-
5411
- auto inoutSelfExpr = new (ctx) InOutExpr (
5412
- SourceLoc (), selfRefExpr,
5413
- fnDecl->mapTypeIntoContext (selfDecl->getValueInterfaceType ()),
5414
- /* isImplicit*/ true );
5415
- inoutSelfExpr->setType (InOutType::get (selfDecl->getInterfaceType ()));
5416
- return inoutSelfExpr;
5402
+ return Argument::implicitInOut (ctx, selfRefExpr);
5417
5403
}
5418
5404
5419
5405
// Synthesize a thunk body for the function created in
@@ -5434,30 +5420,30 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
5434
5420
paramIndex++;
5435
5421
continue ;
5436
5422
}
5423
+ auto paramTy = param->getType ();
5424
+ auto isInOut = param->isInOut ();
5425
+ auto specParamTy =
5426
+ specializedFuncDecl->getParameters ()->get (paramIndex)->getType ();
5437
5427
5438
5428
Expr *paramRefExpr = new (ctx) DeclRefExpr (param, DeclNameLoc (),
5439
5429
/* Implicit=*/ true );
5440
- paramRefExpr->setType (param->getType ());
5441
-
5442
- if (param->isInOut ()) {
5443
- paramRefExpr->setType (LValueType::get (param->getType ()));
5444
-
5445
- paramRefExpr = new (ctx) InOutExpr (
5446
- SourceLoc (), paramRefExpr, param->getType (), /* isImplicit*/ true );
5447
- paramRefExpr->setType (InOutType::get (param->getType ()));
5448
- }
5449
-
5450
- auto specParamTy = specializedFuncDecl->getParameters ()->get (paramIndex)->getType ();
5430
+ paramRefExpr->setType (isInOut ? LValueType::get (paramTy) : paramTy);
5451
5431
5452
- Expr *argExpr = nullptr ;
5453
- if (specParamTy->isEqual (param->getType ())) {
5454
- argExpr = paramRefExpr;
5455
- } else {
5456
- argExpr = ForcedCheckedCastExpr::createImplicit (ctx, paramRefExpr,
5457
- specParamTy);
5458
- }
5459
-
5460
- forwardingParams.push_back (Argument (SourceLoc (), Identifier (), argExpr));
5432
+ Argument arg = [&]() {
5433
+ if (isInOut) {
5434
+ assert (specParamTy->isEqual (paramTy));
5435
+ return Argument::implicitInOut (ctx, paramRefExpr);
5436
+ }
5437
+ Expr *argExpr = nullptr ;
5438
+ if (specParamTy->isEqual (paramTy)) {
5439
+ argExpr = paramRefExpr;
5440
+ } else {
5441
+ argExpr = ForcedCheckedCastExpr::createImplicit (ctx, paramRefExpr,
5442
+ specParamTy);
5443
+ }
5444
+ return Argument::unlabeled (argExpr);
5445
+ }();
5446
+ forwardingParams.push_back (arg);
5461
5447
paramIndex++;
5462
5448
}
5463
5449
@@ -5466,8 +5452,9 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
5466
5452
specializedFuncDeclRef->setType (specializedFuncDecl->getInterfaceType ());
5467
5453
5468
5454
if (specializedFuncDecl->isInstanceMember ()) {
5469
- auto selfExpr = createSelfExpr (thunkDecl);
5470
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfExpr);
5455
+ auto selfArg = createSelfArg (thunkDecl);
5456
+ auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef,
5457
+ SourceLoc (), selfArg);
5471
5458
memberCall->setThrows (false );
5472
5459
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5473
5460
specializedFuncDeclRef = memberCall;
@@ -5476,7 +5463,9 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
5476
5463
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5477
5464
auto selfType = cast<NominalTypeDecl>(thunkDecl->getDeclContext ()->getAsDecl ())->getDeclaredInterfaceType ();
5478
5465
auto selfTypeExpr = TypeExpr::createImplicit (selfType, ctx);
5479
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfTypeExpr);
5466
+ auto *memberCall =
5467
+ DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (),
5468
+ Argument::unlabeled (selfTypeExpr));
5480
5469
memberCall->setThrows (false );
5481
5470
specializedFuncDeclRef = memberCall;
5482
5471
specializedFuncDeclRef->setType (resultType);
@@ -5576,28 +5565,26 @@ synthesizeForwardingThunkBody(AbstractFunctionDecl *afd, void *context) {
5576
5565
if (isa<MetatypeType>(param->getType ().getPointer ())) {
5577
5566
continue ;
5578
5567
}
5568
+ auto paramTy = param->getType ();
5569
+ auto isInOut = param->isInOut ();
5570
+
5579
5571
Expr *paramRefExpr = new (ctx) DeclRefExpr (param, DeclNameLoc (),
5580
5572
/* Implicit=*/ true );
5581
- paramRefExpr->setType (param->getType ());
5582
-
5583
- if (param->isInOut ()) {
5584
- paramRefExpr->setType (LValueType::get (param->getType ()));
5585
-
5586
- paramRefExpr = new (ctx) InOutExpr (
5587
- SourceLoc (), paramRefExpr, param->getType (), /* isImplicit*/ true );
5588
- paramRefExpr->setType (InOutType::get (param->getType ()));
5589
- }
5573
+ paramRefExpr->setType (isInOut ? LValueType::get (paramTy) : paramTy);
5590
5574
5591
- forwardingParams.push_back (Argument (SourceLoc (), Identifier (), paramRefExpr));
5575
+ auto arg = isInOut ? Argument::implicitInOut (ctx, paramRefExpr)
5576
+ : Argument::unlabeled (paramRefExpr);
5577
+ forwardingParams.push_back (arg);
5592
5578
}
5593
5579
5594
5580
Expr *specializedFuncDeclRef = new (ctx) DeclRefExpr (ConcreteDeclRef (specializedFuncDecl),
5595
5581
DeclNameLoc (), true );
5596
5582
specializedFuncDeclRef->setType (specializedFuncDecl->getInterfaceType ());
5597
5583
5598
5584
if (specializedFuncDecl->isInstanceMember ()) {
5599
- auto selfExpr = createSelfExpr (thunkDecl);
5600
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfExpr);
5585
+ auto selfArg = createSelfArg (thunkDecl);
5586
+ auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef,
5587
+ SourceLoc (), selfArg);
5601
5588
memberCall->setThrows (false );
5602
5589
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5603
5590
specializedFuncDeclRef = memberCall;
@@ -5606,7 +5593,9 @@ synthesizeForwardingThunkBody(AbstractFunctionDecl *afd, void *context) {
5606
5593
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5607
5594
auto selfType = cast<NominalTypeDecl>(thunkDecl->getDeclContext ()->getAsDecl ())->getDeclaredInterfaceType ();
5608
5595
auto selfTypeExpr = TypeExpr::createImplicit (selfType, ctx);
5609
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfTypeExpr);
5596
+ auto *memberCall =
5597
+ DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (),
5598
+ Argument::unlabeled (selfTypeExpr));
5610
5599
memberCall->setThrows (false );
5611
5600
specializedFuncDeclRef = memberCall;
5612
5601
specializedFuncDeclRef->setType (resultType);
0 commit comments