Skip to content

Commit 3c3dc2d

Browse files
authored
[STIM] Add tests to semantic pass (#3731)
This PR moves semantic behavior coverage out of QIR generation tests and into semantic pass tests. QIR tests retain coverage for emitted QIR and backend-specific behavior. ## Coverage - **Moved to the semantic pass:** argument and target validation, broadcasting, aliases, measurement-record bounds and scoping, block validation, repeated-qubit checks, and Pauli-product canonicalization. - **Kept in QIR:** generated QIR, gate decompositions, control flow, and unsupported backend behavior. - **Added:** direct coverage of successful instruction and block lowering in `instruction_lowering` and `block_lowering`, plus broad error-case coverage across instruction families and invalid argument, target, and scoping combinations. ## Test Design - Broadcasting tests programmatically inspect every lowered target across instruction families, because missed broadcasts can otherwise fail silently. - Alias tests programmatically compare the lowered canonical and alias forms to ensure they're lowered the same. - Semantic AST snapshots cover successful lowering, while diagnostic snapshots cover error cases.
1 parent 08f6936 commit 3c3dc2d

33 files changed

Lines changed: 9275 additions & 6632 deletions

‎source/compiler/stim_compiler/src/parser.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ pub fn args_span(args: &[Arg]) -> Span {
9999
}
100100
}
101101

102+
pub fn targets_span(targets: &[Target]) -> Span {
103+
let (first, rest) = targets
104+
.split_first()
105+
.expect("target list must not be empty");
106+
Span {
107+
lo: first.span.lo,
108+
hi: rest.last().unwrap_or(first).span.hi,
109+
}
110+
}
111+
102112
#[derive(Clone, Copy)]
103113
pub enum ArgValue {
104114
Default(f64),
@@ -169,7 +179,7 @@ impl Display for TargetKind {
169179
}
170180
}
171181

172-
#[derive(Clone, Copy)]
182+
#[derive(Clone, Copy, Debug, PartialEq)]
173183
pub enum Pauli {
174184
X,
175185
Y,

‎source/compiler/stim_compiler/src/qir/tests.rs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@
33

44
mod boilerplate;
55
mod collapsing_gates;
6-
mod collapsing_gates_broadcasting;
76
mod generalized_pauli_product_gates;
8-
mod measurement_record_bounds;
97
mod measurement_record_targets;
108
mod noise_channels;
11-
mod noise_channels_broadcasting;
129
mod non_clifford_gates;
1310
mod pair_measurements;
14-
mod pair_measurements_broadcasting;
1511
mod peek_loss;
1612
mod repeat;
1713
mod select_block;
1814
mod single_qubit_gates;
19-
mod single_qubit_gates_broadcasting;
2015
mod two_qubit_gates;
21-
mod two_qubit_gates_broadcasting;
2216
mod unsupported_instructions;
2317

2418
use expect_test::Expect;

0 commit comments

Comments
 (0)