compiler: delete lowered constant strings
If we lower a constant string operation in a Binary_expression,
delete the strings. This is safe because constant strings are always
newly allocated.
This is a hack to use much less memory when compiling the new
time/tzdata package, which has a file that contains the sum of over
13,000 constant strings. We don't do this for numeric expressions
because that could cause us to delete an Iota_expression.
We should have a cleaner approach to memory usage some day.
Change-Id: I0e91328633f379d227c957922e0843ce8c23c186
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/246266
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/go/expressions.cc b/go/expressions.cc
index 90f860b..7e7fb8c 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -556,7 +556,10 @@
{
// The child may have marked this expression as having an error.
if (this->classification_ == EXPRESSION_ERROR)
- return context->backend()->error_expression();
+ {
+ go_assert(saw_errors());
+ return context->backend()->error_expression();
+ }
return this->do_get_backend(context);
}
@@ -6080,6 +6083,8 @@
Type* result_type = (left->type()->named_type() != NULL
? left->type()
: right->type());
+ delete left;
+ delete right;
return Expression::make_string_typed(left_string + right_string,
result_type, location);
}
@@ -6087,6 +6092,8 @@
{
int cmp = left_string.compare(right_string);
bool r = Binary_expression::cmp_to_bool(op, cmp);
+ delete left;
+ delete right;
return Expression::make_boolean(r, location);
}
}