chore: tidy

This commit is contained in:
2026-01-24 02:41:18 +08:00
parent e58ebbe408
commit f46ee9d48f
13 changed files with 31 additions and 27 deletions

View File

@@ -31,6 +31,7 @@ export const hasAttr =
(set: NixValue): boolean => (set: NixValue): boolean =>
Object.hasOwn(forceAttrs(set), forceStringValue(s)); Object.hasOwn(forceAttrs(set), forceStringValue(s));
let counter = 0;
export const mapAttrs = export const mapAttrs =
(f: NixValue) => (f: NixValue) =>
(attrs: NixValue): NixAttrs => { (attrs: NixValue): NixAttrs => {
@@ -38,7 +39,8 @@ export const mapAttrs =
const forcedF = forceFunction(f); const forcedF = forceFunction(f);
const newAttrs: NixAttrs = {}; const newAttrs: NixAttrs = {};
for (const key in forcedAttrs) { for (const key in forcedAttrs) {
newAttrs[key] = createThunk(() => forceFunction(forcedF(key))(forcedAttrs[key])); newAttrs[key] = createThunk(() => forceFunction(forcedF(key))(forcedAttrs[key]), `created by mapAttrs (${counter})`);
counter += 1;
} }
return newAttrs; return newAttrs;
}; };

View File

