12
12
13
13
#define DEBUG_TYPE " flow-isolation"
14
14
15
+ #include " swift/AST/Expr.h"
15
16
#include " swift/AST/ActorIsolation.h"
16
17
#include " swift/AST/DiagnosticsSIL.h"
17
18
#include " swift/SIL/ApplySite.h"
@@ -335,30 +336,6 @@ SILInstruction *AnalysisInfo::findNonisolatedBlame(SILInstruction* startInst) {
335
336
llvm_unreachable (" failed to find nonisolated blame." );
336
337
}
337
338
338
- static ValueDecl *findCallee (ApplySite &apply) {
339
- SILValue callee = apply.getCalleeOrigin ();
340
-
341
- auto check = [](ValueDecl *decl) -> ValueDecl* {
342
- // if this is an accessor, then return the storage instead.
343
- if (auto accessor = dyn_cast<AccessorDecl>(decl))
344
- return accessor->getStorage ();
345
-
346
- return decl;
347
- };
348
-
349
- if (auto *methInst = dyn_cast<MethodInst>(callee))
350
- return check (methInst->getMember ().getDecl ());
351
-
352
- if (auto *funcInst = dyn_cast<FunctionRefBaseInst>(callee)) {
353
- auto *refFunc = funcInst->getInitiallyReferencedFunction ();
354
- if (auto *declCxt = refFunc->getDeclContext ())
355
- if (auto *absFn = dyn_cast<AbstractFunctionDecl>(declCxt->getAsDecl ()))
356
- return check (absFn);
357
- }
358
-
359
- return nullptr ;
360
- }
361
-
362
339
static StringRef verbForInvoking (ValueDecl *value) {
363
340
// Only computed properties need a different verb.
364
341
if (isa<AbstractStorageDecl>(value))
@@ -377,24 +354,55 @@ describe(SILInstruction *blame) {
377
354
378
355
// check if it's a call-like thing.
379
356
if (auto apply = ApplySite::isa (blame)) {
380
- // NOTE: we can't use ApplySite::getCalleeFunction because it is overly
381
- // precise in finding the specific corresponding SILFunction. We only care
382
- // about describing the referenced AST decl, since that's all programmers
383
- // know.
384
- ValueDecl *callee = findCallee (apply);
357
+ // / First, look for a callee declaration.
358
+ // /
359
+ // / We can't use ApplySite::getCalleeFunction because it is overly
360
+ // / precise in finding the specific corresponding SILFunction. We only care
361
+ // / about describing the referenced AST decl, since that's all programmers
362
+ // / know.
363
+
364
+ ValueDecl *callee = nullptr ;
365
+
366
+ auto inspect = [](ValueDecl *decl) -> ValueDecl* {
367
+ // if this is an accessor, then return the storage instead.
368
+ if (auto accessor = dyn_cast<AccessorDecl>(decl))
369
+ return accessor->getStorage ();
370
+
371
+ return decl;
372
+ };
373
+
374
+ SILValue silCallee = apply.getCalleeOrigin ();
375
+ if (auto *methInst = dyn_cast<MethodInst>(silCallee))
376
+ callee = inspect (methInst->getMember ().getDecl ());
377
+
378
+ if (auto *funcInst = dyn_cast<FunctionRefBaseInst>(silCallee)) {
379
+ auto *refFunc = funcInst->getInitiallyReferencedFunction ();
380
+
381
+ if (auto *declCxt = refFunc->getDeclContext ()) {
382
+ if (auto *absFn =
383
+ dyn_cast_or_null<AbstractFunctionDecl>(declCxt->getAsDecl ())) {
384
+ callee = inspect (absFn);
385
+ } else if (isa<AbstractClosureExpr>(declCxt)) {
386
+ // TODO: determine if the closure captures self, or is applied to it,
387
+ // so we can be more specific in this message.
388
+ return std::make_tuple (" this closure involving" , " " , ctx.Id_self );
389
+ }
390
+ }
391
+ }
385
392
386
393
// if we have no callee info, all we know is it's a call involving self.
387
394
if (!callee)
388
395
return std::make_tuple (" a call involving" , " " , ctx.Id_self );
389
396
397
+ // otherwise, form the tuple relative to the callee decl.
390
398
return std::make_tuple (
391
399
verbForInvoking (callee),
392
400
callee->getDescriptiveKindName (callee->getDescriptiveKind ()),
393
401
callee->getName ()
394
402
);
395
403
}
396
404
397
- // handle non-call blames
405
+ // handle other non-call blames.
398
406
switch (blame->getKind ()) {
399
407
case SILInstructionKind::CopyValueInst:
400
408
return std::make_tuple (" making a copy of" , " " , ctx.Id_self );
0 commit comments