stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 269 forks source link

rstan compilation conflict with class std::auto_ptr #777

Open bergen288 opened 4 years ago

bergen288 commented 4 years ago

Summary:

rstan compilation conflict with class std::auto_ptr.

Description:

rstan_2.19.3.tar.gz is installed with lots of warning message as below:

In file included from /opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8.3.0/include/c++/memory:80,
                 from /software/R/site-library/BH/include/boost/move/algorithm.hpp:33,
                 from /software/R/site-library/BH/include/boost/move/move.hpp:32,
                 from /software/R/site-library/BH/include/boost/variant/detail/move.hpp:28,
                 from /software/R/site-library/BH/include/boost/variant/recursive_wrapper.hpp:17,
                 from /software/R/site-library/BH/include/boost/variant/detail/enable_recursive.hpp:34,
                 from /software/R/site-library/BH/include/boost/variant/recursive_variant.hpp:17,
                 from /software/R/site-library/StanHeaders/include/src/stan/lang/ast/node/expression.hpp:4,
                 from /software/R/site-library/StanHeaders/include/src/stan/lang/ast/type/bare_expr_type.hpp:4,
                 from /software/R/site-library/StanHeaders/include/src/stan/lang/ast/variable_map.hpp:5,
                 from /software/R/site-library/StanHeaders/include/src/stan/lang/ast.hpp:7,
                 from /software/R/site-library/StanHeaders/include/src/stan/lang/compiler.hpp:5,
                 from stanc.cpp:22:
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8.3.0/include/c++/bits/unique_ptr.h:53:28: note: declared here
   template<typename> class auto_ptr;
                            ^~~~~~~~

In /opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8.3.0/include/c++/bits/unique_ptr.h, class auto_ptr is defined as template<typename> class auto_ptr;.
In backward/auto_ptr.h which is included from /opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8.3.0/include/c++/memory, class auto_ptr is defined twice:

  template<typename _Tp>
    class auto_ptr
    {
    private:
      _Tp* _M_ptr;

    public:
      /// The pointed-to type.
      typedef _Tp element_type;

      /**
       *  @brief  An %auto_ptr is usually constructed from a raw pointer.
       *  @param  __p  A pointer (defaults to NULL).
       *
       *  This object now @e owns the object pointed to by @a __p.
       */
      explicit
      auto_ptr(element_type* __p = 0) throw() : _M_ptr(__p) { }

      /**
       *  @brief  An %auto_ptr can be constructed from another %auto_ptr.
       *  @param  __a  Another %auto_ptr of the same type.
       *
       *  This object now @e owns the object previously owned by @a __a,
       *  which has given up ownership.
       */
      auto_ptr(auto_ptr& __a) throw() : _M_ptr(__a.release()) { }

      /**
       *  @brief  An %auto_ptr can be constructed from another %auto_ptr.
       *  @param  __a  Another %auto_ptr of a different but related type.
       *
       *  A pointer-to-Tp1 must be convertible to a
       *  pointer-to-Tp/element_type.
       *
       *  This object now @e owns the object previously owned by @a __a,
       *  which has given up ownership.
       */
      template<typename _Tp1>
        auto_ptr(auto_ptr<_Tp1>& __a) throw() : _M_ptr(__a.release()) { }

      /**
       *  @brief  %auto_ptr assignment operator.
       *  @param  __a  Another %auto_ptr of the same type.
       *
       *  This object now @e owns the object previously owned by @a __a,
       *  which has given up ownership.  The object that this one @e
       *  used to own and track has been deleted.
       */
      auto_ptr&
      operator=(auto_ptr& __a) throw()
      {
    reset(__a.release());
    return *this;
      }

      /**
       *  @brief  %auto_ptr assignment operator.
       *  @param  __a  Another %auto_ptr of a different but related type.
       *
       *  A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type.
       *
       *  This object now @e owns the object previously owned by @a __a,
       *  which has given up ownership.  The object that this one @e
       *  used to own and track has been deleted.
       */
      template<typename _Tp1>
        auto_ptr&
        operator=(auto_ptr<_Tp1>& __a) throw()
        {
      reset(__a.release());
      return *this;
    }

      /**
       *  When the %auto_ptr goes out of scope, the object it owns is
       *  deleted.  If it no longer owns anything (i.e., @c get() is
       *  @c NULL), then this has no effect.
       *
       *  The C++ standard says there is supposed to be an empty throw
       *  specification here, but omitting it is standard conforming.  Its
       *  presence can be detected only if _Tp::~_Tp() throws, but this is
       *  prohibited.  [17.4.3.6]/2
       */
      ~auto_ptr() { delete _M_ptr; }

      /**
       *  @brief  Smart pointer dereferencing.
       *
       *  If this %auto_ptr no longer owns anything, then this
       *  operation will crash.  (For a smart pointer, <em>no longer owns
       *  anything</em> is the same as being a null pointer, and you know
       *  what happens when you dereference one of those...)
       */
      element_type&
      operator*() const throw() 
      {
    __glibcxx_assert(_M_ptr != 0);
    return *_M_ptr; 
      }

      /**
       *  @brief  Smart pointer dereferencing.
       *
       *  This returns the pointer itself, which the language then will
       *  automatically cause to be dereferenced.
       */
      element_type*
      operator->() const throw() 
      {
    __glibcxx_assert(_M_ptr != 0);
    return _M_ptr; 
      }

      /**
       *  @brief  Bypassing the smart pointer.
       *  @return  The raw pointer being managed.
       *
       *  You can get a copy of the pointer that this object owns, for
       *  situations such as passing to a function which only accepts
       *  a raw pointer.
       *
       *  @note  This %auto_ptr still owns the memory.
       */
      element_type*
      get() const throw() { return _M_ptr; }

      /**
       *  @brief  Bypassing the smart pointer.
       *  @return  The raw pointer being managed.
       *
       *  You can get a copy of the pointer that this object owns, for
       *  situations such as passing to a function which only accepts
       *  a raw pointer.
       *
       *  @note  This %auto_ptr no longer owns the memory.  When this object
       *  goes out of scope, nothing will happen.
       */
      element_type*
      release() throw()
      {
    element_type* __tmp = _M_ptr;
    _M_ptr = 0;
    return __tmp;
      }

      /**
       *  @brief  Forcibly deletes the managed object.
       *  @param  __p  A pointer (defaults to NULL).
       *
       *  This object now @e owns the object pointed to by @a __p.  The
       *  previous object has been deleted.
       */
      void
      reset(element_type* __p = 0) throw()
      {
    if (__p != _M_ptr)
      {
        delete _M_ptr;
        _M_ptr = __p;
      }
      } 

  template<>
    class auto_ptr<void>
    {
    public:
      typedef void element_type;
    } _GLIBCXX_DEPRECATED;

Reproducible Steps:

library(rstan)
model_code <- 'parameters {real y;} model {y ~ normal(0,1);}'
fit <- stan(model_code=model_code)   
mean(extract(fit)$y)   

Current Output:

Failed with warning: 'template class std::auto_ptr' is dep

Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.19.3, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
Error in compileCode(f, code, language = language, verbose = verbose) :
  Compilation ERROR, function(s)/method(s) not created! fileef016a50f67cfc.cpp:6:36: warning: ISO C++11 requires whitespace after the macro name
 #define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
                                    ^
In file included from /software/R/site-library/BH/include/boost/smart_ptr/shared_ptr.hpp:28,
                 from /software/R/site-library/BH/include/boost/shared_ptr.hpp:17,
                 from /software/R/site-library/BH/include/boost/date_time/time_clock.hpp:17,
                 from /software/R/site-library/BH/include/boost/date_time/posix_time/posix_time_types.hpp:10,
                 from /software/R/site-library/rstan/include/rstan/stan_fit.hpp:13,
                 from /software/R/site-library/rstan/include/rstan/rstaninc.hpp:3,
                 from fileef016a50f67cfc.cpp:7:
/software/R/site-library/BH/include/boost/smart_ptr/detail/shared_count.hpp:356:33: warning: 'template<class> class std::auto_ptr' is dep
Calls: stan ... cxxfunctionplus -> <Anonymous> -> cxxfunction -> compileCode
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command '/opt/freeware/lib64/R/bin/R CMD SHLIB fileef016a50f67cfc.cpp 2> fileef016a50f67cfc.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection
Calls: stan -> stan_model -> cxxfunctionplus -> sink
Execution halted.

Expected Output:

How to avoid the conflicted auto_ptr?

RStan Version:

rstan (Version 2.19.3, GitRev: 2e1f913d3ca3)

R Version:

R3.6.1

Operating System:

AIX7.2

SteveBronder commented 4 years ago

What version of the boost headers are you using? I've seen something like this happen before when rstan was updated but BH was not

bergen288 commented 4 years ago

Steve: My BH Version: 1.72.0-3. This is the most recent version in its R CRAN website.

Thanks.

bergen288 commented 4 years ago

This issue was actually reported 3 years ago here: https://github.com/stan-dev/rstan/issues/409. Dirk suggested to add -DBOOST_NO_AUTO_PTR to disable "auto_ptr" so I added it at the end of following line in rstan/src/Makevars file.

PKG_CPPFLAGS = -I"../inst/include" -I"." -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DBOOST_NO_AUTO_PTR 

The rstan package was installed without warning for auto_ptr. But it has lots of warning as below:

ld: 0711-768 WARNING: Object stan/lang/ast_def.o, section 1, function .stan::lang::bare_array_type::oid[abi:cxx11]() const:
    The branch at address 0x91e1c is not followed by a recognized no-op
    or TOC-reload instruction. The unrecognized instruction is 0x38210080.
ld: 0711-768 WARNING: Object stan/lang/ast_def.o, section 1, function .stan::lang::write_expression_vis::operator()[abi:cxx11](stan::lang::binary_op const&) const:
    The branch at address 0x97314 is not followed by a recognized no-op
    or TOC-reload instruction. The unrecognized instruction is 0xE8010090.

The key problem is that I have the same error shown in Current Output section. Now what? Thanks.

Error in compileCode(f, code, language = language, verbose = verbose) :
  Compilation ERROR, function(s)/method(s) not created! file12f01b635c2537.cpp:6:36: warning: ISO C++11 requires whitespace after the macro name
 #define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
                                    ^
In file included from /software/R/site-library/BH/include/boost/smart_ptr/shared_ptr.hpp:28,
                 from /software/R/site-library/BH/include/boost/shared_ptr.hpp:17,
                 from /software/R/site-library/BH/include/boost/date_time/time_clock.hpp:17,
                 from /software/R/site-library/BH/include/boost/date_time/posix_time/posix_time_types.hpp:10,
                 from /software/R/site-library/rstan/include/rstan/stan_fit.hpp:13,
                 from /software/R/site-library/rstan/include/rstan/rstaninc.hpp:3,
                 from file12f01b635c2537.cpp:7:
/software/R/site-library/BH/include/boost/smart_ptr/detail/shared_count.hpp:356:33: warning: 'template<class> class std::auto_ptr' is dep
Calls: stan ... cxxfunctionplus -> <Anonymous> -> cxxfunction -> compileCode
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command '/opt/freeware/lib64/R/bin/R CMD SHLIB file12f01b635c2537.cpp 2> file12f01b635c2537.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection
Calls: stan -> stan_model -> cxxfunctionplus -> sink
Execution halted
SteveBronder commented 4 years ago

It looks like the warning got cut off

warning: 'template<class> class std::auto_ptr' is dep

and it doesn't seem like the error is posted in your last comment.

I've never worked with a powerpc based system before so I can't say much, but it looks like the compiler is attempting to apply an instruction that does not exist? Can you post your full session info? If you are using -mtune=native then maybe you can try -mtune=generic?