Bug 24107 – The error for exceeding the CTFE recursion limit bypasses speculative compilation.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-08-24T21:12:29Z
Last change time
2023-09-11T08:03:07Z
Keywords
CTFE, pull
Assigned to
No Owner
Creator
Harry Gillanders

Comments

Comment #0 by contact — 2023-08-24T21:12:29Z
Exceeding the CTFE recursion limit (which is one-thousand recursive calls) causes the compiler to emit an error. The issue is that this error is emitted even when the compiler is compiling speculatively, such as when evaluating an argument for `__traits(compiles, ...)`. This code will replicate the issue: > bool recurse () > { > return recurse(); > } > > pragma(msg, "This should not output an error message: ", __traits(compiles, {enum bool r = recurse();})); which outputs: > This should not output an error message: .\ctfeRecursionError.d(1): Error: function `ctfeRecursionError.recurse` CTFE recursion limit exceeded > .\ctfeRecursionError.d(3): called from here: `recurse()` > .\ctfeRecursionError.d(1): 1000 recursive calls to function `recurse` > .\ctfeRecursionError.d(6): called from here: `recurse()` > false when it should output: > This should not output an error message: false The offending bit of code, in the compiler, that causes this seems to be in `dmd.dinterpret`, wherein `global.gag` is set to zero: https://github.com/dlang/dmd/blob/0b937d671023a1bf86985b2452096a64aae85f07/compiler/src/dmd/dinterpret.d#L638
Comment #1 by dlang-bot — 2023-09-08T11:08:40Z
@RazvanN7 created dlang/dmd pull request #15587 "Fix Issue 24107 - The error for exceeding the CTFE recursion limit by passes speculative compilation." fixing this issue: - Fix Issue 24107 - The error for exceeding the CTFE recursion limit bypasses speculative compilation. https://github.com/dlang/dmd/pull/15587
Comment #2 by dlang-bot — 2023-09-11T08:03:07Z
dlang/dmd pull request #15587 "Fix Issue 24107 - The error for exceeding the CTFE recursion limit by passes speculative compilation." was merged into master: - 44ddc26d1a3ced47636f54280380db1ef3189a7a by RazvanN7: Fix Issue 24107 - The error for exceeding the CTFE recursion limit bypasses speculative compilation. https://github.com/dlang/dmd/pull/15587