serge-sans-paille / pythran

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

Misused global variables #1633

Open diorcety opened 4 years ago

diorcety commented 4 years ago

Pythran generate function for exposing global variable but don't use it. Example for

gg = [0, 2, 4, 5]

#pythran export aa(int)
def aa(s):
    return [x + s for x in gg]

The following code is generated


  typename gg::type::result_type gg::operator()() const
  {
    {
      static typename gg::type::result_type tmp_global = typename pythonic::assignable<typename __combined<pythonic::types::list<typename std::remove_reference<long>::type>,pythonic::types::list<typename std::remove_reference<typename __combined<typename __combined<typename __combined<typename std::remove_cv<typename std::remove_reference<decltype(4L)>::type>::type,typename std::remove_cv<typename std::remove_reference<decltype(5L)>::type>::type>::type,typename std::remove_cv<typename std::remove_reference<decltype(2L)>::type>::type>::type,typename std::remove_cv<typename std::remove_reference<decltype(0L)>::type>::type>::type>::type>>::type>::type({0L, 2L, 4L, 5L});
      return tmp_global;
    }
  }
  template <typename argument_type0 >
  typename aa::type<argument_type0>::result_type aa::operator()(argument_type0&& s) const
  {
    return pythonic::builtins::functor::list{}(pythonic::builtins::functor::map{}(pythonic::functools::functor::partial{}(aa_lambda0(), s), pythonic::builtins::pythran::functor::static_list{}(pythonic::types::make_tuple(0L, 2L, 4L, 5L))));
  }
serge-sans-paille commented 4 years ago

After some thought: the right approach would be to make all the constructor constexpr, so that building a static_list or a tuple is free

serge-sans-paille commented 4 years ago

Because we actually want global scalars to be inlined

serge-sans-paille commented 4 years ago

Does #1637 improve the situation, performance-wise? It only affects lists...

diorcety commented 4 years ago

Didn't improve significantly.