@@ -4491,29 +4491,23 @@ DeclRefExpr *getInteropStaticCastDeclRefExpr(ASTContext &ctx,
44914491// %2 = __swift_interopStaticCast<UnsafeMutablePointer<Base>?>(%1)
44924492// %3 = %2!
44934493// 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) {
44974497 auto &ctx = funcDecl->getASTContext ();
44984498
4499- auto inoutSelf = [&ctx](FuncDecl *funcDecl) {
4500- auto inoutSelfDecl = funcDecl->getImplicitSelfDecl ();
4499+ auto mutableSelf = [&ctx](FuncDecl *funcDecl) {
4500+ auto selfDecl = funcDecl->getImplicitSelfDecl ();
45014501
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 ()));
45054505
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;
45134507 }(funcDecl);
45144508
45154509 auto createCallToBuiltin = [&](Identifier name, ArrayRef<Type> substTypes,
4516- Expr * arg) {
4510+ Argument arg) {
45174511 auto builtinFn = cast<FuncDecl>(getBuiltinValueDecl (ctx, name));
45184512 auto substMap =
45194513 SubstitutionMap::get (builtinFn->getGenericSignature (), substTypes,
@@ -4526,22 +4520,23 @@ MemberRefExpr *getInOutSelfInteropStaticCast(FuncDecl *funcDecl,
45264520 if (auto genericFnType = dyn_cast<GenericFunctionType>(fnType.getPointer ()))
45274521 fnType = genericFnType->substGenericArgs (substMap);
45284522 builtinFnRefExpr->setType (fnType);
4529- auto *argList = ArgumentList::forImplicitUnlabeled (ctx, {arg});
4523+ auto *argList = ArgumentList::createImplicit (ctx, {arg});
45304524 auto callExpr = CallExpr::create (ctx, builtinFnRefExpr, argList, /* implicit*/ true );
45314525 callExpr->setThrows (false );
45324526 return callExpr;
45334527 };
45344528
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) );
45384532 rawSelfPointer->setType (ctx.TheRawPointerType );
45394533
45404534 auto derivedPtrType = derivedStruct->getSelfInterfaceType ()->wrapInPointer (
45414535 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));
45454540 selfPointer->setType (derivedPtrType);
45464541
45474542 auto staticCastRefExpr = getInteropStaticCastDeclRefExpr (
@@ -4601,14 +4596,11 @@ synthesizeBaseClassMethodBody(AbstractFunctionDecl *afd, void *context) {
46014596 forwardingParams.push_back (paramRefExpr);
46024597 }
46034598
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+ }
46124604 auto *selfDecl = funcDecl->getImplicitSelfDecl ();
46134605 auto selfExpr = new (ctx) DeclRefExpr (selfDecl, DeclNameLoc (),
46144606 /* implicit*/ true );
@@ -4622,8 +4614,8 @@ synthesizeBaseClassMethodBody(AbstractFunctionDecl *afd, void *context) {
46224614 auto castedCall = CallExpr::createImplicit (ctx, staticCastRefExpr, argList);
46234615 castedCall->setType (baseType);
46244616 castedCall->setThrows (false );
4625- casted = castedCall;
4626- }
4617+ return Argument::unlabeled ( castedCall) ;
4618+ }();
46274619
46284620 auto *baseMemberExpr =
46294621 new (ctx) DeclRefExpr (ConcreteDeclRef (baseMember), DeclNameLoc (),
@@ -4727,7 +4719,7 @@ synthesizeBaseClassFieldSetterBody(AbstractFunctionDecl *afd, void *context) {
47274719 cast<NominalTypeDecl>(setterDecl->getDeclContext ()->getAsDecl ());
47284720
47294721 auto *pointeePropertyRefExpr =
4730- getInOutSelfInteropStaticCast (setterDecl, baseStruct, derivedStruct);
4722+ getSelfInteropStaticCast (setterDecl, baseStruct, derivedStruct);
47314723
47324724 Expr *storedRef = nullptr ;
47334725 if (auto subscript = dyn_cast<SubscriptDecl>(baseClassVar)) {
@@ -5442,7 +5434,7 @@ static ValueDecl *rewriteIntegerTypes(SubstitutionMap subst, ValueDecl *oldDecl,
54425434 return newDecl;
54435435}
54445436
5445- static Expr * createSelfExpr (FuncDecl *fnDecl) {
5437+ static Argument createSelfArg (FuncDecl *fnDecl) {
54465438 ASTContext &ctx = fnDecl->getASTContext ();
54475439
54485440 auto selfDecl = fnDecl->getImplicitSelfDecl ();
@@ -5451,16 +5443,10 @@ static Expr *createSelfExpr(FuncDecl *fnDecl) {
54515443
54525444 if (!fnDecl->isMutating ()) {
54535445 selfRefExpr->setType (selfDecl->getInterfaceType ());
5454- return selfRefExpr;
5446+ return Argument::unlabeled ( selfRefExpr) ;
54555447 }
54565448 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);
54645450}
54655451
54665452// Synthesize a thunk body for the function created in
@@ -5481,30 +5467,30 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
54815467 paramIndex++;
54825468 continue ;
54835469 }
5470+ auto paramTy = param->getType ();
5471+ auto isInOut = param->isInOut ();
5472+ auto specParamTy =
5473+ specializedFuncDecl->getParameters ()->get (paramIndex)->getType ();
54845474
54855475 Expr *paramRefExpr = new (ctx) DeclRefExpr (param, DeclNameLoc (),
54865476 /* 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);
54985478
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);
55085494 paramIndex++;
55095495 }
55105496
@@ -5513,8 +5499,9 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
55135499 specializedFuncDeclRef->setType (specializedFuncDecl->getInterfaceType ());
55145500
55155501 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);
55185505 memberCall->setThrows (false );
55195506 auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
55205507 specializedFuncDeclRef = memberCall;
@@ -5523,7 +5510,9 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
55235510 auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
55245511 auto selfType = cast<NominalTypeDecl>(thunkDecl->getDeclContext ()->getAsDecl ())->getDeclaredInterfaceType ();
55255512 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));
55275516 memberCall->setThrows (false );
55285517 specializedFuncDeclRef = memberCall;
55295518 specializedFuncDeclRef->setType (resultType);
@@ -5623,28 +5612,26 @@ synthesizeForwardingThunkBody(AbstractFunctionDecl *afd, void *context) {
56235612 if (isa<MetatypeType>(param->getType ().getPointer ())) {
56245613 continue ;
56255614 }
5615+ auto paramTy = param->getType ();
5616+ auto isInOut = param->isInOut ();
5617+
56265618 Expr *paramRefExpr = new (ctx) DeclRefExpr (param, DeclNameLoc (),
56275619 /* 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);
56375621
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);
56395625 }
56405626
56415627 Expr *specializedFuncDeclRef = new (ctx) DeclRefExpr (ConcreteDeclRef (specializedFuncDecl),
56425628 DeclNameLoc (), true );
56435629 specializedFuncDeclRef->setType (specializedFuncDecl->getInterfaceType ());
56445630
56455631 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);
56485635 memberCall->setThrows (false );
56495636 auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
56505637 specializedFuncDeclRef = memberCall;
@@ -5653,7 +5640,9 @@ synthesizeForwardingThunkBody(AbstractFunctionDecl *afd, void *context) {
56535640 auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
56545641 auto selfType = cast<NominalTypeDecl>(thunkDecl->getDeclContext ()->getAsDecl ())->getDeclaredInterfaceType ();
56555642 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));
56575646 memberCall->setThrows (false );
56585647 specializedFuncDeclRef = memberCall;
56595648 specializedFuncDeclRef->setType (resultType);
0 commit comments