Skip to content

Commit

Permalink
Try out funcarray
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Oct 10, 2024
1 parent e19fcaf commit baf1830
Show file tree
Hide file tree
Showing 20 changed files with 1,599 additions and 160 deletions.
93 changes: 87 additions & 6 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"core",
"cli",
"funcarray",
"lsp/nls",
"lsp/lsp-harness",
"utils",
Expand All @@ -22,6 +23,7 @@ readme = "README.md"

[workspace.dependencies]
nickel-lang-core = { version = "0.9.0", path = "./core", default-features = false }
nickel-lang-funcarray = { version = "0.1.0", path = "./funcarray" }
nickel-lang-utils = { version = "0.1.0", path = "./utils" }
lsp-harness = { version = "0.1.0", path = "./lsp/lsp-harness" }

Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ codespan.workspace = true
codespan-reporting.workspace = true
cxx = { workspace = true, optional = true }
logos.workspace = true
nickel-lang-funcarray.workspace = true
smallvec.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
Expand Down Expand Up @@ -82,7 +83,6 @@ tree-sitter-nickel = { workspace = true, optional = true }

metrics = { workspace = true, optional = true }
strsim = "0.10.0"
rpds = { version = "1.1.0", features = ["serde"] }

[dev-dependencies]
pretty_assertions.workspace = true
Expand Down
5 changes: 4 additions & 1 deletion core/benches/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ fn ncl_random_array(len: usize) -> String {
numbers.push(RichTerm::from(Term::Num(Number::from(acc))));
}

let xs = RichTerm::from(Term::Array(Array::new(numbers), ArrayAttrs::default()));
let xs = RichTerm::from(Term::Array(
Array::collect(numbers.into_iter()),
ArrayAttrs::default(),
));
let doc: DocBuilder<_, ()> = xs.pretty(&BoxAllocator);
let mut out = Vec::new();
doc.render(80, &mut out).unwrap();
Expand Down
5 changes: 4 additions & 1 deletion core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,10 @@ impl Cache {
))
} else {
Ok((
attach_pos(Term::Array(Array::new(terms), Default::default()).into()),
attach_pos(
Term::Array(Array::collect(terms.into_iter()), Default::default())
.into(),
),
ParseErrors::default(),
))
}
Expand Down
7 changes: 3 additions & 4 deletions core/src/closurize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,12 @@ impl Closurize for Array {
env: Environment,
btype: BindingType,
) -> Self {
self.iter()
self.into_iter()
.map(|t| {
if should_share(&t.term) {
t.clone()
.closurize_as_btype(cache, env.clone(), btype.clone())
t.closurize_as_btype(cache, env.clone(), btype.clone())
} else {
t.clone()
t
}
})
.collect()
Expand Down
8 changes: 4 additions & 4 deletions core/src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,8 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
// See the comment on the `BinaryOp::ArrayConcat` match arm.
Term::Array(terms, attrs) if !attrs.closurized => {
let closurized_array = terms
.iter()
.map(|t| t.clone().closurize(&mut self.cache, env.clone()))
.into_iter()
.map(|t| t.closurize(&mut self.cache, env.clone()))
.collect();

let closurized_ctrs = attrs
Expand Down Expand Up @@ -1274,8 +1274,8 @@ pub fn subst<C: Cache>(
}
Term::Array(ts, mut attrs) => {
let ts = ts
.iter()
.map(|t| subst(cache, t.clone(), initial_env, env))
.into_iter()
.map(|t| subst(cache, t, initial_env, env))
.collect();

// cd [^subst-closurized-false]
Expand Down
Loading

0 comments on commit baf1830

Please sign in to comment.