From 904511f62e7cf5e78d1034c63fdbded57c5632ce Mon Sep 17 00:00:00 2001 From: tignear Date: Tue, 27 Oct 2026 21:15:09 +0900 Subject: [PATCH] feat(sv)!: support per-object constraint modes Implement IEEE 1800-2023 18.9 constraint_mode getters and void setters for named blocks, plus the object-wide setter. All modes start enabled; aliases share them and different objects do not. Preserve inherited block indices when a derived constraint overrides the same name, so base-handle mode calls control the effective block. Object-wide changes include dynamic subclasses. Store constraint modes separately from temporary rand_mode selections. Apply named-block modes after pre_randomize, leave inline predicates unconditional, and preserve hook updates on failed solves. Include modes in object copies, heap comparison and checkpoint restoration. Diagnose unknown blocks, invalid getter/setter calls, builtin overrides and unsupported static/external blocks. Add shared cases for modes, aliases, hooks, inheritance, dynamic dispatch and inline/check-only solves, plus a checkpoint regression. Retain the observed Icarus constraint-declaration limitation and Verilator bit-argument/override mode discrepancies with IEEE clause references and exact failure evidence. Package-base randomize dispatch remains the separate existing #1892 limitation; mode calls across that boundary are covered without claiming that fix. Validation: 400 class/backend tests; 847 analyzer tests (3 existing ignores) and analyzer doctests; 27 heap tests; 4 retained-report tests; affected-crate Clippy and formatting. Verilator passes the hook case and exposes three reviewed disagreements; Icarus rejects the four constraint cases. The pinned xezim executable is not installed locally, so that adapter was not run. The upstream constraint_mode positive case uses UVM; expectations stay unchanged. BREAKING CHANGE: serialized heap/checkpoint images contain persistent constraint mode state; regenerate images produced by earlier builds. Ordinary struct fields named constraint_mode retain normal member lookup, including nested fields and class-local structs. The shared regression passes all five backends, Verilator and Icarus; analyzer tests and clippy also pass. Change-Id: Ibecc00dc19b68d9340e4cbf511410478a9b57345 --- .../src/lowering/ff/objects.rs | 20 +++ crates/celox-heap/src/objects.rs | 52 +++++++ crates/celox-heap/src/ops.rs | 14 ++ crates/celox-heap/src/randomization.rs | 14 ++ crates/celox-sv-analyzer/src/ast/classes.rs | 14 +- .../src/ast/classes/constraints.rs | 9 +- .../src/ast/expression_binding.rs | 5 +- .../src/ast/expression_binding/direct.rs | 6 + .../src/ast/expression_binding/objects.rs | 117 +++++++++++++++ .../celox-sv-analyzer/src/ast/procedural.rs | 9 +- .../celox-sv-analyzer/src/system_functions.rs | 7 +- crates/celox-sv-analyzer/src/tests.rs | 45 ++++++ crates/celox-test-suite/LIMITATIONS.md | 10 ++ .../celox-test-suite/src/sv/cases/class.vtest | 140 ++++++++++++++++++ .../repros/sv_constraint_modes.json | 53 +++++++ .../verification/sv/icarus/class.json | 88 +++++++++++ .../verification/sv/limitations.json | 52 +++++++ .../verification/sv/verilator/class.json | 66 +++++++++ .../tests/frontends/systemverilog/class.rs | 53 +++++++ docs/guide/systemverilog-reference.md | 13 +- docs/ja/guide/systemverilog-reference.md | 13 +- 21 files changed, 786 insertions(+), 14 deletions(-) create mode 100644 crates/celox-test-suite/verification/repros/sv_constraint_modes.json diff --git a/crates/celox-frontend-sv/src/lowering/ff/objects.rs b/crates/celox-frontend-sv/src/lowering/ff/objects.rs index d7d455b940c..96a7134c5d9 100644 --- a/crates/celox-frontend-sv/src/lowering/ff/objects.rs +++ b/crates/celox-frontend-sv/src/lowering/ff/objects.rs @@ -52,6 +52,24 @@ impl Ff<'_, '_> { self.heap_call(ops::OBJECT_RANDOMIZE_INPUTS, &[object, program, inputs]) } } + ObjectOp::ConstraintModeGet(index) => { + let object = self.handle(&args[0])?; + self.heap_call( + ops::encode(ops::OBJECT_CONSTRAINT_MODE_GET, u64::from(*index)), + &[object], + ) + } + ObjectOp::ConstraintModeSet(index) => { + let object = self.handle(&args[0])?; + let enabled = self.integer_of_width(&args[1], 1, false)?; + self.heap_call( + ops::encode( + ops::OBJECT_CONSTRAINT_MODE_SET, + u64::from(index.unwrap_or(u32::MAX)), + ), + &[object, enabled], + ) + } ObjectOp::Container { .. } => unreachable!("handled by container_call"), ObjectOp::New { class, @@ -161,6 +179,8 @@ impl Ff<'_, '_> { HandleProperty::Object => celox_design::ValueKind::ObjRef, }), ObjectOp::Randomize(_) + | ObjectOp::ConstraintModeGet(_) + | ObjectOp::ConstraintModeSet(_) | ObjectOp::Store(_) | ObjectOp::ClassOf | ObjectOp::Random diff --git a/crates/celox-heap/src/objects.rs b/crates/celox-heap/src/objects.rs index 4a55a8f4f2f..f42213cff1e 100644 --- a/crates/celox-heap/src/objects.rs +++ b/crates/celox-heap/src/objects.rs @@ -16,6 +16,8 @@ pub(crate) struct Object { class: u32, random_state: u64, random_modes: RandomModes, + constraint_default: bool, + constraint_modes: fxhash::FxHashMap, saved_random_modes: Vec, /// Remaining domain indices for each randc property, keyed by byte offset. random_cycles: fxhash::FxHashMap>, @@ -90,6 +92,8 @@ impl Heap { class, random_state: 0, random_modes: RandomModes::default(), + constraint_default: true, + constraint_modes: Default::default(), saved_random_modes: Vec::new(), random_cycles: Default::default(), bytes: vec![0; size].into(), @@ -100,6 +104,28 @@ impl Heap { handle } + /// Persistent per-object constraint modes (IEEE 1800-2023 18.9). + pub fn constraint_mode(&mut self, handle: Handle, index: u32) -> bool { + self.object_mut(handle).is_some_and(|object| { + object + .constraint_modes + .get(&index) + .copied() + .unwrap_or(object.constraint_default) + }) + } + + pub fn set_constraint_mode(&mut self, handle: Handle, index: Option, enabled: bool) { + if let Some(object) = self.object_mut(handle) { + if let Some(index) = index { + object.constraint_modes.insert(index, enabled); + } else { + object.constraint_modes.clear(); + object.constraint_default = enabled; + } + } + } + /// Seed an object's independent random stream (IEEE 1800-2023 18.13.3). pub fn seed_object(&mut self, handle: Handle, seed: u32) { if let Some(object) = self.object_mut(handle) { @@ -319,6 +345,32 @@ mod tests { assert_eq!(heap.class_of(NULL), 0); } + #[test] + fn constraint_modes_are_object_state_and_do_not_follow_random_mode_scopes() { + let mut heap = Heap::new(); + let handle = heap.new_object(1, 4); + assert!(heap.constraint_mode(handle, 0)); + let original = heap.clone(); + heap.set_constraint_mode(handle, None, false); + heap.set_constraint_mode(handle, Some(1), true); + assert!(!heap.same_contents(&original)); + heap.push_random_modes(handle); + heap.set_constraint_mode(handle, Some(0), true); + heap.pop_random_modes(handle); + assert!(heap.constraint_mode(handle, 0)); + assert!(heap.constraint_mode(handle, 1)); + assert!(!heap.constraint_mode(handle, 2)); + let bytes = serde_json::to_vec(&heap.objects[&handle]).unwrap(); + let restored: Object = serde_json::from_slice(&bytes).unwrap(); + assert_eq!(restored, heap.objects[&handle]); + let copy = heap.copy_object(handle); + heap.set_constraint_mode(copy, None, true); + assert!(heap.constraint_mode(copy, 2)); + assert!(!heap.constraint_mode(handle, 2)); + assert!(!heap.constraint_mode(NULL, 0)); + assert_eq!(heap.take_fault(), Some(Fault::NullDereference)); + } + #[test] fn copies_are_shallow() { let mut heap = Heap::new(); diff --git a/crates/celox-heap/src/ops.rs b/crates/celox-heap/src/ops.rs index a4694a4fcf2..333b3cc25cb 100644 --- a/crates/celox-heap/src/ops.rs +++ b/crates/celox-heap/src/ops.rs @@ -88,6 +88,9 @@ pub const OBJECT_RANDOMIZE: u64 = 64; /// Program b for object a; c is an input buffer (check-only byte followed by /// big-endian u64 values). The buffer is consumed, including on failure. pub const OBJECT_RANDOMIZE_INPUTS: u64 = 65; +/// Constraint index is encoded in the parameter; set-all uses u32::MAX. +pub const OBJECT_CONSTRAINT_MODE_GET: u64 = 66; +pub const OBJECT_CONSTRAINT_MODE_SET: u64 = 67; /// The opcode word of `op` with parameter `parameter`. pub const fn encode(op: u64, parameter: u64) -> u64 { @@ -248,6 +251,17 @@ impl Heap { 0 } OBJECT_CHECK => u64::from(self.check_object(a as Handle, parameter as u32)), + OBJECT_CONSTRAINT_MODE_GET => { + self.constraint_mode(a as Handle, parameter as u32) as u64 + } + OBJECT_CONSTRAINT_MODE_SET => { + self.set_constraint_mode( + a as Handle, + (parameter != u64::from(u32::MAX)).then_some(parameter as u32), + b & 1 != 0, + ); + 0 + } OBJECT_MODE_GET => { u64::from(self.random_mode(a as Handle, parameter as u32, parameter >> 32 != 0)) } diff --git a/crates/celox-heap/src/randomization.rs b/crates/celox-heap/src/randomization.rs index f0e2ade8091..57a3f0d27d7 100644 --- a/crates/celox-heap/src/randomization.rs +++ b/crates/celox-heap/src/randomization.rs @@ -14,6 +14,11 @@ pub struct Field { #[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub enum Expr { + /// Top-level named block predicate; inline predicates remain unconditional. + Enabled { + index: u32, + value: Box, + }, Literal(u32, u64), Field(usize), /// Read-only scalar supplied by this call, never a solver variable. @@ -57,6 +62,7 @@ fn boolean(value: Term) -> Term { impl Expr { fn term(&self, fields: &[Term], inputs: &[u64]) -> Result { Ok(match self { + Self::Enabled { .. } => return Err("nested constraint mode predicate".into()), Self::Literal(width, value) => bv(*width, *value), Self::Input { index, width } => { if !(1..=64).contains(width) { @@ -221,6 +227,14 @@ impl Heap { terms.push(term); } for constraint in &program.constraints { + let constraint = if let Expr::Enabled { index, value } = constraint { + if !self.constraint_mode(handle, *index) { + continue; + } + value.as_ref() + } else { + constraint + }; formula = and(formula, truth(constraint.term(&terms, inputs)?)); } let seed = if projection.is_empty() { diff --git a/crates/celox-sv-analyzer/src/ast/classes.rs b/crates/celox-sv-analyzer/src/ast/classes.rs index 44f89baec5f..49f03400b4c 100644 --- a/crates/celox-sv-analyzer/src/ast/classes.rs +++ b/crates/celox-sv-analyzer/src/ast/classes.rs @@ -778,7 +778,10 @@ pub(super) fn class( for method in &declaration.methods { let subroutine = native.subroutine(method.subroutine); let method_name = instances::normalize_identifier(&subroutine.name.spelling); - if matches!(method_name.as_str(), "randomize" | "srandom" | "rand_mode") { + if matches!( + method_name.as_str(), + "randomize" | "srandom" | "rand_mode" | "constraint_mode" + ) { return Err(unsupported( "overriding built-in class randomization methods", )); @@ -868,7 +871,7 @@ pub(super) fn class( .unwrap_or_default(); for block in &declaration.constraints { let block_name = block.name.spelling.clone(); - constraints.retain(|(name, _)| *name != block_name); + let expressions = block .expressions .as_ref() @@ -879,7 +882,12 @@ pub(super) fn class( .map(|&id| constraints::bind(id, tree, &properties, env)) .collect() }); - constraints.push((block_name, expressions)); + // Constraint indices survive overrides, including calls via base handles. + if let Some((_, inherited)) = constraints.iter_mut().find(|(name, _)| *name == block_name) { + *inherited = expressions; + } else { + constraints.push((block_name, expressions)); + } } let class = Rc::new(Class { name: name.to_owned(), diff --git a/crates/celox-sv-analyzer/src/ast/classes/constraints.rs b/crates/celox-sv-analyzer/src/ast/classes/constraints.rs index 9ecf0d40229..debb7a66df3 100644 --- a/crates/celox-sv-analyzer/src/ast/classes/constraints.rs +++ b/crates/celox-sv-analyzer/src/ast/classes/constraints.rs @@ -350,12 +350,17 @@ impl Class { }); } let mut constraints = Vec::new(); - for (_, block) in &self.constraints { + for (index, (_, block)) in self.constraints.iter().enumerate() { constraints.extend( block .as_ref() .map_err(|reason| unsupported(format!("constraints: {reason}")))? - .clone(), + .iter() + .cloned() + .map(|value| ConstraintExpr::Enabled { + index: index as u32, + value: Box::new(value), + }), ); } Ok(Program { diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding.rs b/crates/celox-sv-analyzer/src/ast/expression_binding.rs index f080a738c02..26416384f7c 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding.rs @@ -17,8 +17,9 @@ pub(super) use lvalues::{net_lvalue, variable_lvalue}; pub(super) use objects::{ Cast as ObjectCast, Receiver as ObjectReceiver, cast as object_cast, check_access as check_member_access, check_assignment as check_handle_assignment, - constructor as object_constructor, method as object_method, property as object_property, - rand_mode_call as object_rand_mode_call, receiver as object_receiver, this as object_this, + constraint_mode_call as object_constraint_mode_call, constructor as object_constructor, + method as object_method, property as object_property, rand_mode_call as object_rand_mode_call, + receiver as object_receiver, this as object_this, }; pub(super) use strings::{ call as string_call, method as string_method, native_string, to_string as string_operand, diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs index 736a4859252..05536104d71 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs @@ -304,6 +304,12 @@ pub(in crate::ast) fn bind_value( values.push(value); continue; } + if let Some(call) = + objects::constraint_mode_call(tree, id, native, dimensions, false)? + { + values.push(call); + continue; + } if let Some(call) = objects::rand_mode_call(tree, id, native, dimensions, false)? { values.push(call); continue; diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs index 714fae46d06..a3d1c036622 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs @@ -829,6 +829,123 @@ pub(super) fn random_selection( ))) } +/// Constraint block modes are independent of member rand_mode and inline constraints (18.9). +pub(in crate::ast) fn constraint_mode_call( + tree: &AnalysisContext<'_>, + id: ExprId, + native: &Declarations, + dimensions: &PackedDimensions, + allow_set: bool, +) -> Converted> { + let (callee, args) = match &native.expression(ungroup(id, native)).kind { + ExprKind::Call { + expression, + arguments, + } => (*expression, arguments.as_slice()), + _ => (id, &[][..]), + }; + let (owner, block, handle) = match &native.expression(ungroup(callee, native)).kind { + ExprKind::Member { + expression, + separator, + name, + } if separator == "." && name.spelling == "constraint_mode" => { + if let Some(owner) = native_class(tree, *expression, native, dimensions) { + ( + owner, + None, + receiver(tree, Some(*expression), native, dimensions)?, + ) + } else { + match &native.expression(ungroup(*expression, native)).kind { + ExprKind::Member { + expression: object, + separator, + name, + } if separator == "." => { + let Some(owner) = native_class(tree, *object, native, dimensions) else { + return Ok(None); + }; + ( + owner, + Some(name.spelling.clone()), + receiver(tree, Some(*object), native, dimensions)?, + ) + } + ExprKind::Name(name) + if scope_class(dimensions).is_some() + && dimensions.get(THIS).is_some() + && dimensions.get(&name.spelling).is_none() => + { + ( + scope_class(dimensions).unwrap(), + Some(name.spelling.clone()), + this(), + ) + } + _ => return Ok(None), + } + } + } + ExprKind::Name(name) + if name.spelling == "constraint_mode" + && dimensions.get("constraint_mode").is_none() => + { + let Some(owner) = scope_class(dimensions) else { + return Ok(None); + }; + if dimensions.get(THIS).is_none() { + return Err(unsupported("constraint_mode requires an object receiver")); + } + (owner, None, this()) + } + _ => return Ok(None), + }; + let class = class(tree, dimensions, &owner)?; + if class.constraints.iter().any(|(_, block)| { + block + .as_ref() + .is_err_and(|reason| reason == "unsupported constraint block form") + }) { + return Err(unsupported( + "constraint_mode for external or static constraint blocks", + )); + } + let index = block + .map(|name| { + class + .constraints + .iter() + .position(|(block, _)| *block == name) + .map(|index| index as u32) + .ok_or_else(|| unsupported(format!("unknown constraint block {name}"))) + }) + .transpose()?; + if args.is_empty() { + let index = index + .ok_or_else(|| unsupported("constraint_mode getter requires one named constraint"))?; + return Ok(Some(classes::object_call( + ObjectOp::ConstraintModeGet(index), + vec![handle], + ))); + } + if !allow_set { + return Err(unsupported( + "constraint_mode setter is void and cannot be used as a value", + )); + } + if args.len() != 1 || args[0].name.is_some() || args[0].value.is_none() { + return Err(unsupported( + "constraint_mode setter requires one on_off argument", + )); + } + let enabled = bind_value(args[0].value.unwrap(), native, tree, dimensions, None)?; + Ok(Some(classes::object_call( + ObjectOp::ConstraintModeSet(index), + vec![handle, enabled], + ))) +} + /// Bind rand_mode's void setter and integer getter separately (18.8). /// A getter requires one random property; only the setter accepts an object. pub(in crate::ast) fn rand_mode_call( diff --git a/crates/celox-sv-analyzer/src/ast/procedural.rs b/crates/celox-sv-analyzer/src/ast/procedural.rs index 7dd29c43dee..35249e4e24e 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural.rs @@ -762,9 +762,12 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { root: celox_sv_syntax::ExprId, ) -> Result, AnalyzerError> { let native = self.tree.declarations(); - if let Some(mut call) = - expression_binding::object_rand_mode_call(self.tree, root, native, &self.dims, true)? - { + if let Some(mut call) = expression_binding::object_constraint_mode_call( + self.tree, root, native, &self.dims, true, + )? + .or(expression_binding::object_rand_mode_call( + self.tree, root, native, &self.dims, true, + )?) { self.rename_expr(&mut call); return Ok(Some(match call { Expr::Call { diff --git a/crates/celox-sv-analyzer/src/system_functions.rs b/crates/celox-sv-analyzer/src/system_functions.rs index e5234516742..eb24e3258ec 100644 --- a/crates/celox-sv-analyzer/src/system_functions.rs +++ b/crates/celox-sv-analyzer/src/system_functions.rs @@ -961,6 +961,8 @@ pub enum ObjectOp { Check(u32), /// Query or set the random mode of a property at its byte offset. ModeGet(u32, bool), + ConstraintModeGet(u32), + ConstraintModeSet(Option), ModeSet(u32), ModePush, ModePop, @@ -992,12 +994,13 @@ impl ObjectOp { Self::Randomize(_) | Self::Seed | Self::Check(_) + | Self::ConstraintModeSet(_) | Self::ModeSet(_) | Self::ModePush | Self::ModePop | Self::ModeSelect(..) | Self::ModeSelected(_) => (32, false), - Self::ModeGet(..) => (32, true), + Self::ModeGet(..) | Self::ConstraintModeGet(_) => (32, true), Self::Load(field) => (field.width as usize, field.signed), Self::New { .. } | Self::ClassOf | Self::Store(_) | Self::Copy => (32, false), } @@ -1018,6 +1021,8 @@ impl fmt::Display for ObjectOp { Self::Seed => "object random seed", Self::Check(_) => "object receiver check", Self::ModeGet(..) => "random mode query", + Self::ConstraintModeGet(_) => "constraint mode query", + Self::ConstraintModeSet(_) => "constraint mode update", Self::ModeSet(_) => "random mode update", Self::ModePush => "save random modes", Self::ModePop => "restore random modes", diff --git a/crates/celox-sv-analyzer/src/tests.rs b/crates/celox-sv-analyzer/src/tests.rs index 641dbb8670d..7c5873c72d4 100644 --- a/crates/celox-sv-analyzer/src/tests.rs +++ b/crates/celox-sv-analyzer/src/tests.rs @@ -7413,3 +7413,48 @@ fn class_inline_randomize_static_names_do_not_capture_caller_locals() { } } } + +#[test] +fn constraint_mode_rejects_invalid_calls() { + for (statement, expected) in [ + ("c.constraint_mode();", "getter requires"), + ("c.missing.constraint_mode(0);", "unknown constraint"), + ("c.x.constraint_mode();", "unknown constraint"), + ("result = c.rule.constraint_mode(1);", "setter is void"), + ("c.rule.constraint_mode(1, 0);", "one on_off"), + ] { + let source = format!( + "module Top; class C; rand bit [3:0] x; constraint rule {{ x == 1; }} endclass C c; int result; initial begin c = new; {statement} end endmodule" + ); + let error = analyze_source(&source, Path::new("constraint_mode.sv")) + .unwrap_err() + .to_string(); + assert!(error.contains(expected), "{statement}: {error}"); + } +} + +#[test] +fn constraint_mode_cannot_be_overridden() { + let source = "module Top; class C; function void constraint_mode(bit flag); endfunction endclass C c; initial c = new; endmodule"; + let error = analyze_source(source, Path::new("constraint_mode_override.sv")) + .unwrap_err() + .to_string(); + assert!(error.contains("overriding"), "{error}"); +} + +#[test] +fn constraint_mode_outside_classes_remains_an_ordinary_function() { + let source = "module Top(output int value); function int constraint_mode(); return 42; endfunction initial value = constraint_mode(); endmodule"; + analyze_source(source, Path::new("constraint_mode_function.sv")).unwrap(); +} + +#[test] +fn constraint_mode_names_do_not_intercept_struct_members() { + for source in [ + "module Top(output int value); struct packed { int constraint_mode; } s; initial value = s.constraint_mode; endmodule", + "module Top(output int value); struct packed { struct packed { int constraint_mode; } child; } s; initial value = s.child.constraint_mode; endmodule", + "module Top(output int value); class C; function int f(); struct packed { int constraint_mode; } s; s.constraint_mode=37; return s.constraint_mode; endfunction endclass C c; initial begin c=new; value=c.f(); end endmodule", + ] { + analyze_source(source, Path::new("constraint_mode_struct.sv")).unwrap(); + } +} diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index 4057357db90..bd95060fcb5 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -881,3 +881,13 @@ Their actual compile diagnostics are retained in [the Verilator operators report](verification/sv/verilator/operators.json); they remain executed cases rather than exclusions. Reproduce with `verify-sv-verilator --filter two_state_case_equality --jobs 1`. + +### Constraint modes + +The `class::constraint_mode_*` cases keep the assertions required by IEEE +1800-2023 18.9 and 18.5.2. Icarus 13.0 rejects constraint declarations. +Verilator 5.052 passes the pre-hook mode case, but treats integer `2` as enabled +instead of converting the setter argument to `bit` zero, and does not apply +base-handle mode changes to an overridden constraint. See +[the retained observations](verification/repros/sv_constraint_modes.json). +Celox runs these assertions on all registered backends. diff --git a/crates/celox-test-suite/src/sv/cases/class.vtest b/crates/celox-test-suite/src/sv/cases/class.vtest index 185ea735a99..15333f44d7c 100644 --- a/crates/celox-test-suite/src/sv/cases/class.vtest +++ b/crates/celox-test-suite/src/sv/cases/class.vtest @@ -2339,3 +2339,143 @@ module Top(output bit done); endmodule "#) (top Top) (run_until 0) (assert_eq done 1)) + +(case constraint_mode_basic + (source "constraint_mode_basic.sv" #" +module Top(output bit done); + class C; + rand bit [3:0] x; + constraint low { x == 2; } + constraint high { x == 9; } + function void enable_low(); constraint_mode(0); low.constraint_mode(1); endfunction + endclass + C c, alias_c, other; + initial begin + c = new; other = new; alias_c = c; + if (c.low.constraint_mode() != 1 || c.high.constraint_mode() != 1) $fatal(1, "initial modes"); + c.x = 7; + if (c.randomize() || c.x != 7) $fatal(1, "initial contradiction"); + alias_c.high.constraint_mode(0); + if ((c.high.constraint_mode() != 0) || (other.high.constraint_mode() == 0)) $fatal(1, "alias isolation"); + if (!c.randomize() || c.x != 2) $fatal(1, "disabled block"); + c.constraint_mode(0); + if (!(c.randomize() with { x == 5; }) || c.x != 5) $fatal(1, "inline remains active"); + c.high.constraint_mode(1); + if (c.randomize(null)) $fatal(1, "check only fails"); + if (!c.randomize() || c.x != 9 || !c.randomize(null)) $fatal(1, "check only succeeds"); + c.enable_low(); + if (!c.randomize() || c.x != 2) $fatal(1, "implicit receiver"); + c.low.constraint_mode(2); + if (c.low.constraint_mode() != 0) $fatal(1, "bit conversion"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constraint_mode_inheritance + (source "constraint_mode_inheritance.sv" #" +package pkg; + class Base; + rand bit [3:0] x, y; + constraint first { x == 1; } + constraint second { y == 3; } + function void disable_first(); first.constraint_mode(0); endfunction + endclass +endpackage +module Top(output bit done); + class Derived extends pkg::Base; + constraint first { x == 7; } + constraint third { y == 5; } + endclass + Derived d; + pkg::Base b; + initial begin + d = new; b = d; + b.constraint_mode(0); + if ((d.first.constraint_mode() != 0) || (d.second.constraint_mode() != 0) || (d.third.constraint_mode() != 0)) $fatal(1, "dynamic all"); + b.first.constraint_mode(1); + d.third.constraint_mode(1); + if ((d.first.constraint_mode() == 0) || (d.second.constraint_mode() != 0) || (d.third.constraint_mode() == 0)) $fatal(1, "override modes"); + // Package-base randomize dispatch is tracked separately in #1892. + if (!d.randomize()) $fatal(1, "override solve"); + if (d.x != 7 || d.y != 5) $fatal(1, "override values x=%d y=%d", d.x, d.y); + b.disable_first(); + if ((d.first.constraint_mode() != 0) || (d.third.constraint_mode() == 0)) $fatal(1, "inherited method"); + if (!(d.randomize() with { x == 2; }) || d.x != 2 || d.y != 5) $fatal(1, "disabled override"); + b.constraint_mode(1); + if ((d.first.constraint_mode() == 0) || (d.second.constraint_mode() == 0) || (d.third.constraint_mode() == 0)) $fatal(1, "all enabled"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constraint_mode_hooks + (source "constraint_mode_hooks.sv" #" +module Top(output bit done); + class C; + rand bit [3:0] x; + bit disable_c; + constraint c { x == 2; } + function void pre_randomize(); c.constraint_mode(!disable_c); endfunction + endclass + C p; + initial begin + p = new; p.disable_c = 1; + if (!(p.randomize(x) with { x == 7; }) || p.x != 7) $fatal(1, "pre-hook disable"); + if (p.c.constraint_mode() != 0) $fatal(1, "mode survives selected randomize"); + p.disable_c = 0; + if (p.randomize(x) with { x == 7; }) $fatal(1, "pre-hook enable"); + if ((p.c.constraint_mode() == 0) || p.x != 7) $fatal(1, "failed solve mode"); + if (!p.randomize() || p.x != 2) $fatal(1, "subsequent solve"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constraint_mode_base_dispatch + (source "constraint_mode_base_dispatch.sv" #" +module Top(output bit done); + class Base; + rand bit [3:0] x, y; + constraint a { x == 1; } + constraint b { y == 3; } + endclass + class Derived extends Base; + constraint a { x == 7; } + constraint c { y == 5; } + endclass + Base b; + Derived d; + initial begin + d = new; b = d; + b.b.constraint_mode(0); + if (!b.randomize() || d.x != 7 || d.y != 5) $fatal(1, "dynamic override"); + b.a.constraint_mode(0); + if (!(b.randomize() with { x == 2; }) || d.x != 2 || d.y != 5) $fatal(1, "inline dynamic modes"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constraint_mode_ordinary_struct_members + (source "constraint_mode_struct.sv" #" + module Top(input int data, output int direct_value, nested_value); + struct packed { int constraint_mode; } direct_data; + struct packed { struct packed { int constraint_mode; } child; } nested_data; + always_comb begin + direct_data.constraint_mode = data; + nested_data.child.constraint_mode = data + 1; + direct_value = direct_data.constraint_mode; + nested_value = nested_data.child.constraint_mode; + end + endmodule + "#) + (top Top) + (for value (list 0 37 255) + (modify (set data value)) + (assert_eq direct_value value) + (assert_eq nested_value (+ value 1)))) diff --git a/crates/celox-test-suite/verification/repros/sv_constraint_modes.json b/crates/celox-test-suite/verification/repros/sv_constraint_modes.json new file mode 100644 index 00000000000..ef9e4f6cc36 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_constraint_modes.json @@ -0,0 +1,53 @@ +{ + "specification": "IEEE 1800-2023 18.9, 18.5.2", + "observations": [ + { + "tool": "icarus", + "case": "class::constraint_mode_base_dispatch", + "status": "compile_error", + "log": "Icarus build exit status: 8; see /build.log\n/source_0.sv:5: sorry: Constraint declarations not supported.\n/source_0.sv:6: sorry: Constraint declarations not supported.\n/source_0.sv:9: sorry: Constraint declarations not supported.\n/source_0.sv:10: sorry: Constraint declarations not supported.\n/source_0.sv:19: syntax error\n/source_0.sv:19: error: Operand of unary ! is not a primary expression.\n/source_0.sv:19: error: Malformed statement\n/source_0.sv:19: error: Malformed conditional expression.\n" + }, + { + "tool": "icarus", + "case": "class::constraint_mode_basic", + "status": "compile_error", + "log": "Icarus build exit status: 6; see /build.log\n/source_0.sv:5: sorry: Constraint declarations not supported.\n/source_0.sv:6: sorry: Constraint declarations not supported.\n/source_0.sv:19: syntax error\n/source_0.sv:19: error: Operand of unary ! is not a primary expression.\n/source_0.sv:19: error: Malformed statement\n/source_0.sv:19: error: Malformed conditional expression.\n" + }, + { + "tool": "icarus", + "case": "class::constraint_mode_hooks", + "status": "compile_error", + "log": "Icarus build exit status: 7; see /build.log\n/source_0.sv:6: sorry: Constraint declarations not supported.\n/source_0.sv:12: syntax error\n/source_0.sv:12: error: Operand of unary ! is not a primary expression.\n/source_0.sv:12: error: Malformed statement\n/source_0.sv:12: error: Malformed conditional expression.\n/source_0.sv:15: syntax error\n/source_0.sv:15: error: Malformed conditional expression.\n" + }, + { + "tool": "icarus", + "case": "class::constraint_mode_inheritance", + "status": "compile_error", + "log": "Icarus build exit status: 8; see /build.log\n/source_0.sv:5: sorry: Constraint declarations not supported.\n/source_0.sv:6: sorry: Constraint declarations not supported.\n/source_0.sv:12: sorry: Constraint declarations not supported.\n/source_0.sv:13: sorry: Constraint declarations not supported.\n/source_0.sv:29: syntax error\n/source_0.sv:29: error: Operand of unary ! is not a primary expression.\n/source_0.sv:29: error: Malformed statement\n/source_0.sv:29: error: Malformed conditional expression.\n" + }, + { + "tool": "verilator", + "case": "class::constraint_mode_base_dispatch", + "status": "runtime_error", + "log": "native testbench failed: exit status: 1; see runtime.log and protocol.log\n" + }, + { + "tool": "verilator", + "case": "class::constraint_mode_basic", + "status": "runtime_error", + "log": "native testbench failed: exit status: 1; see runtime.log and protocol.log\n" + }, + { + "tool": "verilator", + "case": "class::constraint_mode_hooks", + "status": "passed", + "log": "" + }, + { + "tool": "verilator", + "case": "class::constraint_mode_inheritance", + "status": "runtime_error", + "log": "native testbench failed: exit status: 1; see runtime.log and protocol.log\n" + } + ] +} diff --git a/crates/celox-test-suite/verification/sv/icarus/class.json b/crates/celox-test-suite/verification/sv/icarus/class.json index 05ab75a150e..662bbf60606 100644 --- a/crates/celox-test-suite/verification/sv/icarus/class.json +++ b/crates/celox-test-suite/verification/sv/icarus/class.json @@ -576,6 +576,94 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "Icarus rejects constraint declarations and inline randomize with blocks before elaboration. IEEE 1800-2023 18.5 and 18.7 define these constructs. Celox retains all assertions.", + "expectation": "Simulation", + "known_issue": { + "id": "sv_icarus_constraint_modes", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "reason": "Icarus rejects constraint declarations and inline randomize with blocks before elaboration. IEEE 1800-2023 18.5 and 18.7 define these constructs. Celox retains all assertions.", + "upstream": [], + "evidence": [ + "verification/repros/sv_constraint_modes.json" + ] + }, + "name": "class::constraint_mode_base_dispatch", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus rejects constraint declarations and inline randomize with blocks before elaboration. IEEE 1800-2023 18.5 and 18.7 define these constructs. Celox retains all assertions.", + "expectation": "Simulation", + "known_issue": { + "id": "sv_icarus_constraint_modes", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "reason": "Icarus rejects constraint declarations and inline randomize with blocks before elaboration. IEEE 1800-2023 18.5 and 18.7 define these constructs. Celox retains all assertions.", + "upstream": [], + "evidence": [ + "verification/repros/sv_constraint_modes.json" + ] + }, + "name": "class::constraint_mode_basic", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus rejects constraint declarations and inline randomize with blocks before elaboration. IEEE 1800-2023 18.5 and 18.7 define these constructs. Celox retains all assertions.", + "expectation": "Simulation", + "known_issue": { + "id": "sv_icarus_constraint_modes", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "reason": "Icarus rejects constraint declarations and inline randomize with blocks before elaboration. IEEE 1800-2023 18.5 and 18.7 define these constructs. Celox retains all assertions.", + "upstream": [], + "evidence": [ + "verification/repros/sv_constraint_modes.json" + ] + }, + "name": "class::constraint_mode_hooks", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus rejects constraint declarations and inline randomize with blocks before elaboration. IEEE 1800-2023 18.5 and 18.7 define these constructs. Celox retains all assertions.", + "expectation": "Simulation", + "known_issue": { + "id": "sv_icarus_constraint_modes", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "reason": "Icarus rejects constraint declarations and inline randomize with blocks before elaboration. IEEE 1800-2023 18.5 and 18.7 define these constructs. Celox retains all assertions.", + "upstream": [], + "evidence": [ + "verification/repros/sv_constraint_modes.json" + ] + }, + "name": "class::constraint_mode_inheritance", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", diff --git a/crates/celox-test-suite/verification/sv/limitations.json b/crates/celox-test-suite/verification/sv/limitations.json index 3134fa38015..7de2f2a253b 100644 --- a/crates/celox-test-suite/verification/sv/limitations.json +++ b/crates/celox-test-suite/verification/sv/limitations.json @@ -2682,5 +2682,57 @@ "class::constrained_randomize_inline_input_hooks" ] } + }, + { + "id": "sv_verilator_constraint_mode_bit_argument", + "category": "simulator_disagreement", + "phase": "execute", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "reason": "IEEE 1800-2023 18.9 declares constraint_mode(bit on_off). Passing integer 2 converts to bit zero and disables the block. Verilator keeps it enabled; the regression preserves the mode query assertion.", + "upstream": [], + "evidence": [ + "verification/repros/sv_constraint_modes.json" + ], + "cases": { + "verilator": [ + "class::constraint_mode_basic" + ] + } + }, + { + "id": "sv_verilator_constraint_mode_override", + "category": "simulator_disagreement", + "phase": "execute", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "reason": "IEEE 1800-2023 18.5.2 replaces an inherited constraint with the derived block of the same name, and 18.9 permits mode control of a block in the class hierarchy. Verilator changes a separate base-block mode through a base handle: the derived mode query remains disabled after enabling the base name, or the overridden predicate remains active after disabling it. The regressions retain both getter and solve assertions.", + "upstream": [], + "evidence": [ + "verification/repros/sv_constraint_modes.json" + ], + "cases": { + "verilator": [ + "class::constraint_mode_inheritance", + "class::constraint_mode_base_dispatch" + ] + } + }, + { + "id": "sv_icarus_constraint_modes", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "reason": "Icarus rejects constraint declarations and inline randomize with blocks before elaboration. IEEE 1800-2023 18.5 and 18.7 define these constructs. Celox retains all assertions.", + "upstream": [], + "evidence": [ + "verification/repros/sv_constraint_modes.json" + ], + "cases": { + "icarus": [ + "class::constraint_mode_base_dispatch", + "class::constraint_mode_basic", + "class::constraint_mode_hooks", + "class::constraint_mode_inheritance" + ] + } } ] diff --git a/crates/celox-test-suite/verification/sv/verilator/class.json b/crates/celox-test-suite/verification/sv/verilator/class.json index 2cf1b0997f6..c574f51eb23 100644 --- a/crates/celox-test-suite/verification/sv/verilator/class.json +++ b/crates/celox-test-suite/verification/sv/verilator/class.json @@ -194,6 +194,72 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "IEEE 1800-2023 18.5.2 replaces an inherited constraint with the derived block of the same name, and 18.9 permits mode control of a block in the class hierarchy. Verilator changes a separate base-block mode through a base handle: the derived mode query remains disabled after enabling the base name, or the overridden predicate remains active after disabling it. The regressions retain both getter and solve assertions.", + "expectation": "Simulation", + "known_issue": { + "id": "sv_verilator_constraint_mode_override", + "category": "simulator_disagreement", + "phase": "execute", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "reason": "IEEE 1800-2023 18.5.2 replaces an inherited constraint with the derived block of the same name, and 18.9 permits mode control of a block in the class hierarchy. Verilator changes a separate base-block mode through a base handle: the derived mode query remains disabled after enabling the base name, or the overridden predicate remains active after disabling it. The regressions retain both getter and solve assertions.", + "upstream": [], + "evidence": [ + "verification/repros/sv_constraint_modes.json" + ] + }, + "name": "class::constraint_mode_base_dispatch", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "IEEE 1800-2023 18.9 declares constraint_mode(bit on_off). Passing integer 2 converts to bit zero and disables the block. Verilator keeps it enabled; the regression preserves the mode query assertion.", + "expectation": "Simulation", + "known_issue": { + "id": "sv_verilator_constraint_mode_bit_argument", + "category": "simulator_disagreement", + "phase": "execute", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "reason": "IEEE 1800-2023 18.9 declares constraint_mode(bit on_off). Passing integer 2 converts to bit zero and disables the block. Verilator keeps it enabled; the regression preserves the mode query assertion.", + "upstream": [], + "evidence": [ + "verification/repros/sv_constraint_modes.json" + ] + }, + "name": "class::constraint_mode_basic", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "IEEE 1800-2023 18.5.2 replaces an inherited constraint with the derived block of the same name, and 18.9 permits mode control of a block in the class hierarchy. Verilator changes a separate base-block mode through a base handle: the derived mode query remains disabled after enabling the base name, or the overridden predicate remains active after disabling it. The regressions retain both getter and solve assertions.", + "expectation": "Simulation", + "known_issue": { + "id": "sv_verilator_constraint_mode_override", + "category": "simulator_disagreement", + "phase": "execute", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "reason": "IEEE 1800-2023 18.5.2 replaces an inherited constraint with the derived block of the same name, and 18.9 permits mode control of a block in the class hierarchy. Verilator changes a separate base-block mode through a base handle: the derived mode query remains disabled after enabling the base name, or the overridden predicate remains active after disabling it. The regressions retain both getter and solve assertions.", + "upstream": [], + "evidence": [ + "verification/repros/sv_constraint_modes.json" + ] + }, + "name": "class::constraint_mode_inheritance", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", diff --git a/crates/celox/tests/frontends/systemverilog/class.rs b/crates/celox/tests/frontends/systemverilog/class.rs index 96ff7dad702..532dbdbab09 100644 --- a/crates/celox/tests/frontends/systemverilog/class.rs +++ b/crates/celox/tests/frontends/systemverilog/class.rs @@ -3,6 +3,9 @@ use super::*; sv_backends! { + fn constraint_mode_ordinary_struct_members(sim) { + @case "class::constraint_mode_ordinary_struct_members"; + } fn class_objects_properties_and_methods(sim) { @case "class::objects_properties_and_methods"; } } @@ -964,3 +967,53 @@ sv_backends! { sv_backends! { fn constrained_randomize_inline_input_hooks(sim) { @case "class::constrained_randomize_inline_input_hooks"; } } + +sv_backends! { + fn constraint_mode_basic(sim) { @case "class::constraint_mode_basic"; } + fn constraint_mode_inheritance(sim) { @case "class::constraint_mode_inheritance"; } + fn constraint_mode_hooks(sim) { @case "class::constraint_mode_hooks"; } +} + +sv_backends! { + fn constraint_mode_checkpoint(sim) { + @setup { let source = r#" + module Top(input bit enable, output int mode, output bit [3:0] value); + timeunit 1ps / 1ps; + class C; + rand bit [3:0] x; + constraint c { x == 2; } + endclass + C p; + initial begin + p = new; + p.constraint_mode(0); + #10 if (enable) p.c.constraint_mode(1); + #10; + mode = p.c.constraint_mode(); + if (mode) begin + if (!p.randomize()) $fatal(1, "enabled solve"); + end else begin + if (!(p.randomize() with { x == 7; })) $fatal(1, "restored solve"); + end + value = p.x; + end + endmodule + "#; } + @build celox::Simulation::from_sv_sources(vec![(source, Path::new("constraint_mode_checkpoint.sv"))], "Top").four_state(true); + sim.run_until(5).unwrap(); + let saved = sim.checkpoint().unwrap(); + let enable = sim.signal("enable"); + sim.modify(|io| io.set(enable, 1u8)).unwrap(); + sim.run_until(25).unwrap(); + assert_eq!(sim.get(sim.signal("mode")), 1u8.into()); + assert_eq!(sim.get(sim.signal("value")), 2u8.into()); + sim.restore(&saved).unwrap(); + sim.run_until(25).unwrap(); + assert_eq!(sim.get(sim.signal("mode")), 0u8.into()); + assert_eq!(sim.get(sim.signal("value")), 7u8.into()); + } +} + +sv_backends! { + fn constraint_mode_base_dispatch(sim) { @case "class::constraint_mode_base_dispatch"; } +} diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index d13b74f2436..8efcd2f127b 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -222,6 +222,17 @@ properties and skips the post-hook (18.6.3). Resource exhaustion is a runtime er This initial seeded-search policy does not guarantee a uniform distribution; distribution improvements are tracked in [#2187](https://github.com/celox-sim/celox/issues/2187). +`object.block.constraint_mode()` returns the named block's mode as a signed +`int`; `object.block.constraint_mode(bit)` changes it. The void setter +`object.constraint_mode(bit)` changes every constraint of the dynamic object, +including inherited and overridden blocks. All constraints start enabled. +Aliases share modes; other objects do not. A pre-hook's mode updates affect the +current solve and remain installed after success or failure. These modes are +independent of `rand_mode`, explicit member selection and inline `with` +predicates, which remain active. Checkpoints preserve modes (18.9, 18.5.2). +Static/external constraint blocks remain unsupported. Regenerate serialized +heap/checkpoint images from earlier builds after this heap-layout change. + Set membership (`inside`) supports scalar two-state values and inclusive bounded ranges, including expressions of other properties. Reversed ranges are empty; negation excludes the set. All operands share the membership-wide width and @@ -234,7 +245,7 @@ nested blocks. Both sides participate in solving: a required result can constrai the condition. These constructs do not choose a branch before solving. Constrained enums and `randc`, foreach/soft constraints, -`dist`, `solve before`, constraint modes, external/static blocks and typed +`dist`, `solve before`, external/static blocks and typed parameters in constraints remain unsupported. Larger unconstrained `randc` domains, static random properties and random array/object/string properties also remain unsupported. Unsupported dynamic subclasses are rejected before draws. diff --git a/docs/ja/guide/systemverilog-reference.md b/docs/ja/guide/systemverilog-reference.md index 4020fcca030..d6968d5875f 100644 --- a/docs/ja/guide/systemverilog-reference.md +++ b/docs/ja/guide/systemverilog-reference.md @@ -143,8 +143,17 @@ seedを使って解を探索し、成功時だけ対象プロパティをまと 値を保持して`0`を返し、postフックを呼びません(18.6.3)。探索予算切れは実行時エラーです。 この初期実装は一様分布を保証しません。分布の改善は[#2187](https://github.com/celox-sim/celox/issues/2187)で追跡します。 -制約付きenum・`randc`、`inside`、条件付き・foreach・soft制約、`dist`、`solve before`、 -制約モード、外部・static制約ブロック、制約中の型付きパラメーター、inline `with` は未対応です。 +`object.block.constraint_mode()` は制約ブロックの有効状態を `int` で返し、 +`object.block.constraint_mode(bit)` は指定ブロックを切り替えます。 +`object.constraint_mode(bit)` は動的なオブジェクトの全制約を切り替えます。 +初期状態はすべて有効で、継承・同名制約の上書き・別名ハンドルに対応します。 +`pre_randomize()` 内の変更はその回の solve に適用され、成功・失敗後も残ります。 +`rand_mode`、メンバー選択、inline 制約とは独立し、チェックポイントで復元されます +(IEEE 1800-2023 18.9、18.5.2)。ヒープ形式が変わるため、以前のビルドで保存した +シリアライズ済みヒープ・チェックポイントは再生成してください。 + +制約付きenum・`randc`、foreach・soft制約、`dist`、`solve before`、 +外部・static制約ブロック、制約中の型付きパラメーターは未対応です。 上記の上限を超える制約なし`randc`、staticな乱数プロパティ、配列・オブジェクト・文字列の 乱数化も未対応です。未対応の子クラスは乱数生成前に拒否します。 `null` を通した呼び出しは実行時エラーです。