serge-sans-paille / pythran

Ahead of Time compiler for numeric kernels
https://pythran.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.01k stars 193 forks source link

Long C++ errors in sudoku solver #1356

Closed Dapid closed 5 years ago

Dapid commented 5 years ago

I wrote a quick and not so smart sudoku solver. Unfortunately, Pythran cannot compile it. I have been trying to distill it to the minimal failing case and gotten somewhere. I have two fairly minimal versions where they fail, but I haven't been able to pinpoint the problem.

Any ideas?

/tmp/tmpwnbvs4_8.cpp: In instantiation of ‘typename __pythran_solver::solve_lookahead::type<argument_type0, argument_type1>::result_type __pythran_solver::solve_lookahead::operator()(argument_type0&&, argument_type1) const [with argument_type0 = {anonymous}::pythonic::types::numpy_texpr<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >&; argument_type1 = bool; typename __pythran_solver::solve_lookahead::type<argument_type0, argument_type1>::result_type = {anonymous}::pythonic::types::numpy_texpr<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >]’:
/tmp/tmpwnbvs4_8.cpp:1760:93:   required from here
/tmp/tmpwnbvs4_8.cpp:1698:209: error: could not convert ‘{anonymous}::pythonic::__builtin__::functor::list::operator()(Types&& ...) const [with Types = {{anonymous}::pythonic::types::list<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >}; decltype ({anonymous}::pythonic::__builtin__::anonymous::list((forward<Types>)(<unnamed>::pythonic::__builtin__::functor::list::operator()::types)...)) = {anonymous}::pythonic::types::list<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >]({anonymous}::pythonic::__builtin__::functor::map::operator()(Types&& ...) const [with Types = {__pythran_solver::solve_lookahead_lambda2, {anonymous}::pythonic::types::list<std::tuple<{anonymous}::pythonic::types::dict<{anonymous}::pythonic::types::array_base<long int, 2, {anonymous}::pythonic::types::tuple_version>, {anonymous}::pythonic::types::set<long int> >, {anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > > >}; decltype ({anonymous}::pythonic::__builtin__::map((forward<Types>)(<unnamed>::pythonic::__builtin__::functor::map::operator()::types)...)) = {anonymous}::pythonic::types::list<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >](__pythran_solver::solve_lookahead_lambda2(), {anonymous}::pythonic::__builtin__::functor::filter::operator()(Types&& ...) const [with Types = {__pythran_solver::solve_lookahead_lambda3, {anonymous}::pythonic::types::list<std::tuple<{anonymous}::pythonic::types::dict<{anonymous}::pythonic::types::array_base<long int, 2, {anonymous}::pythonic::types::tuple_version>, {anonymous}::pythonic::types::set<long int> >, {anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > > >&}; decltype ({anonymous}::pythonic::__builtin__::filter((forward<Types>)(<unnamed>::pythonic::__builtin__::functor::filter::operator()::types)...)) = {anonymous}::pythonic::types::list<std::tuple<{anonymous}::pythonic::types::dict<{anonymous}::pythonic::types::array_base<long int, 2, {anonymous}::pythonic::types::tuple_version>, {anonymous}::pythonic::types::set<long int> >, {anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > > >](__pythran_solver::solve_lookahead_lambda3(), valid_possibilities)))’ from ‘{anonymous}::pythonic::types::list<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >’ to ‘__pythran_solver::solve_lookahead::type<{anonymous}::pythonic::types::numpy_texpr<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >&, bool>::result_type’ {aka ‘{anonymous}::pythonic::types::numpy_texpr<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >’}
 1698 |         return pythonic::__builtin__::functor::list{}(pythonic::__builtin__::functor::map{}(solve_lookahead_lambda2(), pythonic::__builtin__::functor::filter{}(solve_lookahead_lambda3(), valid_possibilities)));
      |                                                                                                                                                                                                                 ^
      |                                                                                                                                                                                                                 |
      |                                                                                                                                                                                                                 {anonymous}::pythonic::types::list<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /home/david/.virtualenvs/py36/lib/python3.6/site-packages/pythran/pythonic/include/types/traits.hpp:4,
                 from /home/david/.virtualenvs/py36/lib/python3.6/site-packages/pythran/pythonic/include/types/combined.hpp:4,
                 from /home/david/.virtualenvs/py36/lib/python3.6/site-packages/pythran/pythonic/types/combined.hpp:4,for _ in range(10)
                 from /home/david/.virtualenvs/py36/lib/python3.6/site-packages/pythran/pythonic/core.hpp:25,
                 from /tmp/tmpwnbvs4_8.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h: In instantiation of ‘static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = {anonymous}::pythonic::types::nditerator<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >; _OI = signed char*]’:
/usr/include/c++/9/bits/stl_algobase.h:404:30:   required from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = {anonymous}::pythonic::types::nditerator<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >; _OI = signed char*]’
/usr/include/c++/9/bits/stl_algobase.h:441:30:   required from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = {anonymous}::pythonic::types::nditerator<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >; _OI = signed char*]’
/usr/include/c++/9/bits/stl_algobase.h:474:7:   required from ‘_OI std::copy(_II, _II, _OI) [with _II = {anonymous}::pythonic::types::nditerator<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >; _OI = signed char*]’
/home/david/.virtualenvs/py36/lib/python3.6/site-packages/pythran/pythonic/types/ndarray.hpp:237:21:   required from ‘static T* {anonymous}::pythonic::types::type_helper<const {anonymous}::pythonic::types::ndarray<T, {anonymous}::pythonic::types::pshape<T> >&>::initialize_from_iterable(S&, T*, Iter&&) [with S = {anonymous}::pythonic::types::pshape<long int, long int>; Iter = {anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> >&; T = signed char; pS = long int]’
/home/david/.virtualenvs/py36/lib/python3.6/site-packages/pythran/pythonic/types/ndarray.hpp:157:35:   required from ‘static T* {anonymous}::pythonic::types::type_helper<const {anonymous}::pythonic::types::ndarray<T, pS>&>::initialize_from_iterable(S&, T*, Iter&&) [with S = {anonymous}::pythonic::types::pshape<long int, long int>; Iter = {anonymous}::pythonic::types::list<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >; T = signed char; pS = {anonymous}::pythonic::types::pshape<long int, long int>]’                                                                                                                                                                                                                                                                                      
/home/david/.virtualenvs/py36/lib/python3.6/site-packages/pythran/pythonic/types/ndarray.hpp:113:73:   required from ‘static T* {anonymous}::pythonic::types::type_helper<{anonymous}::pythonic::types::ndarray<T, pS> >::initialize_from_iterable(S&, T*, Iter&&) [with S = {anonymous}::pythonic::types::pshape<long int, long int>; Iter = {anonymous}::pythonic::types::list<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >; T = signed char; pS = {anonymous}::pythonic::types::pshape<long int, long int>]’  
/home/david/.virtualenvs/py36/lib/python3.6/site-packages/pythran/pythonic/types/ndarray.hpp:463:51:   required from ‘{anonymous}::pythonic::types::ndarray<T, pS>::ndarray(Iterable&&) [with Iterable = {anonymous}::pythonic::types::list<{anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> > >; <template-parameter-2-2> = void; T = signed char; pS = {anonymous}::pythonic::types::pshape<long int, long int>]’                                                                                                      
/tmp/tmpwnbvs4_8.cpp:1698:209:   required from ‘typename __pythran_solver::solve_lookahead::type<argument_type0, argument_type1>::result_type __pythran_solver::solve_lookahead::operator()(argument_type0&&, argument_type1) const [with argument_type0 = {anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> >&; argument_type1 = bool; typename __pythran_solver::solve_lookahead::type<argument_type0, argument_type1>::result_type = {anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> >]’                                                                                                                                                                                                                                                             
/tmp/tmpwnbvs4_8.cpp:1745:93:   required from here                                                                                                                                                                                                                                        
/usr/include/c++/9/bits/stl_algobase.h:342:18: error: cannot convert ‘{anonymous}::pythonic::types::numpy_iexpr<const {anonymous}::pythonic::types::ndarray<signed char, {anonymous}::pythonic::types::pshape<long int, long int> >&>’ to ‘signed char’ in assignment                     
  342 |        *__result = *__first;                                                                                                                                                                                                                                                      
      |        ~~~~~~~~~~^~~~~~~~~~                                                                                                                                                                                                                                                       
WARNING  Compilation error, trying hard to find its origin...                                                                                                                                                                                                                             
WARNING  Nop, I'm going to flood you with C++ errors!                                                                                                                                                                                                                                     
CRITICAL Cover me Jack. Jack? Jaaaaack!!!!                                                                                                                                                                                                                                                
E: error: Command "gcc -pthread -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -march=native -O2 -pipe -fPIC -DENABLE_PYTHON_MODULE -D__PYTHRAN__=3 -DPYTHRAN_BLAS_OPENBLAS -I/home/david/.virtualenvs/py36/lib/python3.6/site-packages/pythran -I/home/david/.virtualenvs/py36/lib/python3.6/site-packages/numpy/core/include -I/usr/include/python3.6m -c /tmp/tmpwnbvs4_8.cpp -o /tmp/tmp1tubgd11/tmp/tmpwnbvs4_8.o -std=c++11 -fno-math-errno -w -fvisibility=hidden -fno-wrapv" failed with exit status 1              

Note: it takes 7 minutes to compile.

serge-sans-paille commented 5 years ago

From the solve_lookahead function, you have two return paths:

return possibilities[0][1] # type: NDArray[int8,:,:]

or

return pp # type: # type: Tuple[Dict[(int, int), Set[int]], NDArray[int8,:,:]]

they are incompatible.