Skip to content

std::function -> llvm::function_ref for some non-escaping params. #16251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,13 @@ class alignas(8) Expr {
/// Enumerate each immediate child expression of this node, invoking the
/// specific functor on it. This ignores statements and other non-expression
/// children.
void forEachImmediateChildExpr(const std::function<Expr*(Expr*)> &callback);
void forEachImmediateChildExpr(llvm::function_ref<Expr *(Expr *)> callback);

/// Enumerate each expr node within this expression subtree, invoking the
/// specific functor on it. This ignores statements and other non-expression
/// children, and if there is a closure within the expression, this does not
/// walk into the body of it (unless it is single-expression).
void forEachChildExpr(const std::function<Expr*(Expr*)> &callback);
void forEachChildExpr(llvm::function_ref<Expr *(Expr *)> callback);

/// Determine whether this expression refers to a type by name.
///
Expand Down
8 changes: 4 additions & 4 deletions include/swift/AST/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ class alignas(8) Pattern {

/// \brief apply the specified function to all variables referenced in this
/// pattern.
void forEachVariable(const std::function<void(VarDecl*)> &f) const;
void forEachVariable(llvm::function_ref<void(VarDecl *)> f) const;

/// \brief apply the specified function to all pattern nodes recursively in
/// this pattern. This is a pre-order traversal.
void forEachNode(const std::function<void(Pattern*)> &f);
void forEachNode(llvm::function_ref<void(Pattern *)> f);

void forEachNode(const std::function<void(const Pattern*)> &f) const {
const std::function<void(Pattern*)> &f2 = f;
void forEachNode(llvm::function_ref<void(const Pattern *)> f) const {
llvm::function_ref<void(Pattern *)> f2 = f;
const_cast<Pattern *>(this)->forEachNode(f2);
}

Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
/// paramsAndResultMatch which determines in a client-specific way
/// whether the parameters and result of the types match.
bool matchesFunctionType(Type other, TypeMatchOptions matchOptions,
std::function<bool()> paramsAndResultMatch);
llvm::function_ref<bool()> paramsAndResultMatch);

/// \brief Determines whether this type has a retainable pointer
/// representation, i.e. whether it is representable as a single,
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FrontendOptions {
InputFileKind InputKind = InputFileKind::IFK_Swift;

void forAllOutputPaths(const InputFile &input,
std::function<void(StringRef)> fn) const;
llvm::function_ref<void(StringRef)> fn) const;

bool isOutputFileDirectory() const;

Expand Down
2 changes: 1 addition & 1 deletion include/swift/IDE/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool initInvocationByClangArguments(ArrayRef<const char *> ArgList,
/// Visits all overridden declarations exhaustively from VD, including protocol
/// conformances and clang declarations.
void walkOverriddenDecls(const ValueDecl *VD,
std::function<void(llvm::PointerUnion<
llvm::function_ref<void(llvm::PointerUnion<
const ValueDecl*, const clang::NamedDecl*>)> Fn);

void collectModuleNames(StringRef SDKPath, std::vector<std::string> &Modules);
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ class Parser {
ParserStatus parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
bool AllowSepAfterLast, Diag<> ErrorDiag,
syntax::SyntaxKind Kind,
std::function<ParserStatus()> callback);
llvm::function_ref<ParserStatus()> callback);

void consumeTopLevelDecl(ParserPosition BeginParserPosition,
TopLevelCodeDecl *TLCD);
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/MemAccessUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ bool isPossibleFormalAccessBase(const AccessedStorage &storage, SILFunction *F);
/// This only visits instructions that modify memory in some user-visible way,
/// which could be considered part of a formal access.
void visitAccessedAddress(SILInstruction *I,
std::function<void(Operand *)> visitor);
llvm::function_ref<void(Operand *)> visitor);

} // end namespace swift

Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Analysis/ClosureScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class TopDownClosureFunctionOrder {
// Visit all functions in a module, visiting each closure scope function
// before
// the closure function itself.
void visitFunctions(std::function<void(SILFunction *)> visitor);
void visitFunctions(llvm::function_ref<void(SILFunction *)> visitor);
};

} // end namespace swift
Expand Down
6 changes: 3 additions & 3 deletions include/swift/SILOptimizer/Utils/Local.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ NullablePtr<SILInstruction> createDecrementBefore(SILValue Ptr,
void
recursivelyDeleteTriviallyDeadInstructions(
ArrayRef<SILInstruction*> I, bool Force = false,
std::function<void(SILInstruction *)> C = [](SILInstruction *){});
llvm::function_ref<void(SILInstruction *)> C = [](SILInstruction *){});

