@@ -275,9 +275,13 @@ class ActorIsolation {
275275 void print (llvm::raw_ostream &os) const ;
276276
277277 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".
279282 void printForDiagnostics (llvm::raw_ostream &os,
280- StringRef openingQuotationMark = " '" ) const ;
283+ StringRef openingQuotationMark = " '" ,
284+ bool asNoun = false ) const ;
281285
282286 SWIFT_DEBUG_DUMPER (dump());
283287
@@ -287,9 +291,68 @@ class ActorIsolation {
287291 SWIFT_DEBUG_DUMPER (dumpForDiagnostics());
288292};
289293
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+
290349// / Determine how the given value declaration is isolated.
291350ActorIsolation getActorIsolation (ValueDecl *value);
292351
352+ // / Infer the actor isolation of the given declaration, including
353+ // / the source of isolation inference.
354+ InferredActorIsolation getInferredActorIsolation (ValueDecl *value);
355+
293356// / Trampoline for AbstractClosureExpr::getActorIsolation.
294357ActorIsolation
295358__AbstractClosureExpr_getActorIsolation (AbstractClosureExpr *CE);
0 commit comments