authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-28 00:00:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-28 00:00:35-07:00
logc37f273cb053f50bb39ec36fcfeef284adf0a342
tree778ef441e488dcb863da09f3c61861d9f78051eb
parent0965724e31666d156ca96375eee591380f3c9042

stage1: hot path for resolving types of primitives

This is an attempt to save memory when building self-hosted. before: Total bytes allocated: 5.941 GiB, deallocated: 2.259 GiB, remaining: 3.681 GiB after: Total bytes allocated: 5.933 GiB, deallocated: 2.253 GiB, remaining: 3.680 GiB

1 files changed, 14 insertions(+), 0 deletions(-)

src/analyze.cpp+14
......@@ -1490,6 +1490,20 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, ZigV
14901490}
14911491
14921492ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
1493 Error err;
1494 // Hot path for simple identifiers, to avoid unnecessary memory allocations.
1495 if (node->type == NodeTypeSymbol) {
1496 Buf *variable_name = node->data.symbol_expr.symbol;
1497 if (buf_eql_str(variable_name, "_"))
1498 goto abort_hot_path;
1499 ZigType *primitive_type;
1500 if ((err = get_primitive_type(g, variable_name, &primitive_type))) {
1501 goto abort_hot_path;
1502 } else {
1503 return primitive_type;
1504 }
1505abort_hot_path:;
1506 }
14931507 ZigValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type,
14941508 nullptr, UndefBad);
14951509 if (type_is_invalid(result->type))