Skip to content
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: errors resolving bounds after type-checking for fmt::Display #65774

Closed
bradjc opened this issue Oct 24, 2019 · 13 comments
Closed

ICE: errors resolving bounds after type-checking for fmt::Display #65774

bradjc opened this issue Oct 24, 2019 · 13 comments
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system C-bug Category: This is a bug. F-associated_type_defaults `#![feature(associated_type_defaults)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bradjc
Copy link
Contributor

bradjc commented Oct 24, 2019

pnkfelix: here is the reduced test case (play):

#![feature(associated_type_defaults)]

trait MyDisplay { fn method(&self) { } }

impl<'a, T: MyDisplay> MyDisplay for &'a mut T { }

struct T;

trait MPU {
    type MpuConfig: MyDisplay = T;
}

struct S;

impl MPU for S { }

trait MyWrite {
    fn my_write(&self, _: &dyn MyDisplay) { }
}

trait ProcessType {
    fn process_detail_fmt(&self, _: &mut dyn MyWrite);
}

struct Process;

impl ProcessType for Process {
    fn process_detail_fmt(&self, writer: &mut dyn MyWrite)
    {

        let mut val: Option<<S as MPU>::MpuConfig> = None;
        let valref: &mut <S as MPU>::MpuConfig = val.as_mut().unwrap();

        // // This causes a different ICE (but its similar if you squint right):
        // //
        // // `Unimplemented` selecting `Binder(<T as MyDisplay>)` during codegen
        //
        // writer.my_write(valref)

        // This one causes the ICE:
        // FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<T as MyDisplay>)), depth=1),Unimplemented)
        let closure = |config: &mut <S as MPU>::MpuConfig| writer.my_write(&config);
        closure(valref);
    }
}

fn create() -> &'static dyn ProcessType {
    let input: Option<&mut Process> = None;
    let process: &mut Process = input.unwrap();
    process
}

pub fn main() {
    create();
}

(Sadly I have not been able to reduce it further. But this should serve us well enough.)

Original bug report follows:


I'm getting a compiler error when trying to compile:

impl fmt::Display for PMPConfig {
    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
        Ok(())
    }
}

I'm compiling for the riscv32imac-unknown-none-elf target.

Full branch here:

https://github.com/tock/tock/blob/f29f8aa9bf9925893e905feb1aa42db2ce57d36f/arch/rv32i/src/pmp.rs#L26

error: internal compiler error: src/librustc/traits/codegen/mod.rs:127: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<() as core::fmt::Display>)), depth=1),Unimplemented)]` resolving bounds after type-checking

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:925:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: std::panicking::begin_panic
   8: rustc_errors::HandlerInner::bug
   9: rustc_errors::Handler::bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_context_opt
  13: rustc::ty::context::tls::with_opt
  14: rustc::util::bug::opt_span_bug_fmt
  15: rustc::util::bug::bug_fmt
  16: rustc::traits::codegen::<impl rustc::infer::InferCtxt>::drain_fulfillment_cx_or_panic
  17: rustc::ty::context::GlobalCtxt::enter_local
  18: rustc::traits::codegen::codegen_fulfill_obligation
  19: rustc::ty::query::__query_compute::codegen_fulfill_obligation
  20: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::codegen_fulfill_obligation>::compute
  21: rustc::dep_graph::graph::DepGraph::with_task_impl
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  23: rustc::ty::instance::Instance::resolve
  24: rustc::ty::instance::Instance::resolve_for_fn_ptr
  25: <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc::mir::visit::Visitor>::visit_rvalue
  26: rustc_mir::monomorphize::collector::collect_items_rec
  27: rustc_mir::monomorphize::collector::collect_items_rec
  28: rustc_mir::monomorphize::collector::collect_items_rec
  29: rustc_mir::monomorphize::collector::collect_items_rec
  30: rustc_mir::monomorphize::collector::collect_items_rec
  31: rustc_mir::monomorphize::collector::collect_items_rec
  32: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  33: rustc::util::common::time
  34: rustc_mir::monomorphize::collector::collect_crate_mono_items
  35: rustc::util::common::time
  36: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  37: rustc::ty::query::__query_compute::collect_and_partition_mono_items
  38: rustc::dep_graph::graph::DepGraph::with_task_impl
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  40: rustc_codegen_ssa::base::codegen_crate
  41: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  42: rustc_interface::passes::start_codegen::{{closure}}
  43: rustc::util::common::time
  44: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  45: rustc_interface::passes::create_global_ctxt::{{closure}}
  46: rustc_interface::queries::Query<T>::compute
  47: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
  48: rustc_interface::interface::run_compiler_in_existing_thread_pool
  49: std::thread::local::LocalKey<T>::with
  50: scoped_tls::ScopedKey<T>::set
  51: syntax::with_globals

