Skip to content

Commit

Permalink
Migrate llvm::make_unique to std::make_unique
Browse files Browse the repository at this point in the history
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
  • Loading branch information
JDevlieghere committed Aug 15, 2019
1 parent f4e9bef commit b4d268e
Show file tree
Hide file tree
Showing 62 changed files with 147 additions and 147 deletions.
2 changes: 1 addition & 1 deletion include/swift/AST/Evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class Evaluator {
// Check for a cycle.
if (checkDependency(getCanonicalRequest(request))) {
return llvm::Error(
llvm::make_unique<CyclicalRequestError<Request>>(request, *this));
std::make_unique<CyclicalRequestError<Request>>(request, *this));
}

// Make sure we remove this from the set of active requests once we're
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class CompilerInstance {

void createDependencyTracker(bool TrackSystemDeps) {
assert(!Context && "must be called before setup()");
DepTracker = llvm::make_unique<DependencyTracker>(TrackSystemDeps);
DepTracker = std::make_unique<DependencyTracker>(TrackSystemDeps);
}
DependencyTracker *getDependencyTracker() { return DepTracker.get(); }

Expand Down
4 changes: 2 additions & 2 deletions include/swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ class BasicCalleeAnalysis : public SILAnalysis {

CalleeList getCalleeList(FullApplySite FAS) {
if (!Cache)
Cache = llvm::make_unique<CalleeCache>(M);
Cache = std::make_unique<CalleeCache>(M);

return Cache->getCalleeList(FAS);
}

CalleeList getCalleeList(SILInstruction *I) {
if (!Cache)
Cache = llvm::make_unique<CalleeCache>(M);
Cache = std::make_unique<CalleeCache>(M);

return Cache->getCalleeList(I);
}
Expand Down
4 changes: 2 additions & 2 deletions include/swift/SILOptimizer/Analysis/DominanceAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DominanceAnalysis : public FunctionAnalysisBase<DominanceInfo> {
}

std::unique_ptr<DominanceInfo> newFunctionAnalysis(SILFunction *F) override {
return llvm::make_unique<DominanceInfo>(F);
return std::make_unique<DominanceInfo>(F);
}

virtual bool shouldInvalidate(SILAnalysis::InvalidationKind K) override {
Expand Down Expand Up @@ -72,7 +72,7 @@ class PostDominanceAnalysis : public FunctionAnalysisBase<PostDominanceInfo> {

std::unique_ptr<PostDominanceInfo>
newFunctionAnalysis(SILFunction *F) override {
return llvm::make_unique<PostDominanceInfo>(F);
return std::make_unique<PostDominanceInfo>(F);
}

virtual bool shouldInvalidate(SILAnalysis::InvalidationKind K) override {
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Analysis/EpilogueARCAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class EpilogueARCAnalysis : public FunctionAnalysisBase<EpilogueARCFunctionInfo>

virtual std::unique_ptr<EpilogueARCFunctionInfo>
newFunctionAnalysis(SILFunction *F) override {
return llvm::make_unique<EpilogueARCFunctionInfo>(F, PO, AA, RC);
return std::make_unique<EpilogueARCFunctionInfo>(F, PO, AA, RC);
}

virtual bool shouldInvalidate(SILAnalysis::InvalidationKind K) override {
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Analysis/IVAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class IVAnalysis final : public FunctionAnalysisBase<IVInfo> {
}

std::unique_ptr<IVInfo> newFunctionAnalysis(SILFunction *F) override {
return llvm::make_unique<IVInfo>(*F);
return std::make_unique<IVInfo>(*F);
}

/// For now we always invalidate.
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Analysis/LoopRegionAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ class LoopRegionAnalysis : public FunctionAnalysisBase<LoopRegionFunctionInfo> {

virtual std::unique_ptr<LoopRegionFunctionInfo>
newFunctionAnalysis(SILFunction *F) override {
return llvm::make_unique<LoopRegionFunctionInfo>(F, POA->get(F),
return std::make_unique<LoopRegionFunctionInfo>(F, POA->get(F),
SLA->get(F));
}

Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Analysis/PostOrderAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PostOrderAnalysis : public FunctionAnalysisBase<PostOrderFunctionInfo> {
protected:
virtual std::unique_ptr<PostOrderFunctionInfo>
newFunctionAnalysis(SILFunction *F) override {
return llvm::make_unique<PostOrderFunctionInfo>(F);
return std::make_unique<PostOrderFunctionInfo>(F);
}

virtual bool shouldInvalidate(SILAnalysis::InvalidationKind K) override {
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Analysis/RCIdentityAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class RCIdentityAnalysis : public FunctionAnalysisBase<RCIdentityFunctionInfo> {

virtual std::unique_ptr<RCIdentityFunctionInfo>
newFunctionAnalysis(SILFunction *F) override {
return llvm::make_unique<RCIdentityFunctionInfo>(DA);
return std::make_unique<RCIdentityFunctionInfo>(DA);
}

virtual bool shouldInvalidate(SILAnalysis::InvalidationKind K) override {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ void ASTContext::registerGenericSignatureBuilder(

++NumRegisteredGenericSignatureBuilders;
genericSignatureBuilders[canSig] =
llvm::make_unique<GenericSignatureBuilder>(std::move(builder));
std::make_unique<GenericSignatureBuilder>(std::move(builder));
}

GenericSignatureBuilder *ASTContext::getOrCreateGenericSignatureBuilder(
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/DiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ FileSpecificDiagnosticConsumer::consolidateSubconsumers(
if (subconsumers.size() == 1)
return std::move(subconsumers.front()).consumer;
// Cannot use return
// llvm::make_unique<FileSpecificDiagnosticConsumer>(subconsumers); because
// std::make_unique<FileSpecificDiagnosticConsumer>(subconsumers); because
// the constructor is private.
return std::unique_ptr<DiagnosticConsumer>(
new FileSpecificDiagnosticConsumer(subconsumers));
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3432,7 +3432,7 @@ GenericSignatureBuilder::Implementation::getOrCreateRewriteTreeRoot(
return root;

auto &root = RewriteTreeRoots[anchor];
root = llvm::make_unique<RewriteTreeNode>(nullptr);
root = std::make_unique<RewriteTreeNode>(nullptr);
return root.get();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ BuiltinUnit::LookupCache &BuiltinUnit::getCache() const {
// FIXME: This leaks. Sticking this into ASTContext isn't enough because then
// the DenseMap will leak.
if (!Cache)
const_cast<BuiltinUnit *>(this)->Cache = llvm::make_unique<LookupCache>();
const_cast<BuiltinUnit *>(this)->Cache = std::make_unique<LookupCache>();
return *Cache;
}

Expand Down Expand Up @@ -180,7 +180,7 @@ using SourceLookupCache = SourceFile::LookupCache;
SourceLookupCache &SourceFile::getCache() const {
if (!Cache) {
const_cast<SourceFile *>(this)->Cache =
llvm::make_unique<SourceLookupCache>(*this);
std::make_unique<SourceLookupCache>(*this);
}
return *Cache;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Basic/Statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class StatsProfiler {
if (I != Children.end()) {
return I->getSecond().get();
} else {
auto N = llvm::make_unique<Node>(this);
auto N = std::make_unique<Node>(this);
auto P = N.get();
Children.insert(std::make_pair(K, std::move(N)));
return P;
Expand Down Expand Up @@ -343,12 +343,12 @@ UnifiedStatsReporter::UnifiedStatsReporter(StringRef ProgramName,
ProfileDirname(Directory),
StartedTime(llvm::TimeRecord::getCurrentTime()),
MainThreadID(std::this_thread::get_id()),
Timer(make_unique<NamedRegionTimer>(AuxName,
Timer(std::make_unique<NamedRegionTimer>(AuxName,
"Building Target",
ProgramName, "Running Program")),
SourceMgr(SM),
ClangSourceMgr(CSM),
RecursiveTimers(llvm::make_unique<RecursionSafeTimers>())
RecursiveTimers(std::make_unique<RecursionSafeTimers>())
{
path::append(StatsFilename, makeStatsFileName(ProgramName, AuxName));
path::append(TraceFilename, makeTraceFileName(ProgramName, AuxName));
Expand All @@ -360,9 +360,9 @@ UnifiedStatsReporter::UnifiedStatsReporter(StringRef ProgramName,
if (TraceEvents)
FrontendStatsEvents.emplace();
if (ProfileEvents)
EventProfilers = make_unique<StatsProfilers>();
EventProfilers =std::make_unique<StatsProfilers>();
if (ProfileEntities)
EntityProfilers = make_unique<StatsProfilers>();
EntityProfilers =std::make_unique<StatsProfilers>();
}

void UnifiedStatsReporter::recordJobMaxRSS(long rss) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Basic/Windows/TaskQueue.inc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ unsigned TaskQueue::getNumberOfParallelTasks() const {
void TaskQueue::addTask(const char *ExecPath, ArrayRef<const char *> Args,
ArrayRef<const char *> Env, void *Context,
bool SeparateErrors) {
auto T = llvm::make_unique<Task>(ExecPath, Args, Env, Context, SeparateErrors);
auto T = std::make_unique<Task>(ExecPath, Args, Env, Context, SeparateErrors);
QueuedTasks.push(std::move(T));
}

Expand Down
14 changes: 7 additions & 7 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace {
SwiftPCHHash(swiftPCHHash) {}
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &CI, StringRef InFile) override {
return llvm::make_unique<HeaderParsingASTConsumer>(Impl);
return std::make_unique<HeaderParsingASTConsumer>(Impl);
}
bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
// Prefer frameworks over plain headers.
Expand Down Expand Up @@ -796,7 +796,7 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
// reused when building PCM files for the module cache.
clang::SourceManager clangSrcMgr(*clangDiags, CI.getFileManager());
auto FID = clangSrcMgr.createFileID(
llvm::make_unique<ZeroFilledMemoryBuffer>(1, "<main>"));
std::make_unique<ZeroFilledMemoryBuffer>(1, "<main>"));
clangSrcMgr.setMainFileID(FID);

// Note: Reusing the real HeaderSearch is dangerous, but it's not easy to
Expand Down Expand Up @@ -1023,9 +1023,9 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
auto PCHContainerOperations =
std::make_shared<clang::PCHContainerOperations>();
PCHContainerOperations->registerWriter(
llvm::make_unique<clang::ObjectFilePCHContainerWriter>());
std::make_unique<clang::ObjectFilePCHContainerWriter>());
PCHContainerOperations->registerReader(
llvm::make_unique<clang::ObjectFilePCHContainerReader>());
std::make_unique<clang::ObjectFilePCHContainerReader>());
importer->Impl.Instance.reset(
new clang::CompilerInstance(std::move(PCHContainerOperations)));
}
Expand All @@ -1038,7 +1038,7 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
{
// Now set up the real client for Clang diagnostics---configured with proper
// options---as opposed to the temporary one we made above.
auto actualDiagClient = llvm::make_unique<ClangDiagnosticConsumer>(
auto actualDiagClient = std::make_unique<ClangDiagnosticConsumer>(
importer->Impl, instance.getDiagnosticOpts(),
importerOpts.DumpClangDiagnostics);
instance.createDiagnostics(actualDiagClient.release());
Expand Down Expand Up @@ -1107,7 +1107,7 @@ std::unique_ptr<ClangImporter> ClangImporter::create(

// Setup Preprocessor callbacks before initialing the parser to make sure
// we catch implicit includes.
auto ppTracker = llvm::make_unique<BridgingPPTracker>(importer->Impl);
auto ppTracker = std::make_unique<BridgingPPTracker>(importer->Impl);
clangPP.addPPCallbacks(std::move(ppTracker));

instance.createModuleManager();
Expand Down Expand Up @@ -1226,7 +1226,7 @@ ClangImporter::Implementation::getNextIncludeLoc() {
// being deterministic.
includeLoc = includeLoc.getLocWithOffset(1);
DummyIncludeBuffer = srcMgr.createFileID(
llvm::make_unique<ZeroFilledMemoryBuffer>(
std::make_unique<ZeroFilledMemoryBuffer>(
256*1024, StringRef(moduleImportBufferName)),
clang::SrcMgr::C_User, /*LoadedID*/0, /*LoadedOffset*/0, includeLoc);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ const InheritedNameSet *NameImporter::getAllPropertyNames(
known = allProperties.insert(
{ std::pair<const clang::ObjCInterfaceDecl *, char>(classDecl,
forInstance),
llvm::make_unique<InheritedNameSet>(parentSet) }).first;
std::make_unique<InheritedNameSet>(parentSet) }).first;

// Local function to add properties from the given set.
auto addProperties = [&](clang::DeclContext::decl_range members) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/SwiftLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ SwiftLookupTableReader::create(clang::ModuleFileExtension *extension,
if (!serializedTable) return nullptr;

// Create the reader.
// Note: This doesn't use llvm::make_unique because the constructor is
// Note: This doesn't use std::make_unique because the constructor is
// private.
return std::unique_ptr<SwiftLookupTableReader>(
new SwiftLookupTableReader(extension, reader, moduleFile, onRemove,
Expand Down
26 changes: 13 additions & 13 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,19 @@ Driver::buildToolChain(const llvm::opt::InputArgList &ArgList) {
case llvm::Triple::IOS:
case llvm::Triple::TvOS:
case llvm::Triple::WatchOS:
return llvm::make_unique<toolchains::Darwin>(*this, target);
return std::make_unique<toolchains::Darwin>(*this, target);
case llvm::Triple::Linux:
if (target.isAndroid())
return llvm::make_unique<toolchains::Android>(*this, target);
return llvm::make_unique<toolchains::GenericUnix>(*this, target);
return std::make_unique<toolchains::Android>(*this, target);
return std::make_unique<toolchains::GenericUnix>(*this, target);
case llvm::Triple::FreeBSD:
return llvm::make_unique<toolchains::GenericUnix>(*this, target);
return std::make_unique<toolchains::GenericUnix>(*this, target);
case llvm::Triple::Win32:
if (target.isWindowsCygwinEnvironment())
return llvm::make_unique<toolchains::Cygwin>(*this, target);
return llvm::make_unique<toolchains::Windows>(*this, target);
return std::make_unique<toolchains::Cygwin>(*this, target);
return std::make_unique<toolchains::Windows>(*this, target);
case llvm::Triple::Haiku:
return llvm::make_unique<toolchains::GenericUnix>(*this, target);
return std::make_unique<toolchains::GenericUnix>(*this, target);
default:
Diags.diagnose(SourceLoc(), diag::error_unknown_target,
ArgList.getLastArg(options::OPT_target)->getValue());
Expand Down Expand Up @@ -293,9 +293,9 @@ std::unique_ptr<sys::TaskQueue> Driver::buildTaskQueue(const Compilation &C) {
ArgList.hasArg(options::OPT_driver_skip_execution,
options::OPT_driver_print_jobs);
if (DriverSkipExecution) {
return llvm::make_unique<sys::DummyTaskQueue>(NumberOfParallelCommands);
return std::make_unique<sys::DummyTaskQueue>(NumberOfParallelCommands);
} else {
return llvm::make_unique<sys::TaskQueue>(NumberOfParallelCommands,
return std::make_unique<sys::TaskQueue>(NumberOfParallelCommands,
C.getStatsReporter());
}
}
Expand Down Expand Up @@ -726,7 +726,7 @@ createStatsReporter(const llvm::opt::InputArgList *ArgList,
InputName = Inputs[0].second->getSpelling();
}
StringRef OutputType = file_types::getExtension(OI.CompilerOutputType);
return llvm::make_unique<UnifiedStatsReporter>("swift-driver",
return std::make_unique<UnifiedStatsReporter>("swift-driver",
OI.ModuleName,
InputName,
DefaultTargetTriple,
Expand Down Expand Up @@ -920,7 +920,7 @@ Driver::buildCompilation(const ToolChain &TC,
options::OPT_experimental_dependency_include_intrafile);

// clang-format off
C = llvm::make_unique<Compilation>(
C = std::make_unique<Compilation>(
Diags, TC, OI, Level,
std::move(ArgList),
std::move(TranslatedArgList),
Expand Down Expand Up @@ -1012,7 +1012,7 @@ parseArgsUntil(const llvm::opt::OptTable& Opts,
unsigned FlagsToExclude,
llvm::opt::OptSpecifier UntilOption,
RemainingArgsHandler RemainingHandler) {
auto Args = llvm::make_unique<InputArgList>(ArgBegin, ArgEnd);
auto Args = std::make_unique<InputArgList>(ArgBegin, ArgEnd);

// FIXME: Handle '@' args (or at least error on them).

Expand Down Expand Up @@ -1090,7 +1090,7 @@ Driver::parseArgStrings(ArrayRef<const char *> Args) {
ExcludedFlagsBitmask);

} else {
ArgList = llvm::make_unique<InputArgList>(
ArgList = std::make_unique<InputArgList>(
getOpts().ParseArgs(Args, MissingArgIndex, MissingArgCount,
IncludedFlagsBitmask, ExcludedFlagsBitmask));
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ std::unique_ptr<Job> ToolChain::constructJob(
auto responseFileInfo =
getResponseFileInfo(C, executablePath, invocationInfo, context);

return llvm::make_unique<Job>(
return std::make_unique<Job>(
JA, std::move(inputs), std::move(output), executablePath,
std::move(invocationInfo.Arguments),
std::move(invocationInfo.ExtraEnvironment),
Expand Down Expand Up @@ -251,7 +251,7 @@ static std::unique_ptr<CommandOutput>
makeBatchCommandOutput(ArrayRef<const Job *> jobs, Compilation &C,
file_types::ID outputType) {
auto output =
llvm::make_unique<CommandOutput>(outputType, C.getDerivedOutputFileMap());
std::make_unique<CommandOutput>(outputType, C.getDerivedOutputFileMap());
for (auto const *J : jobs) {
output->addOutputs(J->getOutput());
}
Expand Down Expand Up @@ -371,7 +371,7 @@ ToolChain::constructBatchJob(ArrayRef<const Job *> unsortedJobs,
auto responseFileInfo =
getResponseFileInfo(C, executablePath, invocationInfo, context);

return llvm::make_unique<BatchJob>(
return std::make_unique<BatchJob>(
*batchCJA, inputJobs.takeVector(), std::move(output), executablePath,
std::move(invocationInfo.Arguments),
std::move(invocationInfo.ExtraEnvironment),
Expand Down
6 changes: 3 additions & 3 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ void CompilerInstance::createREPLFile(const ImplicitImports &implicitImports) {
std::unique_ptr<DelayedParsingCallbacks>
CompilerInstance::computeDelayedParsingCallback() {
if (Invocation.isCodeCompletion())
return llvm::make_unique<CodeCompleteDelayedCallbacks>(
return std::make_unique<CodeCompleteDelayedCallbacks>(
SourceMgr.getCodeCompletionLoc());
return nullptr;
}
Expand All @@ -777,7 +777,7 @@ void CompilerInstance::parseAndCheckTypesUpTo(
std::unique_ptr<DelayedParsingCallbacks> DelayedCB{
computeDelayedParsingCallback()};

PersistentState = llvm::make_unique<PersistentParserState>(getASTContext());
PersistentState = std::make_unique<PersistentParserState>(getASTContext());

bool hadLoadError = parsePartialModulesAndLibraryFiles(
implicitImports, DelayedCB.get());
Expand Down Expand Up @@ -1048,7 +1048,7 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
MainBufferID);
}

PersistentState = llvm::make_unique<PersistentParserState>(getASTContext());
PersistentState = std::make_unique<PersistentParserState>(getASTContext());

SWIFT_DEFER {
if (ParseDelayedBodyOnEnd)
Expand Down
Loading

0 comments on commit b4d268e

Please sign in to comment.