Skip to content

Materialize recursive_wrapper<T> instead of T when possible#12

Merged
saki7 merged 1 commit intomainfrom
materialize-recursive-wrapper
Feb 7, 2026
Merged

Materialize recursive_wrapper<T> instead of T when possible#12
saki7 merged 1 commit intomainfrom
materialize-recursive-wrapper

Conversation

@saki7
Copy link
Member

@saki7 saki7 commented Feb 7, 2026

Uses the functionality implemented in iris-cpp/iris#18

This PR solves the issue described in:

template<class Attr, class First, class... Rest>
struct variant_find_substitute_impl<Attr, First, Rest...>
{
using type = std::conditional_t<
is_substitute_v<Attr, iris::unwrap_recursive_type<First>>,
// Given some type `T`, when both `T` and `recursive_wrapper<T>` is seen
// during attribute resolution, X4 should ideally materialize the latter
// because:
// - It means that the user has supplied at least one explicit type
// (i.e. exposed attribute type, possibly a rule attribute type) that
// is `recursive_wrapper<T>`, and
// - constructing `T` and then moving it to `recursive_wrapper<T>`
// involves copying from stack to heap.
//
First, // no need to unwrap due to the reason described above
typename variant_find_substitute_impl<Attr, Rest...>::type
>;
};

@saki7 saki7 self-assigned this Feb 7, 2026
@saki7 saki7 added the enhancement New feature or request label Feb 7, 2026
@saki7 saki7 merged commit 97f2a08 into main Feb 7, 2026
13 checks passed
@saki7 saki7 deleted the materialize-recursive-wrapper branch February 7, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant