@@ -3847,7 +3847,14 @@ static void printParameterFlags(ASTPrinter &printer,
3847
3847
const PrintOptions &options,
3848
3848
const ParamDecl *param,
3849
3849
ParameterTypeFlags flags,
3850
- bool escaping) {
3850
+ bool escaping,
3851
+ bool isIsolatedToCaller = false ) {
3852
+ // Always print `nonisolated(nonsending)` specifier on a parameter
3853
+ // first, to avoid any issues with ordering.
3854
+ if (isIsolatedToCaller) {
3855
+ printer.printKeyword (" nonisolated(nonsending)" , options, " " );
3856
+ }
3857
+
3851
3858
if (!options.excludeAttrKind (TypeAttrKind::Autoclosure) &&
3852
3859
flags.isAutoClosure ())
3853
3860
printer.printAttrName (" @autoclosure " );
@@ -4016,11 +4023,24 @@ void PrintAST::printOneParameter(const ParamDecl *param,
4016
4023
4017
4024
printArgName ();
4018
4025
4026
+ auto interfaceTy = param->getInterfaceType ();
4027
+
4028
+ // If type of this parameter is isolated to a caller, let's
4029
+ // strip the isolation from the type to avoid printing it as
4030
+ // part of the function type because that would break ordering
4031
+ // between specifiers and attributes.
4032
+ if (param->isCallerIsolated ()) {
4033
+ if (auto *funcTy = dyn_cast<AnyFunctionType>(interfaceTy.getPointer ())) {
4034
+ interfaceTy =
4035
+ funcTy->withIsolation (FunctionTypeIsolation::forNonIsolated ());
4036
+ }
4037
+ }
4038
+
4019
4039
TypeLoc TheTypeLoc;
4020
4040
if (auto *repr = param->getTypeRepr ()) {
4021
- TheTypeLoc = TypeLoc (repr, param-> getInterfaceType () );
4041
+ TheTypeLoc = TypeLoc (repr, interfaceTy );
4022
4042
} else {
4023
- TheTypeLoc = TypeLoc::withoutLoc (param-> getInterfaceType () );
4043
+ TheTypeLoc = TypeLoc::withoutLoc (interfaceTy );
4024
4044
}
4025
4045
4026
4046
{
@@ -4032,7 +4052,8 @@ void PrintAST::printOneParameter(const ParamDecl *param,
4032
4052
!willUseTypeReprPrinting (TheTypeLoc, CurrentType, Options)) {
4033
4053
auto type = TheTypeLoc.getType ();
4034
4054
printParameterFlags (Printer, Options, param, paramFlags,
4035
- isEscaping (type));
4055
+ isEscaping (type),
4056
+ param->isCallerIsolated ());
4036
4057
}
4037
4058
4038
4059
printTypeLocForImplicitlyUnwrappedOptional (
0 commit comments