@@ -275,9 +275,13 @@ class ActorIsolation {
275
275
void print (llvm::raw_ostream &os) const ;
276
276
277
277
void printForSIL (llvm::raw_ostream &os) const ;
278
-
278
+
279
+ // / Print the given isolation for diagnostics. If \c asNoun is \c false,
280
+ // / the participle adjective form is printed, e.g. "main actor-isolated".
281
+ // / Otherwise, the noun form is printed, e.g. "main actor isolation".
279
282
void printForDiagnostics (llvm::raw_ostream &os,
280
- StringRef openingQuotationMark = " '" ) const ;
283
+ StringRef openingQuotationMark = " '" ,
284
+ bool asNoun = false ) const ;
281
285
282
286
SWIFT_DEBUG_DUMPER (dump());
283
287
@@ -287,9 +291,68 @@ class ActorIsolation {
287
291
SWIFT_DEBUG_DUMPER (dumpForDiagnostics());
288
292
};
289
293
294
+ struct IsolationSource {
295
+ enum Kind : uint8_t {
296
+ // / Isolation is written in an explicit attribute.
297
+ Explicit,
298
+ // / Isolation is inferred from the enclosing lexical context.
299
+ LexicalContext,
300
+ // / Isolation is inferred from conformance to a protocol.
301
+ Conformance,
302
+ // / Isolation is inherited from a superclass.
303
+ Superclass,
304
+ // / Isolation is inferred from an overridden superclass method.
305
+ Override,
306
+ // / Isolation is inferred from \c @main.
307
+ MainFunction,
308
+ // / Isolation is inferred in top-level code.
309
+ TopLevelCode,
310
+ // / Unspecified isolation, which defaults to \c nonisolated.
311
+ None,
312
+ };
313
+
314
+ using InferenceSource =
315
+ llvm::PointerUnion<Decl *, AbstractClosureExpr *>;
316
+
317
+ // / The declaration with the original isolation attribute.
318
+ InferenceSource inferenceSource;
319
+ Kind kind;
320
+
321
+ IsolationSource (InferenceSource inferenceSource = nullptr ,
322
+ Kind kind = Kind::None)
323
+ : inferenceSource(inferenceSource), kind(kind) {}
324
+
325
+ bool isInferred () const {
326
+ return (kind != None) && (kind != Explicit);
327
+ }
328
+
329
+ void printForDiagnostics (llvm::raw_ostream &os,
330
+ StringRef openingQuotationMark = " '" ) const ;
331
+ };
332
+
333
+ struct InferredActorIsolation {
334
+ ActorIsolation isolation;
335
+ IsolationSource source;
336
+
337
+ static InferredActorIsolation forUnspecified () {
338
+ return {
339
+ ActorIsolation::forUnspecified (),
340
+ IsolationSource ()
341
+ };
342
+ }
343
+
344
+ bool preconcurrency () const {
345
+ return isolation.preconcurrency ();
346
+ }
347
+ };
348
+
290
349
// / Determine how the given value declaration is isolated.
291
350
ActorIsolation getActorIsolation (ValueDecl *value);
292
351
352
+ // / Infer the actor isolation of the given declaration, including
353
+ // / the source of isolation inference.
354
+ InferredActorIsolation getInferredActorIsolation (ValueDecl *value);
355
+
293
356
// / Trampoline for AbstractClosureExpr::getActorIsolation.
294
357
ActorIsolation
295
358
__AbstractClosureExpr_getActorIsolation (AbstractClosureExpr *CE);
0 commit comments