@@ -286,6 +286,37 @@ static Type getIdentityOpaqueTypeArchetypeType(
286
286
return OpaqueTypeArchetypeType::get (opaqueDecl, interfaceType, subs);
287
287
}
288
288
289
+ // / Adjust the underlying type of a typealias within the given context to
290
+ // / account for @preconcurrency.
291
+ static Type adjustTypeAliasTypeInContext (
292
+ Type type, TypeAliasDecl *aliasDecl, DeclContext *fromDC,
293
+ TypeResolutionOptions options) {
294
+ // If we are in a @preconcurrency declaration, don't adjust the types of
295
+ // type aliases.
296
+ if (options.contains (TypeResolutionFlags::Preconcurrency))
297
+ return type;
298
+
299
+ // If the type alias itself isn't marked with @preconcurrency, don't
300
+ // adjust the type.
301
+ if (!aliasDecl->preconcurrency ())
302
+ return type;
303
+
304
+ // Only adjust the type within a strict concurrency context, so we don't
305
+ // change the types as seen by code that hasn't adopted concurrency.
306
+ if (contextRequiresStrictConcurrencyChecking (
307
+ fromDC,
308
+ [](const AbstractClosureExpr *closure) {
309
+ return closure->getType ();
310
+ },
311
+ [](const ClosureExpr *closure) {
312
+ return closure->isIsolatedByPreconcurrency ();
313
+ }))
314
+ return type;
315
+
316
+ return type->stripConcurrency (
317
+ /* recurse=*/ true , /* dropGlobalActor=*/ true );
318
+ }
319
+
289
320
Type TypeResolution::resolveTypeInContext (TypeDecl *typeDecl,
290
321
DeclContext *foundDC,
291
322
bool isSpecialized) const {
@@ -307,6 +338,13 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
307
338
return genericParam->getDeclaredInterfaceType ();
308
339
}
309
340
341
+ // / Call this function before returning the underlying type of a typealias,
342
+ // / to adjust its type for concurrency.
343
+ auto adjustAliasType = [&](Type type) -> Type {
344
+ return adjustTypeAliasTypeInContext (
345
+ type, cast<TypeAliasDecl>(typeDecl), fromDC, options);
346
+ };
347
+
310
348
if (!isSpecialized) {
311
349
// If we are referring to a type within its own context, and we have either
312
350
// a generic type with no generic arguments or a non-generic type, use the
@@ -342,9 +380,9 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
342
380
if (ugAliasDecl == aliasDecl) {
343
381
if (getStage () == TypeResolutionStage::Structural &&
344
382
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
345
- return aliasDecl->getStructuralType ();
383
+ return adjustAliasType ( aliasDecl->getStructuralType () );
346
384
}
347
- return aliasDecl->getDeclaredInterfaceType ();
385
+ return adjustAliasType ( aliasDecl->getDeclaredInterfaceType () );
348
386
}
349
387
350
388
extendedType = unboundGeneric->getParent ();
@@ -356,9 +394,9 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
356
394
if (aliasType->getDecl () == aliasDecl) {
357
395
if (getStage () == TypeResolutionStage::Structural &&
358
396
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
359
- return aliasDecl->getStructuralType ();
397
+ return adjustAliasType ( aliasDecl->getStructuralType () );
360
398
}
361
- return aliasDecl->getDeclaredInterfaceType ();
399
+ return adjustAliasType ( aliasDecl->getDeclaredInterfaceType () );
362
400
}
363
401
extendedType = aliasType->getParent ();
364
402
continue ;
@@ -381,9 +419,9 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
381
419
// Otherwise, return the appropriate type.
382
420
if (getStage () == TypeResolutionStage::Structural &&
383
421
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
384
- return aliasDecl->getStructuralType ();
422
+ return adjustAliasType ( aliasDecl->getStructuralType () );
385
423
}
386
- return aliasDecl->getDeclaredInterfaceType ();
424
+ return adjustAliasType ( aliasDecl->getDeclaredInterfaceType () );
387
425
}
388
426
389
427
// When a nominal type used outside its context, return the unbound
@@ -1571,6 +1609,13 @@ static Type resolveNestedIdentTypeComponent(TypeResolution resolution,
1571
1609
AssociatedTypeDecl *inferredAssocType) {
1572
1610
bool hasUnboundOpener = !!resolution.getUnboundTypeOpener ();
1573
1611
1612
+ // Type aliases might require adjustment due to @preconcurrency.
1613
+ if (auto aliasDecl = dyn_cast<TypeAliasDecl>(member)) {
1614
+ memberType = adjustTypeAliasTypeInContext (
1615
+ memberType, aliasDecl, resolution.getDeclContext (),
1616
+ resolution.getOptions ());
1617
+ }
1618
+
1574
1619
if (options.contains (TypeResolutionFlags::SilenceErrors)) {
1575
1620
if (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member,
1576
1621
hasUnboundOpener)
@@ -4401,6 +4446,7 @@ class ExistentialTypeVisitor
4401
4446
}
4402
4447
} else if (auto *alias = dyn_cast_or_null<TypeAliasDecl>(comp->getBoundDecl ())) {
4403
4448
auto type = Type (alias->getDeclaredInterfaceType ()->getDesugaredType ());
4449
+
4404
4450
// If this is a type alias to a constraint type, the type
4405
4451
// alias name must be prefixed with 'any' to be used as an
4406
4452
// existential type.
0 commit comments