Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .git-blame-ignore-revs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can only do this after you’ve committed the PR
Because you have a squash merge, which combines the commits into one and will result in a different SHA

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For example:

Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

# apply clang-format to common, runtime, runtime-common, and runtime-light directories
ff72b37bda68cf282c37a92d23bc763de6f47795
340f945b4bb788c1ad7074e2c81bc15c345f5ccb
10 changes: 5 additions & 5 deletions .github/workflows/pr-code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Check "#pragma once" in files
run: |
EXIT_CODE=0
for file in $(find . -name '*.h' -type f \( -path './common/*' -o -path './runtime/*' -o -path './runtime-common/*' -o -path './runtime-light/*' \)); do
for file in $(find . -name '*.h' -type f \( -path './common/*' -o -path './runtime/*' -o -path './runtime-common/*' -o -path './runtime-light/*' -o -path './compiler/*' \)); do
if [[ $( grep -q -E '^#pragma\ once' "$file" )$? -ne 0 ]]; then
echo "Missing '#pragma once' in file '$file'"
EXIT_CODE=1
Expand All @@ -50,16 +50,16 @@ jobs:
fi

- name: Install clang-format
run: sudo apt-get install -y clang-format-18
run: pip install --break-system-packages clang-format==18.1.8

- name: Run clang-format on changed files
run: |
# Get list of changed files
CHANGED_FILES=$(git diff --name-only --diff-filter=ACM origin/master...HEAD --)
CHANGED_CPP_FILES=$(echo "$CHANGED_FILES" | (grep -E '^(common|runtime|runtime-common|runtime-light)/.*\.(cpp|hpp|h|inl)$' || :; ))
CHANGED_CPP_FILES=$(echo "$CHANGED_FILES" | (grep -E '^(common|runtime|runtime-common|runtime-light|compiler)/.*\.(cpp|hpp|h|inl)$' || :; ))

# Apply clang-format to each changed source file
echo "$CHANGED_CPP_FILES" | xargs -r clang-format-18 -i
echo "$CHANGED_CPP_FILES" | xargs -r clang-format -i

- name: Check for formatting changes
run: |
Expand Down
3 changes: 3 additions & 0 deletions common/algorithms/contains.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#pragma once
#include <algorithm>
#include <iterator>
#include <type_traits>
#include <utility>

