Narrowing protocols with reflection
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
Comienza con el modelo de reducción de múltiples traits duck del issue y con los diseños de vtable protocol propuestos. Investiga enfoques alternativos basados en reflexión y técnicas relevantes de implementadores de STL, tal como se solicita en la conclusión. Se considerará terminado cuando se documente un enfoque viable para la reducción de protocolos y el overhead o las concesiones que introduce.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
The draft notes that narrowing should be allowed for protocols:
// Narrowing constructor from any compatible mutable protocol_view.
template <typename Other>
protocol_view(const protocol_view<Other>& other) noexcept;
This is an idea worth exploring with reflection. I would like to provide a brief overview of duck's approach to this problem, and the issues we may encounter when implementing this for protocol.
duck's model
Rather than accepting a single trait (same as protocol's interface), duck accepts a variadic number of traits. A duck<A, B, C> can then be converted to a duck<A>, duck<B>, etc.
// where A, B, C are interfaces
rjk::duck<A, B, C> d{...};
rjk::duck_view<A> dv1 = d;
rjk::duck_view<B> dv2 = d;
rjk::duck_view<const C> dv3 = d;
The approach we take for this looks like:
struct vtable<A, B, C> {
const vtable<A>* to_trait_0;
const vtable<B>* to_trait_1;
const vtable<C>* to_trait_2;
// actual dispatch functions, lifecycle, etc.
};
// for single-trait vtables
struct vtable<A> {
const vtable<const A>* to_const;
};
I am currently working on a feature for the library I call "multi-trait" narrowing, or converting from a duck<A, B, C> to a duck<A, B>, duck<A, C>, or any other subset of the traits.
With the approach I'm using currently (and the best one I could think of so far) this means that a vtable<A, B, C> will now need to store a vtable<A, B>*, vtable<A, C>*, vtable<B, C>*, in addition to the single-trait vtable pointers. As you imagine, this could become a problem for a lot of traits. It is not, however, an issue for a large number of interface members, since duck does not allow granular narrowing to each method.
protocol's model
Bringing this info to protocol, if I understood the specification correctly, the goal is to support the following:
struct A {
int foo();
int bar();
int baz();
};
struct B {
int foo();
int bar();
};
protocol<A> p{...};
protocol_view<B> pv1 = p;
protocol_view<const B> pv2 = p;
My first thought for implementing this would be to reuse the approach from duck, but treating each interface member as a "trait" instead. So you would make three vtables: one for int foo(), one for int bar(), and one for int baz(). Then each one would need to store a pointer to the vtable for its constituent members. So a vtable for A might contain:
struct vtable<foo, bar, baz> {
const vtable<foo>* to_func_0;
const vtable<bar>* to_func_1;
const vtable<baz>* to_func_2;
const vtable<foo, bar>* to_func_0_1;
const vtable<foo, baz>* to_func_0_2;
const vtable<bar, baz>* to_func_1_2;
// actual dispatch functions, lifecycle, etc.
};
If we are anticipating interfaces with a large number of methods, this could slow down compile time significantly. Defining one interface with many members, even if the user does not intend to narrow it at all, would cause significant overhead.
Conclusion
I am not creating this to discourage narrowing from being included in protocol, since I think it is a high-value feature. Some additional research into alternate methods using reflection would be helpful, so as to potentially avoid the overhead described above. Additionally, it would be valuable to discuss this with STL implementers to see if they have access to some methods that we don't.
- Lenguaje dominante
- C++
- Estrellas
- 12
- Forks
- 4
- Merge medio
- 1 d 11 h
- PR fusionados (30 d)
- 15
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de jbcoe/cc-protocol
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
jbcoe/cc-protocol#507 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
jbcoe/cc-protocol#455 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
jbcoe/cc-protocol#407 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
jbcoe/cc-protocol#194 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
jbcoe/cc-protocol#513 ·
Los mantenedores suelen responder en 1 día
Todos los issues de jbcoe/cc-protocol
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
ai_p1 comp-sql-syntax
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
ClickHouse/ClickHouse#133888 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
documentation good first issue
Dificultad 2/5 Medio día Aptitud para principiantes 66/100
-
bug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día