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

one more misalignment #24

Closed
wants to merge 4 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
1 change: 0 additions & 1 deletion src/library/compiler/csimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,6 @@ class csimp_fn {
expr visit_lambda(expr e, bool is_join_point_def, bool top) {
lean_assert(is_lambda(e));
lean_assert(!top || m_fvars.size() == 0);
lean_assert(!top || !already_simplified(e));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leodemoura It's not clear to me why this one doesn't hold

Copy link
Member

@leodemoura leodemoura Jul 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look. What is it holding before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I investigated this issue. This assertion does not hold anymore.
A few months ago, I added the following function that combines csimp, cse and dead let elimination in a loop until no further simplifications are possible. I reuse the simplifier object. Thus, an expression may be top-level and have already been simplified in the previous iteration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (already_simplified(e))
return e;
buffer<expr> binding_fvars;
Expand Down
12 changes: 12 additions & 0 deletions src/library/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ Authors: Leonardo de Moura, Gabriel Ebner, Sebastian Ullrich
#include "library/time_task.h"
#include "library/util.h"

#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#include <sanitizer/lsan_interface.h>
#endif
#endif

namespace lean {
// manually padded to multiple of word size, see `initialize_module`
static char const * g_olean_header = "oleanfile!!!!!!!";
Expand Down Expand Up @@ -82,6 +88,12 @@ extern "C" object * lean_read_module_data(object * fname, object * w) {
in.close();
/* We don't free compacted_region objects */
compacted_region * region = new compacted_region(size - header_size, buffer);
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
// do not report as leak
__lsan_ignore_object(region);
#endif
#endif
object * mod = region->read();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment. I'd like to add sanitized builds to our CI in the future so that we immediately become aware of such problems.

return set_io_result(w, mod);
} catch (exception & ex) {
Expand Down
21 changes: 14 additions & 7 deletions src/runtime/compact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ Author: Leonardo de Moura
namespace lean {
#define TERMINATOR_ID (static_cast<unsigned>(object_kind::External) + 1)

// special object that terminates the data block constructing the object graph rooted in `m_value`
struct terminator_object : public object {
object * m_value;

explicit terminator_object(object * value) : object(object_kind::External, object_memory_kind::Region), m_value(value) {
// not an actual `object_kind`, so write to the field directly
m_kind = TERMINATOR_ID;
}
};

object_compactor::object_compactor():
m_begin(malloc(LEAN_COMPACTOR_INIT_SZ)),
m_end(m_begin),
Expand Down Expand Up @@ -60,11 +70,8 @@ object_offset object_compactor::to_offset(object * o) {
}

void object_compactor::insert_terminator(object * o) {
void * mem = alloc(sizeof(object) + sizeof(object*));
object * r = new (mem) object(object_kind::External, object_memory_kind::Region);
r->m_kind = TERMINATOR_ID;
object** ptr = reinterpret_cast<object**>(reinterpret_cast<char*>(r) + sizeof(object));
*ptr = to_offset(o);
void * mem = alloc(sizeof(terminator_object));
new (mem) terminator_object(to_offset(o));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this modification?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old ptr was misaligned. Using a struct for the two datums implicitly fixes the alignment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, sizeof(object) was not a multiple of 8, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly

}

object * object_compactor::copy_object(object * o) {
Expand Down Expand Up @@ -296,8 +303,8 @@ object * compacted_region::read() {
lean_assert(static_cast<char*>(m_next) + sizeof(object) <= m_end);
object * curr = reinterpret_cast<object*>(m_next);
if (curr->m_kind == TERMINATOR_ID) {
object * r = *reinterpret_cast<object**>(static_cast<char*>(m_next) + sizeof(object));
move(sizeof(object) + sizeof(object*));
object * r = reinterpret_cast<terminator_object*>(m_next)->m_value;
move(sizeof(terminator_object));
return fix_object_ptr(r);
} else {
switch (get_kind(curr)) {
Expand Down
8 changes: 3 additions & 5 deletions src/runtime/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ static inline void free_heap_obj_core(object * o) {
#endif
#ifdef LEAN_FAKE_FREE
// Set kinds to invalid values, which should trap any further accesses in debug mode.
// Make sure object kind is recoverable for printing deleted objects
if (o->m_mem_kind != 42) {
o->m_kind = -o->m_kind;
o->m_mem_kind = 42;
}
lean_always_assert(o->m_kind != 42);
o->m_kind = 42;
o->m_mem_kind = 42;
#else
#ifdef LEAN_SMALL_ALLOCATOR
dealloc(reinterpret_cast<char *>(o) - sizeof(rc_type), sz);
Expand Down