Skip to content

Commit

Permalink
build: switch to released gcmodule fork
Browse files Browse the repository at this point in the history
Signed-off-by: Yaroslav Bolyukin <[email protected]>
  • Loading branch information
CertainLach committed Jun 5, 2022
1 parent d76beb2 commit bde2637
Show file tree
Hide file tree
Showing 38 changed files with 179 additions and 206 deletions.
175 changes: 82 additions & 93 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/jsonnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false
[dependencies]
jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.4.2" }
jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }
gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
jrsonnet-gcmodule = { version = "0.3.4" }

[lib]
crate-type = ["cdylib"]
Expand Down
8 changes: 4 additions & 4 deletions bindings/jsonnet/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ use std::{
os::raw::{c_char, c_int},
};

use gcmodule::Cc;
use jrsonnet_evaluator::{
error::{Error, LocError},
function::builtin::{BuiltinParam, NativeCallback, NativeCallbackHandler},
tb,
typed::Typed,
IStr, State, Val,
};
use jrsonnet_gcmodule::Cc;

type JsonnetNativeCallback = unsafe extern "C" fn(
ctx: *const c_void,
argv: *const *const Val,
success: *mut c_int,
) -> *mut Val;

#[derive(gcmodule::Trace)]
#[derive(jrsonnet_gcmodule::Trace)]
struct JsonnetNativeCallbackHandler {
#[skip_trace]
#[trace(skip)]
ctx: *const c_void,
#[skip_trace]
#[trace(skip)]
cb: JsonnetNativeCallback,
}
impl NativeCallbackHandler for JsonnetNativeCallbackHandler {
Expand Down
2 changes: 1 addition & 1 deletion bindings/jsonnet/src/val_make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::{
os::raw::{c_char, c_double, c_int},
};

use gcmodule::Cc;
use jrsonnet_evaluator::{val::ArrValue, ObjValue, State, Val};
use jrsonnet_gcmodule::Cc;

/// # Safety
///
Expand Down
2 changes: 1 addition & 1 deletion bindings/jsonnet/src/val_modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use std::{ffi::CStr, os::raw::c_char};

use gcmodule::Cc;
use jrsonnet_evaluator::{val::ArrValue, State, Thunk, Val};
use jrsonnet_gcmodule::Cc;

/// # Safety
///
Expand Down
3 changes: 2 additions & 1 deletion cmds/jrsonnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ exp-destruct = ["jrsonnet-evaluator/exp-destruct"]
jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.4.2" }
jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }
jrsonnet-cli = { path = "../../crates/jrsonnet-cli", version = "0.4.2" }
jrsonnet-gcmodule = { version = "0.3.4" }

mimallocator = { version = "0.1.3", optional = true }
thiserror = "1.0"
gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
clap = { version = "3.1", features = ["derive"] }
clap_complete = { version = "3.1" }
1 change: 0 additions & 1 deletion cmds/jrsonnet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ fn main_catch(opts: Opts) -> bool {
}

fn main_real(s: &State, opts: Opts) -> Result<(), Error> {
opts.gc.configure_global();
opts.general.configure(s)?;
opts.manifest.configure(s)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.4.
"explaining-traces",
] }
jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }
gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
jrsonnet-gcmodule = { version = "0.3.4" }

