diff --git a/crates/celox-sv-analyzer/src/ast.rs b/crates/celox-sv-analyzer/src/ast.rs index 9f87f573325..2f10142e623 100644 --- a/crates/celox-sv-analyzer/src/ast.rs +++ b/crates/celox-sv-analyzer/src/ast.rs @@ -25,6 +25,7 @@ pub(super) struct AnalysisState { interfaces: interface_ast::State, dimensions: dimensions::State, root_subroutines: std::cell::Cell, + inline_randomizations: RefCell>, next_call_site: std::rc::Rc>, timescales: timescales::State, diagnostics: RefCell>, @@ -1308,6 +1309,13 @@ impl Module { )?); (subroutines, comb_processes, ff_processes, initial_processes) }; + let (inline_subroutines, inline_randomizations) = + procedural::randomization::inline_subroutines( + syntax_tree, + &mut body_state, + &packed_dimensions, + )?; + subroutines.extend(inline_subroutines); // Static locals of the processes that keep their value are variables // of the module, initialized once with the declaration initializers. let statics: HashMap = body_state.statics.drain(..).collect(); @@ -1410,6 +1418,7 @@ impl Module { // A package keeps its symbols for the scopes that use it. let symbols = (is_package || export_symbols).then(|| scope::ScopeSymbols { classes: classes::scope_classes(syntax_tree, &const_env), + inline_randomizations, declarations_only: imported.declarations_only, type_parameter_bindings: HashMap::default(), pattern_parameter_bindings: HashMap::default(), diff --git a/crates/celox-sv-analyzer/src/ast/classes.rs b/crates/celox-sv-analyzer/src/ast/classes.rs index a3924547f9b..44f89baec5f 100644 --- a/crates/celox-sv-analyzer/src/ast/classes.rs +++ b/crates/celox-sv-analyzer/src/ast/classes.rs @@ -12,7 +12,7 @@ use std::rc::Rc; use super::*; use crate::system_functions::{HandleProperty, ObjectField, ObjectOp}; -mod constraints; +pub(super) mod constraints; pub(super) mod specializations; /// Bit width of a handle, see `celox_design::HANDLE_WIDTH`. diff --git a/crates/celox-sv-analyzer/src/ast/classes/constraints.rs b/crates/celox-sv-analyzer/src/ast/classes/constraints.rs index 3cb2e87ef24..bd5ecf18c7a 100644 --- a/crates/celox-sv-analyzer/src/ast/classes/constraints.rs +++ b/crates/celox-sv-analyzer/src/ast/classes/constraints.rs @@ -3,16 +3,59 @@ use super::*; use celox_heap::randomization::{Expr as ConstraintExpr, Field, Program}; use celox_sv_syntax::{ExprId, ExprKind}; +#[derive(Clone)] struct Typed { kind: Kind, width: u32, signed: bool, } +#[derive(Clone)] enum Kind { Leaf(ConstraintExpr), + Context(Box), Unary(String, Box), Binary(String, Box, Box), } +fn relation(op: &str, left: Typed, right: Typed) -> Typed { + Typed { + kind: Kind::Binary(op.into(), Box::new(left), Box::new(right)), + width: 1, + signed: false, + } +} + +// Charge copies before allocating them: source nesting alone does not bound +// the expanded tree of nested membership predicates. +fn bounded_clone(value: &Typed, budget: &std::cell::Cell) -> Result { + let mut pending = vec![value]; + while let Some(value) = pending.pop() { + charge(budget)?; + match &value.kind { + Kind::Leaf(_) => {} + Kind::Context(child) | Kind::Unary(_, child) => pending.push(child), + Kind::Binary(_, a, b) => pending.extend([a.as_ref(), b.as_ref()]), + } + } + Ok(value.clone()) +} + +fn charge(budget: &std::cell::Cell) -> Result<(), String> { + let remaining = budget + .get() + .checked_sub(1) + .ok_or("constraint expression expansion limit")?; + budget.set(remaining); + Ok(()) +} + +fn sized(value: Typed, width: u32, signed: bool) -> Typed { + Typed { + kind: Kind::Context(Box::new(value)), + width, + signed, + } +} + fn comparison(op: &str) -> bool { matches!(op, "==" | "!=" | "<" | "<=" | ">" | ">=" | "&&" | "||") } @@ -24,6 +67,7 @@ fn emit(value: Typed, context: Option<(u32, bool)>) -> ConstraintExpr { let (width, signed) = context.unwrap_or((value.width, value.signed)); let (expr, result_width) = match value.kind { Kind::Leaf(expr) => (expr, value.width), + Kind::Context(child) => (emit(*child, Some((value.width, value.signed))), value.width), Kind::Unary(op, child) => { let logical = op == "!"; ( @@ -66,7 +110,7 @@ fn emit(value: Typed, context: Option<(u32, bool)>) -> ConstraintExpr { } } -pub(super) fn bind( +pub(in crate::ast) fn bind( id: ExprId, tree: &AnalysisContext<'_>, properties: &[Property], @@ -78,11 +122,13 @@ pub(super) fn bind( properties: &[Property], env: &HashMap, depth: usize, + budget: &std::cell::Cell, ) -> Result { if depth > 64 { return Err("constraint expression nesting limit".into()); } - let recurse = |id| expression(id, tree, properties, env, depth + 1); + charge(budget)?; + let recurse = |id| expression(id, tree, properties, env, depth + 1, budget); let native = tree.declarations(); Ok(match &native.expression(id).kind { ExprKind::Group(id) => return recurse(*id), @@ -138,6 +184,71 @@ pub(super) fn bind( kind: Kind::Unary(operator.clone(), Box::new(value)), } } + ExprKind::Binary { + left, + operator, + right, + } if operator == "inside" => { + let value = recurse(*left)?; + let ExprKind::Set(items) = &native.expression(*right).kind else { + return Err("constraint inside set".into()); + }; + // Determine the context across every member and range endpoint + // before expanding comparisons, so arithmetic cannot truncate + // differently depending on which alternative is being tested. + let mut members = Vec::new(); + let mut width = value.width; + let mut signed = value.signed; + for item in items { + use celox_sv_syntax::DimensionKind; + let (low, high) = match item.kind { + DimensionKind::Index(id) => (recurse(id)?, None), + DimensionKind::Range { left, right } => { + (recurse(left)?, Some(recurse(right)?)) + } + _ => return Err("constraint inside range".into()), + }; + for operand in std::iter::once(&low).chain(high.iter()) { + width = width.max(operand.width); + signed &= operand.signed; + } + members.push((low, high)); + } + let value = sized(value, width, signed); + let mut alternatives = Vec::new(); + for (low, high) in members { + charge(budget)?; + let left = bounded_clone(&value, budget)?; + let low = sized(low, width, signed); + let predicate = if let Some(high) = high { + relation( + "&&", + relation(">=", left, low), + relation( + "<=", + bounded_clone(&value, budget)?, + sized(high, width, signed), + ), + ) + } else { + relation("==", left, low) + }; + alternatives.push(predicate); + } + // A balanced OR tree bounds recursion for large membership sets. + while alternatives.len() > 1 { + let mut next = Vec::new(); + let mut items = alternatives.into_iter(); + while let Some(a) = items.next() { + next.push(match items.next() { + Some(b) => relation("||", a, b), + None => a, + }); + } + alternatives = next; + } + alternatives.pop().ok_or("empty constraint inside set")? + } ExprKind::Binary { left, operator, @@ -175,7 +286,8 @@ pub(super) fn bind( _ => return Err("unsupported scalar constraint expression".into()), }) } - expression(id, tree, properties, env, 0).map(|value| emit(value, None)) + expression(id, tree, properties, env, 0, &std::cell::Cell::new(16_384)) + .map(|value| emit(value, None)) } impl Class { @@ -212,3 +324,38 @@ impl Class { }) } } + +/// A generated call-specific method. Its immutable predicates never change the +/// object's persistent constraints, including during nested hook calls. +#[derive(Clone)] +pub(in crate::ast) struct Inline { + pub key: usize, + pub class: std::rc::Rc, + pub constraints: Vec, + pub dimensions: PackedDimensions, +} + +impl Inline { + pub fn name(&self, class: &str) -> String { + format!("{class}::$inline_randomize@{}", self.key) + } +} + +/// Bound inline predicates survive package imports without retaining syntax or +/// the declaring scope's dimensions. Consumer scopes can add dispatch targets. +#[derive(Debug, Clone, PartialEq, Eq)] +pub(in crate::ast) struct InlineRequest { + pub key: usize, + pub class: Class, + pub constraints: Vec, +} + +impl Inline { + pub fn request(&self) -> InlineRequest { + InlineRequest { + key: self.key, + class: (*self.class).clone(), + constraints: self.constraints.clone(), + } + } +} 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 bc080e59848..736a4859252 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs @@ -903,6 +903,19 @@ pub(in crate::ast) fn bind_value( ExprKind::Concatenation(_) => { return Err(unsupported("empty unpacked array concatenation")); } + ExprKind::RandomizeWith { + expression, + constraints, + } => { + values.push(objects::randomize_with( + tree, + *expression, + constraints.as_deref(), + native, + dimensions, + )?); + continue; + } ExprKind::ArrayMethodWith { .. } => { return Err(unsupported("array method with expression")); } 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 86aae92e3b1..b438437f392 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs @@ -933,3 +933,55 @@ fn check_random_access( property.protected, ) } + +pub(super) fn randomize_with( + tree: &AnalysisContext<'_>, + expression: ExprId, + constraints: Option<&[ExprId]>, + native: &Declarations, + dimensions: &PackedDimensions, +) -> Converted { + let (callee, arguments) = match &native.expression(ungroup(expression, native)).kind { + ExprKind::Call { + expression, + arguments, + } => (*expression, arguments.as_slice()), + _ => (expression, &[][..]), + }; + let (method_name, _, receiver) = method(tree, callee, native, dimensions)? + .filter(|(name, _, _)| name.ends_with("::randomize")) + .ok_or_else(|| unsupported("inline constraints require class randomize"))?; + let owner = method_name.strip_suffix("::randomize").unwrap(); + let class = class(tree, dimensions, owner)?; + // Inline constraints need the solver even on otherwise unconstrained classes. + class.constraint_program()?; + let constraints = constraints + .ok_or_else(|| unsupported("inline constraint form"))? + .iter() + .map(|&id| { + classes::constraints::bind(id, tree, &class.properties, &dimensions.const_env) + .map_err(|reason| unsupported(format!("inline constraints: {reason}"))) + }) + .collect::>>()?; + let selection = random_selection(tree, dimensions, &method_name, arguments, native)?; + let handle = match receiver { + Receiver::Handle(id) => bind_value(id, native, tree, dimensions, None)?, + Receiver::This => this(), + Receiver::Static => return Err(unsupported("inline randomize object receiver")), + }; + let key = tree.state.next_call_site.get(); + tree.state.next_call_site.set(key + 1); + let inline = classes::constraints::Inline { + key, + class, + constraints, + dimensions: dimensions.clone(), + }; + let name = inline.name(owner); + tree.state.inline_randomizations.borrow_mut().push(inline); + Ok(Expr::Call { + callee: Callee::Subroutine(name), + args: vec![Some(handle), Some(selection)], + arg_order: Vec::new(), + }) +} diff --git a/crates/celox-sv-analyzer/src/ast/parameters/skipped.rs b/crates/celox-sv-analyzer/src/ast/parameters/skipped.rs index 1853cdc01ad..bfb477f6249 100644 --- a/crates/celox-sv-analyzer/src/ast/parameters/skipped.rs +++ b/crates/celox-sv-analyzer/src/ast/parameters/skipped.rs @@ -373,7 +373,7 @@ pub(in crate::ast) fn validate( ExprKind::Copy(_) => { return Err(unsupported("shallow copy in skipped operand")); } - ExprKind::ArrayMethodWith { .. } => { + ExprKind::ArrayMethodWith { .. } | ExprKind::RandomizeWith { .. } => { return Err(unsupported("array method with expression")); } ExprKind::Parameterized { .. } => { @@ -587,7 +587,7 @@ pub(in crate::ast) fn literal_widths( visited.push(id); let add = |jobs: &mut Vec<_>, id| jobs.push((id, evaluated, shape)); match &native.expression(id).kind { - ExprKind::ArrayMethodWith { .. } => { + ExprKind::ArrayMethodWith { .. } | ExprKind::RandomizeWith { .. } => { return Err(unsupported("array method with expression")); } ExprKind::Literal(text) if evaluated => { @@ -1164,6 +1164,13 @@ pub(in crate::ast) fn children( then_expression, else_expression, } => children.extend([*condition, *then_expression, *else_expression]), + ExprKind::RandomizeWith { + expression, + constraints, + } => { + children.push(*expression); + children.extend(constraints.iter().flatten()); + } ExprKind::ArrayMethodWith { expression, predicate, diff --git a/crates/celox-sv-analyzer/src/ast/procedural.rs b/crates/celox-sv-analyzer/src/ast/procedural.rs index 37b5b938a0d..7dd29c43dee 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural.rs @@ -12,7 +12,7 @@ mod control; mod final_procedures; mod foreach; use foreach::ForeachLoop; -mod randomization; +pub(super) mod randomization; pub(super) mod timed_tasks; mod timing; use crate::procedural::{ @@ -1254,6 +1254,14 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { self.rename_expr(&mut value); return Ok(vec![Stmt::Eval(value)]); } + if matches!( + native.expression(query_root).kind, + celox_sv_syntax::ExprKind::RandomizeWith { .. } + ) { + let mut call = self.native_value(query_root)?; + self.rename_expr(&mut call); + return Ok(vec![Stmt::Eval(call)]); + } if let Some(call) = self.method_call_statement(query_root)? { return Ok(vec![call]); } diff --git a/crates/celox-sv-analyzer/src/ast/procedural/randomization.rs b/crates/celox-sv-analyzer/src/ast/procedural/randomization.rs index 06b9c0a3c8d..20c1bdd9e52 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural/randomization.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural/randomization.rs @@ -13,19 +13,45 @@ pub(super) fn lower( state: &mut BodyState<'_>, item: &generate::Item, ) -> Converted> { + lower_methods(class, tree, dimensions, state, Some(item), None) +} + +fn lower_methods( + class: &classes::Class, + tree: &AnalysisContext<'_>, + dimensions: &PackedDimensions, + state: &mut BodyState<'_>, + item: Option<&generate::Item>, + inline: Option<&classes::constraints::Inline>, +) -> Converted> { + let env = item.map(|item| &*item.env).unwrap_or(&dimensions.const_env); + let aliases = item + .map(|item| item.type_aliases(&dimensions.type_aliases)) + .unwrap_or_else(|| std::borrow::Cow::Borrowed(&dimensions.type_aliases)); + let method_name = |class: &str, method: &str| { + if let Some(inline) = inline { + inline.name(class) + } else { + let name = classes::Class::subroutine_name(class, method); + item.map(|item| item.name(&name)).unwrap_or(name) + } + }; let handle = classes::handle_type(tree, &class.name) .ok_or_else(|| unsupported("class randomization receiver"))?; let convert_type = |ty| { crate::ir::Type::from_ast( ty, &const_functions::Environment { - constants: &*item.env, + constants: env, functions: &tree.state.const_functions, }, ) }; let mut result = Vec::new(); for method in ["randomize", "srandom", "rand_mode"] { + if inline.is_some() && method != "randomize" { + continue; + } if method == "randomize" && class.check_randomize().is_err() { continue; } @@ -133,12 +159,16 @@ pub(super) fn lower( else_body: Vec::new(), }); body.extend(hook("pre_randomize")); - if class.has_constraints { + if class.has_constraints || inline.is_some() { + let mut program = class.constraint_program()?; + if let Some(inline) = inline { + program.constraints.extend(inline.constraints.clone()); + } let success = builder.declare("$constraint_success", int_type()); body.push(Stmt::Assign { lhs: LValue::Ident(success.clone()), rhs: classes::object_call( - ObjectOp::Randomize(class.constraint_program()?), + ObjectOp::Randomize(program), vec![ Expr::Ident(this.clone()), Expr::Binary { @@ -216,19 +246,19 @@ pub(super) fn lower( // randomize is virtual, while its pre/post hooks are not (18.6.2). // Object-wide rand_mode also covers the dynamic object's members. let mut items = Vec::new(); - let aliases = item.type_aliases(&dimensions.type_aliases); for name in classes::visible_classes(tree) { if name == class.name { continue; } - let Ok(derived) = classes::class(tree, &name, &item.env, &aliases) else { + let Ok(derived) = classes::class(tree, &name, env, &aliases) else { continue; }; if derived.is_abstract || derived.is_interface { continue; } - if (method == "randomize" && derived.check_randomize().is_err()) - || !derived.derives_from(tree, &class.name, &item.env, &aliases) + if (inline.is_some() && derived.constraint_program().is_err()) + || (method == "randomize" && derived.check_randomize().is_err()) + || !derived.derives_from(tree, &class.name, env, &aliases) { continue; } @@ -236,7 +266,7 @@ pub(super) fn lower( Some(Expr::Ident(this.clone())), Some(Expr::Ident(argument.clone())), ]; - let name = classes::Class::subroutine_name(&name, method); + let name = method_name(&name, method); let call = if method == "randomize" { vec![Stmt::Return(Some(Expr::Call { callee: Callee::Subroutine(name), @@ -274,11 +304,13 @@ pub(super) fn lower( }, ); } - for stmt in &mut body { - qualify_stmt(item, stmt); + if let Some(item) = item { + for stmt in &mut body { + qualify_stmt(item, stmt); + } } result.push(Subroutine { - name: item.name(&classes::Class::subroutine_name(&class.name, method)), + name: method_name(&class.name, method), is_task: false, automatic_locals: builder.state.locals[first_local..] .iter() @@ -382,3 +414,62 @@ fn random_property( ))); body } + +pub(in crate::ast) fn inline_subroutines( + tree: &AnalysisContext<'_>, + state: &mut BodyState<'_>, + dimensions: &PackedDimensions, +) -> Converted<(Vec, Vec)> { + let mut requests = std::mem::take(&mut *tree.state.inline_randomizations.borrow_mut()); + for request in &scope::imported(&tree.state).inline_randomizations { + if !requests.iter().any(|known| known.key == request.key) { + requests.push(classes::constraints::Inline { + key: request.key, + class: std::rc::Rc::new(request.class.clone()), + constraints: request.constraints.clone(), + dimensions: dimensions.clone(), + }); + } + } + let exported = requests + .iter() + .map(classes::constraints::Inline::request) + .collect(); + let mut result = Vec::new(); + for inline in requests { + let dims = &inline.dimensions; + let mut classes = vec![inline.class.clone()]; + for name in classes::visible_classes(tree) { + if name == inline.class.name { + continue; + } + let Ok(class) = classes::class(tree, &name, &dims.const_env, &dims.type_aliases) else { + continue; + }; + if !class.is_abstract + && !class.is_interface + && class.check_randomize().is_ok() + && class.constraint_program().is_ok() + && class.derives_from( + tree, + &inline.class.name, + &dims.const_env, + &dims.type_aliases, + ) + { + classes.push(class); + } + } + for class in classes { + result.extend(lower_methods( + &class, + tree, + dims, + state, + None, + Some(&inline), + )?); + } + } + Ok((result, exported)) +} diff --git a/crates/celox-sv-analyzer/src/ast/scope.rs b/crates/celox-sv-analyzer/src/ast/scope.rs index 9d68fa5589f..acda2b3deef 100644 --- a/crates/celox-sv-analyzer/src/ast/scope.rs +++ b/crates/celox-sv-analyzer/src/ast/scope.rs @@ -65,6 +65,7 @@ pub(super) struct ScopeSymbols { /// (IEEE 1800-2023 26.3): a scope that uses them may be analyzed from /// another source, without their declarations. pub classes: Vec, + pub inline_randomizations: Vec, } #[derive(Default)] @@ -184,6 +185,15 @@ pub(super) fn split_marker(key: &str) -> Option<(&str, &str)> { impl ScopeSymbols { /// Add the symbols of `other` that this scope does not already have. pub fn extend(&mut self, other: &ScopeSymbols) { + for request in &other.inline_randomizations { + if !self + .inline_randomizations + .iter() + .any(|known| known.key == request.key) + { + self.inline_randomizations.push(request.clone()); + } + } for class in &other.classes { if !self.classes.iter().any(|known| known.name == class.name) { self.classes.push(class.clone()); @@ -437,6 +447,7 @@ impl ScopeSymbols { ScopeSymbols { // Classes have their qualified names already. classes: self.classes.clone(), + inline_randomizations: self.inline_randomizations.clone(), declarations_only: self.declarations_only, interface_instances: self.interface_instances.clone(), interface_types: self.interface_types.clone(), diff --git a/crates/celox-sv-analyzer/src/tests.rs b/crates/celox-sv-analyzer/src/tests.rs index 9d1c6193ed2..985f96f74f9 100644 --- a/crates/celox-sv-analyzer/src/tests.rs +++ b/crates/celox-sv-analyzer/src/tests.rs @@ -6587,11 +6587,6 @@ fn explicit_output_data_types_default_to_variables() { #[test] fn class_randomize_rejects_unsupported_semantics() { for (members, call, expected) in [ - ( - "rand int x; constraint c { if (x) x == 1; }", - "c.randomize()", - "constraints", - ), ( "rand int x; constraint c { soft x == 1; }", "c.randomize()", @@ -6603,15 +6598,10 @@ fn class_randomize_rejects_unsupported_semantics() { "constraints", ), ( - "rand int x; constraint c { x inside {[1:3]}; }", + "rand int x; constraint c { x inside {[1:$]}; }", "c.randomize()", "constraint", ), - ( - "rand int x; constraint c { (x == 1) -> (x < 3); }", - "c.randomize()", - "constraints", - ), ( "rand int x; constraint c { (x == 1) <-> (x < 3); }", "c.randomize()", @@ -6646,7 +6636,7 @@ fn class_randomize_rejects_unsupported_semantics() { ), ( "rand int x;", - "c.randomize() with { x == 1; }", + "c.randomize() with { outside == 1; }", "unsupported", ), ("rand int x;", "c.randomize(x + 1)", "arguments"), @@ -7345,3 +7335,42 @@ fn final_procedures_only_follow_defaults_for_omitted_arguments() { } } } + +#[test] +fn class_randomize_bounds_nested_membership_expansion() { + for levels in [4, 25] { + let mut expr = "x".to_owned(); + for _ in 0..levels { + expr = format!("({expr}) inside {{0, 1}}"); + } + let source = format!( + "module Top; class C; rand bit x; constraint c {{ {expr}; }} endclass C c; initial begin c = new; c.randomize(); end endmodule" + ); + let result = analyze_source(&source, Path::new("nested_membership.sv")); + if levels == 4 { + result.expect("small nested membership must remain supported"); + } else { + let error = result + .expect_err("expanded membership must be bounded") + .to_string(); + assert!( + error.contains("constraint expression expansion limit"), + "{error}" + ); + } + } +} + +#[test] +fn class_inline_randomize_retains_call_specific_constraints() { + let source = r#"module Top; + class C; rand int x; constraint c { x < 10; } endclass + C obj; + initial begin + obj = new; + if (!(obj.randomize() with { x == 2; })) $fatal; + obj.randomize() with { x == 3; }; + end + endmodule"#; + analyze_source(source, Path::new("inline_randomize.sv")).unwrap(); +} diff --git a/crates/celox-sv-syntax/src/nodes.rs b/crates/celox-sv-syntax/src/nodes.rs index 219e8a8fea3..753ff1ff74c 100644 --- a/crates/celox-sv-syntax/src/nodes.rs +++ b/crates/celox-sv-syntax/src/nodes.rs @@ -94,6 +94,11 @@ pub enum ExprKind { expression: ExprId, predicate: ExprId, }, + /// Per-call class constraints (IEEE 1800-2023 18.7). + RandomizeWith { + expression: ExprId, + constraints: Option>, + }, Parameterized { expression: ExprId, arguments: Vec, diff --git a/crates/celox-sv-syntax/src/parser.rs b/crates/celox-sv-syntax/src/parser.rs index 0d52b135058..a25d494f4bc 100644 --- a/crates/celox-sv-syntax/src/parser.rs +++ b/crates/celox-sv-syntax/src/parser.rs @@ -109,6 +109,7 @@ impl Declarations { indices, at: 0, next_parameter_id: 0, + inline_constraint_depth: 0, keyword_versions: Vec::new(), source_items: Vec::new(), expressions: Vec::new(), @@ -325,6 +326,7 @@ struct Parser<'a> { indices: Vec, at: usize, next_parameter_id: usize, + inline_constraint_depth: usize, keyword_versions: Vec, source_items: Vec, expressions: Vec, diff --git a/crates/celox-sv-syntax/src/parser/constraints.rs b/crates/celox-sv-syntax/src/parser/constraints.rs index 2469d9465da..778a1b98b14 100644 --- a/crates/celox-sv-syntax/src/parser/constraints.rs +++ b/crates/celox-sv-syntax/src/parser/constraints.rs @@ -6,7 +6,13 @@ enum Job { Block(bool), Expression, Set, - Else, + Guard { + condition: ExprId, + first: usize, + start: usize, + negate: bool, + has_else: bool, + }, } impl Parser<'_> { @@ -43,8 +49,6 @@ impl Parser<'_> { }) { return Err(self.error("duplicate constraint block")); } - let mut expressions = Vec::new(); - let mut supported = !is_static; if self.eat(";") { if let Some(class) = self.class_stack.last_mut() { class.constraints.push(ClassConstraint { @@ -57,6 +61,19 @@ impl Parser<'_> { if prototype { return Err(self.error("extern or pure constraint requires a prototype")); } + let expressions = self.constraint_block()?; + if let Some(class) = self.class_stack.last_mut() { + class.constraints.push(ClassConstraint { + name, + expressions: if is_static { None } else { expressions }, + }); + } + Ok(()) + } + + pub(super) fn constraint_block(&mut self) -> Result>> { + let mut expressions = Vec::new(); + let mut supported = true; self.expect("{")?; let mut jobs = vec![Job::Block(true)]; while let Some(job) = jobs.pop() { @@ -84,18 +101,60 @@ impl Parser<'_> { jobs.push(Job::Expression); } } - Job::Else => { - if self.eat("else") { + Job::Guard { + condition, + first, + start, + negate, + has_else, + } => { + let guard = if negate { + self.node( + start, + ExprKind::Unary { + operator: "!".into(), + expression: condition, + postfix: false, + }, + )? + } else { + condition + }; + let body: Vec<_> = expressions.drain(first..).collect(); + for expression in body { + expressions.push(self.node( + start, + ExprKind::Binary { + left: guard, + operator: "||".into(), + right: expression, + }, + )?); + } + if has_else && self.eat("else") { + jobs.push(Job::Guard { + condition, + first: expressions.len(), + start, + negate: false, + has_else: false, + }); jobs.push(Job::Set); } } Job::Expression => { + let start = self.at; if self.eat("if") { - supported = false; self.expect("(")?; - self.expression(0)?; + let condition = self.expression(0)?; self.expect(")")?; - jobs.push(Job::Else); + jobs.push(Job::Guard { + condition, + first: expressions.len(), + start, + negate: true, + has_else: true, + }); jobs.push(Job::Set); } else if self.eat("foreach") { supported = false; @@ -121,7 +180,14 @@ impl Parser<'_> { supported &= simple; } if !soft && self.eat("->") { - supported = false; + let condition = expressions.pop().expect("condition retained"); + jobs.push(Job::Guard { + condition, + first: expressions.len(), + start, + negate: true, + has_else: false, + }); jobs.push(Job::Set); } else { if self.eat("dist") { @@ -134,13 +200,7 @@ impl Parser<'_> { } } } - if let Some(class) = self.class_stack.last_mut() { - class.constraints.push(ClassConstraint { - name, - expressions: supported.then_some(expressions), - }); - } - Ok(()) + Ok(supported.then_some(expressions)) } fn constraint_condition(&mut self) -> Result<(ExprId, bool)> { diff --git a/crates/celox-sv-syntax/src/parser/expressions.rs b/crates/celox-sv-syntax/src/parser/expressions.rs index 1d1ed656c0c..63fe34a8861 100644 --- a/crates/celox-sv-syntax/src/parser/expressions.rs +++ b/crates/celox-sv-syntax/src/parser/expressions.rs @@ -372,6 +372,13 @@ impl Parser<'_> { pending.extend(expressions); } ExprKind::Tagged { value, .. } => pending.extend(value), + ExprKind::RandomizeWith { + expression, + constraints, + } => { + pending.push(*expression); + pending.extend(constraints.iter().flatten()); + } ExprKind::ArrayMethodWith { expression, predicate, @@ -781,6 +788,38 @@ impl Parser<'_> { }); jobs.push(Job::Arguments); } + "with" if self.nth(1) == "{" => { + let callee = match &self.expressions[left.0].kind { + ExprKind::Call { expression, .. } => *expression, + _ => left, + }; + let is_randomize = match &self.expressions[callee.0].kind { + ExprKind::Name(name) | ExprKind::Member { name, .. } => { + name.value() == "randomize" + } + _ => false, + }; + if !is_randomize { + return Err(self.error("constraint with block requires randomize")); + } + self.at += 1; + if self.inline_constraint_depth != 0 { + return Err(self.unsupported("inline constraint nesting limit")); + } + self.inline_constraint_depth += 1; + let constraints = self.constraint_block(); + self.inline_constraint_depth -= 1; + let constraints = constraints?; + self.tail( + &mut jobs, + start, + minimum, + ExprKind::RandomizeWith { + expression: left, + constraints, + }, + )?; + } "with" if self.nth(1) == "(" => { let method = match &self.expressions[left.0].kind { ExprKind::Call { diff --git a/crates/celox-sv-syntax/src/parser/procedures.rs b/crates/celox-sv-syntax/src/parser/procedures.rs index 1fafa32b459..dd783708210 100644 --- a/crates/celox-sv-syntax/src/parser/procedures.rs +++ b/crates/celox-sv-syntax/src/parser/procedures.rs @@ -98,7 +98,7 @@ impl Parser<'_> { }; match &self.expressions[id.0].kind { ExprKind::Call { expression, .. } => callable(*expression), - ExprKind::ArrayMethodWith { .. } => true, + ExprKind::ArrayMethodWith { .. } | ExprKind::RandomizeWith { .. } => true, _ => callable(id), } } @@ -821,7 +821,7 @@ impl Parser<'_> { } // A parenthesis-free array method followed by `with` is a call, // not a declaration whose variable happens to be named `with`. - if word(cursor) == "with" && word(cursor + 1) == "(" { + if word(cursor) == "with" && matches!(word(cursor + 1), "(" | "{") { return None; } self.indices diff --git a/crates/celox-sv-syntax/src/parser/tests.rs b/crates/celox-sv-syntax/src/parser/tests.rs index 53d0d1c822a..2d264fea687 100644 --- a/crates/celox-sv-syntax/src/parser/tests.rs +++ b/crates/celox-sv-syntax/src/parser/tests.rs @@ -3047,10 +3047,39 @@ fn malformed_array_method_with_is_rejected() { #[test] fn constraints_retain_simple_expressions_and_mark_other_forms() { let tree = parse( - "class C; rand int x; constraint a { x > 0; x < 3; } constraint b { if (x) x == 1; } endclass", + "class C; rand int x; constraint a { x > 0; x < 3; } constraint b { if (x) x == 1; } constraint c { soft x == 1; } constraint d { if (1) {} } endclass", ); let blocks = &tree.classes[0].constraints; assert_eq!(blocks[0].name.spelling, "a"); assert_eq!(blocks[0].expressions.as_ref().unwrap().len(), 2); - assert!(blocks[1].expressions.is_none()); + let guarded = blocks[1].expressions.as_ref().unwrap(); + assert_eq!(guarded.len(), 1); + assert!( + matches!(&tree.expression(guarded[0]).kind, ExprKind::Binary { operator, .. } if operator == "||") + ); + assert!(blocks[2].expressions.is_none()); + assert!(blocks[3].expressions.as_ref().unwrap().is_empty()); +} + +#[test] +fn inline_constraints_retain_ownership_and_bound_nested_calls() { + let syntax = + parse("module M; initial obj.randomize() with { if (x) y == 1; else y == 2; }; endmodule"); + assert!( + syntax + .expression_nodes() + .any(|(_, node)| matches!(&node.kind, + ExprKind::RandomizeWith { constraints: Some(values), .. } if values.len() == 2)) + ); + let source = format!( + "module M; initial {}1;{} endmodule", + "obj.randomize() with { ".repeat(100), + " };".repeat(100) + ); + assert!( + Declarations::parse(&source, Path::new("nested_inline.sv")) + .unwrap_err() + .to_string() + .contains("inline constraint nesting limit") + ); } diff --git a/crates/celox-test-suite/src/sv/cases/class.vtest b/crates/celox-test-suite/src/sv/cases/class.vtest index cd39b6a0903..b4b2156e1ab 100644 --- a/crates/celox-test-suite/src/sv/cases/class.vtest +++ b/crates/celox-test-suite/src/sv/cases/class.vtest @@ -2002,3 +2002,248 @@ module Top(output bit done); endmodule "#) (top Top) (run_until 0) (assert_eq done 1)) + +(case constrained_randomize_inside + (source "constraint_inside.sv" #" +module Top(output bit done); + class Packet; + rand int x, lo, hi; + constraint bounds { lo inside {-3, -2}; hi inside {2, 3}; + x inside {[lo:hi], 9}; !(x inside {0, 9}); } + endclass + class Empty; + rand int x; + constraint c { x inside {[3:-3]}; } + endclass + Packet p; + Empty e; + initial begin + e = new; e.x = 42; + if (e.randomize() || e.x != 42) $fatal(1, "empty range changed fields"); + p = new; + repeat (12) begin + if (!p.randomize()) $fatal(1, "membership unsat"); + if (p.lo < -3 || p.lo > -2 || p.hi < 2 || p.hi > 3 || + p.x < p.lo || p.x > p.hi || p.x == 0) $fatal(1, "membership"); + end + p.lo = 3; p.hi = -3; + if (p.randomize(x)) $fatal(1, "reversed range must be empty"); + p.lo = -2; p.hi = 2; p.x = -1; + if (!p.randomize(null)) $fatal(1, "negative check-only member"); + p.x = p.lo; + if (!p.randomize(null)) $fatal(1, "low endpoint excluded"); + p.x = p.hi; + if (!p.randomize(null)) $fatal(1, "high endpoint excluded"); + p.x = 0; + if (p.randomize(null)) $fatal(1, "excluded check-only member"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constrained_randomize_inside_widths + (source "constraint_inside_widths.sv" #" +module Top(output bit done); + class Packet; + rand bit signed [7:0] x; + rand bit [15:0] y; + constraint c { x inside {-2, -1}; y inside {x}; } + endclass + class WideSet; + bit [3:0] a, b; + constraint c { !((a + b) inside {4'd0, 8'd17}); } + endclass + class WideRange; + bit [3:0] a, b; + constraint c { (a + b) inside {[4'd1:8'd16]}; } + endclass + Packet p; + WideSet s; + WideRange r; + initial begin + p = new; + if (!p.randomize()) $fatal(1, "mixed width membership"); + if (p.x != -2 && p.x != -1) $fatal(1, "signed membership"); + if (p.y != 254 && p.y != 255) $fatal(1, "unsigned comparison context"); + s = new; s.a = 15; s.b = 1; + if (!s.randomize(null)) $fatal(1, "membership-wide sum width"); + r = new; r.a = 15; r.b = 1; + if (!r.randomize(null)) $fatal(1, "range endpoint width"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constrained_randomize_conditionals + (source "conditional_constraints.sv" #" +module Top(output bit done); + class Packet; + rand bit mode; + rand int value; + int required; + constraint c { + value == required; + if (mode) { value inside {[1:3]}; value != 2; } + else value == 8; + mode -> { value > 0; if (value == 3) value != 1; } + } + endclass + Packet p; + initial begin + p = new; + p.required = 8; + if (!p.randomize() || p.mode != 0 || p.value != 8) $fatal(1, "reverse else solve"); + p.required = 3; + if (!p.randomize() || p.mode != 1 || p.value != 3) $fatal(1, "reverse then solve"); + p.required = 2; + if (p.randomize() || p.value != 3) $fatal(1, "block constraint lost"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constrained_randomize_nested_guards + (source "nested_guards.sv" #" +module Top(output bit done); + class Packet; + rand bit a, b; + rand int x; + constraint c { + x == 7; + if (a) if (b) x == 1; else x == 7; + !a -> x == 2; + a -> b -> x == 1; + if (1'b0) x == 123; + } + endclass + Packet p; + initial begin + p = new; + if (!p.randomize() || p.a != 1 || p.b != 0 || p.x != 7) $fatal(1, "nested guards"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constrained_randomize_inline + (source "inline_constraints.sv" #" +module Top(output bit done); + class Packet; + rand int x, y; + int limit, pre_count, post_count; + constraint c { x < 10; } + function void pre_randomize(); limit=3; pre_count++; endfunction + function void post_randomize(); post_count++; endfunction + endclass + Packet p; + initial begin + p = new; + if (!(p.randomize() with { x inside {[1:limit]}; y == x + 1; })) + $fatal(1, "inline success"); + if (p.x < 1 || p.x > 3 || p.y != p.x + 1) $fatal(1, "inline values"); + if (p.randomize() with { x == 12; }) $fatal(1, "lost class constraint"); + if (p.pre_count != 2 || p.post_count != 1) $fatal(1, "inline hooks"); + if (!(p.randomize() with { x == 7; if (x == 7) y == 8; })) $fatal(1, "inline leaked"); + if (!p.randomize(null)) $fatal(1, "ordinary check"); + if (p.randomize(null) with { x == 2; }) $fatal(1, "inline check"); + if (p.x != 7 || p.y != 8) $fatal(1, "check-only changed fields"); + if (!(p.randomize(x) with { x == y; })) $fatal(1, "inline selection"); + if (p.x != 8 || p.y != 8) $fatal(1, "unselected field changed"); + p.randomize() with { x == 4; y == 5; }; + if (p.x != 4 || p.y != 5) $fatal(1, "discarded call"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constrained_randomize_inline_inheritance + (source "inline_inheritance.sv" #" +module Top(output bit done); + class Base; + rand int x; + endclass + class Derived extends Base; + rand int x; + int hook; + constraint c { x == 9; } + function void pre_randomize(); hook++; endfunction + endclass + Base b; + Derived d; + initial begin + d = new; b = d; + if (!(b.randomize() with { x == 2; })) $fatal(1, "base inline scope"); + if (b.x != 2 || d.x != 9 || d.hook != 1) $fatal(1, "static scope or dynamic hooks"); + if (!(b.randomize() with { x == 5; })) $fatal(1, "second inline"); + if (b.x != 5 || d.x != 9 || d.hook != 2) $fatal(1, "inline persistence"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constrained_randomize_inline_basic + (source "inline_basic.sv" #" +module Top(output bit done); + class Packet; + rand int x; + constraint c { x inside {1, 2}; } + function int pick(); return randomize() with { x == 1; }; endfunction + endclass + Packet p; + initial begin + p = new; + if (!(p.randomize() with { x == 2; })) $fatal(1, "inline member"); + if (p.x != 2) $fatal(1, "inline value"); + if (!p.pick() || p.x != 1) $fatal(1, "unqualified inline call"); + if (p.randomize() with { x == 3; }) $fatal(1, "named constraint lost"); + if (p.x != 1) $fatal(1, "failed inline changed member"); + if (!(p.randomize() with { x == 2; })) $fatal(1, "inline not per-call"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) + +(case constrained_randomize_inline_package_instances + (source "inline_package.sv" #" +package pkg; + class Packet; + rand int x; + function int pick(); return randomize() with { x == 2; }; endfunction + endclass +endpackage +module Child(output bit done); + class Derived extends pkg::Packet; + rand int y; + int calls; + constraint c { y == 7; } + function void pre_randomize(); calls++; endfunction + endclass + pkg::Packet p; + Derived d; + if (1) begin : g + initial begin + p = new; + if (!p.pick() || p.x != 2) $fatal(1, "package method inline"); + if (!(p.randomize() with { x == 3; }) || p.x != 3) $fatal(1, "instance inline"); + d = new; + p = d; + if (!p.pick() || p.x != 2 || d.y != 7 || d.calls != 1) + $fatal(1, "imported inline subclass dispatch"); + done = 1; + end + end +endmodule +module Top(output bit done); + wire a, b; + Child c0(a), c1(b); + assign done = a & b; +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1)) diff --git a/crates/celox-test-suite/verification/repros/sv_conditional_constraints.json b/crates/celox-test-suite/verification/repros/sv_conditional_constraints.json new file mode 100644 index 00000000000..a10553b86ec --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_conditional_constraints.json @@ -0,0 +1,16 @@ +{ + "observations": [ + { + "tool": "icarus", + "case": "class::constrained_randomize_conditionals", + "status": "compile_error", + "log": "/sv-icarus/class/constrained_randomize_conditionals/source_0.sv:9: sorry: \"inside\" expressions not supported yet.\n/sv-icarus/class/constrained_randomize_conditionals/source_0.sv:7: sorry: Constraint declarations not supported.\n" + }, + { + "tool": "icarus", + "case": "class::constrained_randomize_nested_guards", + "status": "compile_error", + "log": "/sv-icarus/class/constrained_randomize_nested_guards/source_0.sv:6: sorry: Constraint declarations not supported.\n" + } + ] +} diff --git a/crates/celox-test-suite/verification/repros/sv_inline_constraint_scope.sv b/crates/celox-test-suite/verification/repros/sv_inline_constraint_scope.sv new file mode 100644 index 00000000000..262cbadef21 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_inline_constraint_scope.sv @@ -0,0 +1,20 @@ +// IEEE 1800-2023 18.7: inline names start at the handle's declared class. +module top; + class Base; + rand int x; + endclass + class Derived extends Base; + rand int x; + constraint c { x == 9; } + endclass + Base b; + Derived d; + initial begin + d = new; + b = d; + if (!(b.randomize() with { x == 2; })) $fatal(1, "static inline scope"); + if (b.x != 2 || d.x != 9) $fatal(1, "hidden property binding"); + $display("PASS"); + $finish; + end +endmodule diff --git a/crates/celox-test-suite/verification/repros/sv_inline_constraints.json b/crates/celox-test-suite/verification/repros/sv_inline_constraints.json new file mode 100644 index 00000000000..de333c998b2 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_inline_constraints.json @@ -0,0 +1,55 @@ +{ + "specification": "IEEE 1800-2023 18.6.3, 18.7", + "observations": [ + { + "tool": "verilator", + "version": "Verilator 5.052", + "case": "class::constrained_randomize_inline", + "status": "runtime_error", + "log": "%Warning-UNSATCONSTR: /sv-verilator/class/constrained_randomize_inline/source_0.sv:6: Unsatisfied constraint: 'constraint c { x < 10; }'\n%Warning-UNSATCONSTR: /sv-verilator/class/constrained_randomize_inline/source_0.sv:16: Unsatisfied constraint: 'if (p.randomize() with { x == 12; }) $fatal(1, \"lost class constraint\");'\n[0] %Fatal: source_0.sv:17: Assertion failed in TOP.celox_suite_tb.dut: inline hooks\n%Error: /sv-verilator/class/constrained_randomize_inline/source_0.sv:17: Verilog $stop\nAborting...\n" + }, + { + "tool": "verilator", + "version": "Verilator 5.052", + "case": "class::constrained_randomize_inline_inheritance", + "status": "runtime_error", + "log": "%Warning-UNSATCONSTR: /sv-verilator/class/constrained_randomize_inline_inheritance/source_0.sv:9: Unsatisfied constraint: 'constraint c { x == 9; }'\n%Warning-UNSATCONSTR: /sv-verilator/class/constrained_randomize_inline_inheritance/source_0.sv:16: Unsatisfied constraint: 'if (!(b.randomize() with { x == 2; })) $fatal(1, \"base inline scope\");'\n[0] %Fatal: source_0.sv:16: Assertion failed in TOP.celox_suite_tb.dut: base inline scope\n%Error: /sv-verilator/class/constrained_randomize_inline_inheritance/source_0.sv:16: Verilog $stop\nAborting...\n" + }, + { + "tool": "verilator", + "version": "Verilator 5.052", + "source": "sv_inline_constraint_scope.sv", + "command": "verilator --binary --timing -Wno-fatal --top-module top --Mdir sv_inline_constraint_scope.sv; /Vtop", + "status": "runtime_error", + "log": "%Warning-UNSATCONSTR: crates/celox-test-suite/verification/repros/sv_inline_constraint_scope.sv:8: Unsatisfied constraint: 'constraint c { x == 9; }'\n%Warning-UNSATCONSTR: crates/celox-test-suite/verification/repros/sv_inline_constraint_scope.sv:15: Unsatisfied constraint: 'if (!(b.randomize() with { x == 2; })) $fatal(1, \"static inline scope\");'\n[0] %Fatal: sv_inline_constraint_scope.sv:15: Assertion failed in top: static inline scope\n%Error: crates/celox-test-suite/verification/repros/sv_inline_constraint_scope.sv:15: Verilog $stop\nAborting...\n" + }, + { + "tool": "icarus", + "version": "Icarus 13.0", + "case": "class::constrained_randomize_inline", + "status": "compile_error", + "log": "/sv-icarus/class/constrained_randomize_inline/source_0.sv:6: sorry: Constraint declarations not supported.\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:13: syntax error\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:13: error: Operand of unary ! is not a primary expression.\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:14: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:13: error: Malformed conditional expression.\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:16: syntax error\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:16: error: Malformed conditional expression.\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:18: syntax error\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:18: error: Operand of unary ! is not a primary expression.\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:18: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:18: error: Malformed conditional expression.\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:18: syntax error\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:18: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:20: syntax error\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:20: error: Malformed conditional expression.\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:22: syntax error\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:22: error: Operand of unary ! is not a primary expression.\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:22: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:22: error: Malformed conditional expression.\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:24: syntax error\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:24: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:24: syntax error\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:24: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:24: syntax error\n/sv-icarus/class/constrained_randomize_inline/source_0.sv:24: error: Malformed statement\n" + }, + { + "tool": "icarus", + "version": "Icarus 13.0", + "case": "class::constrained_randomize_inline_inheritance", + "status": "compile_error", + "log": "/sv-icarus/class/constrained_randomize_inline_inheritance/source_0.sv:9: sorry: Constraint declarations not supported.\n/sv-icarus/class/constrained_randomize_inline_inheritance/source_0.sv:16: syntax error\n/sv-icarus/class/constrained_randomize_inline_inheritance/source_0.sv:16: error: Operand of unary ! is not a primary expression.\n/sv-icarus/class/constrained_randomize_inline_inheritance/source_0.sv:16: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline_inheritance/source_0.sv:16: error: Malformed conditional expression.\n/sv-icarus/class/constrained_randomize_inline_inheritance/source_0.sv:18: syntax error\n/sv-icarus/class/constrained_randomize_inline_inheritance/source_0.sv:18: error: Operand of unary ! is not a primary expression.\n/sv-icarus/class/constrained_randomize_inline_inheritance/source_0.sv:18: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline_inheritance/source_0.sv:18: error: Malformed conditional expression.\n" + }, + { + "tool": "icarus", + "version": "Icarus 13.0", + "case": "class::constrained_randomize_inline_basic", + "status": "compile_error", + "log": "/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:5: sorry: \"inside\" expressions not supported yet.\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:5: sorry: Constraint declarations not supported.\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:6: syntax error\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:6: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:6: syntax error\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:6: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:13: syntax error\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:13: error: Operand of unary ! is not a primary expression.\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:13: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:13: error: Malformed conditional expression.\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:13: syntax error\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:13: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:16: syntax error\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:16: error: Malformed conditional expression.\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:18: syntax error\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:18: error: Operand of unary ! is not a primary expression.\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:18: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline_basic/source_0.sv:18: error: Malformed conditional expression.\n" + }, + { + "tool": "icarus", + "version": "Icarus 13.0", + "case": "class::constrained_randomize_inline_package_instances", + "status": "compile_error", + "log": "/sv-icarus/class/constrained_randomize_inline_package_instances/source_0.sv:5: syntax error\n/sv-icarus/class/constrained_randomize_inline_package_instances/source_0.sv:5: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline_package_instances/source_0.sv:5: syntax error\n/sv-icarus/class/constrained_randomize_inline_package_instances/source_0.sv:5: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline_package_instances/source_0.sv:14: syntax error\n/sv-icarus/class/constrained_randomize_inline_package_instances/source_0.sv:14: error: Operand of unary ! is not a primary expression.\n/sv-icarus/class/constrained_randomize_inline_package_instances/source_0.sv:14: error: Malformed statement\n/sv-icarus/class/constrained_randomize_inline_package_instances/source_0.sv:14: error: Malformed conditional expression.\n" + } + ] +} diff --git a/crates/celox-test-suite/verification/repros/sv_inside_constraints.json b/crates/celox-test-suite/verification/repros/sv_inside_constraints.json new file mode 100644 index 00000000000..caa16930ee9 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_inside_constraints.json @@ -0,0 +1,16 @@ +{ + "observations": [ + { + "tool": "icarus", + "case": "class::constrained_randomize_inside", + "status": "compile_error", + "log": "/sv-icarus/class/constrained_randomize_inside/source_0.sv:5: sorry: \"inside\" expressions not supported yet.\n/sv-icarus/class/constrained_randomize_inside/source_0.sv:5: sorry: \"inside\" expressions not supported yet.\n/sv-icarus/class/constrained_randomize_inside/source_0.sv:6: sorry: \"inside\" expressions not supported yet.\n/sv-icarus/class/constrained_randomize_inside/source_0.sv:6: sorry: \"inside\" expressions not supported yet.\n/sv-icarus/class/constrained_randomize_inside/source_0.sv:5: sorry: Constraint declarations not supported.\n/sv-icarus/class/constrained_randomize_inside/source_0.sv:10: sorry: \"inside\" expressions not supported yet.\n/sv-icarus/class/constrained_randomize_inside/source_0.sv:10: sorry: Constraint declarations not supported.\n" + }, + { + "tool": "icarus", + "case": "class::constrained_randomize_inside_widths", + "status": "compile_error", + "log": "/sv-icarus/class/constrained_randomize_inside_widths/source_0.sv:6: sorry: \"inside\" expressions not supported yet.\n/sv-icarus/class/constrained_randomize_inside_widths/source_0.sv:6: sorry: \"inside\" expressions not supported yet.\n/sv-icarus/class/constrained_randomize_inside_widths/source_0.sv:6: sorry: Constraint declarations not supported.\n" + } + ] +} diff --git a/crates/celox-test-suite/verification/sv/icarus/class.json b/crates/celox-test-suite/verification/sv/icarus/class.json index 6aee7194ef9..c0cd8261b6a 100644 --- a/crates/celox-test-suite/verification/sv/icarus/class.json +++ b/crates/celox-test-suite/verification/sv/icarus/class.json @@ -186,18 +186,47 @@ }, { "category": "Types", - "detail": "Icarus rejects constraint declarations before elaboration. IEEE 1800-2023 18.5 defines these blocks. Celox retains all assertions; Verilator passes the scalar and width/inheritance cases.", + "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": { "category": "simulator_compile_limitation", "evidence": [ "verification/repros/sv_scalar_constraints.json", - "LIMITATIONS.md#systemverilog-suite" + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" + ], + "id": "sv_icarus_scalar_constraints", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "phase": "compile", + "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": [] + }, + "name": "class::constrained_randomize_conditionals", + "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": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_scalar_constraints.json", + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" ], "id": "sv_icarus_scalar_constraints", "observed_version": "Icarus Verilog version 13.0 (devel)", "phase": "compile", - "reason": "Icarus rejects constraint declarations before elaboration. IEEE 1800-2023 18.5 defines these blocks. Celox retains all assertions; Verilator passes the scalar and width/inheritance cases.", + "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": [] }, "name": "class::constrained_randomize_hooks", @@ -209,18 +238,203 @@ }, { "category": "Types", - "detail": "Icarus rejects constraint declarations before elaboration. IEEE 1800-2023 18.5 defines these blocks. Celox retains all assertions; Verilator passes the scalar and width/inheritance cases.", + "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": { "category": "simulator_compile_limitation", "evidence": [ "verification/repros/sv_scalar_constraints.json", - "LIMITATIONS.md#systemverilog-suite" + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" + ], + "id": "sv_icarus_scalar_constraints", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "phase": "compile", + "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": [] + }, + "name": "class::constrained_randomize_inline", + "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": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_scalar_constraints.json", + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" + ], + "id": "sv_icarus_scalar_constraints", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "phase": "compile", + "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": [] + }, + "name": "class::constrained_randomize_inline_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": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_scalar_constraints.json", + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" + ], + "id": "sv_icarus_scalar_constraints", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "phase": "compile", + "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": [] + }, + "name": "class::constrained_randomize_inline_inheritance", + "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": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_scalar_constraints.json", + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" ], "id": "sv_icarus_scalar_constraints", "observed_version": "Icarus Verilog version 13.0 (devel)", "phase": "compile", - "reason": "Icarus rejects constraint declarations before elaboration. IEEE 1800-2023 18.5 defines these blocks. Celox retains all assertions; Verilator passes the scalar and width/inheritance cases.", + "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": [] + }, + "name": "class::constrained_randomize_inline_package_instances", + "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": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_scalar_constraints.json", + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" + ], + "id": "sv_icarus_scalar_constraints", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "phase": "compile", + "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": [] + }, + "name": "class::constrained_randomize_inside", + "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": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_scalar_constraints.json", + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" + ], + "id": "sv_icarus_scalar_constraints", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "phase": "compile", + "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": [] + }, + "name": "class::constrained_randomize_inside_widths", + "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": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_scalar_constraints.json", + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" + ], + "id": "sv_icarus_scalar_constraints", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "phase": "compile", + "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": [] + }, + "name": "class::constrained_randomize_nested_guards", + "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": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_scalar_constraints.json", + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" + ], + "id": "sv_icarus_scalar_constraints", + "observed_version": "Icarus Verilog version 13.0 (devel)", + "phase": "compile", + "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": [] }, "name": "class::constrained_randomize_scalar", @@ -232,18 +446,21 @@ }, { "category": "Types", - "detail": "Icarus rejects constraint declarations before elaboration. IEEE 1800-2023 18.5 defines these blocks. Celox retains all assertions; Verilator passes the scalar and width/inheritance cases.", + "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": { "category": "simulator_compile_limitation", "evidence": [ "verification/repros/sv_scalar_constraints.json", - "LIMITATIONS.md#systemverilog-suite" + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" ], "id": "sv_icarus_scalar_constraints", "observed_version": "Icarus Verilog version 13.0 (devel)", "phase": "compile", - "reason": "Icarus rejects constraint declarations before elaboration. IEEE 1800-2023 18.5 defines these blocks. Celox retains all assertions; Verilator passes the scalar and width/inheritance cases.", + "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": [] }, "name": "class::constrained_randomize_width_and_inheritance", diff --git a/crates/celox-test-suite/verification/sv/limitations.json b/crates/celox-test-suite/verification/sv/limitations.json index a3597307bc6..607baebddef 100644 --- a/crates/celox-test-suite/verification/sv/limitations.json +++ b/crates/celox-test-suite/verification/sv/limitations.json @@ -2601,17 +2601,28 @@ "category": "simulator_compile_limitation", "phase": "compile", "observed_version": "Icarus Verilog version 13.0 (devel)", - "reason": "Icarus rejects constraint declarations before elaboration. IEEE 1800-2023 18.5 defines these blocks. Celox retains all assertions; Verilator passes the scalar and width/inheritance cases.", + "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_scalar_constraints.json", - "LIMITATIONS.md#systemverilog-suite" + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inside_constraints.json", + "verification/repros/sv_conditional_constraints.json", + "verification/repros/sv_inline_constraints.json" ], "cases": { "icarus": [ "class::constrained_randomize_scalar", "class::constrained_randomize_width_and_inheritance", - "class::constrained_randomize_hooks" + "class::constrained_randomize_hooks", + "class::constrained_randomize_inside", + "class::constrained_randomize_inside_widths", + "class::constrained_randomize_conditionals", + "class::constrained_randomize_nested_guards", + "class::constrained_randomize_inline", + "class::constrained_randomize_inline_inheritance", + "class::constrained_randomize_inline_basic", + "class::constrained_randomize_inline_package_instances" ] } }, @@ -2624,11 +2635,30 @@ "upstream": [], "evidence": [ "verification/repros/sv_scalar_constraints.json", - "LIMITATIONS.md#systemverilog-suite" + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inline_constraints.json" + ], + "cases": { + "verilator": [ + "class::constrained_randomize_hooks", + "class::constrained_randomize_inline" + ] + } + }, + { + "id": "sv_verilator_inline_constraint_static_scope", + "category": "simulator_disagreement", + "phase": "execute", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "reason": "Through a Base handle containing a Derived object that hides Base.x, Verilator binds inline x == 2 to Derived.x, conflicting with its x == 9 block. IEEE 1800-2023 18.7 starts inline name lookup in the class of the object handle used at the call. Base.x must be 2 and Derived.x must be 9. The standalone source reproduces UNSAT without the suite adapter. Assertions are retained.", + "upstream": [], + "evidence": [ + "verification/repros/sv_inline_constraint_scope.sv", + "verification/repros/sv_inline_constraints.json" ], "cases": { "verilator": [ - "class::constrained_randomize_hooks" + "class::constrained_randomize_inline_inheritance" ] } } diff --git a/crates/celox-test-suite/verification/sv/verilator/class.json b/crates/celox-test-suite/verification/sv/verilator/class.json index d576761f5c8..cb0538712d6 100644 --- a/crates/celox-test-suite/verification/sv/verilator/class.json +++ b/crates/celox-test-suite/verification/sv/verilator/class.json @@ -109,7 +109,8 @@ "category": "simulator_disagreement", "evidence": [ "verification/repros/sv_scalar_constraints.json", - "LIMITATIONS.md#systemverilog-suite" + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inline_constraints.json" ], "id": "sv_verilator_post_randomize_unsat", "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", @@ -124,6 +125,53 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "Verilator invokes post_randomize unconditionally after an UNSAT ordinary randomize call. Generated C++ calls the post hook after constraint.next without testing its return. IEEE 1800-2023 18.6.3 requires skipping the post hook on failure. The case keeps its assertion and tests that pre_randomize updates state before solving.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_disagreement", + "evidence": [ + "verification/repros/sv_scalar_constraints.json", + "LIMITATIONS.md#systemverilog-suite", + "verification/repros/sv_inline_constraints.json" + ], + "id": "sv_verilator_post_randomize_unsat", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "phase": "execute", + "reason": "Verilator invokes post_randomize unconditionally after an UNSAT ordinary randomize call. Generated C++ calls the post hook after constraint.next without testing its return. IEEE 1800-2023 18.6.3 requires skipping the post hook on failure. The case keeps its assertion and tests that pre_randomize updates state before solving.", + "upstream": [] + }, + "name": "class::constrained_randomize_inline", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Through a Base handle containing a Derived object that hides Base.x, Verilator binds inline x == 2 to Derived.x, conflicting with its x == 9 block. IEEE 1800-2023 18.7 starts inline name lookup in the class of the object handle used at the call. Base.x must be 2 and Derived.x must be 9. The standalone source reproduces UNSAT without the suite adapter. Assertions are retained.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_disagreement", + "evidence": [ + "verification/repros/sv_inline_constraint_scope.sv", + "verification/repros/sv_inline_constraints.json" + ], + "id": "sv_verilator_inline_constraint_static_scope", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "phase": "execute", + "reason": "Through a Base handle containing a Derived object that hides Base.x, Verilator binds inline x == 2 to Derived.x, conflicting with its x == 9 block. IEEE 1800-2023 18.7 starts inline name lookup in the class of the object handle used at the call. Base.x must be 2 and Derived.x must be 9. The standalone source reproduces UNSAT without the suite adapter. Assertions are retained.", + "upstream": [] + }, + "name": "class::constrained_randomize_inline_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 22d5d034586..c622ad2a374 100644 --- a/crates/celox/tests/frontends/systemverilog/class.rs +++ b/crates/celox/tests/frontends/systemverilog/class.rs @@ -932,3 +932,26 @@ sv_backends! { sv_backends! { fn constrained_randomize_hooks(sim) { @case "class::constrained_randomize_hooks"; } } + +sv_backends! { + fn constrained_randomize_inside(sim) { @case "class::constrained_randomize_inside"; } + fn constrained_randomize_inside_widths(sim) { @case "class::constrained_randomize_inside_widths"; } +} + +sv_backends! { + fn constrained_randomize_conditionals(sim) { @case "class::constrained_randomize_conditionals"; } + fn constrained_randomize_nested_guards(sim) { @case "class::constrained_randomize_nested_guards"; } +} + +sv_backends! { + fn constrained_randomize_inline(sim) { @case "class::constrained_randomize_inline"; } + fn constrained_randomize_inline_inheritance(sim) { @case "class::constrained_randomize_inline_inheritance"; } +} + +sv_backends! { + fn constrained_randomize_inline_basic(sim) { @case "class::constrained_randomize_inline_basic"; } +} + +sv_backends! { + fn constrained_randomize_inline_package_instances(sim) { @case "class::constrained_randomize_inline_package_instances"; } +} diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index 103d82b24d7..293906005e3 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -222,11 +222,34 @@ 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). -Constrained enums and `randc`, `inside`, conditional/foreach/soft constraints, -`dist`, `solve before`, constraint modes, external/static blocks, typed parameters -in constraints, and inline `with` remain unsupported. Larger unconstrained `randc` +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 +signedness before arithmetic evaluation. Excessive predicate expansion is rejected +during analysis, including repeated nested membership. Array sets, X/Z wildcard items and `$` bounds are not +yet supported. Membership uses the same seeded solver policy described above. + +Conditional constraints support `if` / `else` and implication (`->`), including +nested blocks. Both sides participate in solving: a required result can constrain +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 +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. +`object.randomize() with { ... }` adds per-call scalar constraints to the +object's declared constraints. It supports the operators, membership and +conditional constraints above, explicit member selection and `randomize(null)`. +Unqualified property names resolve against the handle's declared class; derived +object constraints and hooks still apply. A failed solve preserves properties, +skips the post-hook and restores temporary selection modes. Inline constraints +do not remain installed for later calls. + +This initial inline subset accepts unqualified instance-property references. +Caller-local captures, `local::`, `this` / `super` qualified references, restricted +`with (names)` lookup and scope `std::randomize(...) with` remain unsupported. + A call through `null` is a runtime error. ### Time literal delays {#time-literal-delays}