Skip to content

clean up formatting after 129e66ada2b4e461bdf28b88b70cd2465cb213e4#58

Merged
copybara-service[bot] merged 6 commits intodevfrom
dev-cleanup
Feb 28, 2024
Merged

clean up formatting after 129e66ada2b4e461bdf28b88b70cd2465cb213e4#58
copybara-service[bot] merged 6 commits intodevfrom
dev-cleanup

Conversation

@austinvhuang
Copy link
Contributor

  • clean up formatting after 129e66a
  • add .clang-format defaults
  • minor updates to DEVELOPERS doc

Copy link
Collaborator

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

Looks great! Small nit only.

@dan-zheng dan-zheng added the copybara-import Trigger Copybara for merging pull requests label Feb 27, 2024
Copy link
Collaborator

Choose a reason for hiding this comment

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

As @pculliton suggests: it would be good to look into Github Actions enforcement of clang-format.

(https://github.com/marketplace/actions/clang-format-github-action)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this .clang-format file based on clang-format -style=Google? If not, what are the differences?

Following -style=Google seems like a good idea to me, though I'm not up-to-date with the details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, replicated some settings but -style=Google is the right solution (there are some subtle diffs). Adding a commit that dumps -style=Google settings as is.

Copy link
Member

Choose a reason for hiding this comment

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

hm, the Highway one merely sets BasedOnStyle:Google in the style file. That is quite close to the internal IDE. Why not just go with that, rather than output all settings via script and set them again explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The underlying issue is that the style linter source transformation is different on either side of the copybara source transformation. Disabling include sorting makes the style inter source transformation invariant to the copybara source transformation, with the goal of guaranteeing that style linter application can't break the build as it did in this case.

The specification is small -style="{BasedOnStyle: Google, SortIncludes: false}" and the shell script isn't strictly necessary to include, it's mostly just a reminder so the dumped configuration is reproducible.

I'm good with the comment barrier solution proposed though. We'd be modifying the source so the linter doesn't break the build instead of the other way around.

Copy link
Member

Choose a reason for hiding this comment

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

I understand the issue with the include sorting. My comment is more along the lines of "should we include all of the style spec rather than just say BasedOn:Google". I agree with your point that a complete spec is more reproducible in the face of various clang-format versions which do exist externally, so the script does make sense :)

Copy link
Member

Choose a reason for hiding this comment

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

hm, the Highway one merely sets BasedOnStyle:Google in the style file. That is quite close to the internal IDE. Why not just go with that, rather than output all settings via script and set them again explicitly?

DEVELOPERS.md Outdated
before finalizing PR for submission.

The `.clang-format` is the google style (as of feb 27 2024), except with
`SortIncludes` set to `false` to avoid breaking copybara path substitutions
Copy link
Member

Choose a reason for hiding this comment

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

Sorting is generally desirable. An alternative is to // clang-format off only where it would break us, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i believe that would almost work but i think there would still be corner cases that can slip through, eg a PR introduces a new #include. I can't think of anything that's entirely leak proof atm. For now, I'll use your barrier suggestion re-enable sorting.

Copy link
Member

@jan-wassenberg jan-wassenberg Feb 28, 2024

Choose a reason for hiding this comment

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

Right, I like the idea of a next_line/include/end atomic unit. One caveat there is that any // comment after include would break the build, which is a concern. We could prevent that with another regex group in the copybara transform.

// copybara:import_next_line:gemma_cpp
#include "configs.h" // kSeqLen
// copybara:import_next_line:gemma_cpp
#include "util/args.h" // ArgsBase
Copy link
Member

Choose a reason for hiding this comment

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

I think an even simpler solution to the sorting issue is to add a comment line after the this line, which serves as a 'barrier' it does not sort around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there was actually a bottom barrierin @dan-zheng 's original copybara transformations. i think it might've been taken out to simplify since it was technically redundant, but if it also serves to mitigate linter breakage maybe it's worth reintroducing. for now i'll just add a comment line in manually for these cases.

…t lines to #includes in gemma.h as barriers to block destructive sorting, update doc + remove shell script
@copybara-service copybara-service bot merged commit f4a14bf into dev Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copybara-import Trigger Copybara for merging pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants