static bool isCallToStandardLibrarySwap(CallExpr *CE, ASTContext &Ctx) { if (CE->getCalledValue() == Ctx.getSwap()) return true; // Is the call module qualified, i.e. Swift.swap(&a[i], &[j)? if (auto *DSBIE = dyn_cast<DotSyntaxBaseIgnoredExpr>(CE->getFn())) { if (auto *DRE = dyn_cast<DeclRefExpr>(DSBIE->getRHS())) { return DRE->getDecl() == Ctx.getSwap(); } } return false; }
/// Returns true when the apply calls the Standard Library swap(). /// Used for fix-its to suggest replacing with Collection.swapAt() /// on exclusivity violations. static bool isCallToStandardLibrarySwap(ApplyInst *AI, ASTContext &Ctx) { SILFunction *SF = AI->getReferencedFunction(); if (!SF) return false; if (!SF->hasLocation()) return false; auto *FD = SF->getLocation().getAsASTNode<FuncDecl>(); if (!FD) return false; return FD == Ctx.getSwap(); }