Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to deterministic 64 bit type_ids for cross-binary serialisation #2949

Closed
wants to merge 2 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Makefile-ponyc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ endif
version_str = "$(tag) [$(config)]\ncompiled with: llvm $(llvm_version) \
-- "$(compiler_version)

# build ponyc version md5
ifneq (,$(filter $(OSTYPE), osx bsd))
TAG_MD5_CMD = md5 | sed 's/./&,0x/30;s/./&,0x/28;s/./&,0x/26;s/./&,0x/24;s/./&,0x/22;s/./&,0x/20;s/./&,0x/18;s/./&,0x/16;s/./&,0x/14;s/./&,0x/12;s/./&,0x/10;s/./&,0x/8;s/./&,0x/6;s/./&,0x/4;s/./&,0x/2;s/^/0x/'
else
TAG_MD5_CMD = md5sum | sed 's/ -$$//' | sed 's/./&,0x/30;s/./&,0x/28;s/./&,0x/26;s/./&,0x/24;s/./&,0x/22;s/./&,0x/20;s/./&,0x/18;s/./&,0x/16;s/./&,0x/14;s/./&,0x/12;s/./&,0x/10;s/./&,0x/8;s/./&,0x/6;s/./&,0x/4;s/./&,0x/2;s/^/0x/'
endif

tag_formatted_md5 := $(shell echo $(tag) | $(TAG_MD5_CMD))

# package_name, _version, and _iteration can be overridden by Travis or AppVeyor
package_base_version ?= $(tag)
package_iteration ?= "1"
Expand Down Expand Up @@ -116,6 +125,7 @@ ALL_CFLAGS = -std=gnu11 -fexceptions \
-DBUILD_COMPILER=\"$(compiler_version)\" \
-DPONY_BUILD_CONFIG=\"$(config)\" \
-DPONY_VERSION_STR=\"$(version_str)\" \
-DPONY_VERSION_FORMATTED_MD5=$(tag_formatted_md5) \
-D_FILE_OFFSET_BITS=64
ALL_CXXFLAGS = -std=gnu++11 -fno-rtti
LL_FLAGS = -mcpu=$(cpu)
Expand Down
5 changes: 3 additions & 2 deletions packages/json/_test.pony
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,9 @@ class iso _TestPrintObject is UnitTest
obj.data("a") = true
obj.data("b") = I64(3)
let s = doc.string(" ", true)
h.assert_true((s == "{\n \"a\": true,\n \"b\": 3\n}") or
(s == "{\n \"b\": false,\n \"a\": true\n}"))
h.assert_true((s == "{\n \"a\": true,\n \"b\": 3\n}")
or (s == "{\n \"b\": 3,\n \"a\": true\n}")
or (s == "{\n \"b\": false,\n \"a\": true\n}"))

// We don't test with more fields in the object because we don't know what
// order they will be printed in
Expand Down
15 changes: 9 additions & 6 deletions src/libponyc/ast/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1954,12 +1954,12 @@ static void ast_signature_serialise_trace(pony_ctx_t* ctx, void* object)
}

static void ast_signature_serialise(pony_ctx_t* ctx, void* object, void* buf,
size_t offset, int mutability)
uint64_t offset, int mutability)
{
(void)mutability;

ast_t* ast = (ast_t*)object;
ast_signature_t* dst = (ast_signature_t*)((uintptr_t)buf + offset);
ast_signature_t* dst = (ast_signature_t*)((uintptr_t)buf + (uintptr_t)offset);

dst->t = (token_signature_t*)pony_serialise_offset(ctx, ast->t);
dst->child = (ast_signature_t*)pony_serialise_offset(ctx, ast->child);
Expand All @@ -1981,6 +1981,7 @@ static pony_type_t ast_signature_pony =
sizeof(ast_signature_t),
0,
0,
0,
NULL,
NULL,
ast_signature_serialise_trace,
Expand Down Expand Up @@ -2030,12 +2031,12 @@ static void ast_nominal_pkg_id_signature_serialise_trace(pony_ctx_t* ctx,
}

static void ast_nominal_pkg_id_signature_serialise(pony_ctx_t* ctx,
void* object, void* buf, size_t offset, int mutability)
void* object, void* buf, uint64_t offset, int mutability)
{
(void)mutability;

ast_t* ast = (ast_t*)object;
ast_signature_t* dst = (ast_signature_t*)((uintptr_t)buf + offset);
ast_signature_t* dst = (ast_signature_t*)((uintptr_t)buf + (uintptr_t)offset);

ast_t* def = (ast_t*)ast_data(ast_parent(ast));
pony_assert(def != NULL);
Expand All @@ -2059,6 +2060,7 @@ static pony_type_t ast_nominal_pkg_id_signature_pony =
sizeof(ast_signature_t),
0,
0,
0,
NULL,
NULL,
ast_nominal_pkg_id_signature_serialise_trace,
Expand Down Expand Up @@ -2276,12 +2278,12 @@ static void ast_serialise_trace(pony_ctx_t* ctx, void* object)
}

