Skip to content

Commit

Permalink
Merge pull request #149 from jank-lang/compile-times
Browse files Browse the repository at this point in the history
Improve compile times by 25%
  • Loading branch information
jeaye authored Dec 19, 2024
2 parents 739ed59 + 2f79425 commit c88df7b
Show file tree
Hide file tree
Showing 166 changed files with 4,476 additions and 3,819 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ misc-definitions-in-headers,\
-bugprone-easily-swappable-parameters,\
-bugprone-reserved-identifier,\
-bugprone-multi-level-implicit-pointer-conversion,\
-bugprone-crtp-constructor-accessibility,\
-readability-redundant-member-init,\
-readability-implicit-bool-conversion,\
-readability-magic-numbers,\
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
[submodule "compiler+runtime/third-party/immer"]
path = compiler+runtime/third-party/immer
url = https://github.com/jank-lang/immer.git
[submodule "compiler+runtime/third-party/magic_enum"]
path = compiler+runtime/third-party/magic_enum
url = https://github.com/jank-lang/magic_enum.git
[submodule "compiler+runtime/third-party/cli11"]
path = compiler+runtime/third-party/cli11
url = https://github.com/jank-lang/CLI11.git
Expand Down
11 changes: 7 additions & 4 deletions compiler+runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ set(
-Wno-covered-switch-default
-Wno-invalid-offsetof
-fno-common
-frtti
-fno-rtti
-fexceptions
#-ftime-trace
$<$<CONFIG:Debug>:-O0>
$<$<CONFIG:Release>:-O2>
)
Expand All @@ -78,13 +79,10 @@ set(
-w
)

