chore: update deps; restructure tests; use Map over Record

This commit is contained in:
2026-02-17 10:41:08 +08:00
parent f49634ccc0
commit 3cc7c7be75
445 changed files with 107 additions and 125 deletions

65
Cargo.lock generated
View File

@@ -429,9 +429,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.58"
version = "4.5.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63be97961acde393029492ce0be7a1af7e323e6bae9511ebfac33751be5e6806"
checksum = "c5caf74d17c3aec5495110c34cc3f78644bfa89af6c8993ed4de2790e49b6499"
dependencies = [
"clap_builder",
"clap_derive",
@@ -439,9 +439,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.58"
version = "4.5.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f13174bda5dfd69d7e947827e5af4b0f2f94a4a3ee92912fba07a66150f21e2"
checksum = "370daa45065b80218950227371916a1633217ae42b2715b2287b606dcd618e24"
dependencies = [
"anstream",
"anstyle",
@@ -1142,9 +1142,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
[[package]]
name = "futures"
version = "0.3.31"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"
checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d"
dependencies = [
"futures-channel",
"futures-core",
@@ -1157,9 +1157,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.31"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"
dependencies = [
"futures-core",
"futures-sink",
@@ -1167,15 +1167,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.31"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
[[package]]
name = "futures-executor"
version = "0.3.31"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f"
checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d"
dependencies = [
"futures-core",
"futures-task",
@@ -1184,15 +1184,15 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.31"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"
[[package]]
name = "futures-macro"
version = "0.3.31"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"
dependencies = [
"proc-macro2",
"quote",
@@ -1201,21 +1201,21 @@ dependencies = [
[[package]]
name = "futures-sink"
version = "0.3.31"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7"
checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"
[[package]]
name = "futures-task"
version = "0.3.31"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988"
checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
[[package]]
name = "futures-util"
version = "0.3.31"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
dependencies = [
"futures-channel",
"futures-core",
@@ -1225,7 +1225,6 @@ dependencies = [
"futures-task",
"memchr",
"pin-project-lite",
"pin-utils",
"slab",
]
@@ -1987,7 +1986,7 @@ dependencies = [
[[package]]
name = "nix-compat"
version = "0.1.0"
source = "git+https://git.snix.dev/snix/snix.git#9d414bec7c7fff1fca6ba6d14dda6c4295521260"
source = "git+https://git.snix.dev/snix/snix.git#db30e92b30e18ca4d813206ac1b60d1f670adb8c"
dependencies = [
"bitflags",
"bstr",
@@ -2010,7 +2009,7 @@ dependencies = [
[[package]]
name = "nix-compat-derive"
version = "0.1.0"
source = "git+https://git.snix.dev/snix/snix.git#9d414bec7c7fff1fca6ba6d14dda6c4295521260"
source = "git+https://git.snix.dev/snix/snix.git#db30e92b30e18ca4d813206ac1b60d1f670adb8c"
dependencies = [
"proc-macro2",
"quote",
@@ -2678,9 +2677,9 @@ dependencies = [
[[package]]
name = "rnix"
version = "0.13.0"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b8276b540c344ec04cd215fb3d35db378c2b1861cc44802c2c097f3490f6e52"
checksum = "c163bd17372eecdf10d351c34584b7de7c1a33be4e92a32f3fb3f5a7fe3f579b"
dependencies = [
"rowan",
]
@@ -3261,9 +3260,9 @@ checksum = "a7973cce6668464ea31f176d85b13c7ab3bba2cb3b77a2ed26abd7801688010a"
[[package]]
name = "syn"
version = "2.0.115"
version = "2.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e614ed320ac28113fa64972c4262d5dbc89deacdfd00c34a3e4cea073243c12"
checksum = "3df424c70518695237746f84cede799c9c58fcb37450d7b23716568cc8bc69cb"
dependencies = [
"proc-macro2",
"quote",
@@ -3583,9 +3582,9 @@ dependencies = [
[[package]]
name = "toml_parser"
version = "1.0.8+spec-1.1.0"
version = "1.0.9+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0742ff5ff03ea7e67c8ae6c93cac239e0d9784833362da3f9a9c1da8dfefcbdc"
checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4"
dependencies = [
"winnow",
]
@@ -3722,9 +3721,9 @@ checksum = "81b79ad29b5e19de4260020f8919b443b2ef0277d242ce532ec7b7a2cc8b6007"
[[package]]
name = "unicode-ident"
version = "1.0.23"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "unicode-linebreak"

View File

@@ -58,7 +58,7 @@ dirs = "6.0"
tempfile = "3.24"
rusqlite = { version = "0.38", features = ["bundled"] }
rnix = "0.13"
rnix = "0.14"
rowan = "0.16"
nix-js-macros = { path = "../nix-js-macros" }

View File

@@ -149,13 +149,11 @@ export const unsafeGetAttrPos =
return null;
}
const positions = (attrs as NixAttrs & Record<symbol, unknown>)[ATTR_POSITIONS] as
| Record<string, string>
| undefined;
if (!positions || !(name in positions)) {
const positions = attrs[ATTR_POSITIONS];
if (!positions || !positions.has(name)) {
return null;
}
const span = positions[name];
const span = positions.get(name) as string;
return mkPos(span);
};

View File

@@ -146,7 +146,7 @@ export const functionArgs = (f: NixValue): NixAttrs => {
ret.set(key, true);
}
const positions = func.args.positions;
if (positions && Object.keys(positions).length > 0) {
if (positions) {
ret[ATTR_POSITIONS] = positions;
}
return ret;

View File

@@ -314,8 +314,8 @@ interface WithScope {
last: WithScope | null;
}
export const lookupWith = (name: string, withScope: WithScope | null): NixValue => {
let current = withScope;
export const lookupWith = (name: string, withScope: WithScope): NixValue => {
let current: WithScope | null = withScope;
while (current !== null) {
const attrs = forceAttrs(current.env);
if (attrs.has(name)) {

View File

@@ -35,7 +35,7 @@ import { ATTR_POSITIONS, IS_PATH, mkAttrs, mkAttrsWithPos, mkFunction, type NixV
export type NixRuntime = typeof Nix;
const replBindings: Record<string, NixValue> = {};
const replBindings: Map<string, NixValue> = new Map;
export const Nix = {
createThunk,
@@ -74,9 +74,9 @@ export const Nix = {
replBindings,
setReplBinding: (name: string, value: NixValue) => {
replBindings[name] = value;
replBindings.set(name, value);
},
getReplBinding: (name: string) => replBindings[name],
getReplBinding: (name: string) => replBindings.get(name),
};
globalThis.Nix = Nix;

View File

@@ -40,7 +40,7 @@ export const printValue = (value: NixValue, seen: WeakSet<object> = new WeakSet(
}
if (typeof value === "object") {
if (IS_CYCLE in value && (value as Record<symbol, unknown>)[IS_CYCLE] === true) {
if (IS_CYCLE in value) {
return "«repeated»";
}
@@ -68,7 +68,7 @@ export const printValue = (value: NixValue, seen: WeakSet<object> = new WeakSet(
return `{${entries ? ` ${entries} ` : " "}}`;
}
return "<unknown>";
throw new Error("unreachable");
};
const printString = (s: string): string => {

View File

@@ -24,18 +24,18 @@ export type NixNull = null;
export const ATTR_POSITIONS = Symbol("attrPositions");
export type NixList = NixValue[];
export type NixAttrs = Map<string, NixValue> & { [ATTR_POSITIONS]?: Record<string, string> };
export type NixAttrs = Map<string, NixValue> & { [ATTR_POSITIONS]?: Map<string, string> };
export type NixFunction = ((arg: NixValue) => NixValue) & { args?: NixArgs };
export class NixArgs {
required: string[];
optional: string[];
allowed: Set<string>;
ellipsis: boolean;
positions: Record<string, string>;
positions: Map<string, string>;
constructor(required: string[], optional: string[], positions: Record<string, string>, ellipsis: boolean) {
this.required = required;
this.optional = optional;
this.positions = positions;
this.positions = new Map(Object.entries(positions));
this.ellipsis = ellipsis;
this.allowed = new Set(required.concat(optional));
}
@@ -103,7 +103,7 @@ export const mkAttrsWithPos = (
}
if (Object.keys(positions).length > 0) {
attrs[ATTR_POSITIONS] = positions;
attrs[ATTR_POSITIONS] = new Map(Object.entries(positions));
}
return attrs;

View File

@@ -101,6 +101,12 @@ impl<Ctx: DowngradeContext> Downgrade<Ctx> for Expr {
AttrSet(attrs) => attrs.downgrade(ctx),
UnaryOp(op) => op.downgrade(ctx),
Ident(ident) => ident.downgrade(ctx),
CurPos(curpos) => Ok(ctx.new_expr(
self::CurPos {
span: curpos.syntax().text_range(),
}
.to_ir(),
)),
With(with) => with.downgrade(ctx),
HasAttr(has) => has.downgrade(ctx),
Paren(paren) => paren
@@ -265,11 +271,6 @@ impl<Ctx: DowngradeContext> Downgrade<Ctx> for ast::Ident {
fn downgrade(self, ctx: &mut Ctx) -> Result<ExprId> {
let span = self.syntax().text_range();
let text = self.ident_token().require(ctx, span)?.to_string();
if text == "__curPos" {
return Ok(ctx.new_expr(CurPos { span }.to_ir()));
}
let sym = ctx.new_sym(text);
ctx.lookup(sym, span)
}

View File

@@ -2,7 +2,7 @@ use std::path::PathBuf;
use std::process::exit;
use anyhow::Result;
use clap::{Parser, Subcommand, Args};
use clap::{Args, Parser, Subcommand};
use hashbrown::HashSet;
use nix_js::context::Context;
use nix_js::error::Source;
@@ -28,7 +28,7 @@ struct Cli {
enum Command {
Eval {
#[clap(flatten)]
source: ExprSource
source: ExprSource,
},
Repl,
}
@@ -39,7 +39,7 @@ struct ExprSource {
#[clap(short, long)]
expr: Option<String>,
#[clap(short, long)]
file: Option<PathBuf>
file: Option<PathBuf>,
}
fn create_context(#[cfg(feature = "inspector")] cli: &Cli) -> Result<Context> {
@@ -150,9 +150,7 @@ fn main() -> Result<()> {
)?;
match cli.command {
Command::Eval { source } => {
run_eval(&mut context, source)
}
Command::Eval { source } => run_eval(&mut context, source),
Command::Repl => run_repl(&mut context),
}
}

View File

@@ -370,9 +370,13 @@ fn to_value<'a>(
let array = val.as_array(scope);
let attrs = (0..size)
.map(|i| {
let key = array.get_index(scope, i * 2).expect("infallible index operation");
let key = array
.get_index(scope, i * 2)
.expect("infallible index operation");
let key = key.to_rust_string_lossy(scope);
let val = array.get_index(scope, i * 2 + 1).expect("infallible index operation");
let val = array
.get_index(scope, i * 2 + 1)
.expect("infallible index operation");
let val = to_value(
val,
scope,
@@ -383,7 +387,8 @@ fn to_value<'a>(
is_cycle_symbol,
);
(Symbol::new(Cow::Owned(key)), val)
}).collect();
})
.collect();
Value::AttrSet(AttrSet::new(attrs))
}
_ if val.is_object() => {

View File

@@ -1,9 +1,5 @@
mod utils;
use crate::utils::{eval, eval_result};
use nix_js::value::Value;
use utils::eval;
use crate::utils::eval_result;
#[test]
fn arithmetic() {

View File

@@ -1,9 +1,6 @@
mod utils;
use std::collections::BTreeMap;
use crate::utils::eval;
use nix_js::value::{AttrSet, List, Value};
use utils::eval;
use std::collections::BTreeMap;
#[test]
fn builtins_accessible() {

View File

@@ -1,7 +1,5 @@
mod utils;
use crate::utils::eval_result;
use nix_js::value::Value;
use utils::eval_result;
#[test]
fn to_file_simple() {

View File

@@ -1,7 +1,5 @@
mod utils;
use crate::utils::{eval_deep, eval_deep_result};
use nix_js::value::Value;
use utils::{eval_deep, eval_deep_result};
#[test]
fn add_operator_preserves_derivation_context() {

View File

@@ -1,6 +1,4 @@
mod utils;
use utils::eval;
use crate::utils::eval;
#[test]
fn test_find_file_corepkg_fetchurl() {

View File

@@ -1,7 +1,5 @@
mod utils;
use crate::utils::{eval, eval_result};
use nix_js::value::{List, Value};
use utils::eval;
#[test]
fn true_literal() {
@@ -65,7 +63,7 @@ fn shadow_in_function() {
#[test]
fn throw_function() {
let result = utils::eval_result("throw \"error message\"");
let result = eval_result("throw \"error message\"");
assert!(result.is_err());
}

View File

@@ -1,7 +1,5 @@
mod utils;
use crate::utils::{eval, eval_result};
use nix_js::value::Value;
use utils::{eval, eval_result};
#[test]
fn required_parameters() {

View File

@@ -1,11 +1,8 @@
mod utils;
use crate::utils::{eval, eval_result};
use nix_js::context::Context;
use nix_js::error::Source;
use nix_js::value::Value;
use crate::utils::{eval, eval_result};
#[test]
fn import_absolute_path() {
let temp_dir = tempfile::tempdir().unwrap();

View File

@@ -1,7 +1,5 @@
#![allow(non_snake_case)]
mod utils;
use std::path::PathBuf;
use nix_js::context::Context;
@@ -9,7 +7,7 @@ use nix_js::error::Source;
use nix_js::value::Value;
fn get_lang_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/lang")
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/tests/lang")
}
fn eval_file(name: &str) -> Result<(Value, Source), String> {
@@ -195,7 +193,6 @@ eval_okay_test!(partition);
eval_okay_test!(path);
eval_okay_test!(pathexists);
eval_okay_test!(
#[ignore = "rnix 0.13 regression: /${foo}-/*...*/ fails to parse"]
path_string_interpolation,
|| {
unsafe {

Some files were not shown because too many files have changed in this diff Show More