difftreelog
perf static object shapes
in: master
29 files changed
crates/jrsonnet-evaluator/src/analyze.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/analyze.rs
+++ b/crates/jrsonnet-evaluator/src/analyze.rs
@@ -21,16 +21,18 @@
use jrsonnet_interner::IStr;
use jrsonnet_ir::{
ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec, Destruct, Expr,
- ExprParams, FieldName, ForSpecData, IfElse, IfSpecData, ImportKind, LiteralType, NumValue,
- ObjBody, ObjComp, ObjMembers, Slice, SliceDesc, Span, Spanned, UnaryOpType, Visibility,
+ ExprParams, FieldName, ForSpecData, IdentityKind, IfElse, IfSpecData, ImportKind, ObjBody,
+ ObjComp, ObjMembers, Slice, SliceDesc, Span, Spanned, TrivialVal, UnaryOpType, Visibility,
function::FunctionSignature,
};
-use rustc_hash::FxHashMap;
+use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::SmallVec;
use crate::{
arr::arridx,
error::{format_found, suggest_names},
+ gc::WithCapacityExt as _,
+ obj::{ObjFieldFlags, ObjShape, ShapeField, ordering::FieldIndex},
};
#[derive(Debug, Clone, Copy)]
@@ -329,6 +331,7 @@
#[derive(Debug, Acyclic)]
pub enum LObjBody {
MemberList(LObjMembers),
+ StaticMembers(Box<LObjStaticMembers>),
ObjComp(Box<LObjComp>),
}
@@ -349,6 +352,20 @@
}
#[derive(Debug, Acyclic)]
+pub struct LObjStaticMembers {
+ pub frame_shape: ClosureShape,
+ pub this: Option<LocalSlot>,
+ pub set_dollar: bool,
+ pub uses_super: bool,
+
+ pub locals: Rc<Vec<LBind>>,
+ pub asserts: Option<Rc<LObjAsserts>>,
+
+ pub shape: Rc<ObjShape>,
+ pub bindings: Vec<Rc<(ClosureShape, LExpr)>>,
+}
+
+#[derive(Debug, Acyclic)]
pub struct LObjComp {
pub frame_shape: Rc<ClosureShape>,
pub this: Option<LocalSlot>,
@@ -1336,7 +1353,7 @@
taint: &mut AnalysisResult,
) -> LExpr {
if let Expr::Function(span, params, body) = expr {
- return analyze_function(Some(name), &span, ¶ms, body, stack, taint);
+ return analyze_function(Some(name), span, params, body, stack, taint);
}
analyze(expr, stack, taint)
}
@@ -1552,7 +1569,7 @@
BindSpec::Field {
value: Expr::Function(span, params, value),
into: Destruct::Full(name),
- } => analyze_function(Some(name.value.clone()), &span, params, value, stack, taint),
+ } => analyze_function(Some(name.value.clone()), span, params, value, stack, taint),
BindSpec::Field { value, .. } => analyze(value, stack, taint),
BindSpec::Function {
params,
@@ -1694,12 +1711,69 @@
) -> LObjBody {
match obj {
ObjBody::MemberList(members) => {
- LObjBody::MemberList(analyze_obj_members(members, stack, taint))
+ let lowered = analyze_obj_members(members, stack, taint);
+ match try_lower_static(lowered) {
+ Ok(static_members) => LObjBody::StaticMembers(Box::new(static_members)),
+ Err(member_list) => LObjBody::MemberList(member_list),
+ }
}
ObjBody::ObjComp(comp) => LObjBody::ObjComp(Box::new(analyze_obj_comp(comp, stack, taint))),
}
}
+fn try_lower_static(members: LObjMembers) -> Result<LObjStaticMembers, LObjMembers> {
+ let mut seen: FxHashSet<IStr> = FxHashSet::with_capacity(members.fields.len());
+ for f in &members.fields {
+ match &f.name {
+ LFieldName::Fixed(name) => {
+ if !seen.insert(name.clone()) {
+ return Err(members);
+ }
+ }
+ LFieldName::Dyn(_) => return Err(members),
+ }
+ }
+
+ let LObjMembers {
+ frame_shape,
+ this,
+ set_dollar,
+ uses_super,
+ locals,
+ asserts,
+ fields,
+ } = members;
+
+ let mut shape_fields = Vec::with_capacity(fields.len());
+ let mut bindings = Vec::with_capacity(fields.len());
+ let mut next_index = FieldIndex::default();
+ for f in fields {
+ let LFieldName::Fixed(name) = f.name else {
+ unreachable!("checked above");
+ };
+ let index = next_index;
+ next_index = next_index.next();
+ shape_fields.push(ShapeField {
+ name,
+ flags: ObjFieldFlags::new(f.plus, f.visibility),
+ location: None,
+ index,
+ });
+ bindings.push(f.value);
+ }
+
+ Ok(LObjStaticMembers {
+ frame_shape,
+ this,
+ set_dollar,
+ uses_super,
+ locals,
+ asserts,
+ shape: Rc::new(ObjShape::new(shape_fields)),
+ bindings,
+ })
+}
+
fn analyze_obj_members(
members: &ObjMembers,
stack: &mut AnalysisStack,
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth1use std::rc::Rc;23use jrsonnet_gcmodule::{Cc, Trace};4use jrsonnet_interner::IStr;5use jrsonnet_ir::ImportKind;6use jrsonnet_types::ValType;78use self::{9 compspec::{evaluate_arr_comp, evaluate_obj_comp},10 destructure::evaluate_locals_unbound,11 operator::evaluate_binary_op_special,12};13use crate::{14 CcObjectAssertion, CcUnbound, Context, Error, MaybeUnbound, ObjValue, ObjValueBuilder,15 ObjectAssertion, Result, ResultExt as _, StaticShapeOopObject, SupThis, Unbound, Val,16 analyze::{17 ClosureShape, LArgsDesc, LAssertStmt, LExpr, LFieldMember, LFieldName, LFunction,18 LIndexPart, LObjAsserts, LObjBody, LObjMembers, LObjStaticMembers, LSlot,19 },20 arr::ArrValue,21 bail,22 error::{ErrorKind::*, suggest_object_fields},23 evaluate::{destructure::fill_letrec_binds, operator::evaluate_unary_op},24 function::{CallLocation, FuncDesc, FuncVal, prepared::PreparedFuncVal},25 in_frame,26 typed::{BoundedUsize, FromUntyped as _},27 val::{CachedUnbound, Thunk},28 with_state,29};3031pub mod compspec;32pub mod destructure;33pub mod operator;3435// This is the amount of bytes that need to be left on the stack before increasing the size.36// It must be at least as large as the stack required by any code that does not call37// `ensure_sufficient_stack`.38const RED_ZONE: usize = 100 * 1024;3940// Only the first stack that is pushed, grows exponentially (2^n * STACK_PER_RECURSION) from then41// on. This flag has performance relevant characteristics. Don't set it too high.42const STACK_PER_RECURSION: usize = 1024 * 1024;4344/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations45/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit46/// from this.47///48/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.49#[inline]50pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {51 stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)52}5354pub fn evaluate_trivial(expr: &LExpr) -> Option<Val> {55 if let LExpr::Trivial(tv) = expr {56 Some(tv.clone().into())57 } else {58 None59 }60}6162pub fn evaluate_method(ctx: Context, name: IStr, func: &Rc<LFunction>) -> Val {63 Val::Func(FuncVal::Normal(Cc::new(FuncDesc {64 name,65 body_captures: ctx.pack_captures_sup_this(&func.body_shape),66 func: func.clone(),67 })))68}6970pub fn evaluate_field_name(ctx: Context, field_name: &LFieldName) -> Result<Option<IStr>> {71 Ok(match field_name {72 LFieldName::Fixed(n) => Some(n.clone()),73 LFieldName::Dyn(expr) => in_frame(74 // TODO: Spanned<LFieldName>75 CallLocation::native(),76 || "evaluating field name".to_string(),77 || {78 let v = evaluate(ctx.clone(), expr)?;79 Ok(if matches!(v, Val::Null) {80 None81 } else {82 Some(IStr::from_untyped(v)?)83 })84 },85 )?,86 })87}8889pub fn evaluate_thunk(ctx: Context, expr: Rc<LExpr>, tailstrict: bool) -> Result<Thunk<Val>> {90 match &*expr {91 LExpr::Slot(LSlot::Local(i)) => return Ok(ctx.local(*i)),92 LExpr::Slot(LSlot::Capture(i)) => return Ok(ctx.capture(*i)),93 _ => {94 if let Some(v) = evaluate_trivial(&expr) {95 return Ok(Thunk::evaluated(v));96 }97 }98 }99 Ok(if tailstrict {100 Thunk::evaluated(evaluate(ctx, &expr)?)101 } else {102 Thunk!(move || { evaluate(ctx, &expr) })103 })104}105106mod names {107 use crate::names;108109 names! {110 anonymous: "anonymous",111 }112}113114#[allow(clippy::too_many_lines)]115pub fn evaluate(mut ctx: Context, mut expr: &LExpr) -> Result<Val> {116 loop {117 return Ok(match expr {118 LExpr::Trivial(tv) => tv.clone().into(),119 LExpr::Slot(slot) => ctx.slot(*slot).evaluate()?,120 LExpr::BadLocal(name) => panic!("unresolvable reference: {name}"),121 LExpr::ArrConst(rc) => Val::Arr(ArrValue::new(rc.clone())),122 LExpr::Arr { shape, items } => {123 let inner = Context::enter_using(&ctx, shape);124 'eager: {125 let mut out: Vec<Val> = Vec::with_capacity(items.len());126 for item in items.iter() {127 let Ok(r) = evaluate(inner.clone(), item) else {128 break 'eager;129 };130 out.push(r);131 }132 return Ok(Val::Arr(ArrValue::new(out)));133 }134 Val::Arr(ArrValue::expr(inner, items.clone()))135 }136 LExpr::UnaryOp(op, value) => {137 let value = evaluate(ctx, value)?;138 evaluate_unary_op(*op, &value)?139 }140 LExpr::BinaryOp { lhs, op, rhs } => evaluate_binary_op_special(ctx, lhs, *op, rhs)?,141 LExpr::LocalExpr(l) => {142 ctx = ctx143 .pack_captures_sup_this(&l.frame_shape)144 .enter(|fill, ctx| {145 fill_letrec_binds(fill, ctx, &l.binds);146 });147 expr = &l.body;148 continue;149 }150 LExpr::IfElse {151 cond,152 cond_then,153 cond_else,154 } => {155 let cond_val = evaluate(ctx.clone(), cond)?;156 let Val::Bool(b) = cond_val else {157 bail!(TypeMismatch(158 "if condition",159 vec![ValType::Bool],160 cond_val.value_type()161 ))162 };163 if b {164 expr = cond_then;165 continue;166 } else if let Some(e) = cond_else {167 expr = e;168 continue;169 }170 Val::Null171 }172 LExpr::Error(s, e) => in_frame(173 CallLocation::new(s),174 || "error statement".to_owned(),175 || bail!(RuntimeError(evaluate(ctx, e)?.to_string()?,)),176 )?,177 LExpr::AssertExpr { assert, rest } => {178 evaluate_assert(ctx.clone(), assert)?;179 expr = rest;180 continue;181 }182183 LExpr::Function(func) => evaluate_method(184 ctx,185 func.name.clone().unwrap_or_else(names::anonymous),186 func,187 ),188 LExpr::IdentityFunction => Val::Func(FuncVal::identity()),189 LExpr::Apply {190 applicable,191 args,192 tailstrict,193 } => evaluate_apply(194 ctx,195 applicable,196 args,197 CallLocation::new(&args.span),198 *tailstrict,199 )?,200 LExpr::Index { indexable, parts } => evaluate_index(ctx, indexable, parts)?,201 LExpr::Obj(body) => evaluate_obj_body(None, ctx, body)?,202 LExpr::ObjExtend(lhs, body) => {203 let lhs_val = evaluate(ctx.clone(), lhs)?;204 let Val::Obj(lhs_obj) = lhs_val else {205 bail!(TypeMismatch(206 "object extend lhs",207 vec![ValType::Obj],208 lhs_val.value_type(),209 ))210 };211 evaluate_obj_body(Some(lhs_obj), ctx, body)?212 }213 LExpr::ArrComp(comp) => evaluate_arr_comp(ctx, comp)?,214 LExpr::Slice(slice) => {215 let val = evaluate(ctx.clone(), &slice.value)?;216 let indexable = val.into_indexable()?;217 let start = slice218 .start219 .as_ref()220 .map(|e| evaluate(ctx.clone(), e))221 .transpose()?222 .map(|v| -> Result<i32> {223 i32::from_untyped(v).description("slice start value")224 })225 .transpose()?;226 let end = slice227 .end228 .as_ref()229 .map(|e| evaluate(ctx.clone(), e))230 .transpose()?231 .map(|v| -> Result<i32> { i32::from_untyped(v).description("slice end value") })232 .transpose()?;233 let step = slice234 .step235 .as_ref()236 .map(|e| evaluate(ctx, e))237 .transpose()?238 .map(|v| -> Result<BoundedUsize<1, { i32::MAX as usize }>> {239 BoundedUsize::from_untyped(v).description("slice step value")240 })241 .transpose()?;242 Val::from(indexable.slice32(start, end, step)?)243 }244 LExpr::Super => Val::Obj(ctx.try_sup_this()?.standalone_super().ok_or(NoSuperFound)?),245 LExpr::Import {246 kind,247 kind_span,248 path,249 } => with_state(|state| {250 let resolved = state.resolve_from(kind_span.0.source_path(), &path.clone())?;251 Ok::<_, Error>(match kind.value {252 ImportKind::Normal => in_frame(253 CallLocation::new(&kind.span),254 || "import".to_string(),255 || state.import_resolved(resolved),256 )?,257 ImportKind::Str => Val::string(state.import_resolved_str(resolved)?),258 ImportKind::Bin => Val::arr(state.import_resolved_bin(resolved)?),259 })260 })?,261 });262 }263}264265fn evaluate_apply(266 ctx: Context,267 applicable: &LExpr,268 args: &LArgsDesc,269 loc: CallLocation<'_>,270 tailstrict: bool,271) -> Result<Val> {272 let func_val = evaluate(ctx.clone(), applicable)?;273 let Val::Func(func) = func_val else {274 bail!(OnlyFunctionsCanBeCalledGot(func_val.value_type()))275 };276277 if func.is_identity() && args.names.is_empty() && args.unnamed.len() == 1 {278 return evaluate_thunk(ctx, args.unnamed[0].clone(), tailstrict)?.evaluate();279 }280281 let name = func.name();282283 if args.names.is_empty() && args.unnamed.len() == 1 && func.params().len() == 1 {284 use crate::function::prepared::PreparedCall;285 let prepared_inline = PreparedCall::empty();286 let arg = evaluate_thunk(ctx, args.unnamed[0].clone(), tailstrict)?;287 let arg_slice = std::slice::from_ref(&arg);288 return in_frame(289 loc,290 || format!("function <{name}> call"),291 || {292 func.evaluate_prepared(293 &prepared_inline,294 CallLocation::native(),295 arg_slice,296 &[],297 tailstrict,298 )299 },300 );301 }302303 let unnamed = args304 .unnamed305 .iter()306 .cloned()307 .map(|e| evaluate_thunk(ctx.clone(), e, tailstrict))308 .collect::<Result<Vec<_>>>()?;309310 // Fast path: positional-only multi-arg call fully covering the311 // params, no defaults.312 if args.names.is_empty() && unnamed.len() == func.params().len() {313 use crate::function::prepared::PreparedCall;314 let prepared_inline = PreparedCall::empty();315 return in_frame(316 loc,317 || format!("function <{name}> call"),318 || {319 func.evaluate_prepared(320 &prepared_inline,321 CallLocation::native(),322 &unnamed,323 &[],324 tailstrict,325 )326 },327 );328 }329330 let named = args331 .values332 .iter()333 .cloned()334 .map(|e| evaluate_thunk(ctx.clone(), e, tailstrict))335 .collect::<Result<Vec<_>>>()?;336 let prepare = PreparedFuncVal::new(func, unnamed.len(), &args.names)337 .with_description_src(loc, || format!("function <{name}> preparation"))?;338 in_frame(339 loc,340 || format!("function <{name}> call"),341 || prepare.call(CallLocation::native(), &unnamed, &named),342 )343}344345#[allow(clippy::too_many_lines)]346fn evaluate_index(ctx: Context, indexable: &LExpr, parts: &[LIndexPart]) -> Result<Val> {347 let mut parts = parts.iter();348 let mut indexable = if matches!(indexable, LExpr::Super) {349 let part = parts.next().expect("at least part should exist");350 // sup_this existence check might also be skipped here for null-coalesce...351 // But I believe this might cause errors.352 let sup_this = ctx.try_sup_this()?;353354 if !sup_this.has_super() {355 #[cfg(feature = "exp-null-coaelse")]356 if part.null_coaelse {357 return Ok(Val::Null);358 }359 bail!(NoSuperFound);360 }361 let name = evaluate(ctx.clone(), &part.value)?;362363 let Val::Str(name) = name else {364 bail!(ValueIndexMustBeTypeGot(365 ValType::Obj,366 ValType::Str,367 name.value_type(),368 ))369 };370371 let name = name.into_flat();372 match sup_this373 .get_super(name.clone())374 .with_description_src(&part.span, || format!("super field <{name}> access"))?375 {376 Some(v) => v,377 #[cfg(feature = "exp-null-coaelse")]378 None if part.null_coaelse => return Ok(Val::Null),379 None => {380 let suggestions = suggest_object_fields(381 &sup_this.standalone_super().expect("super exists"),382 name.clone(),383 );384 bail!(NoSuchField(name, suggestions))385 }386 }387 } else {388 evaluate(ctx.clone(), indexable)?389 };390391 for part in parts {392 let ctx = ctx.clone();393 let loc = CallLocation::new(&part.span);394 let value = indexable;395 let key_val = evaluate(ctx, &part.value)?;396 indexable = match (&value, &key_val) {397 (Val::Obj(obj), Val::Str(key)) => {398 let key = key.clone().into_flat();399 match obj400 .get(key.clone())401 .with_description_src(loc, || format!("field <{key}> access"))?402 {403 Some(v) => v,404 #[cfg(feature = "exp-null-coaelse")]405 None if part.null_coaelse => return Ok(Val::Null),406 None => {407 return Err(Error::from(NoSuchField(408 key.clone(),409 suggest_object_fields(obj, key.clone()),410 )))411 .with_description_src(loc, || format!("field <{key}> access"));412 }413 }414 }415 (Val::Arr(arr), Val::Num(idx)) => {416 let n = idx.get();417 if n.fract() > f64::EPSILON {418 bail!(FractionalIndex)419 }420 let len = arr.len32();421 if n < 0.0 || n > f64::from(len) {422 bail!(ArrayBoundsError(n, len));423 }424 #[expect(425 clippy::cast_possible_truncation,426 clippy::cast_sign_loss,427 reason = "n is checked range"428 )]429 let i = n as u32;430 arr.get32(i)431 .with_description_src(loc, || format!("element <{i}> access"))?432 .ok_or_else(|| ArrayBoundsError(n, len))?433 }434 (Val::Str(s), Val::Num(idx)) => {435 let n = idx.get();436 if n.fract() > f64::EPSILON {437 bail!(FractionalIndex)438 }439 #[expect(440 clippy::cast_possible_truncation,441 clippy::cast_sign_loss,442 reason = "n is checked positive, overflow will truncate as expected"443 )]444 let i = n as usize;445 let flat = s.clone().into_flat();446 #[allow(clippy::cast_possible_truncation, reason = "string is max 4g")]447 if n >= 0.0448 && n <= f64::from(u32::MAX)449 && let Some(char) = flat.chars().nth(i)450 {451 Val::string(char)452 } else {453 let len = flat.chars().count();454 bail!(StringBoundsError(n, len as u32))455 }456 }457 #[cfg(feature = "exp-null-coaelse")]458 (Val::Null, _) if part.null_coaelse => return Ok(Val::Null),459 _ => bail!(ValueIndexMustBeTypeGot(460 value.value_type(),461 ValType::Str,462 key_val.value_type()463 )),464 };465 }466 Ok(indexable)467}468469fn evaluate_obj_body(super_obj: Option<ObjValue>, ctx: Context, body: &LObjBody) -> Result<Val> {470 match body {471 LObjBody::MemberList(members) => evaluate_obj_members(super_obj, ctx, members),472 LObjBody::StaticMembers(members) => {473 Ok(evaluate_static_obj_members(super_obj, ctx, members))474 }475 LObjBody::ObjComp(comp) => evaluate_obj_comp(super_obj, ctx, comp),476 }477}478479pub fn evaluate_field_member_unbound<B: Unbound<Bound = Context> + Clone>(480 builder: &mut ObjValueBuilder,481 ctx: Context,482 uctx: B,483 field: &LFieldMember,484) -> Result<()> {485 #[derive(Trace)]486 struct UnboundValue<B: Trace> {487 uctx: B,488 value: Rc<(ClosureShape, LExpr)>,489 name: IStr,490 }491 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {492 type Bound = Val;493 fn bind(&self, sup_this: SupThis) -> Result<Val> {494 let a_ctx = self.uctx.bind(sup_this)?;495 let b_ctx = Context::enter_using(&a_ctx, &self.value.0);496 evaluate(b_ctx, &self.value.1)497 }498 }499500 let LFieldMember {501 name,502 plus,503 visibility,504 value,505 } = field;506 let Some(name) = evaluate_field_name(ctx, name)? else {507 return Ok(());508 };509510 builder511 .field(name.clone())512 .with_add(*plus)513 .with_visibility(*visibility)514 .bindable(UnboundValue {515 uctx,516 value: value.clone(),517 name,518 })519}520pub fn evaluate_field_member_static(521 builder: &mut ObjValueBuilder,522 field_ctx: Context,523 value_ctx: Context,524 field: &LFieldMember,525) -> Result<()> {526 let LFieldMember {527 name,528 plus,529 visibility,530 value,531 } = field;532 let Some(name) = evaluate_field_name(field_ctx, name)? else {533 return Ok(());534 };535536 let env = Context::enter_using(&value_ctx, &value.0);537 let value = value.clone();538 builder539 .field(name)540 .with_add(*plus)541 .with_visibility(*visibility)542 .try_thunk(Thunk!(move || evaluate(env, &value.1)))?;543 Ok(())544}545546fn evaluate_static_obj_members(547 super_obj: Option<ObjValue>,548 ctx: Context,549 members: &LObjStaticMembers,550) -> Val {551 #[derive(Trace)]552 struct UnboundField<B: Trace> {553 uctx: B,554 value: Rc<(ClosureShape, LExpr)>,555 name: IStr,556 }557 impl<B: Unbound<Bound = Context>> Unbound for UnboundField<B> {558 type Bound = Val;559 fn bind(&self, sup_this: SupThis) -> Result<Val> {560 let a_ctx = self.uctx.bind(sup_this)?;561 let b_ctx = Context::enter_using(&a_ctx, &self.value.0);562 evaluate(b_ctx, &self.value.1)563 }564 }565566 let needs_unbound = members.this.is_some() || members.uses_super;567568 let mut bindings: Vec<MaybeUnbound> = Vec::with_capacity(members.bindings.len());569570 let assertion = if needs_unbound {571 let uctx = CachedUnbound::new(evaluate_locals_unbound(572 &ctx,573 &members.frame_shape,574 members.this,575 members.locals.clone(),576 ));577 for (binding, field) in members.bindings.iter().zip(members.shape.fields()) {578 if let Some(v) = evaluate_trivial(&binding.1) {579 bindings.push(MaybeUnbound::Const(v));580 continue;581 }582 bindings.push(MaybeUnbound::Unbound(CcUnbound::new(UnboundField {583 uctx: uctx.clone(),584 value: binding.clone(),585 name: field.name.clone(),586 })));587 }588 members589 .asserts590 .as_ref()591 .map(|a| CcObjectAssertion::new(evaluate_object_assertions_unbound(uctx, a.clone())))592 } else {593 let a_ctx = ctx594 .pack_captures_sup_this(&members.frame_shape)595 .enter(|fill, ctx| {596 fill_letrec_binds(fill, ctx, &members.locals);597 });598 for binding in &members.bindings {599 if let Some(v) = evaluate_trivial(&binding.1) {600 bindings.push(MaybeUnbound::Const(v));601 continue;602 }603 let env = Context::enter_using(&a_ctx, &binding.0);604 let value = binding.clone();605 bindings.push(MaybeUnbound::Bound(Thunk!(move || evaluate(env, &value.1))));606 }607 members.asserts.as_ref().map(|a| {608 CcObjectAssertion::new(evaluate_object_assertions_static(a_ctx.clone(), a.clone()))609 })610 };611612 let mut builder = ObjValueBuilder::with_capacity(0);613 if let Some(sup) = super_obj {614 builder.with_super(sup);615 }616 builder.extend_with_core(StaticShapeOopObject::new(617 members.shape.clone(),618 bindings,619 assertion,620 ));621 Val::Obj(builder.build())622}623624fn evaluate_obj_members(625 super_obj: Option<ObjValue>,626 ctx: Context,627 members: &LObjMembers,628) -> Result<Val> {629 let mut builder = ObjValueBuilder::with_capacity(members.fields.len());630 if let Some(sup) = super_obj {631 builder.with_super(sup);632 }633634 let needs_unbound = members.this.is_some() || members.uses_super;635636 if needs_unbound {637 let uctx = CachedUnbound::new(evaluate_locals_unbound(638 &ctx,639 &members.frame_shape,640 members.this,641 members.locals.clone(),642 ));643 for field in &members.fields {644 evaluate_field_member_unbound(&mut builder, ctx.clone(), uctx.clone(), field)?;645 }646 if let Some(asserts_block) = &members.asserts {647 builder.assert(evaluate_object_assertions_unbound(648 uctx,649 asserts_block.clone(),650 ));651 }652 } else {653 let a_ctx = ctx654 .pack_captures_sup_this(&members.frame_shape)655 .enter(|fill, ctx| {656 fill_letrec_binds(fill, ctx, &members.locals);657 });658 for field in &members.fields {659 evaluate_field_member_static(&mut builder, ctx.clone(), a_ctx.clone(), field)?;660 }661 if let Some(asserts_block) = &members.asserts {662 builder.assert(evaluate_object_assertions_static(663 a_ctx,664 asserts_block.clone(),665 ));666 }667 }668669 Ok(Val::Obj(builder.build()))670}671672pub fn evaluate_assert(ctx: Context, assertion: &LAssertStmt) -> Result<()> {673 let LAssertStmt { cond, message } = assertion;674 let assertion_result = in_frame(675 CallLocation::new(&cond.span),676 || "assertion condition".to_owned(),677 || bool::from_untyped(evaluate(ctx.clone(), cond)?),678 )?;679 if !assertion_result {680 in_frame(681 CallLocation::new(&cond.span),682 || "assertion failure".to_owned(),683 || {684 if let Some(msg) = message {685 bail!(AssertionFailed(evaluate(ctx, msg)?.to_string()?));686 }687 bail!(AssertionFailed(Val::Null.to_string()?));688 },689 )?;690 }691 Ok(())692}693694fn evaluate_object_assertions_unbound<B: Unbound<Bound = Context>>(695 uctx: B,696 asserts: Rc<LObjAsserts>,697) -> impl ObjectAssertion {698 #[derive(Trace)]699 struct ObjectAssert<B: Trace> {700 uctx: B,701 asserts: Rc<LObjAsserts>,702 }703 impl<B: Unbound<Bound = Context>> ObjectAssertion for ObjectAssert<B> {704 fn run(&self, sup_this: SupThis) -> Result<()> {705 let a_ctx = self.uctx.bind(sup_this)?;706 let assert_env = Context::enter_using(&a_ctx, &self.asserts.shape);707 for assert in &self.asserts.asserts {708 evaluate_assert(assert_env.clone(), assert)?;709 }710 Ok(())711 }712 }713 ObjectAssert { uctx, asserts }714}715fn evaluate_object_assertions_static(716 a_ctx: Context,717 asserts: Rc<LObjAsserts>,718) -> impl ObjectAssertion {719 #[derive(Trace)]720 struct ObjectAssert {721 assert_env: Context,722 asserts: Rc<LObjAsserts>,723 }724 impl ObjectAssertion for ObjectAssert {725 fn run(&self, _sup_this: SupThis) -> Result<()> {726 for assert in &self.asserts.asserts {727 evaluate_assert(self.assert_env.clone(), assert)?;728 }729 Ok(())730 }731 }732 let assert_env = Context::enter_using(&a_ctx, &asserts.shape);733 ObjectAssert {734 assert_env,735 asserts,736 }737}crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -144,6 +144,7 @@
Unbound(CcUnbound<Val>),
/// Value is object-independent
Bound(Thunk<Val>),
+ Const(Val),
}
impl Debug for MaybeUnbound {
@@ -157,6 +158,7 @@
match self {
Self::Unbound(v) => v.0.bind(sup_this),
Self::Bound(v) => Ok(v.evaluate()?),
+ Self::Const(v) => Ok(v.clone()),
}
}
}
crates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj/mod.rs
+++ b/crates/jrsonnet-evaluator/src/obj/mod.rs
@@ -17,9 +17,11 @@
use rustc_hash::{FxHashMap, FxHashSet};
mod oop;
+mod static_shape;
pub use jrsonnet_ir::Visibility;
pub use oop::ObjValueBuilder;
+pub use static_shape::{ObjShape, ObjShapeBuilder, ShapeField, StaticShapeOopObject};
use crate::{
CcUnbound, MaybeUnbound, Result, Thunk, Unbound, Val,
@@ -99,7 +101,7 @@
#[derive(Clone, Copy, Acyclic)]
pub struct ObjFieldFlags(u8);
impl ObjFieldFlags {
- fn new(add: bool, visibility: Visibility) -> Self {
+ pub fn new(add: bool, visibility: Visibility) -> Self {
let mut v = 0;
if add {
v |= 1;
@@ -140,7 +142,7 @@
pub location: Option<Span>,
}
-cc_dyn!(CcObjectAssertion, ObjectAssertion);
+cc_dyn!(CcObjectAssertion, ObjectAssertion, pub fn new() {...});
pub trait ObjectAssertion: Trace {
fn run(&self, sup_this: SupThis) -> Result<()>;
}
@@ -203,6 +205,10 @@
fn field_visibility_core(&self, field: IStr) -> FieldVisibility;
fn run_assertions_core(&self, sup_this: SupThis) -> Result<()>;
+
+ fn has_assertion(&self) -> bool {
+ false
+ }
}
#[derive(Clone, Trace)]
@@ -1117,7 +1123,7 @@
pub struct ExtendBuilder<'v>(&'v mut ObjValue);
impl ObjMemberBuilder<ExtendBuilder<'_>> {
pub fn value(self, value: impl Into<Val>) {
- self.binding(MaybeUnbound::Bound(Thunk::evaluated(value.into())));
+ self.binding(MaybeUnbound::Const(value.into()));
}
pub fn bindable(self, bindable: impl Unbound<Bound = Val>) {
self.binding(MaybeUnbound::Unbound(CcUnbound::new(bindable)));
crates/jrsonnet-evaluator/src/obj/oop.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj/oop.rs
+++ b/crates/jrsonnet-evaluator/src/obj/oop.rs
@@ -113,6 +113,10 @@
}
Ok(())
}
+
+ fn has_assertion(&self) -> bool {
+ self.assertion.is_some()
+ }
}
#[allow(clippy::module_name_repetitions)]
@@ -177,6 +181,7 @@
pub fn extend_with_core(&mut self, core: impl ObjectCore) {
self.commit();
+ self.has_assertions |= core.has_assertion();
self.sup.push(CcObjectCore::new(core));
}
@@ -219,8 +224,7 @@
impl ObjMemberBuilder<ValueBuilder<'_>> {
/// Inserts value, replacing if it is already defined
pub fn value(self, value: impl Into<Val>) {
- let (receiver, name, idx, member) =
- self.build_member(MaybeUnbound::Bound(Thunk::evaluated(value.into())));
+ let (receiver, name, idx, member) = self.build_member(MaybeUnbound::Const(value.into()));
let entry = receiver.0.new.this_entries.entry(name);
entry.insert_entry((member, idx));
}
@@ -233,7 +237,7 @@
/// Tries to insert value, returns an error if it was already defined
pub fn try_value(self, value: impl Into<Val>) -> Result<()> {
- self.try_thunk(Thunk::evaluated(value.into()))
+ self.binding(MaybeUnbound::Const(value.into()))
}
pub fn try_thunk(self, value: impl Into<Thunk<Val>>) -> Result<()> {
self.binding(MaybeUnbound::Bound(value.into()))
crates/jrsonnet-evaluator/src/obj/static_shape.rsdiffbeforeafterboth--- /dev/null
+++ b/crates/jrsonnet-evaluator/src/obj/static_shape.rs
@@ -0,0 +1,213 @@
+use std::{fmt, ops::ControlFlow, rc::Rc};
+
+use jrsonnet_gcmodule::{Acyclic, Trace, TraceBox};
+use jrsonnet_interner::IStr;
+use jrsonnet_ir::Span;
+
+use super::{
+ CcObjectAssertion, EnumFields, EnumFieldsHandler, FieldVisibility, GetFor,
+ HasFieldIncludeHidden, ObjFieldFlags, ObjectCore, SupThis, Visibility,
+ ordering::{FieldIndex, SuperDepth},
+};
+use crate::{MaybeUnbound, Result};
+
+#[derive(Acyclic, Debug)]
+pub struct ShapeField {
+ pub name: IStr,
+ pub flags: ObjFieldFlags,
+ pub location: Option<Span>,
+ pub index: FieldIndex,
+}
+
+#[derive(Acyclic, Debug)]
+pub struct ObjShape {
+ fields: Vec<ShapeField>,
+}
+
+impl ObjShape {
+ #[must_use]
+ pub fn new(fields: Vec<ShapeField>) -> Self {
+ Self { fields }
+ }
+
+ #[inline]
+ pub fn fields(&self) -> &[ShapeField] {
+ &self.fields
+ }
+
+ #[inline]
+ #[must_use]
+ pub fn len(&self) -> usize {
+ self.fields.len()
+ }
+
+ #[inline]
+ #[must_use]
+ pub fn is_empty(&self) -> bool {
+ self.fields.is_empty()
+ }
+
+ #[inline]
+ pub fn find_index(&self, name: &IStr) -> Option<usize> {
+ self.fields.iter().position(|f| &f.name == name)
+ }
+}
+
+#[derive(Trace)]
+pub struct StaticShapeOopObject {
+ shape: Rc<ObjShape>,
+ bindings: TraceBox<[MaybeUnbound]>,
+ assertion: Option<CcObjectAssertion>,
+}
+
+impl fmt::Debug for StaticShapeOopObject {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("StaticShapeOopObject")
+ .field("shape", &self.shape)
+ .field("has_assertion", &self.assertion.is_some())
+ .finish_non_exhaustive()
+ }
+}
+
+impl StaticShapeOopObject {
+ pub fn new(
+ shape: Rc<ObjShape>,
+ bindings: Vec<MaybeUnbound>,
+ assertion: Option<CcObjectAssertion>,
+ ) -> Self {
+ debug_assert_eq!(
+ shape.fields.len(),
+ bindings.len(),
+ "shape arity must match bindings"
+ );
+ Self {
+ shape,
+ bindings: TraceBox(bindings.into_boxed_slice()),
+ assertion,
+ }
+ }
+
+ #[inline]
+ #[must_use]
+ pub const fn shape(&self) -> &Rc<ObjShape> {
+ &self.shape
+ }
+}
+
+impl ObjectCore for StaticShapeOopObject {
+ fn enum_fields_core(
+ &self,
+ super_depth: &mut SuperDepth,
+ handler: &mut EnumFieldsHandler<'_>,
+ ) -> bool {
+ for field in &self.shape.fields {
+ if matches!(
+ handler(
+ *super_depth,
+ field.index,
+ field.name.clone(),
+ EnumFields::Normal(field.flags.visibility()),
+ ),
+ ControlFlow::Break(())
+ ) {
+ return false;
+ }
+ }
+ true
+ }
+
+ fn has_field_include_hidden_core(&self, name: IStr) -> HasFieldIncludeHidden {
+ if self.shape.find_index(&name).is_some() {
+ HasFieldIncludeHidden::Exists
+ } else {
+ HasFieldIncludeHidden::NotFound
+ }
+ }
+
+ fn get_for_core(&self, key: IStr, sup_this: SupThis, omit_only: bool) -> Result<GetFor> {
+ if omit_only {
+ return Ok(GetFor::NotFound);
+ }
+ let Some(i) = self.shape.find_index(&key) else {
+ return Ok(GetFor::NotFound);
+ };
+ let field = &self.shape.fields[i];
+ let v = self.bindings[i].evaluate(sup_this)?;
+ Ok(if field.flags.add() {
+ GetFor::SuperPlus(v)
+ } else {
+ GetFor::Final(v)
+ })
+ }
+
+ fn field_visibility_core(&self, field: IStr) -> FieldVisibility {
+ self.shape
+ .find_index(&field)
+ .map_or(FieldVisibility::NotFound, |i| {
+ FieldVisibility::Found(self.shape.fields[i].flags.visibility())
+ })
+ }
+
+ fn run_assertions_core(&self, sup_this: SupThis) -> Result<()> {
+ if let Some(assertion) = &self.assertion {
+ assertion.0.run(sup_this)?;
+ }
+ Ok(())
+ }
+
+ fn has_assertion(&self) -> bool {
+ self.assertion.is_some()
+ }
+}
+
+pub struct ObjShapeBuilder {
+ fields: Vec<ShapeField>,
+ next_index: FieldIndex,
+}
+
+impl ObjShapeBuilder {
+ #[must_use]
+ pub fn new() -> Self {
+ Self {
+ fields: Vec::new(),
+ next_index: FieldIndex::default(),
+ }
+ }
+
+ #[must_use]
+ pub fn with_capacity(cap: usize) -> Self {
+ Self {
+ fields: Vec::with_capacity(cap),
+ next_index: FieldIndex::default(),
+ }
+ }
+
+ pub fn field(
+ &mut self,
+ name: impl Into<IStr>,
+ visibility: Visibility,
+ add: bool,
+ location: Option<Span>,
+ ) -> &mut Self {
+ let index = self.next_index;
+ self.next_index = self.next_index.next();
+ self.fields.push(ShapeField {
+ name: name.into(),
+ flags: ObjFieldFlags::new(add, visibility),
+ location,
+ index,
+ });
+ self
+ }
+
+ #[must_use]
+ pub fn build(self) -> ObjShape {
+ ObjShape::new(self.fields)
+ }
+}
+
+impl Default for ObjShapeBuilder {
+ fn default() -> Self {
+ Self::new()
+ }
+}
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@array_comp.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@array_comp.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@array_comp.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/array_comp.jsonnet
---
@@ -26,8 +27,10 @@
),
),
op: Mul,
- rhs: Num(
- 2.0,
+ rhs: Trivial(
+ Num(
+ 2.0,
+ ),
),
},
compspecs: [
@@ -41,12 +44,8 @@
0,
),
),
- over: Arr {
- shape: ClosureShape {
- captures: [],
- n_locals: 0,
- },
- items: [
+ over: ArrConst(
+ [
Num(
1.0,
),
@@ -57,7 +56,7 @@
3.0,
),
],
- },
+ ),
loop_invariant: true,
},
If(
@@ -70,8 +69,10 @@
),
),
op: Gt,
- rhs: Num(
- 1.0,
+ rhs: Trivial(
+ Num(
+ 1.0,
+ ),
),
},
),
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@dollar_deeply_nested.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@dollar_deeply_nested.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@dollar_deeply_nested.jsonnet.snap
@@ -20,8 +20,8 @@
--- diagnostics ---
--- lir ---
Obj(
- MemberList(
- LObjMembers {
+ StaticMembers(
+ LObjStaticMembers {
frame_shape: ClosureShape {
captures: [],
n_locals: 1,
@@ -35,74 +35,145 @@
uses_super: false,
locals: [],
asserts: None,
- fields: [
- LFieldMember {
- name: Fixed(
- "top",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
+ shape: ObjShape {
+ fields: [
+ ShapeField {
+ name: "top",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ShapeField {
+ name: "a",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
},
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Trivial(
Str(
"outer",
),
),
- },
- LFieldMember {
- name: Fixed(
- "a",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
- Obj(
- MemberList(
- LObjMembers {
- frame_shape: ClosureShape {
- captures: [
- Local(
- LocalSlot(
- 0,
- ),
+ ),
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Obj(
+ StaticMembers(
+ LObjStaticMembers {
+ frame_shape: ClosureShape {
+ captures: [
+ Local(
+ LocalSlot(
+ 0,
),
- ],
- n_locals: 1,
- },
- this: None,
- set_dollar: false,
- uses_super: false,
- locals: [],
- asserts: None,
+ ),
+ ],
+ n_locals: 1,
+ },
+ this: None,
+ set_dollar: false,
+ uses_super: false,
+ locals: [],
+ asserts: None,
+ shape: ObjShape {
fields: [
- LFieldMember {
- name: Fixed(
- "b",
+ ShapeField {
+ name: "b",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [
- Capture(
- CaptureSlot(
- 0,
+ },
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
+ captures: [
+ Capture(
+ CaptureSlot(
+ 0,
+ ),
+ ),
+ ],
+ n_locals: 0,
+ },
+ Obj(
+ StaticMembers(
+ LObjStaticMembers {
+ frame_shape: ClosureShape {
+ captures: [
+ Capture(
+ CaptureSlot(
+ 0,
+ ),
),
+ ],
+ n_locals: 1,
+ },
+ this: Some(
+ LocalSlot(
+ 0,
),
- ],
- n_locals: 0,
- },
- Obj(
- MemberList(
- LObjMembers {
- frame_shape: ClosureShape {
+ ),
+ set_dollar: false,
+ uses_super: false,
+ locals: [],
+ asserts: None,
+ shape: ObjShape {
+ fields: [
+ ShapeField {
+ name: "c",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ShapeField {
+ name: "d",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
captures: [
Capture(
CaptureSlot(
@@ -110,86 +181,51 @@
),
),
],
- n_locals: 1,
+ n_locals: 0,
},
- this: Some(
- LocalSlot(
- 0,
- ),
- ),
- set_dollar: false,
- uses_super: false,
- locals: [],
- asserts: None,
- fields: [
- LFieldMember {
- name: Fixed(
- "c",
+ Index {
+ indexable: Slot(
+ Capture(
+ CaptureSlot(
+ 0,
+ ),
),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [
- Capture(
- CaptureSlot(
- 0,
- ),
- ),
- ],
- n_locals: 0,
- },
- Index {
- indexable: Slot(
- Capture(
- CaptureSlot(
- 0,
- ),
- ),
+ ),
+ parts: [
+ LIndexPart {
+ span: virtual:<test>:45-48,
+ value: Trivial(
+ Str(
+ "top",
),
- parts: [
- LIndexPart {
- span: virtual:<test>:45-48,
- value: Str(
- "top",
- ),
- },
- ],
- },
- ),
- },
- LFieldMember {
- name: Fixed(
- "d",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
- Slot(
- Local(
- LocalSlot(
- 0,
- ),
- ),
),
+ },
+ ],
+ },
+ ),
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Slot(
+ Local(
+ LocalSlot(
+ 0,
),
- },
- ],
- },
- ),
- ),
+ ),
+ ),
+ ),
+ ],
+ },
),
- },
- ],
- },
- ),
+ ),
+ ),
+ ],
+ },
),
),
- },
+ ),
],
},
),
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@dollar_outside_object.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@dollar_outside_object.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@dollar_outside_object.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/dollar_outside_object.jsonnet
---
@@ -21,8 +22,10 @@
parts: [
LIndexPart {
span: virtual:<test>:2-3,
- value: Str(
- "a",
+ value: Trivial(
+ Str(
+ "a",
+ ),
),
},
],
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@function_def.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@function_def.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@function_def.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/function_def.jsonnet
---
@@ -108,11 +109,15 @@
),
args: LArgsDesc {
unnamed: [
- Num(
- 1.0,
+ Trivial(
+ Num(
+ 1.0,
+ ),
),
- Num(
- 2.0,
+ Trivial(
+ Num(
+ 2.0,
+ ),
),
],
names: [],
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@hoistable_local.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@hoistable_local.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@hoistable_local.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/hoistable_local.jsonnet
---
@@ -31,8 +32,10 @@
captures: [],
n_locals: 0,
},
- value: Num(
- 1.0,
+ value: Trivial(
+ Num(
+ 1.0,
+ ),
),
},
],
@@ -60,12 +63,16 @@
n_locals: 0,
},
value: BinaryOp {
- lhs: Num(
- 10.0,
+ lhs: Trivial(
+ Num(
+ 10.0,
+ ),
),
op: Add,
- rhs: Num(
- 20.0,
+ rhs: Trivial(
+ Num(
+ 20.0,
+ ),
),
},
},
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@ifelse.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@ifelse.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@ifelse.jsonnet.snap
@@ -1,7 +1,8 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
-input_file: crates/jrsonnet-evaluator/src/analyze_tests/ifelse.jsonnet
+input_file: crates/jrsonnet-evaluator/src/analysis_tests/ifelse.jsonnet
---
--- source ---
if true then 1 else 2
@@ -12,15 +13,21 @@
--- diagnostics ---
--- lir ---
IfElse {
- cond: Bool(
- true,
+ cond: Trivial(
+ Bool(
+ true,
+ ),
),
- cond_then: Num(
- 1.0,
+ cond_then: Trivial(
+ Num(
+ 1.0,
+ ),
),
cond_else: Some(
- Num(
- 2.0,
+ Trivial(
+ Num(
+ 2.0,
+ ),
),
),
}
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@literal.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@literal.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@literal.jsonnet.snap
@@ -1,7 +1,8 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
-input_file: crates/jrsonnet-evaluator/src/analyze_tests/literal.jsonnet
+input_file: crates/jrsonnet-evaluator/src/analysis_tests/literal.jsonnet
---
--- source ---
42
@@ -11,6 +12,8 @@
errored: false
--- diagnostics ---
--- lir ---
-Num(
- 42.0,
+Trivial(
+ Num(
+ 42.0,
+ ),
)
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@loop_invariant.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@loop_invariant.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@loop_invariant.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/loop_invariant.jsonnet
---
@@ -64,19 +65,25 @@
parts: [
LIndexPart {
span: virtual:<test>:21-26,
- value: Str(
- "range",
+ value: Trivial(
+ Str(
+ "range",
+ ),
),
},
],
},
args: LArgsDesc {
unnamed: [
- Num(
- 1.0,
+ Trivial(
+ Num(
+ 1.0,
+ ),
),
- Num(
- 1000.0,
+ Trivial(
+ Num(
+ 1000.0,
+ ),
),
],
names: [],
@@ -110,19 +117,25 @@
parts: [
LIndexPart {
span: virtual:<test>:49-54,
- value: Str(
- "range",
+ value: Trivial(
+ Str(
+ "range",
+ ),
),
},
],
},
args: LArgsDesc {
unnamed: [
- Num(
- 1.0,
+ Trivial(
+ Num(
+ 1.0,
+ ),
),
- Num(
- 1000.0,
+ Trivial(
+ Num(
+ 1000.0,
+ ),
),
],
names: [],
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@mutual_recursion.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@mutual_recursion.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@mutual_recursion.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/mutual_recursion.jsonnet
---
@@ -46,8 +47,10 @@
captures: [],
n_locals: 0,
},
- value: Num(
- 1.0,
+ value: Trivial(
+ Num(
+ 1.0,
+ ),
),
},
],
@@ -60,8 +63,10 @@
),
),
op: Add,
- rhs: Num(
- 2.0,
+ rhs: Trivial(
+ Num(
+ 2.0,
+ ),
),
},
},
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@nested_object_independent.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@nested_object_independent.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@nested_object_independent.jsonnet.snap
@@ -17,8 +17,8 @@
--- diagnostics ---
--- lir ---
Obj(
- MemberList(
- LObjMembers {
+ StaticMembers(
+ LObjStaticMembers {
frame_shape: ClosureShape {
captures: [],
n_locals: 1,
@@ -28,103 +28,133 @@
uses_super: false,
locals: [],
asserts: None,
- fields: [
- LFieldMember {
- name: Fixed(
- "a",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
+ shape: ObjShape {
+ fields: [
+ ShapeField {
+ name: "a",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
},
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ShapeField {
+ name: "b",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Trivial(
Num(
1.0,
),
),
- },
- LFieldMember {
- name: Fixed(
- "b",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
- Obj(
- MemberList(
- LObjMembers {
- frame_shape: ClosureShape {
- captures: [],
- n_locals: 1,
- },
- this: Some(
- LocalSlot(
- 0,
- ),
+ ),
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Obj(
+ StaticMembers(
+ LObjStaticMembers {
+ frame_shape: ClosureShape {
+ captures: [],
+ n_locals: 1,
+ },
+ this: Some(
+ LocalSlot(
+ 0,
),
- set_dollar: false,
- uses_super: false,
- locals: [],
- asserts: None,
+ ),
+ set_dollar: false,
+ uses_super: false,
+ locals: [],
+ asserts: None,
+ shape: ObjShape {
fields: [
- LFieldMember {
- name: Fixed(
- "c",
+ ShapeField {
+ name: "c",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
- Num(
- 2.0,
- ),
+ },
+ ShapeField {
+ name: "d",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
),
},
- LFieldMember {
- name: Fixed(
- "d",
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Trivial(
+ Num(
+ 2.0,
),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
- Index {
- indexable: Slot(
- Local(
- LocalSlot(
- 0,
- ),
+ ),
+ ),
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Index {
+ indexable: Slot(
+ Local(
+ LocalSlot(
+ 0,
+ ),
+ ),
+ ),
+ parts: [
+ LIndexPart {
+ span: virtual:<test>:35-36,
+ value: Trivial(
+ Str(
+ "c",
),
),
- parts: [
- LIndexPart {
- span: virtual:<test>:35-36,
- value: Str(
- "c",
- ),
- },
- ],
},
- ),
+ ],
},
- ],
- },
- ),
+ ),
+ ],
+ },
),
),
- },
+ ),
],
},
),
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_comp.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_comp.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_comp.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/object_comp.jsonnet
---
@@ -71,12 +72,8 @@
0,
),
),
- over: Arr {
- shape: ClosureShape {
- captures: [],
- n_locals: 0,
- },
- items: [
+ over: ArrConst(
+ [
Str(
"a",
),
@@ -84,7 +81,7 @@
"b",
),
],
- },
+ ),
loop_invariant: true,
},
],
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_dollar.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_dollar.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_dollar.jsonnet.snap
@@ -12,8 +12,8 @@
--- diagnostics ---
--- lir ---
Obj(
- MemberList(
- LObjMembers {
+ StaticMembers(
+ LObjStaticMembers {
frame_shape: ClosureShape {
captures: [],
n_locals: 1,
@@ -27,95 +27,119 @@
uses_super: false,
locals: [],
asserts: None,
- fields: [
- LFieldMember {
- name: Fixed(
- "a",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
+ shape: ObjShape {
+ fields: [
+ ShapeField {
+ name: "a",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
},
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ShapeField {
+ name: "b",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Trivial(
Num(
1.0,
),
),
- },
- LFieldMember {
- name: Fixed(
- "b",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
- Obj(
- MemberList(
- LObjMembers {
- frame_shape: ClosureShape {
- captures: [
- Local(
- LocalSlot(
- 0,
- ),
+ ),
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Obj(
+ StaticMembers(
+ LObjStaticMembers {
+ frame_shape: ClosureShape {
+ captures: [
+ Local(
+ LocalSlot(
+ 0,
),
- ],
- n_locals: 1,
- },
- this: None,
- set_dollar: false,
- uses_super: false,
- locals: [],
- asserts: None,
+ ),
+ ],
+ n_locals: 1,
+ },
+ this: None,
+ set_dollar: false,
+ uses_super: false,
+ locals: [],
+ asserts: None,
+ shape: ObjShape {
fields: [
- LFieldMember {
- name: Fixed(
- "c",
+ ShapeField {
+ name: "c",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [
- Capture(
- CaptureSlot(
- 0,
- ),
- ),
- ],
- n_locals: 0,
- },
- Index {
- indexable: Slot(
- Capture(
- CaptureSlot(
- 0,
- ),
+ },
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
+ captures: [
+ Capture(
+ CaptureSlot(
+ 0,
+ ),
+ ),
+ ],
+ n_locals: 0,
+ },
+ Index {
+ indexable: Slot(
+ Capture(
+ CaptureSlot(
+ 0,
+ ),
+ ),
+ ),
+ parts: [
+ LIndexPart {
+ span: virtual:<test>:18-19,
+ value: Trivial(
+ Str(
+ "a",
),
),
- parts: [
- LIndexPart {
- span: virtual:<test>:18-19,
- value: Str(
- "a",
- ),
- },
- ],
},
- ),
+ ],
},
- ],
- },
- ),
+ ),
+ ],
+ },
),
),
- },
+ ),
],
},
),
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_self.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_self.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_self.jsonnet.snap
@@ -12,8 +12,8 @@
--- diagnostics ---
--- lir ---
Obj(
- MemberList(
- LObjMembers {
+ StaticMembers(
+ LObjStaticMembers {
frame_shape: ClosureShape {
captures: [],
n_locals: 1,
@@ -27,53 +27,69 @@
uses_super: false,
locals: [],
asserts: None,
- fields: [
- LFieldMember {
- name: Fixed(
- "a",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
+ shape: ObjShape {
+ fields: [
+ ShapeField {
+ name: "a",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ShapeField {
+ name: "b",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
},
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Trivial(
Num(
1.0,
),
),
- },
- LFieldMember {
- name: Fixed(
- "b",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
- Index {
- indexable: Slot(
- Local(
- LocalSlot(
- 0,
- ),
+ ),
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Index {
+ indexable: Slot(
+ Local(
+ LocalSlot(
+ 0,
),
),
- parts: [
- LIndexPart {
- span: virtual:<test>:16-17,
- value: Str(
+ ),
+ parts: [
+ LIndexPart {
+ span: virtual:<test>:16-17,
+ value: Trivial(
+ Str(
"a",
),
- },
- ],
- },
- ),
- },
+ ),
+ },
+ ],
+ },
+ ),
],
},
),
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_with_locals.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_with_locals.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@object_with_locals.jsonnet.snap
@@ -16,8 +16,8 @@
--- diagnostics ---
--- lir ---
Obj(
- MemberList(
- LObjMembers {
+ StaticMembers(
+ LObjStaticMembers {
frame_shape: ClosureShape {
captures: [],
n_locals: 2,
@@ -36,59 +36,75 @@
captures: [],
n_locals: 0,
},
- value: Num(
- 10.0,
+ value: Trivial(
+ Num(
+ 10.0,
+ ),
),
},
],
asserts: None,
- fields: [
- LFieldMember {
- name: Fixed(
- "a",
+ shape: ObjShape {
+ fields: [
+ ShapeField {
+ name: "a",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ShapeField {
+ name: "b",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Slot(
+ Local(
+ LocalSlot(
+ 1,
+ ),
+ ),
),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
- Slot(
+ ),
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ BinaryOp {
+ lhs: Slot(
Local(
LocalSlot(
1,
),
),
),
- ),
- },
- LFieldMember {
- name: Fixed(
- "b",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
- BinaryOp {
- lhs: Slot(
- Local(
- LocalSlot(
- 1,
- ),
- ),
- ),
- op: Mul,
- rhs: Num(
+ op: Mul,
+ rhs: Trivial(
+ Num(
2.0,
),
- },
- ),
- },
+ ),
+ },
+ ),
],
},
),
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@redeclared_local.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@redeclared_local.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@redeclared_local.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/redeclared_local.jsonnet
---
@@ -31,8 +32,10 @@
captures: [],
n_locals: 0,
},
- value: Num(
- 1.0,
+ value: Trivial(
+ Num(
+ 1.0,
+ ),
),
},
],
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@shadowing.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@shadowing.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@shadowing.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/shadowing.jsonnet
---
@@ -32,8 +33,10 @@
captures: [],
n_locals: 0,
},
- value: Num(
- 1.0,
+ value: Trivial(
+ Num(
+ 1.0,
+ ),
),
},
],
@@ -54,8 +57,10 @@
captures: [],
n_locals: 0,
},
- value: Num(
- 2.0,
+ value: Trivial(
+ Num(
+ 2.0,
+ ),
),
},
],
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@simple_local.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@simple_local.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@simple_local.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/simple_local.jsonnet
---
@@ -28,8 +29,10 @@
captures: [],
n_locals: 0,
},
- value: Num(
- 1.0,
+ value: Trivial(
+ Num(
+ 1.0,
+ ),
),
},
],
@@ -42,8 +45,10 @@
),
),
op: Add,
- rhs: Num(
- 2.0,
+ rhs: Trivial(
+ Num(
+ 2.0,
+ ),
),
},
},
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@slice.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@slice.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@slice.jsonnet.snap
@@ -1,6 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
-assertion_line: 2017
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/slice.jsonnet
---
@@ -14,12 +14,8 @@
--- lir ---
Slice(
LSliceExpr {
- value: Arr {
- shape: ClosureShape {
- captures: [],
- n_locals: 0,
- },
- items: [
+ value: ArrConst(
+ [
Num(
1.0,
),
@@ -36,15 +32,19 @@
5.0,
),
],
- },
+ ),
start: Some(
- Num(
- 1.0,
+ Trivial(
+ Num(
+ 1.0,
+ ),
),
),
end: Some(
- Num(
- 3.0,
+ Trivial(
+ Num(
+ 3.0,
+ ),
),
),
step: None,
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@super_outside_object.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@super_outside_object.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@super_outside_object.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/super_outside_object.jsonnet
---
@@ -21,8 +22,10 @@
parts: [
LIndexPart {
span: virtual:<test>:6-7,
- value: Str(
- "a",
+ value: Trivial(
+ Str(
+ "a",
+ ),
),
},
],
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@super_usage.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@super_usage.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@super_usage.jsonnet.snap
@@ -13,8 +13,8 @@
--- lir ---
BinaryOp {
lhs: Obj(
- MemberList(
- LObjMembers {
+ StaticMembers(
+ LObjStaticMembers {
frame_shape: ClosureShape {
captures: [],
n_locals: 1,
@@ -24,47 +24,63 @@
uses_super: false,
locals: [],
asserts: None,
- fields: [
- LFieldMember {
- name: Fixed(
- "a",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
+ shape: ObjShape {
+ fields: [
+ ShapeField {
+ name: "a",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
},
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ShapeField {
+ name: "b",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Trivial(
Num(
1.0,
),
),
- },
- LFieldMember {
- name: Fixed(
- "b",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
+ ),
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Trivial(
Num(
2.0,
),
),
- },
+ ),
],
},
),
),
op: Add,
rhs: Obj(
- MemberList(
- LObjMembers {
+ StaticMembers(
+ LObjStaticMembers {
frame_shape: ClosureShape {
captures: [],
n_locals: 1,
@@ -78,67 +94,85 @@
uses_super: true,
locals: [],
asserts: None,
- fields: [
- LFieldMember {
- name: Fixed(
- "a",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
+ shape: ObjShape {
+ fields: [
+ ShapeField {
+ name: "a",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
+ },
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ShapeField {
+ name: "c",
+ flags: ObjFieldFlags {
+ add: false,
+ visibility: Normal,
},
- BinaryOp {
- lhs: Index {
- indexable: Super,
- parts: [
- LIndexPart {
- span: virtual:<test>:28-29,
- value: Str(
+ location: None,
+ index: FieldIndex(
+ (),
+ ),
+ },
+ ],
+ },
+ bindings: [
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ BinaryOp {
+ lhs: Index {
+ indexable: Super,
+ parts: [
+ LIndexPart {
+ span: virtual:<test>:28-29,
+ value: Trivial(
+ Str(
"a",
),
- },
- ],
- },
- op: Add,
- rhs: Num(
+ ),
+ },
+ ],
+ },
+ op: Add,
+ rhs: Trivial(
+ Num(
10.0,
),
- },
- ),
- },
- LFieldMember {
- name: Fixed(
- "c",
- ),
- plus: false,
- visibility: Normal,
- value: (
- ClosureShape {
- captures: [],
- n_locals: 0,
- },
- Index {
- indexable: Slot(
- Local(
- LocalSlot(
- 0,
- ),
+ ),
+ },
+ ),
+ (
+ ClosureShape {
+ captures: [],
+ n_locals: 0,
+ },
+ Index {
+ indexable: Slot(
+ Local(
+ LocalSlot(
+ 0,
),
),
- parts: [
- LIndexPart {
- span: virtual:<test>:44-45,
- value: Str(
+ ),
+ parts: [
+ LIndexPart {
+ span: virtual:<test>:44-45,
+ value: Trivial(
+ Str(
"b",
),
- },
- ],
- },
- ),
- },
+ ),
+ },
+ ],
+ },
+ ),
],
},
),
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@undefined_var.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@undefined_var.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@undefined_var.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/undefined_var.jsonnet
---
@@ -19,7 +20,9 @@
"ref",
),
op: Add,
- rhs: Num(
- 1.0,
+ rhs: Trivial(
+ Num(
+ 1.0,
+ ),
),
}
crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@unused_local.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@unused_local.jsonnet.snap
+++ b/crates/jrsonnet-evaluator/src/snapshots/jrsonnet_evaluator__analyze__tests__snapshots@unused_local.jsonnet.snap
@@ -1,5 +1,6 @@
---
source: crates/jrsonnet-evaluator/src/analyze.rs
+assertion_line: 2175
expression: rendered
input_file: crates/jrsonnet-evaluator/src/analysis_tests/unused_local.jsonnet
---
@@ -31,13 +32,17 @@
captures: [],
n_locals: 0,
},
- value: Num(
- 1.0,
+ value: Trivial(
+ Num(
+ 1.0,
+ ),
),
},
],
- body: Num(
- 2.0,
+ body: Trivial(
+ Num(
+ 2.0,
+ ),
),
},
)
crates/jrsonnet-evaluator/src/tla.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/tla.rs
+++ b/crates/jrsonnet-evaluator/src/tla.rs
@@ -5,7 +5,7 @@
use jrsonnet_ir::{SourceFifo, SourcePath};
use crate::{
- Result, Thunk, Val,
+ Result, Thunk, Val, ensure_sufficient_stack,
function::{CallLocation, PreparedFuncVal},
in_description_frame, with_state,
};
@@ -21,7 +21,7 @@
}
impl TlaArg {
pub fn evaluate_tailstrict(&self) -> Result<Val> {
- match self {
+ ensure_sufficient_stack(|| match self {
Self::String(s) => Ok(Val::string(s.clone())),
Self::Val(val) => Ok(val.clone()),
Self::Lazy(lazy) => Ok(lazy.evaluate()?),
@@ -38,7 +38,7 @@
SourcePath::new(SourceFifo("<inline code>".to_owned(), p.as_bytes().into()));
s.import_resolved(resolved)
}),
- }
+ })
}
pub fn evaluate(&self) -> Result<Thunk<Val>> {
match self {