Own asynchronous timer tasks in the managed object lifecycle
Verify Tessera GUI / verify (push) Failing after 7m26s
Verify Tessera GUI / verify (push) Failing after 7m26s
This commit is contained in:
+58
-10
@@ -531,13 +531,15 @@ impl Worker {
|
||||
self.repl = None;
|
||||
return;
|
||||
}
|
||||
if runtime.is_faulted() {
|
||||
return;
|
||||
}
|
||||
let id = runtime.id;
|
||||
let result = catch_unwind(AssertUnwindSafe(|| -> Result<_> {
|
||||
let document = runtime.resize_windows(&viewports)?;
|
||||
Ok((document, runtime.take_window_commands()?))
|
||||
if runtime.is_faulted() {
|
||||
runtime.poll_tasks()?;
|
||||
return Ok((None, Vec::new()));
|
||||
}
|
||||
let resized = runtime.resize_windows(&viewports)?;
|
||||
let completed = runtime.poll_tasks()?;
|
||||
Ok((completed.or(resized), runtime.take_window_commands()?))
|
||||
}));
|
||||
let mut current = match namespace.write() {
|
||||
Ok(current) => current,
|
||||
@@ -563,7 +565,7 @@ impl Worker {
|
||||
failure => {
|
||||
let mut document = current.document.clone();
|
||||
document.frame.fault = Some(match failure {
|
||||
Ok(Err(error)) => format!("Viewport update failed: {error:#}")
|
||||
Ok(Err(error)) => format!("Runtime background update failed: {error:#}")
|
||||
.chars()
|
||||
.take(1024)
|
||||
.collect(),
|
||||
@@ -571,7 +573,7 @@ impl Worker {
|
||||
self.repl = None;
|
||||
current.runtime_session = 0;
|
||||
current.window_commands.clear();
|
||||
"Runtime discarded after an internal viewport failure".into()
|
||||
"Runtime discarded after an internal background failure".into()
|
||||
}
|
||||
});
|
||||
for view in document.windows.values_mut() {
|
||||
@@ -777,7 +779,13 @@ impl Worker {
|
||||
Ok(Err(error)) => {
|
||||
if event.is_some() || faulted {
|
||||
let mut document = current.document.clone();
|
||||
let fault: String = format!("{error:#}").chars().take(1024).collect();
|
||||
// Preserve the first failure of this VM; subsequent
|
||||
// rejected Console input must not hide the callback cause.
|
||||
// A preserved picture from another generation is unrelated.
|
||||
let fault = (document.frame.session == id)
|
||||
.then(|| document.frame.fault.clone())
|
||||
.flatten()
|
||||
.unwrap_or_else(|| format!("{error:#}").chars().take(1024).collect());
|
||||
document.frame.fault = Some(fault.clone());
|
||||
for view in document.windows.values_mut() {
|
||||
view.frame.fault = Some(fault.clone());
|
||||
@@ -1032,7 +1040,7 @@ host executions, not a complete untrusted-code sandbox or a process-isolation de
|
||||
|
||||
## Managed visual types
|
||||
|
||||
`Object`, `Type`, `Function`, `Block`, `ContainerBlock`, `TextBlock`, `RectBlock`,
|
||||
`Object`, `Type`, `Function`, `Task`, `Block`, `ContainerBlock`, `TextBlock`, `RectBlock`,
|
||||
`Spacer`, `Row`, `Column`, `Button`, `Page`, `Mount`, and `Event` are managed nominal
|
||||
Type objects. Use `page = Page()` and `label = TextBlock("Hello")` in Endor source.
|
||||
The existing ui constructors return these same typed objects. `page.type`,
|
||||
@@ -1045,7 +1053,7 @@ are dynamically selected through self. Concrete native visual subclasses reuse r
|
||||
|
||||
Window is a host-provided managed resource: ui.window(), page.window(), page.open(window), window.pages()/id()/viewport(), resize(width,height), setTitle(text) and focus(). Requests project to their actual native window only after successful input/candidate completion and carry the current runtime session. Resize is asynchronous and the reported viewport is authoritative; this host accepts 1..4096 logical dimensions with a native 720x480 minimum. Failed input/candidates discard pending requests and read-only rendering rejects window effects. Open Pages appear in native tab chrome, with page.title, click activation/close, Ctrl+Tab cycling and Cmd/Ctrl+W close when page keyboard focus is active. Overflow arrows reach additional pages. These operations call actual Page methods in the same VM; tab IDs are weak runtime projections and add no GC roots. The 36-logical-pixel bar reduces Page constraint height; window/ui viewport reports the full inner size and native pointer positions are translated into content coordinates. Window() now creates additional native windows in the same VM, up to 16 open resources. Page.open(window)/moveToWindow(window) preserve Page and business identity while replacing Mounts; detachToWindow() creates and returns a new Window. Dragging a tab away from its strip invokes the same method. Window.close()/secondary OS close remove Page roots, unmount, and retire the resource context; retained Pages can reopen in another live window, and closed Window resources reject viewport/resize/title/focus operations. Closing the primary OS shell exits the application. Secondary viewport inputs and frame publication use the same worker. Secondary close after callback/rendering failure uses host-only teardown without invoking source callbacks or resuming execution. After reset/discard, closing an old picture never touches a fresh VM resource with the same number; viewport inputs are also generation-scoped. A teardown failure discards the affected VM and disables remaining pictures. Native initialization/surface errors are reported rather than panicking; failed secondary creation leaves a managed resource closable from Console. Existing-window drag/drop, release-point placement and full application-exit notifications remain pending.
|
||||
|
||||
Source measure and arrange overrides execute bottom-up and top-down in one read-only VM layout call. Structural Mount links exist before first measurement; bounds queries reject premature geometry. Native base layout uses current occurrence child measurements, and Arrangement must assign every stable child slot exactly once. Layout dependencies changed by lifecycle hooks trigger another pass before publication. Page constraints now use the current logical window viewport. Column/Button propagate cross-axis width and Row propagates cross-axis height; desired sizes are clamped. ui.viewport() provides a managed snapshot whose private input participates in rendering dependencies. Native resize updates are coalesced on the same worker without adding source inputs. Source measurement caches use Mount/method/children/constraints and actual subcall object reads, including returned-result decoding; Mount-reading methods conservatively bypass caching. ui.stats() exposes sourceMeasureHits/sourceMeasureMisses outside read-only rendering. General constraint negotiation, wrapping and scrolling remain pending.
|
||||
Source measure and arrange overrides execute bottom-up and top-down in one read-only VM layout call. Structural Mount links exist before first measurement; bounds queries reject premature geometry. Native base layout uses current occurrence child measurements, and Arrangement must assign every stable child slot exactly once. Layout dependencies changed by lifecycle hooks trigger another pass before publication. Page constraints now use the current logical window viewport. Column/Button propagate cross-axis width and Row propagates cross-axis height; desired sizes are clamped. ui.viewport() provides a managed snapshot whose private input participates in rendering dependencies. Native resize updates are coalesced on the same worker without adding source inputs. Source measurement caches use Mount/method/children/constraints and actual subcall object reads, including returned-result decoding; Mount-reading methods conservatively bypass caching. ui.stats() exposes sourceMeasureHits/sourceMeasureMisses outside read-only rendering. General constraint negotiation and text wrapping remain pending; ScrollBlock scrolling is described below.
|
||||
|
||||
Source paint overrides execute in the actual frame pipeline under a read-only heap policy. Source hitTest overrides similarly refine native pointer targets in VM paint order; Point.inside(bounds) and Point.inCircle(cx, cy, radius) provide primitive shape queries. Managed DisplayList/ObjectList/PaintCommand and Constraints/Bounds/Point results are ordinary runtime objects.
|
||||
|
||||
@@ -1053,6 +1061,8 @@ ScrollBlock(width,height,child) is a ContainerBlock with managed viewport dimens
|
||||
|
||||
Native wheel POST /events uses kind scroll with the normal window/session/layout_version, a scrollable mount ID, point=[x,y], delta=[dx,dy], and no press_point. Deltas are signed finite logical pixels within +/-1000000; positive moves toward the end of content. Other kinds must omit delta. Native Shift+wheel maps to horizontal. The host checks the active committed frame, target attachment and clipped viewport before invoking Mount.scrollBy. These fields are transport metadata; source code uses the Endor methods above.
|
||||
|
||||
ui.after(owner,key,milliseconds,callback) returns Task. The zero-argument callback runs on the owning VM worker after at least the integer 0..86400000 ms delay and must return Unit. Idle polling can add up to 100 ms; execution load may delay delivery further. Task.cancel/active/status expose cancellation, eligibility and pending/running/completed/cancelled/failed state. One owner/key replaces the prior pending task. Owner scopes and callback captures are managed strong edges; scheduler and owner links are weak. ui is an application owner. Hidden live objects continue; Page close cancels its and its Mount tasks, even close/reopen within one input. Page movement preserves Page tasks but replaces Mounts. Window close cancels its Pages/tasks; reset/DELETE/program replacement discard old scheduler/VM and generation checks reject stale publication. Failed PUT preserves old tasks. Callback failure stops the domain and cancels remaining tasks; earlier writes do not roll back. Read-only rendering cannot schedule/cancel. Limits: 64 pending per owner, 1024 per runtime, 64 delivered per poll, 128 frames/100000 instructions per callback. Providers currently support timers; network/file providers and await are pending.
|
||||
|
||||
Source function parameter annotations are checked before the body and return annotations before returning. Object accepts any live value; Unit accepts nil; Number, String/Text and Bool match scalar kinds. Function includes source/native functions and bound methods, while callable class definitions remain Type. View is a compatibility alias for Block. Other names resolve actual Type/Trait objects in the function's globals then captured builtins at each call. The method's own class uses the receiver's actual owning definition, preserving old bound methods after REPL redefinition. Other type names are not frozen at definition. UnknownAnnotation and TypeMismatch report failures; bad returns do not roll back earlier writes. No static inference, field-write validation, override variance, generic or effect typing is provided.
|
||||
|
||||
Trait definitions Visual, EventTarget, Children and Presentable are managed nominal capabilities. ui.implement(type,capability) explicitly declares an implementation after required-method/positional-arity checks; ui.implements(type,capability) and ui.supports(value,capability) query it. Block declares Visual/EventTarget; ContainerBlock declares Children, inherited by Page. Same-name methods alone never declare an implementation. Source subclass construction and host method replacement validate inherited/affected descendant contracts. Native callable signatures are trusted; source parameter/return annotations are checked at invocation. Native signature metadata, field-write and effect checks and formal trait syntax remain pending. EventTarget requires canonical on/dispatch/onEvent arities 3/2/1 after self; native optional convenience forms remain.
|
||||
@@ -1281,6 +1291,44 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn background_failure_preserves_its_cause_after_rejected_console_input() {
|
||||
let server = Arc::new(Server::http("127.0.0.1:0").unwrap());
|
||||
let namespace = Arc::new(RwLock::new(NamespaceState::default()));
|
||||
let api = start_server(server.clone(), namespace.clone(), Arc::new(|| {})).unwrap();
|
||||
let client = TestServer {
|
||||
address: server.server_addr().to_ip().unwrap(),
|
||||
server,
|
||||
api: Some(api),
|
||||
};
|
||||
let source = r#"class Failure {
|
||||
function stop(self: Failure): Unit { ui.window().resize(0,600) }
|
||||
}
|
||||
failure=Failure()
|
||||
page=Page()
|
||||
page.render(TextBlock("preserved"))
|
||||
task=ui.after(ui,"failure",0,failure.stop)"#;
|
||||
let result = client.request("PUT", "/v1/namespaces/app.main/code", source);
|
||||
assert_eq!(result.0, 200, "{}", result.2);
|
||||
let repl = "/v1/namespaces/app.main/repl";
|
||||
assert_eq!(client.request("POST", repl, "42").0, 422);
|
||||
let fault = namespace
|
||||
.read()
|
||||
.unwrap()
|
||||
.document
|
||||
.frame
|
||||
.fault
|
||||
.clone()
|
||||
.unwrap();
|
||||
assert!(fault.contains("window size"), "{fault}");
|
||||
assert!(fault.contains("stop"), "{fault}");
|
||||
assert_eq!(client.request("POST", repl, "42").0, 422);
|
||||
assert_eq!(
|
||||
namespace.read().unwrap().document.frame.fault.as_ref(),
|
||||
Some(&fault)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn console_keeps_memory_until_reset_or_complete_put_without_erasing_the_page() {
|
||||
let server = Arc::new(Server::http("127.0.0.1:0").unwrap());
|
||||
|
||||
Reference in New Issue
Block a user