difftreelog
style fix clippy warnings
in: master
30 files changed
bindings/jrsonnet-web/src/lib.rsdiffbeforeafterboth1#![allow(clippy::future_not_send, reason = "we work with js promises anyway")]23use std::{cell::RefCell, result::Result};45use jrsonnet_evaluator::{6 IStr, NumValue, ObjValue, Result as JrResult, SourcePath, SourceUrl, State, StateBuilder, Val,7 async_import::{ResolvedImportResolver, async_import},8 error,9 function::builtin::{NativeCallback, NativeCallbackHandler},10 manifest::{JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat},11 tla::{TlaArg, apply_tla},12 trace::PathResolver,13 val::ArrValue,14 with_state,15};16use jrsonnet_formatter::FormatOptions;17use jrsonnet_gcmodule::Trace;18use jrsonnet_stdlib::{IniFormat, TomlFormat, XmlJsonmlFormat, YamlFormat};19use jrsonnet_types::ValType;20use js_sys::Reflect::get;21use rustc_hash::FxHashMap;22use wasm_bindgen::{convert::RefFromWasmAbi, prelude::*};2324#[wasm_bindgen]25#[derive(Clone, Copy)]26pub enum ValKind {27 Null,28 Bool,29 Num,30 Str,31 Arr,32 Obj,33 Func,34 BigInt,35}3637thread_local! {38 static ERR_FACTORY: RefCell<Option<js_sys::Function>> = const { RefCell::new(None) };39}40#[wasm_bindgen(js_name = setErrorFactory)]41pub fn set_error_factory(f: js_sys::Function) {42 ERR_FACTORY.with(|c| *c.borrow_mut() = Some(f));43}44fn make_jrsonnet_error(message: &str, frames: js_sys::Array, cause: &JsValue) -> JsValue {45 ERR_FACTORY.with(|c| {46 c.borrow().as_ref().map_or_else(47 || js_sys::Error::new(message).into(),48 |f| {49 let args = js_sys::Array::new();50 args.push(&JsValue::from_str(message));51 args.push(&frames);52 args.push(cause);53 f.apply(&JsValue::NULL, &args)54 .unwrap_or_else(|e| js_sys::Error::new(&format!("{e:?}")).into())55 },56 )57 })58}5960fn js_error_message(e: &JsValue) -> String {61 e.dyn_ref::<js_sys::Error>().map_or_else(62 || e.as_string().unwrap_or_else(|| format!("{e:?}")),63 |err| String::from(err.message()),64 )65}6667fn unwrap_val_ref(value: &JsValue) -> Result<<WasmVal as RefFromWasmAbi>::Anchor, JsValue> {68 #[allow(69 clippy::cast_sign_loss,70 clippy::cast_possible_truncation,71 reason = "defined to be u32"72 )]73 let ptr = get(value, &JsValue::from_str("__wbg_ptr"))74 .ok()75 .and_then(|v| v.as_f64())76 .ok_or_else(|| JsValue::from_str("expected a Val instance"))? as u32;77 if ptr == 0 {78 return Err(JsValue::from_str("Val has been freed"));79 }80 Ok(unsafe { <WasmVal as RefFromWasmAbi>::ref_from_abi(ptr) })81}8283fn js_resolver_error(prefix: &str, e: JsValue) -> JsValue {84 let msg = format!("{prefix}: {}", js_error_message(&e));85 let frames = js_sys::Array::new();86 let frame = js_sys::Object::new();87 let _ = js_sys::Reflect::set(88 &frame,89 &JsValue::from_str("desc"),90 &JsValue::from_str(prefix),91 );92 frames.push(&frame);93 make_jrsonnet_error(&msg, frames, &e)94}9596fn jrsonnet_js_error(e: &jrsonnet_evaluator::Error) -> JsValue {97 let msg = e.error().to_string();98 // let msg = format.format(e).unwrap_or_else(|_| e.to_string());99 let frames = js_sys::Array::new();100 for el in &e.trace().0 {101 let frame = js_sys::Object::new();102 let _ = js_sys::Reflect::set(103 &frame,104 &JsValue::from_str("desc"),105 &JsValue::from_str(&el.desc),106 );107 if let Some(loc) = &el.location {108 let path = loc.0.source_path().to_string();109 let _ = js_sys::Reflect::set(110 &frame,111 &JsValue::from_str("path"),112 &JsValue::from_str(&path),113 );114 let mapped = loc.0.map_source_locations(&[loc.1, loc.2]);115 let _ = js_sys::Reflect::set(116 &frame,117 &JsValue::from_str("line"),118 &JsValue::from(mapped[0].line),119 );120 let _ = js_sys::Reflect::set(121 &frame,122 &JsValue::from_str("column"),123 &JsValue::from(mapped[0].column),124 );125 }126 frames.push(&frame);127 }128 make_jrsonnet_error(&msg, frames, &JsValue::UNDEFINED)129}130131impl From<ValType> for ValKind {132 fn from(v: ValType) -> Self {133 match v {134 ValType::Null => Self::Null,135 ValType::Bool => Self::Bool,136 ValType::Num => Self::Num,137 ValType::Str => Self::Str,138 ValType::Arr => Self::Arr,139 ValType::Obj => Self::Obj,140 ValType::Func => Self::Func,141 #[cfg(feature = "exp-bigint")]142 ValType::BigInt => Self::BigInt,143 }144 }145}146147#[wasm_bindgen(js_name = Val)]148pub struct WasmVal {149 val: Val,150 state: Option<State>,151}152153impl WasmVal {154 fn new(val: Val) -> Self {155 Self { val, state: None }156 }157 fn with_state(val: Val, state: State) -> Self {158 Self {159 val,160 state: Some(state),161 }162 }163 fn run<R>(&self, f: impl FnOnce(&Val) -> R) -> R {164 if let Some(state) = &self.state {165 let _guard = state.try_enter();166 f(&self.val)167 } else {168 f(&self.val)169 }170 }171 fn manifest_with(&self, format: impl ManifestFormat) -> Result<String, JsValue> {172 self.run(|v| v.manifest(format))173 .map_err(|e| jrsonnet_js_error(&e))174 }175}176177#[wasm_bindgen(js_class = Val)]178impl WasmVal {179 pub fn null() -> Self {180 Self::new(Val::Null)181 }182 pub fn bool(b: bool) -> Self {183 Self::new(Val::Bool(b))184 }185 pub fn num(n: f64) -> Result<Self, JsError> {186 let n = NumValue::new(n)187 .ok_or_else(|| JsError::new("only finite numbers are supported by jsonnet"))?;188 Ok(Self::new(Val::num(n)))189 }190 pub fn string(s: String) -> Self {191 Self::new(Val::string(s))192 }193 pub fn bigint(value: js_sys::BigInt) -> Result<Self, JsError> {194 #[cfg(feature = "exp-bigint")]195 {196 let s: String = value197 .to_string(10)198 .map_err(|_| JsError::new("invalid bigint"))?199 .into();200 let bi = s201 .parse::<num_bigint::BigInt>()202 .map_err(|e| JsError::new(&format!("failed to parse bigint: {e}")))?;203 Ok(Self::new(Val::BigInt(Box::new(bi))))204 }205 #[cfg(not(feature = "exp-bigint"))]206 {207 let _ = value;208 Err(JsError::new(209 "bigint support is not enabled in this build (exp-bigint feature)",210 ))211 }212 }213 pub fn arr(items: Vec<WasmVal>) -> Self {214 Self::new(Val::arr(215 items.into_iter().map(|v| v.val).collect::<Vec<_>>(),216 ))217 }218 pub fn func(219 params: Vec<String>,220221 #[wasm_bindgen(unchecked_param_type = "(...args: Val[]) => Val")]222 callback: js_sys::Function,223 ) -> Self {224 #[allow(deprecated)]225 Self::new(Val::function(NativeCallback::new(226 params,227 JsHandler { func: callback },228 )))229 }230231 #[wasm_bindgen(getter)]232 pub fn kind(&self) -> ValKind {233 self.val.value_type().into()234 }235 #[wasm_bindgen(js_name = asBool)]236 pub fn as_bool(&self) -> Option<bool> {237 self.val.as_bool()238 }239 #[wasm_bindgen(js_name = asNum)]240 pub fn as_num(&self) -> Option<f64> {241 self.val.as_num()242 }243 #[wasm_bindgen(js_name = asBigint)]244 pub fn as_bigint(&self) -> Result<Option<js_sys::BigInt>, JsError> {245 #[cfg(feature = "exp-bigint")]246 {247 let Some(bi) = self.val.as_bigint() else {248 return Ok(None);249 };250 let big = js_sys::BigInt::new(&JsValue::from_str(&bi.to_string()))251 .map_err(|e| JsError::new(&format!("{e:?}")))?;252 Ok(Some(big))253 }254 #[cfg(not(feature = "exp-bigint"))]255 {256 Err(JsError::new(257 "bigint support is not enabled in this build (exp-bigint feature)",258 ))259 }260 }261 #[wasm_bindgen(js_name = asString)]262 pub fn as_string(&self) -> Option<String> {263 self.val.as_str().map(|s| s.to_string())264 }265 #[wasm_bindgen(js_name = asArr)]266 pub fn as_arr(&self) -> Option<WasmArrValue> {267 self.val.as_arr().map(|arr| WasmArrValue {268 arr,269 state: self.state.clone(),270 })271 }272 #[wasm_bindgen(js_name = asObj)]273 pub fn as_obj(&self) -> Option<WasmObjValue> {274 self.val.as_obj().map(|obj| WasmObjValue {275 obj,276 state: self.state.clone(),277 })278 }279280 #[wasm_bindgen(js_name = applyTla)]281 pub fn apply_tla(282 &self,283 #[wasm_bindgen(unchecked_param_type = "Record<string, Val>")] args: &js_sys::Object,284 ) -> Result<WasmVal, JsValue> {285 let mut map: FxHashMap<IStr, TlaArg> = FxHashMap::default();286 for entry in js_sys::Object::entries(args).iter() {287 let pair: js_sys::Array = entry288 .dyn_into()289 .map_err(|_| JsValue::from_str("expected [key, value] entry"))?;290 let key = pair291 .get(0)292 .as_string()293 .ok_or_else(|| JsValue::from_str("TLA arg key must be a string"))?;294 let value = unwrap_val_ref(&pair.get(1))?;295 map.insert(key.into(), TlaArg::Val(value.val.clone()));296 }297 let val = self.val.clone();298 self.run(|_| apply_tla(&map, val))299 .map(|v| WasmVal {300 val: v,301 state: self.state.clone(),302 })303 .map_err(|e| jrsonnet_js_error(&e))304 }305306 #[wasm_bindgen(js_name = manifestJson)]307 pub fn manifest_json(&self, indent: u32) -> Result<String, JsValue> {308 self.manifest_with(JsonFormat::cli(309 indent as usize,310 #[cfg(feature = "exp-preserve-order")]311 false,312 ))313 }314 #[wasm_bindgen(js_name = manifestToString)]315 pub fn manifest_to_string(&self) -> Result<String, JsValue> {316 self.manifest_with(ToStringFormat)317 }318 #[wasm_bindgen(js_name = manifestString)]319 pub fn manifest_string(&self) -> Result<String, JsValue> {320 self.manifest_with(StringFormat)321 }322 #[wasm_bindgen(js_name = manifestYaml)]323 pub fn manifest_yaml(&self, indent: u32, quote_keys: bool) -> Result<String, JsValue> {324 self.manifest_with(YamlFormat::std_to_yaml(325 indent != 0,326 quote_keys,327 #[cfg(feature = "exp-preserve-order")]328 false,329 ))330 }331 #[wasm_bindgen(js_name = manifestYamlStream)]332 pub fn manifest_yaml_stream(333 &self,334 indent: u32,335 quote_keys: bool,336 c_document_end: bool,337 ) -> Result<String, JsValue> {338 self.manifest_with(YamlStreamFormat::std_yaml_stream(339 YamlFormat::std_to_yaml(340 indent != 0,341 quote_keys,342 #[cfg(feature = "exp-preserve-order")]343 false,344 ),345 c_document_end,346 ))347 }348 #[wasm_bindgen(js_name = manifestXmlJsonml)]349 pub fn manifest_xml_jsonml(&self) -> Result<String, JsValue> {350 self.manifest_with(XmlJsonmlFormat::std_to_xml())351 }352 #[wasm_bindgen(js_name = manifestToml)]353 pub fn manifest_toml(&self, indent: u32) -> Result<String, JsValue> {354 self.manifest_with(TomlFormat::std_to_toml(355 " ".repeat(indent as usize),356 #[cfg(feature = "exp-preserve-order")]357 false,358 ))359 }360 #[wasm_bindgen(js_name = manifestIni)]361 pub fn manifest_ini(&self) -> Result<String, JsValue> {362 self.manifest_with(IniFormat::std(363 #[cfg(feature = "exp-preserve-order")]364 false,365 ))366 }367}368369#[wasm_bindgen(js_name = ArrValue)]370pub struct WasmArrValue {371 arr: ArrValue,372 state: Option<State>,373}374375#[wasm_bindgen(js_class = ArrValue)]376impl WasmArrValue {377 #[wasm_bindgen(getter)]378 pub fn length(&self) -> u32 {379 self.arr.len32()380 }381 pub fn at(&self, index: u32) -> Result<Option<WasmVal>, JsValue> {382 let result = self.state.as_ref().map_or_else(383 || self.arr.get32(index),384 |state| {385 let _guard = state.try_enter();386 self.arr.get32(index)387 },388 );389 result390 .map(|opt: Option<Val>| {391 opt.map(|v| WasmVal {392 val: v,393 state: self.state.clone(),394 })395 })396 .map_err(|e| jrsonnet_js_error(&e))397 }398}399400#[wasm_bindgen(js_name = ObjValue)]401pub struct WasmObjValue {402 obj: ObjValue,403 state: Option<State>,404}405406#[wasm_bindgen(js_class = ObjValue)]407impl WasmObjValue {408 pub fn keys(&self) -> Vec<String> {409 self.obj410 .fields(411 #[cfg(feature = "exp-preserve-order")]412 false,413 )414 .into_iter()415 .map(|s| s.to_string())416 .collect()417 }418 pub fn get(&self, key: String) -> Result<Option<WasmVal>, JsValue> {419 let result = if let Some(state) = &self.state {420 let _guard = state.try_enter();421 self.obj.get(key.into())422 } else {423 self.obj.get(key.into())424 };425 result426 .map(|opt: Option<Val>| {427 opt.map(|v| WasmVal {428 val: v,429 state: self.state.clone(),430 })431 })432 .map_err(|e| jrsonnet_js_error(&e))433 }434}435436#[derive(Trace)]437struct JsHandler {438 #[trace(skip)]439 func: js_sys::Function,440}441442#[wasm_bindgen(inline_js = r"443export function js_invoke_val_callback(cb, args) {444 return cb.apply(null, args);445}446")]447extern "C" {448 #[wasm_bindgen(catch)]449 fn js_invoke_val_callback(450 cb: &js_sys::Function,451 args: &js_sys::Array,452 ) -> Result<WasmVal, JsValue>;453}454455impl NativeCallbackHandler for JsHandler {456 fn call(&self, args: &[Val]) -> JrResult<Val> {457 let js_args = js_sys::Array::new();458 let state = with_state(|s| s);459 for arg in args {460 js_args.push(&JsValue::from(WasmVal::with_state(461 arg.clone(),462 state.clone(),463 )));464 }465 let result = js_invoke_val_callback(&self.func, &js_args).map_err(|e| {466 let msg = e467 .as_string()468 .or_else(|| {469 e.dyn_ref::<js_sys::Error>()470 .map(|err| String::from(err.message()))471 })472 .unwrap_or_else(|| format!("{e:?}"));473 error!("js callback threw: {msg}")474 })?;475 Ok(result.val)476 }477}478479#[wasm_bindgen(js_name = State)]480pub struct WasmState {481 state: State,482 resolver: Option<JsAsyncResolver>,483}484#[wasm_bindgen(js_class = State)]485impl WasmState {486 #[wasm_bindgen(constructor)]487 pub fn new(resolver: Option<ImportResolverJs>) -> Self {488 console_error_panic_hook::set_once();489 let mut state = StateBuilder::default();490 state.import_resolver(ResolvedImportResolver::new());491 let std = jrsonnet_stdlib::ContextInitializer::new(PathResolver::Absolute);492 state.context_initializer(std);493 let state = state.build();494 Self {495 state,496 resolver: resolver.map(|js| JsAsyncResolver { js }),497 }498 }499500 #[wasm_bindgen(js_name = evaluateSnippet)]501 pub fn evaluate_snippet(&self, name: &str, snippet: &str) -> Result<WasmVal, JsValue> {502 let _guard = self.state.enter();503 self.state504 .evaluate_snippet(name, snippet)505 .map(|v| WasmVal::with_state(v, self.state.clone()))506 .map_err(|e| jrsonnet_js_error(&e))507 }508509 #[wasm_bindgen(js_name = evaluateFile)]510 pub async fn evaluate_file(&self, path: String) -> Result<WasmVal, JsValue> {511 self.evaluate_file_from_impl(None, path).await512 }513514 #[wasm_bindgen(js_name = evaluateFileFrom)]515 pub async fn evaluate_file_from(&self, from: String, path: String) -> Result<WasmVal, JsValue> {516 self.evaluate_file_from_impl(Some(from), path).await517 }518}519520impl WasmState {521 async fn evaluate_file_from_impl(522 &self,523 from: Option<String>,524 path: String,525 ) -> Result<WasmVal, JsValue> {526 let resolver = self527 .resolver528 .clone()529 .ok_or_else(|| JsValue::from_str("file evaluation requires an ImportResolver"))?;530 let from = match from {531 Some(s) => {532 let url = url::Url::parse(&s).map_err(|e| JsValue::from_str(&e.to_string()))?;533 SourcePath::new(SourceUrl::new(url))534 }535 None => SourcePath::default(),536 };537 let path = async_import(self.state.clone(), resolver, &from, &path.as_str()).await?;538 let _guard = self.state.enter();539 self.state540 .import_resolved(path)541 .map(|v| WasmVal::with_state(v, self.state.clone()))542 .map_err(|e| jrsonnet_js_error(&e))543 }544}545546#[wasm_bindgen]547extern "C" {548 #[wasm_bindgen(typescript_type = "ImportResolver")]549 #[derive(Clone)]550 pub type ImportResolverJs;551552 #[wasm_bindgen(catch, method, structural, js_name = resolveFrom)]553 fn resolve_from(554 this: &ImportResolverJs,555 from: Option<String>,556 path: &str,557 ) -> Result<js_sys::Promise, JsValue>;558559 #[wasm_bindgen(catch, method, structural, js_name = loadFileContents)]560 fn load_file_contents(561 this: &ImportResolverJs,562 resolved: &str,563 ) -> Result<js_sys::Promise, JsValue>;564}565566#[wasm_bindgen(typescript_custom_section)]567const TS_IMPORT_RESOLVER: &'static str = r"568export interface ImportResolver {569 resolveFrom(from: string | undefined, path: string): Promise<string>;570 loadFileContents(resolved: string): Promise<Uint8Array>;571}572";573574#[derive(Clone)]575struct JsAsyncResolver {576 js: ImportResolverJs,577}578579impl jrsonnet_evaluator::async_import::AsyncImportResolver for JsAsyncResolver {580 type Error = JsValue;581582 async fn resolve_from(583 &self,584 from: &SourcePath,585 path: &dyn jrsonnet_evaluator::AsPathLike,586 ) -> Result<SourcePath, JsValue> {587 let from_js = (!from.is_default()).then(|| from.to_string());588 let path_str = path.as_path().as_ref().to_string_lossy().into_owned();589 let promise = self590 .js591 .resolve_from(from_js, &path_str)592 .map_err(|e| js_resolver_error("resolveFrom", e))?;593 let resolved_js = wasm_bindgen_futures::JsFuture::from(promise)594 .await595 .map_err(|e| js_resolver_error("resolveFrom", e))?;596 let resolved_str = resolved_js597 .as_string()598 .ok_or_else(|| JsValue::from_str("resolveFrom must return string"))?;599 let url = url::Url::parse(&resolved_str).map_err(|e| JsValue::from_str(&e.to_string()))?;600 Ok(SourcePath::new(SourceUrl::new(url)))601 }602603 async fn load_file_contents(&self, resolved: &SourcePath) -> Result<Vec<u8>, JsValue> {604 let resolved_str = resolved.to_string();605 let promise = self606 .js607 .load_file_contents(&resolved_str)608 .map_err(|e| js_resolver_error("loadFileContents", e))?;609 let bytes_js = wasm_bindgen_futures::JsFuture::from(promise)610 .await611 .map_err(|e| js_resolver_error("loadFileContents", e))?;612 let arr = bytes_js613 .dyn_into::<js_sys::Uint8Array>()614 .map_err(|_| JsValue::from_str("loadFileContents must return Uint8Array"))?;615 Ok(arr.to_vec())616 }617}618619#[wasm_bindgen(js_name = FormatOptions)]620pub struct WasmFormatOptions {621 indent: u8,622 use_tabs: bool,623 max_width: u32,624}625#[wasm_bindgen(js_class = FormatOptions)]626impl WasmFormatOptions {627 #[wasm_bindgen(constructor)]628 pub fn new() -> Self {629 Self {630 indent: 4,631 use_tabs: true,632 max_width: 100,633 }634 }635636 fn build(&self) -> FormatOptions {637 FormatOptions {638 indent: self.indent,639 use_tabs: self.use_tabs,640 max_width: self.max_width,641 }642 }643}644645impl Default for WasmFormatOptions {646 fn default() -> Self {647 Self::new()648 }649}650651#[wasm_bindgen]652pub fn format(src: &str, opts: &WasmFormatOptions) -> Result<String, String> {653 match jrsonnet_formatter::format(src, &opts.build()) {654 Ok(v) => Ok(v),655 Err(e) => {656 let e = e.build();657 Err(hi_doc::source_to_ansi(&e))658 }659 }660}bindings/jsonnet/src/lib.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -66,14 +66,12 @@
#[cfg(target_family = "unix")]
{
use std::os::unix::ffi::OsStrExt;
- let str = CString::new(input.as_os_str().as_bytes()).expect("input has zero byte in it");
- str
+ CString::new(input.as_os_str().as_bytes()).expect("input has zero byte in it")
}
#[cfg(not(target_family = "unix"))]
{
let str = input.as_os_str().to_str().expect("bad utf-8");
- let cstr = CString::new(str).expect("input has NUL inside");
- cstr
+ CString::new(str).expect("input has NUL inside")
}
}
cmds/jrb/src/main.rsdiffbeforeafterboth--- a/cmds/jrb/src/main.rs
+++ b/cmds/jrb/src/main.rs
@@ -104,6 +104,7 @@
}
}
+#[allow(clippy::too_many_lines)]
fn main() {
tracing_subscriber::fmt().init();
crates/jrsonnet-evaluator/src/analyze.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/analyze.rs
+++ b/crates/jrsonnet-evaluator/src/analyze.rs
@@ -28,7 +28,10 @@
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
-use crate::error::{format_found, suggest_names};
+use crate::{
+ arr::arridx,
+ error::{format_found, suggest_names},
+};
#[derive(Debug, Clone, Copy)]
#[must_use]
@@ -658,7 +661,7 @@
stack: &'s mut AnalysisStack,
bomb: DropBomb,
}
-impl<'s> PendingBody<'s> {
+impl PendingBody<'_> {
/// After the body is processed, drop the frame's locals and emit any
/// "unused local" warnings.
fn finish(self) {
@@ -704,7 +707,7 @@
.drain(closures.first_in_frame.idx()..)
.collect();
for (i, def) in drained.iter().enumerate().rev() {
- let id = LocalId(closures.first_in_frame.0 + i as u32);
+ let id = LocalId(closures.first_in_frame.0 + arridx(i));
let stack_locals = stack
.local_by_name
.get_mut(&def.name)
@@ -819,7 +822,7 @@
let (this_refs, rest) = refs.split_at(*refs_len);
refs = rest;
let start = next_id;
- next_id += *dest_count as u32;
+ next_id += arridx(*dest_count);
Closure {
references: this_refs,
ids: start..next_id,
@@ -1043,7 +1046,7 @@
}
fn next_local_id(&self) -> LocalId {
- LocalId(self.local_defs.len() as u32)
+ LocalId(arridx(self.local_defs.len()))
}
fn report_error(&mut self, msg: impl Into<String>, span: Option<Span>) {
@@ -1565,7 +1568,7 @@
let mut pending = alloc.finish();
let mut l_binds: Vec<LBind> = Vec::with_capacity(binds.len());
- for (bind, destruct) in binds.iter().zip(destructs.into_iter()) {
+ for (bind, destruct) in binds.iter().zip(destructs) {
let mut value_taint = AnalysisResult::default();
let (value_shape, value) = pending
.stack
@@ -1608,7 +1611,7 @@
let mut pending = alloc.finish();
let mut l_params: Vec<LParam> = Vec::with_capacity(params.exprs.len());
- for (p, destruct) in params.exprs.iter().zip(param_destructs.into_iter()) {
+ for (p, destruct) in params.exprs.iter().zip(param_destructs) {
let mut value_taint = AnalysisResult::default();
let default = p.default.as_ref().map_or_else(
|| None,
crates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/arr/mod.rs
+++ b/crates/jrsonnet-evaluator/src/arr/mod.rs
@@ -2,6 +2,7 @@
any::Any,
fmt::{self},
num::NonZeroU32,
+ ops::{Bound, RangeBounds},
rc::Rc,
};
@@ -104,20 +105,37 @@
Self::new(RangeArray::new_inclusive(a, b))
}
+ #[inline]
#[must_use]
- pub fn slice(self, index: Option<i32>, end: Option<i32>, step: Option<NonZeroU32>) -> Self {
+ pub fn slice(self, range: impl RangeBounds<usize>) -> Self {
+ fn map_bound(start: bool, bound: Bound<&usize>) -> Option<i32> {
+ match bound {
+ Bound::Included(&v) => Some(i32::try_from(v).unwrap_or(i32::MAX)),
+ Bound::Excluded(&v) => Some(
+ i32::try_from(v)
+ .unwrap_or(i32::MAX)
+ .saturating_add(if start { 1 } else { -1 }),
+ ),
+ Bound::Unbounded => None,
+ }
+ }
+ self.slice32(
+ map_bound(true, range.start_bound()),
+ map_bound(false, range.end_bound()),
+ None,
+ )
+ }
+
+ #[must_use]
+ pub fn slice32(self, index: Option<i32>, end: Option<i32>, step: Option<NonZeroU32>) -> Self {
let get_idx = |pos: Option<i32>, len: u32, default| match pos {
- #[expect(
- clippy::cast_sign_loss,
- reason = "abs value is used, len is limited to u31"
- )]
Some(v) if v < 0 => len.saturating_add_signed(v),
#[expect(clippy::cast_sign_loss, reason = "abs value is used")]
Some(v) => (v as u32).min(len),
None => default,
};
- let index = get_idx(index, self.len(), 0);
- let end = get_idx(end, self.len(), self.len());
+ let index = get_idx(index, self.len32(), 0);
+ let end = get_idx(end, self.len32(), self.len32());
let step = step.unwrap_or_else(|| NonZeroU32::new(1).expect("1 != 0"));
if index >= end {
@@ -126,24 +144,29 @@
Self::new(SliceArray {
inner: self,
- #[expect(clippy::cast_possible_truncation, reason = "len is limited to u31")]
- from: index as u32,
- #[expect(clippy::cast_possible_truncation, reason = "len is limited to u31")]
- to: end as u32,
+ from: index,
+ to: end,
step: step.get(),
})
}
/// Array length.
- pub fn len(&self) -> u32 {
- self.0.len()
+ #[inline]
+ pub fn len32(&self) -> u32 {
+ self.0.len32()
}
+ pub fn len(&self) -> usize {
+ self.len32() as usize
+ }
+
/// Is array contains no elements?
+ #[inline]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
+ #[inline]
pub fn is_cheap(&self) -> bool {
self.0.is_cheap()
}
@@ -151,24 +174,37 @@
/// Get array element by index, evaluating it, if it is lazy.
///
/// Returns `None` on out-of-bounds condition.
- pub fn get(&self, index: u32) -> Result<Option<Val>> {
- self.0.get(index)
+ #[inline]
+ pub fn get32(&self, index: u32) -> Result<Option<Val>> {
+ self.0.get32(index)
+ }
+
+ pub fn get(&self, index: usize) -> Result<Option<Val>> {
+ let Ok(i) = u32::try_from(index) else {
+ return Ok(None);
+ };
+ self.get32(i)
}
/// Get array element by index, without evaluation.
///
/// Returns `None` on out-of-bounds condition.
- pub fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
- self.0.get_lazy(index)
+ #[inline]
+ pub fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
+ self.0.get_lazy32(index)
+ }
+
+ pub fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
+ u32::try_from(index).ok().and_then(|i| self.get_lazy32(i))
}
pub fn iter(&self) -> impl ArrayLikeIter<Result<Val>> + '_ {
- (0..self.len()).map(|i| self.get(i).transpose().expect("length checked"))
+ (0..self.len32()).map(|i| self.get32(i).transpose().expect("length checked"))
}
/// Iterate over elements, returning lazy values.
pub fn iter_lazy(&self) -> impl ArrayLikeIter<Thunk<Val>> + '_ {
- (0..self.len()).map(|i| self.get_lazy(i).expect("length checked"))
+ (0..self.len32()).map(|i| self.get_lazy32(i).expect("length checked"))
}
/// Return a reversed view on current array.
@@ -201,3 +237,18 @@
Self::new(iter.into_iter().collect::<Vec<_>>())
}
}
+
+/// Checks that the usize does not exceed 4g with debug assertions enabled
+/// Should only be used on values that can't reasonably exceed this value
+#[inline]
+pub(crate) fn arridx(i: usize) -> u32 {
+ #[allow(
+ clippy::cast_possible_truncation,
+ reason = "array indexes never exceed 4g"
+ )]
+ if cfg!(debug_assertions) {
+ u32::try_from(i).expect("4g hard limit")
+ } else {
+ i as u32
+ }
+}
crates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/arr/spec.rs
+++ b/crates/jrsonnet-evaluator/src/arr/spec.rs
@@ -9,7 +9,7 @@
use jrsonnet_gcmodule::{Cc, Trace};
use jrsonnet_interner::{IBytes, IStr};
-use super::ArrValue;
+use super::{ArrValue, arridx};
use crate::{
Context, Error, ObjValue, Result, Thunk, Val,
analyze::{ClosureShape, LExpr},
@@ -21,12 +21,12 @@
};
pub trait ArrayLike: Any + Trace + Debug {
- fn len(&self) -> u32;
+ fn len32(&self) -> u32;
fn is_empty(&self) -> bool {
- self.len() == 0
+ self.len32() == 0
}
- fn get(&self, index: u32) -> Result<Option<Val>>;
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>>;
+ fn get32(&self, index: u32) -> Result<Option<Val>>;
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>>;
fn is_cheap(&self) -> bool {
false
@@ -40,15 +40,15 @@
where
T: Any + Trace + Debug + ArrayCheap,
{
- fn len(&self) -> u32 {
+ fn len32(&self) -> u32 {
<T as ArrayCheap>::len(self)
}
- fn get(&self, index: u32) -> Result<Option<Val>> {
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
Ok(<T as ArrayCheap>::get(self, index))
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
<T as ArrayCheap>::get(self, index).map(Thunk::evaluated)
}
@@ -80,16 +80,16 @@
}
}
impl ArrayLike for SliceArray {
- fn len(&self) -> u32 {
+ fn len32(&self) -> u32 {
(self.to - self.from).div_ceil(self.step)
}
- fn get(&self, index: u32) -> Result<Option<Val>> {
- self.inner.get(self.map_idx(index))
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
+ self.inner.get32(self.map_idx(index))
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
- self.inner.get_lazy(self.map_idx(index))
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
+ self.inner.get_lazy32(self.map_idx(index))
}
fn is_cheap(&self) -> bool {
@@ -99,7 +99,7 @@
impl ArrayCheap for IBytes {
fn len(&self) -> u32 {
- self.as_slice().len() as u32
+ arridx(self.as_slice().len())
}
fn get(&self, index: u32) -> Option<Val> {
self.as_slice()
@@ -132,11 +132,11 @@
}
}
impl ArrayLike for ExprArray {
- fn len(&self) -> u32 {
- self.cached.borrow().len() as u32
+ fn len32(&self) -> u32 {
+ arridx(self.cached.borrow().len())
}
- fn get(&self, index: u32) -> Result<Option<Val>> {
- if index >= self.len() {
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
+ if index >= self.len32() {
return Ok(None);
}
match &self.cached.borrow()[index as usize] {
@@ -157,7 +157,7 @@
self.cached.borrow_mut()[index as usize] = ArrayThunk::Computed(new_value.clone());
Ok(Some(new_value))
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
#[derive(Trace)]
struct ExprArrThunk {
expr: ExprArray,
@@ -168,13 +168,13 @@
fn get(&self) -> Result<Self::Output> {
self.expr
- .get(self.index)
+ .get32(self.index)
.transpose()
.expect("index checked")
}
}
- if index >= self.len() {
+ if index >= self.len32() {
return None;
}
match &self.cached.borrow()[index as usize] {
@@ -202,8 +202,8 @@
}
impl ExtendedArray {
pub fn new(a: ArrValue, b: ArrValue) -> Option<Self> {
- let a_len = a.len();
- let b_len = b.len();
+ let a_len = a.len32();
+ let b_len = b.len32();
let len = a_len.checked_add(b_len)?;
Some(Self {
a,
@@ -251,22 +251,22 @@
}
}
impl ArrayLike for ExtendedArray {
- fn get(&self, index: u32) -> Result<Option<Val>> {
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
if self.split > index {
- self.a.get(index)
+ self.a.get32(index)
} else {
- self.b.get(index - self.split)
+ self.b.get32(index - self.split)
}
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
if self.split > index {
- self.a.get_lazy(index)
+ self.a.get_lazy32(index)
} else {
- self.b.get_lazy(index - self.split)
+ self.b.get_lazy32(index - self.split)
}
}
- fn len(&self) -> u32 {
+ fn len32(&self) -> u32 {
self.len
}
@@ -280,18 +280,18 @@
T: IntoUntyped + Trace + fmt::Debug,
for<'a> &'a T: IntoUntyped,
{
- fn len(&self) -> u32 {
+ fn len32(&self) -> u32 {
self.as_slice().len().try_into().unwrap_or(u32::MAX)
}
- fn get(&self, index: u32) -> Result<Option<Val>> {
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
let Some(elem) = self.as_slice().get(index as usize) else {
return Ok(None);
};
IntoUntyped::into_untyped(elem).map(Some)
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
let elem = self.as_slice().get(index as usize)?;
Some(IntoUntyped::into_lazy_untyped(elem))
}
@@ -343,16 +343,16 @@
#[derive(Debug, Trace)]
pub struct ReverseArray(pub ArrValue);
impl ArrayLike for ReverseArray {
- fn len(&self) -> u32 {
- self.0.len()
+ fn len32(&self) -> u32 {
+ self.0.len32()
}
- fn get(&self, index: u32) -> Result<Option<Val>> {
- self.0.get(self.0.len() - index - 1)
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
+ self.0.get32(self.0.len32() - index - 1)
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
- self.0.get_lazy(self.0.len() - index - 1)
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
+ self.0.get_lazy32(self.0.len32() - index - 1)
}
fn is_cheap(&self) -> bool {
@@ -374,7 +374,7 @@
}
impl MappedArray {
pub fn new(inner: ArrValue, mapper: ArrayMapper) -> Self {
- let len = inner.len();
+ let len = inner.len32();
Self {
inner,
cached: Cc::new(RefCell::new(vec![ArrayThunk::Waiting; len as usize])),
@@ -389,12 +389,12 @@
}
}
impl ArrayLike for MappedArray {
- fn len(&self) -> u32 {
- self.cached.borrow().len() as u32
+ fn len32(&self) -> u32 {
+ arridx(self.cached.borrow().len())
}
- fn get(&self, index: u32) -> Result<Option<Val>> {
- if index >= self.len() {
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
+ if index >= self.len32() {
return Ok(None);
}
match &self.cached.borrow()[index as usize] {
@@ -413,7 +413,7 @@
let val = self
.inner
- .get(index)
+ .get32(index)
.transpose()
.expect("index checked")
.and_then(|r| self.evaluate(index, r));
@@ -428,7 +428,7 @@
self.cached.borrow_mut()[index as usize] = ArrayThunk::Computed(new_value.clone());
Ok(Some(new_value))
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
#[derive(Trace)]
struct MappedArrayThunk {
arr: MappedArray,
@@ -438,11 +438,14 @@
type Output = Val;
fn get(&self) -> Result<Self::Output> {
- self.arr.get(self.index).transpose().expect("index checked")
+ self.arr
+ .get32(self.index)
+ .transpose()
+ .expect("index checked")
}
}
- if index >= self.len() {
+ if index >= self.len32() {
return None;
}
match &self.cached.borrow()[index as usize] {
@@ -471,12 +474,12 @@
}
}
impl ArrayLike for MakeArray {
- fn len(&self) -> u32 {
- self.cached.borrow().len() as u32
+ fn len32(&self) -> u32 {
+ arridx(self.cached.borrow().len())
}
- fn get(&self, index: u32) -> Result<Option<Val>> {
- if index >= self.len() {
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
+ if index >= self.len32() {
return Ok(None);
}
match &self.cached.borrow()[index as usize] {
@@ -493,7 +496,7 @@
unreachable!()
};
- let val = self.mapper.call(index as u32);
+ let val = self.mapper.call(index);
let new_value = match val {
Ok(v) => v,
@@ -505,7 +508,7 @@
self.cached.borrow_mut()[index as usize] = ArrayThunk::Computed(new_value.clone());
Ok(Some(new_value))
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
#[derive(Trace)]
struct MakeArrayThunk {
arr: MakeArray,
@@ -515,11 +518,14 @@
type Output = Val;
fn get(&self) -> Result<Self::Output> {
- self.arr.get(self.index).transpose().expect("index checked")
+ self.arr
+ .get32(self.index)
+ .transpose()
+ .expect("index checked")
}
}
- if index >= self.len() {
+ if index >= self.len32() {
return None;
}
match &self.cached.borrow()[index as usize] {
@@ -543,7 +549,7 @@
}
impl RepeatedArray {
pub fn new(data: ArrValue, repeats: u32) -> Option<Self> {
- let total_len = data.len().checked_mul(repeats)?;
+ let total_len = data.len32().checked_mul(repeats)?;
Some(Self {
data,
repeats,
@@ -554,25 +560,25 @@
if index > self.total_len {
return None;
}
- Some(index % self.data.len())
+ Some(index % self.data.len32())
}
}
impl ArrayLike for RepeatedArray {
- fn len(&self) -> u32 {
+ fn len32(&self) -> u32 {
self.total_len
}
- fn get(&self, index: u32) -> Result<Option<Val>> {
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
let Some(idx) = self.map_idx(index) else {
return Ok(None);
};
- self.data.get(idx)
+ self.data.get32(idx)
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
let idx = self.map_idx(index)?;
- self.data.get_lazy(idx)
+ self.data.get_lazy32(idx)
}
fn is_cheap(&self) -> bool {
@@ -593,18 +599,18 @@
}
impl ArrayLike for PickObjectValues {
- fn len(&self) -> u32 {
- self.keys.len() as u32
+ fn len32(&self) -> u32 {
+ arridx(self.keys.len())
}
- fn get(&self, index: u32) -> Result<Option<Val>> {
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
let Some(key) = self.keys.as_slice().get(index as usize) else {
return Ok(None);
};
Ok(Some(self.obj.get_or_bail(key.clone())?))
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
let key = self.keys.as_slice().get(index as usize)?;
Some(self.obj.get_lazy_or_bail(key.clone()))
}
@@ -633,11 +639,11 @@
}
impl ArrayLike for PickObjectKeyValues {
- fn len(&self) -> u32 {
- self.keys.len() as u32
+ fn len32(&self) -> u32 {
+ arridx(self.keys.len())
}
- fn get(&self, index: u32) -> Result<Option<Val>> {
+ fn get32(&self, index: u32) -> Result<Option<Val>> {
let Some(key) = self.keys.as_slice().get(index as usize) else {
return Ok(None);
};
@@ -650,7 +656,7 @@
))
}
- fn get_lazy(&self, index: u32) -> Option<Thunk<Val>> {
+ fn get_lazy32(&self, index: u32) -> Option<Thunk<Val>> {
let key = self.keys.as_slice().get(index as usize)?;
// Nothing can fail in the key part, yet value is still
// lazy-evaluated
crates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -122,7 +122,7 @@
pub fn enter(self, sup_this: SupThis, build: impl FnOnce(&LocalsFrame, &Context)) -> Context {
let locals = LocalsFrame::new_once(self.n_locals);
let val = Context(Cc::new(ContextInternal {
- captures: self.captures.clone(),
+ captures: self.captures,
locals,
sup_this: Some(sup_this),
}));
crates/jrsonnet-evaluator/src/evaluate/compspec.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/compspec.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/compspec.rs
@@ -97,7 +97,7 @@
let value_ctx = inner_ctx
.pack_captures_sup_this(self.frame_shape)
.enter(|fill, ctx| {
- fill_letrec_binds(fill, &ctx, self.locals);
+ fill_letrec_binds(fill, ctx, self.locals);
});
evaluate_field_member_static(self.builder, inner_ctx, value_ctx, self.field)
}
@@ -336,6 +336,7 @@
Ok(())
}
+#[allow(clippy::too_many_lines)]
fn evaluate_compspecs(
ctx: Context,
specs: &[LCompSpec],
@@ -381,7 +382,7 @@
for (i, item) in arr.iter().enumerate() {
let item = item?;
let inner_ctx = ctx.pack_captures_sup_this(frame_shape).enter(|fill, ctx| {
- destruct(dst, fill, Thunk::evaluated(item), &ctx);
+ destruct(dst, fill, Thunk::evaluated(item), ctx);
});
evaluate_compspecs(
inner_ctx,
crates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
@@ -5,7 +5,7 @@
use crate::{
Context, LocalsFrame, PackedContext, Result, SupThis, Thunk, Unbound, Val,
analyze::{
- ClosureShape, LBind, LDestruct, LDestructField, LDestructRest, LExpr, LLocalExpr, LocalSlot,
+ ClosureShape, LBind, LDestruct, LDestructField, LDestructRest, LLocalExpr, LocalSlot,
},
bail,
evaluate::evaluate,
@@ -19,7 +19,7 @@
fill: &LocalsFrame,
value: Thunk<Val>,
- a_ctx: &Context,
+ ctx: &Context,
) {
let min_len = start.len() + end.len();
let has_rest = rest.is_some();
@@ -29,14 +29,14 @@
bail!("expected array");
};
if !has_rest {
- if arr.len() as usize != min_len {
- bail!("expected {} elements, got {}", min_len, arr.len())
+ if arr.len() != min_len {
+ bail!("expected {} elements, got {}", min_len, arr.len32())
}
- } else if (arr.len() as usize) < min_len {
+ } else if arr.len() < min_len {
bail!(
"expected at least {} elements, but array was only {}",
min_len,
- arr.len()
+ arr.len32()
)
}
Ok(arr)
@@ -47,13 +47,13 @@
destruct(
d,
fill,
- Thunk!(move || Ok(full.evaluate()?.get(i as u32)?.expect("length is checked"))),
- a_ctx,
+ Thunk!(move || Ok(full.evaluate()?.get(i)?.expect("length is checked"))),
+ ctx,
);
}
- let start_len = start.len() as u32;
- let end_len = end.len() as u32;
+ let start_len = start.len();
+ let end_len = end.len();
if let Some(LDestructRest::Keep(slot)) = rest {
let full = full.clone();
@@ -62,11 +62,7 @@
Thunk!(move || {
let full = full.evaluate()?;
let to = full.len() - end_len;
- Ok(Val::Arr(full.slice(
- Some(start_len as i32),
- Some(to as i32),
- None,
- )))
+ Ok(Val::Arr(full.slice(start_len..to)))
}),
);
}
@@ -79,10 +75,10 @@
Thunk!(move || {
let full = full.evaluate()?;
Ok(full
- .get(full.len() - end_len + i as u32)?
+ .get(full.len() - end_len + i)?
.expect("length is checked"))
}),
- a_ctx,
+ ctx,
);
}
}
@@ -94,7 +90,7 @@
fill: &LocalsFrame,
value: Thunk<Val>,
- a_ctx: &Context,
+ ctx: &Context,
) {
use jrsonnet_interner::IStr;
use rustc_hash::FxHashSet;
@@ -118,7 +114,7 @@
}
}
if !has_rest {
- let len = obj.len();
+ let len = obj.len32();
if len as usize > field_names.len() {
bail!("too many fields, and rest not found");
}
@@ -142,10 +138,11 @@
for field in fields {
let field_name = field.name.clone();
- let default_thunk: Option<Thunk<Val>> = field
- .default
- .as_ref()
- .map(|(shape, expr)| build_b_thunk(a_ctx, shape, expr.clone()));
+ let default_thunk: Option<Thunk<Val>> = field.default.as_ref().map(|(shape, expr)| {
+ let expr = expr.clone();
+ let env = Context::enter_using(ctx, shape);
+ Thunk!(move || evaluate(env, &expr))
+ });
let field_full = full.clone();
let value_thunk = Thunk!(move || {
@@ -157,7 +154,7 @@
});
if let Some(into) = &field.into {
- destruct(into, fill, value_thunk, a_ctx);
+ destruct(into, fill, value_thunk, ctx);
} else {
unreachable!("analyzer lowers object-destruct shorthands into `into`");
}
@@ -177,21 +174,18 @@
#[cfg(feature = "exp-destruct")]
LDestruct::Object { fields, rest } => destruct_object(fields, rest.as_ref(), fill, value, a_ctx),
}
-}
-
-pub fn build_b_thunk(a_ctx: &Context, shape: &ClosureShape, expr: Rc<LExpr>) -> Thunk<Val> {
- let env = Context::enter_using(a_ctx, shape);
- Thunk!(move || evaluate(env, &expr))
-}
-pub fn build_b_thunk_uno(a_ctx: &Context, shape: Rc<(ClosureShape, LExpr)>) -> Thunk<Val> {
- let env = Context::enter_using(a_ctx, &shape.0);
- Thunk!(move || evaluate(env, &shape.1))
}
pub fn fill_letrec_binds(fill: &LocalsFrame, ctx: &Context, binds: &[LBind]) {
for bind in binds {
- let value_thunk = build_b_thunk(ctx, &bind.value_shape, bind.value.clone());
- destruct(&bind.destruct, fill, value_thunk, ctx);
+ let expr = bind.value.clone();
+ let env = Context::enter_using(ctx, &bind.value_shape);
+ destruct(
+ &bind.destruct,
+ fill,
+ Thunk!(move || evaluate(env, &expr)),
+ ctx,
+ );
}
}
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -7,7 +7,7 @@
use self::{
compspec::{evaluate_arr_comp, evaluate_obj_comp},
- destructure::{build_b_thunk_uno, evaluate_local_expr, evaluate_locals_unbound},
+ destructure::{evaluate_local_expr, evaluate_locals_unbound},
operator::evaluate_binary_op_special,
};
use crate::{
@@ -115,6 +115,7 @@
}
}
+#[allow(clippy::too_many_lines)]
pub fn evaluate(ctx: Context, expr: &LExpr) -> Result<Val> {
Ok(match expr {
LExpr::Null => Val::Null,
@@ -218,7 +219,7 @@
BoundedUsize::from_untyped(v).description("slice step value")
})
.transpose()?;
- Val::from(indexable.slice(start, end, step)?)
+ Val::from(indexable.slice32(start, end, step)?)
}
LExpr::Super => Val::Obj(ctx.try_sup_this()?.standalone_super().ok_or(NoSuperFound)?),
LExpr::Import {
@@ -320,6 +321,7 @@
)
}
+#[allow(clippy::too_many_lines)]
fn evaluate_index(ctx: Context, indexable: &LExpr, parts: &[LIndexPart]) -> Result<Val> {
let mut parts = parts.iter();
let mut indexable = if matches!(indexable, LExpr::Super) {
@@ -394,17 +396,17 @@
if n.fract() > f64::EPSILON {
bail!(FractionalIndex)
}
- let len = arr.len();
+ let len = arr.len32();
if n < 0.0 || n > f64::from(len) {
bail!(ArrayBoundsError(n, len));
}
#[expect(
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
- reason = "n is checked positive"
+ reason = "n is checked range"
)]
let i = n as u32;
- arr.get(i)
+ arr.get32(i)
.with_description_src(loc, || format!("element <{i}> access"))?
.ok_or_else(|| ArrayBoundsError(n, len))?
}
@@ -507,12 +509,13 @@
return Ok(());
};
- let thunk = build_b_thunk_uno(&value_ctx, value.clone());
+ let env = Context::enter_using(&value_ctx, &value.0);
+ let value = value.clone();
builder
.field(name)
.with_add(*plus)
.with_visibility(*visibility)
- .try_thunk(thunk)?;
+ .try_thunk(Thunk!(move || evaluate(env, &value.1)))?;
Ok(())
}
crates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/mod.rs
+++ b/crates/jrsonnet-evaluator/src/function/mod.rs
@@ -11,12 +11,10 @@
prepared::{PreparedCall, parse_prepared_builtin_call},
};
use crate::{
- PackedContextSupThis, Result, Thunk, Val,
+ Context, PackedContextSupThis, Result, Thunk, Val,
analyze::LFunction,
- evaluate::{
- destructure::{build_b_thunk, destruct},
- ensure_sufficient_stack, evaluate, evaluate_trivial,
- },
+ arr::arridx,
+ evaluate::{destructure::destruct, ensure_sufficient_stack, evaluate, evaluate_trivial},
function::builtin::BuiltinFunc,
};
@@ -83,7 +81,7 @@
&self.func.params[param_idx].destruct,
fill,
thunk.clone(),
- &ctx,
+ ctx,
);
}
for &(param_idx, arg_idx) in prepared.named() {
@@ -91,15 +89,22 @@
&self.func.params[param_idx].destruct,
fill,
named[arg_idx].clone(),
- &ctx,
+ ctx,
);
}
for ¶m_idx in prepared.defaults() {
let param = &self.func.params[param_idx];
let (shape, expr) = param.default.as_ref().expect("default exists");
- let thunk = build_b_thunk(&ctx, shape, expr.clone());
- destruct(¶m.destruct, fill, thunk, &ctx);
+ let expr = expr.clone();
+ let env = Context::enter_using(ctx, shape);
+
+ destruct(
+ ¶m.destruct,
+ fill,
+ Thunk!(move || evaluate(env, &expr)),
+ ctx,
+ );
}
});
@@ -152,8 +157,8 @@
}
}
/// Amount of non-default required arguments
- pub fn params_len(&self) -> u32 {
- self.params().iter().filter(|p| !p.has_default()).count() as u32
+ pub fn params_len32(&self) -> u32 {
+ arridx(self.params().iter().filter(|p| !p.has_default()).count())
}
/// Function name, as defined in code.
pub fn name(&self) -> IStr {
crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -182,7 +182,7 @@
#[cfg(feature = "exp-bigint")]
Self::BigInt(b) => b.serialize(serializer),
Self::Arr(arr) => {
- let mut seq = serializer.serialize_seq(Some(arr.len() as usize))?;
+ let mut seq = serializer.serialize_seq(Some(arr.len()))?;
for (i, element) in arr.iter().enumerate() {
let mut serde_error = None;
in_description_frame(
@@ -203,7 +203,7 @@
seq.end()
}
Self::Obj(obj) => {
- let mut map = serializer.serialize_map(Some(obj.len() as usize))?;
+ let mut map = serializer.serialize_map(Some(obj.len32() as usize))?;
for (field, value) in obj.iter(
#[cfg(feature = "exp-preserve-order")]
true,
crates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj/mod.rs
+++ b/crates/jrsonnet-evaluator/src/obj/mod.rs
@@ -23,7 +23,7 @@
use crate::{
CcUnbound, MaybeUnbound, Result, Thunk, Unbound, Val,
- arr::{PickObjectKeyValues, PickObjectValues},
+ arr::{PickObjectKeyValues, PickObjectValues, arridx},
bail,
error::{ErrorKind::*, suggest_object_fields},
evaluate::operator::evaluate_add_op,
@@ -510,11 +510,14 @@
// }
/// Returns amount of visible object fields
/// If object only contains hidden fields - may return zero.
- pub fn len(&self) -> u32 {
+ pub fn len(&self) -> usize {
self.fields_visibility()
.values()
.filter(|d| d.visible())
- .count() as u32
+ .count()
+ }
+ pub fn len32(&self) -> u32 {
+ arridx(self.len())
}
/// For each field, calls callback.
/// If callback returns false - ends iteration prematurely.
@@ -625,7 +628,7 @@
Entry::Vacant(v) => {
v.insert(CacheValue::Pending);
}
- };
+ }
}
let result = self.get_idx_uncached(key, core);
{
crates/jrsonnet-evaluator/src/stack.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/stack.rs
+++ b/crates/jrsonnet-evaluator/src/stack.rs
@@ -11,7 +11,7 @@
struct NightlyLocalKey<T>(pub T);
#[cfg(nightly)]
impl<T> NightlyLocalKey<T> {
- #[inline(always)]
+ #[inline]
fn with<U>(&self, v: impl FnOnce(&T) -> U) -> U {
v(&self.0)
}
crates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -197,7 +197,7 @@
w = align
)?;
} else {
- write!(out, "{:<p$}{}", "", el.desc, p = self.padding,)?;
+ write!(out, "{:<p$}{}", "", el.desc, p = self.padding)?;
}
}
Ok(())
@@ -258,6 +258,7 @@
}
#[cfg(feature = "explaining-traces")]
impl TraceFormat for HiDocFormat {
+ #[allow(clippy::too_many_lines)]
fn write_trace(&self, out: &mut dyn fmt::Write, error: &Error) -> Result<(), fmt::Error> {
struct ResetData {
loc: Span,
crates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -637,7 +637,7 @@
}
<Self as Typed>::TYPE.check(&value)?;
// Any::downcast_ref::<ByteArray>(&a);
- let mut out = Vec::with_capacity(a.len() as usize);
+ let mut out = Vec::with_capacity(a.len());
for e in a.iter() {
let r = e?;
out.push(u8::from_untyped(r)?);
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -277,7 +277,7 @@
/// For strings, will create a copy of specified interval.
///
/// For arrays, nothing will be copied on this call, instead [`ArrValue::Slice`] view will be returned.
- pub fn slice(
+ pub fn slice32(
self,
index: Option<i32>,
end: Option<i32>,
@@ -321,7 +321,7 @@
.into(),
))
}
- Self::Arr(arr) => Ok(Self::Arr(arr.clone().slice(
+ Self::Arr(arr) => Ok(Self::Arr(arr.clone().slice32(
index,
end,
#[expect(
@@ -658,7 +658,7 @@
if ArrValue::ptr_eq(a, b) {
return Ok(true);
}
- if a.len() != b.len() {
+ if a.len32() != b.len32() {
return Ok(false);
}
for (a, b) in a.iter().zip(b.iter()) {
crates/jrsonnet-formatter/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-formatter/src/lib.rs
+++ b/crates/jrsonnet-formatter/src/lib.rs
@@ -477,8 +477,7 @@
&mut out,
);
- let mut compspecs = compspecs.into_iter().peekable();
- while let Some(mem) = compspecs.next() {
+ for mem in compspecs {
if mem.should_start_with_newline {
p!(out, nl);
}
crates/jrsonnet-peg-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-peg-parser/src/lib.rs
+++ b/crates/jrsonnet-peg-parser/src/lib.rs
@@ -273,19 +273,15 @@
Expr::ArrComp(Box::new(expr), specs)
}
pub rule number_expr(s: &ParserSettings) -> Expr
- = n:number() {? if let Some(n) = NumValue::new(n) {
- Ok(Expr::Num(n))
- } else {
- Err("!!!numbers are finite")
- }}
+ = n:number() {? NumValue::new(n).map_or_else(|| Err("!!!numbers are finite"), |n| Ok(Expr::Num(n)))}
rule spanned<T: Acyclic>(x: rule<T>, s: &ParserSettings) -> Spanned<T>
- = a:position!() n:x() b:position!() { Spanned::new(n, Span(s.source.clone(), a as u32, b as u32)) }
+ = a:position!() n:x() b:position!() { Spanned::new(n, Span(s.source.clone(), codeidx(a), codeidx(b))) }
pub rule var_expr(s: &ParserSettings) -> Expr
= n:spanned(<id()>, s) { Expr::Var(n) }
pub rule id_loc(s: &ParserSettings) -> Spanned<Expr>
- = a:position!() n:id() b:position!() { Spanned::new(Expr::Str(n), Span(s.source.clone(), a as u32,b as u32)) }
+ = a:position!() n:id() b:position!() { Spanned::new(Expr::Str(n), Span(s.source.clone(), codeidx(a), codeidx(b))) }
pub rule if_then_else_expr(s: &ParserSettings) -> Expr
= cond:ifspec(s) _ keyword("then") _ cond_then:expr(s) cond_else:(_ keyword("else") _ e:expr(s) {e})? {Expr::IfElse(Box::new(IfElse{
cond,
@@ -421,6 +417,10 @@
}
}
+fn codeidx(i: usize) -> u32 {
+ u32::try_from(i).expect("code has 4g hard limit")
+}
+
pub type ParseError = peg::error::ParseError<peg::str::LineCol>;
pub fn parse(str: &str, settings: &ParserSettings) -> Result<Expr, ParseError> {
jsonnet_parser::jsonnet(str, settings)
@@ -428,7 +428,10 @@
/// Used for importstr values
pub fn string_to_expr(str: IStr, settings: &ParserSettings) -> Spanned<Expr> {
let len = str.len();
- Spanned::new(Expr::Str(str), Span(settings.source.clone(), 0, len as u32))
+ Spanned::new(
+ Expr::Str(str),
+ Span(settings.source.clone(), 0, codeidx(len)),
+ )
}
#[cfg(test)]
crates/jrsonnet-pkg/src/install/accessor.rsdiffbeforeafterboth--- a/crates/jrsonnet-pkg/src/install/accessor.rs
+++ b/crates/jrsonnet-pkg/src/install/accessor.rs
@@ -66,6 +66,10 @@
Ok(Some(out))
}
#[allow(clippy::significant_drop_tightening, reason = "false-positive")]
+ #[allow(
+ clippy::iter_not_returning_iterator,
+ reason = "idk for a better name, it is still inner iteration"
+ )]
pub fn iter<E>(
&self,
subdir: &SubDir,
crates/jrsonnet-rowan-parser/src/parser.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/parser.rs
+++ b/crates/jrsonnet-rowan-parser/src/parser.rs
@@ -226,12 +226,12 @@
self.nth_at(0, kind)
}
pub fn nth_at(&self, n: usize, kind: SyntaxKind) -> bool {
- if n == 0 {
- if let ExpectedSyntax::Unnamed(kinds) = self.expected_syntax_tracking_state.get() {
- let kinds = kinds.with(kind);
- self.expected_syntax_tracking_state
- .set(ExpectedSyntax::Unnamed(kinds));
- }
+ if n == 0
+ && let ExpectedSyntax::Unnamed(kinds) = self.expected_syntax_tracking_state.get()
+ {
+ let kinds = kinds.with(kind);
+ self.expected_syntax_tracking_state
+ .set(ExpectedSyntax::Unnamed(kinds));
}
self.nth(n) == kind
}
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -52,7 +52,7 @@
step: Option<Option<BoundedUsize<1, { i32::MAX as usize }>>>,
) -> Result<Val> {
indexable
- .slice(index.flatten(), end.flatten(), step.flatten())
+ .slice32(index.flatten(), end.flatten(), step.flatten())
.map(Val::from)
}
@@ -204,14 +204,14 @@
let item = item?.clone();
if let Val::Arr(items) = item {
if !first {
- out.reserve(joiner_items.len() as usize);
+ out.reserve(joiner_items.len());
// TODO: extend
for item in joiner_items.iter() {
out.push(item?);
}
}
first = false;
- out.reserve(items.len() as usize);
+ out.reserve(items.len());
for item in items.iter() {
out.push(item?);
}
@@ -372,10 +372,10 @@
#[builtin]
pub fn builtin_remove_at(arr: ArrValue, at: i32) -> Result<ArrValue> {
- let newArrLeft = arr.clone().slice(None, Some(at), None);
- let newArrRight = arr.slice(Some(at + 1), None, None);
+ let newArrLeft = arr.clone().slice32(None, Some(at), None);
+ let newArrRight = arr.slice32(Some(at + 1), None, None);
- Ok(ArrValue::extended(newArrLeft, newArrRight).ok_or_else(|| error!("array is too large"))?)
+ ArrValue::extended(newArrLeft, newArrRight).ok_or_else(|| error!("array is too large"))
}
#[builtin]
crates/jrsonnet-stdlib/src/manifest/xml.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/manifest/xml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/xml.rs
@@ -44,15 +44,15 @@
bail!("JSONML value should have tag (array length should be >=1)");
}
let tag = String::from_untyped(
- arr.get(0)
+ arr.get32(0)
.description("getting JSONML tag")?
.expect("length checked"),
)
.description("parsing JSONML tag")?;
- let (has_attrs, attrs) = if arr.len() >= 2 {
+ let (has_attrs, attrs) = if arr.len32() >= 2 {
let maybe_attrs = arr
- .get(1)
+ .get32(1)
.with_description(|| "getting JSONML attrs")?
.expect("length checked");
if let Val::Obj(attrs) = maybe_attrs {
@@ -68,13 +68,7 @@
attrs,
children: in_description_frame(
|| "parsing children".to_owned(),
- || {
- FromUntyped::from_untyped(Val::Arr(arr.slice(
- Some(if has_attrs { 2 } else { 1 }),
- None,
- None,
- )))
- },
+ || FromUntyped::from_untyped(Val::Arr(arr.slice(if has_attrs { 2 } else { 1 }..))),
)?,
})
}
crates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/misc.rs
+++ b/crates/jrsonnet-stdlib/src/misc.rs
@@ -16,10 +16,10 @@
pub fn builtin_length(x: Either![IStr, ArrValue, ObjValue, FuncVal]) -> u32 {
use Either4::*;
match x {
- A(x) => x.chars().count() as u32,
- B(x) => x.len(),
- C(x) => x.len(),
- D(f) => f.params_len(),
+ A(x) => u32::try_from(x.chars().count()).expect("4g limit"),
+ B(x) => x.len32(),
+ C(x) => x.len32(),
+ D(f) => f.params_len32(),
}
}
@@ -102,7 +102,7 @@
} else if b.len() == a.len() {
return equals(&Val::Arr(a), &Val::Arr(b));
}
- for (a, b) in a.iter().take(b.len() as usize).zip(b.iter()) {
+ for (a, b) in a.iter().take(b.len()).zip(b.iter()) {
let a = a?;
let b = b?;
if !equals(&a, &b)? {
@@ -127,7 +127,7 @@
return equals(&Val::Arr(a), &Val::Arr(b));
}
let a_len = a.len();
- for (a, b) in a.iter().skip((a_len - b.len()) as usize).zip(b.iter()) {
+ for (a, b) in a.iter().skip(a_len - b.len()).zip(b.iter()) {
let a = a?;
let b = b?;
if !equals(&a, &b)? {
crates/jrsonnet-stdlib/src/sets.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/sets.rs
+++ b/crates/jrsonnet-stdlib/src/sets.rs
@@ -8,13 +8,13 @@
#[allow(non_snake_case)]
pub fn builtin_set_member(x: Thunk<Val>, arr: ArrValue, #[default] keyF: KeyF) -> Result<bool> {
let mut low = 0;
- let mut high = arr.len();
+ let mut high = arr.len32();
let x = keyF.eval(x)?;
while low < high {
let middle = u32::midpoint(high, low);
- let comp = keyF.eval(arr.get_lazy(middle).expect("in bounds"))?;
+ let comp = keyF.eval(arr.get_lazy32(middle).expect("in bounds"))?;
match Val::try_cmp(&comp, &x)? {
Ordering::Less => low = middle + 1,
Ordering::Equal => return Ok(true),
crates/jrsonnet-stdlib/src/sort.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/sort.rs
+++ b/crates/jrsonnet-stdlib/src/sort.rs
@@ -69,7 +69,7 @@
fn sort_keyf(values: ArrValue, keyf: KeyF) -> Result<Vec<Thunk<Val>>> {
// Slow path, user provided key getter
- let mut vk = Vec::with_capacity(values.len() as usize);
+ let mut vk = Vec::with_capacity(values.len());
for value in values.iter_lazy() {
vk.push((value.clone(), keyf.eval(value)?));
}
@@ -137,7 +137,7 @@
fn uniq_keyf(arr: ArrValue, keyf: KeyF) -> Result<Vec<Thunk<Val>>> {
let mut out = Vec::new();
- let last_value = arr.get_lazy(0).unwrap();
+ let last_value = arr.get_lazy32(0).unwrap();
let mut last_key = keyf.eval(last_value.clone())?;
out.push(last_value);
crates/jrsonnet-types/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-types/src/lib.rs
+++ b/crates/jrsonnet-types/src/lib.rs
@@ -103,10 +103,8 @@
Self::BoundedNumber(a, b) => write!(
f,
"BoundedNumber<{}, {}>",
- a.map(|e| e.to_string())
- .unwrap_or_else(|| "open".to_owned()),
- b.map(|e| e.to_string())
- .unwrap_or_else(|| "open".to_owned())
+ a.map_or_else(|| "open".to_owned(), |e| e.to_string()),
+ b.map_or_else(|| "open".to_owned(), |e| e.to_string())
)?,
Self::ArrayRef(a) => print_array(a, f)?,
Self::Array(a) => print_array(a, f)?,
tests/tests/cpp_test_suite.rsdiffbeforeafterboth--- a/tests/tests/cpp_test_suite.rs
+++ b/tests/tests/cpp_test_suite.rs
@@ -60,7 +60,7 @@
let _entered = s.enter();
let trace_format = CompactFormat {
- resolver: resolver.clone(),
+ resolver,
max_trace: 20,
padding: 4,
};
xtask/src/bench.rsdiffbeforeafterboth--- a/xtask/src/bench.rs
+++ b/xtask/src/bench.rs
@@ -91,6 +91,10 @@
let start = Instant::now();
let child = cmd.spawn()?;
+ #[allow(
+ clippy::cast_possible_wrap,
+ reason = "it is signed, but libc didn't set unsigned for it"
+ )]
let pid = child.id() as libc::pid_t;
// We'll reap via wait4 ourselves; don't let std touch this handle again.
mem::forget(child);
@@ -133,10 +137,10 @@
);
eprintln!(
" max_rss: {} ± {} KiB [{}..{}]",
- r.max_rss_kib.mean as i64,
- r.max_rss_kib.stddev as i64,
- r.max_rss_kib.min as i64,
- r.max_rss_kib.max as i64,
+ r.max_rss_kib.mean.trunc(),
+ r.max_rss_kib.stddev.trunc(),
+ r.max_rss_kib.min.trunc(),
+ r.max_rss_kib.max.trunc(),
);
Ok(())
}
xtask/src/sourcegen/mod.rsdiffbeforeafterboth--- a/xtask/src/sourcegen/mod.rs
+++ b/xtask/src/sourcegen/mod.rs
@@ -113,6 +113,7 @@
Ok(())
}
+#[allow(clippy::too_many_lines)]
fn generate_syntax_kinds(kinds: &KindsSrc, grammar: &AstSrc, lexer: bool) -> Result<String> {
let t_macros = kinds.tokens().filter_map(TokenKind::expand_t_macros);
let token_kinds = kinds.tokens().map(|t| t.expand_kind(lexer));