clap = { version = "3.1", features = ["derive"] }
27 changes: 17 additions & 10 deletions crates/jrsonnet-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{env, path::PathBuf};
use clap::Parser;
pub use ext::*;
use jrsonnet_evaluator::{error::Result, FileImportResolver, State};
use jrsonnet_gcmodule::with_thread_object_space;
pub use manifest::*;
pub use tla::*;
pub use trace::*;
Expand Down Expand Up @@ -111,15 +112,21 @@ pub struct GcOpts {
gc_collect_before_printing_stats: bool,
}
impl GcOpts {
pub fn configure_global(&self) {
if !self.gc_collect_on_exit {
gcmodule::set_thread_collect_on_drop(false)
}
pub fn stats_printer(&self) -> (Option<GcStatsPrinter>, Option<LeakSpace>) {
(
self.gc_print_stats.then(|| GcStatsPrinter {
collect_before_printing_stats: self.gc_collect_before_printing_stats,
}),
(!self.gc_collect_on_exit).then(|| LeakSpace {}),
)
}
pub fn stats_printer(&self) -> Option<GcStatsPrinter> {
self.gc_print_stats.then(|| GcStatsPrinter {
collect_before_printing_stats: self.gc_collect_before_printing_stats,
})
}

pub struct LeakSpace {}

impl Drop for LeakSpace {
fn drop(&mut self) {
with_thread_object_space(|s| s.leak())
}
}

Expand All @@ -130,9 +137,9 @@ impl Drop for GcStatsPrinter {
fn drop(&mut self) {
eprintln!("=== GC STATS ===");
if self.collect_before_printing_stats {
let collected = gcmodule::collect_thread_cycles();
let collected = jrsonnet_gcmodule::collect_thread_cycles();
eprintln!("Collected: {}", collected);
}
eprintln!("Tracked: {}", gcmodule::count_thread_tracked())
eprintln!("Tracked: {}", jrsonnet_gcmodule::count_thread_tracked())
}
}
3 changes: 2 additions & 1 deletion crates/jrsonnet-evaluator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jrsonnet-parser = { path = "../jrsonnet-parser", version = "0.4.2" }
jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.4.2" }
jrsonnet-types = { path = "../jrsonnet-types", version = "0.4.2" }
jrsonnet-macros = { path = "../jrsonnet-macros", version = "0.4.2" }
jrsonnet-gcmodule = { version = "0.3.4" }

pathdiff = "0.2.1"
hashbrown = "0.12.1"
static_assertions = "1.1.0"
Expand All @@ -39,7 +41,6 @@ base64 = "0.13.0"
rustc-hash = "1.1"

thiserror = "1.0"
gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }

serde = "1.0"
serde_json = "1.0"
Expand Down
7 changes: 3 additions & 4 deletions crates/jrsonnet-evaluator/src/ctx.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::fmt::Debug;

use gcmodule::{Cc, Trace};
use jrsonnet_gcmodule::{Cc, Trace};
use jrsonnet_interner::IStr;

use crate::{
cc_ptr_eq, error::Error::*, gc::GcHashMap, map::LayeredHashMap, ObjValue, Pending, Result,
Thunk, Val,
error::Error::*, gc::GcHashMap, map::LayeredHashMap, ObjValue, Pending, Result, Thunk, Val,
};

#[derive(Trace)]
Expand Down Expand Up @@ -136,6 +135,6 @@ impl Default for Context {

impl PartialEq for Context {
fn eq(&self, other: &Self) -> bool {
cc_ptr_eq(&self.0, &other.0)
Cc::ptr_eq(&self.0, &other.0)
}
}
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::cell::RefCell;

use gcmodule::{Cc, Trace};
use jrsonnet_gcmodule::{Cc, Trace};

#[derive(Clone, Trace)]
pub struct Pending<V: Trace + 'static>(pub Cc<RefCell<Option<V>>>);
Expand Down
4 changes: 2 additions & 2 deletions crates/jrsonnet-evaluator/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt::Debug, path::PathBuf};

use gcmodule::Trace;
use jrsonnet_gcmodule::Trace;
use jrsonnet_interner::IStr;
use jrsonnet_parser::{BinaryOpType, ExprLocation, Source, UnaryOpType};
use jrsonnet_types::ValType;
Expand Down Expand Up @@ -125,7 +125,7 @@ pub enum Error {
ImportSyntaxError {
path: Source,
source_code: IStr,
#[skip_trace]
#[trace(skip)]
error: Box<jrsonnet_parser::ParseError>,
},

Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/evaluate/destructure.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gcmodule::Trace;
use jrsonnet_gcmodule::Trace;
use jrsonnet_interner::IStr;
use jrsonnet_parser::{BindSpec, Destruct, LocExpr, ParamsDesc};

Expand Down
10 changes: 5 additions & 5 deletions crates/jrsonnet-evaluator/src/evaluate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{cmp::Ordering, rc::Rc};

use gcmodule::{Cc, Trace};
use jrsonnet_gcmodule::{Cc, Trace};
use jrsonnet_interner::IStr;
use jrsonnet_parser::{
ArgsDesc, AssertStmt, BindSpec, CompSpec, Expr, FieldMember, FieldName, ForSpecData,
Expand Down Expand Up @@ -151,7 +151,7 @@ pub fn evaluate_member_list_object(s: State, ctx: Context, members: &[Member]) -
value,
}) => {
#[derive(Trace)]
struct UnboundValue<B> {
struct UnboundValue<B: Trace> {
uctx: B,
value: LocExpr,
name: IStr,
Expand Down Expand Up @@ -201,7 +201,7 @@ pub fn evaluate_member_list_object(s: State, ctx: Context, members: &[Member]) -
..
}) => {
#[derive(Trace)]
struct UnboundMethod<B> {
struct UnboundMethod<B: Trace> {
uctx: B,
value: LocExpr,
params: ParamsDesc,
Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn evaluate_member_list_object(s: State, ctx: Context, members: &[Member]) -
Member::BindStmt(_) => {}
Member::AssertStmt(stmt) => {
#[derive(Trace)]
struct ObjectAssert<B> {
struct ObjectAssert<B: Trace> {
uctx: B,
assert: AssertStmt,
}
Expand Down Expand Up @@ -299,7 +299,7 @@ pub fn evaluate_object(s: State, ctx: Context, object: &ObjBody) -> Result<ObjVa
Val::Null => {}
Val::Str(n) => {
#[derive(Trace)]
struct UnboundValue<B> {
struct UnboundValue<B: Trace> {
uctx: B,
value: LocExpr,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/function/arglike.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use gcmodule::Trace;
use jrsonnet_gcmodule::Trace;
use jrsonnet_interner::IStr;
use jrsonnet_parser::{ArgsDesc, LocExpr};

Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/function/builtin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

use gcmodule::Trace;
use jrsonnet_gcmodule::Trace;

use super::{arglike::ArgsLike, parse::parse_builtin_call, CallLocation};
use crate::{error::Result, gc::TraceBox, Context, State, Val};
Expand Down
4 changes: 2 additions & 2 deletions crates/jrsonnet-evaluator/src/function/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Debug;

pub use arglike::{ArgLike, ArgsLike, TlaArg};
use gcmodule::{Cc, Trace};
use jrsonnet_gcmodule::{Cc, Trace};
use jrsonnet_interner::IStr;
pub use jrsonnet_macros::builtin;
use jrsonnet_parser::{ExprLocation, LocExpr, ParamsDesc};
Expand Down Expand Up @@ -91,7 +91,7 @@ pub enum FuncVal {
/// Plain function implemented in jsonnet
Normal(Cc<FuncDesc>),
/// Standard library function
StaticBuiltin(#[skip_trace] &'static dyn StaticBuiltin),
StaticBuiltin(#[trace(skip)] &'static dyn StaticBuiltin),
/// User-provided function
Builtin(Cc<TraceBox<dyn Builtin>>),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/function/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gcmodule::Trace;
use jrsonnet_gcmodule::Trace;
use jrsonnet_interner::IStr;
use jrsonnet_parser::{LocExpr, ParamsDesc};

Expand Down
6 changes: 3 additions & 3 deletions crates/jrsonnet-evaluator/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::{
ops::{Deref, DerefMut},
};

use gcmodule::{Trace, Tracer};
use hashbrown::HashMap;
use jrsonnet_gcmodule::{Trace, Tracer};
use rustc_hash::{FxHashSet, FxHasher};

/// Replacement for box, which assumes that the underlying type is [`Trace`]
Expand Down Expand Up @@ -92,7 +92,7 @@ impl<V> Trace for GcHashSet<V>
where
V: Trace,
{
fn trace(&self, tracer: &mut gcmodule::Tracer) {
fn trace(&self, tracer: &mut jrsonnet_gcmodule::Tracer) {
for v in &self.0 {
v.trace(tracer);
}
Expand Down Expand Up @@ -133,7 +133,7 @@ where
K: Trace,
V: Trace,
{
fn trace(&self, tracer: &mut gcmodule::Tracer) {
fn trace(&self, tracer: &mut jrsonnet_gcmodule::Tracer) {
for (k, v) in &self.0 {
k.trace(tracer);
v.trace(tracer);
Expand Down
30 changes: 1 addition & 29 deletions crates/jrsonnet-evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ use error::{Error::*, LocError, Result, StackTraceElement};
pub use evaluate::*;
use function::{builtin::Builtin, CallLocation, TlaArg};
use gc::{GcHashMap, TraceBox};
use gcmodule::{Cc, Trace, Weak};
use hashbrown::hash_map::RawEntryMut;
pub use import::*;
use jrsonnet_gcmodule::{Cc, Trace};
use jrsonnet_interner::IBytes;
pub use jrsonnet_interner::IStr;
pub use jrsonnet_parser as parser;
Expand Down Expand Up @@ -705,31 +705,3 @@ impl State {
self.settings_mut().max_stack = trace;
}
}

pub fn cc_ptr_eq<T>(a: &Cc<T>, b: &Cc<T>) -> bool {
let a = a as &T;
let b = b as &T;
std::ptr::eq(a, b)
}

fn weak_raw<T>(a: Weak<T>) -> *const () {
unsafe { std::mem::transmute(a) }
}
fn weak_ptr_eq<T>(a: Weak<T>, b: Weak<T>) -> bool {
std::ptr::eq(weak_raw(a), weak_raw(b))
}

#[test]
fn weak_unsafe() {
let a = Cc::new(1);
let b = Cc::new(2);

let aw1 = a.clone().downgrade();
let aw2 = a.clone().downgrade();
let aw3 = a.clone().downgrade();

let bw = b.clone().downgrade();

assert!(weak_ptr_eq(aw1, aw2));
assert!(!weak_ptr_eq(aw3, bw));
}
4 changes: 2 additions & 2 deletions crates/jrsonnet-evaluator/src/map.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use gcmodule::{Cc, Trace};
use jrsonnet_gcmodule::{Cc, Trace};
use jrsonnet_interner::IStr;

use crate::{GcHashMap, Thunk, Val};

#[derive(Trace)]
#[force_tracking]
#[trace(tracking(force))]
pub struct LayeredHashMapInternals {
parent: Option<LayeredHashMap>,
current: GcHashMap<IStr, Thunk<Val>>,
Expand Down
Loading

0 comments on commit bde2637

Please sign in to comment.