Skip to content

Commit 315f1d4

Browse files
authored
A few minor bug fixes related to Geth Integration (#1151)
1. Fix a bug causing gdb to crash when pretty printing certain values. 2. Modify llvm backend code to actually respect the value of the `gc_enabled` flag.
1 parent c23fb6f commit 315f1d4

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

debug/kgdb.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ def kllvm_lookup_function(val):
671671
kind = t.tag
672672
else:
673673
kind = t.name
674+
if not kind:
675+
return None
674676
if kind.startswith('immer::list'):
675677
return termPrinter(val.address, "list", "SortList{}")
676678
elif kind.startswith('immer::set'):

include/runtime/collect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void migrate_rangemap(void *m);
3838
void migrate_set(void *s);
3939
void migrate_collection_node(void **node_ptr);
4040
void set_kore_memory_functions_for_gmp(void);
41-
void kore_collect(void **, uint8_t, layoutitem *);
41+
void kore_collect(void **, uint8_t, layoutitem *, bool force = false);
4242
}
4343

4444
#ifdef GC_DBG

lib/codegen/Decision.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,14 +1106,15 @@ std::pair<std::vector<llvm::Value *>, llvm::BasicBlock *> step_function_header(
11061106
llvm::FunctionType::get(
11071107
llvm::Type::getVoidTy(module->getContext()),
11081108
{arr->getType(), llvm::Type::getInt8Ty(module->getContext()), ptr_ty,
1109-
ptr_ty},
1109+
ptr_ty, llvm::Type::getInt1Ty(module->getContext())},
11101110
false));
11111111
auto *call = llvm::CallInst::Create(
11121112
kore_collect,
11131113
{arr,
11141114
llvm::ConstantInt::get(
11151115
llvm::Type::getInt8Ty(module->getContext()), nroots),
1116-
llvm::ConstantExpr::getBitCast(layout, ptr_ty)},
1116+
llvm::ConstantExpr::getBitCast(layout, ptr_ty),
1117+
llvm::ConstantInt::getFalse(module->getContext())},
11171118
"", collect);
11181119
set_debug_loc(call);
11191120
std::vector<llvm::Value *> phis;

runtime/alloc/arena.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void fresh_block(struct arena *arena) {
122122
BLOCK_SIZE - sizeof(memory_block_header));
123123
}
124124

125-
bool gc_enabled;
125+
bool gc_enabled = true;
126126

127127
__attribute__((noinline)) void *
128128
do_alloc_slow(size_t requested, struct arena *arena) {

runtime/collect/collect.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,11 @@ void init_static_objects(void) {
280280
set_kore_memory_functions_for_gmp();
281281
}
282282

283-
void kore_collect(void **roots, uint8_t nroots, layoutitem *type_info) {
283+
void kore_collect(
284+
void **roots, uint8_t nroots, layoutitem *type_info, bool force) {
285+
if (!force && !gc_enabled) {
286+
return;
287+
}
284288
is_gc = true;
285289
time_for_collection = false;
286290
collect_old = should_collect_old_gen();
@@ -350,7 +354,7 @@ void kore_collect(void **roots, uint8_t nroots, layoutitem *type_info) {
350354
}
351355

352356
void free_all_kore_mem() {
353-
kore_collect(nullptr, 0, nullptr);
357+
kore_collect(nullptr, 0, nullptr, true);
354358
kore_clear();
355359
}
356360
}

runtime/util/ConfigurationParser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct construction {
9898

9999
// NOLINTNEXTLINE(*-cognitive-complexity)
100100
extern "C" void *construct_initial_configuration(kore_pattern const *initial) {
101+
bool enabled = gc_enabled;
101102
gc_enabled = false;
102103
std::vector<std::variant<kore_pattern const *, construction>> work_list{
103104
initial};
@@ -157,14 +158,15 @@ extern "C" void *construct_initial_configuration(kore_pattern const *initial) {
157158
}
158159
}
159160

160-
gc_enabled = true;
161+
gc_enabled = enabled;
161162
return output[0];
162163
}
163164

164165
// NOLINTBEGIN(*-cognitive-complexity)
165166
template <typename It>
166167
static void *
167168
deserialize_initial_configuration(It ptr, It end, binary_version version) {
169+
bool enabled = gc_enabled;
168170
gc_enabled = false;
169171
using namespace kllvm::detail;
170172
auto begin = ptr;
@@ -256,7 +258,7 @@ deserialize_initial_configuration(It ptr, It end, binary_version version) {
256258
}
257259
}
258260

259-
gc_enabled = true;
261+
gc_enabled = enabled;
260262
assert(output.size() == 1 && "Output stack left in invalid state");
261263
return output.front();
262264
}

0 commit comments

Comments
 (0)