or with full backtrace:

error: internal compiler error: src/librustc/traits/codegen/mod.rs:127: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<() as core::fmt::Display>)), depth=1),Unimplemented)]` resolving bounds after type-checking

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:925:9
stack backtrace:
   0:        0x107ee4765 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc92d616cef8f0450
   1:        0x107f1afe0 - core::fmt::write::h716de5060e2e2331
   2:        0x107ed7eab - std::io::Write::write_fmt::hcf7751f7cc575a83
   3:        0x107ee8ac3 - std::panicking::default_hook::{{closure}}::hcbef2dce5efa48e4
   4:        0x107ee87da - std::panicking::default_hook::h8d36105439fe91d2
   5:        0x10886f852 - rustc_driver::report_ice::hfa643614a34e50c3
   6:        0x107ee9302 - std::panicking::rust_panic_with_hook::h66761634aad950e8
   7:        0x10a3f0631 - std::panicking::begin_panic::h34e760fb9453ebea
   8:        0x10a3ed727 - rustc_errors::HandlerInner::bug::h6632965e0eab1113
   9:        0x10a3ec3bd - rustc_errors::Handler::bug::hcfa8e791cebcb41f
  10:        0x109b82ebb - rustc::util::bug::opt_span_bug_fmt::{{closure}}::h1f12cbc5d5c9e30d
  11:        0x109b81fc6 - rustc::ty::context::tls::with_opt::{{closure}}::h3c1d0ef67ec726db
  12:        0x109b81f54 - rustc::ty::context::tls::with_context_opt::h0bc959fbaa3c960b
  13:        0x109b81f82 - rustc::ty::context::tls::with_opt::h5b98f20d68bd6455
  14:        0x109b82dd8 - rustc::util::bug::opt_span_bug_fmt::h4b691449484f2e2d
  15:        0x109b82d2b - rustc::util::bug::bug_fmt::h94ea7325307137cb
  16:        0x109bee1de - rustc::traits::codegen::<impl rustc::infer::InferCtxt>::drain_fulfillment_cx_or_panic::haf0249c10c545ad4
  17:        0x10a085320 - rustc::ty::context::GlobalCtxt::enter_local::hc3ed889af372304b
  18:        0x109de43a6 - rustc::traits::codegen::codegen_fulfill_obligation::h2083639e26b40870
  19:        0x109ada6ca - rustc::ty::query::__query_compute::codegen_fulfill_obligation::h47add3629ad3c7c9
  20:        0x10a090f30 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::codegen_fulfill_obligation>::compute::h367720f4ad252193
  21:        0x109b25685 - rustc::dep_graph::graph::DepGraph::with_task_impl::hdb658fea3c8e03a0
  22:        0x109f73e7e - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::hc4e638aed84e9309
  23:        0x109a4ee08 - rustc::ty::instance::Instance::resolve::h7f14c4b030d04908
  24:        0x109a4f40a - rustc::ty::instance::Instance::resolve_for_fn_ptr::hd3f49848b140835f
  25:        0x109304298 - <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc::mir::visit::Visitor>::visit_rvalue::hc49ddd5adf94cfe8
  26:        0x109302eb7 - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  27:        0x1093038cf - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  28:        0x1093038cf - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  29:        0x1093038cf - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  30:        0x1093038cf - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  31:        0x1093038cf - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  32:        0x109174c1e - rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}::h4b9955786c837751
  33:        0x10913f7d3 - rustc::util::common::time::h7f14ec4a929068d5
  34:        0x109301530 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hb405aac8f6d07af3
  35:        0x10913f8f8 - rustc::util::common::time::hbfb52e7fe607ac6c
  36:        0x10940bfba - rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items::h9dba4196ae508ffb
  37:        0x10b65bad2 - rustc::ty::query::__query_compute::collect_and_partition_mono_items::h7b08395218e7aba3
  38:        0x10b6706fa - rustc::dep_graph::graph::DepGraph::with_task_impl::h25d923dce7eb1416
  39:        0x10b7236af - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h9078560050296908
  40:        0x10b73eedd - rustc_codegen_ssa::base::codegen_crate::hef4e5fc37e1a7a0e
  41:        0x10b6e0b49 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate::ha5087cf525770987
  42:        0x10893605e - rustc_interface::passes::start_codegen::{{closure}}::h63426f234991945a
  43:        0x108931068 - rustc::util::common::time::h9caa4ccff6ec0bfb
  44:        0x10890b16f - rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}::ha08746ee0b93b578
  45:        0x10893529b - rustc_interface::passes::create_global_ctxt::{{closure}}::h600047dc314d4bba
  46:        0x108907399 - rustc_interface::queries::Query<T>::compute::h9cd0fdded8634953
  47:        0x10899f19c - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen::h51958e05ed750756
  48:        0x108874d25 - rustc_interface::interface::run_compiler_in_existing_thread_pool::haa58e61254d8def5
  49:        0x1088877e4 - std::thread::local::LocalKey<T>::with::h702dc95be888a0e1
  50:        0x1088719a2 - scoped_tls::ScopedKey<T>::set::hb39b6f973e4a5679
  51:        0x1088a22d5 - syntax::with_globals::h58d861cb85a086c0
  52:        0x1088a6e37 - std::sys_common::backtrace::__rust_begin_short_backtrace::hdf8e7185d0994576
  53:        0x107ef84af - __rust_maybe_catch_panic
  54:        0x1088b0f17 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h7bb4ccc9b14ced04
  55:        0x107eca6ce - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h87e32ddb36700069
  56:        0x107ef72be - std::sys::unix::thread::Thread::new::thread_start::h20e18e6fa0d2566a
  57:     0x7fff744f62eb - _pthread_body
  58:     0x7fff744f9249 - _pthread_start

and more debug output on my build:

*******************************************************
TOCK KERNEL BUILD SYSTEM -- VERBOSE BUILD CONFIGURATION
*******************************************************
PLATFORM            = arty-e21
TARGET              = riscv32imac-unknown-none-elf
TOCK_KERNEL_VERSION = release-1.4-61-g4c6b652c6
RUSTFLAGS_FOR_CARGO = -C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512
MAKEFLAGS           =  -r -R
OBJDUMP_FLAGS       = --disassemble-all --source --section-headers

TOOLCHAIN           = "/Users/bradjc/.rustup/toolchains/nightly-2019-10-17-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/bin/llvm"
SIZE                = "/Users/bradjc/.rustup/toolchains/nightly-2019-10-17-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/bin/llvm"-size
OBJCOPY             = "/Users/bradjc/.rustup/toolchains/nightly-2019-10-17-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/bin/llvm"-objcopy
OBJDUMP             = "/Users/bradjc/.rustup/toolchains/nightly-2019-10-17-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/bin/llvm"-objdump
CARGO               = cargo
RUSTUP              = rustup

cargo --version     = cargo 1.40.0-nightly (3a9abe3f0 2019-10-15)
rustc --version     = rustc 1.40.0-nightly (0e8a4b441 2019-10-16)
rustup --version    = rustup 1.20.2 (13979c968 2019-10-16)
*******************************************************

RUSTFLAGS="-C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512" cargo build --target=riscv32imac-unknown-none-elf --verbose --release
       Fresh tock-registers v0.3.0 (/Users/bradjc/git/tock/libraries/tock-register-interface)
       Fresh tock-cells v0.1.0 (/Users/bradjc/git/tock/libraries/tock-cells)
       Fresh tock_rt0 v0.1.0 (/Users/bradjc/git/tock/libraries/tock-rt0)
       Fresh enum_primitive v0.1.0 (/Users/bradjc/git/tock/libraries/enum_primitive)
       Fresh riscv-csr v0.1.0 (/Users/bradjc/git/tock/libraries/riscv-csr)
       Fresh kernel v0.1.0 (/Users/bradjc/git/tock/kernel)
       Fresh rv32i v0.1.0 (/Users/bradjc/git/tock/arch/rv32i)
       Fresh capsules v0.1.0 (/Users/bradjc/git/tock/capsules)
       Fresh sifive v0.1.0 (/Users/bradjc/git/tock/chips/sifive)
       Fresh arty_e21 v0.1.0 (/Users/bradjc/git/tock/chips/arty_e21)
   Compiling arty-e21 v0.1.0 (/Users/bradjc/git/tock/boards/arty-e21)
     Running `rustc --edition=2018 --crate-name arty_e21 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=z -C panic=abort -C lto -C debuginfo=2 -C metadata=c1355c6c3289bbe0 -C extra-filename=-c1355c6c3289bbe0 --out-dir /Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps --target riscv32imac-unknown-none-elf -L dependency=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps -L dependency=/Users/bradjc/git/tock/boards/arty-e21/target/release/deps --extern arty_e21=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libarty_e21-fe0d635f7042045b.rlib --extern capsules=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libcapsules-16a235e3bdbefd38.rlib --extern kernel=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libkernel-1dbef041a1db2265.rlib --extern rv32i=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/librv32i-854677d7afde0e8d.rlib --extern sifive=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libsifive-1da1c765f34d5c05.rlib -C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512`
error: internal compiler error: src/librustc/traits/codegen/mod.rs:127: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<() as core::fmt::Display>)), depth=1),Unimplemented)]` resolving bounds after type-checking

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:925:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.40.0-nightly (0e8a4b441 2019-10-16) running on x86_64-apple-darwin