# TODO: Remove FMT_HEADER_ONLY once the extern template Clang bug is fixed.
set(
jank_common_compiler_flags
-std=gnu++20
-DIMMER_HAS_LIBGC=1 -DIMMER_TAGGED_NODE=0 -DHAVE_CXX14=1
-DFMT_HEADER_ONLY=1
#-DLIBASSERT_USE_MAGIC_ENUM=1
#-DLIBASSERT_USE_FMT=1
#-DLIBASSERT_STATIC_DEFINE=1
#-stdlib=libc++
Expand Down Expand Up @@ -153,6 +151,7 @@ add_library(
src/cpp/jank/util/scope_exit.cpp
src/cpp/jank/util/escape.cpp
src/cpp/jank/util/clang_format.cpp
src/cpp/jank/util/string_builder.cpp
src/cpp/jank/profile/time.cpp
src/cpp/jank/read/lex.cpp
src/cpp/jank/read/parse.cpp
Expand Down Expand Up @@ -187,6 +186,8 @@ add_library(
src/cpp/jank/runtime/obj/transient_hash_map.cpp
src/cpp/jank/runtime/obj/persistent_sorted_map.cpp
src/cpp/jank/runtime/obj/transient_sorted_map.cpp
src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp
src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp
src/cpp/jank/runtime/obj/transient_vector.cpp
src/cpp/jank/runtime/obj/persistent_hash_set.cpp
src/cpp/jank/runtime/obj/transient_hash_set.cpp
Expand All @@ -204,6 +205,7 @@ add_library(
src/cpp/jank/runtime/obj/chunk_buffer.cpp
src/cpp/jank/runtime/obj/array_chunk.cpp
src/cpp/jank/runtime/obj/chunked_cons.cpp
src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp
src/cpp/jank/runtime/obj/native_array_sequence.cpp
src/cpp/jank/runtime/obj/native_vector_sequence.cpp
src/cpp/jank/runtime/obj/atom.cpp
Expand Down Expand Up @@ -426,6 +428,7 @@ if(jank_tests)
jank_test_exe
test/cpp/main.cpp
test/cpp/jank/native_persistent_string.cpp
test/cpp/jank/util/string_builder.cpp
test/cpp/jank/read/lex.cpp
test/cpp/jank/read/parse.cpp
test/cpp/jank/analyze/box.cpp
Expand Down
1 change: 0 additions & 1 deletion compiler+runtime/include/cpp/jank/analyze/expr/call.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <jank/runtime/obj/persistent_list.hpp>
#include <jank/analyze/expression_base.hpp>

namespace jank::analyze::expr
Expand Down
3 changes: 1 addition & 2 deletions compiler+runtime/include/cpp/jank/analyze/expr/def.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once

#include <jank/runtime/obj/symbol.hpp>
#include <jank/detail/to_runtime_data.hpp>
#include <jank/analyze/local_frame.hpp>
#include <jank/analyze/expression_base.hpp>
#include <jank/option.hpp>
#include <jank/detail/to_runtime_data.hpp>

namespace jank::analyze::expr
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <jank/runtime/obj/symbol.hpp>
#include <jank/analyze/local_frame.hpp>
#include <jank/analyze/expr/do.hpp>
#include <jank/analyze/expression_base.hpp>
Expand Down
1 change: 0 additions & 1 deletion compiler+runtime/include/cpp/jank/analyze/expr/let.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <jank/runtime/obj/symbol.hpp>
#include <jank/analyze/expr/do.hpp>
#include <jank/analyze/local_frame.hpp>
#include <jank/analyze/expression_base.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <jank/runtime/obj/symbol.hpp>
#include <jank/analyze/expression_base.hpp>
#include <jank/detail/to_runtime_data.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <jank/runtime/obj/persistent_list.hpp>
#include <jank/analyze/expression_base.hpp>
#include <jank/analyze/expr/recursion_reference.hpp>

Expand Down
3 changes: 0 additions & 3 deletions compiler+runtime/include/cpp/jank/analyze/expr/recur.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pragma once

#include <memory>

#include <jank/runtime/obj/persistent_list.hpp>
#include <jank/analyze/expression_base.hpp>

namespace jank::analyze::expr
Expand Down
1 change: 0 additions & 1 deletion compiler+runtime/include/cpp/jank/analyze/expr/set.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <jank/analyze/expression_base.hpp>
#include <jank/runtime/obj/persistent_hash_set.hpp>

namespace jank::analyze::expr
{
Expand Down
20 changes: 16 additions & 4 deletions compiler+runtime/include/cpp/jank/analyze/expression_base.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include <magic_enum.hpp>

#include <jank/detail/to_runtime_data.hpp>
#include <jank/runtime/core/make_box.hpp>
#include <jank/runtime/core/seq.hpp>
#include <jank/runtime/obj/persistent_array_map.hpp>
#include <jank/analyze/local_frame.hpp>
#include <jank/detail/to_runtime_data.hpp>

namespace jank::analyze
{
Expand All @@ -18,13 +17,26 @@ namespace jank::analyze
tail
};

constexpr char const *expression_position_str(expression_position const pos)
{
switch(pos)
{
case expression_position::value:
return "value";
case expression_position::statement:
return "statement";
case expression_position::tail:
return "tail";
}
}

/* Common base class for every expression. */
struct expression_base : gc
{
object_ptr to_runtime_data() const
{
return obj::persistent_array_map::create_unique(make_box("position"),
make_box(magic_enum::enum_name(position)),
make_box(expression_position_str(position)),
make_box("needs_box"),
make_box(needs_box));
}
Expand Down
26 changes: 25 additions & 1 deletion compiler+runtime/include/cpp/jank/analyze/local_frame.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#pragma once

#include <jank/runtime/obj/symbol.hpp>
#include <jank/option.hpp>
#include <jank/runtime/object.hpp>

namespace jank::runtime
{
struct context;

namespace obj
{
using symbol_ptr = native_box<struct symbol>;
}
}

namespace jank::analyze
Expand Down Expand Up @@ -60,6 +65,25 @@ namespace jank::analyze
finally
};

static constexpr char const *frame_type_str(frame_type const type)
{
switch(type)
{
case frame_type::root:
return "root";
case frame_type::fn:
return "fn";
case frame_type::let:
return "let";
case frame_type::try_:
return "try_";
case frame_type::catch_:
return "catch_";
case frame_type::finally:
return "finally";
}
}

static constexpr native_bool pointer_free{ false };

local_frame() = delete;
Expand Down
12 changes: 8 additions & 4 deletions compiler+runtime/include/cpp/jank/analyze/processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#include <functional>

#include <jank/read/parse.hpp>
#include <jank/runtime/obj/symbol.hpp>
#include <jank/runtime/obj/persistent_list.hpp>
#include <jank/runtime/obj/persistent_vector.hpp>
#include <jank/runtime/obj/persistent_array_map.hpp>
#include <jank/runtime/var.hpp>
#include <jank/analyze/local_frame.hpp>
#include <jank/analyze/expression.hpp>
Expand All @@ -15,6 +11,14 @@
namespace jank::runtime
{
struct context;

namespace obj
{
using symbol_ptr = native_box<struct symbol>;
using persistent_list_ptr = native_box<struct persistent_list>;
using persistent_vector_ptr = native_box<struct persistent_vector>;
using persistent_array_map_ptr = native_box<struct persistent_array_map>;
}
}

namespace jank::analyze
Expand Down
6 changes: 5 additions & 1 deletion compiler+runtime/include/cpp/jank/codegen/llvm_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
#include <llvm/Analysis/LoopAnalysisManager.h>
#include <llvm/Analysis/CGSCCPassManager.h>

#include <jank/runtime/obj/keyword.hpp>
#include <jank/analyze/expression.hpp>
#include <jank/analyze/processor.hpp>

namespace jank::runtime::obj
{
using keyword_ptr = native_box<struct keyword>;
}

namespace jank::codegen
{
using namespace jank::runtime;
Expand Down
5 changes: 4 additions & 1 deletion compiler+runtime/include/cpp/jank/detail/to_runtime_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <boost/filesystem/path.hpp>

#include <jank/runtime/object.hpp>
#include <jank/runtime/obj/symbol.hpp>
#include <jank/runtime/obj/persistent_array_map.hpp>
#include <jank/runtime/core/make_box.hpp>

namespace jank::detail
Expand All @@ -29,7 +31,8 @@ namespace jank::detail
template <typename T>
object_ptr to_runtime_data(native_box<T> const &d)
{
return make_box(fmt::format("box({})", reinterpret_cast<void const *>(d.data)));
util::string_builder sb;
return make_box(sb("box(")(reinterpret_cast<void const *>(d.data))(")").release());
}

inline object_ptr to_runtime_data(native_persistent_string const &d)
Expand Down
20 changes: 7 additions & 13 deletions compiler+runtime/include/cpp/jank/native_persistent_string.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <bit>
#include <fmt/format.h>

#include <jank/type.hpp>

Expand All @@ -12,6 +11,11 @@ namespace jank
uint32_t integer(native_hash const input);
}

namespace util
{
struct string_builder;
}

/* This is a not-completely-standard replacement for std::string, with a few goals in mind:
*
* 1. Be as fast, or faster, than `std::string` and `folly::fbstring`
Expand Down Expand Up @@ -62,6 +66,8 @@ namespace jank

static constexpr size_type npos{ std::numeric_limits<size_type>::max() };

friend struct util::string_builder;

constexpr native_persistent_string() noexcept
{
set_small_size(0);
Expand Down Expand Up @@ -926,18 +932,6 @@ namespace jank
}
}

template <>
struct fmt::formatter<jank::native_persistent_string> : private formatter<fmt::string_view>
{
using formatter<fmt::string_view>::parse;

template <typename Context>
auto format(jank::native_persistent_string const &s, Context &ctx) const
{
return formatter<fmt::string_view>::format({ s.data(), s.size() }, ctx);
}
};

namespace std
{
template <>
Expand Down
17 changes: 17 additions & 0 deletions compiler+runtime/include/cpp/jank/native_persistent_string/fmt.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <fmt/base.h>

#include <jank/native_persistent_string.hpp>

template <>
struct fmt::formatter<jank::native_persistent_string> : private formatter<fmt::string_view>
{
using formatter<fmt::string_view>::parse;

template <typename Context>
auto format(jank::native_persistent_string const &s, Context &ctx) const
{
return formatter<fmt::string_view>::format({ s.data(), s.size() }, ctx);
}
};
21 changes: 0 additions & 21 deletions compiler+runtime/include/cpp/jank/option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#include <cassert>
#include <utility> // move, forward
#include <type_traits>
#include <ostream>

#include <fmt/ostream.h>

#include <jank/type.hpp>

Expand Down Expand Up @@ -268,22 +265,4 @@ namespace jank
}

constexpr inline none_t none = none_t{};

template <typename T>
std::ostream &operator<<(std::ostream &os, option<T> const &o)
{
if(o.is_none())
{
return os << "none";
}
return os << "some(" << o.unwrap() << ")";
}
}

namespace fmt
{
template <typename T>
struct formatter<jank::option<T>> : fmt::ostream_formatter
{
};
}
Loading

0 comments on commit c88df7b

Please sign in to comment.