Skip to content

Don't let clang-format reorder Fiddle #includes#7887

Merged
expipiplus1 merged 2 commits intomasterfrom
fiddle-include-consistency
Aug 18, 2025
Merged

Don't let clang-format reorder Fiddle #includes#7887
expipiplus1 merged 2 commits intomasterfrom
fiddle-include-consistency

Conversation

@samestep
Copy link
Copy Markdown
Contributor

The documentation added by #6844 included instructions to make sure that the Fiddle #include in a file comes after all the other #includes, but it's easy to accidentally violate this via clang-format, as happened for source/slang/slang-ast-modifier.h in #7559. This PR guards against this sort of violation by separating all Fiddle #includes from other #includes via a blank line followed by a // line (as we already do in most cases), and also adds a sentence about this in tools/slang-fiddle/README.md.

As a bonus, I also enabled Markdown syntax highlighting for all the code blocks in that doc file.

@samestep samestep requested a review from a team as a code owner July 23, 2025 20:28
@samestep samestep added the pr: non-breaking PRs without breaking changes label Jul 23, 2025
@samestep samestep requested a review from tangent-vector July 23, 2025 20:56

#include "slang-ast-base.h"

//
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't an empty line sufficient? The // line shouldn't be needed?

Copy link
Copy Markdown
Contributor Author

@samestep samestep Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@csyonghe no, I tried that when writing this PR and it didn't work; e.g. if you write this in source/slang/slang-ast-modifier.h:

#include "slang-ast-base.h"
#include "slang-ir-insts-enum.h"

#include "slang-ast-modifier.h.fiddle"

then clang-format rewrites it as this:

#include "slang-ast-base.h"
#include "slang-ast-modifier.h.fiddle"
#include "slang-ir-insts-enum.h"

which is incorrect.

This is because we use Regroup for the IncludeBlocks setting:

slang/.clang-format

Lines 8 to 10 in 2d23a96

# Preprocessor
AlignEscapedNewlines: Left
IncludeBlocks: Regroup

Your suggestion would work if we were using IncludeBlocks: Preserve, but the // lines here make that unnecessary.

@expipiplus1 expipiplus1 enabled auto-merge August 18, 2025 13:55
@expipiplus1 expipiplus1 added this pull request to the merge queue Aug 18, 2025
github-merge-queue bot pushed a commit that referenced this pull request Aug 18, 2025
Similar to #7887, this PR improves the Fiddle docs a bit by showing how
the `FIDDLE TEMPLATE` example would actually need to include `FIDDLE
END` at some point after `FIDDLE OUTPUT`.
Merged via the queue into master with commit 09054bf Aug 18, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants