1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/// Stack budget for the dedicated parsing thread used by
/// [`parse_solidity_guarded`].
///
/// `solang_parser`'s recursive-descent grammar recurses once per nesting
/// level of the input, so a hostile (or generated) source such as
/// `return 1 +1 +1 ...` a few thousand terms deep overflows the default
/// ~8 MiB main-thread stack and aborts the whole process (SIGABRT) before
/// any error can be reported. 256 MiB raises the depth ceiling by ~32x —
/// far beyond anything a legitimate contract reaches — while staying a
/// hard bound (the memory is only reserved, not committed, until used).
const PARSE_THREAD_STACK_BYTES: usize = 256 * 1024 * 1024;
/// Run `solang_parser::parse(source, 0)` on a worker thread with a large
/// bounded stack, joining failures back as ordinary parse diagnostics.
///
/// The compiler's own recursive AST walks are already `stacker`-guarded
/// (see `src/ir/expressions/dispatch/entry.rs`), but the parser entry point
/// runs *before* those guards and `solang_parser` recurses on its own
/// internal stack. Every call site that parses Solidity source MUST go
/// through this helper — CLI single-file (`extract_imports`), standard-json
/// import resolution, and `parse_source` — so the nesting-depth ceiling
/// stays consistent across entry points.
///
/// A parser panic (rather than a returned `Err`) is converted into a normal
/// error diagnostic instead of unwinding into — or aborting — the caller.