Lines
100 %
Functions
92.5 %
Branches
//! A whole-state digest of a `CompileContext`, for rollback tests. Every field
//! is destructured, so a new field fails to compile until it is covered.
use std::collections::{HashMap, HashSet};
use std::fmt::Debug;
use std::fmt::Write as _;
use wasm_encoder::Encode;
use super::CompileContext;
fn section(out: &mut String, name: &str, value: &impl Encode) {
let mut bytes = Vec::new();
value.encode(&mut bytes);
let _ = writeln!(out, "{name}: {bytes:?}");
}
fn map<K: Debug, V: Debug>(out: &mut String, name: &str, value: &HashMap<K, V>) {
let mut entries: Vec<String> = value.iter().map(|entry| format!("{entry:?}")).collect();
entries.sort();
let _ = writeln!(out, "{name}: {entries:?}");
fn set<K: Debug>(out: &mut String, name: &str, value: &HashSet<K>) {
fn debug(out: &mut String, name: &str, value: &impl Debug) {
let _ = writeln!(out, "{name}: {value:?}");
impl CompileContext {
pub(crate) fn state_digest(&self) -> String {
let CompileContext {
types,
imports,
functions,
memories,
tags,
globals,
global_count,
exports,
data,
codes,
data_count,
type_count,
tag_count,
import_func_count,
local_func_count,
type_cache,
func_names,
host_fns,
pending_helpers,
next_local,
local_types,
serializer,
closures,
declared_funcs,
monomorphs,
nomi_error_tag,
ids,
inlining_stack,
inlining_set,
block_labels,
hidden_labels,
outer_labels,
tag_frames,
unwind_frames,
block_joins,
stats,
read_checks,
struct_layouts,
struct_serial,
struct_serial_base,
instance_globals,
instances_init,
} = self;
let mut out = String::new();
section(&mut out, "types", types);
section(&mut out, "imports", imports);
section(&mut out, "functions", functions);
section(&mut out, "memories", memories);
section(&mut out, "tags", tags);
section(&mut out, "globals", globals);
section(&mut out, "exports", exports);
section(&mut out, "data", data);
section(&mut out, "codes", codes);
for (index, helper) in pending_helpers.iter().enumerate() {
section(&mut out, &format!("pending_helper[{index}]"), helper);
let counters = (
);
debug(&mut out, "counters", &counters);
let mut caches: Vec<String> = type_cache
.iter()
.map(|(params, results)| {
let mut inner: Vec<String> =
results.iter().map(|entry| format!("{entry:?}")).collect();
inner.sort();
format!("{params:?} -> {inner:?}")
})
.collect();
caches.sort();
debug(&mut out, "type_cache", &caches);
map(&mut out, "func_names", func_names);
map(&mut out, "host_fns", host_fns);
map(&mut out, "read_checks", read_checks);
map(&mut out, "struct_layouts", struct_layouts);
debug(&mut out, "struct_serial", struct_serial);
debug(&mut out, "struct_serial_base", struct_serial_base);
debug(&mut out, "instance_globals", instance_globals);
debug(&mut out, "instances_init", instances_init);
set(&mut out, "inlining_set", inlining_set);
debug(&mut out, "local_types", local_types);
debug(&mut out, "serializer", serializer);
debug(&mut out, "closures", closures);
debug(&mut out, "declared_funcs", declared_funcs);
debug(&mut out, "monomorphs", monomorphs);
debug(&mut out, "nomi_error_tag", nomi_error_tag);
debug(&mut out, "ids", ids);
debug(&mut out, "inlining_stack", inlining_stack);
debug(&mut out, "block_labels", block_labels);
debug(&mut out, "hidden_labels", hidden_labels);
debug(&mut out, "outer_labels", outer_labels);
debug(&mut out, "tag_frames", tag_frames);
debug(&mut out, "unwind_frames", unwind_frames);
debug(&mut out, "block_joins", block_joins);
debug(&mut out, "stats", stats);
out