diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock b/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock index 73368397082c..71a1b585206b 100644 --- a/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock +++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock @@ -2,6 +2,26 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +dependencies = [ + "memchr", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -14,13 +34,49 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69" +[[package]] +name = "env_logger" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "ffi-polonius" version = "0.1.0" dependencies = [ + "env_logger", + "log", "polonius-engine", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "libc" +version = "0.2.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966" + [[package]] name = "log" version = "0.4.14" @@ -30,6 +86,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + [[package]] name = "polonius-engine" version = "0.13.0" @@ -41,8 +103,65 @@ dependencies = [ "rustc-hash", ] +[[package]] +name = "regex" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" + [[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.toml b/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.toml index 809635620e79..e17f1e3ca0e2 100644 --- a/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.toml +++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.toml @@ -8,3 +8,5 @@ crate-type = ["staticlib"] [dependencies] polonius-engine = "0.13" +log = "0.4" +env_logger = "0.9" diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs index ca654e17a770..da3cc7a39d52 100644 --- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs +++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs @@ -1,6 +1,7 @@ //! There are two main components to the polonius-engine library: Facts and //! Output. +use log::{debug, info}; use polonius_engine::{AllFacts, Atom, FactTypes, Output}; use std::convert::From; @@ -8,6 +9,7 @@ use std::convert::From; #[derive(Debug, Clone, Copy, Default)] struct GccrsPolonius; +/// This represents an `HirId` as emitted by `gccrs`. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] struct GccrsAtom(usize); @@ -30,6 +32,7 @@ impl From for usize { } impl FactTypes for GccrsPolonius { + // FIXME: Do we want anything else than the `HirId` here? type Origin = GccrsAtom; type Loan = GccrsAtom; type Point = GccrsAtom; @@ -46,8 +49,12 @@ pub struct FfiGccrsPolonius(pub(crate) AllFacts); /// and return. #[no_mangle] pub unsafe extern "C" fn polonius_init() -> *mut FfiGccrsPolonius { + env_logger::init(); + + info!("initializing handle"); + let facts = AllFacts::default(); - eprintln!("[polonius] init"); + Box::into_raw(Box::new(FfiGccrsPolonius(facts))) } @@ -57,8 +64,9 @@ pub unsafe extern "C" fn polonius_init() -> *mut FfiGccrsPolonius { /// performed. #[no_mangle] pub unsafe extern "C" fn polonius_deinit(handle: *mut FfiGccrsPolonius) { - eprintln!("[polonius] deinit"); - Box::from_raw(handle); + info!("deinitializing handle"); + + drop(Box::from_raw(handle)); } /// # Safety @@ -72,7 +80,7 @@ pub unsafe extern "C" fn polonius_var_used_at( ) { let handle = handle.as_mut().unwrap(); - eprintln!("[polonius] variable {} used at {}", var_id, point_id); + debug!("variable {} used at {}", var_id, point_id); handle.0.var_used_at.push((var_id.into(), point_id.into())) } @@ -88,10 +96,7 @@ pub unsafe extern "C" fn polonius_define_var( ) { let handle = handle.as_mut().unwrap(); - eprintln!( - "[polonius] defining variable ([point] {}: [var] {})", - point_id, var_id - ); + debug!("defining variable ([point] {}: [var] {})", point_id, var_id); handle .0 @@ -106,7 +111,7 @@ pub unsafe extern "C" fn polonius_define_var( pub unsafe extern "C" fn polonius_borrow_var(handle: *mut FfiGccrsPolonius) { let _handle = handle.as_mut().unwrap(); - eprintln!("[polonius] borrowing variable"); + debug!("borrowing variable"); } /// # Safety @@ -116,5 +121,7 @@ pub unsafe extern "C" fn polonius_borrow_var(handle: *mut FfiGccrsPolonius) { pub unsafe extern "C" fn polonius_compute(handle: *mut FfiGccrsPolonius) { let handle = handle.as_mut().unwrap(); + info!("computing facts"); + Output::compute(&handle.0, polonius_engine::Algorithm::Naive, true); }