Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC: Fixes #166

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lager/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#define LAGER_HAS_CPP17 1
#endif

#if defined(_MSC_VER) && !defined(LAGER_DISABLE_STORE_DEPENDENCY_CHECKS)
#define LAGER_DISABLE_STORE_DEPENDENCY_CHECKS
#endif

#ifdef __has_feature
#if !__has_feature(cxx_exceptions)
#define LAGER_NO_EXCEPTIONS
Expand Down
3 changes: 2 additions & 1 deletion lager/store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ class store
base_t::send_down();
base_t::notify();
}
auto& ctxMsvcWorkaround = ctx;
if constexpr (std::is_same_v<void,
decltype(eff(ctx))>) {
Comment on lines +172 to -173
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of binding ctx to ctxMsvcWorkaround, have you tried using this->ctx in the decltype expression?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I tried that first... It fails with the original error:

Error Report
D:\Work\cpp_ui\lager\lager/store.hpp(174,56): error C2039: 'ctx': is not a member of 'lager::store<action_t,model_t,deps_t>::store_node<ReducerFn,EventLoop,Deps,Tags>::dispatch::<lambda_2>::()::<lambda_1>' [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              ReducerFn=lager::default_reducer_t,
              EventLoop=lager::with_manual_event_loop,
              Deps=deps_t,
              Tags=boost::hana::set<boost::hana::type_impl<void>::_>
          ]
D:\Work\cpp_ui\lager\lager/store.hpp(196): message : see declaration of 'lager::store<action_t,model_t,deps_t>::store_node<ReducerFn,EventLoop,Deps,Tags>::dispatch::<lambda_2>::()::<lambda_1>' [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              ReducerFn=lager::default_reducer_t,
              EventLoop=lager::with_manual_event_loop,
              Deps=deps_t,
              Tags=boost::hana::set<boost::hana::type_impl<void>::_>
          ]
D:\Work\cpp_ui\lager\lager/effect.hpp(224): message : see reference to function template instantiation 'auto lager::store<action_t,model_t,deps_t>::store_node<ReducerFn,EventLoop,Deps,Tags>::dispatch::<lambda_2>::()::<lambda_1>::operator ()<_This&>(_T1) const' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              ReducerFn=lager::default_reducer_t,
              EventLoop=lager::with_manual_event_loop,
              Deps=deps_t,
              Tags=boost::hana::set<boost::hana::type_impl<void>::_>,
              _This=lager::effect<Action,lager::deps<Effect &>>,
              _T1=lager::effect<Action,lager::deps<Effect &>> &
          ]
D:\Work\cpp_ui\lager\lager/store.hpp(196): message : see reference to function template instantiation 'immer::vector<const std::string,immer::default_memory_policy,5,2> lager::invoke_reducer<lager::deps<lager::dep::ref<T>,lager::dep::val<lager::with_debugger::<lambda_1>>>,lager::default_reducer_t&,const immer::vector<const std::string,immer::default_memory_policy,5,2>&,Action,lager::store<action_t,model_t,deps_t>::store_node<ReducerFn,EventLoop,Deps,Tags>::dispatch::<lambda_2>::()::<lambda_1>,lager::store<action_t,model_t,deps_t>::store_node<ReducerFn,EventLoop,Deps,Tags>::dispatch::<lambda_2>::()::<lambda_2>>(Reducer,Model,Action &&,EffectHandler &&,NoEffectHandler &&)' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              T=Effect,
              ReducerFn=lager::default_reducer_t,
              EventLoop=lager::with_manual_event_loop,
              Deps=deps_t,
              Tags=boost::hana::set<boost::hana::type_impl<void>::_>,
              Reducer=lager::default_reducer_t &,
              Model=const immer::vector<const std::string,immer::default_memory_policy,5,2> &,
              Action=Action,
              EffectHandler=lager::store<action_t,model_t,deps_t>::store_node<lager::default_reducer_t,lager::with_manual_event_loop,deps_t,boost::hana::set<boost::hana::type_impl<void>::_>>::dispatch::<lambda_2>::()::<lambda_1>,
              NoEffectHandler=lager::store<action_t,model_t,deps_t>::store_node<lager::default_reducer_t,lager::with_manual_event_loop,deps_t,boost::hana::set<boost::hana::type_impl<void>::_>>::dispatch::<lambda_2>::()::<lambda_2>
          ]
D:\Work\cpp_ui\lager\lager/store.hpp(150): message : while compiling class template member function 'lager::future lager::store<action_t,model_t,deps_t>::store_node<ReducerFn,EventLoop,Deps,Tags>::dispatch(Action)' [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              ReducerFn=lager::default_reducer_t,
              EventLoop=lager::with_manual_event_loop,
              Deps=deps_t,
              Tags=boost::hana::set<boost::hana::type_impl<void>::_>
          ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(1893): message : see reference to class template instantiation 'lager::store<action_t,model_t,deps_t>::store_node<ReducerFn,EventLoop,Deps,Tags>' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              ReducerFn=lager::default_reducer_t,
              EventLoop=lager::with_manual_event_loop,
              Deps=deps_t,
              Tags=boost::hana::set<boost::hana::type_impl<void>::_>
          ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\memory(2027): message : see reference to class template instantiation 'std::_Wrap<_Ty>' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              _Ty=lager::store<action_t,model_t,deps_t>::store_node<lager::default_reducer_t,lager::with_manual_event_loop,deps_t,boost::hana::set<boost::hana::type_impl<void>::_>>
          ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\memory(2725): message : see reference to class template instantiation 'std::_Ref_count_obj2<_Ty>' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              _Ty=lager::store<action_t,model_t,deps_t>::store_node<lager::default_reducer_t,lager::with_manual_event_loop,deps_t,boost::hana::set<boost::hana::type_impl<void>::_>>
          ]
