February 07, 2023
https://issues.dlang.org/show_bug.cgi?id=23676

          Issue ID: 23676
           Summary: Compilation differences w/ braceless vs brace-full
                    static if within switch statement
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Mac OS X
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: bradley@chatha.dev

The main, (mostly) reduced code is here: https://gist.github.com/BradleyChatha/873077996b36c9f575fa2410e03705d5

DMD version: DMD64 D Compiler v2.101.2

LDC2 version (has same issue):
LDC - the LLVM D compiler (1.30.0):
  based on DMD v2.100.1 and LLVM 14.0.6
  built with LDC - the LLVM D compiler (1.28.1)
  Default target: arm64-apple-darwin21.6.0
  Host CPU: cyclone
  http://dlang.org - http://wiki.dlang.org/LDC

Main issue:

If you don't wrap the body of the `static if` on Line 70 inside curly braces, the compiler begins to error out with the following:

```
to_report.d(85): Error: `@safe` function
`lexer.Lexer.nextVaryingLengthToken!(safePeek,
Operator).nextVaryingLengthToken` cannot call `@system` function
`lexer.Lexer.nextVaryingLengthToken!(safePeek,
Operator).nextVaryingLengthToken.tryLexLongerOperators!(noreturn).tryLexLongerOperators`
to_report.d(58):        `lexer.Lexer.nextVaryingLengthToken!(safePeek,
Operator).nextVaryingLengthToken.tryLexLongerOperators!(noreturn).tryLexLongerOperators`
is declared here
```

It then proceeds to hang and use max out its CPU usage for a few minutes, before exiting.

However, if you wrap the static if's body in braces, it will succesfully compile without the weird performance issues.

Side issue:

I'm very uncertain about the cause of the hang; if you delete any field within the `Token.Type` enum, the hang reduces to a couple of seconds, instead of minutes.

--