note: compiler flags: -C opt-level=z -C panic=abort -C lto -C debuginfo=2 -C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: aborting due to previous error

error: could not compile `arty-e21`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name arty_e21 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=z -C panic=abort -C lto -C debuginfo=2 -C metadata=c1355c6c3289bbe0 -C extra-filename=-c1355c6c3289bbe0 --out-dir /Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps --target riscv32imac-unknown-none-elf -L dependency=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps -L dependency=/Users/bradjc/git/tock/boards/arty-e21/target/release/deps --extern arty_e21=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libarty_e21-fe0d635f7042045b.rlib --extern capsules=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libcapsules-16a235e3bdbefd38.rlib --extern kernel=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libkernel-1dbef041a1db2265.rlib --extern rv32i=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/librv32i-854677d7afde0e8d.rlib --extern sifive=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libsifive-1da1c765f34d5c05.rlib -C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512` (exit code: 101)
make: *** [target/riscv32imac-unknown-none-elf/release/arty-e21] Error 101

Travis also seems to agree that it will not compile: https://travis-ci.org/tock/tock/builds/602484885

@Centril Centril added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-codegen Area: Code generation A-trait-system Area: Trait system I-nominated labels Oct 24, 2019
@Centril
Copy link
Contributor

Centril commented Oct 24, 2019

If possible, could you please provide a self-contained example that ICEs on e.g. the playground?

@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Oct 24, 2019
@Mark-Simulacrum Mark-Simulacrum added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Oct 24, 2019
@bradjc
Copy link
Contributor Author

bradjc commented Oct 24, 2019

Hmm...I tried creating a small example, but I can't seem to replicate the behavior. I'm not really sure what is happening to cause it.

I have found that the error occurs even though I'm not actually creating an object of type PMPConfig. However, if I remove

let _ = writer.write_fmt(format_args!("{}", config));

from a different crate which is where the fmt function would get used if I did create something of the type then the error does not occur.

@pnkfelix
Copy link
Member

triage: P-high, removing I-nominated label

@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Oct 31, 2019
@pnkfelix
Copy link
Member

I cannot reproduce this locally:

% git remote -v
origin	git@github.com:tock/tock.git (fetch)
origin	git@github.com:tock/tock.git (push)
% git log -1 --format=oneline
d423f7e969972e8cd662a37cd13c4fbf2b0a6ee9 (HEAD -> master, origin/staging, origin/master, origin/HEAD) Merge #1458
% git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
% cd boards/arty-e21/
% RUSTFLAGS="-C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512" cargo +nightly-2019-10-17 build  --target riscv32imac-unknown-none-elf 
   Compiling tock-registers v0.4.1 (/Users/felixklock/Dev/Mozilla/issue65774/tock/libraries/tock-register-interface)
   Compiling tock-cells v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/libraries/tock-cells)
   Compiling tock_rt0 v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/libraries/tock-rt0)
   Compiling enum_primitive v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/libraries/enum_primitive)
   Compiling arty-e21 v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/boards/arty-e21)
   Compiling kernel v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/kernel)
   Compiling riscv-csr v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/libraries/riscv-csr)
   Compiling rv32i v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/arch/rv32i)
   Compiling capsules v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/capsules)
   Compiling sifive v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/chips/sifive)
   Compiling arty_e21 v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/chips/arty_e21)
   Compiling components v0.1.0 (/Users/felixklock/Dev/Mozilla/issue65774/tock/boards/components)
    Finished dev [optimized + debuginfo] target(s) in 10.99s
% 

Please do try to come up with an MCVE. I recommend taking the original code and paring it down, rather than trying to jump straight to a minimal bit of code.

@pnkfelix
Copy link
Member

closing as not reproducible in absence of MCVE

@bradjc
Copy link
Contributor Author

bradjc commented Nov 14, 2019 via email

@pnkfelix
Copy link
Member

Ah, okay, I overlooked that detail earlier.

Now I can reproduce it.

Reopening (and will try to minimize, if only as fodder for a blog post on reducing i am planning)

@pnkfelix pnkfelix reopened this Nov 14, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Nov 15, 2019

Okay I've narrowed it down.

I don't have the test case into a state where I'm ready to post it yet (I need to clean it up a little more)

But if you want to fix your problem, its this:

https://github.com/tock/tock/blob/f29f8aa9bf9925893e905feb1aa42db2ce57d36f/kernel/src/platform/mpu.rs#L48

pub trait MPU {
    type MpuConfig: Default + Display = ();
    ...
}

Namely, you are using the (feature-gated) #![feature(associated_type_defaults)], and we do not currently properly check that the right-hand side of a given default actually implements any traits that bound the associated type.

Specifically in this case, () does not implement Display.

But instead of nicely reporting that to you at the trait definition site, or even at a trait implementation site, you are instead seeing an error far far downstream, unfortunately.

(As for how to work around this, I suspect your best bet is to make your own unit-struct that implements Default and Display and then plug that in as the default type in MpuConfig.)

@pnkfelix pnkfelix added the requires-nightly This issue requires a nightly compiler in some way. label Nov 15, 2019
@pnkfelix
Copy link
Member

Okay here is the reduction (play):

#![feature(associated_type_defaults)]

trait MyDisplay { fn method(&self) { } }

impl<'a, T: MyDisplay> MyDisplay for &'a mut T { }

struct T;

trait MPU {
    type MpuConfig: MyDisplay = T;
}

struct S;

impl MPU for S { }

trait MyWrite {
    fn my_write(&self, _: &dyn MyDisplay) { }
}

trait ProcessType {
    fn process_detail_fmt(&self, _: &mut dyn MyWrite);
}

struct Process;

impl ProcessType for Process {
    fn process_detail_fmt(&self, writer: &mut dyn MyWrite)
    {

        let mut val: Option<<S as MPU>::MpuConfig> = None;
        let valref: &mut <S as MPU>::MpuConfig = val.as_mut().unwrap();

        // // This causes a different ICE (but its similar if you squint right):
        // //
        // // `Unimplemented` selecting `Binder(<T as MyDisplay>)` during codegen
        //
        // writer.my_write(valref)

        // This one causes the ICE:
        // FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<T as MyDisplay>)), depth=1),Unimplemented)
        let closure = |config: &mut <S as MPU>::MpuConfig| writer.my_write(&config);
        closure(valref);
    }
}

fn create() -> &'static dyn ProcessType {
    let input: Option<&mut Process> = None;
    let process: &mut Process = input.unwrap();
    process
}

pub fn main() {
    create();
}

@pnkfelix pnkfelix added A-associated-items Area: Associated items (types, constants & functions) F-associated_type_defaults `#![feature(associated_type_defaults)]` and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example A-codegen Area: Code generation labels Nov 15, 2019
@pnkfelix
Copy link
Member

