Skip to content

Commit 37b4902

Browse files
celinvaltedinski
authored andcommitted
Get rid of skip monomorphizer hack (rust-lang#485) (rust-lang#624)
Remove the hack we added to monomorphizer to skip functions that we were not able to handle. The latest fixes that we added to RMC was enough to allow us to run the monomorphizer as is.
1 parent b3f376d commit 37b4902

File tree

11 files changed

+75
-22
lines changed

11 files changed

+75
-22
lines changed

compiler/rustc_codegen_rmc/src/compiler_interface.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
//! This file contains the code necessary to interface with the compiler backend
55
6-
use crate::overrides::skip_monomorphize;
76
use crate::GotocCtx;
7+
88
use bitflags::_core::any::Any;
99
use cbmc::goto_program::symtab_transformer;
1010
use cbmc::goto_program::SymbolTable;
@@ -46,9 +46,7 @@ impl CodegenBackend for GotocCodegenBackend {
4646
Box::new(rustc_codegen_ssa::back::metadata::DefaultMetadataLoader)
4747
}
4848

49-
fn provide(&self, providers: &mut Providers) {
50-
providers.skip_monomorphize = skip_monomorphize;
51-
}
49+
fn provide(&self, _providers: &mut Providers) {}
5250

5351
fn provide_extern(&self, _providers: &mut ty::query::ExternProviders) {}
5452

compiler/rustc_codegen_rmc/src/overrides/hooks.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ struct MemSwap;
326326

327327
impl<'tcx> GotocHook<'tcx> for MemSwap {
328328
fn hook_applies(&self, tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
329+
// We need to keep the old std / core functions here because we don't compile std yet.
329330
let name = with_no_trimmed_paths(|| tcx.def_path_str(instance.def_id()));
330331
name == "core::mem::swap"
331332
|| name == "std::mem::swap"
@@ -688,7 +689,3 @@ impl<'tcx> GotocHooks<'tcx> {
688689
None
689690
}
690691
}
691-
692-
pub fn skip_monomorphize<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
693-
fn_hooks().hooks.iter().any(|hook| hook.hook_applies(tcx, instance))
694-
}

compiler/rustc_codegen_rmc/src/overrides/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
99
mod hooks;
1010

11-
pub use hooks::{fn_hooks, skip_monomorphize, GotocHooks};
11+
pub use hooks::{fn_hooks, GotocHooks};

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ impl CrateInfo {
874874
}
875875

876876
pub fn provide(providers: &mut Providers) {
877-
providers.skip_monomorphize = |_, _| false;
878877
providers.backend_optimization_level = |tcx, cratenum| {
879878
let for_speed = match tcx.sess.opts.optimize {
880879
// If globally no optimisation is done, #[optimize] has no effect.

compiler/rustc_middle/src/query/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,11 +1862,4 @@ rustc_queries! {
18621862
no_hash
18631863
desc { "performing HIR wf-checking for predicate {:?} at item {:?}", key.0, key.1 }
18641864
}
1865-
1866-
query skip_monomorphize(key: ty::Instance<'tcx>)
1867-
-> bool {
1868-
eval_always
1869-
no_hash
1870-
desc { "Check if we should skip monomorphization for `{}`", key}
1871-
}
18721865
}

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ pub fn collect_crate_mono_items(
317317
(visited.into_inner(), inlining_map.into_inner())
318318
}
319319

320-
// Temporary function that allow us to skip monomorphizing lang_start.
321320
// Find all non-generic items by walking the HIR. These items serve as roots to
322321
// start monomorphizing from.
323322
fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<'_>> {
@@ -922,10 +921,6 @@ fn visit_instance_use<'tcx>(
922921
return;
923922
}
924923

925-
if tcx.skip_monomorphize(instance) {
926-
return;
927-
}
928-
929924
match instance.def {
930925
ty::InstanceDef::Virtual(..) | ty::InstanceDef::Intrinsic(_) => {
931926
if !is_direct_call {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
use std::mem;
5+
6+
pub fn main() {
7+
let mut var1 = rmc::nondet::<i32>();
8+
let mut var2 = rmc::nondet::<i32>();
9+
let old_var1 = var1;
10+
unsafe {
11+
assert_eq!(mem::replace(&mut var1, var2), old_var1);
12+
}
13+
assert_eq!(var1, var2);
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
use std::mem;
5+
6+
pub fn main() {
7+
let mut var1 = rmc::nondet::<i32>();
8+
let mut var2 = rmc::nondet::<i32>();
9+
let old_var1 = var1;
10+
let old_var2 = var2;
11+
unsafe {
12+
mem::swap(&mut var1, &mut var2);
13+
}
14+
assert_eq!(var1, old_var2);
15+
assert_eq!(var2, old_var1);
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
use std::ptr::read;
5+
6+
pub fn main() {
7+
let var = 1;
8+
unsafe {
9+
assert_eq!(read(&var), var);
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
use std::ptr::write;
5+
6+
pub fn main() {
7+
let mut var = 1;
8+
unsafe {
9+
write(&mut var, 10);
10+
}
11+
assert_eq!(var, 10);
12+
}

src/test/rmc/Never/never_return.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
#![feature(never_type)]
5+
6+
/// Test using the never type
7+
pub fn err() -> ! {
8+
panic!("EXPECTED FAIL: Function should always fail");
9+
}
10+
11+
// Give an empty main to make rustc happy.
12+
#[no_mangle]
13+
pub fn main() {
14+
let var = rmc::nondet::<i32>();
15+
if var > 0 {
16+
err();
17+
}
18+
}

0 commit comments

Comments
 (0)