@@ -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)) {
@@ -5378,7 +5370,7 @@ static ValueDecl *rewriteIntegerTypes(SubstitutionMap subst, ValueDecl *oldDecl,
5378
5370
return newDecl;
5379
5371
}
5380
5372
5381
- static Expr * createSelfExpr (FuncDecl *fnDecl) {
5373
+ static Argument createSelfArg (FuncDecl *fnDecl) {
5382
5374
ASTContext &ctx = fnDecl->getASTContext ();
5383
5375
5384
5376
auto selfDecl = fnDecl->getImplicitSelfDecl ();
@@ -5387,16 +5379,10 @@ static Expr *createSelfExpr(FuncDecl *fnDecl) {
5387
5379
5388
5380
if (!fnDecl->isMutating ()) {
5389
5381
selfRefExpr->setType (selfDecl->getInterfaceType ());
5390
- return selfRefExpr;
5382
+ return Argument::unlabeled ( selfRefExpr) ;
5391
5383
}
5392
5384
selfRefExpr->setType (LValueType::get (selfDecl->getInterfaceType ()));
5393
-
5394
- auto inoutSelfExpr = new (ctx) InOutExpr (
5395
- SourceLoc (), selfRefExpr,
5396
- fnDecl->mapTypeIntoContext (selfDecl->getValueInterfaceType ()),
5397
- /* isImplicit*/ true );
5398
- inoutSelfExpr->setType (InOutType::get (selfDecl->getInterfaceType ()));
5399
- return inoutSelfExpr;
5385
+ return Argument::implicitInOut (ctx, selfRefExpr);
5400
5386
}
5401
5387
5402
5388
// Synthesize a thunk body for the function created in
@@ -5449,8 +5435,9 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
5449
5435
specializedFuncDeclRef->setType (specializedFuncDecl->getInterfaceType ());
5450
5436
5451
5437
if (specializedFuncDecl->isInstanceMember ()) {
5452
- auto selfExpr = createSelfExpr (thunkDecl);
5453
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfExpr);
5438
+ auto selfArg = createSelfArg (thunkDecl);
5439
+ auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef,
5440
+ SourceLoc (), selfArg);
5454
5441
memberCall->setThrows (false );
5455
5442
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5456
5443
specializedFuncDeclRef = memberCall;
@@ -5459,7 +5446,9 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
5459
5446
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5460
5447
auto selfType = cast<NominalTypeDecl>(thunkDecl->getDeclContext ()->getAsDecl ())->getDeclaredInterfaceType ();
5461
5448
auto selfTypeExpr = TypeExpr::createImplicit (selfType, ctx);
5462
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfTypeExpr);
5449
+ auto *memberCall =
5450
+ DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (),
5451
+ Argument::unlabeled (selfTypeExpr));
5463
5452
memberCall->setThrows (false );
5464
5453
specializedFuncDeclRef = memberCall;
5465
5454
specializedFuncDeclRef->setType (resultType);
@@ -5576,8 +5565,9 @@ synthesizeForwardingThunkBody(AbstractFunctionDecl *afd, void *context) {
5576
5565
specializedFuncDeclRef->setType (specializedFuncDecl->getInterfaceType ());
5577
5566
5578
5567
if (specializedFuncDecl->isInstanceMember ()) {
5579
- auto selfExpr = createSelfExpr (thunkDecl);
5580
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfExpr);
5568
+ auto selfArg = createSelfArg (thunkDecl);
5569
+ auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef,
5570
+ SourceLoc (), selfArg);
5581
5571
memberCall->setThrows (false );
5582
5572
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5583
5573
specializedFuncDeclRef = memberCall;
@@ -5586,7 +5576,9 @@ synthesizeForwardingThunkBody(AbstractFunctionDecl *afd, void *context) {
5586
5576
auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
5587
5577
auto selfType = cast<NominalTypeDecl>(thunkDecl->getDeclContext ()->getAsDecl ())->getDeclaredInterfaceType ();
5588
5578
auto selfTypeExpr = TypeExpr::createImplicit (selfType, ctx);
5589
- auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfTypeExpr);
5579
+ auto *memberCall =
5580
+ DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (),
5581
+ Argument::unlabeled (selfTypeExpr));
5590
5582
memberCall->setThrows (false );
5591
5583
specializedFuncDeclRef = memberCall;
5592
5584
specializedFuncDeclRef->setType (resultType);
0 commit comments