mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Migrate remaining exits to FATAL_*_ERROR calls (#704)
Adds FATAL for things that are most likely programming errors in executable_semantics.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
#ifndef EXECUTABLE_SEMANTICS_INTERPRETER_DICTIONARY_H_
|
||||
#define EXECUTABLE_SEMANTICS_INTERPRETER_DICTIONARY_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
@@ -34,9 +34,8 @@ void Heap::Write(const Address& a, const Value* v, int line_num) {
|
||||
|
||||
void Heap::CheckAlive(const Address& address, int line_num) {
|
||||
if (!alive_[address.index]) {
|
||||
FATAL_RUNTIME_ERROR(line_num)
|
||||
<< ": undefined behavior: access to dead value "
|
||||
<< *values_[address.index];
|
||||
FATAL_RUNTIME_ERROR(line_num) << "undefined behavior: access to dead value "
|
||||
<< *values_[address.index];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,8 +99,7 @@ auto EvalPrim(Operator op, const std::vector<const Value*>& args, int line_num)
|
||||
case Operator::Ptr:
|
||||
return global_arena->New<PointerType>(args[0]);
|
||||
case Operator::Deref:
|
||||
llvm::errs() << line_num << ": dereference not implemented yet\n";
|
||||
exit(-1);
|
||||
FATAL() << "dereference not implemented yet";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,10 +297,7 @@ auto PatternMatch(const Value* p, const Value* v, Env values,
|
||||
return values;
|
||||
}
|
||||
default:
|
||||
llvm::errs()
|
||||
<< "internal error, expected a tuple value in pattern, not " << *v
|
||||
<< "\n";
|
||||
exit(-1);
|
||||
FATAL() << "expected a tuple value in pattern, not " << *v;
|
||||
}
|
||||
case Value::Kind::AlternativeValue:
|
||||
switch (v->Tag()) {
|
||||
@@ -320,11 +316,7 @@ auto PatternMatch(const Value* p, const Value* v, Env values,
|
||||
return *matches;
|
||||
}
|
||||
default:
|
||||
llvm::errs()
|
||||
<< "internal error, expected a choice alternative in pattern, "
|
||||
"not "
|
||||
<< *v << "\n";
|
||||
exit(-1);
|
||||
FATAL() << "expected a choice alternative in pattern, not " << *v;
|
||||
}
|
||||
case Value::Kind::FunctionType:
|
||||
switch (v->Tag()) {
|
||||
@@ -377,11 +369,7 @@ void PatternAssignment(const Value* pat, const Value* val, int line_num) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
llvm::errs()
|
||||
<< "internal error, expected a tuple value on right-hand-side, "
|
||||
"not "
|
||||
<< *val << "\n";
|
||||
exit(-1);
|
||||
FATAL() << "expected a tuple value on right-hand-side, not " << *val;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -397,11 +385,7 @@ void PatternAssignment(const Value* pat, const Value* val, int line_num) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
llvm::errs()
|
||||
<< "internal error, expected an alternative in left-hand-side, "
|
||||
"not "
|
||||
<< *val << "\n";
|
||||
exit(-1);
|
||||
FATAL() << "expected an alternative in left-hand-side, not " << *val;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -428,8 +412,7 @@ void StepLvalue() {
|
||||
CurrentEnv(state).Get(exp->GetIdentifierExpression().name);
|
||||
if (!pointer) {
|
||||
FATAL_RUNTIME_ERROR(exp->line_num)
|
||||
<< ": could not find `" << exp->GetIdentifierExpression().name
|
||||
<< "`";
|
||||
<< "could not find `" << exp->GetIdentifierExpression().name << "`";
|
||||
}
|
||||
const Value* v = global_arena->New<PointerValue>(*pointer);
|
||||
frame->todo.Pop();
|
||||
@@ -610,8 +593,7 @@ void StepExp() {
|
||||
CurrentEnv(state).Get(exp->GetIdentifierExpression().name);
|
||||
if (!pointer) {
|
||||
FATAL_RUNTIME_ERROR(exp->line_num)
|
||||
<< ": could not find `" << exp->GetIdentifierExpression().name
|
||||
<< "`";
|
||||
<< "could not find `" << exp->GetIdentifierExpression().name << "`";
|
||||
}
|
||||
const Value* pointee = state->heap.Read(*pointer, exp->line_num);
|
||||
frame->todo.Pop(1);
|
||||
@@ -670,8 +652,7 @@ void StepExp() {
|
||||
frame->todo.Pop(1);
|
||||
CallFunction(exp->line_num, act->results, state);
|
||||
} else {
|
||||
llvm::errs() << "internal error in handle_value with Call\n";
|
||||
exit(-1);
|
||||
FATAL() << "in handle_value with Call pos " << act->pos;
|
||||
}
|
||||
break;
|
||||
case ExpressionKind::IntTypeLiteral: {
|
||||
|
||||
@@ -82,8 +82,7 @@ auto ReifyType(const Value* t, int line_num) -> const Expression* {
|
||||
return Expression::MakeIdentifierExpression(
|
||||
0, cast<VariableType>(*t).Name());
|
||||
default:
|
||||
llvm::errs() << line_num << ": expected a type, not " << *t << "\n";
|
||||
exit(-1);
|
||||
FATAL() << "expected a type, not " << *t;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,10 +116,9 @@ auto ArgumentDeduction(int line_num, TypeEnv deduced, const Value* param,
|
||||
}
|
||||
for (size_t i = 0; i < param_tup.Elements().size(); ++i) {
|
||||
if (param_tup.Elements()[i].name != arg_tup.Elements()[i].name) {
|
||||
std::cerr << line_num << ": mismatch in tuple names, "
|
||||
<< param_tup.Elements()[i].name
|
||||
<< " != " << arg_tup.Elements()[i].name << std::endl;
|
||||
exit(-1);
|
||||
FATAL_COMPILATION_ERROR(line_num)
|
||||
<< "mismatch in tuple names, " << param_tup.Elements()[i].name
|
||||
<< " != " << arg_tup.Elements()[i].name;
|
||||
}
|
||||
deduced =
|
||||
ArgumentDeduction(line_num, deduced, param_tup.Elements()[i].value,
|
||||
@@ -173,10 +171,7 @@ auto ArgumentDeduction(int line_num, TypeEnv deduced, const Value* param,
|
||||
case Value::Kind::BindingPlaceholderValue:
|
||||
case Value::Kind::AlternativeConstructorValue:
|
||||
case Value::Kind::ContinuationValue:
|
||||
llvm::errs() << line_num
|
||||
<< ": internal error in ArgumentDeduction: expected type, "
|
||||
<< "not value " << *param << "\n";
|
||||
exit(-1);
|
||||
FATAL() << "In ArgumentDeduction: expected type, not value " << *param;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,9 +223,7 @@ auto Substitute(TypeEnv dict, const Value* type) -> const Value* {
|
||||
case Value::Kind::BindingPlaceholderValue:
|
||||
case Value::Kind::AlternativeConstructorValue:
|
||||
case Value::Kind::ContinuationValue:
|
||||
llvm::errs() << "internal error in Substitute: expected type, "
|
||||
<< "not value " << *type << "\n";
|
||||
exit(-1);
|
||||
FATAL() << "In Substitute: expected type, not value " << *type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,11 +440,9 @@ auto TypeCheckExp(const Expression* e, TypeEnv types, Env values)
|
||||
// TODO: change the following to a CHECK once the real checking
|
||||
// has been added to the type checking of function signatures.
|
||||
if (!deduced_args.Get(deduced_param.name)) {
|
||||
std::cerr << e->line_num
|
||||
<< ": error, could not deduce type argument for type "
|
||||
"parameter "
|
||||
<< deduced_param.name << std::endl;
|
||||
exit(-1);
|
||||
FATAL_COMPILATION_ERROR(e->line_num)
|
||||
<< "could not deduce type argument for type parameter "
|
||||
<< deduced_param.name;
|
||||
}
|
||||
}
|
||||
parameter_type = Substitute(deduced_args, parameter_type);
|
||||
|
||||
@@ -81,8 +81,7 @@ auto GetMember(const Value* v, const std::string& f, int line_num)
|
||||
return global_arena->New<AlternativeConstructorValue>(f, choice.Name());
|
||||
}
|
||||
default:
|
||||
llvm::errs() << "field access not allowed for value " << *v << "\n";
|
||||
exit(-1);
|
||||
FATAL() << "field access not allowed for value " << *v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,8 +125,7 @@ auto SetFieldImpl(const Value* value,
|
||||
return global_arena->New<TupleValue>(elements);
|
||||
}
|
||||
default:
|
||||
llvm::errs() << "field access not allowed for value " << *value << "\n";
|
||||
exit(-1);
|
||||
FATAL() << "field access not allowed for value " << *value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,10 +343,9 @@ auto TypeEqual(const Value* t1, const Value* t2) -> bool {
|
||||
case Value::Kind::VariableType:
|
||||
return cast<VariableType>(*t1).Name() == cast<VariableType>(*t2).Name();
|
||||
default:
|
||||
llvm::errs() << "TypeEqual used to compare non-type values\n"
|
||||
<< *t1 << "\n"
|
||||
<< *t2 << "\n";
|
||||
exit(-1);
|
||||
FATAL() << "TypeEqual used to compare non-type values\n"
|
||||
<< *t1 << "\n"
|
||||
<< *t2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,7 +390,6 @@ auto ValueEqual(const Value* v1, const Value* v2, int line_num) -> bool {
|
||||
case Value::Kind::TupleValue:
|
||||
return FieldsValueEqual(cast<TupleValue>(*v1).Elements(),
|
||||
cast<TupleValue>(*v2).Elements(), line_num);
|
||||
default:
|
||||
case Value::Kind::IntType:
|
||||
case Value::Kind::BoolType:
|
||||
case Value::Kind::TypeType:
|
||||
@@ -403,14 +399,14 @@ auto ValueEqual(const Value* v1, const Value* v2, int line_num) -> bool {
|
||||
case Value::Kind::StructType:
|
||||
case Value::Kind::ChoiceType:
|
||||
case Value::Kind::ContinuationType:
|
||||
case Value::Kind::VariableType:
|
||||
return TypeEqual(v1, v2);
|
||||
case Value::Kind::StructValue:
|
||||
case Value::Kind::AlternativeValue:
|
||||
case Value::Kind::BindingPlaceholderValue:
|
||||
case Value::Kind::AlternativeConstructorValue:
|
||||
case Value::Kind::ContinuationValue:
|
||||
llvm::errs() << "ValueEqual does not support this kind of value.\n";
|
||||
exit(-1);
|
||||
FATAL() << "ValueEqual does not support this kind of value: " << *v1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user