diff --git a/conformance/sv-tests/README.md b/conformance/sv-tests/README.md index d1cba2b74f9..54eb8ebdb3e 100644 --- a/conformance/sv-tests/README.md +++ b/conformance/sv-tests/README.md @@ -198,6 +198,14 @@ parameters, as in `8.26.3--type_access_extends` and `6.24.2--cast_fn`, `6.24.2--cast_task` and `8.16--cast_func` keep failing because they cast to integral and enum variables. +Tagged packed union support changes `chapter-7/unions/tagged/packed.sv` from +fail to pass in both state modes. The official runner selects simulation: the +probe switches the active member with two tagged constructors and checks the +packed value with its `:assert:` output. Both executions return zero and pass +the assertion. The [reviewed full CI run](https://github.com/celox-sim/celox/actions/runs/40084353934) +contains 2054 case/mode verdicts; these are the only two changed rows, and all +verdicts match the updated expectations. + The report contains each case’s state mode, verdict, selected execution mode, tags, tool return code and path to the official log. The output directory retains both the official log and runner diagnostics for each case and state mode. diff --git a/conformance/sv-tests/expected.tsv b/conformance/sv-tests/expected.tsv index 535226b7930..5d3d4d4fb63 100644 --- a/conformance/sv-tests/expected.tsv +++ b/conformance/sv-tests/expected.tsv @@ -1457,8 +1457,8 @@ chapter-7/unions/packed/basic.sv 2state pass chapter-7/unions/packed/basic.sv 4state pass chapter-7/unions/tagged/basic.sv 2state fail chapter-7/unions/tagged/basic.sv 4state fail -chapter-7/unions/tagged/packed.sv 2state fail -chapter-7/unions/tagged/packed.sv 4state fail +chapter-7/unions/tagged/packed.sv 2state pass +chapter-7/unions/tagged/packed.sv 4state pass chapter-7/unions/unpacked/basic.sv 2state fail chapter-7/unions/unpacked/basic.sv 4state fail chapter-8/8.10--static_methods.sv 2state pass diff --git a/crates/celox-frontend-sv/src/lowering.rs b/crates/celox-frontend-sv/src/lowering.rs index 4b662c6bf0d..8cf8c077ad4 100644 --- a/crates/celox-frontend-sv/src/lowering.rs +++ b/crates/celox-frontend-sv/src/lowering.rs @@ -1227,7 +1227,9 @@ fn kernel_written_names( ); continue; } - sv::ir::Callee::String(_) | sv::ir::Callee::Object(_) => continue, + sv::ir::Callee::String(_) + | sv::ir::Callee::Object(_) + | sv::ir::Callee::Checked { .. } => continue, sv::ir::Callee::Subroutine(name) => name, }; let Some(subroutine) = subroutines @@ -1372,7 +1374,9 @@ impl DriverScan<'_> { } continue; } - sv::ir::Callee::String(_) | sv::ir::Callee::Object(_) => continue, + sv::ir::Callee::String(_) + | sv::ir::Callee::Object(_) + | sv::ir::Callee::Checked { .. } => continue, sv::ir::Callee::Subroutine(name) => name, }; let Some(subroutine) = self @@ -3710,6 +3714,87 @@ fn array_element_connections( .collect() } +/// Tagged unions cannot acquire an arbitrary tag through an integral port connection. +fn check_tagged_port_connections( + parent: &sv::ir::Module, + child: &sv::ir::Module, + connections: &[LoweredSvPortConnection], +) -> Result<(), ParserError> { + let type_of = |name: &str| { + parent + .ports() + .iter() + .find(|port| port.name() == name) + .map(|port| port.r#type()) + .or_else(|| { + parent + .signals() + .iter() + .find(|signal| signal.name() == name) + .map(|signal| signal.r#type()) + }) + }; + for connection in connections { + let Some(port) = child + .ports() + .iter() + .find(|port| port.name() == connection.formal) + else { + continue; + }; + let Some(expr) = &connection.actual_expr else { + continue; + }; + let actual = if let sv::ir::Expr::Ident(name) = expr { + type_of(name) + } else { + None + }; + let writes_actual = matches!( + port.direction(), + sv::ir::PortDirection::Output + | sv::ir::PortDirection::Inout + | sv::ir::PortDirection::Ref + ); + let mut writes_tagged = false; + if writes_actual { + let mut pending = vec![expr]; + while let Some(part) = pending.pop() { + match part { + sv::ir::Expr::Ident(name) => { + writes_tagged |= + type_of(name).is_some_and(|ty| ty.tagged_identity().is_some()); + } + sv::ir::Expr::Concat(parts) => pending.extend(parts), + sv::ir::Expr::Select { expr, .. } | sv::ir::Expr::Resize { expr, .. } => { + pending.push(expr) + } + _ => {} + } + } + } + let target = port.r#type(); + if target.tagged_identity().is_none() && !writes_tagged { + continue; + } + if !actual.is_some_and(|ty| { + ty.tagged_identity() == target.tagged_identity() + && ty.resolved_width() == target.resolved_width() + && ty.unpacked_ranges() == target.unpacked_ranges() + }) { + return Err(ParserError::illegal_context( + "systemverilog tagged union port", + format!( + "port `{}` requires a signal of the same tagged union type", + connection.formal + ), + None, + )); + } + } + Ok(()) +} + fn bind_port_patterns( connections: &mut [LoweredSvPortConnection], child: &LoweredSvModule, @@ -3805,6 +3890,7 @@ pub(crate) fn attach_instance_glue( } None => authored_connections, }; + check_tagged_port_connections(&lowered.source, &child.source, &connections)?; ensure_parent_output_signals( module, &mut parent_variables, diff --git a/crates/celox-frontend-sv/src/lowering/comb.rs b/crates/celox-frontend-sv/src/lowering/comb.rs index f076de318d5..c9117dac590 100644 --- a/crates/celox-frontend-sv/src/lowering/comb.rs +++ b/crates/celox-frontend-sv/src/lowering/comb.rs @@ -3192,6 +3192,13 @@ impl<'p, 'a> Comb<'p, 'a> { .subroutine(name) .cloned() .ok_or_else(|| unsupported(format!("call of `{name}`")))?; + if args + .iter() + .flatten() + .any(|arg| !tagged_actual_guards(arg).is_empty()) + { + return Err(unsupported("checked tagged union argument")); + } // Symbolic execution cannot represent state shared by invocations. // Fall back to Ff, including for runtime declaration initializers. if !subroutine.persistent_locals.is_empty() { diff --git a/crates/celox-frontend-sv/src/lowering/ff.rs b/crates/celox-frontend-sv/src/lowering/ff.rs index 8b17897b8c4..5a8236e21a8 100644 --- a/crates/celox-frontend-sv/src/lowering/ff.rs +++ b/crates/celox-frontend-sv/src/lowering/ff.rs @@ -356,7 +356,9 @@ impl<'p, 'a> Ff<'p, 'a> { self.urandom_state(); continue; } - sv::ir::Callee::String(_) | sv::ir::Callee::Object(_) => continue, + sv::ir::Callee::String(_) + | sv::ir::Callee::Object(_) + | sv::ir::Callee::Checked { .. } => continue, sv::ir::Callee::Subroutine(name) => name, }; let Some(subroutine) = self.m.subroutine(&name).cloned() else { @@ -938,6 +940,28 @@ impl<'p, 'a> Ff<'p, 'a> { return Ok(expr.clone()); } Ok(match expr { + Expr::Call { + callee: sv::ir::Callee::Checked { width, signed }, + args, + .. + } => { + let [Some(condition), Some(value)] = args.as_slice() else { + return Err(unsupported("invalid tagged access check")); + }; + self.system_task( + sv::ir::SystemTask::Assert, + &[ + sv::ir::SystemTaskArg::Expr(condition.clone()), + sv::ir::SystemTaskArg::Str( + "tagged union member does not match the active tag".into(), + ), + ], + None, + )?; + let (_, name) = self.m.temp("tagged_member", *width, *signed, true); + self.assign(&sv::ir::LValue::Ident(name.clone()), value)?; + Expr::Ident(name) + } Expr::Call { callee: sv::ir::Callee::System(sv::ir::SystemFunction::Fread), args, @@ -1733,9 +1757,8 @@ impl<'p, 'a> Ff<'p, 'a> { use sv::ir::{BinaryOp, Expr}; let (current, store_back) = match seed { Some(seed) => { - let lvalues = lvalue_from_expr(seed) - .ok_or_else(|| unsupported("seed variable of `$random`"))?; - (self.hoist(seed)?, Some(lvalues)) + let (lvalues, read, guards) = self.capture_system_actual(seed)?; + (self.hoist(&read)?, Some((lvalues, guards))) } None => (Expr::Ident(self.dist_seed().1), None), }; @@ -1802,10 +1825,13 @@ impl<'p, 'a> Ff<'p, 'a> { }; let result = self.hidden("random_result", &value, true)?; match store_back { - Some(lvalues) => match lvalues.as_slice() { - [lvalue] => self.assign(lvalue, &next)?, - parts => self.assign_concat(parts, &next)?, - }, + Some((lvalues, guards)) => { + self.check_tagged_guards(&guards)?; + match lvalues.as_slice() { + [lvalue] => self.assign(lvalue, &next)?, + parts => self.assign_concat(parts, &next)?, + } + } None => { let (id, _) = self.dist_seed(); let next = self.eval(&next, Some((32, false)))?; @@ -1826,7 +1852,7 @@ impl<'p, 'a> Ff<'p, 'a> { .first() .and_then(Option::as_ref) .ok_or_else(|| unsupported("seed of `$dist_uniform`"))?; - let (lvalues, seed_read) = self.capture_system_actual(seed)?; + let (lvalues, seed_read, guards) = self.capture_system_actual(seed)?; let seed_width = self .m .comparison_width(&seed_read, &seed_read) @@ -1974,6 +2000,7 @@ impl<'p, 'a> Ff<'p, 'a> { signed: true, }; let restored = mux(invalid, original, next); + self.check_tagged_guards(&guards)?; match lvalues.as_slice() { [lvalue] => self.assign(lvalue, &restored)?, parts => self.assign_concat(parts, &restored)?, @@ -1985,15 +2012,33 @@ impl<'p, 'a> Ff<'p, 'a> { }) } + fn check_tagged_guards(&mut self, guards: &[sv::ir::Expr]) -> Result<(), sv::AnalyzerError> { + for guard in guards { + self.system_task( + sv::ir::SystemTask::Assert, + &[ + sv::ir::SystemTaskArg::Expr(guard.clone()), + sv::ir::SystemTaskArg::Str( + "tagged union member does not match the active tag".into(), + ), + ], + None, + )?; + } + Ok(()) + } + /// Capture an inout/output actual's reference before reading or writing /// it, including selectors changed by the call or by other selectors. fn capture_system_actual( &mut self, expr: &sv::ir::Expr, - ) -> Result<(Vec, sv::ir::Expr), sv::AnalyzerError> { + ) -> Result<(Vec, sv::ir::Expr, Vec), sv::AnalyzerError> { use sv::ir::{Expr, LValue}; let parts = lvalue_from_expr(expr).ok_or_else(|| unsupported("integral output/inout actual"))?; + let guards = tagged_actual_guards(expr); + self.check_tagged_guards(&guards)?; let signed = self.expr_signed(expr); let mut captured = Vec::new(); for part in parts { @@ -2017,7 +2062,7 @@ impl<'p, 'a> Ff<'p, 'a> { } else { Expr::Concat(reads) }; - Ok((captured, read)) + Ok((captured, read, guards)) } fn host_hidden( @@ -2062,7 +2107,7 @@ impl<'p, 'a> Ff<'p, 'a> { .ok_or_else(|| unsupported("distribution seed"))?; // Capture selectors once before evaluating the other actuals, and // suspend with an int formal rather than writing the caller's storage. - let (lvalues, captured) = self.capture_system_actual(seed)?; + let (lvalues, captured, guards) = self.capture_system_actual(seed)?; let formal = self.int_formal(captured); let (seed_id, seed_result) = self.host_hidden("distribution_seed", &formal, 32, true, true)?; @@ -2099,6 +2144,7 @@ impl<'p, 'a> Ff<'p, 'a> { }); self.with_kernel(|kernel| kernel.host_request(HostRequestKind::Distribution, site)) .map_err(kernel_error)?; + self.check_tagged_guards(&guards)?; match lvalues.as_slice() { [lvalue] => self.assign(lvalue, &seed_result)?, parts => self.assign_concat(parts, &seed_result)?, @@ -2144,7 +2190,7 @@ impl<'p, 'a> Ff<'p, 'a> { .get(1) .and_then(Option::as_ref) .ok_or_else(|| unsupported("plusargs destination"))?; - let (lvalues, captured) = self.capture_system_actual(expr)?; + let (lvalues, captured, guards) = self.capture_system_actual(expr)?; let width = self .m .comparison_width(expr, expr) @@ -2157,7 +2203,7 @@ impl<'p, 'a> Ff<'p, 'a> { signed: false, is_string: false, }); - Some((lvalues, result)) + Some((lvalues, result, guards)) } else { None }; @@ -2182,7 +2228,8 @@ impl<'p, 'a> Ff<'p, 'a> { }); self.with_kernel(|kernel| kernel.host_request(HostRequestKind::Plusargs, site)) .map_err(kernel_error)?; - if let Some((lvalues, result)) = target { + if let Some((lvalues, result, guards)) = target { + self.check_tagged_guards(&guards)?; match lvalues.as_slice() { [lvalue] => self.assign(lvalue, &result)?, parts => self.assign_concat(parts, &result)?, @@ -3647,13 +3694,18 @@ impl<'p, 'a> Ff<'p, 'a> { .flatten() .or_else(|| param.default.clone()); if param.direction.is_written() { - let lvalues = actual.as_ref().and_then(lvalue_from_expr).ok_or_else(|| { + let reference = actual + .as_ref() + .ok_or_else(|| unsupported("missing output argument"))?; + let lvalues = lvalue_from_expr(reference).ok_or_else(|| { unsupported(format!( "output argument `{}` of `{name}`", param.source_name )) })?; - outputs.push((param.name.clone(), id, lvalues)); + let guards = tagged_actual_guards(reference); + self.check_tagged_guards(&guards)?; + outputs.push((param.name.clone(), id, lvalues, guards)); } if param.direction.is_read() { let actual = actual.ok_or_else(|| { @@ -3741,7 +3793,8 @@ impl<'p, 'a> Ff<'p, 'a> { self.jump(return_block); } self.b.switch_to_block(return_block); - for (formal, id, lvalues) in outputs { + for (formal, id, lvalues, guards) in outputs { + self.check_tagged_guards(&guards)?; let signed = self.m.var(id).signed; if let [lvalue] = lvalues.as_slice() { self.assign(lvalue, &sv::ir::Expr::Ident(formal))?; @@ -5716,6 +5769,7 @@ fn impure_call(pm: &ProcModule<'_>, expr: &sv::ir::Expr) -> Option { sv::ir::Callee::String(_) => continue, // A property can change without the handle changing. sv::ir::Callee::Object(op) => return Some(op.to_string()), + sv::ir::Callee::Checked { .. } => return Some("tagged union access".into()), sv::ir::Callee::Subroutine(name) => name, }; if !visited.insert(name.clone()) { diff --git a/crates/celox-frontend-sv/src/lowering/ff/fread.rs b/crates/celox-frontend-sv/src/lowering/ff/fread.rs index 1a63b5ab2d0..876a884d5ae 100644 --- a/crates/celox-frontend-sv/src/lowering/ff/fread.rs +++ b/crates/celox-frontend-sv/src/lowering/ff/fread.rs @@ -34,7 +34,7 @@ impl Ff<'_, '_> { }; // Evaluate the reference once, then all value operands, then snapshot // the referenced storage so partial reads retain argument side effects. - let (lvalues, captured) = self.capture_system_actual(destination)?; + let (lvalues, captured, guards) = self.capture_system_actual(destination)?; let mut values = Vec::new(); for (position, arg) in args.iter().enumerate().skip(1) { if let Some(arg) = arg { @@ -84,6 +84,7 @@ impl Ff<'_, '_> { u8::from(args.get(3).is_some_and(Option::is_some)).to_string(), ], )?; + self.check_tagged_guards(&guards)?; match lvalues.as_slice() { [target] => self.assign(target, &data)?, targets => self.assign_concat(targets, &data)?, diff --git a/crates/celox-frontend-sv/src/lowering/ff/scan.rs b/crates/celox-frontend-sv/src/lowering/ff/scan.rs index 7a24f55f6b5..dc5629469f8 100644 --- a/crates/celox-frontend-sv/src/lowering/ff/scan.rs +++ b/crates/celox-frontend-sv/src/lowering/ff/scan.rs @@ -55,7 +55,7 @@ impl Ff<'_, '_> { let argument = argument .as_ref() .ok_or_else(|| unsupported("omitted scan destination"))?; - let (lvalues, _) = self.capture_system_actual(argument)?; + let (lvalues, _, guards) = self.capture_system_actual(argument)?; let precision = match lvalues.as_slice() { [one] => self.m.id(one.name()).and_then(|id| self.m.var(id).float), _ => None, @@ -76,7 +76,7 @@ impl Ff<'_, '_> { signed: false, is_string: false, }); - destinations.push((lvalues, Expr::Ident(name))); + destinations.push((lvalues, Expr::Ident(name), guards)); } let site = self .host_request_sites @@ -95,7 +95,7 @@ impl Ff<'_, '_> { .map_err(kernel_error)?; // A failed or ignored output must not overwrite a previously assigned // alias. Scan assignments are contiguous even with suppressed fields. - for (index, (lvalues, value)) in destinations.into_iter().enumerate() { + for (index, (lvalues, value, guards)) in destinations.into_iter().enumerate() { let condition = Expr::Binary { left: Box::new(Expr::Ident(result_name.clone())), op: sv::ir::BinaryOp::Gt, @@ -110,6 +110,7 @@ impl Ff<'_, '_> { false_block: (join, Vec::new()), }); self.b.switch_to_block(write); + self.check_tagged_guards(&guards)?; match lvalues.as_slice() { [one] => self.assign(one, &value)?, parts => self.assign_concat(parts, &value)?, diff --git a/crates/celox-frontend-sv/src/lowering/procedural.rs b/crates/celox-frontend-sv/src/lowering/procedural.rs index 1f420e26e28..3b750498bf7 100644 --- a/crates/celox-frontend-sv/src/lowering/procedural.rs +++ b/crates/celox-frontend-sv/src/lowering/procedural.rs @@ -273,7 +273,9 @@ impl<'a> ProcModule<'a> { continue; } // String operations use the simulator's heap. - sv::ir::Callee::String(_) | sv::ir::Callee::Object(_) => return true, + sv::ir::Callee::String(_) + | sv::ir::Callee::Object(_) + | sv::ir::Callee::Checked { .. } => return true, sv::ir::Callee::Subroutine(name) => name, }; if let Some(subroutine) = self.subroutine(&name) { @@ -1001,7 +1003,9 @@ impl<'a> ProcModule<'a> { pub fn is_callee(&self, callee: &sv::ir::Callee) -> bool { match callee { sv::ir::Callee::System(function) => function.reads_simulation_state(), - sv::ir::Callee::String(_) | sv::ir::Callee::Object(_) => true, + sv::ir::Callee::String(_) + | sv::ir::Callee::Object(_) + | sv::ir::Callee::Checked { .. } => true, sv::ir::Callee::Subroutine(name) => { self.subroutines.contains_key(name) || self.dpi_imports.contains_key(name) } @@ -2587,6 +2591,32 @@ pub(super) fn written_system_arguments( .collect() } +/// Keep checked member references writable while carrying their live tag checks +/// separately. Callers that perform stores must execute these checks. +pub(super) fn tagged_actual_guards(expr: &sv::ir::Expr) -> Vec { + use sv::ir::{Callee, Expr}; + let mut guards = Vec::new(); + let mut pending = vec![expr]; + while let Some(expr) = pending.pop() { + match expr { + Expr::Call { + callee: Callee::Checked { .. }, + args, + .. + } => { + if let [Some(guard), Some(value)] = args.as_slice() { + guards.push(guard.clone()); + pending.push(value); + } + } + Expr::Resize { expr, .. } | Expr::Select { expr, .. } => pending.push(expr), + Expr::Concat(parts) => pending.extend(parts.iter().rev()), + _ => {} + } + } + guards +} + pub(super) fn lvalue_from_expr(expr: &sv::ir::Expr) -> Option> { match expr { sv::ir::Expr::Ident(name) => Some(vec![sv::ir::LValue::Ident(name.clone())]), @@ -2608,6 +2638,14 @@ pub(super) fn lvalue_from_expr(expr: &sv::ir::Expr) -> Option lvalue_from_expr(expr), + sv::ir::Expr::Call { + callee: sv::ir::Callee::Checked { .. }, + args, + .. + } => match args.as_slice() { + [Some(_), Some(value)] => lvalue_from_expr(value), + _ => None, + }, _ => None, } } diff --git a/crates/celox-sv-analyzer/src/ast.rs b/crates/celox-sv-analyzer/src/ast.rs index a33c623e978..b5866c233fd 100644 --- a/crates/celox-sv-analyzer/src/ast.rs +++ b/crates/celox-sv-analyzer/src/ast.rs @@ -956,6 +956,7 @@ impl Module { ); } packed_dimensions.subroutine_param_shapes = Arc::new(subroutine_shapes.clone()); + packed_dimensions.subroutine_directions = Arc::new(subroutine_directions.clone()); packed_dimensions.subroutine_param_names = Arc::new(subroutine_params.clone()); // Array parameters retain a constant value as well as their signal layout. // Bind their values in declaration order before child parameter arguments. @@ -2790,6 +2791,7 @@ struct PackedDimensions { /// The declared shape of each argument of each subroutine, for /// assignment patterns passed as arguments. subroutine_param_shapes: Arc>>, + subroutine_directions: Arc, subroutine_param_names: Arc>>, /// The class whose method is being bound. class_scope: Option, @@ -2814,6 +2816,7 @@ impl PackedDimensions { scope_types_complete: false, type_query: false, subroutine_param_shapes: Arc::default(), + subroutine_directions: Arc::default(), subroutine_param_names: Arc::default(), class_scope: None, } diff --git a/crates/celox-sv-analyzer/src/ast/bound_patterns.rs b/crates/celox-sv-analyzer/src/ast/bound_patterns.rs index 78b6b1f50d8..795f265f5ce 100644 --- a/crates/celox-sv-analyzer/src/ast/bound_patterns.rs +++ b/crates/celox-sv-analyzer/src/ast/bound_patterns.rs @@ -263,7 +263,12 @@ impl BoundPattern { }) .collect(); } else if !shape.members.is_empty() { - if shape.members.len() > 1 && shape.members.iter().all(|m| m.offset() == 0) { + if shape + .members + .iter() + .any(packed_structs::PackedMember::is_tagged) + || (shape.members.len() > 1 && shape.members.iter().all(|m| m.offset() == 0)) + { return Err(unsupported("assignment pattern for a packed union")); } keys = shape diff --git a/crates/celox-sv-analyzer/src/ast/case.rs b/crates/celox-sv-analyzer/src/ast/case.rs index f309f94a38d..4a9e1598fa8 100644 --- a/crates/celox-sv-analyzer/src/ast/case.rs +++ b/crates/celox-sv-analyzer/src/ast/case.rs @@ -65,6 +65,10 @@ pub(super) fn expr_is_two_state( .. } => !matches!(op, crate::system_functions::StringOp::Atoi(_)), // Properties are 2-state. + Expr::Call { + callee: Callee::Checked { .. }, + .. + } => false, Expr::Call { callee: Callee::Object(_), .. diff --git a/crates/celox-sv-analyzer/src/ast/comb_rewrite.rs b/crates/celox-sv-analyzer/src/ast/comb_rewrite.rs index 6241980bc29..68e6e82b630 100644 --- a/crates/celox-sv-analyzer/src/ast/comb_rewrite.rs +++ b/crates/celox-sv-analyzer/src/ast/comb_rewrite.rs @@ -111,6 +111,10 @@ pub(super) fn expr_static_width( callee: Callee::String(op), .. } => Some(op.result_type().0), + Expr::Call { + callee: Callee::Checked { width, .. }, + .. + } => Some(*width), Expr::Call { callee: Callee::Object(op), .. diff --git a/crates/celox-sv-analyzer/src/ast/const_functions.rs b/crates/celox-sv-analyzer/src/ast/const_functions.rs index 0ddd4912b4f..a9503d24d1c 100644 --- a/crates/celox-sv-analyzer/src/ast/const_functions.rs +++ b/crates/celox-sv-analyzer/src/ast/const_functions.rs @@ -475,6 +475,7 @@ fn collect_module_constant_functions( let mut dimensions = PackedDimensions::new(HashMap::default(), const_env, type_aliases); dimensions.subroutine_param_names = Arc::new(subroutine_params.clone()); dimensions.subroutine_param_shapes = Arc::new(subroutine_shapes); + dimensions.subroutine_directions = Arc::new(subroutine_directions.clone()); let mut locals = Vec::new(); let mut counter = 0usize; let mut state = procedural::BodyState { @@ -615,7 +616,10 @@ fn simulation_state_readers(functions: &[Subroutine]) -> HashMap { reads.get_or_insert(*system); } - Callee::System(_) | Callee::String(_) | Callee::Object(_) => {} + Callee::System(_) + | Callee::String(_) + | Callee::Object(_) + | Callee::Checked { .. } => {} Callee::Subroutine(callee) => calls.push(callee.as_str()), } } diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding.rs b/crates/celox-sv-analyzer/src/ast/expression_binding.rs index 90550ded28a..aa217e1c1b2 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding.rs @@ -10,8 +10,8 @@ mod selected; mod strings; pub(super) use calls::{statement as call_statement, statement_root as call_statement_root}; pub(super) use direct::{ - arguments, bind_value, call_name as native_name, callable_name, cast_target_native, real_value, - remove_real_division_guards, ungroup, + arguments, bind_value, call_name as native_name, callable_name, cast_target_native, + member_context, real_value, remove_real_division_guards, ungroup, }; pub(super) use lvalues::{net_lvalue, variable_lvalue}; pub(super) use objects::{ 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 6f80370ce22..1f6ddd9a74a 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs @@ -217,6 +217,7 @@ pub(in crate::ast) fn cast_target_native( enum Finish { ScopeRandomize(Vec>>), + Tagged(packed_structs::Construction), Unary(String), Binary(String), Mux, @@ -267,6 +268,34 @@ pub(in crate::ast) fn bind_value( match job { Job::Enter(id, target, scope) => { let dimensions = scope.as_deref().unwrap_or(dimensions); + if let Some(shape) = target.as_deref() + && shape + .members + .first() + .is_some_and(packed_structs::PackedMember::is_tagged) + && !matches!( + native.expression(id).kind, + ExprKind::Group(_) | ExprKind::Conditional { .. } | ExprKind::Tagged { .. } + ) + { + let actual = if let ExprKind::Cast { target, .. } = native.expression(id).kind { + cast_shape(target, native, tree, dimensions)? + .and_then(|shape| shape.pattern_type(&tree.state, dimensions)) + } else { + bound_patterns::native_value_type(id, tree, dimensions)? + }; + if !actual.is_some_and(|ty| { + ty.members + .first() + .is_some_and(|member| member.same_owner(&shape.members[0])) + && ty.packed_ranges.len() == 1 + && ty.unpacked_ranges.is_empty() + }) { + return Err(unsupported( + "assignment to a tagged union requires the same union type or a tagged expression", + )); + } + } if let Some(call) = objects::rand_mode_call(tree, id, native, dimensions, false)? { values.push(call); continue; @@ -390,8 +419,8 @@ pub(in crate::ast) fn bind_value( Finish::Mux, vec![ (*condition, None), - (*then_expression, None), - (*else_expression, None), + (*then_expression, target.clone()), + (*else_expression, target.clone()), ], ), ExprKind::Concatenation(parts) if !parts.is_empty() => { @@ -410,7 +439,10 @@ pub(in crate::ast) fn bind_value( tree, dimensions, )?), - vec![(*expression, None)], + vec![( + *expression, + cast_shape(*target, native, tree, dimensions)?.map(Rc::new), + )], ), ExprKind::Call { expression, @@ -672,6 +704,13 @@ pub(in crate::ast) fn bind_value( return Err(unsupported(format!("integral argument of `{name}`"))); } let actuals = args.iter().map(|arg| arg.value).collect::>(); + for (position, id) in actuals.iter().enumerate() { + if function.writes_argument(position) + && let Some(id) = id + { + check_tagged_copyout(*id, None, tree, dimensions)?; + } + } ( Finish::Call { name, @@ -690,6 +729,14 @@ pub(in crate::ast) fn bind_value( .get(&name) .and_then(|shapes| shapes.get(position)) { + if dimensions + .subroutine_directions + .get(&name) + .and_then(|directions| directions.get(position)) + .is_some_and(|direction| direction.is_written()) + { + check_tagged_copyout(*id, Some(shape), tree, dimensions)?; + } array_compatibility::check_native_unpacked_assignment( &tree.state, *id, @@ -814,7 +861,25 @@ pub(in crate::ast) fn bind_value( ExprKind::Assignment { .. } => { return Err(unsupported("assignment used as an expression")); } - ExprKind::Tagged { .. } => return Err(unsupported("tagged union expression")), + ExprKind::Tagged { member, value } => { + let shape = target.as_deref().ok_or_else(|| { + unsupported("tagged union expression without a type context") + })?; + let plan = packed_structs::construction_member( + shape, + &instances::normalize_identifier(&member.spelling), + )?; + if value.is_some() != plan.shape.is_some() { + return Err(unsupported( + "tagged member payload does not match void/non-void member", + )); + } + let children = value + .iter() + .map(|id| (*id, plan.shape.clone().map(Rc::new))) + .collect(); + (Finish::Tagged(plan), children) + } ExprKind::Streaming { .. } => { return Err(unsupported("streaming concatenation")); } @@ -837,6 +902,9 @@ pub(in crate::ast) fn bind_value( let start = values.len().checked_sub(count).ok_or_else(disagreement)?; let mut operands = values.split_off(start); let value = match finish { + Finish::Tagged(plan) => { + packed_structs::construct(&tree.state, plan, operands.pop(), dimensions)? + } Finish::Unary(op) => { let operand = operands.pop().ok_or_else(disagreement)?; if strings::string_value(&operand, dimensions) { @@ -1455,11 +1523,15 @@ fn selected_value( read_index_value(*id, native, tree, dimensions)?; } } - Ok(expr_from_lvalue( + let value = expr_from_lvalue( &tree.state, &selected_lvalue(root, native, tree, dimensions, false)?, dimensions, - )) + ); + let guards = member_context(root, native, tree, dimensions)? + .map(|(guards, _)| guards) + .unwrap_or_default(); + packed_structs::checked_value(guards, value, &tree.state, dimensions) } pub(in crate::ast) fn selected_lvalue( @@ -1485,6 +1557,14 @@ pub(in crate::ast) fn selected_lvalue( return packed_structs::whole_member(&tree.state, parts, qualified, dimensions); } let finish = |name: String, context: &PackedDimensions, strict: bool| -> Converted { + if context.get(&name).is_some_and(|ty| { + ty.members + .first() + .is_some_and(packed_structs::PackedMember::is_tagged) + && suffix.len() >= ty.unpacked.len() + ty.packed.len() + }) { + return Err(unsupported("bit-select or part-select of a tagged union")); + } if context .get(&name) .is_some_and(|ty| ty.real && suffix.len() > ty.unpacked.len()) @@ -1769,6 +1849,77 @@ pub(in crate::ast) fn remove_real_division_guards(expr: Expr, dims: &PackedDimen } } +/// Preserve the native member path before flattening it to bit coordinates. +pub(in crate::ast) fn member_context( + mut root: ExprId, + native: &Declarations, + tree: &AnalysisContext<'_>, + dims: &PackedDimensions, +) -> Converted, Type)>> { + while let ExprKind::Select { expression, .. } = native.expression(root).kind { + root = expression; + } + if !matches!(native.expression(root).kind, ExprKind::Member { .. }) { + return Ok(None); + } + let (mut parts, qualified) = path(root, native, tree, dims)?; + if let Some(name) = qualified { + parts[0] = name; + } + packed_structs::member_access(parts, dims, &tree.state) +} + +fn cast_shape( + target: ExprId, + native: &Declarations, + tree: &AnalysisContext<'_>, + dims: &PackedDimensions, +) -> Converted> { + let ty = if let Some(name) = call_name(&tree.state, target, native) { + dims.type_aliases.get(&name).cloned() + } else if let ExprKind::Type(id) = native.expression(target).kind { + type_binding::binding::bind_in(id, native, tree, dims)? + } else { + None + }; + Ok(ty + .filter(|ty| !ty.members.is_empty()) + .map(|ty| procedural::dimensions_from_type(&ty))) +} + +/// Output/inout copy-out is an assignment to the actual, whose nominal tagged +/// type must match the formal. Concatenations and system outputs are integral. +fn check_tagged_copyout( + root: ExprId, + formal: Option<&VariableDimensions>, + tree: &AnalysisContext<'_>, + dims: &PackedDimensions, +) -> Converted<()> { + let native = tree.declarations(); + let mut pending = vec![(root, formal)]; + while let Some((root, formal)) = pending.pop() { + let root = ungroup(root, native); + if let ExprKind::Concatenation(parts) = &native.expression(root).kind { + pending.extend(parts.iter().map(|id| (*id, None))); + continue; + } + let Some(actual) = bound_patterns::native_value_type(root, tree, dims)? else { + continue; + }; + if actual.tagged_identity().is_some() + && formal + .and_then(|shape| shape.pattern_type(&tree.state, dims)) + .as_ref() + != Some(&actual) + { + return Err(unsupported( + "copy-out to a tagged union requires the same union type", + )); + } + } + Ok(()) +} + #[cfg(test)] mod string_literal_tests { use super::packed_string_literal; diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/lvalues.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/lvalues.rs index ff9e23a4826..e022fc51b3e 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/lvalues.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/lvalues.rs @@ -14,6 +14,11 @@ pub(in crate::ast) fn net_lvalue( tree: &AnalysisContext<'_>, dimensions: &PackedDimensions, ) -> Converted { + if direct::member_context(root, native, tree, dimensions)? + .is_some_and(|(guards, _)| !guards.is_empty()) + { + return Err(unsupported("continuous driver of a tagged union member")); + } direct::selected_lvalue(root, native, tree, dimensions, true) } #[cfg(test)] diff --git a/crates/celox-sv-analyzer/src/ast/expressions.rs b/crates/celox-sv-analyzer/src/ast/expressions.rs index 5dd450c54b0..c19568558e4 100644 --- a/crates/celox-sv-analyzer/src/ast/expressions.rs +++ b/crates/celox-sv-analyzer/src/ast/expressions.rs @@ -285,6 +285,13 @@ pub(super) fn query_actual_is_writable(expression: &Expr, dimensions: &PackedDim .const_env .contains_key(¶meters::unbounded_parameter_marker(name)) } + Expr::Call { + callee: Callee::Checked { .. }, + args, + .. + } => { + matches!(args.as_slice(), [Some(_), Some(value)] if query_actual_is_writable(value, dimensions)) + } Expr::Select { expr, .. } => query_actual_is_writable(expr, dimensions), Expr::Concat(parts) => { !parts.is_empty() diff --git a/crates/celox-sv-analyzer/src/ast/generate.rs b/crates/celox-sv-analyzer/src/ast/generate.rs index 37f63213a44..f5b19ef58bf 100644 --- a/crates/celox-sv-analyzer/src/ast/generate.rs +++ b/crates/celox-sv-analyzer/src/ast/generate.rs @@ -310,6 +310,10 @@ impl Item { local.subroutine_param_shapes = Arc::new(self.function_aliases((*dimensions.subroutine_param_shapes).clone())); } + if !dimensions.subroutine_directions.is_empty() { + local.subroutine_directions = + Arc::new(self.function_aliases((*dimensions.subroutine_directions).clone())); + } if !dimensions.function_return_types.is_empty() { local.function_return_types = self.function_aliases(dimensions.function_return_types.clone()); diff --git a/crates/celox-sv-analyzer/src/ast/inlining.rs b/crates/celox-sv-analyzer/src/ast/inlining.rs index 424f95348e4..bcbffdacd43 100644 --- a/crates/celox-sv-analyzer/src/ast/inlining.rs +++ b/crates/celox-sv-analyzer/src/ast/inlining.rs @@ -123,6 +123,10 @@ pub(super) fn expr_signedness_with_return_types( callee: Callee::String(op), .. } => Some(op.result_type().1), + Expr::Call { + callee: Callee::Checked { signed, .. }, + .. + } => Some(*signed), Expr::Call { callee: Callee::Object(op), .. @@ -146,7 +150,8 @@ pub(super) fn calls_subroutine(expr: &Expr) -> bool { fn constant(expr: &ConstExpr) -> bool { match expr { ConstExpr::Function { callee, args, .. } => { - callee.subroutine().is_some() || args.iter().any(constant) + (callee.subroutine().is_some() || matches!(callee, Callee::Checked { .. })) + || args.iter().any(constant) } ConstExpr::SelectRange { expr, msb, lsb, .. } => { constant(expr) || constant(msb) || constant(lsb) @@ -164,7 +169,9 @@ pub(super) fn calls_subroutine(expr: &Expr) -> bool { } match expr { Expr::Call { callee, args, .. } => { - callee.subroutine().is_some() || args.iter().flatten().any(calls_subroutine) + callee.subroutine().is_some() + || matches!(callee, Callee::Checked { .. }) + || args.iter().flatten().any(calls_subroutine) } Expr::Ident(_) | Expr::Literal(_) => false, Expr::Select { expr, msb, lsb, .. } => { diff --git a/crates/celox-sv-analyzer/src/ast/packed_structs.rs b/crates/celox-sv-analyzer/src/ast/packed_structs.rs index 55f7b038349..c0932e27f40 100644 --- a/crates/celox-sv-analyzer/src/ast/packed_structs.rs +++ b/crates/celox-sv-analyzer/src/ast/packed_structs.rs @@ -4,6 +4,10 @@ use super::*; mod layout; mod selects; +mod tagged; +pub(in crate::ast) use tagged::{ + Construction, checked_value, construct, construction_member, member_access, +}; #[cfg(test)] mod tests; @@ -16,10 +20,18 @@ pub(super) struct PackedMember { owner: Arc, name: String, offset: usize, + tag: Option, + is_void: bool, r#type: Type, } impl PackedMember { + pub(in crate::ast) fn is_tagged(&self) -> bool { + self.tag.is_some() + } + pub(in crate::ast) fn same_owner(&self, other: &Self) -> bool { + self.owner == other.owner + } /// This member with its type replaced by `map` of it. pub(in crate::ast) fn with_type(mut self, map: impl FnOnce(Type) -> Type) -> Self { self.r#type = map(self.r#type); @@ -38,3 +50,11 @@ impl PackedMember { &self.r#type } } + +/// IEEE 1800-2023 7.3.2: tag bits precede a right-justified payload. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub(in crate::ast) struct TaggedMember { + index: usize, + tag_width: usize, + payload_width: usize, +} diff --git a/crates/celox-sv-analyzer/src/ast/packed_structs/layout.rs b/crates/celox-sv-analyzer/src/ast/packed_structs/layout.rs index c7cda41d379..2409ee97561 100644 --- a/crates/celox-sv-analyzer/src/ast/packed_structs/layout.rs +++ b/crates/celox-sv-analyzer/src/ast/packed_structs/layout.rs @@ -7,6 +7,7 @@ pub(in crate::ast) enum AggregateKind { Struct, HardUnion, SoftUnion, + TaggedUnion, } /// Freeze member bounds in the declaration environment before generated scopes @@ -40,14 +41,14 @@ pub(in crate::ast) fn native_type( kind: AggregateKind, signed: bool, owner: Arc, - fields: Vec<(String, Type)>, + fields: Vec<(String, Type, bool)>, ranges: Vec, env: &HashMap, ) -> Option { let mut names = HashSet::default(); let members = fields .into_iter() - .map(|(name, ty)| { + .map(|(name, ty, is_void)| { if !names.insert(name.clone()) { return None; } @@ -55,6 +56,8 @@ pub(in crate::ast) fn native_type( owner: owner.clone(), name, offset: 0, + tag: None, + is_void, r#type: capture_member_type(state, ty, env)?, }) }) @@ -72,7 +75,11 @@ fn finish_type( let mut width = 0usize; // The first declared member occupies the most significant bits. for member in members.iter_mut().rev() { - let member_width = expr_type_from_type(state, &member.r#type, const_env)?.width; + let member_width = if member.is_void { + 0 + } else { + expr_type_from_type(state, &member.r#type, const_env)?.width + }; if !matches!(kind, AggregateKind::Struct) { // IEEE 1800-2023 7.3.1: hard packed members share all bits // and must have the same width. @@ -86,9 +93,22 @@ fn finish_type( width = width.checked_add(member_width)?; } } - let kind = if members - .iter() - .all(|member| member.r#type.kind == TypeKind::Bit) + let tagged = matches!(kind, AggregateKind::TaggedUnion); + if tagged { + let tag_width = (usize::BITS - members.len().checked_sub(1)?.leading_zeros()) as usize; + for (index, member) in members.iter_mut().enumerate() { + member.tag = Some(TaggedMember { + index, + tag_width, + payload_width: width, + }); + } + width = width.checked_add(tag_width)?; + } + let kind = if !tagged + && members + .iter() + .all(|member| member.r#type.kind == TypeKind::Bit) { TypeKind::Bit } else { diff --git a/crates/celox-sv-analyzer/src/ast/packed_structs/selects.rs b/crates/celox-sv-analyzer/src/ast/packed_structs/selects.rs index 382384aad5d..e9f47900bf7 100644 --- a/crates/celox-sv-analyzer/src/ast/packed_structs/selects.rs +++ b/crates/celox-sv-analyzer/src/ast/packed_structs/selects.rs @@ -4,7 +4,7 @@ use super::*; /// Collapse an interface handle/member prefix using its bound symbols. Any /// remaining path selects a packed-structure member of the interface signal. -fn bind_interface_path( +pub(super) fn bind_interface_path( state: &AnalysisState, path: &mut Vec, dimensions: &PackedDimensions, @@ -40,6 +40,9 @@ fn selected_member<'a>( let mut selected = None; for name in &path[1..] { let member = members.iter().find(|member| &member.name == name)?; + if member.is_void { + return None; + } offset = offset.checked_add(member.offset)?; selected = Some(&member.r#type); members = if member.r#type.packed_ranges.len() == 1 { diff --git a/crates/celox-sv-analyzer/src/ast/packed_structs/tagged.rs b/crates/celox-sv-analyzer/src/ast/packed_structs/tagged.rs new file mode 100644 index 00000000000..69130cd13c6 --- /dev/null +++ b/crates/celox-sv-analyzer/src/ast/packed_structs/tagged.rs @@ -0,0 +1,159 @@ +//! Tagged packed values and access checks (IEEE 1800-2023 7.3.2, 11.9). +use super::*; + +pub(in crate::ast) struct Construction { + tag: TaggedMember, + pub shape: Option, + signed: bool, +} + +pub(in crate::ast) fn construction_member( + shape: &VariableDimensions, + name: &str, +) -> Converted { + if !shape.members.first().is_some_and(PackedMember::is_tagged) { + return Err(unsupported("tagged union expression for an untagged type")); + } + if !shape.unpacked.is_empty() || shape.packed.len() != 1 { + return Err(unsupported( + "tagged expression without a scalar union context", + )); + } + let member = shape + .members + .iter() + .find(|m| m.name == name) + .ok_or_else(|| unsupported(format!("unknown tagged union member `{name}`")))?; + let tag = member + .tag + .clone() + .ok_or_else(|| unsupported("tagged expression for an untagged type"))?; + Ok(Construction { + tag, + shape: (!member.is_void).then(|| procedural::dimensions_from_type(&member.r#type)), + signed: shape.signed, + }) +} + +pub(in crate::ast) fn construct( + state: &AnalysisState, + plan: Construction, + value: Option, + dims: &PackedDimensions, +) -> Converted { + let mut parts = Vec::new(); + if plan.tag.tag_width > 0 { + parts.push(Expr::Literal(format!( + "{}'d{}", + plan.tag.tag_width, plan.tag.index + ))); + } + let width = match &plan.shape { + Some(shape) => patterns::shape_width(state, shape, dims) + .ok_or_else(|| unsupported("tagged payload width"))?, + None => 0, + }; + if plan.tag.payload_width > width { + parts.push(Expr::Literal(format!( + "{}'bx", + plan.tag.payload_width - width + ))); + } + match (plan.shape, value) { + (Some(shape), Some(value)) => { + let signed = + dimensions::expression_signedness(&value, dims, &dims.const_env).unwrap_or(false); + parts.push(patterns::assignment_value( + state, &value, signed, None, &shape, dims, false, + )?); + } + (None, None) => {} + _ => { + return Err(unsupported( + "tagged member payload does not match void/non-void member", + )); + } + } + Ok(Expr::Resize { + expr: Box::new(Expr::Concat(parts)), + width: plan.tag.tag_width + plan.tag.payload_width, + signed: plan.signed, + }) +} + +/// A member path can cross several nested tags; each must be checked. +pub(in crate::ast) fn member_access( + mut path: Vec, + dims: &PackedDimensions, + state: &AnalysisState, +) -> Converted, Type)>> { + selects::bind_interface_path(state, &mut path, dims); + let Some(root) = path.first().and_then(|name| dims.get(name)) else { + return Ok(None); + }; + if path.len() < 2 || !root.unpacked.is_empty() || root.packed.len() != 1 { + return Ok(None); + } + let mut members = &root.members; + let mut offset = 0; + let mut guards = Vec::new(); + let mut result = None; + for name in &path[1..] { + let Some(member) = members.iter().find(|m| &m.name == name) else { + return Ok(None); + }; + if member.is_void { + return Err(unsupported("access to a void tagged union member")); + } + if let Some(tag) = &member.tag { + if tag.tag_width > 0 { + let lsb = offset + tag.payload_width; + guards.push(Expr::Binary { + left: Box::new(Expr::Select { + expr: Box::new(Expr::Ident(path[0].clone())), + msb: ConstExpr::Literal((lsb + tag.tag_width - 1).to_string()), + lsb: ConstExpr::Literal(lsb.to_string()), + signed: false, + }), + op: BinaryOp::EqCase, + right: Box::new(Expr::Literal(format!("{}'d{}", tag.tag_width, tag.index))), + }); + } + } + offset += member.offset; + result = Some(member.r#type.clone()); + members = &member.r#type.members; + } + Ok(result.map(|ty| (guards, ty))) +} + +pub(in crate::ast) fn checked_value( + guards: Vec, + mut value: Expr, + state: &AnalysisState, + dims: &PackedDimensions, +) -> Converted { + if guards.is_empty() { + return Ok(value); + } + let width = + expr_static_width(state, &value, dims).ok_or_else(|| unsupported("tagged access width"))?; + let signed = dimensions::expression_signedness(&value, dims, &dims.const_env).unwrap_or(false); + for guard in guards.into_iter().rev() { + value = Expr::Call { + callee: Callee::Checked { width, signed }, + args: vec![Some(guard), Some(value)], + arg_order: Vec::new(), + }; + } + Ok(value) +} + +impl Type { + pub(crate) fn tagged_identity(&self) -> Option<&str> { + self.members + .first() + .filter(|member| member.is_tagged()) + .map(|member| member.owner.as_ref()) + } +} diff --git a/crates/celox-sv-analyzer/src/ast/packed_structs/tests.rs b/crates/celox-sv-analyzer/src/ast/packed_structs/tests.rs index a9a0fd594aa..6c745e2f934 100644 --- a/crates/celox-sv-analyzer/src/ast/packed_structs/tests.rs +++ b/crates/celox-sv-analyzer/src/ast/packed_structs/tests.rs @@ -49,7 +49,6 @@ fn rejects_invalid_or_unsupported_struct_shapes() { for body in [ "struct { logic a; } value;", "union packed { logic a; logic [1:0] b; } value;", - "union tagged packed { logic a; logic b; } value;", "union soft { real a; bit [63:0] b; } value;", "union soft { logic a[2]; logic b; } value;", "union soft { logic a; logic a; } value;", @@ -173,3 +172,40 @@ fn rejects_member_access_on_packed_struct_array_aliases() { ); } } + +#[test] +fn tagged_union_layout_includes_minimal_tag_and_maximum_payload() { + let ir = analyze_source( + r#" + module Top; + union tagged packed { void Empty; logic [7:0] ByteValue; logic [3:0] Nibble; } three; + union tagged packed { void Empty; bit [129:0] Full; } wide; + union tagged packed { void A; void B; } flags; + union tagged packed { logic [7:0] Only; } one; + endmodule + "#, + Path::new("tagged_layout.sv"), + ) + .unwrap(); + for (name, width) in [("three", 10), ("wide", 131), ("flags", 1), ("one", 8)] { + let ty = ir.modules()[0] + .signals() + .iter() + .find(|s| s.name() == name) + .unwrap() + .r#type(); + assert_eq!(ty.resolved_width(), Some(width)); + assert_eq!(ty.kind(), ir::TypeKind::Logic); + } +} + +#[test] +fn rejects_empty_tagged_union_without_panicking() { + assert!( + analyze_source( + "module Top; union tagged packed {} item; endmodule", + Path::new("empty_tagged.sv") + ) + .is_err() + ); +} diff --git a/crates/celox-sv-analyzer/src/ast/parameters/skipped.rs b/crates/celox-sv-analyzer/src/ast/parameters/skipped.rs index 1184772f60f..6572ebce485 100644 --- a/crates/celox-sv-analyzer/src/ast/parameters/skipped.rs +++ b/crates/celox-sv-analyzer/src/ast/parameters/skipped.rs @@ -407,7 +407,12 @@ fn pattern_items( let plan = bound_patterns::prepare_native(root, tree, dims, Some(shape))?; let wrong = || unsupported("assignment pattern items do not match the target shape"); if shape.unpacked.is_empty() && shape.packed.len() <= 1 && !shape.members.is_empty() { - if shape.members.len() > 1 && shape.members.iter().all(|member| member.offset() == 0) { + if shape + .members + .iter() + .any(packed_structs::PackedMember::is_tagged) + || (shape.members.len() > 1 && shape.members.iter().all(|member| member.offset() == 0)) + { return Err(unsupported("assignment pattern for a packed union")); } let mut values = Vec::new(); diff --git a/crates/celox-sv-analyzer/src/ast/patterns.rs b/crates/celox-sv-analyzer/src/ast/patterns.rs index 59521c62944..b0a1da41272 100644 --- a/crates/celox-sv-analyzer/src/ast/patterns.rs +++ b/crates/celox-sv-analyzer/src/ast/patterns.rs @@ -174,7 +174,13 @@ pub(super) fn assignment_value( ])); } if !shape.members.is_empty() { - if shape.members.len() > 1 && shape.members.iter().all(|member| member.offset() == 0) { + if shape + .members + .iter() + .any(packed_structs::PackedMember::is_tagged) + || (shape.members.len() > 1 + && shape.members.iter().all(|member| member.offset() == 0)) + { return Err(unsupported("assignment pattern for a packed union")); } return Ok(Expr::Concat( diff --git a/crates/celox-sv-analyzer/src/ast/patterns/binding.rs b/crates/celox-sv-analyzer/src/ast/patterns/binding.rs index 79d17825612..373fe5f90db 100644 --- a/crates/celox-sv-analyzer/src/ast/patterns/binding.rs +++ b/crates/celox-sv-analyzer/src/ast/patterns/binding.rs @@ -173,7 +173,9 @@ fn select<'a>( } if !shape.members.is_empty() { let members = &shape.members; - if members.len() > 1 && members.iter().all(|member| member.offset() == 0) { + if members.iter().any(packed_structs::PackedMember::is_tagged) + || (members.len() > 1 && members.iter().all(|member| member.offset() == 0)) + { return Err(unsupported("assignment pattern for a packed union")); } let values = match kind { diff --git a/crates/celox-sv-analyzer/src/ast/procedural.rs b/crates/celox-sv-analyzer/src/ast/procedural.rs index 11830353e22..d47ebdb5f70 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural.rs @@ -67,6 +67,7 @@ pub(super) struct BodyBuilder<'s, 't, 'a> { /// Whether the body's variables are automatic by default. automatic: bool, task_timing: bool, + return_shape: Option, pub(super) sensitivity_body: Vec, } @@ -142,6 +143,7 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { Self { automatic, task_timing: false, + return_shape: None, sensitivity_body: Vec::new(), tree, dims: dims.clone(), @@ -472,6 +474,14 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { if let celox_sv_syntax::ExprKind::Concatenation(items) = &native.expression(id).kind { pending.extend(items.iter().rev().copied()); } else { + if expression_binding::member_context(id, native, self.tree, &self.dims)? + .is_some_and(|(guards, _)| !guards.is_empty()) + { + return Err(unsupported( + "concatenation assignment to a tagged union member", + )); + } + self.reject_tagged_integral_target(id)?; let mut target = expression_binding::variable_lvalue(id, native, self.tree, &self.dims)?; self.rename_lvalue(&mut target); @@ -520,6 +530,9 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { if let Some(stmt) = self.property_assignment(op, nonblocking, left, right)? { return Ok(stmt); } + if op != "=" { + self.reject_tagged_integral_target(left)?; + } let (written, lhs) = self.native_lvalue(left)?; if op != "=" && expression_binding::native_string( @@ -531,7 +544,24 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { { return Err(unsupported(format!("operator `{op}` on a string"))); } - let mut rhs = if op == "=" { + let member_context = expression_binding::member_context( + left, + self.tree.declarations(), + self.tree, + &self.dims, + )?; + let mut rhs = if op == "=" + && let Some((_, ty)) = &member_context + { + let shape = procedural::dimensions_from_type(ty); + expression_binding::bind_value( + right, + self.tree.declarations(), + self.tree, + &self.dims, + Some(&shape), + )? + } else if op == "=" { expression_binding::expression( right, self.tree.declarations(), @@ -544,16 +574,24 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { expression_binding::value(right, self.tree.declarations(), self.tree, &self.dims)?; assignment_op_expr(&self.tree.state, &written, op, value, &self.dims)? }; - // A two-state member of a four-state packed struct drops unknown bits. + // Preserve assignment sizing before checked accesses introduce a temporary + // (IEEE 1800-2023 11.8.2), using the selected destination width. + // A two-state member of a four-state packed struct also drops unknown bits. if matches!( written, LValue::Select { is_2state: true, .. } - ) { + ) || member_context + .as_ref() + .is_some_and(|(guards, _)| !guards.is_empty()) + { rhs = coerce_procedural_assignment_rhs(&self.tree.state, rhs, &written, &self.dims); } + if let Some((guards, _)) = member_context { + rhs = packed_structs::checked_value(guards, rhs, &self.tree.state, &self.dims)?; + } self.rename_expr(&mut rhs); Ok(Stmt::Assign { lhs, @@ -831,6 +869,17 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { }) } + fn reject_tagged_integral_target(&self, root: celox_sv_syntax::ExprId) -> Converted<()> { + if dimensions::operand_shape(root, self.tree, &self.dims)?.is_some_and(|ty| { + ty.members + .first() + .is_some_and(packed_structs::PackedMember::is_tagged) + }) { + return Err(unsupported("integral update of a tagged union")); + } + Ok(()) + } + fn inc_or_dec(&self, root: celox_sv_syntax::ExprId) -> Result { let celox_sv_syntax::ExprKind::Unary { operator, @@ -856,6 +905,7 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { expression_binding::object_receiver(self.tree, receiver, native, &self.dims)?; return self.property_store(&property, handle, op, Expr::Literal("1".into())); } + self.reject_tagged_integral_target(*expression)?; let (written, lhs) = self.native_lvalue(*expression)?; let mut rhs = assignment_op_expr( &self.tree.state, @@ -864,6 +914,11 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { Expr::Literal("1".into()), &self.dims, )?; + if let Some((guards, _)) = + expression_binding::member_context(*expression, native, self.tree, &self.dims)? + { + rhs = packed_structs::checked_value(guards, rhs, &self.tree.state, &self.dims)?; + } self.rename_expr(&mut rhs); Ok(Stmt::Assign { lhs, @@ -1978,10 +2033,17 @@ pub(super) fn lower_subroutine( // any formal can shadow those names (IEEE 1800-2023 13.5.3). let defaults = params .iter() - .map(|(_, _, _, default)| { + .map(|(_, _, ty, default)| { default .map(|root| { - let mut value = expression_binding::bind(root, tree, &builder.dims)?; + let shape = ty.tagged_identity().map(|_| dimensions_from_type(ty)); + let mut value = expression_binding::bind_value( + root, + tree.declarations(), + tree, + &builder.dims, + shape.as_ref(), + )?; builder.rename_expr(&mut value); Ok(value) }) @@ -2028,6 +2090,10 @@ pub(super) fn lower_subroutine( if let (Some(name), Some(ty)) = (&return_var, &return_type) { formal_types.insert(name.clone(), scoped_type(ty.clone(), declaration_env)); } + builder.return_shape = return_type + .as_ref() + .filter(|ty| ty.tagged_identity().is_some()) + .map(dimensions_from_type); let parameter_locals_end = builder.state.locals.len(); let mut items = native.items.clone(); let mut prologue = Vec::new(); diff --git a/crates/celox-sv-analyzer/src/ast/procedural/control.rs b/crates/celox-sv-analyzer/src/ast/procedural/control.rs index 8b1c7b4b101..44d2400f926 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural/control.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural/control.rs @@ -251,7 +251,19 @@ impl BodyBuilder<'_, '_, '_> { StatementKind::Break => output.push(Stmt::Break), StatementKind::Continue => output.push(Stmt::Continue), StatementKind::Return(value) => { - let value = value.map(|id| self.native_value(id)).transpose()?; + let value = value + .map(|id| { + let mut value = expression_binding::bind_value( + id, + native, + self.tree, + &self.dims, + self.return_shape.as_ref(), + )?; + self.rename_expr(&mut value); + Ok(value) + }) + .transpose()?; output.push(Stmt::Return(value)); } _ => output.extend(self.native_statement_leaf(&native.statement(id).kind)?), diff --git a/crates/celox-sv-analyzer/src/ast/type_binding/binding.rs b/crates/celox-sv-analyzer/src/ast/type_binding/binding.rs index 6ff5bd6c541..4f6d6b471c3 100644 --- a/crates/celox-sv-analyzer/src/ast/type_binding/binding.rs +++ b/crates/celox-sv-analyzer/src/ast/type_binding/binding.rs @@ -18,11 +18,14 @@ pub(in crate::ast) fn bind_in( ) -> Converted> { enum Job { Enter(TypeId), + Void, Enum(TypeId, Vec), Aggregate { owner: Arc, union: bool, soft: bool, + tagged: bool, + voids: Vec, signed: bool, names: Vec, ranges: Vec, @@ -32,6 +35,7 @@ pub(in crate::ast) fn bind_in( let mut values = Vec::::new(); while let Some(job) = jobs.pop() { match job { + Job::Void => values.push(Type::new(TypeKind::Bit)), Job::Enter(id) => { let data = native.data_type(id); let ranges = if matches!(data.kind, DataTypeKind::Struct { .. }) { @@ -96,10 +100,11 @@ pub(in crate::ast) fn bind_in( packed, fields, } => { - if (!packed && !soft) || *tagged { + if !packed && !soft { return Ok(None); } let mut names = Vec::new(); + let mut voids = Vec::new(); let mut seen = HashSet::default(); for field in fields { if field.random.is_some() @@ -114,6 +119,11 @@ pub(in crate::ast) fn bind_in( "duplicate aggregate field `{name}`" ))); } + let is_void = matches!(&native.data_type(field.data_type).kind, DataTypeKind::Builtin(name) if name == "void"); + if is_void && !tagged { + return Ok(None); + } + voids.push(is_void); names.push(name); } let token = &native.tokens[data.tokens.start]; @@ -129,11 +139,19 @@ pub(in crate::ast) fn bind_in( owner, union: *union, soft: *soft, + tagged: *tagged, + voids: voids.clone(), signed: data.signed.unwrap_or(false), names, ranges, }); - jobs.extend(fields.iter().rev().map(|field| Job::Enter(field.data_type))); + jobs.extend(fields.iter().zip(voids).rev().map(|(field, is_void)| { + if is_void { + Job::Void + } else { + Job::Enter(field.data_type) + } + })); } DataTypeKind::TypeOf(expression) => { // The existing query kernel recognizes an explicit @@ -175,6 +193,8 @@ pub(in crate::ast) fn bind_in( owner, union, soft, + tagged, + voids, signed, names, ranges, @@ -183,10 +203,17 @@ pub(in crate::ast) fn bind_in( .len() .checked_sub(names.len()) .ok_or_else(|| unsupported("aggregate fields"))?; - let fields = names.into_iter().zip(values.split_off(start)).collect(); + let fields = names + .into_iter() + .zip(values.split_off(start)) + .zip(voids) + .map(|((name, ty), is_void)| (name, ty, is_void)) + .collect(); let Some(ty) = packed_structs::native_type( &tree.state, - if soft { + if tagged { + packed_structs::AggregateKind::TaggedUnion + } else if soft { packed_structs::AggregateKind::SoftUnion } else if union { packed_structs::AggregateKind::HardUnion diff --git a/crates/celox-sv-analyzer/src/ir.rs b/crates/celox-sv-analyzer/src/ir.rs index 3fabbdb7eb8..3d5b58428a6 100644 --- a/crates/celox-sv-analyzer/src/ir.rs +++ b/crates/celox-sv-analyzer/src/ir.rs @@ -661,6 +661,7 @@ impl From for PortDirection { #[derive(Debug, Clone, PartialEq, Eq)] pub struct Type { + tagged_identity: Option, kind: TypeKind, is_signed: bool, packed_ranges: Vec, @@ -670,6 +671,11 @@ pub struct Type { } impl Type { + /// Nominal identity of a tagged union, retained for port type checking. + pub fn tagged_identity(&self) -> Option<&str> { + self.tagged_identity.as_deref() + } + pub fn kind(&self) -> TypeKind { self.kind } @@ -749,11 +755,13 @@ impl Type { r#type: ast::Type, constants: &dyn typecheck::ConstantEnvironment, ) -> Self { + let tagged_identity = r#type.tagged_identity().map(str::to_owned); let kind = r#type.kind().into(); let is_signed = r#type.is_signed(); let class = r#type.class().map(str::to_owned); let (packed_ranges, unpacked_ranges, resolved_width) = convert_type(r#type, constants); Self { + tagged_identity, kind, is_signed, packed_ranges, diff --git a/crates/celox-sv-analyzer/src/system_functions.rs b/crates/celox-sv-analyzer/src/system_functions.rs index dfdf49d219d..b19b8529431 100644 --- a/crates/celox-sv-analyzer/src/system_functions.rs +++ b/crates/celox-sv-analyzer/src/system_functions.rs @@ -850,6 +850,12 @@ impl fmt::Display for ObjectOp { /// The subroutine a call expression calls. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Callee { + /// Check the first argument at runtime before evaluating/returning the second. + /// Used for tagged union member access (IEEE 1800-2023 11.9). + Checked { + width: usize, + signed: bool, + }, /// A user function or a DPI import, by its resolved name. Subroutine(String), System(SystemFunction), @@ -865,14 +871,14 @@ impl Callee { pub fn subroutine(&self) -> Option<&str> { match self { Self::Subroutine(name) => Some(name), - Self::System(_) | Self::String(_) | Self::Object(_) => None, + Self::System(_) | Self::String(_) | Self::Object(_) | Self::Checked { .. } => None, } } /// The system function, if this is one. pub fn system(&self) -> Option { match self { - Self::Subroutine(_) | Self::String(_) | Self::Object(_) => None, + Self::Subroutine(_) | Self::String(_) | Self::Object(_) | Self::Checked { .. } => None, Self::System(function) => Some(*function), } } @@ -881,6 +887,7 @@ impl Callee { /// lowered as an integral operation; see [`SystemFunction::result_type`]. pub fn result_type(&self) -> Option<(usize, bool)> { match self { + Self::Checked { width, signed } => Some((*width, *signed)), Self::String(op) => Some(op.result_type()), Self::Object(op) => Some(op.result_type()), _ => self.system()?.result_type(), @@ -890,6 +897,7 @@ impl Callee { /// Rename a user subroutine with `rename`. pub fn map_subroutine(self, rename: impl FnOnce(String) -> String) -> Self { match self { + Self::Checked { .. } => self, Self::Subroutine(name) => Self::Subroutine(rename(name)), Self::System(function) => Self::System(function), Self::String(op) => Self::String(op), @@ -908,6 +916,7 @@ impl Callee { impl fmt::Display for Callee { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { + Self::Checked { .. } => f.write_str("tagged union access"), Self::Subroutine(name) => f.write_str(name), Self::System(function) => f.write_str(function.name()), Self::String(op) => op.fmt(f), diff --git a/crates/celox-sv-analyzer/src/tests.rs b/crates/celox-sv-analyzer/src/tests.rs index 4314adf6bae..bc7669ccad1 100644 --- a/crates/celox-sv-analyzer/src/tests.rs +++ b/crates/celox-sv-analyzer/src/tests.rs @@ -6697,3 +6697,105 @@ fn class_randomize_rejects_unresolved_enum_domains() { ); } } + +#[test] +fn tagged_targets_reject_time_values_before_fast_paths() { + for value in [ + "$time", + "$stime", + "$realtime", + "$time()", + "$stime()", + "$realtime()", + "($time)", + "$timeunit", + "$timeprecision", + ] { + for declaration in [ + format!("item_t item; initial item = {value};"), + format!("item_t item = {value};"), + format!("task consume(input item_t item); endtask initial consume({value});"), + format!("function automatic item_t get(); return {value}; endfunction"), + format!( + "function automatic int get(input item_t item = {value}); return 0; endfunction" + ), + ] { + let source = format!( + "module Top; typedef union tagged packed {{ void Empty; logic [7:0] Full; }} item_t; {declaration} endmodule" + ); + assert!( + analyze_source(&source, Path::new("tagged_time.sv")).is_err(), + "{declaration}" + ); + } + } +} + +#[test] +fn tagged_constant_function_member_sets_packed_bound() { + let source = r#" +module Top(output logic [N-1:0] data); + typedef union tagged packed { void Empty; logic [7:0] Full; } item_t; + function automatic int size(); + item_t item; + item = tagged Full 8'd4; + return item.Full; + endfunction + localparam int N = size(); + assign data = '1; +endmodule +"#; + let ir = analyze_source(source, Path::new("tagged_constant.sv")).unwrap(); + assert_eq!(ir.modules()[0].parameters()[0].resolved_value(), Some(4)); + assert_eq!( + ir.modules()[0].ports()[0].r#type().resolved_width(), + Some(4) + ); +} + +#[test] +fn tagged_constant_checks_preserve_guard_width_and_sign() { + use ir::{Callee, ConstExpr}; + let constants = HashMap::default(); + for (guard, payload, width, signed, expected) in [ + ("1'b1", "16'h1ff", 8, false, Some(255)), + ("1'b1", "8'hfe", 8, true, Some(-2)), + ("1'b0", "8'd4", 8, false, None), + ("1'bx", "8'd4", 8, false, None), + ("1'bz", "8'd4", 8, false, None), + ] { + let expr = ConstExpr::Function { + callee: Callee::Checked { width, signed }, + args: vec![ + ConstExpr::Literal(guard.into()), + ConstExpr::Literal(payload.into()), + ], + site: None, + }; + assert_eq!( + typecheck::eval_const_expr(&expr, &constants), + expected, + "{guard}, {payload}" + ); + } +} + +#[test] +fn tagged_inactive_constant_member_cannot_supply_bound() { + let source = r#" +module Top; + typedef union tagged packed { logic [7:0] Empty; logic [7:0] Full; } item_t; + function automatic int size(); + item_t item; + item = tagged Empty 8'd4; + return item.Full; + endfunction + localparam int N = size(); + logic [N-1:0] data; +endmodule +"#; + // The analyzer may retain unresolved constants for the frontend to reject. + if let Ok(ir) = analyze_source(source, Path::new("tagged_inactive_constant.sv")) { + assert_eq!(ir.modules()[0].parameters()[0].resolved_value(), None); + } +} diff --git a/crates/celox-sv-analyzer/src/typecheck.rs b/crates/celox-sv-analyzer/src/typecheck.rs index 580948196f1..709bd4be783 100644 --- a/crates/celox-sv-analyzer/src/typecheck.rs +++ b/crates/celox-sv-analyzer/src/typecheck.rs @@ -218,6 +218,24 @@ pub(crate) fn eval_const_expr_in_env( crate::ast::const_functions::eval_call(name, args, constants) } Callee::System(function) => eval_system_function(*function, args, constants), + Callee::Checked { width, signed } => { + let [guard, payload] = args.as_slice() else { + return None; + }; + // IEEE 1800-2023 7.3.2: a member can only be read with its active tag. + // Keep the guard even when evaluating a constant function (13.4.3). + if eval_const_expr_in_env(guard, constants)? == 0 { + return None; + } + eval_const_expr_in_env( + &ConstExpr::Resize { + expr: Box::new(payload.clone()), + width: *width, + signed: *signed, + }, + constants, + ) + } Callee::String(_) | Callee::Object(_) => None, }, ConstExpr::Unary { op, expr: operand } => { diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index 97530f68a62..46fd10f8c17 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -743,3 +743,45 @@ the full-suite gate accepts only those unchanged failures, never a passing result in their place. Reproduce with `verify-sv-verilator` or `verify-sv-icarus` and `--filter unions::`. Normal reports are written under `target/sv-verilator/` and `target/sv-icarus/`. + +## SystemVerilog tagged packed unions + +The `tagged_unions` shared group covers constructors (including `void`), +nested tags, checked member reads and writes, conditional/short-circuit access, +typed casts and ports, clocked copies, signed payloads and wide four-state values. +Task/function output and inout arguments retain writable members (including +concatenations and nested members), with live tag checks before the call and +before copy-out. System-function destinations and seeds use the same checks. +Whole-union output/inout actuals require the same declared union type as the +formal; integral formals and system outputs cannot fabricate a union tag. +Function returns and argument defaults accept context-typed `tagged` constructors; +default expressions retain the enclosing declaration scope. Checked +member arguments retain their runtime checks even when expression inlining +would otherwise discard an unused formal. +Layout and access rules follow IEEE 1800-2023 7.3.2 and 11.9. Invalid active-tag +access is tested separately in Celox's runtime-event harness. + +Verilator 5.052 rejects `void` and `tagged` expressions in the seven two-state +cases; its adapter reports the two four-state cases as unsupported. Icarus 13.0 +rejects all nine cases during parsing. The cases remain executable with their +original assertions and no exclusions. Reviewed compilation diagnostics are +retained in [Verilator evidence](verification/sv/verilator/tagged_unions.json) +and [Icarus evidence](verification/sv/icarus/tagged_unions.json), with exact +failure matching in the full-suite gate. Reproduce with `verify-sv-verilator` +or `verify-sv-icarus` and `--filter tagged_unions::`. + +This implementation supports scalar packed tagged unions. Unpacked tagged +unions, `matches`/`case matches`, and continuous or concatenation drivers of +tagged members remain unsupported. Whole-union copies through ports and +continuous assignments are supported. Port connections currently require a +signal of the same declared tagged union type; constructor expressions at +instance connections require an intermediate typed signal. Use four-state simulation to preserve +undefined initial tags and unused payload bits. + + +Whole-value equality currently compares the packed representation, including +undefined payload padding. The review request for active-payload-only equality +needs a specification ruling and is tracked in +[issue #1889](https://github.com/celox-sim/celox/issues/1889); it is not yet a +confirmed conformance defect. Equality behavior is unchanged pending that +investigation. diff --git a/crates/celox-test-suite/src/sv/cases/mod.rs b/crates/celox-test-suite/src/sv/cases/mod.rs index 66a5ad1db5a..83ee776c13f 100644 --- a/crates/celox-test-suite/src/sv/cases/mod.rs +++ b/crates/celox-test-suite/src/sv/cases/mod.rs @@ -7,6 +7,10 @@ pub(super) struct Group { } pub(super) const GROUPS: &[Group] = &[ + Group { + file: "src/sv/cases/tagged_unions.vtest", + text: include_str!("tagged_unions.vtest"), + }, Group { file: "src/sv/cases/unions.vtest", text: include_str!("unions.vtest"), diff --git a/crates/celox-test-suite/src/sv/cases/tagged_unions.vtest b/crates/celox-test-suite/src/sv/cases/tagged_unions.vtest new file mode 100644 index 00000000000..42ada7a9bd9 --- /dev/null +++ b/crates/celox-test-suite/src/sv/cases/tagged_unions.vtest @@ -0,0 +1,334 @@ +(group tagged_unions (category types)) + +(case constructors_and_checked_members + (source "tagged_union.sv" #" +module Top(input bit full_value, input logic [7:0] data, + output logic [7:0] result, output logic [31:0] width, + output logic [7:0] widened, selected, selected_context, signed_sum); + typedef union tagged packed { void Empty; logic [7:0] Full; logic [3:0] Short; } item_t; + item_t item, copied; + always_comb begin + if (full_value) item = tagged Full data; + else item = tagged Empty; + copied = item; + result = full_value ? copied.Full : 8'h5a; + if (full_value) begin + copied.Full[3:0] = 4'hf; + result = copied.Full; + end + copied = tagged Full 8'h00; + copied.Full = data[0] + data[0]; + widened = copied.Full; + copied = tagged Full 8'ha0; + copied.Full[3:0] = (data[0] + data[0]) >> 1; + selected = copied.Full; + copied.Full[3:0] = (data[0] << 4) >> 4; + selected_context = copied.Full; + copied.Full = 2'sb11 + 2'sb11; + signed_sum = copied.Full; + end + assign width = $bits(item_t); +endmodule +"#) + (top Top) + (assert_eq width 10) + (assert_eq result 0x5a) + (for value (list 0 0xa5 0xff) + (modify (set full_value 1) (set data value)) + (assert_eq result (| value 15)) + (assert_eq widened (* (& value 1) 2)) + (assert_eq selected (| 0xa0 (& value 1))) + (assert_eq selected_context 0xa0) + (assert_eq signed_sum 0xfe) + (modify (set full_value 0)) + (assert_eq result 0x5a))) + +(case nested_and_void_constructors + (source "tagged_nested.sv" #" +module Top(input bit enabled, input logic [7:0] data, + output logic [7:0] result, output logic safe_and, safe_or); + typedef union tagged packed { void Empty; logic [7:0] Full; } inner_t; + typedef union tagged packed { inner_t Nested; logic [15:0] Word; } outer_t; + outer_t item; + always_comb begin + item = tagged Nested (tagged Full data); + result = item.Nested.Full; + item = tagged Word 16'hffff; + safe_and = 1'b0 && (item.Nested.Full == 8'hff); + safe_or = 1'b1 || (item.Nested.Full == 8'hff); + if (enabled) begin + item = tagged Nested (tagged Full data); + item.Nested.Full = data ^ 8'hff; + result = item.Nested.Full; + end + end +endmodule +"#) + (top Top) + (for value (list 0 0xa5 0xff) + (modify (set enabled 0) (set data value)) + (assert_eq result value) + (assert_eq safe_and 0) + (assert_eq safe_or 1) + (modify (set enabled 1)) + (assert_eq result (^ value 255)))) + +(case casts_ports_and_registers + (four_state) + (source "tagged_ports.sv" #" +package Types; + typedef union tagged packed { void Empty; logic signed [7:0] Full; } item_t; +endpackage +module Pass(input Types::item_t incoming, output Types::item_t outgoing); + assign outgoing = incoming; +endmodule +module Top(input bit clk, input bit read_saved, input logic signed [3:0] data, + output logic signed [15:0] result, output logic [7:0] saved_result); + Types::item_t current_value, copied, saved; + always_comb current_value = Types::item_t'(tagged Full data); + Pass pass_value(.incoming(current_value), .outgoing(copied)); + always_ff @(posedge clk) saved <= copied; + assign result = copied.Full; + assign saved_result = read_saved ? saved.Full : 8'h00; +endmodule +"#) + (top Top) + (assert_eq saved_result 0) + (for (d expected saved) (list (0 0 0) (7 7 7) (8 0xfff8 0xf8) (15 0xffff 0xff)) + (modify (set data d)) + (assert_eq result expected) + (tick clk) + (modify (set read_saved 1)) + (assert_eq saved_result saved))) + +(case wide_four_state_payload + (four_state) + (source "tagged_wide.sv" #" +module Top(input logic [129:0] data, output logic [129:0] result, + output logic [31:0] width); + typedef union tagged packed { void Empty; logic [129:0] Full; } item_t; + item_t item; + always_comb begin + item = tagged Full data; + result = item.Full; + end + assign width = $bits(item_t); +endmodule +"#) + (top Top) + (assert_eq width 131) + (for bit (list 0 63 64 127 128 129) + (let v (| 1 (<< 1 bit))) + (let m (<< 1 bit)) + (modify (set data (fourstate v m))) + (assert_eq result (fourstate v m)))) + +(case conditional_struct_payload + (source "tagged_struct.sv" #" +module Top(input bit enabled, input logic [7:0] data, output logic [7:0] result); + typedef union tagged packed { + void Empty; + struct packed { bit [3:0] high; logic [3:0] low; } Data; + } item_t; + item_t item; + always_comb begin + item = enabled ? tagged Data '{data[7:4], data[3:0]} : tagged Empty; + result = 8'h5a; + if (enabled) begin + item.Data.high += 1; + result = {item.Data.high, item.Data.low}; + item.Data = '{high: 0, low: 0}; + end + end +endmodule +"#) + (top Top) + (assert_eq result 0x5a) + (for value (list 0 0xa5 0xff) + (modify (set enabled 1) (set data value)) + (assert_eq result (& (+ value 16) 255)) + (modify (set enabled 0)) + (assert_eq result 0x5a))) + +(case writable_task_arguments + (source "tagged_arguments.sv" #" +module Top(input logic [7:0] data, output logic [7:0] result, nested_result, function_result); + typedef union tagged packed { void Empty; logic [7:0] Full; } item_t; + union tagged packed { void Empty; item_t Some; } nested; + item_t item; + logic [7:0] unused_result; + task automatic set_value(output logic [7:0] value, input logic [7:0] d); + value = d; + endtask + task automatic increment(inout logic [7:0] value); + value += 1; + endtask + function automatic logic [7:0] complement(output logic [7:0] value, input logic [7:0] d); + value = ~d; + return d; + endfunction + always_comb begin + item = tagged Full 0; + set_value({item.Full[7:4], item.Full[3:0]}, data); + increment(item.Full); + result = item.Full; + nested = tagged Some (tagged Full 0); + set_value(nested.Some.Full, data); + nested_result = nested.Some.Full; + unused_result = complement(item.Full, data); + function_result = item.Full; + end +endmodule +"#) + (top Top) + (for value (list 0 1 0xa5 0xff) + (modify (set data value)) + (assert_eq result (& (+ value 1) 255)) + (assert_eq nested_result value) + (assert_eq function_result (^ value 255)))) + +(case writable_system_arguments + (source "tagged_system_arguments.sv" #" +module Top(output logic ok); + union tagged packed { void Empty; logic [31:0] Full; } item; + int count, seed, a, b; + initial begin + item = tagged Full 0; + count = $sscanf("42", "%d", item.Full); + ok = count == 1 && item.Full == 42; + count = $sscanf("165", "%d", item.Full[7:0]); + ok &= count == 1 && item.Full == 165; + count = $sscanf("bad", "%d", item.Full); + ok &= count == 0 && item.Full == 165; + item = tagged Full 123; + seed = 123; + a = $random(item.Full); + b = $random(seed); + ok &= a == b && item.Full == seed; + a = $dist_uniform(item.Full, 1, 10); + b = $dist_uniform(seed, 1, 10); + ok &= a == b && item.Full == seed; + end +endmodule +"#) + (top Top) + (run_until 0) + (assert_eq ok 1)) + +(case factory_and_union_arguments + (source "tagged_factory.sv" #" +module Top(input bit enabled, input logic [7:0] data, + output logic [7:0] result, copied, output logic selected, + output logic [31:0] constant_width, constant_signed, constant_nested, constant_lazy); + typedef union tagged packed { void Empty; logic [7:0] Full; } item_t; + typedef item_t alias_t; + typedef union tagged packed { void Empty; logic signed [7:0] Full; } signed_t; + typedef union tagged packed { void Empty; item_t Some; } outer_t; + function automatic int size(); + item_t value; + value = tagged Full 8'd4; + return value.Full; + endfunction + function automatic int negative(); + signed_t value; + value = tagged Full (-8'sd2); + return value.Full; + endfunction + function automatic int nested(); + outer_t value; + value = tagged Some (tagged Full 8'd7); + return value.Some.Full; + endfunction + function automatic int lazy(); + union tagged packed { logic [7:0] Empty; logic [7:0] Full; } value; + value = tagged Empty 8'd4; + return 1'b1 ? 3 : value.Full; + endfunction + localparam int N = size(); + localparam int S = negative(); + localparam int T = nested(); + localparam int L = lazy(); + logic [N-1:0] sized; + assign constant_width = $bits(sized); + assign constant_signed = S; + assign constant_nested = T; + assign constant_lazy = L; + item_t item; + logic [1:0] bits; + function automatic item_t make(input logic [7:0] value); + return tagged Full value; + endfunction + function automatic item_t optional(input bit valid, input logic [7:0] value); + return valid ? tagged Full value : tagged Empty; + endfunction + function automatic int zero(input logic [7:0] unused_value); return 0; endfunction + task automatic fill(output alias_t value, input logic [7:0] d); + value = tagged Full d; + endtask + task automatic invert(inout item_t value); + value = tagged Full (~value.Full); + endtask + always_comb begin + item = make(data); + result = item.Full; + fill(.d(data), .value(item)); + invert(item); + copied = item.Full; + item = optional(enabled, data); + bits = 2'b01; + selected = bits[enabled ? zero(item.Full) : 1]; + end +endmodule +"#) + (top Top) + (assert_eq constant_width 4) + (assert_eq constant_signed 0xfffffffe) + (assert_eq constant_nested 7) + (assert_eq constant_lazy 3) + (for value (list 0 1 0xa5 0xff) + (modify (set enabled 0) (set data value)) + (assert_eq result value) + (assert_eq copied (^ value 255)) + (assert_eq selected 0) + (modify (set enabled 1)) + (assert_eq selected 1))) + +(case default_arguments + (source "tagged_defaults.sv" #" +module Top(input logic [7:0] data, + output logic [7:0] scoped, omitted, explicit_value, task_value, nested_value, void_value); + typedef union tagged packed { void Empty; logic [7:0] Full; } item_t; + typedef union tagged packed { void Empty; item_t Some; } outer_t; + function automatic logic [7:0] get(input item_t value = tagged Full data, + input logic [7:0] data = 8'hee); + return value.Full; + endfunction + function automatic logic [7:0] get_nested(input outer_t value = tagged Some (tagged Full 8'h35)); + return value.Some.Full; + endfunction + function automatic logic [7:0] get_void(input item_t value = tagged Empty); + value = tagged Full 8'h19; + return value.Full; + endfunction + task automatic read_value(output logic [7:0] result, input item_t value = tagged Full 8'h2a); + result = value.Full; + endtask + always_comb begin + scoped = get(); + omitted = get(, 8'h00); + explicit_value = get(tagged Full 8'h55); + read_value(task_value); + nested_value = get_nested(); + void_value = get_void(); + end +endmodule +"#) + (top Top) + (for value (list 0 1 0xa5 0xff) + (modify (set data value)) + (assert_eq scoped value) + (assert_eq omitted value) + (assert_eq explicit_value 0x55) + (assert_eq task_value 0x2a) + (assert_eq nested_value 0x35) + (assert_eq void_value 0x19))) diff --git a/crates/celox-test-suite/tests/retained_reports.rs b/crates/celox-test-suite/tests/retained_reports.rs index a071551e694..15323592238 100644 --- a/crates/celox-test-suite/tests/retained_reports.rs +++ b/crates/celox-test-suite/tests/retained_reports.rs @@ -187,18 +187,40 @@ fn systemverilog_retained_reports_explain_exclusions_and_executed_failures() { } } "compile_error" | "mismatch" => { - assert_eq!(tool, "icarus", "{name}"); - let (expected_status, phase, diagnostic) = match name { - "unions::packed_mixed_state" => ( + let (expected_status, phase, diagnostic) = match (tool, name) { + ( + "verilator", + "tagged_unions::conditional_struct_payload" + | "tagged_unions::constructors_and_checked_members" + | "tagged_unions::writable_system_arguments" + | "tagged_unions::writable_task_arguments" + | "tagged_unions::default_arguments" + | "tagged_unions::factory_and_union_arguments" + | "tagged_unions::nested_and_void_constructors", + ) => ("compile_error", "compile", "Unsupported: tagged union"), + ( + "icarus", + "tagged_unions::casts_ports_and_registers" + | "tagged_unions::conditional_struct_payload" + | "tagged_unions::constructors_and_checked_members" + | "tagged_unions::writable_system_arguments" + | "tagged_unions::writable_task_arguments" + | "tagged_unions::default_arguments" + | "tagged_unions::factory_and_union_arguments" + | "tagged_unions::nested_and_void_constructors" + | "tagged_unions::wide_four_state_payload", + ) => ("compile_error", "compile", "syntax error"), + ("icarus", "unions::packed_mixed_state") => ( "mismatch", "execute", "assert_eq two: expected 0xa0, got 0xaX", ), - "unions::soft_overlay" - | "unions::soft_signed_ports" - | "unions::soft_wide_four_state" => { - ("compile_error", "compile", "syntax error") - } + ( + "icarus", + "unions::soft_overlay" + | "unions::soft_signed_ports" + | "unions::soft_wide_four_state", + ) => ("compile_error", "compile", "syntax error"), _ => panic!("unreviewed failure: {tool} {name}: {status}"), }; assert_eq!(status, expected_status, "{name}"); diff --git a/crates/celox-test-suite/verification/sv/icarus.json b/crates/celox-test-suite/verification/sv/icarus.json index cca4d440665..3e26155c6cf 100644 --- a/crates/celox-test-suite/verification/sv/icarus.json +++ b/crates/celox-test-suite/verification/sv/icarus.json @@ -16,6 +16,7 @@ "icarus/string.json", "icarus/synthesizable.json", "icarus/system_functions.json", + "icarus/tagged_unions.json", "icarus/timing.json", "icarus/types.json", "icarus/unions.json" diff --git a/crates/celox-test-suite/verification/sv/icarus/tagged_unions.json b/crates/celox-test-suite/verification/sv/icarus/tagged_unions.json new file mode 100644 index 00000000000..7791025b65c --- /dev/null +++ b/crates/celox-test-suite/verification/sv/icarus/tagged_unions.json @@ -0,0 +1,103 @@ +{ + "cases": [ + { + "category": "Types", + "detail": "Icarus build exit status: 4; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Syntax error in typedef clause.\n/source_0.sv:3: syntax error\nI give up.\n", + "expectation": "Simulation", + "name": "tagged_unions::casts_ports_and_registers", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus build exit status: 10; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Syntax error in typedef clause.\n/source_0.sv:6: syntax error\n/source_0.sv:6: error: Invalid module item.\n/source_0.sv:7: syntax error\n/source_0.sv:7: error: Invalid module instantiation\n/source_0.sv:9: syntax error\n/source_0.sv:9: error: Malformed statement\n/source_0.sv:14: syntax error\n/source_0.sv:14: error: Malformed statement\n", + "expectation": "Simulation", + "name": "tagged_unions::conditional_struct_payload", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus build exit status: 14; see /build.log\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Syntax error in typedef clause.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Invalid module item.\n/source_0.sv:6: syntax error\n/source_0.sv:6: error: Invalid module instantiation\n/source_0.sv:8: syntax error\n/source_0.sv:8: error: Malformed statement\n/source_0.sv:9: syntax error\n/source_0.sv:9: error: Malformed statement\n/source_0.sv:16: syntax error\n/source_0.sv:16: error: Malformed statement\n/source_0.sv:19: syntax error\n/source_0.sv:19: error: Malformed statement\n", + "expectation": "Simulation", + "name": "tagged_unions::constructors_and_checked_members", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus build exit status: 26; see /build.log\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Syntax error in typedef clause.\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Invalid module item.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Syntax error in typedef clause.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Invalid module instantiation\n/source_0.sv:5: error: Invalid module item.\n/source_0.sv:6: syntax error\n/source_0.sv:1: error: Error in task/function port item after port name item_t.\n/source_0.sv:6: syntax error\n/source_0.sv:6: error: Syntax error defining function.\n/source_0.sv:10: syntax error\n/source_0.sv:1: error: Error in task/function port item after port name outer_t.\n/source_0.sv:10: syntax error\n/source_0.sv:10: error: Syntax error defining function.\n/source_0.sv:13: syntax error\n/source_0.sv:1: error: Error in task/function port item after port name item_t.\n/source_0.sv:13: syntax error\n/source_0.sv:13: error: Syntax error defining function.\n/source_0.sv:17: syntax error\n/source_0.sv:1: error: Error in task/function port item after port name item_t.\n/source_0.sv:17: syntax error\n/source_0.sv:23: syntax error\n/source_0.sv:23: error: Malformed statement\n", + "expectation": "Simulation", + "name": "tagged_unions::default_arguments", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus build exit status: 42; see /build.log\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Syntax error in typedef clause.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Invalid module item.\n/source_0.sv:6: syntax error\n/source_0.sv:6: error: Syntax error in typedef clause.\n/source_0.sv:7: syntax error\n/source_0.sv:7: error: Syntax error in typedef clause.\n/source_0.sv:7: error: 'Full' has already been declared in this scope.\n/source_0.sv:5: : It was declared here as a variable.\n/source_0.sv:7: syntax error\n/source_0.sv:7: error: Invalid module item.\n/source_0.sv:8: syntax error\n/source_0.sv:8: error: Syntax error in typedef clause.\n/source_0.sv:8: syntax error\n/source_0.sv:8: error: Invalid module instantiation\n/source_0.sv:8: error: Invalid module item.\n/source_0.sv:10: syntax error\n/source_0.sv:10: error: Malformed statement\n/source_0.sv:11: syntax error\n/source_0.sv:11: error: Malformed statement\n/source_0.sv:15: syntax error\n/source_0.sv:15: error: Malformed statement\n/source_0.sv:16: syntax error\n/source_0.sv:16: error: Malformed statement\n/source_0.sv:20: syntax error\n/source_0.sv:20: error: Malformed statement\n/source_0.sv:21: syntax error\n/source_0.sv:21: error: Malformed statement\n/source_0.sv:25: syntax error\n/source_0.sv:24: error: Syntax error defining function.\n/source_0.sv:38: syntax error\n/source_0.sv:38: error: Invalid module instantiation\n/source_0.sv:40: syntax error\n/source_0.sv:40: error: Syntax error defining function.\n/source_0.sv:43: syntax error\n/source_0.sv:43: error: Syntax error defining function.\n/source_0.sv:47: syntax error\n/source_0.sv:1: error: Error in task/function port item after port name alias_t.\n/source_0.sv:47: syntax error\n/source_0.sv:50: syntax error\n/source_0.sv:1: error: Error in task/function port item after port name item_t.\n/source_0.sv:50: syntax error\n", + "expectation": "Simulation", + "name": "tagged_unions::factory_and_union_arguments", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus build exit status: 16; see /build.log\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Syntax error in typedef clause.\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Invalid module item.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Syntax error in typedef clause.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Invalid module item.\n/source_0.sv:6: syntax error\n/source_0.sv:6: error: Invalid module instantiation\n/source_0.sv:8: syntax error\n/source_0.sv:8: error: Malformed statement\n/source_0.sv:10: syntax error\n/source_0.sv:10: error: Malformed statement\n/source_0.sv:14: syntax error\n/source_0.sv:14: error: Malformed statement\n", + "expectation": "Simulation", + "name": "tagged_unions::nested_and_void_constructors", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus build exit status: 8; see /build.log\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Syntax error in typedef clause.\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Invalid module item.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Invalid module instantiation\n/source_0.sv:7: syntax error\n/source_0.sv:7: error: Malformed statement\n", + "expectation": "Simulation", + "name": "tagged_unions::wide_four_state_payload", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus build exit status: 8; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:6: syntax error\n/source_0.sv:6: error: Malformed statement\n/source_0.sv:13: syntax error\n/source_0.sv:13: error: Malformed statement\n", + "expectation": "Simulation", + "name": "tagged_unions::writable_system_arguments", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus build exit status: 15; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Syntax error in typedef clause.\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Invalid module item.\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Invalid module instantiation\n/source_0.sv:4: error: Invalid module item.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Invalid module instantiation\n/source_0.sv:18: syntax error\n/source_0.sv:18: error: Malformed statement\n/source_0.sv:22: syntax error\n/source_0.sv:22: error: Malformed statement\n", + "expectation": "Simulation", + "name": "tagged_unions::writable_task_arguments", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ] +} diff --git a/crates/celox-test-suite/verification/sv/verilator.json b/crates/celox-test-suite/verification/sv/verilator.json index 5f3051a715c..e99caed8950 100644 --- a/crates/celox-test-suite/verification/sv/verilator.json +++ b/crates/celox-test-suite/verification/sv/verilator.json @@ -16,6 +16,7 @@ "verilator/string.json", "verilator/synthesizable.json", "verilator/system_functions.json", + "verilator/tagged_unions.json", "verilator/timing.json", "verilator/types.json" ], diff --git a/crates/celox-test-suite/verification/sv/verilator/tagged_unions.json b/crates/celox-test-suite/verification/sv/verilator/tagged_unions.json new file mode 100644 index 00000000000..2ac715e4997 --- /dev/null +++ b/crates/celox-test-suite/verification/sv/verilator/tagged_unions.json @@ -0,0 +1,103 @@ +{ + "cases": [ + { + "category": "Types", + "detail": "four-state expectations", + "expectation": "Simulation", + "name": "tagged_unions::casts_ports_and_registers", + "phase": "compile", + "status": "unsupported", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator build exit status: 1; see /build.log\n%Error-UNSUPPORTED: /source_0.sv:4:9: Unsupported: void (for tagged unions)\n 4 | void Empty;\n | ^~~~\n ... For error description see https://verilator.org/warn/UNSUPPORTED?v=5.052\n%Error-UNSUPPORTED: /source_0.sv:9:26: Unsupported: tagged union\n 9 | item = enabled ? tagged Data '{data[7:4], data[3:0]} : tagged Empty;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:9:64: Unsupported: tagged union\n 9 | item = enabled ? tagged Data '{data[7:4], data[3:0]} : tagged Empty;\n | ^~~~~~\n%Error: Exiting due to 3 error(s)\n", + "expectation": "Simulation", + "name": "tagged_unions::conditional_struct_payload", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator build exit status: 1; see /build.log\n%Error-UNSUPPORTED: /source_0.sv:5:35: Unsupported: void (for tagged unions)\n 5 | typedef union tagged packed { void Empty; logic [7:0] Full; logic [3:0] Short; } item_t;\n | ^~~~\n ... For error description see https://verilator.org/warn/UNSUPPORTED?v=5.052\n%Error-UNSUPPORTED: /source_0.sv:8:32: Unsupported: tagged union\n 8 | if (full_value) item = tagged Full data;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:9:21: Unsupported: tagged union\n 9 | else item = tagged Empty;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:16:18: Unsupported: tagged union\n 16 | copied = tagged Full 8'h00;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:19:18: Unsupported: tagged union\n 19 | copied = tagged Full 8'ha0;\n | ^~~~~~\n%Error: Exiting due to 5 error(s)\n", + "expectation": "Simulation", + "name": "tagged_unions::constructors_and_checked_members", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator build exit status: 1; see /build.log\n%Error-UNSUPPORTED: /source_0.sv:4:35: Unsupported: void (for tagged unions)\n 4 | typedef union tagged packed { void Empty; logic [7:0] Full; } item_t;\n | ^~~~\n ... For error description see https://verilator.org/warn/UNSUPPORTED?v=5.052\n%Error-UNSUPPORTED: /source_0.sv:5:35: Unsupported: void (for tagged unions)\n 5 | typedef union tagged packed { void Empty; item_t Some; } outer_t;\n | ^~~~\n%Error-UNSUPPORTED: /source_0.sv:6:61: Unsupported: tagged union\n 6 | function automatic logic [7:0] get(input item_t value = tagged Full data,\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:10:69: Unsupported: tagged union\n 10 | function automatic logic [7:0] get_nested(input outer_t value = tagged Some (tagged Full 8'h35));\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:10:82: Unsupported: tagged union\n 10 | function automatic logic [7:0] get_nested(input outer_t value = tagged Some (tagged Full 8'h35));\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:13:66: Unsupported: tagged union\n 13 | function automatic logic [7:0] get_void(input item_t value = tagged Empty);\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:14:17: Unsupported: tagged union\n 14 | value = tagged Full 8'h19;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:17:79: Unsupported: tagged union\n 17 | task automatic read_value(output logic [7:0] result, input item_t value = tagged Full 8'h2a);\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:23:30: Unsupported: tagged union\n 23 | explicit_value = get(tagged Full 8'h55);\n | ^~~~~~\n%Error: Exiting due to 9 error(s)\n", + "expectation": "Simulation", + "name": "tagged_unions::default_arguments", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator build exit status: 1; see /build.log\n%Error-UNSUPPORTED: /source_0.sv:5:35: Unsupported: void (for tagged unions)\n 5 | typedef union tagged packed { void Empty; logic [7:0] Full; } item_t;\n | ^~~~\n ... For error description see https://verilator.org/warn/UNSUPPORTED?v=5.052\n%Error-UNSUPPORTED: /source_0.sv:7:35: Unsupported: void (for tagged unions)\n 7 | typedef union tagged packed { void Empty; logic signed [7:0] Full; } signed_t;\n | ^~~~\n%Error-UNSUPPORTED: /source_0.sv:8:35: Unsupported: void (for tagged unions)\n 8 | typedef union tagged packed { void Empty; item_t Some; } outer_t;\n | ^~~~\n%Error-UNSUPPORTED: /source_0.sv:11:17: Unsupported: tagged union\n 11 | value = tagged Full 8'd4;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:16:17: Unsupported: tagged union\n 16 | value = tagged Full (-8'sd2);\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:21:17: Unsupported: tagged union\n 21 | value = tagged Some (tagged Full 8'd7);\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:21:30: Unsupported: tagged union\n 21 | value = tagged Some (tagged Full 8'd7);\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:26:17: Unsupported: tagged union\n 26 | value = tagged Empty 8'd4;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:41:16: Unsupported: tagged union\n 41 | return tagged Full value;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:44:24: Unsupported: tagged union\n 44 | return valid ? tagged Full value : tagged Empty;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:44:44: Unsupported: tagged union\n 44 | return valid ? tagged Full value : tagged Empty;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:48:17: Unsupported: tagged union\n 48 | value = tagged Full d;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:51:17: Unsupported: tagged union\n 51 | value = tagged Full (~value.Full);\n | ^~~~~~\n%Error: Exiting due to 13 error(s)\n", + "expectation": "Simulation", + "name": "tagged_unions::factory_and_union_arguments", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator build exit status: 1; see /build.log\n%Error-UNSUPPORTED: /source_0.sv:4:35: Unsupported: void (for tagged unions)\n 4 | typedef union tagged packed { void Empty; logic [7:0] Full; } inner_t;\n | ^~~~\n ... For error description see https://verilator.org/warn/UNSUPPORTED?v=5.052\n%Error-UNSUPPORTED: /source_0.sv:8:16: Unsupported: tagged union\n 8 | item = tagged Nested (tagged Full data);\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:8:31: Unsupported: tagged union\n 8 | item = tagged Nested (tagged Full data);\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:10:16: Unsupported: tagged union\n 10 | item = tagged Word 16'hffff;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:14:20: Unsupported: tagged union\n 14 | item = tagged Nested (tagged Full data);\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:14:35: Unsupported: tagged union\n 14 | item = tagged Nested (tagged Full data);\n | ^~~~~~\n%Error: Exiting due to 6 error(s)\n", + "expectation": "Simulation", + "name": "tagged_unions::nested_and_void_constructors", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "four-state expectations", + "expectation": "Simulation", + "name": "tagged_unions::wide_four_state_payload", + "phase": "compile", + "status": "unsupported", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator build exit status: 1; see /build.log\n%Error-UNSUPPORTED: /source_0.sv:3:27: Unsupported: void (for tagged unions)\n 3 | union tagged packed { void Empty; logic [31:0] Full; } item;\n | ^~~~\n ... For error description see https://verilator.org/warn/UNSUPPORTED?v=5.052\n%Error-UNSUPPORTED: /source_0.sv:6:16: Unsupported: tagged union\n 6 | item = tagged Full 0;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:13:16: Unsupported: tagged union\n 13 | item = tagged Full 123;\n | ^~~~~~\n%Error: Exiting due to 3 error(s)\n", + "expectation": "Simulation", + "name": "tagged_unions::writable_system_arguments", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator build exit status: 1; see /build.log\n%Error-UNSUPPORTED: /source_0.sv:3:35: Unsupported: void (for tagged unions)\n 3 | typedef union tagged packed { void Empty; logic [7:0] Full; } item_t;\n | ^~~~\n ... For error description see https://verilator.org/warn/UNSUPPORTED?v=5.052\n%Error-UNSUPPORTED: /source_0.sv:4:27: Unsupported: void (for tagged unions)\n 4 | union tagged packed { void Empty; item_t Some; } nested;\n | ^~~~\n%Error-UNSUPPORTED: /source_0.sv:18:16: Unsupported: tagged union\n 18 | item = tagged Full 0;\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:22:18: Unsupported: tagged union\n 22 | nested = tagged Some (tagged Full 0);\n | ^~~~~~\n%Error-UNSUPPORTED: /source_0.sv:22:31: Unsupported: tagged union\n 22 | nested = tagged Some (tagged Full 0);\n | ^~~~~~\n%Error: Exiting due to 5 error(s)\n", + "expectation": "Simulation", + "name": "tagged_unions::writable_task_arguments", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ] +} diff --git a/crates/celox/tests/frontends/systemverilog/tagged_unions.rs b/crates/celox/tests/frontends/systemverilog/tagged_unions.rs new file mode 100644 index 00000000000..6092a2c1b48 --- /dev/null +++ b/crates/celox/tests/frontends/systemverilog/tagged_unions.rs @@ -0,0 +1,404 @@ +use super::*; + +sv_backends! { + fn default_arguments(sim) { + @case "tagged_unions::default_arguments"; + } + fn factory_and_union_arguments(sim) { + @case "tagged_unions::factory_and_union_arguments"; + } + fn writable_task_arguments(sim) { + @case "tagged_unions::writable_task_arguments"; + } + fn writable_system_arguments(sim) { + @case "tagged_unions::writable_system_arguments"; + } + fn conditional_struct_payload(sim) { + @case "tagged_unions::conditional_struct_payload"; + } + fn constructors_and_checked_members(sim) { + @case "tagged_unions::constructors_and_checked_members"; + } + fn nested_and_void_constructors(sim) { + @case "tagged_unions::nested_and_void_constructors"; + } +} + +#[test] +fn inactive_member_read_and_write_report_runtime_errors() { + for statement in ["y = item.Full;", "item.Full = 8'hff;"] { + let source = format!( + r#" + module Top(output logic [7:0] y); + union tagged packed {{ void Empty; logic [7:0] Full; }} item; + initial begin + item = tagged Empty; + {statement} + end + endmodule + "# + ); + let mut sim = celox::Simulation::from_sv_sources( + vec![(&source, std::path::Path::new("tagged_error.sv"))], + "Top", + ) + .build() + .unwrap(); + let error = sim.step().unwrap_err(); + assert!(error.to_string().contains("tagged union member"), "{error}"); + } +} + +#[test] +fn rejects_invalid_tagged_constructors() { + for rhs in [ + "tagged Missing 1", + "tagged Empty 1", + "tagged Full", + "8'hff", + "other", + ] { + let source = format!( + r#" + module Top; + typedef union tagged packed {{ void Empty; logic [7:0] Full; }} first_t; + typedef union tagged packed {{ void Empty; logic [7:0] Full; }} second_t; + first_t item; + second_t other; + initial item = {rhs}; + endmodule + "# + ); + assert!( + celox_sv_analyzer::analyze_source(&source, std::path::Path::new("tagged_invalid.sv")) + .is_err(), + "{rhs}" + ); + } +} + +sv_backends! { + fn casts_ports_and_registers(sim) { + @case "tagged_unions::casts_ports_and_registers"; + } + fn wide_four_state_payload(sim) { + @case "tagged_unions::wide_four_state_payload"; + } + fn inactive_read_fails_on_clock(sim) { + @setup { + let source = r#" + module Top(input bit clk, output logic [7:0] y); + union tagged packed { void Empty; logic [7:0] Full; } item; + always_ff @(posedge clk) begin + item = tagged Empty; + y <= item.Full; + end + endmodule + "#; + } + @build Simulator::from_sv_sources(vec![(source, Path::new("tagged_read.sv"))], "Top").four_state(true); + let clk = sim.event("clk"); + assert!(sim.tick(clk).is_err()); + assert_eq!(sim.drain_runtime_events(), vec![celox::RuntimeEvent::AssertFatal { + message: b"tagged union member does not match the active tag".to_vec(), + }]); + } + fn inactive_write_fails_on_clock(sim) { + @setup { + let source = r#" + module Top(input bit clk, output logic [7:0] y); + union tagged packed { void Empty; logic [7:0] Full; } item; + always_ff @(posedge clk) begin + item = tagged Empty; + item.Full = 8'hff; + y <= 0; + end + endmodule + "#; + } + @build Simulator::from_sv_sources(vec![(source, Path::new("tagged_write.sv"))], "Top").four_state(true); + let clk = sim.event("clk"); + assert!(sim.tick(clk).is_err()); + assert_eq!(sim.drain_runtime_events(), vec![celox::RuntimeEvent::AssertFatal { + message: b"tagged union member does not match the active tag".to_vec(), + }]); + } + fn uninitialized_tag_fails_on_clock(sim) { + @setup { + let source = r#" + module Top(input bit clk, output logic [7:0] y); + union tagged packed { void Empty; logic [7:0] Full; } item; + always_ff @(posedge clk) y <= item.Full; + endmodule + "#; + } + @build Simulator::from_sv_sources(vec![(source, Path::new("tagged_unknown.sv"))], "Top").four_state(true); + let clk = sim.event("clk"); + assert!(sim.tick(clk).is_err()); + assert_eq!(sim.drain_runtime_events(), vec![celox::RuntimeEvent::AssertFatal { + message: b"tagged union member does not match the active tag".to_vec(), + }]); + } +} + +#[test] +fn rejects_writes_that_bypass_the_tag() { + for statement in [ + "item[8] = 1;", + "item += 1;", + "item++;", + "{item} = 9'h100;", + "{item.Full} = 8'hff;", + "assign item.Full = 8'hff;", + ] { + let source = format!( + "module Top; union tagged packed {{ void Empty; logic [7:0] Full; }} item; {} endmodule", + if statement.starts_with("assign") { + statement.to_owned() + } else { + format!("initial begin {statement} end") + } + ); + assert!( + celox_sv_analyzer::analyze_source(&source, Path::new("tagged_write.sv")).is_err(), + "{statement}" + ); + } +} + +#[test] +fn ports_reject_fabricated_tags_and_different_union_types() { + for (direction, actual_type, expr) in [ + ("input", "logic [8:0]", "value"), + ("output", "logic [8:0]", "value"), + ("input", "Types::second_t", "value"), + ("input", "Types::first_t", "9'h100"), + ] { + let source = format!( + r#" + package Types; + typedef union tagged packed {{ void Empty; logic [7:0] Full; }} first_t; + typedef union tagged packed {{ void Empty; logic [7:0] Full; }} second_t; + endpackage + module Child({direction} Types::first_t item); endmodule + module Top; + {actual_type} value; + Child child(.item({expr})); + endmodule + "# + ); + let result = celox::Simulation::from_sv_sources( + vec![(&source, Path::new("tagged_ports_invalid.sv"))], + "Top", + ) + .build(); + let error = match result { + Ok(_) => panic!("incompatible tagged union port must fail"), + Err(error) => error, + }; + assert!(error.to_string().contains("requires a signal"), "{error}"); + } +} + +#[test] +fn writable_arguments_check_active_tags_and_recheck_copyout() { + for (setup, body, call) in [ + ( + "item = tagged Empty;", + "value = 42;", + "set_value(item.Full);", + ), + ( + "item = tagged Empty;", + "value += 1;", + "increment(item.Full);", + ), + ( + "item = tagged Full 0;", + "item = tagged Empty; value = 42;", + "set_value(item.Full);", + ), + ( + "item = tagged Empty;", + "value = 42;", + "count = $sscanf(\"42\", \"%d\", item.Full);", + ), + ( + "item = tagged Full 123;", + "value = 42;", + "count = $dist_uniform(item.Full, change_tag(), 10);", + ), + ( + "item = tagged Full 0; other = tagged Empty;", + "value = 42;", + "set_value({item.Full[3:0], other.Full[3:0]});", + ), + ] { + let source = format!( + r#" + module Top(output logic [7:0] y); + union tagged packed {{ void Empty; logic [7:0] Full; }} item, other; + int count; + function automatic int change_tag(); item = tagged Empty; return 1; endfunction + task automatic set_value(output logic [7:0] value); {body} endtask + task automatic increment(inout logic [7:0] value); {body} endtask + initial begin {setup} {call} y = 0; end + endmodule + "# + ); + let mut sim = celox::Simulation::from_sv_sources( + vec![(&source, Path::new("tagged_argument_error.sv"))], + "Top", + ) + .build() + .unwrap(); + let error = sim.step().unwrap_err(); + assert!(error.to_string().contains("tagged union member"), "{error}"); + } +} + +#[test] +fn copyout_rejects_fabricated_union_tags() { + for direction in ["output", "inout"] { + for actual in ["item", "{item}"] { + let source = format!( + r#" + module Top; + union tagged packed {{ void Empty; logic [7:0] Full; }} item; + task automatic fill({direction} logic [8:0] value); value = 9'h100; endtask + initial begin item = tagged Empty; fill({actual}); end + endmodule + "# + ); + assert!( + celox_sv_analyzer::analyze_source(&source, Path::new("tagged_copyout.sv")).is_err(), + "{direction} {actual}" + ); + } + } +} + +#[test] +fn unused_index_argument_preserves_tag_check() { + let source = r#" + module Top(output logic y); + union tagged packed { void Empty; logic [7:0] Full; } item; + logic [7:0] data; + function automatic int zero(input logic [7:0] value); return 0; endfunction + initial begin + item = tagged Empty; + data = 8'hff; + y = data[zero(item.Full)]; + end + endmodule + "#; + let mut sim = + celox::Simulation::from_sv_sources(vec![(source, Path::new("tagged_index.sv"))], "Top") + .build() + .unwrap(); + let error = sim.step().unwrap_err(); + assert!(error.to_string().contains("tagged union member"), "{error}"); +} + +#[test] +fn rejects_integral_system_copyout_and_invalid_factory_returns() { + for statement in [ + "count = $sscanf(\"256\", \"%d\", item);", + "count = $random(item);", + "count = $fread(item, 0);", + ] { + let source = format!( + "module Top; union tagged packed {{ void Empty; logic [7:0] Full; }} item; int count; initial begin {statement} end endmodule" + ); + assert!( + celox_sv_analyzer::analyze_source(&source, Path::new("tagged_system_copyout.sv")) + .is_err(), + "{statement}" + ); + } + for value in ["9'h100", "other"] { + let source = format!( + r#" + module Top; + typedef union tagged packed {{ void Empty; logic [7:0] Full; }} item_t; + union tagged packed {{ void Empty; logic [7:0] Full; }} other; + item_t item; + function automatic item_t make(); return {value}; endfunction + initial item = make(); + endmodule + "# + ); + assert!( + celox_sv_analyzer::analyze_source(&source, Path::new("tagged_invalid_return.sv")) + .is_err(), + "{value}" + ); + } +} + +#[test] +fn output_port_concatenations_cannot_fabricate_tags() { + for actual in ["{item}", "{{item}}", "{pad, item}"] { + let source = format!( + r#" + module Child(output logic [9:0] value); assign value = 10'h100; endmodule + module Top; + union tagged packed {{ void Empty; logic [7:0] Full; }} item; + logic pad; + Child child(.value({actual})); + endmodule + "# + ); + let result = celox::Simulation::from_sv_sources( + vec![(&source, Path::new("tagged_concat_port.sv"))], + "Top", + ) + .build(); + assert!(result.is_err(), "{actual}"); + } +} + +#[test] +fn rejects_invalid_tagged_argument_defaults() { + for default in ["9'h100", "tagged Missing 1", "tagged Full"] { + let source = format!( + r#" + module Top; + typedef union tagged packed {{ void Empty; logic [7:0] Full; }} item_t; + function automatic logic [7:0] get(input item_t value = {default}); return value.Full; endfunction + logic [7:0] result; + initial result = get(); + endmodule + "# + ); + assert!( + celox_sv_analyzer::analyze_source(&source, Path::new("tagged_invalid_default.sv")) + .is_err(), + "{default}" + ); + } +} + +#[test] +fn inactive_constant_member_cannot_supply_packed_bound() { + let source = r#" +module Top(output logic [N-1:0] data); + typedef union tagged packed { logic [7:0] Empty; logic [7:0] Full; } item_t; + function automatic int size(); + item_t item; + item = tagged Empty 8'd4; + return item.Full; + endfunction + localparam int N = size(); + assign data = '1; +endmodule +"#; + assert!( + celox::Simulation::from_sv_sources( + vec![(source, Path::new("tagged_inactive_constant.sv"))], + "Top", + ) + .build() + .is_err() + ); +} diff --git a/crates/celox/tests/systemverilog.rs b/crates/celox/tests/systemverilog.rs index de1a3301960..979045aa957 100644 --- a/crates/celox/tests/systemverilog.rs +++ b/crates/celox/tests/systemverilog.rs @@ -243,3 +243,6 @@ mod real_extensions; #[path = "frontends/systemverilog/unions.rs"] mod unions; + +#[path = "frontends/systemverilog/tagged_unions.rs"] +mod tagged_unions; diff --git a/scripts/check-external-suite-report.test.mjs b/scripts/check-external-suite-report.test.mjs index 4013d41a552..036b9780064 100644 --- a/scripts/check-external-suite-report.test.mjs +++ b/scripts/check-external-suite-report.test.mjs @@ -276,12 +276,29 @@ test("all four retained baselines accept only their existing failures", () => { result.accepted_failures, tool === "icarus" ? [ + "tagged_unions::casts_ports_and_registers", + "tagged_unions::conditional_struct_payload", + "tagged_unions::constructors_and_checked_members", + "tagged_unions::default_arguments", + "tagged_unions::factory_and_union_arguments", + "tagged_unions::nested_and_void_constructors", + "tagged_unions::wide_four_state_payload", + "tagged_unions::writable_system_arguments", + "tagged_unions::writable_task_arguments", "unions::packed_mixed_state", "unions::soft_overlay", "unions::soft_signed_ports", "unions::soft_wide_four_state", ] - : [], + : [ + "tagged_unions::conditional_struct_payload", + "tagged_unions::constructors_and_checked_members", + "tagged_unions::default_arguments", + "tagged_unions::factory_and_union_arguments", + "tagged_unions::nested_and_void_constructors", + "tagged_unions::writable_system_arguments", + "tagged_unions::writable_task_arguments", + ], ); } else { assert.equal(result.accepted_failures.length, tool === "icarus" ? 11 : 2);