related: bug #62211, PR #61812, bug #33017

@pnkfelix
Copy link
Member

I'm going to downgrade this from P-high to P-medium, based on:

(it may or may not be fixed by #61812; I haven't checked that.)

@pnkfelix pnkfelix added P-medium Medium priority and removed P-high High priority labels Nov 15, 2019
bradjc added a commit to tock/tock that referenced this issue Nov 15, 2019
This is needed to workaround a compiler error. If
rust-lang/rust#65774 is fixed then we should
be able to revert this commit.
@Centril
Copy link
Contributor

Centril commented Nov 15, 2019

cc @jonas-schievink re. #61812.

bors bot added a commit to tock/tock that referenced this issue Nov 18, 2019
1428: Add MPU information to panic!() print r=ppannuto a=bradjc

### Pull Request Overview

This pull request changes the `MpuConfig` type to require that it implement the `fmt::Display` trait so that the process.rs panic printout can display the MPU information.

This fixes #925.


### Testing Strategy

This pull request was tested by running `crash_dummy` on Hail and verifying that the MPU display looks ok.


### TODO or Help Wanted

1. The output looks like:

    ```
     Cortex-M MPU
      Region 0: base:  20004000, length: 8192 bytes; ReadWrite (0x3)
      Region 1: base:     30000, length: 1024 bytes; ReadOnly (0x6)
      Region 2: Unused
      Region 3: Unused
      Region 4: Unused
      Region 5: Unused
      Region 6: Unused
      Region 7: Unused
    ```

    I'm not sure how to get the `0x` to display on the base address. The format string looks like `Region {}: base:{:>width$x}` and sticking a `#` in there to make it print the `0x` gives me errors.

2. The rust compiler generates an error when linking for risc-v. rust-lang/rust#65774 I have no idea what to do about that.


### Documentation Updated

I added a new copy of the panic!() output to the docs to keep that up to date.

- [x] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [x] Ran `make formatall`.


Co-authored-by: Brad Campbell <bradjc5@gmail.com>
Co-authored-by: Pat Pannuto <pat.pannuto@gmail.com>
@jonas-schievink
Copy link
Contributor

#61812 will currently reject this trait due to the unfulfilled trait bound. I've added a test.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Nov 26, 2019
@bors bors closed this as completed in 708f053 Feb 26, 2020
bradjc added a commit to tock/tock that referenced this issue Sep 17, 2021
Clean up comment now that rust-lang/rust#65774
has been closed.
bors bot added a commit to tock/tock that referenced this issue Sep 17, 2021
2829: kernel: mpu: Cleanup the comment for the default config type r=hudson-ayers a=bradjc

Clean up comment now that rust-lang/rust#65774 has been closed.




### Testing Strategy

I tried just using `()` and I got a compiler error this time.


### TODO or Help Wanted

n/a


### Documentation Updated

- [x] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [x] Ran `make prepush`.


Co-authored-by: Brad Campbell <bradjc5@gmail.com>
lschuermann pushed a commit to lschuermann/tock-registers that referenced this issue Dec 18, 2021
1428: Add MPU information to panic!() print r=ppannuto a=bradjc

### Pull Request Overview

This pull request changes the `MpuConfig` type to require that it implement the `fmt::Display` trait so that the process.rs panic printout can display the MPU information.

This fixes #925.


### Testing Strategy

This pull request was tested by running `crash_dummy` on Hail and verifying that the MPU display looks ok.


### TODO or Help Wanted

1. The output looks like:

    ```
     Cortex-M MPU
      Region 0: base:  20004000, length: 8192 bytes; ReadWrite (0x3)
      Region 1: base:     30000, length: 1024 bytes; ReadOnly (0x6)
      Region 2: Unused
      Region 3: Unused
      Region 4: Unused
      Region 5: Unused
      Region 6: Unused
      Region 7: Unused
    ```

    I'm not sure how to get the `0x` to display on the base address. The format string looks like `Region {}: base:{:>width$x}` and sticking a `#` in there to make it print the `0x` gives me errors.

2. The rust compiler generates an error when linking for risc-v. rust-lang/rust#65774 I have no idea what to do about that.


### Documentation Updated

I added a new copy of the panic!() output to the docs to keep that up to date.

- [x] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [x] Ran `make formatall`.


Co-authored-by: Brad Campbell <bradjc5@gmail.com>
Co-authored-by: Pat Pannuto <pat.pannuto@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system C-bug Category: This is a bug. F-associated_type_defaults `#![feature(associated_type_defaults)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants