mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 20:44:53 +01:00
Drop CopyVal (#895)
Values are immutable, so they should never need to be copied.
This commit is contained in:
@@ -223,7 +223,7 @@ auto Interpreter::PatternMatch(Nonnull<const Value*> p, Nonnull<const Value*> v,
|
||||
const auto& placeholder = cast<BindingPlaceholderValue>(*p);
|
||||
Env values(arena);
|
||||
if (placeholder.name().has_value()) {
|
||||
Address a = heap.AllocateValue(CopyVal(arena, v, source_loc));
|
||||
Address a = heap.AllocateValue(v);
|
||||
values.Set(*placeholder.name(), a);
|
||||
}
|
||||
return values;
|
||||
@@ -329,8 +329,7 @@ void Interpreter::PatternAssignment(Nonnull<const Value*> pat,
|
||||
SourceLocation source_loc) {
|
||||
switch (pat->kind()) {
|
||||
case Value::Kind::PointerValue:
|
||||
heap.Write(cast<PointerValue>(*pat).value(),
|
||||
CopyVal(arena, val, source_loc), source_loc);
|
||||
heap.Write(cast<PointerValue>(*pat).value(), val, source_loc);
|
||||
break;
|
||||
case Value::Kind::TupleValue: {
|
||||
switch (val->kind()) {
|
||||
@@ -582,10 +581,8 @@ auto Interpreter::StepExp() -> Transition {
|
||||
case Value::Kind::AlternativeConstructorValue: {
|
||||
const auto& alt =
|
||||
cast<AlternativeConstructorValue>(*act->results()[0]);
|
||||
Nonnull<const Value*> arg =
|
||||
CopyVal(arena, act->results()[1], exp.source_loc());
|
||||
return Done{arena->New<AlternativeValue>(alt.alt_name(),
|
||||
alt.choice_name(), arg)};
|
||||
return Done{arena->New<AlternativeValue>(
|
||||
alt.alt_name(), alt.choice_name(), act->results()[1])};
|
||||
}
|
||||
case Value::Kind::FunctionValue:
|
||||
return CallFunction{
|
||||
@@ -937,9 +934,7 @@ auto Interpreter::StepStmt() -> Transition {
|
||||
} else {
|
||||
// { {v :: return [] :: C, E, F} :: {C', E', F'} :: S, H}
|
||||
// -> { {v :: C', E', F'} :: S, H}
|
||||
Nonnull<const Value*> ret_val =
|
||||
CopyVal(arena, act->results()[0], stmt.source_loc());
|
||||
return UnwindFunctionCall{ret_val};
|
||||
return UnwindFunctionCall{act->results()[0]};
|
||||
}
|
||||
case Statement::Kind::Sequence: {
|
||||
// { { (s1,s2) :: C, E, F} :: S, H}
|
||||
|
||||
Reference in New Issue
Block a user