Skip to content

Commit

Permalink
refactor: lint errors and warnings
Browse files Browse the repository at this point in the history
Update clang-tidy to 16 and stylua v0.20.0
  • Loading branch information
vfusco committed Feb 6, 2024
1 parent d6c8bd9 commit c6c06eb
Show file tree
Hide file tree
Showing 118 changed files with 316 additions and 357 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Checks: >-
misc*,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-misc-use-anonymous-namespace,
modernize*,
-modernize-redundant-void-arg,
-modernize-use-default-member-init,
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ ARG SANITIZE=no

RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \
build-essential vim wget git clang-tidy-15 clang-format-15 lcov \
build-essential vim wget git clang-tidy-16 clang-format-16 lcov \
libboost1.81-dev libssl-dev \
ca-certificates pkg-config lua5.4 liblua5.4-dev \
libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \
luarocks xxd procps && \
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 120 && \
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 120 && \
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-16 120 && \
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-16 120 && \
rm -rf /var/lib/apt/lists/*


Expand All @@ -22,7 +22,7 @@ RUN luarocks install --lua-version=5.4 luasocket && \
luarocks install --lua-version=5.4 lpeg && \
luarocks install --lua-version=5.4 dkjson && \
luarocks install --lua-version=5.4 luacheck && \
cargo install stylua@0.18.1 --features lua54
cargo install stylua@0.20.0 --features lua54

# Environment has the riscv64-cartesi-linux-gnu-* toolchain
ENV DEV_ENV_HAS_TOOLCHAIN=yes
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ test% coverage% build-tests%:
build-tests-misc-with-builder-image: build-emulator-builder-image

lint check-format format check-format-lua check-lua format-lua:
$(MAKE) $@-src $@-tests
@$(MAKE) $@-src $@-tests

lint-% check-format-% format-% check-format-lua-% check-lua-% format-lua-%:
@eval $$($(MAKE) -s --no-print-directory env); $(MAKE) -C $(if $(findstring -src,$@),src,tests) $(subst -src,,$(subst -tests,,$@))
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Obs: Please note that Apple Clang Version number does not follow upstream LLVM/C
#### Debian Bookworm

```bash
sudo apt-get install build-essential wget git clang-tidy-15 clang-format-15 \
sudo apt-get install build-essential wget git clang-tidy-16 clang-format-16 \
libboost1.81-dev libssl-dev \
ca-certificates pkg-config lua5.4 liblua5.4-dev \
libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \
Expand All @@ -64,7 +64,7 @@ sudo luarocks install --lua-version=5.4 luaposix

##### MacPorts
```bash
sudo port install clang-15 boost181 wget pkgconfig grpc lua54 lua-luarocks
sudo port install clang-16 boost181 wget pkgconfig grpc lua54 lua-luarocks

sudo luarocks install --lua-version=5.4 lpeg
sudo luarocks install --lua-version=5.4 dkjson
Expand Down Expand Up @@ -176,11 +176,11 @@ We use clang-tidy 15 as the linter.

#### Debian Bookworm

You need to install the package clang-tidy-15 and set it as the default executable with update-alternatives.
You need to install the package clang-tidy-16 and set it as the default executable with update-alternatives.

```bash
apt install clang-tidy-15
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 120
apt install clang-tidy-16
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-16 120
```

### Running Lint
Expand All @@ -197,11 +197,11 @@ We use clang-format to format the code base.

#### Debian Bookworm

You need to install the package clang-format-15 and set is as the default executable with update-alternatives.
You need to install the package clang-format-16 and set is as the default executable with update-alternatives.

```bash
apt install clang-format-15
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 120
apt install clang-format-16
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-16 120
```

### Formatting code
Expand Down
13 changes: 6 additions & 7 deletions src/access-log.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class access {
using sibling_hashes_type = std::vector<hash_type>;
using proof_type = machine_merkle_tree::proof_type;

public:
void set_type(access_type type) {
m_type = type;
}
Expand Down Expand Up @@ -170,14 +169,14 @@ class access {
throw std::runtime_error("can't make proof if access doesn't have sibling hashes");
}
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
const auto &sibiling_hashes = m_sibling_hashes.value();
auto log2_root_size = m_log2_size + sibiling_hashes.size();
const auto &sibling_hashes = m_sibling_hashes.value();
const int log2_root_size = m_log2_size + static_cast<int>(sibling_hashes.size());
proof_type proof(log2_root_size, m_log2_size);
proof.set_root_hash(root_hash);
proof.set_target_address(m_address);
proof.set_target_hash(m_read_hash);
for (size_t log2_size = m_log2_size; log2_size < log2_root_size; log2_size++) {
proof.set_sibling_hash(sibiling_hashes[log2_size - m_log2_size], log2_size);
for (int log2_size = m_log2_size; log2_size < log2_root_size; log2_size++) {
proof.set_sibling_hash(sibling_hashes[log2_size - m_log2_size], log2_size);
}
return proof;
}
Expand All @@ -198,7 +197,7 @@ class access {
uint64_t m_address{0}; ///< Address of access
int m_log2_size{0}; ///< Log2 of size of access
std::optional<access_data> m_read{}; ///< Data before access
hash_type m_read_hash; ///< Hash of data before access
hash_type m_read_hash{}; ///< Hash of data before access
std::optional<access_data> m_written{}; ///< Written data
std::optional<hash_type> m_written_hash{}; ///< Hash of written data
std::optional<sibling_hashes_type> m_sibling_hashes{}; ///< Hashes of siblings in path from address to root
Expand All @@ -213,7 +212,7 @@ class access_log {
bool m_annotations; ///< Includes annotations
bool m_large_data; ///< Includes data bigger than 8 bytes
public:
/// \brief Default constructur
/// \brief Default constructor
/// \param proofs Include proofs
/// \param annotations Include annotations (default false)
explicit type(bool proofs, bool annotations = false, bool large_data = false) :
Expand Down
10 changes: 5 additions & 5 deletions src/back-merkle-tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
//

#include "back-merkle-tree.h"
#include <iomanip>
#include <iostream>
#include <limits>

/// \file
/// \brief Back Merkle tree implementation.

#include "back-merkle-tree.h"

#include <cassert>
#include <limits>

namespace cartesi {

back_merkle_tree::back_merkle_tree(int log2_root_size, int log2_leaf_size, int log2_word_size) :
Expand Down
8 changes: 4 additions & 4 deletions src/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
//

#include "base64.h"

#include <cstdint>
#include <cstring>
#include <sstream>

#include "base64.h"

namespace cartesi {

// Base64 globals
Expand All @@ -37,7 +37,7 @@ static constexpr uint8_t b64unbase[] = {255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255};

// Acumulates bytes in input buffer until 3 bytes are available.
// Accumulates bytes in input buffer until 3 bytes are available.
// Translate the 3 bytes into Base64 form and append to buffer.
// Returns new number of bytes in buffer.
static size_t b64encode(uint8_t c, uint8_t *input, size_t size, std::ostringstream &sout) {
Expand Down Expand Up @@ -98,7 +98,7 @@ static size_t b64pad(const uint8_t *input, size_t size, std::ostringstream &sout
return 0;
}

// Acumulates bytes in input buffer until 4 bytes are available.
// Accumulates bytes in input buffer until 4 bytes are available.
// Translate the 4 bytes from Base64 form and append to buffer.
// Returns new number of bytes in buffer.
static size_t b64decode(uint8_t c, uint8_t *input, size_t size, std::ostringstream &sout) {
Expand Down
2 changes: 2 additions & 0 deletions src/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef BASE64_H
#define BASE64_H

#include <string>

namespace cartesi {

std::string encode_base64(const std::string &input);
Expand Down
5 changes: 1 addition & 4 deletions src/clint-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
//

#include "clint-factory.h"
#include "i-device-state-access.h"
#include "clint.h"
#include "machine.h"
#include "pma.h"
#include "riscv-constants.h"
#include "rtc.h"
#include "strict-aliasing.h"

namespace cartesi {

Expand Down
1 change: 0 additions & 1 deletion src/clint-factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include <cstdint>

#include "clint.h"
#include "pma.h"

namespace cartesi {
Expand Down
1 change: 0 additions & 1 deletion src/clint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "pma-constants.h"
#include "riscv-constants.h"
#include "rtc.h"
#include "strict-aliasing.h"

namespace cartesi {

Expand Down
3 changes: 2 additions & 1 deletion src/clint.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
#ifndef CLINT_H
#define CLINT_H

#include "pma-driver.h"
#include <cstdint>

#include "pma-driver.h"

/// \file
/// \brief Clock interruptor device.

Expand Down
4 changes: 1 addition & 3 deletions src/clua-cartesi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
//

#include "keccak-256-hasher.h"

#include "clua-i-virtual-machine.h"
#include "clua-machine-util.h"
#include "clua-machine.h"
#include "clua.h"
#include "keccak-256-hasher.h"
#include "machine-c-api.h"
#include "riscv-constants.h"
#include "uarch-constants.h"
Expand Down
1 change: 0 additions & 1 deletion src/clua-grpc-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "clua-grpc-machine.h"
#include "clua-htif.h"
#include "clua-i-virtual-machine.h"
#include "clua-machine-util.h"
#include "clua.h"
#include "grpc-machine-c-api.h"
Expand Down
4 changes: 3 additions & 1 deletion src/clua-grpc-machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#ifndef CLUA_GRPC_MACHINE_H
#define CLUA_GRPC_MACHINE_H

#include "clua.h"
extern "C" {
#include <lua.h>
}

/// \file
/// \brief Remote Cartesi machine Lua interface
Expand Down
3 changes: 2 additions & 1 deletion src/clua-htif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
//

#include "clua-htif.h"
#include "clua.h"
#include "htif.h"

#include <array>

namespace cartesi {

int clua_htif_export(lua_State *L, int ctxidx) {
Expand Down
4 changes: 3 additions & 1 deletion src/clua-htif.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#ifndef CLUA_HTIF_H
#define CLUA_HTIF_H

#include "clua.h"
extern "C" {
#include <lua.h>
}

/// \file
/// \brief HTIF device Lua interface
Expand Down
6 changes: 2 additions & 4 deletions src/clua-i-virtual-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
//

#include "clua-i-virtual-machine.h"

#include <cinttypes>

#include "clua-htif.h"
#include "clua-i-virtual-machine.h"
#include "clua-machine-util.h"
#include "clua.h"
#include "unique-c-ptr.h"
#include "virtual-machine.h"

namespace cartesi {

Expand Down
6 changes: 4 additions & 2 deletions src/clua-i-virtual-machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

#include <memory>

#include "clua.h"
extern "C" {
#include <lua.h>
}

#include "i-virtual-machine.h"
#include "machine-c-api.h"

/// \file
/// \brief Cartesi machine Lua interface
Expand Down
1 change: 0 additions & 1 deletion src/clua-jsonrpc-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "clua-jsonrpc-machine.h"
#include "clua-htif.h"
#include "clua-i-virtual-machine.h"
#include "clua-machine-util.h"
#include "clua.h"
#include "jsonrpc-machine-c-api.h"
Expand Down
4 changes: 3 additions & 1 deletion src/clua-jsonrpc-machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#ifndef CLUA_JSONRPC_MACHINE_H
#define CLUA_JSONRPC_MACHINE_H

#include "clua.h"
extern "C" {
#include <lua.h>
}

/// \file
/// \brief Remote Cartesi machine Lua interface
Expand Down
8 changes: 6 additions & 2 deletions src/clua-machine-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
//

#include "clua-machine-util.h"

#include <cstring>
#include <unordered_map>

#include "clua-machine-util.h"
#include "clua.h"
#include "riscv-constants.h"

namespace cartesi {

Expand Down Expand Up @@ -150,6 +152,7 @@ static uint64_t opt_uint_field(lua_State *L, int tabidx, const char *field, uint
return static_cast<uint64_t>(val);
}

// NOLINTNEXTLINE
#if 0 // Unused
/// \brief Returns an optional string field indexed by string in a table.
/// \param L Lua state.
Expand Down Expand Up @@ -746,11 +749,12 @@ cm_access_log_type clua_check_cm_log_type(lua_State *L, int tabidx) {
clua_setintegerfield(L, p.regname, #regname, -1); \
} while (0)

// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
// NOLINTBEGIN(cppcoreguidelines-macro-usage,cppcoreguidelines-avoid-do-while)
#define PUSH_CM_PROCESSOR_CONFIG_CSR(regname) \
do { \
clua_setintegerfield(L, p->regname, #regname, -1); \
} while (0)
// NOLINTEND(cppcoreguidelines-macro-usage,cppcoreguidelines-avoid-do-while)

/// \brief Pushes a cm_processor_config to the Lua stack
/// \param L Lua state.
Expand Down
Loading

0 comments on commit c6c06eb

Please sign in to comment.