Skip to content

Commit f686ee5

Browse files
authored
Merge pull request #260 from calcit-lang/rust2024
try rust 2024 with some fixes
2 parents 1549ab0 + 76e3500 commit f686ee5

File tree

6 files changed

+22
-24
lines changed

6 files changed

+22
-24
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "calcit"
33
version = "0.9.8"
44
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
5-
edition = "2021"
5+
edition = "2024"
66
license = "MIT"
77
description = "Interpreter and js codegen for Calcit"
88
homepage = "http://calcit-lang.org"

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22
[toolchain]
3-
channel = "stable"
3+
channel = "1.85.0"

src/bin/injection/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub fn blocking_dylib_edn_fn(xs: Vec<Calcit>, call_stack: &CallStackList) -> Res
268268
}
269269

270270
/// need to put it here since the crate does not compile for dylib
271-
#[no_mangle]
271+
#[unsafe(no_mangle)]
272272
pub fn on_ctrl_c(xs: Vec<Calcit>, call_stack: &CallStackList) -> Result<Calcit, CalcitErr> {
273273
if xs.len() == 1 {
274274
let cb = Arc::new(xs[0].to_owned());

src/builtins/lists.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ pub fn foldl_shortcut(xs: &[Calcit], call_stack: &CallStackList) -> Result<Calci
278278
format!("return value in foldl-shortcut should be a bool, got: {a}"),
279279
call_stack,
280280
a.get_location(),
281-
))
281+
));
282282
}
283283
},
284284
_ => {
285285
return Err(CalcitErr::use_msg_stack(
286286
format!("return value for foldl-shortcut should be `:: bool acc`, got: {pair}"),
287287
call_stack,
288-
))
288+
));
289289
}
290290
}
291291
}
@@ -315,14 +315,14 @@ pub fn foldl_shortcut(xs: &[Calcit], call_stack: &CallStackList) -> Result<Calci
315315
format!("return value in foldl-shortcut should be a bool, got: {a}"),
316316
call_stack,
317317
a.get_location(),
318-
))
318+
));
319319
}
320320
},
321321
_ => {
322322
return Err(CalcitErr::use_msg_stack(
323323
format!("return value for foldl-shortcut should be `:: bool acc`, got: {pair}"),
324324
call_stack,
325-
))
325+
));
326326
}
327327
}
328328
}
@@ -356,14 +356,14 @@ pub fn foldl_shortcut(xs: &[Calcit], call_stack: &CallStackList) -> Result<Calci
356356
format!("return value in foldl-shortcut should be a bool, got: {a}"),
357357
call_stack,
358358
a.get_location(),
359-
))
359+
));
360360
}
361361
},
362362
_ => {
363363
return Err(CalcitErr::use_msg_stack(
364364
format!("return value for foldl-shortcut should be `:: bool acc`, got: {pair}"),
365365
call_stack,
366-
))
366+
));
367367
}
368368
}
369369
}
@@ -420,14 +420,14 @@ pub fn foldr_shortcut(xs: &[Calcit], call_stack: &CallStackList) -> Result<Calci
420420
format!("return value in foldr-shortcut should be a bool, got: {a}"),
421421
call_stack,
422422
a.get_location(),
423-
))
423+
));
424424
}
425425
},
426426
_ => {
427427
return Err(CalcitErr::use_msg_stack(
428428
format!("return value for foldr-shortcut should be `:: bool acc`, got: {pair}"),
429429
call_stack,
430-
))
430+
));
431431
}
432432
}
433433
}
@@ -464,8 +464,8 @@ pub fn sort(xs: &[Calcit], call_stack: &CallStackList) -> Result<Calcit, CalcitE
464464
let v = runner::run_fn(&[(*a).to_owned(), (*b).to_owned()], info, call_stack);
465465
match v {
466466
Ok(Calcit::Number(x)) if x < 0.0 => Ordering::Less,
467-
Ok(Calcit::Number(x)) if x == 0.0 => Ordering::Equal,
468467
Ok(Calcit::Number(x)) if x > 0.0 => Ordering::Greater,
468+
Ok(Calcit::Number(_)) => Ordering::Equal,
469469
Ok(a) => {
470470
eprintln!("expected number from sort comparator, got: {a}");
471471
panic!("failed to sort")
@@ -491,8 +491,8 @@ pub fn sort(xs: &[Calcit], call_stack: &CallStackList) -> Result<Calcit, CalcitE
491491
let v = builtins::handle_proc(*proc, &[(*a).to_owned(), (*b).to_owned()], call_stack);
492492
match v {
493493
Ok(Calcit::Number(x)) if x < 0.0 => Ordering::Less,
494-
Ok(Calcit::Number(x)) if x == 0.0 => Ordering::Equal,
495494
Ok(Calcit::Number(x)) if x > 0.0 => Ordering::Greater,
495+
Ok(Calcit::Number(_)) => Ordering::Equal,
496496
Ok(a) => {
497497
eprintln!("expected number from sort comparator, got: {a}");
498498
panic!("failed to sort")

src/codegen/emit_js/internal_states.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use std::collections::{HashMap, HashSet};
55
use std::sync::atomic::{AtomicBool, Ordering};
66
use std::sync::{Arc, LazyLock, RwLock};
77

8+
type ProgramCache = HashMap<Arc<str>, HashSet<Arc<str>>>;
9+
810
// track if it's the first compilation
911
static FIRST_COMPILATION: AtomicBool = AtomicBool::new(true);
1012

1113
// caches program data for detecting incremental changes of libs
12-
static GLOBAL_PREVIOUS_PROGRAM_CACHES: LazyLock<RwLock<HashMap<Arc<str>, HashSet<Arc<str>>>>> =
13-
LazyLock::new(|| RwLock::new(HashMap::new()));
14+
static GLOBAL_PREVIOUS_PROGRAM_CACHES: LazyLock<RwLock<ProgramCache>> = LazyLock::new(|| RwLock::new(HashMap::new()));
1415

1516
pub fn lookup_prev_ns_cache(ns: &str) -> Option<HashSet<Arc<str>>> {
1617
let previous_program_caches = &GLOBAL_PREVIOUS_PROGRAM_CACHES.read().expect("load cache");

src/runner/preprocess.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
builtins::{is_js_syntax_procs, is_proc_name, is_registered_proc},
33
calcit::{
44
self, Calcit, CalcitArgLabel, CalcitErr, CalcitFnArgs, CalcitImport, CalcitList, CalcitLocal, CalcitProc, CalcitScope,
5-
CalcitSymbolInfo, CalcitSyntax, CalcitThunk, CalcitThunkInfo, ImportInfo, LocatedWarning, NodeLocation, RawCodeType, GENERATED_DEF,
5+
CalcitSymbolInfo, CalcitSyntax, CalcitThunk, CalcitThunkInfo, GENERATED_DEF, ImportInfo, LocatedWarning, NodeLocation, RawCodeType,
66
},
77
call_stack::{CallStackList, StackKind},
88
codegen, program, runner,
@@ -43,10 +43,7 @@ pub fn preprocess_ns_def(
4343
let resolved_code = preprocess_expr(&code, &HashSet::new(), ns, check_warnings, &next_stack)?;
4444
// println!("\n resolve code to run: {:?}", resolved_code);
4545
let v = if is_fn_or_macro(&resolved_code) {
46-
match runner::evaluate_expr(&resolved_code, &CalcitScope::default(), ns, &next_stack) {
47-
Ok(ret) => ret,
48-
Err(e) => return Err(e),
49-
}
46+
runner::evaluate_expr(&resolved_code, &CalcitScope::default(), ns, &next_stack)?
5047
} else {
5148
Calcit::Thunk(CalcitThunk::Code {
5249
code: Arc::new(resolved_code),
@@ -832,27 +829,27 @@ pub fn preprocess_core_let(
832829
format!("invalid pair for &let binding: {a} {b}"),
833830
call_stack,
834831
a.get_location().or_else(|| b.get_location()),
835-
))
832+
));
836833
}
837834
},
838835
Some(a @ Calcit::List(_)) => {
839836
return Err(CalcitErr::use_msg_stack(
840837
format!("expected binding of a pair, got: {a}"),
841838
call_stack,
842-
))
839+
));
843840
}
844841
Some(a) => {
845842
return Err(CalcitErr::use_msg_stack_location(
846843
format!("expected binding of a pair, got: {a}"),
847844
call_stack,
848845
a.get_location(),
849-
))
846+
));
850847
}
851848
None => {
852849
return Err(CalcitErr::use_msg_stack(
853850
"expected binding of a pair, got nothing".to_owned(),
854851
call_stack,
855-
))
852+
));
856853
}
857854
};
858855
xs.push(binding);

0 commit comments

Comments
 (0)