[lld] r213312 - Use std::function instead of llvm::function_ref.

Rui Ueyama ruiu at google.com
Sun Jul 27 13:39:27 PDT 2014


The function passed to registerObserver() is used after the function
returns, so we cannot make it a llvm::function_ref. This is a minus delta
patch that apparently simplifies the stuff.


On Sun, Jul 27, 2014 at 12:21 PM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> Why? inst't llvm::function_ref preferred when it is valid?
>
> On 17 July 2014 17:23, Rui Ueyama <ruiu at google.com> wrote:
> > Author: ruiu
> > Date: Thu Jul 17 16:23:52 2014
> > New Revision: 213312
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=213312&view=rev
> > Log:
> > Use std::function instead of llvm::function_ref.
> >
> > Modified:
> >     lld/trunk/include/lld/Core/InputGraph.h
> >     lld/trunk/lib/Core/InputGraph.cpp
> >     lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
> >
> > Modified: lld/trunk/include/lld/Core/InputGraph.h
> > URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=213312&r1=213311&r2=213312&view=diff
> >
> ==============================================================================
> > --- lld/trunk/include/lld/Core/InputGraph.h (original)
> > +++ lld/trunk/include/lld/Core/InputGraph.h Thu Jul 17 16:23:52 2014
> > @@ -24,6 +24,7 @@
> >  #include "llvm/Support/MemoryBuffer.h"
> >  #include "llvm/Support/raw_ostream.h"
> >
> > +#include <functional>
> >  #include <memory>
> >  #include <stack>
> >  #include <vector>
> > @@ -71,7 +72,7 @@ public:
> >    /// Adds an observer of getNextFile(). Each time a new file is about
> to be
> >    /// returned from getNextFile(), registered observers are called with
> the file
> >    /// being returned.
> > -  void registerObserver(llvm::function_ref<void(File *)> fn);
> > +  void registerObserver(std::function<void(File *)>);
> >
> >    /// \brief Adds a node into the InputGraph
> >    void addInputElement(std::unique_ptr<InputElement>);
> > @@ -99,7 +100,7 @@ protected:
> >    // Index of the next element to be processed
> >    uint32_t _nextElementIndex;
> >    InputElement *_currentInputElement;
> > -  std::vector<llvm::function_ref<void(File *)>> _observers;
> > +  std::vector<std::function<void(File *)>> _observers;
> >
> >  private:
> >    ErrorOr<InputElement *> getNextInputElement();
> >
> > Modified: lld/trunk/lib/Core/InputGraph.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?rev=213312&r1=213311&r2=213312&view=diff
> >
> ==============================================================================
> > --- lld/trunk/lib/Core/InputGraph.cpp (original)
> > +++ lld/trunk/lib/Core/InputGraph.cpp Thu Jul 17 16:23:52 2014
> > @@ -38,7 +38,7 @@ ErrorOr<File &> InputGraph::getNextFile(
> >
> >  void InputGraph::notifyProgress() {
> _currentInputElement->notifyProgress(); }
> >
> > -void InputGraph::registerObserver(llvm::function_ref<void(File *)> fn) {
> > +void InputGraph::registerObserver(std::function<void(File *)> fn) {
> >    _observers.push_back(fn);
> >  }
> >
> >
> > Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=213312&r1=213311&r2=213312&view=diff
> >
> ==============================================================================
> > --- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
> > +++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Thu Jul
> 17 16:23:52 2014
> > @@ -101,20 +101,6 @@ std::unique_ptr<File> PECOFFLinkingConte
> >        "<command line option /include>");
> >  }
> >
> > -namespace {
> > -// As per policy, we cannot use std::function.
> > -class ObserverCallback {
> > -public:
> > -  explicit ObserverCallback(pecoff::ExportedSymbolRenameFile *f)
> > -      : _renameFile(f) {}
> > -
> > -  void operator()(File *file) {
> _renameFile->addResolvableSymbols(file); }
> > -
> > -private:
> > -  pecoff::ExportedSymbolRenameFile *_renameFile;
> > -};
> > -} // end anonymous namespace
> > -
> >  bool PECOFFLinkingContext::createImplicitFiles(
> >      std::vector<std::unique_ptr<File>> &) const {
> >    // Create a file for __ImageBase.
> > @@ -140,7 +126,7 @@ bool PECOFFLinkingContext::createImplici
> >    exportNode->appendInputFile(std::unique_ptr<File>(renameFile));
> >    getLibraryGroup()->addFile(std::move(exportNode));
> >    getInputGraph().registerObserver(
> > -      *(new (_allocator) ObserverCallback(renameFile)));
> > +      [=](File *file) { renameFile->addResolvableSymbols(file); });
> >    return true;
> >  }
> >
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140727/ee115cf5/attachment.html>


More information about the llvm-commits mailing list