D:\Work\cpp_ui\lager\lager/store.hpp(87): message : see reference to function template instantiation 'std::shared_ptr<lager::store<action_t,model_t,deps_t>::store_node<ReducerFn,EventLoop,Deps,Tags>> std::make_shared<lager::store<action_t,model_t,deps_t>::store_node<ReducerFn,EventLoop,Deps,Tags>,immer::vector<const std::string,immer::default_memory_policy,5,2>,lager::default_reducer_t,lager::with_manual_event_loop,lager::deps<lager::dep::ref<T>,lager::dep::val<lager::with_debugger::<lambda_1>>>>(immer::vector<const std::string,immer::default_memory_policy,5,2> &&,lager::default_reducer_t &&,lager::with_manual_event_loop &&,lager::deps<lager::dep::ref<T>,lager::dep::val<lager::with_debugger::<lambda_1>>> &&)' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              ReducerFn=lager::default_reducer_t,
              EventLoop=lager::with_manual_event_loop,
              Deps=deps_t,
              Tags=boost::hana::set<boost::hana::type_impl<void>::_>,
              T=Effect
          ]
D:\Work\cpp_ui\lager\lager/store.hpp(376): message : see reference to function template instantiation 'lager::store<action_t,model_t,deps_t>::store<lager::default_reducer_t,_T19,_T14,_T15>(immer::vector<const std::string,immer::default_memory_policy,5,2>,ReducerFn,EventLoop,Deps,Tags)' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              _T19=lager::with_manual_event_loop,
              _T14=deps_t,
              _T15=boost::hana::set<boost::hana::type_impl<void>::_>,
              ReducerFn=lager::default_reducer_t,
              EventLoop=lager::with_manual_event_loop,
              Deps=deps_t,
              Tags=boost::hana::set<boost::hana::type_impl<void>::_>
          ]
D:\Work\cpp_ui\lager\lager/store.hpp(371): message : see reference to function template instantiation 'lager::store<action_t,model_t,deps_t>::store<lager::default_reducer_t,_T19,_T14,_T15>(immer::vector<const std::string,immer::default_memory_policy,5,2>,ReducerFn,EventLoop,Deps,Tags)' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              _T19=lager::with_manual_event_loop,
              _T14=deps_t,
              _T15=boost::hana::set<boost::hana::type_impl<void>::_>,
              ReducerFn=lager::default_reducer_t,
              EventLoop=lager::with_manual_event_loop,
              Deps=deps_t,
              Tags=boost::hana::set<boost::hana::type_impl<void>::_>
          ]
D:\Work\cpp_ui\lager\lager/store.hpp(260): message : see reference to function template instantiation 'lager::store<action_t,model_t,deps_t> lager::make_store::<lambda_1>::operator ()<_T16,_T17,const lager::default_reducer_t&,_T19,deps_t,_T21>(_T10,_T11 &&,_T12,_T13 &&,_T14 &&,_T15 &&) const' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              _T16=lager::type_<Action>,
              _T17=State,
              _T19=lager::with_manual_event_loop,
              _T21=boost::hana::set<boost::hana::type_impl<void>::_>,
              _T10=lager::type_<Action>,
              _T11=State,
              _T12=const lager::default_reducer_t &,
              _T13=lager::with_manual_event_loop,
              _T14=deps_t,
              _T15=boost::hana::set<boost::hana::type_impl<void>::_>
          ]
D:\Work\cpp_ui\lager\lager/store.hpp(360): message : see reference to function template instantiation 'lager::store<action_t,model_t,deps_t> lager::with_deps::<lambda_1>::()::<lambda_1>::operator ()<lager::type_<Action>,_Ty,const lager::default_reducer_t&,lager::with_manual_event_loop,lager::deps<>,boost::hana::set<boost::hana::type_impl<Tag>::_>>(_T16,_T17 &&,_T18,_T19 &&,_T20 &&,_T21 &&) const' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              Action=Action,
              _Ty=State,
              Tag=void,
              _T16=lager::type_<Action>,
              _T17=State,
              _T18=const lager::default_reducer_t &,
              _T19=lager::with_manual_event_loop,
              _T20=lager::deps<>,
              _T21=boost::hana::set<boost::hana::type_impl<void>::_>
          ]
D:\Work\cpp_ui\main.cpp(45): message : see reference to function template instantiation 'lager::store<action_t,model_t,deps_t> lager::make_store<Action,void,State,lager::with_manual_event_loop,lager::with_deps::<lambda_1>>(Model &&,EventLoop &&,lager::with_deps::<lambda_1> &&)' being compiled [D:\Work\cpp_ui\build\cpp_ui.vcxproj]
          with
          [
              Model=State,
              EventLoop=lager::with_manual_event_loop
          ]

That's why I suspect this is a compiler bug... It seems to fail when referring to "this" from within an unevaluated context within a multi-level lambda. I suspect that's why it does compile when you pull the reference into the local scope with the workaround.

I'm still not a huge fan of this solution, but it works 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...it's getting late tonight, but I'll try and build the failing tests @kevin-- mentioned in the next day or two.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for what its worth, this error does not seem to appear with your work around. So step by step 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't std::invoke_result work instead of the decltype on the entire expression?
Can't really test myself anymore. We have had a lot of compiler bugs with older MSVCs and ended up switching to clang-cl that just works...

decltype(eff(ctxMsvcWorkaround))>) {
eff(ctx);
if constexpr (has_futures)
p();
Expand Down