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