Skip to content

csharp: func_start linear on adjacent [...] and <...> runs (Part of #3320) - #4999

Merged
squid-protocol merged 5 commits into
mainfrom
churn/3320-20261012T1402Z
Oct 12, 2026
Merged

squid-protocol merged 5 commits into
mainfrom
churn/3320-20261012T1402Z

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #3320

What

C# func_start parsed any [...] run three ways on failure (the attribute shield, single [/] chars in the return-type token class, and the \[[^\]]{0,80}\] token), so k adjacent brackets cost 3^k. Brackets now have one owner each, with no atomic groups or possessive quantifiers (py3.10-safe):

  • the line-start shield body is \[(?:[^\[\]]|\[(?:[^\[\]]|\[[^\[\]]{0,40}\]){0,80}\]){0,250}\] (two nested levels; every char class excludes [/]);
  • [ is removed from the return-type token's char class. The \[...\] suffix stays (int[], T[,]). A token may start with [ only as an empty rank specifier (byte [] M());
  • same mechanism on <: it was a char and also the start of the <...> group (.C0<int>.C1<int>..., 260 levels = 2^260, three runtime files timed out on BOTH old and new bracket-only). The < char alternative is now (?!<group>)<, so it applies only where the group can't match (3+ nesting).

Evidence

  • Real file: roslyn UserDefinedCompoundAssignmentOperatorsTests.cs 60s timeout / 0 functions -> 1264 matches in 0.1s. runtime NestedGeneric{Classes,Structs,TypesMix}.cs: 60s timeout -> 0.0s.
  • 47,305 C# files (roslyn 13,987, runtime 31,990, PowerShell 1,337, crucible csharp 6; burned estates under data.hdd/ + language-crucible): total old regex time 421s -> 53s, slowest file 0.29s.
  • Golden: crucible_check.py --update --yes under golden-lock: no drift on both legs; scope_check.py --expect csharp --mode both: 0 differences.
  • pr_gates --fast 5/5 pass; --ratchets 7 pass, 0 fail, 0 skipped.

Parity delta (not zero; for the tick to accept or reject)

Match set of the old regex vs new (name at line, 47,305 files, 898,844 old matches): crucible csharp 0; estates 1829 lost (0.2%), 33 gained, in 263 roslyn/runtime/PowerShell files (roslyn 1606, runtime 210, PowerShell 14 by the first pass). Each lost match is a phantom the old redundant [ derivation produced, not a declaration:

  • 1330: a collection/array-literal element or call statement after a bare [ line ([\n Edit(SemanticEditKind.Update, ...), -> Edit, Row, SemanticEdit, DocumentResults, Diagnostic; [|int x = ...;\n Console.WriteLine(x);|]).
  • 81: an indexer or index chain before a call (item[await GetOffsetAsync(GetOffset(ref item))] += 1; -> GetOffsetAsync, Program<T>.F[await Get0()]++).
  • 383: text inside strings/comments or non-C# dumps that started at [ ([InlineData("[A] void local() { }")], // [A] void M1() { }, IL instance valuetype [mscorlib]...add_E (, VB Property [Select](...), [|F|]-style test markup).
  • 35 more, same kinds (IL, VB, d < F() comparison -> F, public void Goo($$){} inside a raw-string test source; Update [static void F() markup).
    Spot checks found no genuine declaration lost. An earlier intermediate version did lose byte [] M() / T [] method<S>() (space before [], Mono corpus style); fixed and pinned by tests. Gained (33): real declarations the old redundant derivations missed, e.g. [return: NativeInteger(new[] { false, true })] static UIntPtr[] M2() (nested bracket in an attribute), static void F(object? x, object?[] y), void S.F(scoped R r).
    Zero delta would mean keeping the phantoms, which are the extra derivations.

Tests

tests/extraction/languages/test_csharp_strict.py (time-bounded): stacked [InlineData(1, 2)] x400; [GetA][Get0][G1][operator]1True x400 (+ one-line and empty-rank variants); a synthetic UserDefinedCompoundAssignmentOperatorsTests.cs shape (4000 expected-output lines) extracts both methods in < 5s; the 260-level generic chain; 17-case bracket-ownership parity table.

Class sweep (same mechanism in other languages)

Timed all 53 func_start regexes (n=12 vs 24; 18 shapes: [a][b]..., [[a]], @A @B, @A(1) @B(2), @Foo lines, Java nested @A(@B(...)), Kotlin @get:C @field:[D E], Swift @objc @available(...), Rust #[derive], indexers, nested generics). None grows super-linearly or exceeds 0.5s; the harness flags old C# on 5 shapes. So no sibling in Java, Kotlin, Swift, C++, etc.

Cross-repo: none.

🤖 Generated with Claude Code

the 60s worker fuse (it used to exceed it, so the file shipped with 0 functions)."""
import time

func_start = LANGUAGE_DEFINITIONS["csharp"]["rules"]["func_start"]
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol

Copy link
Copy Markdown
Owner Author

Tick review: parity delta accepted. The 1,829 lost matches are phantom derivations from the redundant [ owner (literal elements, indexers, strings/comments/IL/VB test markup); spot checks found no real declaration lost, and the 33 gained are real declarations. Golden has no drift on both legs, gates are clean, and the class sweep found no sibling (53 func_start regexes timed). Acceptance of #3320 is met once this merges.

@squid-protocol squid-protocol added the shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md label Oct 12, 2026
@squid-protocol

Copy link
Copy Markdown
Owner Author

No description provided.

@squid-protocol
squid-protocol marked this pull request as ready for review October 12, 2026 17:29
@squid-protocol
squid-protocol enabled auto-merge (squash) October 12, 2026 17:29
@squid-protocol
squid-protocol merged commit 2e35113 into main Oct 12, 2026
40 checks passed
@squid-protocol
squid-protocol deleted the churn/3320-20261012T1402Z branch October 12, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants