diff --git a/crates/celox-sv-analyzer/src/ast/declarations.rs b/crates/celox-sv-analyzer/src/ast/declarations.rs index e7013f13a15..588d8a08f10 100644 --- a/crates/celox-sv-analyzer/src/ast/declarations.rs +++ b/crates/celox-sv-analyzer/src/ast/declarations.rs @@ -37,6 +37,20 @@ pub(super) fn ports_from_scope( None if native.data_type.is_none() => inherited_type.clone(), None => return Err(unsupported("unsupported port data type")), }; + if !type_binding::declared_port_range_matches( + native, + &base, + syntax_tree, + session, + const_env, + type_aliases, + )? { + return Err(AnalyzerError::Parse(format!( + "the ranges of a non-ANSI port declaration and its net or variable \ + declaration of `{}` differ", + native_port_name(native)? + ))); + } inherited_direction = direction; inherited_type = base.clone(); let ty = type_with_unpacked_ranges( diff --git a/crates/celox-sv-analyzer/src/ast/type_binding.rs b/crates/celox-sv-analyzer/src/ast/type_binding.rs index 841ba578a4e..1a9b0ed86fa 100644 --- a/crates/celox-sv-analyzer/src/ast/type_binding.rs +++ b/crates/celox-sv-analyzer/src/ast/type_binding.rs @@ -86,6 +86,40 @@ pub(super) fn port_type( bind(id, tree, session, &context) } +/// Whether the range of the port declaration of a non-ANSI port, which its +/// net or variable declaration repeats in other words, has the bounds of the +/// port's type (IEEE 1800-2023 23.2.2.1). +pub(super) fn declared_port_range_matches( + port: &celox_sv_syntax::Port, + ty: &Type, + tree: &AnalysisContext<'_>, + session: &mut Session, + env: &HashMap, + aliases: &HashMap, +) -> Converted { + let Some(id) = port.declared_type else { + return Ok(true); + }; + let context = PackedDimensions::new(HashMap::default(), env, aliases); + let data = tree.declarations().data_type(id); + let declared = binding::packed_ranges(&data.packed_dimensions, tree, session, &context)?; + let bounds = |range: &PackedRange| { + constants::eval_ast_const_expr(&tree.functions, range.left(), env).zip( + constants::eval_ast_const_expr(&tree.functions, range.right(), env), + ) + }; + Ok(declared.len() == ty.packed_ranges.len() + && declared + .iter() + .zip(&ty.packed_ranges) + .all( + |(declared, range)| match (bounds(declared), bounds(range)) { + (Some(declared), Some(range)) => declared == range, + _ => declared == range, + }, + )) +} + /// Formal/return implicit types use scalar logic rather than an unsized local. pub(super) fn implicit_subroutine_type( id: TypeId, diff --git a/crates/celox-sv-syntax/src/nodes.rs b/crates/celox-sv-syntax/src/nodes.rs index b37fef66046..4ae7ec33857 100644 --- a/crates/celox-sv-syntax/src/nodes.rs +++ b/crates/celox-sv-syntax/src/nodes.rs @@ -322,6 +322,11 @@ pub struct Port { pub data_type: Option, pub dimensions: Vec, pub default: Option, + /// The type of the port declaration of a non-ANSI port whose net or + /// variable declaration repeats its range in other words. The ranges + /// must have the same bounds (IEEE 1800-2023 23.2.2.1), which takes + /// parameter values to check. + pub declared_type: Option, pub tokens: TokenRange, } diff --git a/crates/celox-sv-syntax/src/parser/declarations.rs b/crates/celox-sv-syntax/src/parser/declarations.rs index 529706cb3ad..9e4e54aaed9 100644 --- a/crates/celox-sv-syntax/src/parser/declarations.rs +++ b/crates/celox-sv-syntax/src/parser/declarations.rs @@ -1324,6 +1324,7 @@ impl Parser<'_> { data_type, dimensions, default, + declared_type: None, tokens: self.range(start), }; inherited = Some(port.clone()); diff --git a/crates/celox-sv-syntax/src/parser/non_ansi.rs b/crates/celox-sv-syntax/src/parser/non_ansi.rs index 1a1560d916d..c20aa9a2dc3 100644 --- a/crates/celox-sv-syntax/src/parser/non_ansi.rs +++ b/crates/celox-sv-syntax/src/parser/non_ansi.rs @@ -72,7 +72,7 @@ impl Parser<'_> { return Err(self.error(format!("port `{name}` has no port declaration"))); }; let (_, declaration) = declarations.swap_remove(index); - let (net_type, variable, data_type) = if declaration.net_type.is_some() + let (net_type, variable, data_type, declared_type) = if declaration.net_type.is_some() || declaration.variable || !matches!( self.types[declaration.data_type.0].kind, @@ -89,6 +89,7 @@ impl Parser<'_> { declaration.net_type, declaration.variable, declaration.data_type, + None, ) } else { // The port is completed by a net or variable declaration of @@ -104,13 +105,14 @@ impl Parser<'_> { declaration.data_type, )? { Some(object) => object, - None => (None, false, declaration.data_type), + None => (None, false, declaration.data_type, None), } }; port.direction = Some(declaration.direction); port.net_type = net_type; port.variable = variable; port.data_type = Some(data_type); + port.declared_type = declared_type; port.dimensions = declaration.dimensions; port.default = declaration.default; port.tokens = declaration.tokens; @@ -187,10 +189,12 @@ impl Parser<'_> { } /// Remove the declarator of `name` from the module-scope net or variable - /// declarations, returning the port's net type, `var` and type. The - /// port declaration's packed range and signing carry over to a type - /// that has neither (IEEE 1800-2023 23.2.2.1). A net declaration - /// assignment stays as the continuous assignment it is (10.3.1). + /// declarations, returning the port's net type, `var` and type, and the + /// port declaration's type when its range must be checked against the + /// object's (see [`Self::merge_port_type`]). The port declaration's + /// packed range and signing carry over to a type that has neither (IEEE + /// 1800-2023 23.2.2.1). A net declaration assignment stays as the + /// continuous assignment it is (10.3.1). fn take_port_object( &mut self, items: &mut Vec, @@ -201,7 +205,7 @@ impl Parser<'_> { ), name: &str, port_type: TypeId, - ) -> Result, bool, TypeId)>> { + ) -> Result, bool, TypeId, Option)>> { let qualified = items .iter() .any(|&item| match self.body_items[item.0].kind { @@ -297,11 +301,8 @@ impl Parser<'_> { } (None, false) => {} } - Ok(Some(( - net_type, - variable, - self.merge_port_type(port_type, object_type)?, - ))) + let (data_type, declared_type) = self.merge_port_type(port_type, object_type)?; + Ok(Some((net_type, variable, data_type, declared_type))) } /// The continuous assignment `name = right` of a net declaration @@ -357,16 +358,23 @@ impl Parser<'_> { } /// The type of a port declared by a port declaration of type - /// `port_type` and a net or variable declaration of type `object_type`. - fn merge_port_type(&mut self, port_type: TypeId, object_type: TypeId) -> Result { + /// `port_type` and a net or variable declaration of type `object_type`, + /// and `port_type` when both give a range in other words: the ranges + /// must be identical (IEEE 1800-2023 23.2.2.1), so their bounds are + /// compared once parameters have values. + fn merge_port_type( + &mut self, + port_type: TypeId, + object_type: TypeId, + ) -> Result<(TypeId, Option)> { let port = self.types[port_type.0].clone(); let mut object = self.types[object_type.0].clone(); let mut changed = false; + let mut declared = None; if object.packed_dimensions.is_empty() { changed |= !port.packed_dimensions.is_empty(); object.packed_dimensions = port.packed_dimensions.clone(); } else { - // A vector net or variable repeats the port's range exactly. let text = |dimensions: &[Dimension]| { dimensions .iter() @@ -379,25 +387,28 @@ impl Parser<'_> { }) .collect::>() }; - if text(&port.packed_dimensions) != text(&object.packed_dimensions) { + if port.packed_dimensions.is_empty() { return Err(self.error( "the ranges of a non-ANSI port declaration and its net or variable \ declaration differ", )); } + if text(&port.packed_dimensions) != text(&object.packed_dimensions) { + declared = Some(port_type); + } } if port.signed == Some(true) && object.signed != Some(true) { object.signed = Some(true); changed = true; } if !changed { - return Ok(object_type); + return Ok((object_type, declared)); } if self.types.len() >= 1_000_000 { return Err(self.unsupported("native type arena exceeds one million nodes")); } let id = TypeId(self.types.len()); self.types.push(object); - Ok(id) + Ok((id, declared)) } } diff --git a/crates/celox-test-suite/src/sv/cases/hierarchy.vtest b/crates/celox-test-suite/src/sv/cases/hierarchy.vtest index 891856da116..ceb2ca02dff 100644 --- a/crates/celox-test-suite/src/sv/cases/hierarchy.vtest +++ b/crates/celox-test-suite/src/sv/cases/hierarchy.vtest @@ -1760,3 +1760,29 @@ (modify (set x 255)) (assert_eq first 255) (assert_eq last 191)) + +; The range of a non-ANSI port declaration and of the net declaration that +; completes it must be identical (IEEE 1800-2023 23.2.2.1): the bounds, not +; the spelling, as in E902's `cr_clic_busif` (#2126). +(case non_ansi_port_ranges_compare_bounds + (source "non_ansi_ranges.sv" #" + `define EXT_INT_NUM 64 + `define CLIC_INTNUM `EXT_INT_NUM+16 + module child(o); + parameter N = `CLIC_INTNUM; + output [79:0] o; + wire [N-1:0] o; + assign o = {N{1'b1}}; + endmodule + module Top; + wire [79:0] o; + child c(o); + initial begin + #1 $display("%h", o); + $finish; + end + endmodule + "#) + (top Top) + (run_to_finish) + (expect_output "ffffffffffffffffffff\n")) diff --git a/crates/celox/tests/frontends/systemverilog/hierarchy.rs b/crates/celox/tests/frontends/systemverilog/hierarchy.rs index 8c893ac3d94..a925b6e234d 100644 --- a/crates/celox/tests/frontends/systemverilog/hierarchy.rs +++ b/crates/celox/tests/frontends/systemverilog/hierarchy.rs @@ -746,7 +746,11 @@ fn rejects_malformed_non_ansi_port_declarations() { ), ( "module Top(a); input [3:0] a; wire [7:0] a; endmodule", - "its net or variable declaration differ", + "its net or variable declaration of `a` differ", + ), + ( + "module Top(a); parameter N = 8; input [3:0] a; wire [N-1:0] a; endmodule", + "its net or variable declaration of `a` differ", ), ( "module Top(a); input a; wire [3:0] a; endmodule", @@ -781,4 +785,8 @@ sv_backends! { fn many_sibling_parameter_specializations(sim) { @case "hierarchy::many_sibling_parameter_specializations"; } + + fn non_ansi_port_ranges_compare_bounds(sim) { + @case "hierarchy::non_ansi_port_ranges_compare_bounds"; + } } diff --git a/scripts/release-please/package-lock.json b/scripts/release-please/package-lock.json index 3b3d334a27d..10fa76a1f43 100644 --- a/scripts/release-please/package-lock.json +++ b/scripts/release-please/package-lock.json @@ -5,7 +5,7 @@ "packages": { "": { "dependencies": { - "release-please": "17.6.0" + "release-please": "17.11.2" } }, "node_modules/@babel/code-frame": { @@ -263,21 +263,6 @@ "integrity": "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==", "license": "MIT" }, - "node_modules/@types/yargs": { - "version": "16.0.11", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.11.tgz", - "integrity": "sha512-sbtvk8wDN+JvEdabmZExoW/HNr1cB7D/j4LT08rMiuikfA7m/JNJg7ATQcgzs34zHnoScDkY0ZRSl29Fkmk36g==", - "license": "MIT", - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/@types/yargs-parser": { - "version": "21.0.3", - "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz", - "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", - "license": "MIT" - }, "node_modules/@xmldom/xmldom": { "version": "0.8.15", "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.15.tgz", @@ -439,56 +424,6 @@ "node": ">=12" } }, - "node_modules/code-suggester": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/code-suggester/-/code-suggester-5.0.1.tgz", - "integrity": "sha512-8qJiiSCfkbPNWvjEFzdG1UW3axL+Bs0ldV1/TdlBKmF9I/a/WooSQZQCi9M44HoXbVTQesn/IQr6+nIWNnVIWA==", - "license": "Apache-2.0", - "dependencies": { - "@octokit/rest": "^20.1.2", - "@types/yargs": "^16.0.0", - "async-retry": "^1.3.1", - "diff": "^8.0.3", - "glob": "^7.1.6", - "parse-diff": "^0.11.0", - "yargs": "^16.0.0" - }, - "bin": { - "code-suggester": "build/src/bin/code-suggester.js" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/code-suggester/node_modules/cliui": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", - "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", - "license": "ISC", - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" - } - }, - "node_modules/code-suggester/node_modules/yargs": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.2.tgz", - "integrity": "sha512-Nt9ZJjXTv5R8MHbqby/wXQ6Gi0Bb3TcYZkR1bzuL4yB2OxWPkXknz513gEF0GoA6tn00UpbPvERW8rzCuWCA6w==", - "license": "MIT", - "dependencies": { - "cliui": "^7.0.2", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.0", - "y18n": "^5.0.5", - "yargs-parser": "^20.2.2" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -517,12 +452,6 @@ "dot-prop": "^5.1.0" } }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", - "license": "MIT" - }, "node_modules/conventional-changelog-conventionalcommits": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-6.1.0.tgz", @@ -830,12 +759,6 @@ "node": ">=8" } }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "license": "ISC" - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -854,55 +777,6 @@ "node": "6.* || 8.* || >= 10.*" } }, - "node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me", - "license": "ISC", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/glob/node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "license": "MIT" - }, - "node_modules/glob/node_modules/brace-expansion": { - "version": "1.1.21", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.21.tgz", - "integrity": "sha512-9zeA+KLZNNzglF2TPKRQEDyx6Yby7daAkuy8MiPzpXPsYDWi/DRM8jmwUDxokQjYqBpv5DgPiwD4h4ZZSy1Ujw==", - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/glob/node_modules/minimatch": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", - "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", - "license": "ISC", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, "node_modules/handlebars": { "version": "4.7.10", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.10.tgz", @@ -1010,23 +884,6 @@ "node": ">=8" } }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", - "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", - "license": "ISC", - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "license": "ISC" - }, "node_modules/is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -1386,12 +1243,6 @@ "node": ">=6" } }, - "node_modules/parse-diff": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/parse-diff/-/parse-diff-0.11.1.tgz", - "integrity": "sha512-Oq4j8LAOPOcssanQkIjxosjATBIEJhCxMCxPhMu+Ci4wdNmAEdx0O+a7gzbR2PyKXgKPvRLIN5g224+dJAsKHA==", - "license": "MIT" - }, "node_modules/parse-github-repo-url": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/parse-github-repo-url/-/parse-github-repo-url-1.4.1.tgz", @@ -1425,15 +1276,6 @@ "node": ">=8" } }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", @@ -1546,13 +1388,13 @@ } }, "node_modules/release-please": { - "version": "17.6.0", - "resolved": "https://registry.npmjs.org/release-please/-/release-please-17.6.0.tgz", - "integrity": "sha512-ItzkkEBeEbKsCrx7N1QlADrCahoONA4WPlsOinSnXTkqUBIWlHC6+S28VJ9PaHy7ZPSJwSQsRuDjI0/HL5G6hw==", + "version": "17.11.2", + "resolved": "https://registry.npmjs.org/release-please/-/release-please-17.11.2.tgz", + "integrity": "sha512-we0+NgyHjvczxrilD6aujnRNuASd65Jem0dY5evevxSZvz8BnKnB/QRN3UzGA229fcV09lKCYbqeE9HgkXzGmA==", "license": "Apache-2.0", "dependencies": { "@conventional-commits/parser": "^0.4.1", - "@google-automations/git-file-utils": "^3.0.0", + "@google-automations/git-file-utils": "^3.2.0", "@iarna/toml": "^3.0.0", "@octokit/graphql": "^7.1.0", "@octokit/request": "^8.3.1", @@ -1560,8 +1402,8 @@ "@octokit/rest": "^20.1.1", "@types/npm-package-arg": "^6.1.0", "@xmldom/xmldom": "^0.8.4", + "async-retry": "^1.3.3", "chalk": "^4.0.0", - "code-suggester": "^5.0.0", "conventional-changelog-conventionalcommits": "^6.0.0", "conventional-changelog-writer": "^6.0.0", "conventional-commits-filter": "^3.0.0", @@ -1570,7 +1412,7 @@ "figures": "^3.0.0", "http-proxy-agent": "^7.0.0", "https-proxy-agent": "^7.0.0", - "js-yaml": "^4.0.0", + "js-yaml": "^4.3.1", "jsonpath-plus": "^10.0.0", "node-html-parser": "^6.0.0", "parse-github-repo-url": "^1.4.1", @@ -1587,7 +1429,7 @@ "release-please": "build/src/bin/release-please.js" }, "engines": { - "node": ">=20.0.0" + "node": ">=22.0.0" } }, "node_modules/require-directory": { diff --git a/scripts/release-please/package.json b/scripts/release-please/package.json index aa8fc66cbb8..75014069561 100644 --- a/scripts/release-please/package.json +++ b/scripts/release-please/package.json @@ -1,6 +1,6 @@ { "private": true, "dependencies": { - "release-please": "17.6.0" + "release-please": "17.11.2" } }