git.delta.rocks / jrsonnet / refs/commits / 480843191a79

difftreelog

feat DestructRest in object destructuring

prkunoywYaroslav Bolyukin2026-04-01parent: #0afd461.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth
107 }107 }
108 #[cfg(feature = "exp-destruct")]108 #[cfg(feature = "exp-destruct")]
109 Destruct::Object { fields, rest } => {109 Destruct::Object { fields, rest } => {
110 use crate::ObjValueBuilder;
111 use jrsonnet_ir::DestructRest;
112 use rustc_hash::FxHashSet;
113
114 let captured_fields: FxHashSet<_> = fields.iter().map(|f| f.0.clone()).collect();
110 let field_names: Vec<_> = fields115 let field_names: Vec<_> = fields
111 .iter()116 .iter()
112 .map(|f| (f.0.clone(), f.2.is_some()))117 .map(|f| (f.0.clone(), f.2.is_some()))
131 Ok(obj)136 Ok(obj)
132 });137 });
138
139 match rest {
140 Some(DestructRest::Keep(v)) => {
141 let full = full.clone();
142 destruct(
143 &Destruct::Full(v.clone()),
144 Thunk!(move || {
145 let full = full.evaluate()?;
146 let mut builder = ObjValueBuilder::new();
147 builder
148 .reserve_cores(1)
149 .extend_with_core(full.as_standalone());
150 builder.with_fields_omitted(captured_fields);
151 Ok(Val::Obj(builder.build()))
152 }),
153 fctx.clone(),
154 new_bindings,
155 )?;
156 }
157 Some(DestructRest::Drop) | None => {}
158 }
133159
134 for (field, d, default) in fields {160 for (field, d, default) in fields {
135 let default = default.clone().map(|e| (fctx.clone(), e));161 let default = default.clone().map(|e| (fctx.clone(), e));
modifiedcrates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth
158pub type EnumFieldsHandler<'a> =158pub type EnumFieldsHandler<'a> =
159 dyn FnMut(SuperDepth, FieldIndex, IStr, EnumFields) -> ControlFlow<()> + 'a;159 dyn FnMut(SuperDepth, FieldIndex, IStr, EnumFields) -> ControlFlow<()> + 'a;
160160
161#[derive(Debug)]
161pub enum EnumFields {162pub enum EnumFields {
162 Normal(Visibility),163 Normal(Visibility),
163 Omit(Skip),164 Omit(Skip),
289}290}
290291
291#[derive(Trace, Debug)]292#[derive(Trace, Debug)]
292struct StandaloneSuperCore {293pub(crate) struct StandaloneSuperCore {
293 sup: CoreIdx,294 sup: CoreIdx,
294 this: ObjValue,295 this: ObjValue,
295}296}
791 key,792 key,
792 })793 })
793 }794 }
795 pub(crate) fn as_standalone(&self) -> StandaloneSuperCore {
796 StandaloneSuperCore {
797 sup: CoreIdx {
798 idx: self.0.cores.len(),
799 },
800 this: self.clone(),
801 }
802 }
794 pub fn ptr_eq(a: &Self, b: &Self) -> bool {803 pub fn ptr_eq(a: &Self, b: &Self) -> bool {
795 Cc::ptr_eq(&a.0, &b.0)804 Cc::ptr_eq(&a.0, &b.0)
796 }805 }