@@ -249,11 +249,11 @@ export const builtins: any = {
tryEval: mkPrimop(misc.tryEval, "tryEval", 1), tryEval: mkPrimop(misc.tryEval, "tryEval", 1),
zipAttrsWith: mkPrimop(misc.zipAttrsWith, "zipAttrsWith", 2), zipAttrsWith: mkPrimop(misc.zipAttrsWith, "zipAttrsWith", 2),
builtins: createThunk(() => builtins), builtins: createThunk(() => builtins, "builtins"),
currentSystem: createThunk(() => { currentSystem: createThunk(() => {
return "x86_64-linux"; return "x86_64-linux";
}), }, "currentSystem"),
currentTime: createThunk(() => Date.now()), currentTime: createThunk(() => Date.now(), "currentTime"),
false: false, false: false,
true: true, true: true,

View File

@@ -7,7 +7,7 @@ import { CatchableError } from "../types";
import type { NixAttrs, NixBool, NixStrictValue, NixValue } from "../types"; import type { NixAttrs, NixBool, NixStrictValue, NixValue } from "../types";
import { forceList, forceAttrs, forceFunction, forceStringValue, forceString } from "../type-assert"; import { forceList, forceAttrs, forceFunction, forceStringValue, forceString } from "../type-assert";
import * as context from "./context"; import * as context from "./context";
import { compareValues, op } from "../operators"; import { compareValues } from "../operators";
import { isBool, isFloat, isInt, isList, isString, typeOf } from "./type-check"; import { isBool, isFloat, isInt, isList, isString, typeOf } from "./type-check";
import { OrderedSet } from "js-sdsl"; import { OrderedSet } from "js-sdsl";
import { import {
@@ -15,13 +15,13 @@ import {
getStringValue, getStringValue,
getStringContext, getStringContext,
mkStringWithContext, mkStringWithContext,
mergeContexts,
} from "../string-context"; } from "../string-context";
export const addErrorContext = export const addErrorContext =
(e1: NixValue) => (e1: NixValue) =>
(e2: NixValue): never => { (e2: NixValue): NixValue => {
throw new Error("Not implemented: addErrorContext"); console.log("[WARNING]: addErrorContext not implemented");
return e2;
}; };
export const appendContext = context.appendContext; export const appendContext = context.appendContext;

View File

@@ -62,11 +62,16 @@ export class NixArgs {
} }
} }
} }
export const mkFunction = (f: (arg: NixValue) => NixValue, required: string[], optional: string[], ellipsis: boolean): NixFunction => { export const mkFunction = (
f: (arg: NixValue) => NixValue,
required: string[],
optional: string[],
ellipsis: boolean,
): NixFunction => {
const func = f as NixFunction; const func = f as NixFunction;
func.args = new NixArgs(required, optional, ellipsis); func.args = new NixArgs(required, optional, ellipsis);
return func return func;
} };
/** /**
* Interface for lazy thunk values * Interface for lazy thunk values

View File

@@ -47,9 +47,6 @@ mod private {
fn compile_code(&mut self, source: Source) -> Result<String> { fn compile_code(&mut self, source: Source) -> Result<String> {
self.as_mut().compile_code(source) self.as_mut().compile_code(source)
} }
fn get_current_source(&self) -> Source {
self.as_ref().get_current_source()
}
fn get_source(&self, id: usize) -> Source { fn get_source(&self, id: usize) -> Source {
self.as_ref().get_source(id) self.as_ref().get_source(id)
} }

View File

@@ -1,11 +1,12 @@
#![allow(unused_assignments)]
use std::path::{Path, PathBuf};
use std::sync::Arc;
use miette::{Diagnostic, NamedSource, SourceSpan}; use miette::{Diagnostic, NamedSource, SourceSpan};
use std::{
path::{Path, PathBuf},
sync::Arc,
};
use thiserror::Error; use thiserror::Error;
use crate::{context::Ctx, runtime::RuntimeContext}; use crate::runtime::RuntimeContext;
pub type Result<T> = core::result::Result<T, Box<Error>>; pub type Result<T> = core::result::Result<T, Box<Error>>;

View File

@@ -1,3 +1,5 @@
#![allow(dead_code)]
use rusqlite::{Connection, OptionalExtension, params}; use rusqlite::{Connection, OptionalExtension, params};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;

View File

@@ -1,5 +1,5 @@
use derive_more::{IsVariant, TryUnwrap, Unwrap}; use derive_more::{IsVariant, TryUnwrap, Unwrap};
use hashbrown::{HashMap, HashSet}; use hashbrown::HashMap;
use rnix::{TextRange, ast}; use rnix::{TextRange, ast};
use string_interner::symbol::SymbolU32; use string_interner::symbol::SymbolU32;

View File

@@ -401,7 +401,6 @@ impl<Ctx: DowngradeContext> Downgrade<Ctx> for ast::Lambda {
pat_entries, pat_entries,
alias, alias,
arg, arg,
ellipsis,
ctx, ctx,
|ctx, _| self.body().unwrap().downgrade(ctx), |ctx, _| self.body().unwrap().downgrade(ctx),
)?; )?;

View File

@@ -1,3 +1,5 @@
#![allow(unused)]
use rnix::TextRange; use rnix::TextRange;
pub fn merge_spans(spans: impl IntoIterator<Item = TextRange>) -> TextRange { pub fn merge_spans(spans: impl IntoIterator<Item = TextRange>) -> TextRange {
@@ -11,10 +13,6 @@ pub fn merge_spans(spans: impl IntoIterator<Item = TextRange>) -> TextRange {
}) })
} }
pub fn point_span() -> TextRange {
TextRange::new(0.into(), 0.into())
}
pub fn synthetic_span() -> TextRange { pub fn synthetic_span() -> TextRange {
TextRange::new(0.into(), 0.into()) TextRange::new(0.into(), 0.into())
} }

View File

@@ -225,7 +225,6 @@ pub fn downgrade_pattern_bindings<Ctx>(
pat_entries: impl Iterator<Item = ast::PatEntry>, pat_entries: impl Iterator<Item = ast::PatEntry>,
alias: Option<SymId>, alias: Option<SymId>,
arg: ExprId, arg: ExprId,
has_ellipsis: bool,
ctx: &mut Ctx, ctx: &mut Ctx,
body_fn: impl FnOnce(&mut Ctx, &[SymId]) -> Result<ExprId>, body_fn: impl FnOnce(&mut Ctx, &[SymId]) -> Result<ExprId>,
) -> Result<PatternBindings> ) -> Result<PatternBindings>

View File

@@ -18,7 +18,6 @@ pub(crate) trait RuntimeContext: 'static {
fn get_current_dir(&self) -> &Path; fn get_current_dir(&self) -> &Path;
fn add_source(&mut self, path: Source); fn add_source(&mut self, path: Source);
fn compile_code(&mut self, source: Source) -> Result<String>; fn compile_code(&mut self, source: Source) -> Result<String>;
fn get_current_source(&self) -> Source;
fn get_source(&self, id: usize) -> Source; fn get_source(&self, id: usize) -> Source;
} }

View File

@@ -1,3 +1,5 @@
#![allow(dead_code)]
mod config; mod config;
mod error; mod error;
mod validation; mod validation;