Skip to content

Commit

Permalink
chore: documents why we have symbol counter in codegen.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samy-33 committed Jan 16, 2025
1 parent 4ca9842 commit 07217e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compiler+runtime/include/cpp/jank/jit/processor.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <boost/filesystem/path.hpp>
#include <fmt/format.h>
#include <memory>

#include <clang/Interpreter/Interpreter.h>
Expand Down Expand Up @@ -45,7 +46,7 @@ namespace jank::jit
return symbol.get().toPtr<T>();
}

return err("Failed to find symbol");
return err(fmt::format("Failed to find the symbol: '{}'", name.c_str()));
}

result<void, native_persistent_string>
Expand Down
11 changes: 11 additions & 0 deletions compiler+runtime/src/cpp/jank/codegen/llvm_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ namespace jank::codegen
auto const global_ctor_fn(ctx->global_ctor_block->getParent());
ctx->builder->CreateCall(global_ctor_fn, {});

/* This dance is performed to keep symbol names unique across all the modules.
* Considering LLVM JIT symbols to be global, we need to define them with
* unique names to avoid conflicts during JIT recompilation/reloading.
*
* The approach, right now, is for each namespace, we will keep a counter
* and will increase it every time we define a new symbol. When we JIT reload
* the same namespace again, we will define new symbols.
*
* This IR codegen for calling `jank_ns_set_symbol_counter`, is to set the counter
* on intial load.
*/
auto const current_ns{ __rt_ctx->current_ns() };
auto const fn_type(
llvm::FunctionType::get(ctx->builder->getVoidTy(),
Expand Down
2 changes: 1 addition & 1 deletion compiler+runtime/src/cpp/jank/jit/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace jank::jit

if(error.isA<llvm::orc::SymbolsCouldNotBeRemoved>())
{
return err(fmt::format("Failed to remove the symbol: {}", name));
return err(fmt::format("Failed to remove the symbol: '{}'", name));
}
return ok();
}
Expand Down

0 comments on commit 07217e6

Please sign in to comment.