/// \brief If the given instruction is dead, delete it along with its dead
/// operands.
Expand All @@ -76,7 +76,7 @@ void
recursivelyDeleteTriviallyDeadInstructions(
SILInstruction *I,
bool Force = false,
std::function<void(SILInstruction *)> C = [](SILInstruction *){});
llvm::function_ref<void(SILInstruction *)> C = [](SILInstruction *){});

/// \brief Perform a fast local check to see if the instruction is dead.
///
Expand All @@ -96,7 +96,7 @@ collectUsesOfValue(SILValue V, llvm::SmallPtrSetImpl<SILInstruction *> &Insts);
/// instruction itself)
void eraseUsesOfInstruction(
SILInstruction *Inst,
std::function<void(SILInstruction *)> C = [](SILInstruction *){});
llvm::function_ref<void(SILInstruction *)> C = [](SILInstruction *){});

/// \brief Recursively erase all of the uses of the value (but not the
/// value itself)
Expand Down
3 changes: 2 additions & 1 deletion include/swift/Syntax/AtomicCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <functional>
#include "swift/Syntax/References.h"
#include "llvm/ADT/STLExtras.h"

namespace swift {

Expand All @@ -38,7 +39,7 @@ class AtomicCache {

/// Gets the value inside the cache, or creates it atomically using the
/// provided lambda if it doesn't already exist.
RC<T> getOrCreate(std::function<RC<T> ()> Create) const {
RC<T> getOrCreate(llvm::function_ref<RC<T>()> Create) const {
auto &Ptr = *reinterpret_cast<std::atomic<uintptr_t> *>(&Storage);

// If an atomic load gets an initialized value, then return Storage.
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
bool Curried, bool ArgNameIsAPIByDefault);

void printParameterList(ParameterList *PL, Type paramListTy, bool isCurried,
std::function<bool()> isAPINameByDefault);
llvm::function_ref<bool()> isAPINameByDefault);

/// \brief Print the function parameters in curried or selector style,
/// to match the original function declaration.
Expand Down Expand Up @@ -2310,7 +2310,7 @@ void PrintAST::printOneParameter(const ParamDecl *param,

void PrintAST::printParameterList(ParameterList *PL, Type paramListTy,
bool isCurried,
std::function<bool()> isAPINameByDefault) {
llvm::function_ref<bool()> isAPINameByDefault) {
SmallVector<ParameterTypeFlags, 4> paramFlags;
if (paramListTy && !paramListTy->hasError()) {
if (auto parenTy = dyn_cast<ParenType>(paramListTy.getPointer())) {
Expand Down
5 changes: 2 additions & 3 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3414,9 +3414,8 @@ class Verifier : public ASTWalker {

/// \brief Verify that the given source ranges is contained within the
/// parent's source range.
void checkSourceRanges(SourceRange Current,
ASTWalker::ParentTy Parent,
std::function<void()> printEntity) {
void checkSourceRanges(SourceRange Current, ASTWalker::ParentTy Parent,
llvm::function_ref<void()> printEntity) {
SourceRange Enclosing;
if (Parent.isNull())
return;
Expand Down
12 changes: 6 additions & 6 deletions lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,12 @@ ConcreteDeclRef Expr::getReferencedDecl() const {
/// specific functor on it. This ignores statements and other non-expression
/// children.
void Expr::
forEachImmediateChildExpr(const std::function<Expr*(Expr*)> &callback) {
forEachImmediateChildExpr(llvm::function_ref<Expr *(Expr *)> callback) {
struct ChildWalker : ASTWalker {
const std::function<Expr*(Expr*)> &callback;
llvm::function_ref<Expr *(Expr *)> callback;
Expr *ThisNode;

ChildWalker(const std::function<Expr*(Expr*)> &callback, Expr *ThisNode)
ChildWalker(llvm::function_ref<Expr *(Expr *)> callback, Expr *ThisNode)
: callback(callback), ThisNode(ThisNode) {}

std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
Expand Down Expand Up @@ -576,11 +576,11 @@ forEachImmediateChildExpr(const std::function<Expr*(Expr*)> &callback) {
/// Enumerate each immediate child expression of this node, invoking the
/// specific functor on it. This ignores statements and other non-expression
/// children.
void Expr::forEachChildExpr(const std::function<Expr*(Expr*)> &callback) {
void Expr::forEachChildExpr(llvm::function_ref<Expr *(Expr *)> callback) {
struct ChildWalker : ASTWalker {
const std::function<Expr*(Expr*)> &callback;
llvm::function_ref<Expr *(Expr *)> callback;

ChildWalker(const std::function<Expr*(Expr*)> &callback)
ChildWalker(llvm::function_ref<Expr *(Expr *)> callback)
: callback(callback) {}

std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ namespace {

/// \brief apply the specified function to all variables referenced in this
/// pattern.
void Pattern::forEachVariable(const std::function<void(VarDecl*)> &fn) const {
void Pattern::forEachVariable(llvm::function_ref<void(VarDecl *)> fn) const {
switch (getKind()) {
case PatternKind::Any:
case PatternKind::Bool:
Expand Down Expand Up @@ -235,7 +235,7 @@ void Pattern::forEachVariable(const std::function<void(VarDecl*)> &fn) const {

/// \brief apply the specified function to all pattern nodes recursively in
/// this pattern. This is a pre-order traversal.
void Pattern::forEachNode(const std::function<void(Pattern*)> &f) {
void Pattern::forEachNode(llvm::function_ref<void(Pattern*)> f) {
f(this);

switch (getKind()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ namespace {
static bool matchesFunctionType(CanAnyFunctionType fn1, CanAnyFunctionType fn2,
TypeMatchOptions matchMode,
OptionalUnwrapping insideOptional,
std::function<bool()> paramsAndResultMatch) {
llvm::function_ref<bool()> paramsAndResultMatch) {
// FIXME: Handle generic functions in non-ABI matches.
if (!matchMode.contains(TypeMatchFlags::AllowABICompatible)) {
if (!isa<FunctionType>(fn1) || !isa<FunctionType>(fn2))
Expand Down Expand Up @@ -2335,7 +2335,7 @@ static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,
if (!fn1)
return false;

std::function<bool()> paramsAndResultMatch = [=]() {
auto paramsAndResultMatch = [&]() {
// Inputs are contravariant, results are covariant.
return (matches(fn2.getInput(), fn1.getInput(), matchMode,
ParameterPosition::Parameter, OptionalUnwrapping::None) &&
Expand Down Expand Up @@ -2371,7 +2371,7 @@ bool TypeBase::matchesParameter(Type other, TypeMatchOptions matchMode) {
}

bool TypeBase::matchesFunctionType(Type other, TypeMatchOptions matchMode,
std::function<bool()> paramsAndResultMatch) {
llvm::function_ref<bool()> paramsAndResultMatch) {
auto thisFnTy = dyn_cast<AnyFunctionType>(getCanonicalType());
auto otherFnTy = dyn_cast<AnyFunctionType>(other->getCanonicalType());

Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ static Arg *makeInputArg(const DerivedArgList &Args, OptTable &Opts,
return A;
}

using RemainingArgsHandler = std::function<void(InputArgList &, unsigned)>;
using RemainingArgsHandler = llvm::function_ref<void(InputArgList &, unsigned)>;

std::unique_ptr<InputArgList>
parseArgsUntil(const llvm::opt::OptTable& Opts,
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/FrontendOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool FrontendOptions::shouldActionOnlyParse(ActionType action) {
}

void FrontendOptions::forAllOutputPaths(
const InputFile &input, std::function<void(StringRef)> fn) const {
const InputFile &input, llvm::function_ref<void(StringRef)> fn) const {
if (RequestedAction != FrontendOptions::ActionType::EmitModuleOnly &&
RequestedAction != FrontendOptions::ActionType::MergeModules) {
if (InputsAndOutputs.isWholeModule())
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ static void walkOverriddenClangDecls(const clang::NamedDecl *D, const FnTy &Fn){

void
ide::walkOverriddenDecls(const ValueDecl *VD,
std::function<void(llvm::PointerUnion<
llvm::function_ref<void(llvm::PointerUnion<
const ValueDecl*, const clang::NamedDecl*>)> Fn) {
for (auto CurrOver = VD; CurrOver; CurrOver = CurrOver->getOverriddenDecl()) {
if (CurrOver != VD)
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3895,7 +3895,7 @@ namespace {
}

void forNontrivialPayloads(IRGenFunction &IGF, llvm::Value *tag,
std::function<void (unsigned, EnumImplStrategy::Element)> f)
llvm::function_ref<void(unsigned, EnumImplStrategy::Element)> f)
const {
auto *endBB = llvm::BasicBlock::Create(IGF.IGM.getLLVMContext());

Expand Down
11 changes: 5 additions & 6 deletions lib/IRGen/GenExistential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,12 +1545,11 @@ TypeConverter::convertExistentialMetatypeType(ExistentialMetatypeType *T) {

/// Emit protocol witness table pointers for the given protocol conformances,
/// passing each emitted witness table index into the given function body.
static void forEachProtocolWitnessTable(IRGenFunction &IGF,
CanType srcType, llvm::Value **srcMetadataCache,
CanType destType,
ArrayRef<ProtocolEntry> protocols,
ArrayRef<ProtocolConformanceRef> conformances,
std::function<void (unsigned, llvm::Value*)> body) {
static void forEachProtocolWitnessTable(
IRGenFunction &IGF, CanType srcType, llvm::Value **srcMetadataCache,
CanType destType, ArrayRef<ProtocolEntry> protocols,
ArrayRef<ProtocolConformanceRef> conformances,
llvm::function_ref<void(unsigned, llvm::Value *)> body) {
// Collect the conformances that need witness tables.
auto layout = destType.getExistentialLayout();
auto destProtocols = layout.getProtocols();
Expand Down
2 changes: 1 addition & 1 deletion lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ static SyntaxKind getListElementKind(SyntaxKind ListKind) {
ParserStatus
Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
bool AllowSepAfterLast, Diag<> ErrorDiag, SyntaxKind Kind,
std::function<ParserStatus()> callback) {
llvm::function_ref<ParserStatus()> callback) {
llvm::Optional<SyntaxParsingContext> ListContext;
ListContext.emplace(SyntaxContext, Kind);
if (Kind == SyntaxKind::Unknown)
Expand Down
2 changes: 1 addition & 1 deletion lib/PrintAsObjC/PrintAsObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ class ModuleWriter {
}

void forwardDeclare(const NominalTypeDecl *NTD,
std::function<void (void)> Printer) {
llvm::function_ref<void(void)> Printer) {
if (NTD->getModuleContext()->isStdlibModule())
return;
auto &state = seenTypes[NTD];
Expand Down
6 changes: 3 additions & 3 deletions lib/SIL/MemAccessUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ bool swift::isPossibleFormalAccessBase(const AccessedStorage &storage,
/// including arguments to @noescape functions that are passed as closures to
/// the current call.
static void visitApplyAccesses(ApplySite apply,
std::function<void(Operand *)> visitor) {
llvm::function_ref<void(Operand *)> visitor) {
for (Operand &oper : apply.getArgumentOperands()) {
// Consider any address-type operand an access. Whether it is read or modify
// depends on the argument convention.
Expand All @@ -355,7 +355,7 @@ static void visitApplyAccesses(ApplySite apply,
}

static void visitBuiltinAddress(BuiltinInst *builtin,
std::function<void(Operand *)> visitor) {
llvm::function_ref<void(Operand *)> visitor) {
if (auto kind = builtin->getBuiltinKind()) {
switch (kind.getValue()) {
default:
Expand Down Expand Up @@ -430,7 +430,7 @@ static void visitBuiltinAddress(BuiltinInst *builtin,
}

void swift::visitAccessedAddress(SILInstruction *I,
std::function<void(Operand *)> visitor) {
llvm::function_ref<void(Operand *)> visitor) {
assert(I->mayReadOrWriteMemory());

// Reference counting instructions do not access user visible memory.
Expand Down
10 changes: 5 additions & 5 deletions lib/SILGen/SILGenBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,10 @@ ManagedValue SILGenBuilder::createFormalAccessCopyAddr(
return SGF.emitFormalAccessManagedBufferWithCleanup(loc, newAddr);
}

ManagedValue SILGenBuilder::bufferForExpr(
SILLocation loc, SILType ty, const TypeLowering &lowering,
SGFContext context, std::function<void (SILValue)> rvalueEmitter) {
ManagedValue
SILGenBuilder::bufferForExpr(SILLocation loc, SILType ty,
const TypeLowering &lowering, SGFContext context,
llvm::function_ref<void(SILValue)> rvalueEmitter) {
// If we have a single-buffer "emit into" initialization, use that for the
// result.
SILValue address = context.getAddressForInPlaceInitialization(SGF, loc);
Expand All @@ -459,10 +460,9 @@ ManagedValue SILGenBuilder::bufferForExpr(
return SGF.emitManagedBufferWithCleanup(address);
}


ManagedValue SILGenBuilder::formalAccessBufferForExpr(
SILLocation loc, SILType ty, const TypeLowering &lowering,
SGFContext context, std::function<void(SILValue)> rvalueEmitter) {
SGFContext context, llvm::function_ref<void(SILValue)> rvalueEmitter) {
// If we have a single-buffer "emit into" initialization, use that for the
// result.
SILValue address = context.getAddressForInPlaceInitialization(SGF, loc);
Expand Down
12 changes: 6 additions & 6 deletions lib/SILGen/SILGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,8 @@ class SILGenBuilder : public SILBuilder {
///
/// \return an empty value if the buffer was taken from the context.
ManagedValue bufferForExpr(SILLocation loc, SILType ty,
const TypeLowering &lowering,
SGFContext context,
std::function<void(SILValue)> rvalueEmitter);
const TypeLowering &lowering, SGFContext context,
llvm::function_ref<void(SILValue)> rvalueEmitter);

using SILBuilder::createUncheckedEnumData;
ManagedValue createUncheckedEnumData(SILLocation loc, ManagedValue operand,
Expand Down Expand Up @@ -276,9 +275,10 @@ class SILGenBuilder : public SILBuilder {

ManagedValue createSemanticLoadBorrow(SILLocation loc, ManagedValue addr);

ManagedValue formalAccessBufferForExpr(
SILLocation loc, SILType ty, const TypeLowering &lowering,
SGFContext context, std::function<void(SILValue)> rvalueEmitter);
ManagedValue
formalAccessBufferForExpr(SILLocation loc, SILType ty,
const TypeLowering &lowering, SGFContext context,
llvm::function_ref<void(SILValue)> rvalueEmitter);

using SILBuilder::createUnconditionalCheckedCastValue;
ManagedValue
Expand Down
Loading