Skip to content
Myr

Simplify definition of block_bind_referenced

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Muh Muhten · committed by Nico Williams · parent 88e1f59 · Browse files · 1 file+8 added−41 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−41 removed

  • other:+8 added−41 removed

1 file+8 added−41 removed

modified:src/compile.c+8 added-41 removed
315 unmodified lines
316 }317 return args;318}319320static int block_count_refs(block binder, block body) {321 int nrefs = 0;322 for (inst* i = body.first; i; i = i->next) {323 if (i != binder.first && i->bound_by == binder.first) {324 nrefs++;325 }326 // counting recurses into closures327 nrefs += block_count_refs(binder, i->subfn);328 // counting recurses into argument list329 nrefs += block_count_refs(binder, i->arglist);330 }331 return nrefs;332}333320static int block_bind_subblock_inner(int* any_unbound, block binder, block body, int bindflags, int break_distance) {321 assert(block_is_single(binder));322 assert((opcode_describe(binder.first->op)->flags & bindflags) == (bindflags & ~OP_BIND_WILDCARD));323 assert(binder.first->symbol);
95 unmodified lines
419 free(matchname);420 return body; // We don't return a join because we don't want those sticking around...421}422437// Bind binder to body and throw away any defs in binder not referenced438// (directly or indirectly) from body.423// Bind binder to body, then throw it away if not referenced.424block block_bind_referenced(block binder, block body, int bindflags) {425 assert(block_is_single(binder));426 assert(block_has_only_binders(binder, bindflags));427 bindflags |= OP_HAS_BINDING;442 block refd = gen_noop();443 block unrefd = gen_noop();444 int nrefs;445 for (int last_kept = 0, kept = 0; ; ) {446 for (inst* curr; (curr = block_take(&binder));) {447 block b = inst_block(curr);448 nrefs = block_bind_each(b, body, bindflags);449 // Check if this binder is referenced from any of the ones we450 // already know are referenced by body.451 nrefs += block_count_refs(b, refd);452 nrefs += block_count_refs(b, body);453 if (nrefs) {454 refd = BLOCK(refd, b);455 kept++;456 } else {457 unrefd = BLOCK(unrefd, b);458 }459 }460 if (kept == last_kept)461 break;462 last_kept = kept;463 binder = unrefd;464 unrefd = gen_noop();428429 if (block_bind_subblock(binder, body, bindflags, 0) == 0) {430 block_free(binder);431 } else {432 body = BLOCK(binder, body);433 }466 block_free(unrefd);467 return block_join(refd, body);434 return body;435}436437static void block_mark_referenced(block body) {438 int saw_top = 0;
944 unmodified lines