feat: separate candidate program execution from initial layout continuation

This commit is contained in:
2026-10-23 10:52:01 +08:00
parent 470454caa6
commit 799fe9f3c7
3 changed files with 42 additions and 9 deletions
+34 -7
View File
@@ -240,6 +240,7 @@ pub struct ReplResult {
impl ReplSession {
/// Compile once into an isolated candidate, then keep its actual heap and
/// callback environments alive after the first successful publication.
#[cfg(test)]
pub fn load(
source: &str,
namespace: &str,
@@ -249,6 +250,7 @@ impl ReplSession {
Self::load_with_viewport(source, namespace, submission, id, None)
}
#[cfg(test)]
pub fn load_with_viewport(
source: &str,
namespace: &str,
@@ -256,6 +258,37 @@ impl ReplSession {
id: u64,
viewport: Option<crate::layout::Size>,
) -> Result<(Self, RenderDocument)> {
let mut runtime = Self::prepare_program(source, namespace, submission, id, viewport)?;
let document = runtime.refresh_document()?
.ok_or_else(|| anyhow::anyhow!("program did not publish a Page"))?;
runtime.bridge.reclaim(&mut runtime.candidate.vm, &mut runtime.candidate.roots)?;
Ok((runtime, document))
}
pub fn load_incremental(
source: &str,
namespace: &str,
submission: u64,
id: u64,
viewport: Option<crate::layout::Size>,
) -> Result<(Self, Option<RenderDocument>)> {
let mut runtime = Self::prepare_program(source, namespace, submission, id, viewport)?;
let viewports = viewport.map(|size| (crate::window::MAIN_WINDOW, size)).into_iter().collect();
let document = runtime.refresh_after_mutation(Some(&viewports))?;
if !runtime.has_pending_refresh() {
anyhow::ensure!(document.is_some(), "program did not publish a Page");
runtime.bridge.reclaim(&mut runtime.candidate.vm, &mut runtime.candidate.roots)?;
}
Ok((runtime, document))
}
fn prepare_program(
source: &str,
namespace: &str,
submission: u64,
id: u64,
viewport: Option<crate::layout::Size>,
) -> Result<Self> {
if source.len() > MAX_SOURCE_BYTES {
bail!("source exceeds the 1 MiB limit");
}
@@ -317,13 +350,7 @@ impl ReplSession {
runtime.source = source.into();
runtime.ast_nodes = budget.nodes;
runtime.program_root = Some(architecture(&unit, &plan, namespace, submission));
let document = runtime
.refresh_document()?
.ok_or_else(|| anyhow::anyhow!("program did not publish a Page"))?;
runtime
.bridge
.reclaim(&mut runtime.candidate.vm, &mut runtime.candidate.roots)?;
Ok((runtime, document))
Ok(runtime)
}
pub fn new_with_viewport(id: u64, viewport: Option<crate::layout::Size>) -> Result<Self> {