static void ast_serialise(pony_ctx_t* ctx, void* object, void* buf,
size_t offset, int mutability)
uint64_t offset, int mutability)
{
(void)mutability;

ast_t* ast = (ast_t*)object;
ast_t* dst = (ast_t*)((uintptr_t)buf + offset);
ast_t* dst = (ast_t*)((uintptr_t)buf + (uintptr_t)offset);

dst->t = (token_t*)pony_serialise_offset(ctx, ast->t);
ast_serialise_data(ctx, ast, dst);
Expand Down Expand Up @@ -2321,6 +2323,7 @@ static pony_type_t ast_pony =
sizeof(ast_t),
0,
0,
0,
NULL,
NULL,
ast_serialise_trace,
Expand Down
5 changes: 3 additions & 2 deletions src/libponyc/ast/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ static void source_serialise_trace(pony_ctx_t* ctx, void* object)
}

static void source_serialise(pony_ctx_t* ctx, void* object, void* buf,
size_t offset, int mutability)
uint64_t offset, int mutability)
{
(void)mutability;

source_t* source = (source_t*)object;
source_t* dst = (source_t*)((uintptr_t)buf + offset);
source_t* dst = (source_t*)((uintptr_t)buf + (uintptr_t)offset);

dst->file = (const char*)pony_serialise_offset(ctx, (char*)source->file);
dst->m = (char*)pony_serialise_offset(ctx, source->m);
Expand All @@ -114,6 +114,7 @@ static pony_type_t source_pony =
sizeof(source_t),
0,
0,
0,
NULL,
NULL,
source_serialise_trace,
Expand Down
11 changes: 7 additions & 4 deletions src/libponyc/ast/stringtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,15 @@ void stringtab_done()
}

static void string_serialise(pony_ctx_t* ctx, void* object, void* buf,
size_t offset, int mutability)
uint64_t offset, int mutability)
{
(void)ctx;
(void)mutability;

const char* string = (const char*)object;

memcpy((void*)((uintptr_t)buf + offset), object, strlen(string) + 1);
memcpy((void*)((uintptr_t)buf + (uintptr_t)offset), object,
strlen(string) + 1);
}

static __pony_thread_local struct _pony_type_t string_pony =
Expand All @@ -134,6 +135,7 @@ static __pony_thread_local struct _pony_type_t string_pony =
0,
0,
0,
0,
NULL,
NULL,
NULL,
Expand Down Expand Up @@ -191,12 +193,12 @@ static void strlist_serialise_trace(pony_ctx_t* ctx, void* object)
}

static void strlist_serialise(pony_ctx_t* ctx, void* object, void* buf,
size_t offset, int mutability)
uint64_t offset, int mutability)
{
(void)mutability;

strlist_t* list = (strlist_t*)object;
strlist_t* dst = (strlist_t*)((uintptr_t)buf + offset);
strlist_t* dst = (strlist_t*)((uintptr_t)buf + (uintptr_t)offset);

dst->contents.data = (void*)pony_serialise_offset(ctx, list->contents.data);
dst->contents.next = (list_t*)pony_serialise_offset(ctx, list->contents.next);
Expand All @@ -219,6 +221,7 @@ static pony_type_t strlist_pony =
sizeof(strlist_t),
0,
0,
0,
NULL,
NULL,
strlist_serialise_trace,
Expand Down
5 changes: 3 additions & 2 deletions src/libponyc/ast/symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ static void symbol_serialise_trace(pony_ctx_t* ctx, void* object)
}

static void symbol_serialise(pony_ctx_t* ctx, void* object, void* buf,
size_t offset, int mutability)
uint64_t offset, int mutability)
{
(void)mutability;

symbol_t* sym = (symbol_t*)object;
symbol_t* dst = (symbol_t*)((uintptr_t)buf + offset);
symbol_t* dst = (symbol_t*)((uintptr_t)buf + (uintptr_t)offset);

dst->name = (const char*)pony_serialise_offset(ctx, (char*)sym->name);
dst->def = (ast_t*)pony_serialise_offset(ctx, sym->def);
Expand All @@ -381,6 +381,7 @@ static pony_type_t symbol_pony =
sizeof(symbol_t),
0,
0,
0,
NULL,
NULL,
symbol_serialise_trace,
Expand Down
17 changes: 11 additions & 6 deletions src/libponyc/ast/token.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,13 @@ static void token_signature_serialise_trace(pony_ctx_t* ctx, void* object)
}

