Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/celox-sv-analyzer/src/ast/dimensions/query_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ pub(in crate::ast) fn query_context_for_operand(
tree: &AnalysisContext<'_>,
context: &PackedDimensions,
) -> Converted<PackedDimensions> {
if context.scope_types_complete {
// Literals carry their type in their spelling and cannot reference lexical
// declarations. Pattern elements otherwise rediscover the whole scope for
// each literal while the surrounding declaration is still being bound.
let operand = expression_binding::ungroup(root, tree.declarations());
if context.scope_types_complete
|| matches!(
tree.declarations().expression(operand).kind,
ExprKind::Literal(_)
)
{
return Ok(query_context(context));
}
Ok(query_context(&query_operand_dimensions_id(
Expand Down
56 changes: 56 additions & 0 deletions crates/celox-sv-analyzer/src/ast/dimensions/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,59 @@ fn recursive_generate_dimension_discovery_uses_explicit_specialization() {
);
}
}

#[test]
fn preliminary_literal_queries_do_not_discover_scope_declarations() {
let tree = crate::source_tree::parse_scope_fixture(
r#"module Top;
logic [7:0] unrelated [0:31];
localparam A = $bits(123);
localparam B = $bits((8'shff));
localparam C = $bits(4'bx);
localparam D = $bits("ab");
localparam E = $bits('1);
endmodule"#,
Path::new("literal_query.sv"),
)
.unwrap();
let tree = AnalysisContext::unspecialized(&tree);
let input = PackedDimensions::default();
let calls = native_calls(&tree);
assert_eq!(calls.len(), 5);
// Keep the discovery path as an independent reference for the result.
let discovered = calls
.iter()
.map(|call| {
let celox_sv_syntax::ExprKind::Call { arguments, .. } =
&tree.declarations().expression(*call).kind
else {
unreachable!()
};
let context =
query_operand_dimensions_id(arguments[0].value.unwrap(), &tree, &input).unwrap();
query_number(
*call,
&tree,
&HashMap::default(),
&HashMap::default(),
Some(&context),
)
})
.collect::<Vec<_>>();
SYNTAX_TYPE_DISCOVERIES.with(|count| count.set(0));
let direct = calls
.iter()
.map(|call| {
query_number(
*call,
&tree,
&HashMap::default(),
&HashMap::default(),
Some(&input),
)
})
.collect::<Vec<_>>();
assert_eq!(&direct[..4], &[Some(32), Some(8), Some(4), Some(16)]);
assert_eq!(direct, discovered);
assert_eq!(SYNTAX_TYPE_DISCOVERIES.with(|count| count.get()), 0);
}
Loading