Skip to content

Rvalue::ThreadLocalRef is unimplemented #541

Closed

Description

@celinval

While compiling the latest version of std library, RMC fails to compile library/std/src/sys_common/thread_info.rs

#![allow(dead_code)] // stack_guard isn't used right now on all platforms
#![allow(unused_unsafe)] // thread_local with `const {}` triggers this liny

use crate::cell::RefCell;
use crate::sys::thread::guard::Guard;
use crate::thread::Thread;

struct ThreadInfo {
    stack_guard: Option<Guard>,
    thread: Thread,
}

thread_local! { static THREAD_INFO: RefCell<Option<ThreadInfo>> = const { RefCell::new(None) } }

impl ThreadInfo {
    fn with<R, F>(f: F) -> Option<R>
    where
        F: FnOnce(&mut ThreadInfo) -> R,
    {
        THREAD_INFO
            .try_with(move |thread_info| {
                let mut thread_info = thread_info.borrow_mut();
                let thread_info = thread_info.get_or_insert_with(|| ThreadInfo {
                    stack_guard: None,
                    thread: Thread::new(None),
                });
                f(thread_info)
            })
            .ok()
    }
}

pub fn current_thread() -> Option<Thread> {
    ThreadInfo::with(|info| info.thread.clone())
}

pub fn stack_guard() -> Option<Guard> {
    ThreadInfo::with(|info| info.stack_guard.clone()).and_then(|o| o)
}

pub fn set(stack_guard: Option<Guard>, thread: Thread) {
    THREAD_INFO.with(move |thread_info| {
        let mut thread_info = thread_info.borrow_mut();
        rtassert!(thread_info.is_none());
        *thread_info = Some(ThreadInfo { stack_guard, thread });
    });
}

using the following command line invocation:

RUSTFLAGS="-Z trim-diagnostic-paths=no -Z codegen-backend=gotoc --cfg=rmc" RUSTC=rmc-rustc cargo +nightly build -Z build-std --target x86_64-unknown-linux-gnu

with RMC version:

I expected to see this happen: The module should be able to compile without any problem.

Instead, this happened:

thread 'rustc' panicked at 'not implemented', compiler/rustc_codegen_rmc/src/codegen/rvalue.rs:433:42
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: rustc_codegen_rmc::codegen::rvalue::<impl rustc_codegen_rmc::context::goto_ctx::GotocCtx>::codegen_rvalue
             at /home/ANT.AMAZON.COM/celinval/workspace/rmc-project/rmc/compiler/rustc_codegen_rmc/src/codegen/rvalue.rs:433:42
   4: rustc_codegen_rmc::codegen::statement::<impl rustc_codegen_rmc::context::goto_ctx::GotocCtx>::codegen_statement
             at /home/ANT.AMAZON.COM/celinval/workspace/rmc-project/rmc/compiler/rustc_codegen_rmc/src/codegen/statement.rs:537:60
   5: rustc_codegen_rmc::codegen::block::<impl rustc_codegen_rmc::context::goto_ctx::GotocCtx>::codegen_block
             at /home/ANT.AMAZON.COM/celinval/workspace/rmc-project/rmc/compiler/rustc_codegen_rmc/src/codegen/block.rs:27:32
   6: rustc_codegen_rmc::codegen::function::<impl rustc_codegen_rmc::context::goto_ctx::GotocCtx>::codegen_function::{{closure}}
             at /home/ANT.AMAZON.COM/celinval/workspace/rmc-project/rmc/compiler/rustc_codegen_rmc/src/codegen/function.rs:99:71
   7: core::iter::traits::iterator::Iterator::for_each::call::{{closure}}
             at /home/ANT.AMAZON.COM/celinval/workspace/rmc-project/rmc/library/core/src/iter/traits/iterator.rs:728:29
   8: core::iter::adapters::map::map_fold::{{closure}}
             at /home/ANT.AMAZON.COM/celinval/workspace/rmc-project/rmc/library/core/src/iter/adapters/map.rs:84:21
   9: <core::iter::adapters::enumerate::Enumerate<I> as core::iter::traits::iterator::Iterator>::fold::enumerate::{{closure}}
             at /home/ANT.AMAZON.COM/celinval/workspace/rmc-project/rmc/library/core/src/iter/adapters/enumerate.rs:106:27
  10: core::iter::traits::iterator::Iterator::fold
             at /home/ANT.AMAZON.COM/celinval/workspace/rmc-project/rmc/library/core/src/iter/traits/iterator.rs:2165:21
  11: <core::iter::adapters::enumerate::Enumerate<I> as core::iter::traits::iterator::Iterator>::fold
             at /home/ANT.AMAZON.COM/celinval/workspace/rmc-project/rmc/library/core/src/iter/adapters/enumerate.rs:112:9
  12: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
             at /home/ANT.AMAZON.COM/celinval/workspace/rmc-project/rmc/library/core/src/iter/adapters/map.rs:124:9
  13: core::iter::traits::iterator::Iterator::for_each
 ...

Activity

  1. added
    [C] Bug
    on Oct 6, 2021
  2. celinval commented on Mar 14, 2022

    @celinval
    ContributorAuthor

    I'm closing this since build std works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [C] Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions