1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
use rebel_lang::{
scope::{Context, ModuleEntry, Var},
typing::Type,
};
use rebel_parse::ast;
fn main() {
divan::main();
}
const RECIPE: &str = include_str!("../../../examples/recipes/gmp/build.recipe");
fn recipe() -> ast::Recipe<'static> {
let tokens = rebel_parse::tokenize::token_stream(RECIPE).unwrap();
rebel_parse::recipe::recipe(&tokens).unwrap()
}
fn context() -> Context {
let mut ctx = Context::default();
ctx.vars.0.insert(
"workdir".to_owned(),
ModuleEntry::Def(Var {
explicit_type: Type::Str,
inferred_type: Type::Str,
value: None,
}),
);
ctx.vars.0.insert(
"name".to_owned(),
ModuleEntry::Def(Var {
explicit_type: Type::Str,
inferred_type: Type::Str,
value: None,
}),
);
ctx
}
#[divan::bench]
fn validate(bencher: divan::Bencher) {
let recipe = recipe();
bencher.bench(|| {
for stmt in divan::black_box(&recipe) {
stmt.validate().unwrap();
}
});
}
#[divan::bench]
fn typecheck(bencher: divan::Bencher) {
let recipe = recipe();
let ctx = context();
for stmt in &recipe {
stmt.validate().unwrap();
}
bencher.bench(|| {
let mut ctx = divan::black_box(ctx.clone());
for stmt in divan::black_box(&recipe) {
let ast::RecipeStmt::BodyStmt(stmt) = stmt else {
// TODO: Check other statements
continue;
};
ctx.record_type(stmt).unwrap();
}
});
}
|