kompics/kompact

Conflicting impls when there are multiple ports of the same type

segeljakt opened this issue · 1 comments

When there are multiple ports of (potentially) the same type, you get a conflicting impl:

pub(crate) trait Event: 'static + Sync + Send + Debug + Clone {}
impl<T> Event for T where T: 'static + Sync + Send + Debug + Clone {}

pub(crate) struct MyPort<T>(PhantomData<T>);
impl<T: Event> Port for MyPort<T> {
    type Indication = Never;
    type Request = T;
}

#[derive(ComponentDefinition, Actor)]
pub(crate) struct MyComponent<I0: Event, I1: Event> {
    pub(crate) ctx: ComponentContext<Self>,
    pub(crate) p0: ProvidedPort<MyPort<I0>>,
    pub(crate) p1: ProvidedPort<MyPort<I1>>,
}
[rustc E0119] [E] conflicting implementations of trait `kompact::component::ProvideRef<test::MyPort<_>>` for type `test::MyComponent<_, _, _, _>`

As far as I understand, it should not be possible to have two ports of the same type. Could the error be reported earlier by the macro expansion instead of Rust? It took me some time to understand why I was getting this error.

Well, it should be possible, but it comes with some caveats. I think we should change the macro to produce only one impl of the handler for identical port types and do something sensible about the connection impls, since duplicate ports prevent us from just connecting by name. So probably just don't generate any impl for those traits and produce a warning to make it clear that duplicate ports offer somewhat reduced functionality/convenience.