diff --git a/nix-js/src/context.rs b/nix-js/src/context.rs index 7d67c7e..10b98cb 100644 --- a/nix-js/src/context.rs +++ b/nix-js/src/context.rs @@ -10,7 +10,7 @@ use crate::codegen::{CodegenContext, compile}; use crate::error::{Error, Result, Source}; use crate::ir::{ Arg, ArgId, Bool, Builtin, Downgrade as _, DowngradeContext, ExprId, Ir, Null, SymId, Thunk, - ToIr as _, synthetic_span, + ToIr as _, }; use crate::runtime::{Runtime, RuntimeContext}; use crate::store::{Store, StoreBackend, StoreConfig}; @@ -79,7 +79,7 @@ impl Ctx { irs.push( Builtins { - span: synthetic_span(), + span: rnix::TextRange::default(), } .to_ir(), ); @@ -114,7 +114,7 @@ impl Ctx { "true", Bool { inner: true, - span: synthetic_span(), + span: rnix::TextRange::default(), } .to_ir(), ), @@ -122,14 +122,14 @@ impl Ctx { "false", Bool { inner: false, - span: synthetic_span(), + span: rnix::TextRange::default(), } .to_ir(), ), ( "null", Null { - span: synthetic_span(), + span: rnix::TextRange::default(), } .to_ir(), ), @@ -141,7 +141,7 @@ impl Ctx { irs.push( Builtin { inner: name_sym, - span: synthetic_span(), + span: rnix::TextRange::default(), } .to_ir(), ); @@ -394,7 +394,7 @@ impl DowngradeContext for DowngradeCtx<'_> { use crate::ir::{Attr, Select}; let select = Select { expr: namespace, - attrpath: vec![Attr::Str(sym, synthetic_span())], + attrpath: vec![Attr::Str(sym, rnix::TextRange::default())], default: result, // Link to outer With or None span, }; @@ -422,7 +422,7 @@ impl DowngradeContext for DowngradeCtx<'_> { fn reserve_slots(&mut self, slots: usize) -> impl Iterator + Clone + use<> { let start = self.ctx.irs.len() + self.irs.len(); let range = (start..start + slots).map(ExprId); - let span = synthetic_span(); + let span = rnix::TextRange::default(); // Fill reserved slots with placeholder value self.irs.extend( range diff --git a/nix-js/src/ir.rs b/nix-js/src/ir.rs index 4ba0209..ba9e08d 100644 --- a/nix-js/src/ir.rs +++ b/nix-js/src/ir.rs @@ -7,13 +7,11 @@ use crate::error::{Result, Source}; use nix_js_macros::ir; mod downgrade; -mod span_utils; mod utils; use utils::*; pub use downgrade::Downgrade; -pub(crate) use span_utils::*; pub trait DowngradeContext { fn downgrade(self, expr: rnix::ast::Expr) -> Result; diff --git a/nix-js/src/ir/downgrade.rs b/nix-js/src/ir/downgrade.rs index 3d357f7..6301305 100644 --- a/nix-js/src/ir/downgrade.rs +++ b/nix-js/src/ir/downgrade.rs @@ -331,8 +331,8 @@ impl Downgrade for ast::LegacyLet { }; for sym in binding_keys { - let expr = ctx.lookup(*sym, synthetic_span())?; - attrs.stcs.insert(*sym, (expr, synthetic_span())); + let expr = ctx.lookup(*sym, rnix::TextRange::default())?; + attrs.stcs.insert(*sym, (expr, rnix::TextRange::default())); } Ok(ctx.new_expr(attrs.to_ir())) @@ -341,7 +341,7 @@ impl Downgrade for ast::LegacyLet { let body_sym = ctx.new_sym("body".to_string()); let select = Select { expr: attrset_expr, - attrpath: vec![Attr::Str(body_sym, synthetic_span())], + attrpath: vec![Attr::Str(body_sym, rnix::TextRange::default())], default: None, span, }; diff --git a/nix-js/src/ir/span_utils.rs b/nix-js/src/ir/span_utils.rs deleted file mode 100644 index 4442faa..0000000 --- a/nix-js/src/ir/span_utils.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![allow(unused)] - -use rnix::TextRange; - -pub fn merge_spans(spans: impl IntoIterator) -> TextRange { - let mut spans = spans.into_iter(); - let first = spans.next().unwrap_or_else(synthetic_span); - - spans.fold(first, |acc, span| { - let start = acc.start().min(span.start()); - let end = acc.end().max(span.end()); - TextRange::new(start, end) - }) -} - -pub fn synthetic_span() -> TextRange { - TextRange::new(0.into(), 0.into()) -} diff --git a/nix-js/src/ir/utils.rs b/nix-js/src/ir/utils.rs index 938e592..a149e43 100644 --- a/nix-js/src/ir/utils.rs +++ b/nix-js/src/ir/utils.rs @@ -553,7 +553,7 @@ where .collect(); for &slot in &slots { - let span = synthetic_span(); + let span = rnix::TextRange::default(); ctx.replace_ir(slot, Thunk { inner: slot, span }.to_ir()); } @@ -635,8 +635,8 @@ where }; for sym in binding_keys { - let expr = ctx.lookup(*sym, synthetic_span())?; - attrs.stcs.insert(*sym, (expr, synthetic_span())); + let expr = ctx.lookup(*sym, rnix::TextRange::default())?; + attrs.stcs.insert(*sym, (expr, rnix::TextRange::default())); } Ok(ctx.new_expr(attrs.to_ir())) @@ -671,7 +671,7 @@ where .collect(); for &slot in &slots { - let slot_span = synthetic_span(); + let slot_span = rnix::TextRange::default(); ctx.replace_ir( slot, Thunk {