Skip to content

Commit

Permalink
Merge branch 'master' into pool-cleanup-block
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvanc committed Mar 3, 2017
2 parents ba28fee + b7299f6 commit 6b35cb0
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 36 deletions.
38 changes: 18 additions & 20 deletions src/libponyc/type/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,6 @@ static bool is_nominal_sub_structural(ast_t* sub, ast_t* super,
ast_t* sub_def = (ast_t*)ast_data(sub);
ast_t* super_def = (ast_t*)ast_data(super);

// Add an assumption: sub <: super
if(push_assume(sub, super, opt))
return true;

bool ret = true;

ast_t* sub_typeargs = ast_childidx(sub, 2);
Expand Down Expand Up @@ -838,7 +834,6 @@ static bool is_nominal_sub_structural(ast_t* sub, ast_t* super,
super_member = ast_sibling(super_member);
}

pop_assume();
return ret;
}

Expand Down Expand Up @@ -926,14 +921,8 @@ static bool is_entity_sub_trait(ast_t* sub, ast_t* super,
return true;
}

static bool is_struct_sub_trait(ast_t* sub, ast_t* super, check_cap_t check_cap,
errorframe_t* errorf, pass_opt_t* opt)
static bool is_struct_sub_trait(ast_t* sub, ast_t* super, errorframe_t* errorf)
{
(void)check_cap;

if(check_assume(sub, super, opt))
return true;

struct_cant_be_x(sub, super, errorf, "a trait");
return false;
}
Expand Down Expand Up @@ -995,7 +984,7 @@ static bool is_nominal_sub_trait(ast_t* sub, ast_t* super,
return is_entity_sub_trait(sub, super, check_cap, errorf, opt);

case TK_STRUCT:
return is_struct_sub_trait(sub, super, check_cap, errorf, opt);
return is_struct_sub_trait(sub, super, errorf);

case TK_TRAIT:
return is_trait_sub_trait(sub, super, check_cap, errorf, opt);
Expand All @@ -1013,28 +1002,37 @@ static bool is_nominal_sub_trait(ast_t* sub, ast_t* super,
static bool is_nominal_sub_nominal(ast_t* sub, ast_t* super,
check_cap_t check_cap, errorframe_t* errorf, pass_opt_t* opt)
{
// Add an assumption: sub <: super
if(push_assume(sub, super, opt))
return true;

// N k <: N' k'
ast_t* super_def = (ast_t*)ast_data(super);
bool ret = false;

switch(ast_id(super_def))
{
case TK_PRIMITIVE:
case TK_STRUCT:
case TK_CLASS:
case TK_ACTOR:
return is_nominal_sub_entity(sub, super, check_cap, errorf, opt);
ret = is_nominal_sub_entity(sub, super, check_cap, errorf, opt);
break;

case TK_INTERFACE:
return is_nominal_sub_interface(sub, super, check_cap, errorf, opt);
ret = is_nominal_sub_interface(sub, super, check_cap, errorf, opt);
break;

case TK_TRAIT:
return is_nominal_sub_trait(sub, super, check_cap, errorf, opt);
ret = is_nominal_sub_trait(sub, super, check_cap, errorf, opt);
break;

default: {}
default:
pony_assert(0);
}

pony_assert(0);
return false;
pop_assume();
return ret;
}

static bool is_nominal_sub_typeparam(ast_t* sub, ast_t* super,
Expand Down Expand Up @@ -1515,7 +1513,7 @@ static bool is_arrow_sub_x(ast_t* sub, ast_t* super, check_cap_t check_cap,
return false;
}

bool is_x_sub_x(ast_t* sub, ast_t* super, check_cap_t check_cap,
static bool is_x_sub_x(ast_t* sub, ast_t* super, check_cap_t check_cap,
errorframe_t* errorf, pass_opt_t* opt)
{
pony_assert(sub != NULL);
Expand Down
7 changes: 3 additions & 4 deletions src/libponyrt/actor/messageq.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ bool ponyint_messageq_push(messageq_t* q, pony_msg_t* m)
pony_msg_t* ponyint_messageq_pop(messageq_t* q)
{
pony_msg_t* tail = q->tail;
pony_msg_t* next = atomic_load_explicit(&tail->next, memory_order_acquire);
#ifdef USE_VALGRIND
ANNOTATE_HAPPENS_AFTER(&tail->next);
#endif
pony_msg_t* next = atomic_load_explicit(&tail->next, memory_order_relaxed);

if(next != NULL)
{
q->tail = next;
atomic_thread_fence(memory_order_acquire);
#ifdef USE_VALGRIND
ANNOTATE_HAPPENS_AFTER(&tail->next);
ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(tail);
#endif
ponyint_pool_free(tail->index, tail);
Expand Down
33 changes: 23 additions & 10 deletions src/libponyrt/gc/cycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,22 +675,25 @@ static void final(pony_ctx_t* ctx, pony_actor_t* self)
// Find block messages and invoke finalisers for those actors
pony_msg_t* msg;

while((msg = ponyint_messageq_pop(&self->q)) != NULL)
do
{
if(msg->id == ACTORMSG_BLOCK)
while((msg = ponyint_messageq_pop(&self->q)) != NULL)
{
block_msg_t* m = (block_msg_t*)msg;
if(msg->id == ACTORMSG_BLOCK)
{
block_msg_t* m = (block_msg_t*)msg;

if(m->delta != NULL)
ponyint_deltamap_free(m->delta);
if(m->delta != NULL)
ponyint_deltamap_free(m->delta);

if(!ponyint_actor_pendingdestroy(m->actor))
{
ponyint_actor_setpendingdestroy(m->actor);
ponyint_actor_final(ctx, m->actor);
if(!ponyint_actor_pendingdestroy(m->actor))
{
ponyint_actor_setpendingdestroy(m->actor);
ponyint_actor_final(ctx, m->actor);
}
}
}
}
} while(!ponyint_messageq_markempty(&self->q));

detector_t* d = (detector_t*)self;
size_t i = HASHMAP_BEGIN;
Expand All @@ -707,6 +710,14 @@ static void final(pony_ctx_t* ctx, pony_actor_t* self)
ponyint_actor_final(ctx, view->actor);
}
}

i = HASHMAP_BEGIN;
while((view = ponyint_viewmap_next(&d->deferred, &i)) != NULL)
ponyint_viewmap_remove(&d->deferred, view);

ponyint_viewmap_destroy(&d->deferred);
ponyint_viewmap_destroy(&d->views);
ponyint_perceivedmap_destroy(&d->perceived);
}

#ifndef NDEBUG
Expand Down Expand Up @@ -908,6 +919,8 @@ void ponyint_cycle_terminate(pony_ctx_t* ctx)
{
pony_become(ctx, cycle_detector);
final(ctx, cycle_detector);
ponyint_destroy(cycle_detector);
cycle_detector = NULL;
}

bool ponyint_is_cycle(pony_actor_t* actor)
Expand Down
8 changes: 6 additions & 2 deletions src/libponyrt/sched/mpmcq.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ void ponyint_mpmcq_push_single(mpmcq_t* q, void* data)
void* ponyint_mpmcq_pop(mpmcq_t* q)
{
#ifdef PLATFORM_IS_X86
PONY_ABA_PROTECTED_PTR(mpmcq_node_t) cmp = bigatomic_load_explicit(&q->tail,
memory_order_relaxed);
PONY_ABA_PROTECTED_PTR(mpmcq_node_t) cmp;
PONY_ABA_PROTECTED_PTR(mpmcq_node_t) xchg;
mpmcq_node_t* tail;
// Load the tail non-atomically. If object and counter are out of sync, we'll
// do an additional CAS iteration which isn't less efficient than doing an
// atomic initial load.
cmp.object = q->tail.object;
cmp.counter = q->tail.counter;
#else
mpmcq_node_t* tail = atomic_load_explicit(&q->tail, memory_order_relaxed);
#endif
Expand Down
19 changes: 19 additions & 0 deletions test/libponyc/type_check_subtype.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1033,3 +1033,22 @@ TEST_F(SubTypeTest, IsBeSubFunTag)

pass_opt_init(&opt);
}


TEST_F(SubTypeTest, IsTypeparamSubIntersect)
{
const char* src =
"class B\n"
" fun f[A: (I32 & Real[A])](a: A, b: (I32 & Real[A])) =>\n"
" None";

TEST_COMPILE(src);

pass_opt_t opt;
pass_opt_init(&opt);

ASSERT_TRUE(is_subtype(type_of("a"), type_of("b"), NULL, &opt));
ASSERT_TRUE(is_subtype(type_of("b"), type_of("a"), NULL, &opt));

pass_opt_init(&opt);
}

0 comments on commit 6b35cb0

Please sign in to comment.