namespace vk {

Expand Down
317 changes: 155 additions & 162 deletions compiler/class-assumptions.cpp

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions compiler/class-assumptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,39 @@
#include "compiler/debug.h"

class Assumption {
DEBUG_STRING_METHOD { return as_human_readable(); }
DEBUG_STRING_METHOD {
return as_human_readable();
}

public:
// the only field of Assumption indicates a possible state:
// 1) nullptr — undefined (meaning "not instance inside")
// 2) otherwise, it contains an instance inside
// important! no int / string[] / tuple(int): only if it has instances! (so that it will help -> resolving)
const TypeHint *assum_hint{nullptr};
const TypeHint* assum_hint{nullptr};

Assumption() = default;
explicit Assumption(const TypeHint *type_hint) : assum_hint(type_hint) {}
explicit Assumption(const TypeHint* type_hint)
: assum_hint(type_hint) {}
explicit Assumption(ClassPtr klass);

std::string as_human_readable() const;

explicit operator bool() const { return assum_hint != nullptr; }
explicit operator bool() const {
return assum_hint != nullptr;
}

ClassPtr try_as_class() const { return extract_instance_from_type_hint(assum_hint); }
ClassPtr try_as_class() const {
return extract_instance_from_type_hint(assum_hint);
}
Assumption get_inner_if_array() const;
Assumption get_subkey_by_index(VertexPtr index_key) const;

static ClassPtr extract_instance_from_type_hint(const TypeHint *type_hint);
static ClassPtr extract_instance_from_type_hint(const TypeHint* type_hint);
};


void assumption_add_for_var(FunctionPtr f, const std::string &var_name, const Assumption &assumption, VertexPtr v_location);
void assumption_add_for_return(FunctionPtr f, const Assumption &assumption, VertexPtr v_location);
void assumption_add_for_var(FunctionPtr f, const std::string& var_name, const Assumption& assumption, VertexPtr v_location);
void assumption_add_for_return(FunctionPtr f, const Assumption& assumption, VertexPtr v_location);

Assumption assume_class_of_expr(FunctionPtr f, VertexPtr root, VertexPtr stop_at);
Assumption assume_return_of_function(FunctionPtr f);
3 changes: 1 addition & 2 deletions compiler/code-gen/code-gen-root-cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

struct CodeGenRootCmd {
virtual ~CodeGenRootCmd() = default;
virtual void compile(CodeGenerator &W) const = 0;
virtual void compile(CodeGenerator& W) const = 0;
};

16 changes: 8 additions & 8 deletions compiler/code-gen/code-gen-task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
// Copyright (c) 2020 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt

#include "compiler/code-gen/code-gen-root-cmd.h"
#include "compiler/code-gen/code-gen-task.h"
#include "compiler/code-gen/code-gen-root-cmd.h"

// this os exists to be passed to CodeGenerator constructor,
// but it won't be used actually, as CodeGenerator is not created in "just calc hashes" mode
static DataStream<WriterData *> dummy_os;
static DataStream<WriterData*> dummy_os;

ProfilerRaw &get_code_gen_profiler() {
ProfilerRaw& get_code_gen_profiler() {
static CachedProfiler profiler{"Code generation - calc hashes"};
return *profiler;
}

CodeGenSchedulerTask::CodeGenSchedulerTask(DataStream<std::unique_ptr<CodeGenRootCmd>> &os, std::unique_ptr<CodeGenRootCmd> &&cmd)
: W(true, dummy_os)
, os(os)
, cmd(std::move(cmd)) {}
CodeGenSchedulerTask::CodeGenSchedulerTask(DataStream<std::unique_ptr<CodeGenRootCmd>>& os, std::unique_ptr<CodeGenRootCmd>&& cmd)
: W(true, dummy_os),
os(os),
cmd(std::move(cmd)) {}

void CodeGenSchedulerTask::execute() {
AutoProfiler profler{get_code_gen_profiler()};
stage::set_name("Code generation");

cmd->compile(W);
// if a command produced diff since the previous kphp launch, forward it next, it will be re-launched and saved
if (W.was_diff_in_any_file()) {
Expand Down
8 changes: 4 additions & 4 deletions compiler/code-gen/code-gen-task.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
#include "compiler/stage.h"
#include "compiler/threading/profiler.h"

ProfilerRaw &get_code_gen_profiler();
ProfilerRaw& get_code_gen_profiler();

struct CodeGenRootCmd;

class CodeGenSchedulerTask : public Task {
CodeGenerator W;
DataStream<std::unique_ptr<CodeGenRootCmd>> &os;
DataStream<std::unique_ptr<CodeGenRootCmd>>& os;
std::unique_ptr<CodeGenRootCmd> cmd;

public:
CodeGenSchedulerTask(DataStream<std::unique_ptr<CodeGenRootCmd>> &os, std::unique_ptr<CodeGenRootCmd> &&cmd);
CodeGenSchedulerTask(DataStream<std::unique_ptr<CodeGenRootCmd>>& os, std::unique_ptr<CodeGenRootCmd>&& cmd);

void execute() final;
};

inline void code_gen_start_root_task(DataStream<std::unique_ptr<CodeGenRootCmd>> &os, std::unique_ptr<CodeGenRootCmd> &&cmd) {
inline void code_gen_start_root_task(DataStream<std::unique_ptr<CodeGenRootCmd>>& os, std::unique_ptr<CodeGenRootCmd>&& cmd) {
register_async_task(new CodeGenSchedulerTask(os, std::move(cmd)));
}
16 changes: 8 additions & 8 deletions compiler/code-gen/code-generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// Copyright (c) 2021 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt

#include "compiler/compiler-core.h"
#include "compiler/code-gen/code-generator.h"
#include "compiler/compiler-core.h"
#include "compiler/data/src-file.h"

void CodeGenerator::open_file_create_writer(bool compile_with_debug_info_flag, bool compile_with_crc, const std::string &file_name, const std::string &subdir) {
void CodeGenerator::open_file_create_writer(bool compile_with_debug_info_flag, bool compile_with_crc, const std::string& file_name, const std::string& subdir) {
std::string full_file_name = G->cpp_dir;
if (!subdir.empty()) {
full_file_name += subdir;
full_file_name += "/";
}
full_file_name += file_name;

const auto &exclude_from_debug = G->get_exclude_namespaces();
for (const auto &exclude_symbol : exclude_from_debug) {
const auto& exclude_from_debug = G->get_exclude_namespaces();
for (const auto& exclude_symbol : exclude_from_debug) {
if (file_name.rfind(exclude_symbol, 0) != std::string::npos) {
compile_with_debug_info_flag = false;
}
Expand Down Expand Up @@ -66,8 +66,8 @@ void CodeGenerator::close_file_clear_writer() {
kphp_assert(data != nullptr);
data->end_line();
data->set_calculated_hashes(hash_of_cpp, hash_of_comments);
os << data; // pass it to WriteFilesF
data = nullptr; // do not delete data, as it will be used by and deleted by WriteFilesF
os << data; // pass it to WriteFilesF
data = nullptr; // do not delete data, as it will be used by and deleted by WriteFilesF
}
}

Expand All @@ -76,14 +76,14 @@ void CodeGenerator::feed_hash_of_comments(SrcFilePtr file, int line_num) {
hash_of_comments = hash_of_comments * 56235415617457ULL + string_hash(line_contents.data(), line_contents.size());
}

void CodeGenerator::add_include(const std::string &s) {
void CodeGenerator::add_include(const std::string& s) {
kphp_assert(cur_file != nullptr);
feed_hash(string_hash(s.c_str(), s.size()));
// we need to store includes even when just calculating hashes — to make a dependency map for make
cur_file->includes.emplace_front(s);
}

void CodeGenerator::add_lib_include(const std::string &s) {
void CodeGenerator::add_lib_include(const std::string& s) {
kphp_assert(cur_file != nullptr);
feed_hash(string_hash(s.c_str(), s.size()));
cur_file->lib_includes.emplace_front(s);
Expand Down
55 changes: 26 additions & 29 deletions compiler/code-gen/code-generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct CGContext {
std::vector<std::string> catch_labels;
std::vector<int> catch_label_used;
FunctionPtr parent_func;
const TypeData *null_coalescing_rhs_t{};
const TypeData* null_coalescing_rhs_t{};
bool resumable_flag{false};
bool interruptible_flag{false};
bool namespace_opened{false};
Expand All @@ -45,11 +45,11 @@ class CodeGenerator {
// (one codegen command may produce multiple files, they are set to 0 on opening a new one)
unsigned long long hash_of_cpp;
unsigned long long hash_of_comments;
File *cur_file{nullptr};
File* cur_file{nullptr};

WriterData* data{nullptr}; // stored contents, is created only on step 2 (re-generating diff files)
DataStream<WriterData*>& os; // output stream for stored contents, used only on step 2

WriterData *data{nullptr}; // stored contents, is created only on step 2 (re-generating diff files)
DataStream<WriterData *> &os; // output stream for stored contents, used only on step 2

CGContext context;

int indent_level;
Expand All @@ -63,16 +63,15 @@ class CodeGenerator {
void feed_hash_of_comments(SrcFilePtr file, int line_num);

public:

explicit CodeGenerator(bool is_step_just_calc_hashes, DataStream<WriterData *> &os)
: is_step_just_calc_hashes(is_step_just_calc_hashes)
, os(os) {}
explicit CodeGenerator(bool is_step_just_calc_hashes, DataStream<WriterData*>& os)
: is_step_just_calc_hashes(is_step_just_calc_hashes),
os(os) {}
~CodeGenerator() = default;

CodeGenerator(const CodeGenerator &from) = delete;
CodeGenerator &operator=(const CodeGenerator &) = delete;
CodeGenerator(const CodeGenerator& from) = delete;
CodeGenerator& operator=(const CodeGenerator&) = delete;

void open_file_create_writer(bool compile_with_debug_info_flag, bool compile_with_crc, const std::string &file_name, const std::string &subdir);
void open_file_create_writer(bool compile_with_debug_info_flag, bool compile_with_crc, const std::string& file_name, const std::string& subdir);
void close_file_clear_writer();

void append(char c) {
Expand All @@ -82,7 +81,7 @@ class CodeGenerator {
}
}

void append(const char *p, size_t len) {
void append(const char* p, size_t len) {
if (need_indent) {
need_indent = false;
feed_hash(static_cast<unsigned long long>(' ') * indent_level);
Expand Down Expand Up @@ -132,7 +131,6 @@ class CodeGenerator {
}
}


void indent(int diff) {
indent_level += diff;
}
Expand Down Expand Up @@ -168,10 +166,10 @@ class CodeGenerator {
lock_comments_cnt--;
}

void add_include(const std::string &s);
void add_lib_include(const std::string &s);
void add_include(const std::string& s);
void add_lib_include(const std::string& s);

CGContext &get_context() {
CGContext& get_context() {
return context;
}

Expand All @@ -181,58 +179,57 @@ class CodeGenerator {
};

template<class T, class = decltype(&T::compile)>
CodeGenerator &operator<<(CodeGenerator &c, const T &value) {
CodeGenerator& operator<<(CodeGenerator& c, const T& value) {
value.compile(c);
return c;
}

inline CodeGenerator &operator<<(CodeGenerator &c, const std::string &value) {
inline CodeGenerator& operator<<(CodeGenerator& c, const std::string& value) {
c.append(value.c_str(), value.size());
return c;
}

inline CodeGenerator &operator<<(CodeGenerator &c, const char *value) {
inline CodeGenerator& operator<<(CodeGenerator& c, const char* value) {
c.append(value, strlen(value));
return c;
}

inline CodeGenerator &operator<<(CodeGenerator &c, const vk::string_view &value) {
inline CodeGenerator& operator<<(CodeGenerator& c, const vk::string_view& value) {
c.append(value.data(), value.size());
return c;
}

inline CodeGenerator &operator<<(CodeGenerator &c, long long value) {
inline CodeGenerator& operator<<(CodeGenerator& c, long long value) {
c.append(value);
return c;
}

inline CodeGenerator &operator<<(CodeGenerator &c, long value) {
inline CodeGenerator& operator<<(CodeGenerator& c, long value) {
c.append(static_cast<long long>(value));
return c;
}

inline CodeGenerator &operator<<(CodeGenerator &c, unsigned long long value) {
inline CodeGenerator& operator<<(CodeGenerator& c, unsigned long long value) {
c.append(value);
return c;
}

inline CodeGenerator &operator<<(CodeGenerator &c, unsigned long value) {
inline CodeGenerator& operator<<(CodeGenerator& c, unsigned long value) {
c.append(static_cast<unsigned long long>(value));
return c;
}

inline CodeGenerator &operator<<(CodeGenerator &c, int value) {
inline CodeGenerator& operator<<(CodeGenerator& c, int value) {
c.append(value);
return c;
}

inline CodeGenerator &operator<<(CodeGenerator &c, unsigned int value) {
inline CodeGenerator& operator<<(CodeGenerator& c, unsigned int value) {
c.append(value);
return c;
}

inline CodeGenerator& operator<<(CodeGenerator &c, char value) {
inline CodeGenerator& operator<<(CodeGenerator& c, char value) {
c.append(value);
return c;
}

Loading
Loading