feat: TODO

This commit is contained in:
2025-08-28 18:18:35 +08:00
parent 2fbd2a26a9
commit f7131079e5
26 changed files with 580 additions and 580 deletions

View File

@@ -27,6 +27,7 @@ impl ExprId {
/// Returns the raw `usize` index.
///
/// # Safety
///
/// The caller is responsible for using this index correctly and not causing out-of-bounds access.
#[inline(always)]
pub unsafe fn raw(self) -> usize {
@@ -36,6 +37,7 @@ impl ExprId {
/// Creates an `ExprId` from a raw `usize` index.
///
/// # Safety
///
/// The caller must ensure that the provided index is valid for the expression table.
#[inline(always)]
pub unsafe fn from_raw(id: usize) -> Self {
@@ -43,6 +45,33 @@ impl ExprId {
}
}
/// A type-safe wrapper for an index into an symbol table.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SymId(usize);
impl SymId {
/// Returns the raw `usize` index.
///
/// # Safety
///
/// The caller is responsible for using this index correctly and not causing out-of-bounds access.
#[inline(always)]
pub unsafe fn raw(self) -> usize {
self.0
}
/// Creates an `SymId` from a raw `usize` index.
///
/// # Safety
///
/// The caller must ensure that the provided index is valid for the symbol table.
#[inline(always)]
pub unsafe fn from_raw(id: usize) -> Self {
Self(id)
}
}
/// A type-safe wrapper for an index into a primop (builtin function) table.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -52,6 +81,7 @@ impl PrimOpId {
/// Returns the raw `usize` index.
///
/// # Safety
///
/// The caller is responsible for using this index correctly.
#[inline(always)]
pub unsafe fn raw(self) -> usize {
@@ -61,6 +91,7 @@ impl PrimOpId {
/// Creates a `PrimOpId` from a raw `usize` index.
///
/// # Safety
///
/// The caller must ensure that the provided index is valid.
#[inline(always)]
pub unsafe fn from_raw(id: usize) -> Self {
@@ -77,6 +108,7 @@ impl StackIdx {
/// Returns the raw `usize` index.
///
/// # Safety
///
/// The caller is responsible for using this index correctly.
#[inline(always)]
pub unsafe fn raw(self) -> usize {
@@ -86,6 +118,7 @@ impl StackIdx {
/// Creates an `StackIdx` from a raw `usize` index.
///
/// # Safety
///
/// The caller must ensure that the provided index is valid.
#[inline(always)]
pub unsafe fn from_raw(idx: usize) -> Self {
@@ -100,7 +133,7 @@ pub struct Arg;
#[derive(Debug, Default)]
pub struct AttrSet {
/// Statically known attributes (key is a string).
pub stcs: HashMap<String, ExprId>,
pub stcs: HashMap<SymId, ExprId>,
/// Dynamically computed attributes, where both the key and value are expressions.
pub dyns: Vec<(ExprId, ExprId)>,
}
@@ -113,7 +146,7 @@ pub enum Attr {
Dynamic(ExprId),
/// A static attribute key.
/// Example: `attrs.key`
Str(String),
Str(SymId),
}
/// Represents a Nix list.
@@ -246,6 +279,8 @@ pub struct Func {
pub body: ExprId,
/// The parameter specification for the function.
pub param: Param,
pub arg: ExprId,
}
/// Describes the parameters of a function.
@@ -253,12 +288,12 @@ pub struct Func {
pub struct Param {
/// The name of the argument if it's a simple identifier (e.g., `x: ...`).
/// Also used for the alias in a pattern (e.g., `args @ { ... }`).
pub ident: Option<String>,
pub ident: Option<SymId>,
/// The set of required parameter names for a pattern-matching function.
pub required: Option<Vec<String>>,
pub required: Option<Vec<SymId>>,
/// The set of all allowed parameter names for a non-ellipsis pattern-matching function.
/// If `None`, any attribute is allowed (ellipsis `...` is present).
pub allowed: Option<HashSet<String>>,
pub allowed: Option<HashSet<SymId>>,
}
/// Represents a function call.
@@ -315,7 +350,7 @@ pub struct Str {
/// Represents a variable lookup by its name.
#[derive(Debug)]
pub struct Var {
pub sym: String,
pub sym: SymId,
}
/// Represents a path literal.