Skip to content

Commit 78962ae

Browse files
committed
add a uuid to each Module that is stable across serialization
1 parent 56fe4d5 commit 78962ae

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/dump.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ static void jl_serialize_module(ios_t *s, jl_module_t *m)
486486
}
487487
}
488488
jl_serialize_value(s, m->constant_table);
489+
write_int32(s, (uint32_t)m->uuid);
490+
write_int32(s, (uint32_t)(m->uuid>>32));
489491
}
490492

491493
static int is_ast_node(jl_value_t *v)
@@ -1163,6 +1165,8 @@ static jl_value_t *jl_deserialize_value_(ios_t *s, jl_value_t *vtag, jl_value_t
11631165
i++;
11641166
}
11651167
m->constant_table = (jl_array_t*)jl_deserialize_value(s, (jl_value_t**)&m->constant_table);
1168+
m->uuid = read_int32(s);
1169+
m->uuid |= ((uint64_t)read_int32(s))<<32;
11661170
return (jl_value_t*)m;
11671171
}
11681172
else if (vtag == (jl_value_t*)SmallInt64_tag) {

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ typedef struct _jl_module_t {
253253
arraylist_t usings; // modules with all bindings potentially imported
254254
jl_array_t *constant_table;
255255
jl_function_t *call_func; // cached lookup of `call` within this module
256+
uint64_t uuid;
256257
} jl_module_t;
257258

258259
typedef struct _jl_methlist_t {

src/module.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jl_module_t *jl_new_module(jl_sym_t *name)
2323
m->name = name;
2424
m->constant_table = NULL;
2525
m->call_func = NULL;
26+
m->uuid = uv_now(uv_default_loop());
2627
htable_new(&m->bindings, 0);
2728
arraylist_new(&m->usings, 0);
2829
if (jl_core_module) {
@@ -417,6 +418,7 @@ DLLEXPORT jl_value_t *jl_module_names(jl_module_t *m, int all, int imported)
417418

418419
DLLEXPORT jl_sym_t *jl_module_name(jl_module_t *m) { return m->name; }
419420
DLLEXPORT jl_module_t *jl_module_parent(jl_module_t *m) { return m->parent; }
421+
DLLEXPORT uint64_t jl_module_uuid(jl_module_t *m) { return m->uuid; }
420422

421423
jl_function_t *jl_module_get_initializer(jl_module_t *m)
422424
{

0 commit comments

Comments
 (0)