Prune unneeded stack versions based on a depth criteria

This commit is contained in:
Max Brunsfeld 2017-06-30 17:46:11 -07:00
parent d6579956f5
commit eccb3893eb
4 changed files with 20 additions and 2 deletions

View file

@ -2,6 +2,8 @@
static const unsigned MAX_COST_DIFFERENCE = 16 * ERROR_COST_PER_SKIPPED_TREE;
static const unsigned MAX_PUSH_COUNT_WITH_COUNT_DIFFERENCE = 24;
static const unsigned MAX_PUSH_COUNT_TO_ALLOW_MULTIPLE = 32;
static const unsigned MAX_DEPTH_TO_ALLOW_MULTIPLE = 12;
ErrorComparison error_status_compare(ErrorStatus a, ErrorStatus b, bool are_mergeable) {
if (a.count < b.count) {
@ -42,5 +44,20 @@ ErrorComparison error_status_compare(ErrorStatus a, ErrorStatus b, bool are_merg
}
}
if (a.count > 0) {
if (a.push_count > MAX_PUSH_COUNT_TO_ALLOW_MULTIPLE ||
b.push_count > MAX_PUSH_COUNT_TO_ALLOW_MULTIPLE ||
a.depth > MAX_DEPTH_TO_ALLOW_MULTIPLE ||
b.depth > MAX_DEPTH_TO_ALLOW_MULTIPLE) {
return a.depth <= b.depth ?
ErrorComparisonTakeLeft :
ErrorComparisonTakeRight;
} else {
return a.depth <= b.depth ?
ErrorComparisonPreferLeft :
ErrorComparisonPreferRight;
}
}
return ErrorComparisonNone;
}

View file

@ -16,6 +16,7 @@ typedef struct {
unsigned count;
unsigned cost;
unsigned push_count;
unsigned depth;
} ErrorStatus;
typedef enum {

View file

@ -384,6 +384,7 @@ ErrorStatus ts_stack_error_status(const Stack *self, StackVersion version) {
.cost = head->node->error_cost,
.count = head->node->error_count,
.push_count = head->push_count,
.depth = head->depth,
};
}

View file

@ -30,9 +30,8 @@ h i j k;
(program
(if_statement
(ERROR (identifier))
(ERROR (identifier) (identifier))
(identifier)
(ERROR (identifier))
(statement_block
(expression_statement
(identifier)