Skip to content

Commit

Permalink
Revert some MSVC workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jun 21, 2022
1 parent 2ccc847 commit aba2712
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
42 changes: 22 additions & 20 deletions include/llama/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,26 +483,8 @@ namespace llama
return size;
}

template<bool Align, typename TypeList, std::size_t I>
template<typename TypeList, std::size_t I, bool Align>
constexpr auto offsetOfImplWorkaround() -> std::size_t;

// recursive formulation to benefit from template instantiation memoization
// this massively improves compilation time when this template is instantiated with a lot of different I
template<bool Align, typename TypeList, std::size_t I>
inline constexpr std::size_t offsetOfImpl
= offsetOfImplWorkaround<Align, TypeList, I>(); // FIXME: MSVC fails to compile an IILE here.

template<bool Align, typename TypeList>
inline constexpr std::size_t offsetOfImpl<Align, TypeList, 0> = 0;

template<bool Align, typename TypeList, std::size_t I>
constexpr auto offsetOfImplWorkaround() -> std::size_t
{
std::size_t offset = offsetOfImpl<Align, TypeList, I - 1> + sizeof(boost::mp11::mp_at_c<TypeList, I - 1>);
if constexpr(Align)
offset = roundUpToMultiple(offset, alignof(boost::mp11::mp_at_c<TypeList, I>));
return offset;
}
} // namespace internal

/// The size of a type list if its elements would be in a normal struct.
Expand All @@ -522,7 +504,27 @@ namespace llama

/// The byte offset of an element in a type list ifs elements would be in a normal struct.
template<typename TypeList, std::size_t I, bool Align>
inline constexpr std::size_t flatOffsetOf = internal::offsetOfImpl<Align, TypeList, I>;
inline constexpr std::size_t flatOffsetOf = internal::offsetOfImplWorkaround<TypeList, I, Align>();

namespace internal
{
// unfortunately, we cannot inline this function as an IILE, as MSVC complains:
// fatal error C1202: recursive type or function dependency context too complex
template<typename TypeList, std::size_t I, bool Align>
constexpr auto offsetOfImplWorkaround() -> std::size_t
{
if constexpr(I == 0)
return 0;
else
{
std::size_t offset
= flatOffsetOf<TypeList, I - 1, Align> + sizeof(boost::mp11::mp_at_c<TypeList, I - 1>);
if constexpr(Align)
offset = roundUpToMultiple(offset, alignof(boost::mp11::mp_at_c<TypeList, I>));
return offset;
}
}
} // namespace internal

/// The byte offset of an element in a record dimension if it would be a normal struct.
/// \tparam RecordDim Record dimension tree.
Expand Down
19 changes: 7 additions & 12 deletions include/llama/VirtualRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,32 +747,27 @@ namespace llama
{
using RecordDim = typename VirtualRecord<View, BoundRecordCoord, OwnView>::AccessibleRecordDim;
os << "{";
// TODO(bgruber): I tried refactoring both branches into one, but MSVC and icpc have troubles with correctly
// discarding the discarded if constexpr branch and not instantiating templates inside them.
if constexpr(std::is_array_v<RecordDim>)
{
constexpr auto size = std::extent_v<RecordDim>;
boost::mp11::mp_for_each<boost::mp11::mp_iota_c<size>>(
boost::mp11::mp_for_each<boost::mp11::mp_iota_c<std::extent_v<RecordDim>>>(
[&](auto ic)
{
constexpr std::size_t i = decltype(ic)::value;
os << '[' << i << ']' << ": " << vr(RecordCoord<i>{});
if(i + 1 < size)
if(i > 0)
os << ", ";
os << '[' << i << ']' << ": " << vr(RecordCoord<i>{});
});
}
else
{
constexpr auto size = boost::mp11::mp_size<RecordDim>::value;
boost::mp11::mp_for_each<boost::mp11::mp_iota_c<size>>(
boost::mp11::mp_for_each<boost::mp11::mp_iota<boost::mp11::mp_size<RecordDim>>>(
[&](auto ic)
{
constexpr std::size_t i = decltype(ic)::value;
using Field = boost::mp11::mp_at_c<RecordDim, i>;
using Tag = GetFieldTag<Field>;
os << structName<Tag>() << ": " << vr(RecordCoord<i>{});
if(i + 1 < size)
if(i > 0)
os << ", ";
using Field = boost::mp11::mp_at_c<RecordDim, i>;
os << structName<GetFieldTag<Field>>() << ": " << vr(RecordCoord<i>{});
});
}
os << "}";
Expand Down

0 comments on commit aba2712

Please sign in to comment.