Explorer: make pattern match trace consistent (#3093)

Makes the trace output for pattern match more consistent with the rest
of the trace by using `Match()` and `Indent()` prefix methods and
wrapping the code in the trace with backticks.
This commit is contained in:
Prabhat Sachdeva
2023-08-12 00:02:41 +00:00
committed by GitHub
parent 9228487d46
commit da35a9806a
4 changed files with 21 additions and 19 deletions
+5 -3
View File
@@ -61,9 +61,11 @@ auto PatternMatch(Nonnull<const Value*> p, ExpressionResult v,
BindingMap& generic_args, Nonnull<TraceStream*> trace_stream,
Nonnull<Arena*> arena) -> bool {
if (trace_stream->is_enabled()) {
*trace_stream << "match pattern " << *p << "\nfrom "
<< ExpressionCategoryToString(v.expression_category())
<< " expression with value " << *v.value() << "\n";
trace_stream->Match() << "match pattern `" << *p << "`\n";
trace_stream->Indent() << "from "
<< ExpressionCategoryToString(
v.expression_category())
<< " expression with value `" << *v.value() << "`\n";
}
const auto make_expr_result =
[](Nonnull<const Value*> v) -> ExpressionResult {
+2 -2
View File
@@ -272,8 +272,8 @@ fn Main() -> i32 {
// CHECK:STDOUT: <[] stack-pop: ValueExpressionAction pos: 1 `Main` results: [`fun<Main>`] (<Main()>:0)
// CHECK:STDOUT: ->> step ExpressionAction pos: 1 `Main()` results: [`fun<Main>`] scope: [] (<Main()>:0) --->
// CHECK:STDOUT: -() calling function: fun<Main>
// CHECK:STDOUT: match pattern ()
// CHECK:STDOUT: from value expression with value ()
// CHECK:STDOUT: === match pattern `()`
// CHECK:STDOUT: from value expression with value `()`
// CHECK:STDOUT: >[] stack-push: ScopeAction pos: 0 scope: [] (None)
// CHECK:STDOUT: >[] stack-push: StatementAction pos: 0 `{return 0;}` (context_main.carbon:11)
// CHECK:STDOUT: ->> step StatementAction pos: 0 `{return 0;}` (context_main.carbon:11) --->
+8 -8
View File
@@ -490,8 +490,8 @@ fn Main() -> i32 {
// CHECK:STDOUT: <[] stack-pop: ValueExpressionAction pos: 1 `Main` results: [`fun<Main>`] (<Main()>:0)
// CHECK:STDOUT: ->> step ExpressionAction pos: 1 `Main()` results: [`fun<Main>`] scope: [] (<Main()>:0) --->
// CHECK:STDOUT: -() calling function: fun<Main>
// CHECK:STDOUT: match pattern ()
// CHECK:STDOUT: from value expression with value ()
// CHECK:STDOUT: === match pattern `()`
// CHECK:STDOUT: from value expression with value `()`
// CHECK:STDOUT: >[] stack-push: ScopeAction pos: 0 scope: [] (None)
// CHECK:STDOUT: >[] stack-push: StatementAction pos: 0 `{var x: i32 = N.Foo(0);return x;}` (phase_all.carbon:18)
// CHECK:STDOUT: ->> step StatementAction pos: 0 `{var x: i32 = N.Foo(0);return x;}` (phase_all.carbon:18) --->
@@ -528,10 +528,10 @@ fn Main() -> i32 {
// CHECK:STDOUT: <[] stack-pop: ExpressionAction pos: 0 `0` (phase_all.carbon:16)
// CHECK:STDOUT: ->> step ExpressionAction pos: 2 `N.Foo(0)` results: [`fun<N.Foo>`, `0`] scope: [] (phase_all.carbon:16) --->
// CHECK:STDOUT: -() calling function: fun<N.Foo>
// CHECK:STDOUT: match pattern (Placeholder<n>,)
// CHECK:STDOUT: from value expression with value (0,)
// CHECK:STDOUT: match pattern Placeholder<n>
// CHECK:STDOUT: from value expression with value 0
// CHECK:STDOUT: === match pattern `(Placeholder<n>,)`
// CHECK:STDOUT: from value expression with value `(0,)`
// CHECK:STDOUT: === match pattern `Placeholder<n>`
// CHECK:STDOUT: from value expression with value `0`
// CHECK:STDOUT: >[] stack-push: ScopeAction pos: 0 scope: [`n: i32`: `0`] (None)
// CHECK:STDOUT: >[] stack-push: StatementAction pos: 0 `{return (n + 1);}` (phase_all.carbon:13)
// CHECK:STDOUT: ->> step StatementAction pos: 0 `{return (n + 1);}` (phase_all.carbon:13) --->
@@ -597,8 +597,8 @@ fn Main() -> i32 {
// CHECK:STDOUT: var x: i32 = N.Foo(0);
// CHECK:STDOUT: ```
// CHECK:STDOUT: <-- memory-read: #1 `1`
// CHECK:STDOUT: match pattern Placeholder<x>
// CHECK:STDOUT: from initializing expression with value 1
// CHECK:STDOUT: === match pattern `Placeholder<x>`
// CHECK:STDOUT: from initializing expression with value `1`
// CHECK:STDOUT: <[] stack-pop: StatementAction pos: 1 `var x: i32 = N.Foo(0);` results: [`1`] (phase_all.carbon:16)
// CHECK:STDOUT: ->> step StatementAction pos: 1 `{var x: i32 = N.Foo(0);return x;}` scope: [`x: i32`: `lval<Allocation(1)>`] (phase_all.carbon:18) --->
// CHECK:STDOUT: *** statement at (phase_all.carbon:18)
+6 -6
View File
@@ -56,8 +56,8 @@ fn Main() -> i32 {
// CHECK:STDOUT: <[] stack-pop: ValueExpressionAction pos: 1 `Main` results: [`fun<Main>`] (<Main()>:0)
// CHECK:STDOUT: ->> step ExpressionAction pos: 1 `Main()` results: [`fun<Main>`] scope: [] (<Main()>:0) --->
// CHECK:STDOUT: -() calling function: fun<Main>
// CHECK:STDOUT: match pattern ()
// CHECK:STDOUT: from value expression with value ()
// CHECK:STDOUT: === match pattern `()`
// CHECK:STDOUT: from value expression with value `()`
// CHECK:STDOUT: >[] stack-push: ScopeAction pos: 0 scope: [] (None)
// CHECK:STDOUT: >[] stack-push: StatementAction pos: 0 `{var x: T = {}.(interface ImplicitAs(T = class T).Convert)();return 0;}` (phase_execution.carbon:12)
// CHECK:STDOUT: ->> step StatementAction pos: 0 `{var x: T = {}.(interface ImplicitAs(T = class T).Convert)();return 0;}` (phase_execution.carbon:12) --->
@@ -106,8 +106,8 @@ fn Main() -> i32 {
// CHECK:STDOUT: <[] stack-pop: ValueExpressionAction pos: 1 `{}.(interface ImplicitAs(T = class T).Convert)` results: [`bound_method<Convert>`] (phase_execution.carbon:10)
// CHECK:STDOUT: ->> step ExpressionAction pos: 1 `{}.(interface ImplicitAs(T = class T).Convert)()` results: [`bound_method<Convert>`] scope: [] (phase_execution.carbon:10) --->
// CHECK:STDOUT: -() calling function: bound_method<Convert>
// CHECK:STDOUT: match pattern ()
// CHECK:STDOUT: from value expression with value ()
// CHECK:STDOUT: === match pattern `()`
// CHECK:STDOUT: from value expression with value `()`
// CHECK:STDOUT: >[] stack-push: ScopeAction pos: 0 scope: [`self: Self`: `{}`] (None)
// CHECK:STDOUT: >[] stack-push: StatementAction pos: 0 `{return __intrinsic_implicit_as_convert(self, U);}` (prelude.carbon:{{\d+}})
// CHECK:STDOUT: ->> step StatementAction pos: 0 `{return __intrinsic_implicit_as_convert(self, U);}` (prelude.carbon:{{\d+}}) --->
@@ -173,8 +173,8 @@ fn Main() -> i32 {
// CHECK:STDOUT: var x: T = {}.(interface ImplicitAs(T = class T).Convert)();
// CHECK:STDOUT: ```
// CHECK:STDOUT: <-- memory-read: #1 `T{}`
// CHECK:STDOUT: match pattern Placeholder<x>
// CHECK:STDOUT: from initializing expression with value T{}
// CHECK:STDOUT: === match pattern `Placeholder<x>`
// CHECK:STDOUT: from initializing expression with value `T{}`
// CHECK:STDOUT: <[] stack-pop: StatementAction pos: 1 `var x: T = {}.(interface ImplicitAs(T = class T).Convert)();` results: [`T{}`] (phase_execution.carbon:10)
// CHECK:STDOUT: ->> step StatementAction pos: 1 `{var x: T = {}.(interface ImplicitAs(T = class T).Convert)();return 0;}` scope: [`x: T`: `lval<Allocation(1)>`] (phase_execution.carbon:12) --->
// CHECK:STDOUT: *** statement at (phase_execution.carbon:12)