More detailed traces for type checking (#760)

This commit is contained in:
Geoff Romer
2021-08-18 12:34:16 -07:00
committed by GitHub
parent c6ebe0db67
commit 2295658697
2 changed files with 21 additions and 5 deletions
@@ -31,7 +31,7 @@ extern State* state;
void InitEnv(const Declaration& d, Env* env);
void PrintStack(const Stack<Frame*>& ls, llvm::raw_ostream& out);
void PrintEnv(Env values);
void PrintEnv(Env values, llvm::raw_ostream& out);
/***** Interpreters *****/
+20 -4
View File
@@ -17,6 +17,7 @@
#include "executable_semantics/common/tracing_flag.h"
#include "executable_semantics/interpreter/interpreter.h"
#include "executable_semantics/interpreter/value.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Casting.h"
using llvm::cast;
@@ -24,6 +25,13 @@ using llvm::dyn_cast;
namespace Carbon {
void PrintTypeEnv(TypeEnv types, llvm::raw_ostream& out) {
llvm::ListSeparator sep;
for (const auto& [name, type] : types) {
out << sep << name << ": " << *type;
}
}
static void ExpectType(int line_num, const std::string& context,
const Value* expected, const Value* actual) {
if (!TypeEqual(expected, actual)) {
@@ -259,7 +267,11 @@ static auto Substitute(TypeEnv dict, const Value* type) -> const Value* {
auto TypeCheckExp(const Expression* e, TypeEnv types, Env values)
-> TCExpression {
if (tracing_output) {
llvm::outs() << "checking expression " << *e << "\n";
llvm::outs() << "checking expression " << *e << "\ntypes: ";
PrintTypeEnv(types, llvm::outs());
llvm::outs() << "\nvalues: ";
PrintEnv(values, llvm::outs());
llvm::outs() << "\n";
}
switch (e->Tag()) {
case Expression::Kind::IndexExpression: {
@@ -522,11 +534,15 @@ auto TypeCheckExp(const Expression* e, TypeEnv types, Env values)
auto TypeCheckPattern(const Pattern* p, TypeEnv types, Env values,
const Value* expected) -> TCPattern {
if (tracing_output) {
llvm::outs() << "checking pattern, ";
llvm::outs() << "checking pattern " << *p;
if (expected) {
llvm::outs() << "expecting " << *expected;
llvm::outs() << ", expecting " << *expected;
}
llvm::outs() << ", " << *p << "\n";
llvm::outs() << "\ntypes: ";
PrintTypeEnv(types, llvm::outs());
llvm::outs() << "\nvalues: ";
PrintEnv(values, llvm::outs());
llvm::outs() << "\n";
}
switch (p->Tag()) {
case Pattern::Kind::AutoPattern: {