runtimeverification / runtimeverification/llvm-backend

Decide on and enforce house C++ style

Open
#994 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
43
Forks
22
PR merge metrics
No merged PRs in 30d

Description

Introduction

After https://github.com/runtimeverification/llvm-backend/pull/992 [^1], I think it's worth putting the effort in to properly clean up our C++ code with a house style. We use a bunch of different styles in the C++ code, and there is no strong consensus for what the correct solution will look like. This issue is an attempt at an opinionated set of defaults that we can bikeshed, then start to apply gradually to the code.[^2]

[!NOTE]
There are a few things that are out of scope here. We already have a consistent structural style for the code that's enforced conveniently by clang-format, and similarly we have a lot of semantic best practices and conventions being enforced by clang-tidy. We can therefore restrict the bikeshedding here to naming aesthetics and consistency.

Proposed Style


#define MACRO_IF_NEEDED(x) x

namespace some_namespace_name {

enum class some_enum {
  variant_a,
  variant_b,
};

template <typename TypeParameter>
class some_class_name {
public:
  void member_function() const;

private:
  int member_variable_ = 0;
};

void some_class_name::member_function() const {
  auto local_var = f();
  free_function(member_variable_);
}

void free_function(int my_parameter_name) {
  ...
}

}

Some things we should also consider that are not directly naming style:

  • Prefixing extern "C" functions with a prefix like kllvm_ (see #992)
  • Using namespaces rather than purely textual namespacing (e.g. kore::composite_pattern rather than kllvm::KORECompositePattern).

Migration Strategy

Once we agree on a style, it should be easily achievable to migrate one stylistic element at a time using clang-tidy.

[^1]: We'd have avoided this pain by enforcing a consistent naming prefix for our C code so as to remain hygienic when interfacing with the outside world. Nobody other than us is naming their functions kllvm_arena_alloc!
[^2]: We can hopefully clean up or improve some of the bigger, gnarlier functions that are currently exempted from clang-tidy's congitive-complexity warnings when we do this.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed naming examples in this issue and the related #992 pull request. Use clang-tidy's readability-identifier-naming check to assess how the proposed conventions could be enforced. The work is done only after the project agrees on a style and defines a migration approach; no specific files or tests are identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.