Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: clang format & tidy + CI #393

Merged
merged 13 commits into from
May 1, 2023
Merged

Conversation

dbanks12
Copy link
Contributor

@dbanks12 dbanks12 commented Apr 27, 2023

Description

This PR does the following:

  • Establishes a documented coding standard
  • Updates VSCode settings to auto-format code on filesave
    • uses .clang-format
    • includes header grouping & sorting
  • Adds .clangd settings to provide more VSCode warnings for bad code
  • Adds CI job to enforce coding standards via clang-tidy
    • CI job fails if ./scripts/tidy.sh fix would change code
  • Tidys entire codebase (.clang-tidy)
  • Formats entire codebase (updated .clang-format)

Checklist:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

@dbanks12 dbanks12 marked this pull request as ready for review April 29, 2023 16:12
@dbanks12 dbanks12 changed the title Draft: clang format & tidy feat: clang format & tidy + CI Apr 29, 2023
@@ -153,7 +154,7 @@ WASM_EXPORT void abis__compute_function_selector(char const* func_sig_cstr, uint
// hash the function signature using keccak256
auto keccak_hash = ethash_keccak256(reinterpret_cast<uint8_t const*>(func_sig_cstr), strlen(func_sig_cstr));
// get a pointer to the start of the hash bytes
uint8_t const* hash_bytes = reinterpret_cast<uint8_t const*>(&keccak_hash.word64s[0]);
auto const* hash_bytes = reinterpret_cast<uint8_t const*>(&keccak_hash.word64s[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I like that this is being changed from uint8_t to auto, but I can live with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Consistent approach throughout, which I got used to, ove the 160 files :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to only switch to auto when the type is obvious. And that is what I say to do in our standard.

@@ -36,15 +36,14 @@ template <typename NCT> class Contract {

std::map<std::string, Contract<NCT>> imported_contracts;

Contract<NCT>(std::string const& contract_name)
: contract_name(contract_name)
explicit Contract<NCT>(std::string const& contract_name) : contract_name(contract_name)
Copy link
Contributor

@iAmMichaelConnor iAmMichaelConnor May 1, 2023

Choose a reason for hiding this comment

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

This seems to be the only explicit constructor. I wonder why it chose to make this one explicit (and others not)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, not sure why it didn't change others too.... I can look into it.

static std::vector<Note> UTXO_SLOAD(UTXOSetStateVar<Composer, Note>* utxo_set_state_var,
size_t const& num_notes,
typename Note::NotePreimage const& advice);
template <typename Note> static std::vector<Note> UTXO_SLOAD(UTXOSetStateVar<Composer, Note>* utxo_set_state_var,
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be more legible if we always put template <...> on a line before the function declaration. Not worth pauding this PR, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can choose to do have it always on its own line, sometimes on its own line, or just let people use their best judgement. What do you think?

@@ -163,15 +162,15 @@ PublicKernelInputsNoPreviousKernel<NT> get_kernel_inputs_no_previous_kernel()
const NT::fr portal_contract_address = 23456;

const NT::address msg_sender = NT::fr(1);
const NT::address tx_origin = msg_sender;
const NT::address& tx_origin = msg_sender;
Copy link
Contributor

@iAmMichaelConnor iAmMichaelConnor May 1, 2023

Choose a reason for hiding this comment

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

Should this be a reference? If msg_sender changes, we don't want tx_origin to change...
Maybe it's ok in this particular case, because tx_origin is probably only used below to initialise structs... and I think (???) it will always create a copy of the value of tx_origin, rather than passing a reference. Makes me nervous, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't be a problem here because they are both const I believe. But yes you make a good point about it adding & in general. I'll look through and see if there are any sketchy spots where it did this.

template <typename KernelInput>
void propagate_valid_state_transitions(KernelInput const& public_kernel_inputs,
KernelCircuitPublicInputs<NT>& circuit_outputs)
template <typename KernelInput> void propagate_valid_state_transitions(KernelInput const& public_kernel_inputs,
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, not sure I like this moving down to be on same line as function declaration. Seems like in some files it does this, in some files it leaves it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't seem right. Maybe I have the settings different for functions/structs/enums/classes. I'll look into it.

Copy link
Contributor

@iAmMichaelConnor iAmMichaelConnor left a comment

Choose a reason for hiding this comment

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

A few comments, but none of those need stop merging

@iAmMichaelConnor iAmMichaelConnor merged commit 823979a into master May 1, 2023
@iAmMichaelConnor iAmMichaelConnor deleted the db/clang-format-tidy branch May 1, 2023 10:10
ludamad pushed a commit that referenced this pull request Jul 14, 2023
codygunton pushed a commit that referenced this pull request Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants