@@ -232,6 +232,21 @@ namespace {
232
232
return props;
233
233
}
234
234
235
+ RecursiveProperties applyLifetimeAnnotation (LifetimeAnnotation annotation,
236
+ RecursiveProperties props) {
237
+ switch (annotation) {
238
+ case LifetimeAnnotation::None:
239
+ break ;
240
+ case LifetimeAnnotation::Lexical:
241
+ props.setLexical (IsLexical);
242
+ break ;
243
+ case LifetimeAnnotation::EagerMove:
244
+ props.setLexical (IsNotLexical);
245
+ break ;
246
+ }
247
+ return props;
248
+ }
249
+
235
250
RecursiveProperties
236
251
getTrivialRecursiveProperties (IsTypeExpansionSensitive_t isSensitive) {
237
252
return mergeIsTypeExpansionSensitive (isSensitive,
@@ -267,8 +282,6 @@ namespace {
267
282
IMPL (BuiltinBridgeObject, Reference)
268
283
IMPL (BuiltinVector, Trivial)
269
284
IMPL (SILToken, Trivial)
270
- IMPL (Class, Reference)
271
- IMPL (BoundGenericClass, Reference)
272
285
IMPL (AnyMetatype, Trivial)
273
286
IMPL (Module, Trivial)
274
287
@@ -288,7 +301,9 @@ namespace {
288
301
IsTypeExpansionSensitive_t isSensitive) {
289
302
return asImpl ().handleAddressOnly (type, {IsNotTrivial, IsFixedABI,
290
303
IsAddressOnly, IsNotResilient,
291
- isSensitive});
304
+ isSensitive,
305
+ DoesNotHaveRawPointer,
306
+ IsLexical});
292
307
}
293
308
294
309
RetTy visitBuiltinDefaultActorStorageType (
@@ -297,7 +312,9 @@ namespace {
297
312
IsTypeExpansionSensitive_t isSensitive) {
298
313
return asImpl ().handleAddressOnly (type, {IsNotTrivial, IsFixedABI,
299
314
IsAddressOnly, IsNotResilient,
300
- isSensitive});
315
+ isSensitive,
316
+ DoesNotHaveRawPointer,
317
+ IsLexical});
301
318
}
302
319
303
320
RetTy visitAnyFunctionType (CanAnyFunctionType type,
@@ -479,7 +496,9 @@ namespace {
479
496
IsFixedABI, \
480
497
IsAddressOnly, \
481
498
IsNotResilient, \
482
- isSensitive}); \
499
+ isSensitive, \
500
+ DoesNotHaveRawPointer, \
501
+ IsLexical}); \
483
502
}
484
503
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
485
504
RetTy visit##Name##StorageType(Can##Name##StorageType type, \
@@ -502,7 +521,9 @@ namespace {
502
521
IsFixedABI, \
503
522
IsAddressOnly, \
504
523
IsNotResilient, \
505
- isSensitive}); \
524
+ isSensitive, \
525
+ DoesNotHaveRawPointer, \
526
+ IsLexical}); \
506
527
} \
507
528
RetTy visit##Name##StorageType(Can##Name##StorageType type, \
508
529
AbstractionPattern origType, \
@@ -579,7 +600,9 @@ namespace {
579
600
IsFixedABI,
580
601
IsAddressOnly,
581
602
IsNotResilient,
582
- isSensitive});
603
+ isSensitive,
604
+ DoesNotHaveRawPointer,
605
+ IsLexical});
583
606
// Class-constrained and boxed existentials are refcounted.
584
607
case ExistentialRepresentation::Class:
585
608
case ExistentialRepresentation::Boxed:
@@ -608,6 +631,20 @@ namespace {
608
631
return visitExistentialType (type, origType, isSensitive);
609
632
}
610
633
634
+ // Classes depend on their attributes.
635
+ RetTy visitClassType (CanClassType type, AbstractionPattern origType,
636
+ IsTypeExpansionSensitive_t isSensitive) {
637
+ return asImpl ().visitAnyClassType (type, origType, type->getDecl (),
638
+ isSensitive);
639
+ }
640
+
641
+ RetTy visitBoundGenericClassType (CanBoundGenericClassType type,
642
+ AbstractionPattern origType,
643
+ IsTypeExpansionSensitive_t isSensitive) {
644
+ return asImpl ().visitAnyClassType (type, origType, type->getDecl (),
645
+ isSensitive);
646
+ }
647
+
611
648
// Enums depend on their enumerators.
612
649
RetTy visitEnumType (CanEnumType type, AbstractionPattern origType,
613
650
IsTypeExpansionSensitive_t isSensitive) {
@@ -671,7 +708,9 @@ namespace {
671
708
IsFixedABI,
672
709
IsAddressOnly,
673
710
IsNotResilient,
674
- isSensitive});
711
+ isSensitive,
712
+ DoesNotHaveRawPointer,
713
+ IsLexical});
675
714
}
676
715
677
716
RetTy visitSILBoxType (CanSILBoxType type,
@@ -723,6 +762,14 @@ namespace {
723
762
return properties;
724
763
}
725
764
765
+ RecursiveProperties
766
+ visitAnyClassType (CanType type, AbstractionPattern origType, ClassDecl *D,
767
+ IsTypeExpansionSensitive_t isSensitive) {
768
+ // Consult the type lowering.
769
+ auto &lowering = TC.getTypeLowering (origType, type, Expansion);
770
+ return handleClassificationFromLowering (type, lowering, isSensitive);
771
+ }
772
+
726
773
RecursiveProperties visitAnyEnumType (CanType type,
727
774
AbstractionPattern origType,
728
775
EnumDecl *D,
@@ -1743,7 +1790,8 @@ namespace {
1743
1790
IsTypeExpansionSensitive_t isSensitive)
1744
1791
: AddressOnlyTypeLowering(type,
1745
1792
{IsNotTrivial, IsFixedABI,
1746
- IsAddressOnly, IsNotResilient, isSensitive},
1793
+ IsAddressOnly, IsNotResilient, isSensitive,
1794
+ DoesNotHaveRawPointer, IsLexical},
1747
1795
forExpansion) {}
1748
1796
1749
1797
void emitCopyInto (SILBuilder &B, SILLocation loc,
@@ -2019,6 +2067,18 @@ namespace {
2019
2067
return false ;
2020
2068
}
2021
2069
2070
+ TypeLowering *visitAnyClassType (CanType classType,
2071
+ AbstractionPattern origType, ClassDecl *C,
2072
+ IsTypeExpansionSensitive_t isSensitive) {
2073
+ RecursiveProperties properties =
2074
+ getReferenceRecursiveProperties (isSensitive);
2075
+
2076
+ if (C->getLifetimeAnnotation () == LifetimeAnnotation::EagerMove)
2077
+ properties.setLexical (IsNotLexical);
2078
+
2079
+ return handleReference (classType, properties);
2080
+ }
2081
+
2022
2082
TypeLowering *visitAnyStructType (CanType structType,
2023
2083
AbstractionPattern origType,
2024
2084
StructDecl *D,
@@ -2061,8 +2121,14 @@ namespace {
2061
2121
2062
2122
properties.addSubobject (classifyType (origFieldType, substFieldType,
2063
2123
TC, Expansion));
2124
+ properties =
2125
+ applyLifetimeAnnotation (field->getLifetimeAnnotation (), properties);
2064
2126
}
2065
2127
2128
+ // Type-level annotations override inferred behavior.
2129
+ properties =
2130
+ applyLifetimeAnnotation (D->getLifetimeAnnotation (), properties);
2131
+
2066
2132
return handleAggregateByProperties<LoadableStructTypeLowering>(structType,
2067
2133
properties);
2068
2134
}
@@ -2119,8 +2185,14 @@ namespace {
2119
2185
->getReducedType (D->getGenericSignature ()));
2120
2186
properties.addSubobject (classifyType (origEltType, substEltType,
2121
2187
TC, Expansion));
2188
+ properties =
2189
+ applyLifetimeAnnotation (elt->getLifetimeAnnotation (), properties);
2122
2190
}
2123
2191
2192
+ // Type-level annotations override inferred behavior.
2193
+ properties =
2194
+ applyLifetimeAnnotation (D->getLifetimeAnnotation (), properties);
2195
+
2124
2196
return handleAggregateByProperties<LoadableEnumTypeLowering>(enumType,
2125
2197
properties);
2126
2198
}
0 commit comments