-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
ICE FulfillmentError in trait codegen #64401
Comments
Please provide the source code needed to reproduce this |
It can be found here https://github.com/ajuvercr/MOZAIC on the CRASH branch. |
Here is a self-contained reduced example from that code. It can probably be reduced a lot more. pub trait Owned<'a> {
type Reader: FromPointerReader<'a>;
}
pub trait FromPointerReader<'a> : Sized {
fn get_from_pointer(reader: &'a[u8]) -> Self;
}
pub mod messaging {
pub mod reactor {
use std::collections::HashMap;
use super::types::{Handler, AnyPtrHandler};
use crate::any_pointer;
use crate::Owned;
pub trait Ctx : 'static + for<'a> Context<'a> {}
impl<C> Ctx for C where C: 'static + for<'a> Context<'a> {}
pub trait Context<'a> : Sized {
type Handle: 'a + CtxHandle<Self>;
}
pub trait CtxHandle<C> {
fn spawn<S>(&mut self, params: CoreParams<S, C>)
where S: 'static + Send,
C: Ctx;
}
pub struct Reactor<S, C: Ctx> {
pub internal_state: S,
pub internal_handlers: HashMap<u64, CoreHandler<S, C>>,
}
pub struct LinkReducer<S, C>
where C: Ctx
{
pub state: S,
pub internal_handlers: LinkHandlers<S, C>,
}
pub struct ReactorHandle<'a, 'c: 'a, C: Ctx> {
_ctx: &'a mut <C as Context<'c>>::Handle,
}
impl<'a, 'c, C: Ctx> ReactorHandle<'a, 'c, C> {
pub fn open_link<S>(&mut self, _params: LinkParams<S, C>)
where S: 'static + Send
{
todo!()
}
}
pub struct LinkHandle<'a, 'c: 'a, C: Ctx> {
_ctx: &'a mut <C as Context<'c>>::Handle,
}
pub struct HandlerCtx<'a, S, H> {
state: &'a mut S,
handle: &'a mut H,
}
impl<'a, S, H> HandlerCtx<'a, S, H> {
pub fn state<'b>(&'b mut self) -> &'b mut S {
&mut self.state
}
pub fn handle<'b>(&'b mut self) -> &'b mut H {
&mut self.handle
}
}
use std::marker::PhantomData;
pub struct CtxHandler<M, F> {
message_type: PhantomData<M>,
function: F,
}
impl<M, F> CtxHandler<M, F> {
pub fn new(function: F) -> Self {
CtxHandler {
message_type: PhantomData,
function,
}
}
}
impl<'a, S, H, M, F> Handler<'a, HandlerCtx<'a, S, H>, M> for CtxHandler<M, F>
where F: Fn(&mut S, &mut H, <M as Owned<'a>>::Reader),
F: Send,
M: Owned<'a> + 'static + Send
{
fn handle(&self, ctx: &mut HandlerCtx<'a, S, H>, reader: <M as Owned<'a>>::Reader)
{
(self.function)(&mut ctx.state, &mut ctx.handle, reader);
}
}
pub struct CtxHandlerWithoutState<M, F> {
message_type: PhantomData<M>,
_function: F,
}
impl<M, F> CtxHandlerWithoutState<M, F> {
pub fn new(_function: F) -> Self { todo!() }
}
impl<'a, S, H, M, F> Handler<'a, HandlerCtx<'a, S, H>, M> for CtxHandlerWithoutState<M, F>
where F: Fn(&mut H, <M as Owned<'a>>::Reader),
F: Send,
M: Owned<'a> + 'static + Send
{
fn handle(&self, _ctx: &mut HandlerCtx<'a, S, H>, _reader: <M as Owned<'a>>::Reader)
{
todo!()
}
}
pub type ReactorCtx<'a, 'c, S, C> = HandlerCtx<'a, S, ReactorHandle<'a, 'c, C>>;
pub type LinkCtx<'a, 'c, S, C> = HandlerCtx<'a, S, LinkHandle<'a, 'c, C>>;
type CoreHandler<S, C> = Box<
dyn for <'a, 'c>
Handler<
'a,
HandlerCtx<'a, S, ReactorHandle<'a, 'c, C>>,
any_pointer::Owned,
>
>;
type LinkHandler<S, C> = Box<
dyn for<'a, 'c>
Handler<'a,
HandlerCtx<'a, S, LinkHandle<'a, 'c, C>>,
any_pointer::Owned,
>
>;
type LinkHandlers<S, C> = HashMap<u64, LinkHandler<S, C>>;
pub struct CoreParams<S, C: Ctx> {
pub state: S,
pub handlers: HashMap<u64, CoreHandler<S, C>>,
}
impl<S, C: Ctx> CoreParams<S, C> {
pub fn new(_state: S) -> Self {
todo!()
}
pub fn handler<M, H>(&mut self, _m: M, h: H)
where M: for<'a> Owned<'a> + Send + 'static,
H: 'static + for <'a, 'c> Handler<'a, HandlerCtx<'a, S, ReactorHandle<'a, 'c, C>>, M>,
{
let boxed = Box::new(AnyPtrHandler::new(h));
self.handlers.insert(
0,
boxed,
);
}
}
pub struct LinkParams<S, C: Ctx> {
pub state: S,
pub external_handlers: LinkHandlers<S, C>,
}
impl<S, C: Ctx> LinkParams<S, C> {
pub fn new(_state: S) -> Self {
todo!()
}
pub fn external_handler<M, H>(&mut self, _m: M, h: H)
where M: for<'a> Owned<'a> + Send + 'static,
H: 'static + for <'a, 'c> Handler<'a, HandlerCtx<'a, S, LinkHandle<'a, 'c, C>>, M>
{
let boxed = Box::new(AnyPtrHandler::new(h));
self.external_handlers.insert(
0,
boxed,
);
}
pub fn send_external_to_internal<M>(&mut self, m: M,)
where M: for<'a> Owned<'a> + Send + 'static,
{
self.external_handler(m, CtxHandlerWithoutState::new(e_to_i::<C, M>));
}
}
fn e_to_i<C:Ctx, M>(_handle: &mut LinkHandle<C>, _msg: <M as Owned<'_>>::Reader)
where
M: for<'a> Owned<'a> + Send + 'static,
{
todo!()
}
}
pub mod types {
use std::marker::PhantomData;
use crate::any_pointer;
use crate::Owned;
pub trait Handler<'a, S, M>: Send
where M: Owned<'a>
{
fn handle(&self, state: &mut S, reader: <M as Owned<'a>>::Reader);
}
pub struct FnHandler<M, F> {
message_type: PhantomData<M>,
_function: F,
}
impl<M, F> FnHandler<M, F> {
pub fn new(function: F) -> Self {
FnHandler {
_function: function,
message_type: PhantomData,
}
}
}
impl<'a, S, M, F, T, E> Handler<'a, S, M> for FnHandler<M, F>
where F: Fn(&mut S, <M as Owned<'a>>::Reader) -> Result<T, E>,
F: Send,
M: Owned<'a> + 'static + Send
{
fn handle(&self, _state: &mut S, _reader: <M as Owned<'a>>::Reader)
{}
}
pub struct AnyPtrHandler<H, M> {
message_type: PhantomData<M>,
handler: H,
}
impl<H, M> AnyPtrHandler<H, M> {
pub fn new(handler: H) -> Self {
AnyPtrHandler {
handler,
message_type: PhantomData,
}
}
}
impl<'a, S, M, H> Handler<'a, S, any_pointer::Owned> for AnyPtrHandler<H, M>
where H: Handler<'a, S, M>,
M: Send + Owned<'a>
{
fn handle(&self, state: &mut S, reader: any_pointer::Reader<'a>)
{
let m = reader.get_as();
return self.handler.handle(state, m);
}
}
}
}
pub mod runtime {
use crate::messaging::reactor::{CtxHandle, CoreParams, Context};
pub struct Runtime;
pub fn spawn<S>(_core_params: CoreParams<S, Runtime>)
where S: 'static + Send
{
todo!()
}
impl<'a> Context<'a> for Runtime {
type Handle = DriverHandle<'a>;
}
pub struct DriverHandle<'a> {
_broker: &'a (),
}
impl<'a> CtxHandle<Runtime> for DriverHandle<'a> {
fn spawn<T>(&mut self, _params: CoreParams<T, Runtime>)
where T: 'static + Send
{
todo!()
}
}
}
pub mod aggregator {
use crate::messaging::reactor::{LinkParams, Ctx, ReactorHandle, CoreParams, CtxHandler};
use crate::any_pointer;
pub struct Aggregator;
impl Aggregator {
pub fn params<C: Ctx>() -> CoreParams<Self, C> {
let me = Self;
let mut params = CoreParams::new(me);
params.handler(any_pointer::Owned, CtxHandler::new(Self::handle_initialize));
return params;
}
fn handle_initialize<C: Ctx>(
&mut self,
handle: &mut ReactorHandle<C>,
_: any_pointer::Reader,
)
{
handle.open_link(HostLink::params());
}
}
struct HostLink;
impl HostLink {
fn params<C: Ctx>() -> LinkParams<Self, C> {
let mut params = LinkParams::new(HostLink);
params.send_external_to_internal(any_pointer::Owned);
return params;
}
}
}
pub mod any_pointer {
pub struct Owned;
impl <'a> crate::Owned<'a> for Owned {
type Reader = Reader<'a>;
}
pub struct Reader<'a> {
_reader: &'a[u8],
}
impl <'a> Reader<'a> {
pub fn get_as<T: crate::FromPointerReader<'a>>(&self) -> T {
todo!()
}
}
impl <'a,> crate::FromPointerReader<'a> for Reader<'a,> {
fn get_from_pointer(_reader: &'a[u8]) -> Reader<'a,> {
todo!()
}
}
}
pub fn foo() {
crate::runtime::spawn(crate::aggregator::Aggregator::params());
} |
Is this good enough as MCVE? use std::marker::PhantomData;
trait Owned<'a> {
type Reader;
}
impl<'a> Owned<'a> for () {
type Reader = ();
}
trait Handler {
fn handle(&self);
}
struct CtxHandlerWithoutState<M, F> {
message_type: PhantomData<M>,
_function: F,
}
impl<M, F> CtxHandlerWithoutState<M, F> {
pub fn new(_function: F) -> Self {
Self {
message_type: PhantomData,
_function,
}
}
}
impl<'a, M, F> Handler for CtxHandlerWithoutState<M, F>
where
F: Fn(<M as Owned<'a>>::Reader),
M: Owned<'a>,
{
fn handle(&self) {}
}
fn e_to_i<M: for<'a> Owned<'a>>(_: <M as Owned<'_>>::Reader) {}
fn send_external_to_internal<M>()
where
M: for<'a> Owned<'a>,
{
let _: Box<dyn Handler> = Box::new(CtxHandlerWithoutState::<M, _>::new(e_to_i::<M>));
}
pub fn main() {
send_external_to_internal::<()>()
} Edit: Reduced it further |
Seems to no longer ICE with @rustbot modify labels: E-needs-test |
searched nightlies: from nightly-2021-05-01 to nightly-2021-09-10 bisected with cargo-bisect-rustc v0.6.0Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --start=2021-5-1 --end=2021-09-10 --regress non-ice |
Looks like #85499 fixed this. |
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
Rollup of 7 pull requests Successful merges: - rust-lang#98387 (Add new unstable API `downcast` to `std::io::Error`) - rust-lang#98662 (Add std::fs::write documentation precision) - rust-lang#99253 (Remove FIXME from MIR `always_storage_live_locals`) - rust-lang#99264 (Fix typo in mod.rs) - rust-lang#99270 (Add `#[must_use]` to `Box::from_raw`) - rust-lang#99277 (Stabilize `core::ffi::CStr`, `alloc::ffi::CString`, and friends) - rust-lang#99307 (Add regression test for rust-lang#64401) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
When trying to use generic function with capnproto structs the compiler fails to infer types correctly.
I failed to distil the problem to a smaller size.
Capnproto generates code that implements traits like this
impl <'a> ::capnp::traits::Owned<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; }
Error
Which I think can be distilled down to
expected: host_message::Reader<'_>, found: <host_message::Owned as Owned<'_>>::Reader
which is the same type.Meta
rustc --version --verbose
:rustc 1.37.0 (eae3437df 2019-08-13) binary: rustc commit-hash: eae3437dfe991621e8afdc82734f4a172d7ddf9b commit-date: 2019-08-13 host: x86_64-unknown-linux-gnu release: 1.37.0 LLVM version: 8.0
My first issue btw, sorry for noobyness.
The text was updated successfully, but these errors were encountered: