use std::io::{Read, Write};
use std::fmt::Debug;
use std::io::{stdout,stdin, BufRead};
use arrayvec::ArrayString;
use std::vec::Vec;
use std::convert::TryInto;
struct VM {
r: [u32;16],
pc: u32,
mem: Vec<u8>,
}
impl VM{
fn check_instr(&mut self)-> bool{
self.pc += 1;
let idx = self.pc as usize;
match self.mem[idx]{
0x00 => {
self.r[self.mem[idx+1] as usize] ^= self.r[self.mem[idx+2] as usize];
self.pc += 3;
return false;
}, //xor det_reg,src_reg
0x01 => {
self.r[self.mem[idx+1] as usize] &= self.r[self.mem[idx+2] as usize];
self.pc += 3;
return false;
},
0x02 => {
self.r[self.mem[idx+1] as usize] |= self.r[self.mem[idx+2] as usize];
self.pc += 3;
return false;
},
// MOV dst_reg, std_reg
0x11 =>{
let idx = self.pc as usize;
let data = self.mem[idx+1];
self.mem[idx+2].clone_from(&data);
self.pc += 6;
return false;
},
// MOV dst_reg, imm32
0x10 =>{
let idx = self.pc as usize;
let data = self.mem[idx+1] as u32;
self.r[self.mem[idx+2] as usize].clone_from(&data);
self.pc += 3;
return false;
},
0xff =>{
return true;
}
_ => return false,
}
println!("Should never get here!");
return true;
}
fn check(&mut self, key: &[u8;16]) -> bool{
key.chunks_exact(4)
.take(4)
.zip(&mut self.r[..4])
.for_each(|(chunk,slot)| * slot = u32::from_le_bytes(chunk.try_into().unwrap()));
let mut end = false;
while !end {
end = self.check_instr();
}
return self.r[0] == 0;
}
}
fn main() {
const MAX_SIZE: u64 = 256;
let key_valid = false;
let mut key = [0;16];
println!("Hello there\nPlease enter your key: ");
let _ = stdout().flush();
if let Err(_) = stdin().read_exact(&mut key){
println!("Bad user input!");
}
// let mut vm = VM::new();
// let key_valid = vm.check(key);
if (key_valid){
println!("Yup.");
}else{
println!("Nope.");
}
}
rustc --version --verbose:
rustc 1.45.0 (5c1f21c3b 2020-07-13)
binary: rustc
commit-hash: 5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2
commit-date: 2020-07-13
host: x86_64-unknown-linux-gnu
release: 1.45.0
LLVM version: 10.0
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 43', /rustc/5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2/src/librustc_query_system/dep_graph/serialized.rs:42:23
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/backtrace.rs:78
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/backtrace.rs:59
4: core::fmt::write
at src/libcore/fmt/mod.rs:1076
5: std::io::Write::write_fmt
at src/libstd/io/mod.rs:1537
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:62
7: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:49
8: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:198
9: std::panicking::default_hook
at src/libstd/panicking.rs:218
10: rustc_driver::report_ice
11: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:490
12: rust_begin_unwind
at src/libstd/panicking.rs:388
13: core::panicking::panic_fmt
at src/libcore/panicking.rs:101
14: core::panicking::panic_bounds_check
at src/libcore/panicking.rs:73
15: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
16: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_green_and_read
17: rustc_data_structures::stack::ensure_sufficient_stack
18: rustc_query_system::query::plumbing::get_query_impl
19: rustc_passes::entry::find_entry_point
20: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
21: rustc_session::utils::<impl rustc_session::session::Session>::time
22: rustc_interface::passes::analysis
23: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
24: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
25: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
26: rustc_query_system::query::plumbing::get_query_impl
27: rustc_middle::ty::context::tls::enter_global
28: rustc_interface::interface::run_compiler_in_existing_thread_pool
29: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: internal compiler error: unexpected panic
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.45.0 (5c1f21c3b 2020-07-13) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [entry_fn] looking up the entry function of a crate
#1 [analysis] running analysis passes on this crate
end of query stack
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 46', /rustc/5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2/src/librustc_query_system/dep_graph/serialized.rs:42:23
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/backtrace.rs:78
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/backtrace.rs:59
4: core::fmt::write
at src/libcore/fmt/mod.rs:1076
5: std::io::Write::write_fmt
at src/libstd/io/mod.rs:1537
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:62
7: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:49
8: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:198
9: std::panicking::default_hook
at src/libstd/panicking.rs:218
10: rustc_driver::report_ice
11: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:490
12: rust_begin_unwind
at src/libstd/panicking.rs:388
13: core::panicking::panic_fmt
at src/libcore/panicking.rs:101
14: core::panicking::panic_bounds_check
at src/libcore/panicking.rs:73
15: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
16: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_green_and_read
17: rustc_query_system::query::plumbing::ensure_query_impl
18: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
19: rustc_session::utils::<impl rustc_session::session::Session>::time
20: rustc_interface::passes::analysis
21: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
22: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
24: rustc_query_system::query::plumbing::get_query_impl
25: rustc_middle::ty::context::tls::enter_global
26: rustc_interface::interface::run_compiler_in_existing_thread_pool
27: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: internal compiler error: unexpected panic
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.45.0 (5c1f21c3b 2020-07-13) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
warning: 4 warnings emitted
error: could not compile `VM`.
To learn more, run the command again with --verbose.
Process finished with exit code 101
Backtrace
stack trace is included above
Seems to compile fine on godbolt.org (sans the removed use arrayvec::ArrayString;). What settings did you use?
Seems to compile fine on godbolt.org (sans the removed
use arrayvec::ArrayString;). What settings did you use?
Hi! my settings:
[package]
name = "VM"
version = "0.1.0"
authors = ["intersys"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
arrayvec = "0.5.1"
Please retry on newest stable and nightly toolchain.
Edit: Cannot reproduce on playground with stable and nightly toolchain: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c9aa65afb868046ae8529a15a5a6e0b0.
src/librustc_query_system/dep_graph/serialized.rs:42:23
This looks incremental-compilation related. Searching thread 'rustc' panicked at 'index out of bounds' gives a whole bunch of similar issues, which are probably duplicates of each other.
Please retry on newest stable and nightly toolchain.
Edit: Cannot reproduce on playground with stable and nightly toolchain: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c9aa65afb868046ae8529a15a5a6e0b0.
I believe a have a problem with my system. That happens when I try to update rust:
intersys@intersys-VirtualBox:~$ rustup toolchain install nightly
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-17, rust version 1.49.0-nightly (e3051d8c2 2020-10-16)
info: downloading component 'cargo'
error: component download failed for cargo-x86_64-unknown-linux-gnu
error: caused by: checksum failed
intersys@intersys-VirtualBox:~$ rustup update
info: no updatable toolchains installed
info: checking for self-updates
info: cleaning up downloads & tmp directories
intersys@intersys-VirtualBox:~$ rustup update
info: no updatable toolchains installed
info: checking for self-updates
info: cleaning up downloads & tmp directories
intersys@intersys-VirtualBox:~$ rustup update
info: no updatable toolchains installed
info: checking for self-updates
info: cleaning up downloads & tmp directories
intersys@intersys-VirtualBox:~$ rustup toolchain install stable
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-08, rust version 1.47.0 (18bf6b4f0 2020-10-07)
info: downloading component 'cargo'
error: component download failed for cargo-x86_64-unknown-linux-gnu
error: caused by: checksum failed
Most helpful comment
I believe a have a problem with my system. That happens when I try to update rust: