Does anyone know another way to hunt for spurious
includes?
Sorry -- I meant spurious "usings", not spurious "includes".
Just grepping, it's hard to see the context of the using statements
and I want to check we don't have any outside of function
scopes.
git grep -n -F --show-function "using" src/stan | catSorry -- I meant spurious "usings", not spurious "includes".
Just grepping, it's hard to see the context of the using statements
and I want to check we don't have any outside of function
scopes.
Getting rid of spurious includes is good, too.
We should run this again and clean up now that Daniel's
refactored so much of the math lib.
goodrich@CYBERPOWERPC:/opt/stan$ find src/stan -name '*.hpp' -print | xargs -n 1 -P 7 clang++ -x c++-header -I src -I lib/eigen_3.1.2/ -I lib/boost_1.53.0/ -Wall -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS 2> /tmp/pch_errors.txt
I was getting ready to run this tool again. But first I ran into an issue that confused me. I had thought thatgoodrich@CYBERPOWERPC:/opt/stan$ find src/stan -name '*.hpp' -print | xargs -n 1 -P 7 clang++ -x c++-header -I src -I lib/eigen_3.1.2/ -I lib/boost_1.53.0/ -Wall -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS 2> /tmp/pch_errors.txt
would succeed in making a precompiled header out of every .hpp file in stan/src/. Instead, there are many errors (attached) that do not show up in our file_include tests.
src/stan/math/matrix/typedefs.hpp:9:66: error: no type named 'size_type' in 'Eigen::Matrix<double, -1, -1, 0, -1, -1>'
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>::size_type size_type;
git show 5911afb
...
- typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>::size_type size_type;
+ typedef size_t size_type;
src/stan/memory/chunk_alloc.hpp:34:18: error: use of undeclared identifier 'eight_byte_aligned_malloc'
blocks_(1, eight_byte_aligned_malloc(sizeof(T)*Tnchunks_per_block)),
git show a6bc07e
...
+#include <stan/memory/stack_alloc.hpp>
src/stan/agrad/hessian.hpp:7:10: fatal error: 'stan/agrad/fvar.hpp' file not found #include <stan/agrad/fvar.hpp>
Not fixed but hessian.hpp shouldn't even be in the master branch yet
src/stan/mcmc/nuts_nondiag.hpp:73:21: error: no member named 'sub' in namespace 'stan::math'; did you mean 'sum'? stan::math::sub(xplus, xminus, total_direction);git show 456629d
...
+#include <stan/math/functions/sub.hpp>
src/stan/mcmc/nuts_nondiag.hpp:165:28: error: no matching function for call to 'dot_self' double H0 = -0.5 * stan::math::dot_self(mminus) + this->_logp;git show 4c9a4ab
...
+#include <stan/math/functions/dot_self.hpp>
src/stan/mcmc/nuts_nondiag.hpp:389:22: error: no matching function for call to 'min' prob_sum = stan::math::min(1, exp(newH - H0));
git show 95b4dee
...
- prob_sum = stan::math::min(1, exp(newH - H0));
+ prob_sum = exp(newH - H0);
+ if(prob_sum > 1)
+ prob_sum = 1;
src/stan/mcmc/nuts_massgiven.hpp:71:25: error: no member named 'sub' in namespace 'stan::math'; did you mean 'sum'?
stan::math::sub(xplus, xminus, total_direction);
Same fix as 456629d
src/stan/mcmc/nuts_massgiven.hpp:166:28: error: no matching function for call to 'dot_self'
double H0 = -0.5 * stan::math::dot_self(mminus) + this->_logp;
src/stan/mcmc/nuts_massgiven.hpp:358:22: error: no matching function for call to 'min'
prob_sum = stan::math::min(1, exp(newH - H0));
Same fix as 95b4dee
src/stan/gm/function_signatures.hpp
...
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.In file included from src/stan/gm/grammars/statement_2_grammar.hpp:14:
src/stan/gm/grammars/statement_grammar.hpp:39:7: error: no template named 'statement_2_grammar'; did you mean 'statement_grammar'?
statement_2_grammar<Iterator> statement_2_g;
Not sure what is going wrong here because the statement_2_grammar is #included
src/stan/math/matrix/EigenDenseBaseAddons.hpp:1:18: error: use of undeclared identifier 'internal'
typedef typename internal::traits<Derived>::Index size_type;
src/stan/math/matrix/EigenDenseBaseAddons.hpp:2:18: error: use of undeclared identifier 'internal'
typedef typename internal::traits<Derived>::Scalar value_type;
I think these two are valid, but I don't know if there are any workarounds.
src/stan/math/functions/scaled_add.hpp:13:12: error: unknown type name 'size_t'; did you mean '__gnu_cxx::size_t'?
git show bd513b2
...
+#include <cstddef>
src/stan/math/functions/dist.hpp:12:12: error: unknown type name 'size_t'; did you mean '__gnu_cxx::size_t'?
Same fix as bd513b2
src/stan/math/functions/dist.hpp:10:18: error: no member named 'sqrt' in namespace 'std'
using std::sqrt;
git show f51a02c
...
+#include <cmath>
src/stan/math/functions/dot.hpp:13:12: error: unknown type name 'size_t'; did you mean '__gnu_cxx::size_t'?
Same fix as bd513b2
src/stan/math/functions/sub.hpp:12:12: error: unknown type name 'size_t'; did you mean '__gnu_cxx::size_t'?
Same fix as bd513b2
src/stan/math/functions/sum.hpp:11:12: error: unknown type name 'size_t'; did you mean '__gnu_cxx::size_t'?
Same fix as bd513b2
Ben
Sorry -- I meant spurious "usings", not spurious "includes".
Just grepping, it's hard to see the context of the using statements
and I want to check we don't have any outside of function
scopes.
Getting rid of spurious includes is good, too.
We should run this again and clean up now that Daniel's
refactored so much of the math lib.
goodrich@CYBERPOWERPC:/tmp/llvm/build/bin$ export CFLAGS="-I /opt/stan/src -I /opt/stan/lib/eigen_3.1.2/ -I /opt/stan/lib/boost_1.53.0/ -Wall -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS"
goodrich@CYBERPOWERPC:/tmp/llvm/build/bin$ find /opt/stan/src/stan -name '*.hpp' -print0 | parallel -0 -j7 ./include-what-you-use $CFLAGS {} "2>" {}_iwyu.txt
goodrich@CYBERPOWERPC:/tmp/llvm/build/bin$ cd /opt/stan/src/stan
goodrich@CYBERPOWERPC:/opt/stan/src/stan$ find . -name '*_iwyu.txt' -print0 | xargs -0 tar -rf /tmp/iwyu.tar
goodrich@CYBERPOWERPC:/opt/stan/src/stan$ gzip /tmp/iwyu.tar
cd /tmp
mkdir -p STAN_TEMP/src/stan
cd STAN_TEMP/src/stan
tar -xvf /path/to/iwyu.tar.gz .
src/stan/math/matrix/typedefs.hpp:9:66: error: no type named 'size_type' in 'Eigen::Matrix<double, -1, -1, 0, -1, -1>'
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>::size_type size_type;
git show 5911afb
...
- typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>::size_type size_type;
+ typedef size_t size_type;
Hi Ben,Sorry, but can you explain what this output is supposed to tell us? It looks like there are a lot of non-issues in here. For example:src/stan/math/matrix/typedefs.hpp:9:66: error: no type named 'size_type' in 'Eigen::Matrix<double, -1, -1, 0, -1, -1>' typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>::size_type size_type;git show 5911afb
...
- typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>::size_type size_type;
+ typedef size_t size_type;This comes from us extending Eigen's base type with an EigenDenseMatrixPlugin so we can exchange std::vector and Eigen (row-)vectors and use appropriate types for indexing.
goodrich@CYBERPOWERPC:/opt/eigen$ hg grep "::size_type" Eigen/
Eigen/src/StlSupport/StdDeque.h:4751: typedef typename deque_base::size_type size_type; \
Eigen/src/StlSupport/StdDeque.h:4751: typedef typename deque_base::size_type size_type; \
Eigen/src/StlSupport/StdList.h:4751: typedef typename list_base::size_type size_type; \
Eigen/src/StlSupport/StdList.h:4751: typedef typename list_base::size_type size_type; \
Eigen/src/StlSupport/StdVector.h:4751: typedef vector_base::size_type size_type; \
Eigen/src/StlSupport/StdVector.h:4751: typedef typename vector_base::size_type size_type; \
Eigen/NewStdVector:2630: typedef typename vector_base::size_type size_type; \
Eigen/StdVector:2389: typedef typename vector_base::size_type size_type; \
Eigen/StdVector:2389: typedef typename vector_base::size_type size_type; \
Eigen/src/StdVector/StdVector.h:796: typedef typename unaligned_base::size_type size_type; \
goodrich@CYBERPOWERPC:/opt/stan$ cat src/stan.hpp
#ifndef STAN_HPP
#define STAN_HPP
// #include "stan/gm.hpp"
#include "stan/io.hpp"
#include "stan/memory.hpp"
#include "stan/mcmc.hpp"
#include "stan/meta.hpp"
#include "stan/model.hpp"
#include "stan/prob.hpp"
#include "stan/version.hpp"
#endif
Yes, we wrote an EigenDenseMatrixPlugin. See src/stan/math/matrix/EigenDenseBaseAddons.hpp and how we utilize the plugin in the file Eigen.hpp in the same folder.
I can do it again anytime, but according to the include-what-you-use principle, something likegoodrich@CYBERPOWERPC:/opt/stan$ cat src/stan.hpp
#ifndef STAN_HPP
#define STAN_HPP
// #include "stan/gm.hpp"
#include "stan/io.hpp"
#include "stan/memory.hpp"
#include "stan/mcmc.hpp"
#include "stan/meta.hpp"
#include "stan/model.hpp"
#include "stan/prob.hpp"
#include "stan/version.hpp"
#endif
should just be deleted because whatever might need any of the above .hpp files should be #including it directly rather than #including <stan.hpp> and pulling in those things indirectly. That said, I don't know if it is possible to fully adhere to the include-what-you-use principle, particularly with the model header. I did a model once before at
https://groups.google.com/d/msg/stan-dev/q977l_VE2Ls/0spLJnlceXIJ
and it suggested a lot of changes, but I don't know if it is possible to make the parser sophisticated enough to do that for an arbitrary model.
Ben
Although I agree in principle, I don't think it's that easy to build a minimal include list for arbitrary models that may be generated by users. If you wanted to run it on something that represents the language as a whole, if you can figure out a way to paste together all the Stan models we compile to verify parsing and generation, that would be worthwhile. The files are located under src/test/gm/model_specs/compiled/.
Indexes in Eigen are ints :-( So as not to
get gripes from the compiler about signed/unsigned
assignments, we need to use the typedefs in polymorphic
code.
std::ptrdiff_t by default.goodrich@CYBERPOWERPC:/opt/stan/src/stan$ find . -name '*_iwyu.txt' -print0 | xargs -0 wc -l | sort -g -r > /tmp/iwyu_sorted.txt