llvm / llvm/llvm-project

[Clang-Format] Tablegen formatter should prefer breaking after `let ... in`

Open
#160,414 1 comment 1 reaction 0 assignees View on GitHub
clang-format tablegen
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

We currently end up with formatting like the following (running clang-format on RISCVInstrInfo.td:
```
let isTrap =
1 in def EBREAK : RVInstI<0b000, OPC_SYSTEM, (outs), (ins), "ebreak", "">,
Sched<[]> {
let rs1 = 0;
let rd = 0;
let imm12 = 1;
}
```

It looks better with curly braces, but still not ideal:
```
let isTrap = 1 in {
def EBREAK : RVInstI<0b000, OPC_SYSTEM, (outs), (ins), "ebreak", "">,
Sched<[]> {
let rs1 = 0;
let rd = 0;
let imm12 = 1;
}
}
```

IMO it would be cleanest to use something like this, i.e. break after `let ... in` and no indentation.
```
let isTrap = 1 in
def EBREAK : RVInstI<0b000, OPC_SYSTEM, (outs), (ins), "ebreak", "">,
Sched<[]> {
let rs1 = 0;
let rd = 0;
let imm12 = 1;
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the formatting in RISCVInstrInfo.td by running clang-format and compare the current output with the proposed break after `let ... in`. Trace the TableGen formatter behavior responsible for this construct, then verify that the resulting output matches the example without regressing related formatting.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.