@@ -2418,6 +2418,11 @@ namespace {
24182418 class TypeAttrSet {
24192419 const ASTContext &ctx;
24202420
2421+ // / FIXME:
2422+ // / `nonisolated(nonsending)` is modeled as a separate `TypeRepr`, but
2423+ // / needs to be considered together with subsequent attributes.
2424+ CallerIsolatedTypeRepr *nonisolatedNonsendingAttr;
2425+
24212426 llvm::TinyPtrVector<CustomAttr*> customAttrs;
24222427 EnumMap<TypeAttrKind, TypeAttribute *> typeAttrs;
24232428
@@ -2429,7 +2434,9 @@ namespace {
24292434#endif
24302435
24312436 public:
2432- TypeAttrSet (const ASTContext &ctx) : ctx(ctx) {}
2437+ TypeAttrSet (const ASTContext &ctx,
2438+ CallerIsolatedTypeRepr *nonisolatedNonsendingAttr = nullptr )
2439+ : ctx(ctx), nonisolatedNonsendingAttr(nonisolatedNonsendingAttr) {}
24332440
24342441 TypeAttrSet (const TypeAttrSet &) = delete ;
24352442 TypeAttrSet &operator =(const TypeAttrSet &) = delete ;
@@ -2448,6 +2455,10 @@ namespace {
24482455 // / will be diagnosed.
24492456 void accumulate (ArrayRef<TypeOrCustomAttr> attrs);
24502457
2458+ CallerIsolatedTypeRepr *getNonisolatedNonsendingAttr () const {
2459+ return nonisolatedNonsendingAttr;
2460+ }
2461+
24512462 // / Return all of the custom attributes.
24522463 ArrayRef<CustomAttr*> getCustomAttrs () const {
24532464 return customAttrs;
@@ -2547,9 +2558,17 @@ namespace {
25472558 }
25482559
25492560 template <class AttrClass >
2550- AttrClass *getWithoutClaiming (TypeAttrSet *attrs) {
2561+ std::enable_if_t <std::is_base_of_v<TypeAttribute, AttrClass>, AttrClass *>
2562+ getWithoutClaiming (TypeAttrSet *attrs) {
25512563 return (attrs ? getWithoutClaiming<AttrClass>(*attrs) : nullptr );
25522564 }
2565+
2566+ template <class AttrClass >
2567+ std::enable_if_t <std::is_same_v<AttrClass, CallerIsolatedTypeRepr>,
2568+ CallerIsolatedTypeRepr *>
2569+ getWithoutClaiming (TypeAttrSet *attrs) {
2570+ return attrs ? attrs->getNonisolatedNonsendingAttr () : nullptr ;
2571+ }
25532572} // end anonymous namespace
25542573
25552574Type TypeResolution::resolveContextualType (
@@ -4247,10 +4266,19 @@ NeverNullType TypeResolver::resolveASTFunctionType(
42474266 };
42484267
42494268 if (auto concurrentAttr = claim<ConcurrentTypeAttr>(attrs)) {
4269+ if (auto *nonisolatedNonsendingAttr =
4270+ getWithoutClaiming<CallerIsolatedTypeRepr>(attrs)) {
4271+ diagnoseInvalid (
4272+ nonisolatedNonsendingAttr, nonisolatedNonsendingAttr->getStartLoc (),
4273+ diag::cannot_use_nonisolated_nonsending_together_with_concurrent,
4274+ nonisolatedNonsendingAttr);
4275+ }
4276+
42504277 checkExecutionBehaviorAttribute (concurrentAttr);
4278+
42514279 if (!repr->isInvalid ())
42524280 isolation = FunctionTypeIsolation::forNonIsolated ();
4253- } else {
4281+ } else if (!getWithoutClaiming<CallerIsolatedTypeRepr>(attrs)) {
42544282 if (ctx.LangOpts .getFeatureState (Feature::NonisolatedNonsendingByDefault)
42554283 .isEnabledForMigration ()) {
42564284 // Diagnose only in the interface stage, which is run once.
@@ -5281,7 +5309,20 @@ TypeResolver::resolveSendingTypeRepr(SendingTypeRepr *repr,
52815309NeverNullType
52825310TypeResolver::resolveCallerIsolatedTypeRepr (CallerIsolatedTypeRepr *repr,
52835311 TypeResolutionOptions options) {
5284- Type type = resolveType (repr->getBase (), options);
5312+ Type type;
5313+ {
5314+ TypeAttrSet attrs (getASTContext (), repr);
5315+
5316+ auto *baseRepr = repr->getBase ();
5317+ if (auto *attrRepr = dyn_cast<AttributedTypeRepr>(baseRepr)) {
5318+ baseRepr = attrs.accumulate (attrRepr);
5319+ }
5320+
5321+ type = resolveAttributedType (baseRepr, options, attrs);
5322+
5323+ attrs.diagnoseUnclaimed (resolution, options, type);
5324+ }
5325+
52855326 if (type->hasError ())
52865327 return ErrorType::get (getASTContext ());
52875328
@@ -5297,15 +5338,6 @@ TypeResolver::resolveCallerIsolatedTypeRepr(CallerIsolatedTypeRepr *repr,
52975338 diag::nonisolated_nonsending_only_on_async, repr);
52985339 }
52995340
5300- if (auto *ATR = dyn_cast<AttributedTypeRepr>(repr->getBase ())) {
5301- if (ATR->get (TypeAttrKind::Concurrent)) {
5302- diagnoseInvalid (
5303- repr, repr->getStartLoc (),
5304- diag::cannot_use_nonisolated_nonsending_together_with_concurrent,
5305- repr);
5306- }
5307- }
5308-
53095341 switch (fnType->getIsolation ().getKind ()) {
53105342 case FunctionTypeIsolation::Kind::NonIsolated:
53115343 break ;
0 commit comments