Out-of-class constraints parse: one line, 45 files, a cascade gone
constraint C::name { ... } at file/package scope failed at the `::` —
parse_constraint's name was expect_name where the out-of-body method
path already existed; it is now parse_method_name, and nothing else
moved: the item was always a verbatim leaf, so no AST variant, no
formatter/binder/spans arm, verify.rs untouched. On the real opentitan
checkout: 45 of 45 bucket-1 files unblocked (44 fully clean, the 45th
advancing to its documented bucket-10 gap), whole-sweep failures
151 -> 107 with zero newly-failing files, and the tolerant-mode
cascade collapsing 1,349 diagnostics -> 1 across the bucket — the LSP
win the round was chosen for. Corpus gate exactly at baseline. QA
reproduced every number independently via stash before/after,
attacked the grammar widening and the verbatim byte-integrity, and
pinned the index-opacity promise with the corrected semantic test.
Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
34b766cbef
commit
e2c954ba77
7 files changed
+701
-1
No files matched your search
@@ -1670,12 +1670,19 @@ impl<'a> Parser<'a> {
|
||||
/// `solve ... before`, `inside`, `foreach`, `if`/`else`) that lucisv models
|
||||
/// none of, and reflowing it has no payoff, so the block is copied out of
|
||||
/// the source by span. A prototype (`constraint c;`) has no braces.
|
||||
///
|
||||
/// The name may carry a `my_class::` scope — the out-of-block constraint
|
||||
/// definition of an `extern constraint` prototype (IEEE 1800 §18.5.2),
|
||||
/// written at file or package scope. That is the constraint sibling of
|
||||
/// `function my_class::method(...)`, so it reuses the same scoped-name
|
||||
/// path; the scope is only consumed, since the whole item is verbatim and
|
||||
/// binds no name either way.
|
||||
fn parse_constraint(&mut self) -> PResult<RawText> {
|
||||
let start = self.here();
|
||||
let col = self.cur().col;
|
||||
self.take_member_prefix();
|
||||
self.expect_kw("constraint")?;
|
||||
self.expect_name()?;
|
||||
self.parse_method_name()?;
|
||||
if !self.eat_sym(";") {
|
||||
self.expect_sym("{")?;
|
||||
self.skip_balanced("{", "}")?;
|
||||
@@ -6404,6 +6411,59 @@ mod tests {
|
||||
assert_eq!(items[0].meta.trailing.as_ref().expect("the comment survived").text, "// why");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Out-of-block constraints
|
||||
// (`docs/features/out-of-class-constraints/README.md`)
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn an_out_of_block_constraint_is_a_file_scope_verbatim_item() {
|
||||
let src = "constraint my_item::delay_c {\n soft delay dist {0 :/ 5};\n}\n";
|
||||
let f = parse_ok(src);
|
||||
let ItemKind::Verbatim(raw) = &f.items[0].kind else { panic!("expected a verbatim block") };
|
||||
assert_eq!(raw.text, "constraint my_item::delay_c {\n soft delay dist {0 :/ 5};\n}");
|
||||
assert_eq!(raw.text, src[raw.span.as_range()], "the capture is the source bytes");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_out_of_block_constraint_scope_may_be_a_chain() {
|
||||
// `pkg::cls::name` — the same chain `parse_method_name` accepts for an
|
||||
// out-of-body method. Nothing is bound either way, so all that matters
|
||||
// is that the whole chain is consumed before the `{`.
|
||||
let f = parse_ok("constraint pkg::cls::deep_c { x < 4; }\n");
|
||||
let ItemKind::Verbatim(raw) = &f.items[0].kind else { panic!("expected a verbatim block") };
|
||||
assert_eq!(raw.text, "constraint pkg::cls::deep_c { x < 4; }");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_out_of_block_constraint_lives_in_a_package_too() {
|
||||
let f = parse_ok("package p;\n constraint c::x { a > 0; }\nendpackage\n");
|
||||
let ItemKind::Package { items, .. } = &f.items[0].kind else {
|
||||
panic!("expected a package")
|
||||
};
|
||||
assert!(matches!(items[0].kind, ItemKind::Verbatim(_)), "{:?}", items[0].kind);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_out_of_block_constraint_keeps_its_trailing_semicolon_and_comments() {
|
||||
// `constraint C::c { ... };` — the stray `;` belongs to the block, and
|
||||
// a comment written past the block must stay outside the capture.
|
||||
let f = parse_ok("// head\nconstraint c::x { a == 0; }; // tail\nint b;\n");
|
||||
let ItemKind::Verbatim(raw) = &f.items[0].kind else { panic!("expected a verbatim block") };
|
||||
assert_eq!(raw.text, "constraint c::x { a == 0; };");
|
||||
assert!(!raw.text.contains("tail"), "the capture swallowed the comment: {:?}", raw.text);
|
||||
assert_eq!(f.items[0].meta.leading[0].text, "// head");
|
||||
assert_eq!(f.items[0].meta.trailing.as_ref().expect("trailing comment").text, "// tail");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_in_class_constraint_still_rejects_a_scope_free_syntax_error() {
|
||||
// The widened name must not swallow a genuinely broken header: the
|
||||
// `::` path only accepts an identifier after the separator.
|
||||
assert_eq!(parse_err("constraint c:: { a == 0; }\n"), "expected identifier (found \"{\")");
|
||||
assert_eq!(parse_err("constraint 4::x { a == 0; }\n"), "expected identifier (found \"4\")");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Concurrent assertions (`docs/features/assertions/README.md`)
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user