Skip to content

Commit

Permalink
Add sanity checks to checker
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerBill committed Aug 2, 2021
1 parent c0f746a commit 9e6e769
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
3 changes: 0 additions & 3 deletions src/check_decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,9 +1171,6 @@ end:;
// NOTE(bill): Add it to the list of checked entities
if (e->flags & EntityFlag_Lazy) {
array_add(&ctx->info->entities, e);
}

if (e->flags & EntityFlag_Lazy) {
mutex_unlock(&ctx->info->lazy_mutex);
}
}
Expand Down
33 changes: 21 additions & 12 deletions src/checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5014,23 +5014,23 @@ void check_unique_package_names(Checker *c) {
}

void check_add_entities_from_queues(Checker *c) {
{
isize cap = c->info.entities.count + c->info.entity_queue.count.load(std::memory_order_relaxed);
array_reserve(&c->info.entities, cap);
for (Entity *e; mpmc_dequeue(&c->info.entity_queue, &e); /**/) {
array_add(&c->info.entities, e);
}
isize cap = c->info.entities.count + c->info.entity_queue.count.load(std::memory_order_relaxed);
array_reserve(&c->info.entities, cap);
for (Entity *e; mpmc_dequeue(&c->info.entity_queue, &e); /**/) {
array_add(&c->info.entities, e);
}
{
isize cap = c->info.definitions.count + c->info.definition_queue.count.load(std::memory_order_relaxed);
array_reserve(&c->info.definitions, cap);
for (Entity *e; mpmc_dequeue(&c->info.definition_queue, &e); /**/) {
array_add(&c->info.definitions, e);
}
}

void check_add_definitions_from_queues(Checker *c) {
isize cap = c->info.definitions.count + c->info.definition_queue.count.load(std::memory_order_relaxed);
array_reserve(&c->info.definitions, cap);
for (Entity *e; mpmc_dequeue(&c->info.definition_queue, &e); /**/) {
array_add(&c->info.definitions, e);
}
}



void check_parsed_files(Checker *c) {
#define TIME_SECTION(str) do { debugf("[Section] %s\n", str); if (build_context.show_more_timings) timings_start_section(&global_timings, str_lit(str)); } while (0)

Expand Down Expand Up @@ -5071,6 +5071,7 @@ void check_parsed_files(Checker *c) {

TIME_SECTION("add entities from packages");
check_add_entities_from_queues(c);
check_add_definitions_from_queues(c);

TIME_SECTION("check all global entities");
check_all_global_entities(c);
Expand All @@ -5090,6 +5091,7 @@ void check_parsed_files(Checker *c) {

TIME_SECTION("add entities from procedure bodies");
check_add_entities_from_queues(c);
check_add_definitions_from_queues(c);

TIME_SECTION("check scope usage");
for_array(i, c->info.files.entries) {
Expand Down Expand Up @@ -5132,6 +5134,8 @@ void check_parsed_files(Checker *c) {
}

TIME_SECTION("check for type cycles and inline cycles");
check_add_definitions_from_queues(c);

// NOTE(bill): Check for illegal cyclic type declarations
for_array(i, c->info.definitions) {
Entity *e = c->info.definitions[i];
Expand Down Expand Up @@ -5190,6 +5194,11 @@ void check_parsed_files(Checker *c) {
TIME_SECTION("check unique package names");
check_unique_package_names(c);


TIME_SECTION("sanity checks");
GB_ASSERT(c->info.entity_queue.count.load(std::memory_order_relaxed) == 0);
GB_ASSERT(c->info.definition_queue.count.load(std::memory_order_relaxed) == 0);

TIME_SECTION("type check finish");

#undef TIME_SECTION
Expand Down

0 comments on commit 9e6e769

Please sign in to comment.