diff --git a/Cargo.lock b/Cargo.lock index 53d378f..1f485b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -376,6 +376,7 @@ dependencies = [ [[package]] name = "makepad-error-log" version = "1.0.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" dependencies = [ "makepad-micro-serde", ] @@ -383,6 +384,7 @@ dependencies = [ [[package]] name = "makepad-html" version = "1.0.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" dependencies = [ "makepad-live-id", ] @@ -390,6 +392,7 @@ dependencies = [ [[package]] name = "makepad-live-id" version = "1.0.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" dependencies = [ "makepad-live-id-macros", ] @@ -397,6 +400,7 @@ dependencies = [ [[package]] name = "makepad-live-id-macros" version = "1.0.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" dependencies = [ "makepad-micro-proc-macro", ] @@ -404,6 +408,7 @@ dependencies = [ [[package]] name = "makepad-math" version = "1.0.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" dependencies = [ "makepad-micro-serde", ] @@ -411,10 +416,12 @@ dependencies = [ [[package]] name = "makepad-micro-proc-macro" version = "1.0.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" [[package]] name = "makepad-micro-serde" version = "1.0.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" dependencies = [ "makepad-live-id", "makepad-micro-serde-derive", @@ -423,6 +430,7 @@ dependencies = [ [[package]] name = "makepad-micro-serde-derive" version = "1.0.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" dependencies = [ "makepad-micro-proc-macro", ] @@ -430,10 +438,12 @@ dependencies = [ [[package]] name = "makepad-regex" version = "0.1.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" [[package]] name = "makepad-script" version = "1.0.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" dependencies = [ "makepad-error-log", "makepad-html", @@ -441,16 +451,23 @@ dependencies = [ "makepad-math", "makepad-regex", "makepad-script-derive", + "makepad-stitch", "smallvec 1.15.1", ] [[package]] name = "makepad-script-derive" version = "1.0.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" dependencies = [ "makepad-micro-proc-macro", ] +[[package]] +name = "makepad-stitch" +version = "0.1.0" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" + [[package]] name = "memchr" version = "2.8.3" @@ -851,6 +868,7 @@ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" [[package]] name = "smallvec" version = "1.15.1" +source = "git+https://github.com/OctoSense-org/makepad.git?rev=1fdce273bf888239079754a1834734635eaed34f#1fdce273bf888239079754a1834734635eaed34f" [[package]] name = "smallvec" diff --git a/crates/octoscript-capabilities/Cargo.toml b/crates/octoscript-capabilities/Cargo.toml index 79bb0b3..8f86171 100644 --- a/crates/octoscript-capabilities/Cargo.toml +++ b/crates/octoscript-capabilities/Cargo.toml @@ -13,7 +13,7 @@ workspace = true blake3 = { version = "1.8.5", features = ["pure"] } getrandom = { version = "0.3.4", features = ["wasm_js"] } keyring = { version = "3.6.3", default-features = false, features = ["apple-native", "windows-native"], optional = true } -makepad-script = { path = "../../vendor/makepad/platform/script" } +makepad-script = { git = "https://github.com/OctoSense-org/makepad.git", rev = "1fdce273bf888239079754a1834734635eaed34f" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.150" octoscript-core = { path = "../octoscript-core" } diff --git a/crates/octoscript-capabilities/src/lib.rs b/crates/octoscript-capabilities/src/lib.rs index 6ac5ef9..6eaf055 100644 --- a/crates/octoscript-capabilities/src/lib.rs +++ b/crates/octoscript-capabilities/src/lib.rs @@ -18,8 +18,8 @@ use std::time::{Duration, Instant}; use makepad_script::{ id, id_lut, script_args_def, script_err_not_allowed, script_err_unexpected, script_value, - LiveId, ScriptHandle, ScriptHandleGc, ScriptHandleType, ScriptIp, ScriptThreadId, ScriptValue, - NIL, + LiveId, ScriptHandle, ScriptHandleGc, ScriptHandleType, ScriptIp, ScriptStringSink, + ScriptThreadId, ScriptValue, NIL, }; use serde::{de::DeserializeOwned, Deserialize, Serialize}; pub use serde_json::{json, Value as JsonValue}; @@ -5793,7 +5793,7 @@ fn install_capability_module( ) } }; - let output = match vm.host.downcast_mut::() { + let output = match vm.host.as_any_mut().downcast_mut::() { Some(host) => host.call_json(&tool, &input), None => { return script_err_unexpected!( @@ -5841,7 +5841,7 @@ fn install_capability_module( ) } }; - let result = match vm.host.downcast_mut::() { + let result = match vm.host.as_any_mut().downcast_mut::() { Some(host) => host.begin_async_json(&tool, &input, max_pending_tools), None => { return script_err_unexpected!( @@ -5904,7 +5904,7 @@ fn install_tool_module(runtime: &mut Runtime, max_pending_to ) } }; - let pending = match vm.host.downcast_ref::() { + let pending = match vm.host.as_any().downcast_ref::() { Some(host) => host.pending(), None => { return script_err_unexpected!( @@ -5951,7 +5951,9 @@ fn install_tool_module(runtime: &mut Runtime, max_pending_to match ready { Some(Ok(output)) => match promise_output { ToolPromiseOutput::Text => { - vm.new_string_with(|_, destination| destination.push_str(&output)) + vm.bx.heap.new_bounded_string_with(|_, destination| { + destination.append_str(&output) + }) } ToolPromiseOutput::DecodedJson { max_output_bytes, @@ -5985,22 +5987,25 @@ fn install_tool_module(runtime: &mut Runtime, max_pending_to let name = script_text(vm, script_value!(vm, args.name)); let input = script_text(vm, script_value!(vm, args.input)); let result = match (name, input) { - (Ok(name), Ok(input)) => match vm.host.downcast_mut::() { - Some(host) => host.call(&name, &input), - None => { - return script_err_unexpected!( - vm.bx.threads.cur_ref().trap, - "invalid Octoscript capability host" - ) + (Ok(name), Ok(input)) => { + match vm.host.as_any_mut().downcast_mut::() { + Some(host) => host.call(&name, &input), + None => { + return script_err_unexpected!( + vm.bx.threads.cur_ref().trap, + "invalid Octoscript capability host" + ) + } } - }, + } (Err(error), _) | (_, Err(error)) => Err(error), }; match result { - Ok(output) => { - vm.new_string_with(|_, destination| destination.push_str(&output)) - } + Ok(output) => vm + .bx + .heap + .new_bounded_string_with(|_, destination| destination.append_str(&output)), Err(error) => { script_err_not_allowed!(vm.bx.threads.cur_ref().trap, "{}", error) } @@ -6016,22 +6021,25 @@ fn install_tool_module(runtime: &mut Runtime, max_pending_to let name = script_text(vm, script_value!(vm, args.name)); let input = script_json(vm, script_value!(vm, args.input)); let result = match (name, input) { - (Ok(name), Ok(input)) => match vm.host.downcast_mut::() { - Some(host) => host.call_json(&name, &input), - None => { - return script_err_unexpected!( - vm.bx.threads.cur_ref().trap, - "invalid Octoscript capability host" - ) + (Ok(name), Ok(input)) => { + match vm.host.as_any_mut().downcast_mut::() { + Some(host) => host.call_json(&name, &input), + None => { + return script_err_unexpected!( + vm.bx.threads.cur_ref().trap, + "invalid Octoscript capability host" + ) + } } - }, + } (Err(error), _) | (_, Err(error)) => Err(error), }; match result { - Ok(output) => { - vm.new_string_with(|_, destination| destination.push_str(&output)) - } + Ok(output) => vm + .bx + .heap + .new_bounded_string_with(|_, destination| destination.append_str(&output)), Err(error) => { script_err_not_allowed!(vm.bx.threads.cur_ref().trap, "{}", error) } @@ -6047,15 +6055,17 @@ fn install_tool_module(runtime: &mut Runtime, max_pending_to let name = script_text(vm, script_value!(vm, args.name)); let input = script_text(vm, script_value!(vm, args.input)); let result = match (name, input) { - (Ok(name), Ok(input)) => match vm.host.downcast_mut::() { - Some(host) => host.begin_async(&name, &input, max_pending_tools), - None => { - return script_err_unexpected!( - vm.bx.threads.cur_ref().trap, - "invalid Octoscript capability host" - ) + (Ok(name), Ok(input)) => { + match vm.host.as_any_mut().downcast_mut::() { + Some(host) => host.begin_async(&name, &input, max_pending_tools), + None => { + return script_err_unexpected!( + vm.bx.threads.cur_ref().trap, + "invalid Octoscript capability host" + ) + } } - }, + } (Err(error), _) | (_, Err(error)) => Err(error), }; @@ -6084,15 +6094,17 @@ fn install_tool_module(runtime: &mut Runtime, max_pending_to let name = script_text(vm, script_value!(vm, args.name)); let input = script_json(vm, script_value!(vm, args.input)); let result = match (name, input) { - (Ok(name), Ok(input)) => match vm.host.downcast_mut::() { - Some(host) => host.begin_async_json(&name, &input, max_pending_tools), - None => { - return script_err_unexpected!( - vm.bx.threads.cur_ref().trap, - "invalid Octoscript capability host" - ) + (Ok(name), Ok(input)) => { + match vm.host.as_any_mut().downcast_mut::() { + Some(host) => host.begin_async_json(&name, &input, max_pending_tools), + None => { + return script_err_unexpected!( + vm.bx.threads.cur_ref().trap, + "invalid Octoscript capability host" + ) + } } - }, + } (Err(error), _) | (_, Err(error)) => Err(error), }; diff --git a/crates/octoscript-core/Cargo.toml b/crates/octoscript-core/Cargo.toml index ef286d2..e0fbba9 100644 --- a/crates/octoscript-core/Cargo.toml +++ b/crates/octoscript-core/Cargo.toml @@ -11,5 +11,5 @@ workspace = true [dependencies] octoscript-ui-l0 = { path = "../octoscript-ui-l0" } -makepad-script = { path = "../../vendor/makepad/platform/script" } +makepad-script = { git = "https://github.com/OctoSense-org/makepad.git", rev = "1fdce273bf888239079754a1834734635eaed34f" } serde_json = "1.0.150" diff --git a/crates/octoscript-core/src/lib.rs b/crates/octoscript-core/src/lib.rs index c470507..626380e 100644 --- a/crates/octoscript-core/src/lib.rs +++ b/crates/octoscript-core/src/lib.rs @@ -799,8 +799,7 @@ impl Evaluation { /// install native bindings through [`Runtime::configure`]; scripts only see /// the bindings that configuration creates. pub struct Runtime { - host: H, - std: S, + host: vm::ScriptVmHost, vm: Box, limits: ExecutionLimits, json_method_limits: Rc>, @@ -818,8 +817,7 @@ impl Runtime { ))); let installed_limits = json_method_limits.clone(); let mut runtime = Self { - host, - std, + host: vm::ScriptVmHost::new(host, std), vm: Box::new(vm::ScriptVmBase::new()), limits, json_method_limits, @@ -894,11 +892,11 @@ impl Runtime { } pub fn host(&self) -> &H { - &self.host + &self.host.host } pub fn host_mut(&mut self) -> &mut H { - &mut self.host + &mut self.host.host } /// Installs trusted native bindings. The standalone `std` module is frozen, @@ -1215,7 +1213,6 @@ impl Runtime { let previous_vm = std::mem::replace(&mut self.vm, Box::new(vm::ScriptVmBase::new())); let mut vm = vm::ScriptVm { host: &mut self.host, - std: &mut self.std, bx: previous_vm, }; let result = operation(&mut vm); @@ -5499,13 +5496,15 @@ mod tests { #[test] fn canonical_newline_boundaries_are_lowered_for_vm_compatibility() { - // The inherited tokenizer sees the newline as whitespace and would - // otherwise parse `(42)` as a call on the imported module field. + // The ported VM (upstream makepad #1139) treats a `(` on a new line as + // the start of a new statement, so the inherited tokenizer no longer + // parses `(42)` as a call on the imported module field. Both the + // compatibility preflight and canonical lowering now agree. let source = "use mod.std.a\n(42)\n"; let compatibility = check_vm_compatibility(source).unwrap(); let canonical = check_syntax(source).unwrap(); - assert!(!compatibility.valid); + assert!(compatibility.valid, "{:?}", compatibility.diagnostics); assert!(canonical.valid, "{:?}", canonical.diagnostics); } @@ -7720,10 +7719,12 @@ compute(outer, 2) .iter() .any(|diagnostic| diagnostic.contains("heap allocation limit"))); - assert!(matches!( - runtime.eval("2"), - Err(RuntimeError::HeapLimitExceeded { maximum, .. }) if maximum == limits.max_heap_bytes - )); + // The ported heap preflights the charge and never allocates the + // over-limit string, so the runtime is not left above its cap after + // the failure: the next evaluation runs, and stays within the limit. + let next = runtime.eval("2").unwrap(); + assert!(next.completed(), "{:?}", next.diagnostics); + assert!(runtime.accounted_heap_bytes() <= limits.max_heap_bytes); } #[test]