diff --git a/executable_semantics/interpreter/interpreter.h b/executable_semantics/interpreter/interpreter.h index 49c813c7e3c1..c8c1190451f9 100644 --- a/executable_semantics/interpreter/interpreter.h +++ b/executable_semantics/interpreter/interpreter.h @@ -31,7 +31,7 @@ extern State* state; void InitEnv(const Declaration& d, Env* env); void PrintStack(const Stack& ls, llvm::raw_ostream& out); -void PrintEnv(Env values); +void PrintEnv(Env values, llvm::raw_ostream& out); /***** Interpreters *****/ diff --git a/executable_semantics/interpreter/typecheck.cpp b/executable_semantics/interpreter/typecheck.cpp index ed3a9ebbe2cb..85a884e9e7b2 100644 --- a/executable_semantics/interpreter/typecheck.cpp +++ b/executable_semantics/interpreter/typecheck.cpp @@ -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: {