mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add TupleValue::Empty for the common empty tuple case (#708)
This commit is contained in:
@@ -759,8 +759,7 @@ void StepPattern() {
|
||||
if (act->pos == 0) {
|
||||
if (tuple.Fields().empty()) {
|
||||
frame->todo.Pop(1);
|
||||
frame->todo.Push(Action::MakeValAction(
|
||||
global_arena->New<TupleValue>(std::vector<TupleElement>())));
|
||||
frame->todo.Push(Action::MakeValAction(&TupleValue::Empty()));
|
||||
} else {
|
||||
const Pattern* p1 = tuple.Fields()[0].pattern;
|
||||
frame->todo.Push(Action::MakePatternAction(p1));
|
||||
|
||||
@@ -855,8 +855,7 @@ auto TypeCheckFunDef(const FunctionDefinition* f, TypeEnv types, Env values)
|
||||
// TODO: Check that main doesn't have any parameters.
|
||||
}
|
||||
auto res = TypeCheckStmt(f->body, param_res.types, values, return_type);
|
||||
bool void_return = TypeEqual(
|
||||
return_type, global_arena->New<TupleValue>(std::vector<TupleElement>()));
|
||||
bool void_return = TypeEqual(return_type, &TupleValue::Empty());
|
||||
auto body = CheckOrEnsureReturn(res.stmt, void_return, f->line_num);
|
||||
return global_arena->New<FunctionDefinition>(
|
||||
f->line_num, f->name, f->deduced_parameters, f->param_pattern,
|
||||
|
||||
@@ -233,6 +233,12 @@ class AlternativeValue : public Value {
|
||||
// A function value.
|
||||
class TupleValue : public Value {
|
||||
public:
|
||||
// An empty tuple, also known as the unit type.
|
||||
static const TupleValue& Empty() {
|
||||
static const TupleValue empty = TupleValue(std::vector<TupleElement>());
|
||||
return empty;
|
||||
}
|
||||
|
||||
explicit TupleValue(std::vector<TupleElement> elements)
|
||||
: Value(Kind::TupleValue), elements(std::move(elements)) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user