static void token_signature_serialise(pony_ctx_t* ctx, void* object, void* buf,
size_t offset, int mutability)
uint64_t offset, int mutability)
{
(void)mutability;

token_t* token = (token_t*)object;
token_signature_t* dst = (token_signature_t*)((uintptr_t)buf + offset);
token_signature_t* dst = (token_signature_t*)((uintptr_t)buf +
(uintptr_t)offset);

memset(dst, 0, sizeof(token_signature_t));

Expand Down Expand Up @@ -402,6 +403,7 @@ static pony_type_t token_signature_pony =
sizeof(token_signature_t),
0,
0,
0,
NULL,
NULL,
token_signature_serialise_trace,
Expand Down Expand Up @@ -435,13 +437,14 @@ static void token_docstring_signature_serialise_trace(pony_ctx_t* ctx,
}

static void token_docstring_signature_serialise(pony_ctx_t* ctx, void* object,
void* buf, size_t offset, int mutability)
void* buf, uint64_t offset, int mutability)
{
(void)ctx;
(void)object;
(void)mutability;

token_signature_t* dst = (token_signature_t*)((uintptr_t)buf + offset);
token_signature_t* dst = (token_signature_t*)((uintptr_t)buf +
(uintptr_t)offset);

memset(dst, 0, sizeof(token_signature_t));

Expand All @@ -454,6 +457,7 @@ static pony_type_t token_docstring_signature_pony =
sizeof(token_signature_t),
0,
0,
0,
NULL,
NULL,
token_docstring_signature_serialise_trace,
Expand Down Expand Up @@ -486,12 +490,12 @@ static void token_serialise_trace(pony_ctx_t* ctx, void* object)
}

static void token_serialise(pony_ctx_t* ctx, void* object, void* buf,
size_t offset, int mutability)
uint64_t offset, int mutability)
{
(void)mutability;

token_t* token = (token_t*)object;
token_t* dst = (token_t*)((uintptr_t)buf + offset);
token_t* dst = (token_t*)((uintptr_t)buf + (uintptr_t)offset);

dst->id = token->id;

Expand Down Expand Up @@ -541,6 +545,7 @@ static pony_type_t token_pony =
sizeof(token_t),
0,
0,
0,
NULL,
NULL,
token_serialise_trace,
Expand Down
11 changes: 9 additions & 2 deletions src/libponyc/codegen/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ static void init_runtime(compile_t* c)
c->msg_ptr = LLVMPointerType(c->msg_type, 0);
LLVMStructSetBody(c->msg_type, params, 2, false);

// descriptor_offset_lookup
// uint32_t (*)(i64)
params[0] = c->i64;
c->descriptor_offset_lookup_type = LLVMFunctionType(c->i32, params, 1, false);
c->descriptor_offset_lookup_fn =
LLVMPointerType(c->descriptor_offset_lookup_type, 0);

// trace
// void (*)(i8*, __object*)
params[0] = c->void_ptr;
Expand All @@ -211,11 +218,11 @@ static void init_runtime(compile_t* c)
c->trace_fn = LLVMPointerType(c->trace_type, 0);

// serialise
// void (*)(i8*, __object*, i8*, intptr, i32)
// void (*)(i8*, __object*, i8*, i64, i32)
params[0] = c->void_ptr;
params[1] = c->object_ptr;
params[2] = c->void_ptr;
params[3] = c->intptr;
params[3] = c->i64;
params[4] = c->i32;
c->serialise_type = LLVMFunctionType(c->void_type, params, 5, false);
c->serialise_fn = LLVMPointerType(c->serialise_type, 0);
Expand Down
3 changes: 3 additions & 0 deletions src/libponyc/codegen/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ typedef struct compile_t
LLVMValueRef primitives_init;
LLVMValueRef primitives_final;
LLVMValueRef desc_table;
LLVMValueRef desc_table_offset_lookup_fn;
LLVMValueRef numeric_sizes;

LLVMTypeRef void_type;
Expand All @@ -199,6 +200,8 @@ typedef struct compile_t
LLVMTypeRef void_ptr;
LLVMTypeRef descriptor_type;
LLVMTypeRef descriptor_ptr;
LLVMTypeRef descriptor_offset_lookup_type;
LLVMTypeRef descriptor_offset_lookup_fn;
LLVMTypeRef field_descriptor;
LLVMTypeRef object_type;
LLVMTypeRef object_ptr;
Expand Down
Loading