A design file keeps its evaluated model so that it opens without
evaluating the timeline. A feature whose boolean needed a retry records
it, and the kernel's BooleanDiagnostics leaves `rejected` out when it is
empty but has no default for it when read, so reading those records
failed ("saved model: diagnostics"), the saved model was refused, and
the design was evaluated on every open (17.6 s for the reporter's
17-feature design, 1.2 ms with this).
The reading side now takes an absent list as an empty one, without a
change to the kernel crate.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,17 @@ const MAX_ITEMS: usize = 1_000_000;
|
||||
/// Bodies and sketches all the states hold together, at most (a state is a list of clones).
|
||||
const MAX_HELD: usize = 50_000_000;
|
||||
|
||||
/// A feature's boolean retries as saved. The kernel leaves `rejected` out when it is empty, and
|
||||
/// the field has no default when read, so a saved model whose booleans retried was refused and
|
||||
/// the design evaluated on every open (#5286): an absent list is an empty one.
|
||||
fn saved_diagnostics(d: &Json) -> Result<kernel::BooleanDiagnostics> {
|
||||
let mut d = d.clone();
|
||||
if let Some(fields) = d.as_object_mut() {
|
||||
fields.entry("rejected").or_insert_with(|| json!([]));
|
||||
}
|
||||
serde_json::from_value(d).map_err(|_| bad("saved model: diagnostics"))
|
||||
}
|
||||
|
||||
fn hex(v: u64) -> String {
|
||||
format!("{v:016x}")
|
||||
}
|
||||
@@ -557,7 +568,7 @@ impl Model {
|
||||
error: None,
|
||||
warning: r.get("warning").map(|w| text(Some(w))).transpose()?,
|
||||
boolean_diagnostics: match r.get("diagnostics") {
|
||||
Some(d) => serde_json::from_value(d.clone()).map_err(|_| bad("saved model: diagnostics"))?,
|
||||
Some(d) => saved_diagnostics(d)?,
|
||||
None => Default::default(),
|
||||
},
|
||||
ms,
|
||||
|
||||
@@ -864,6 +864,30 @@ mod tests {
|
||||
std::fs::remove_file(format!("{}.bak", path.display())).unwrap();
|
||||
}
|
||||
|
||||
/// #5286: a saved model whose feature records the boolean retries it took (as the kernel
|
||||
/// writes them, with no `rejected` list when there were none) is taken on opening, not
|
||||
/// refused and evaluated again.
|
||||
#[test]
|
||||
fn a_saved_model_with_boolean_retries_is_adopted() {
|
||||
let mut session = Session::new(Document::new("Retried"));
|
||||
session.execute("solid.box", &json!({"length":10,"width":20,"height":30})).unwrap();
|
||||
let mut saved = saved_geometry(&session, &session.doc).unwrap();
|
||||
// What a coplanar-face retry leaves in the file (a user's design, #5286).
|
||||
let retry = json!({"events": [{"face_shift_mm": 0.6477, "rotation_rad": 0.0, "strategy": "coplanar_separation", "tolerance_mm": 0.0, "translation_mm": 0.0}], "truncated": false});
|
||||
saved.records["features"][0]["diagnostics"] = retry;
|
||||
let bytes =
|
||||
solidcraft_io::write_design_container_with_cache(&session.doc, solidcraft_io::DesignCompression::Fast, None, Some(&saved)).unwrap();
|
||||
let path = std::env::temp_dir().join(format!("solidcraft-saved-retries-{}.solidcraft", std::process::id()));
|
||||
std::fs::write(&path, &bytes).unwrap();
|
||||
let mut reopened = Session::default();
|
||||
reopened.execute("doc.open", &json!({"path": path})).unwrap();
|
||||
std::fs::remove_file(&path).unwrap();
|
||||
assert!(reopened.model.results.iter().all(|r| r.ms == session.model.results[0].ms), "taken from the file, not evaluated");
|
||||
let d = &reopened.model.results[0].boolean_diagnostics;
|
||||
assert_eq!(d.events.len(), 1, "{d:?}");
|
||||
assert!(d.rejected.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_model_needs_no_meshes_and_is_adopted_only_for_its_document() {
|
||||
let mut session = Session::new(Document::new("Saved model"));
|
||||
|
||||
Reference in New Issue
Block a user