From 92e63d24f79ab95723602cd8e895b728873f502e Mon Sep 17 00:00:00 2001 From: dkcumming Date: Wed, 30 Oct 2024 06:16:34 +1000 Subject: [PATCH 1/4] weakened guard for logging --- src/printer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 4352d02..18c84bb 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -372,11 +372,11 @@ fn update_link_map<'tcx>(link_map: &mut LinkMap<'tcx>, fn_sym: Option {:?}, {:?}", check_collision, (ty, ty.kind().fn_def(), &kind), curr_val.1, new_val.1); } curr_val.0.0 |= new_val.0.0; - if check_collision && debug_enabled() { + if check_collision || debug_enabled() { println!("Regenerated link map entry: {:?}:{:?} -> {:?}", &key, key.0.kind().fn_def(), new_val); } } else { - if check_collision && debug_enabled() { + if check_collision || debug_enabled() { println!("Generated link map entry from call: {:?}:{:?} -> {:?}", &key, key.0.kind().fn_def(), new_val); } link_map.insert(key.clone(), new_val); From 263e125acb8ad0bd3dceb65dab74479bd4cfc522 Mon Sep 17 00:00:00 2001 From: dkcumming Date: Wed, 30 Oct 2024 06:27:41 +1000 Subject: [PATCH 2/4] removed collision flag entirely from update_link_map --- src/printer.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 18c84bb..45a72c8 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -362,21 +362,21 @@ struct LinkNameCollector<'tcx, 'local> { locals: &'local [LocalDecl], } -fn update_link_map<'tcx>(link_map: &mut LinkMap<'tcx>, fn_sym: Option>, source: ItemSource, check_collision: bool) { +fn update_link_map<'tcx>(link_map: &mut LinkMap<'tcx>, fn_sym: Option>, source: ItemSource) { if fn_sym.is_none() { return } let (ty, kind, name) = fn_sym.unwrap(); let new_val = (source, name); let key = if link_instance_enabled() { LinkMapKey(ty, Some(kind)) } else { LinkMapKey(ty, None) }; if let Some(curr_val) = link_map.get_mut(&key.clone()) { if curr_val.1 != new_val.1 { - panic!("Checking collisions: {}, Added inconsistent entries into link map! {:?} -> {:?}, {:?}", check_collision, (ty, ty.kind().fn_def(), &kind), curr_val.1, new_val.1); + panic!("Added inconsistent entries into link map! {:?} -> {:?}, {:?}", (ty, ty.kind().fn_def(), &kind), curr_val.1, new_val.1); } curr_val.0.0 |= new_val.0.0; - if check_collision || debug_enabled() { + if debug_enabled() { println!("Regenerated link map entry: {:?}:{:?} -> {:?}", &key, key.0.kind().fn_def(), new_val); } } else { - if check_collision || debug_enabled() { + if debug_enabled() { println!("Generated link map entry from call: {:?}:{:?} -> {:?}", &key, key.0.kind().fn_def(), new_val); } link_map.insert(key.clone(), new_val); @@ -400,7 +400,7 @@ impl MirVisitor for LinkNameCollector<'_, '_> { } _ => None }; - update_link_map(self.link_map, fn_sym, ItemSource(TERM), true); + update_link_map(self.link_map, fn_sym, ItemSource(TERM)); self.super_terminator(term, loc); } @@ -410,7 +410,7 @@ impl MirVisitor for LinkNameCollector<'_, '_> { Rvalue::Cast(CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer), ref op, _) => { let inst = fn_inst_for_ty(op.ty(self.locals).unwrap(), false).expect("ReifyFnPointer Cast operand type does not resolve to an instance"); let fn_sym = fn_inst_sym(self.tcx, None, Some(&inst)); - update_link_map(self.link_map, fn_sym, ItemSource(FPTR), true); + update_link_map(self.link_map, fn_sym, ItemSource(FPTR)); } _ => {} }; @@ -423,7 +423,7 @@ fn collect_fn_calls<'tcx,'local>(tcx: TyCtxt<'tcx>, items: Vec<&'local MonoItem> if link_items_enabled() { for item in items.iter() { if let MonoItem::Fn ( inst ) = item { - update_link_map(&mut hash_map, fn_inst_sym(tcx, None, Some(inst)), ItemSource(ITEM), false) + update_link_map(&mut hash_map, fn_inst_sym(tcx, None, Some(inst)), ItemSource(ITEM)) } } } From 45ae8a10386e2d27c2cb1820600e1df54e4bf275 Mon Sep 17 00:00:00 2001 From: dkcumming Date: Thu, 31 Oct 2024 05:17:41 +1000 Subject: [PATCH 3/4] Added documentation for how to generatate smir.json for the std-lib --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index a3f06f7..2799ede 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,17 @@ There are a few environment variables that can be set to control the tools outpu 2. `LINK_INST` - use a richer key-structure for the link-time `functions` map which uses keys that are pairs of a function type (`Ty`) _and_ an function instance kind (`InstanceKind`) 3. `DEBUG` - serialize additional data in the JSON file and dump logs to stdout +### Usage For std-lib +To generate the stable MIR output for the entire standard libary, the most simple way is using the `cargo` option `build-std` on a new project while pointing the `RUSTC` environment variable to `run.sh`. For example: +``` +cargo new example +cd example +RUSTC="//smir_prety/run.sh" cargo build -Z build-std --target +``` +If the `smir_pretty` is not built this will not initiate a build of `smir_pretty` and will crash instead. If the target is unknown it can be read using the `rustc_arch.sh` script in this repo. The generated files can be found in `example/target//deps/` and will have extension `*.smir.json`. + +WARNING: This option has been succeeding on cargo version `1.79.0-nightly` but has been failing on `1.82.0-nightly` + ### Invocation Details We use an uncommon build process where we link against a patched rustc installed in this repo. From 574f43363dac375d359604e018dba99d50fa63f5 Mon Sep 17 00:00:00 2001 From: dkcumming Date: Thu, 31 Oct 2024 05:23:17 +1000 Subject: [PATCH 4/4] Linked to build-std docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2799ede..5102f96 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ There are a few environment variables that can be set to control the tools outpu 3. `DEBUG` - serialize additional data in the JSON file and dump logs to stdout ### Usage For std-lib -To generate the stable MIR output for the entire standard libary, the most simple way is using the `cargo` option `build-std` on a new project while pointing the `RUSTC` environment variable to `run.sh`. For example: +To generate the stable MIR output for the entire standard libary, the most simple way is using the [cargo option build-std](https://doc.rust-lang.org/cargo/reference/unstable.html#build-std) on a new project while pointing the `RUSTC` environment variable to `run.sh`. For example: ``` cargo new example cd example