Skip to content

Commit

Permalink
ffi-polonius: Add logging using env_logger
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Sep 27, 2022
1 parent 747a14d commit 9e0a229
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 9 deletions.
119 changes: 119 additions & 0 deletions gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ crate-type = ["staticlib"]

[dependencies]
polonius-engine = "0.13"
log = "0.4"
env_logger = "0.9"
25 changes: 16 additions & 9 deletions gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! 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;

#[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);

Expand All @@ -30,6 +32,7 @@ impl From<GccrsAtom> 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;
Expand All @@ -46,8 +49,12 @@ pub struct FfiGccrsPolonius(pub(crate) AllFacts<GccrsPolonius>);
/// 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)))
}

Expand All @@ -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
Expand All @@ -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()))
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}

0 comments on commit 9e0a229

Please sign in to comment.