Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #trace debugging hook #2560

Merged
merged 5 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions k-distribution/include/kframework/builtin/domains.md
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,18 @@ finishes.
syntax K ::= #logToFile(name: String, value: String) [function, functional, hook(IO.log), impure, returnsUnit, symbol]
```

Terms can also be logged to standard error in _surface syntax_, rather than as
KORE using `#trace`. This operator has similar semantics to `#logToFile` (i.e.
it returns `.K`, but prints as an impure side effect). Note that calling
`#trace` is equivalent to invoking the `kprint` tool for the first term that is
logged, which requires re-parsing the underlying K definition. Subsequent calls
do not incur this overhead again; the definition is cached.

```k
syntax K ::= #trace(value: KItem) [function, functional, hook(IO.traceTerm), impure, returnsUnit, symbol]
| #traceK(value: K) [function, functional, hook(IO.traceTerm), impure, returnsUnit, symbol]
```

### Implementation of high-level I/O streams in K

Below is an implementation of the `stream="stdin"` and `stream="stdout"`
Expand Down
1 change: 1 addition & 0 deletions k-distribution/tests/regression-new/trace/1.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar foo(34) * frob("Hello", false)
8 changes: 8 additions & 0 deletions k-distribution/tests/regression-new/trace/1.test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
foo ( 34 )
frob ( "Hello" , false )
"builtin"
bar
foo ( 2 ) * foo ( 0 )
<k>
.
</k>
8 changes: 8 additions & 0 deletions k-distribution/tests/regression-new/trace/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DEF=test
EXT=test
TESTDIR=.
KOMPILE_FLAGS=--syntax-module TEST

CHECK=2>&1 | diff -

include ../../../include/kframework/ktest.mak
14 changes: 14 additions & 0 deletions k-distribution/tests/regression-new/trace/test.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module TEST
imports DOMAINS
imports K-IO

syntax Foo ::= foo(Int)
| frob(String, Bool)

syntax Bar ::= "bar" Foo "*" Foo [format(%1%i%n%2 %3 %4)]
| "(" Bar ")" [bracket]

rule bar F1 * F2 =>
#let _ = #trace(F1) #in
(#trace(F2) ~> #trace("builtin") ~> #trace(bar foo(2) * foo(0)) ~> .K)
endmodule