Skip to content

Commit

Permalink
Improve trace printing (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr authored Oct 17, 2023
2 parents 4f22f41 + 7468489 commit 7141734
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
20 changes: 6 additions & 14 deletions compiler/shared_ast/interpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,16 @@ let propagate_empty_error_list elist f =
let indent_str = ref ""

(** {1 Evaluation} *)
let print_log entry infos pos e =
let print_log lang entry infos pos e =
if Cli.globals.trace then
match entry with
| VarDef _ ->
let module Printer = Print.ExprGen (struct
include Print.ExprConciseParam

let bypass : type a. Format.formatter -> (a, 't) gexpr -> bool =
fun ppf e ->
match e with
| EAbs _, _ ->
Print.op_style ppf "<function>";
true
| _ -> false
end) in
Message.emit_log "%s%a %a: @{<green>%s@}" !indent_str Print.log_entry
entry Print.uid_list infos
(Message.unformat (fun ppf -> Printer.expr ppf e))
(Message.unformat (fun ppf ->
(if Cli.globals.debug then Print.expr ~debug:true ()
else Print.UserFacing.expr lang)
ppf e))
| PosRecordIfTrueBool -> (
match pos <> Pos.no_pos, Mark.remove e with
| true, ELit (LBool true) ->
Expand Down Expand Up @@ -203,7 +195,7 @@ let rec evaluate_operator
| Length, [(EArray es, _)] ->
ELit (LInt (Runtime.integer_of_int (List.length es)))
| Log (entry, infos), [e'] ->
print_log entry infos pos e';
print_log lang entry infos pos e';
Mark.remove e'
| (FromClosureEnv | ToClosureEnv), [e'] ->
(* [FromClosureEnv] and [ToClosureEnv] are just there to bypass the need for
Expand Down
8 changes: 4 additions & 4 deletions tests/test_scope/good/scope_call3.catala_en
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $ catala Interpret -t -s HousingComputation --debug
[DEBUG] Translating to default calculus...
[DEBUG] Typechecking again...
[DEBUG] Starting interpretation...
[LOG] ≔ HousingComputation.f: <function>
[LOG] ≔ HousingComputation.f: λ (x_90: integer) → error_empty ⟨#{☛ } true ⊢ (let result_91 : RentComputation = (#{→ RentComputation.direct} (λ (RentComputation_in_92: RentComputation_in) → let g_93 : integer → integer = #{≔ RentComputation.g} (λ (x1_94: integer) → error_empty ⟨#{☛ } true ⊢ x1_94 +! 1⟩) in let f_95 : integer → integer = #{≔ RentComputation.f} (λ (x1_96: integer) → error_empty ⟨#{☛ } true ⊢ #{← RentComputation.g} #{≔ RentComputation.g.output} (#{→ RentComputation.g} g_93) #{≔ RentComputation.g.input0} (x1_96 +! 1)⟩) in { RentComputation f = f_95; })) #{≔ RentComputation.direct.input} {RentComputation_in} in let result1_97 : RentComputation = { RentComputation f = λ (param0_98: integer) → #{← RentComputation.f} #{≔ RentComputation.f.output} (#{→ RentComputation.f} result_91.f) #{≔ RentComputation.f.input0} param0_98; } in #{← RentComputation.direct} #{≔ RentComputation.direct.output} if #{☛ RentComputation.direct.output} true then result1_97 else result1_97).f x_90⟩
[LOG] ☛ Definition applied:
┌─⯈ tests/test_scope/good/scope_call3.catala_en:8.14-8.20:
└─┐
Expand All @@ -47,14 +47,14 @@ $ catala Interpret -t -s HousingComputation --debug
│ ‾
[LOG] → RentComputation.direct
[LOG] ≔ RentComputation.direct.input: {RentComputation_in}
[LOG] ≔ RentComputation.g: <function>
[LOG] ≔ RentComputation.f: <function>
[LOG] ≔ RentComputation.g: λ (x_99: integer) → error_empty ⟨#{☛ } true ⊢ x_99 +! 1⟩
[LOG] ≔ RentComputation.f: λ (x_100: integer) → error_empty ⟨#{☛ } true ⊢ #{← RentComputation.g} #{≔ RentComputation.g.output} (#{→ RentComputation.g} (λ (x1_101: integer) → error_empty ⟨#{☛ } true ⊢ x1_101 +! 1⟩)) #{≔ RentComputation.g.input0} (x_100 +! 1)⟩
[LOG] ☛ Definition applied:
┌─⯈ tests/test_scope/good/scope_call3.catala_en:7.29-7.54:
└─┐
7 │ definition f of x equals (output of RentComputation).f of x
│ ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
[LOG] ≔ RentComputation.direct.output: { RentComputation f = <function>; }
[LOG] ≔ RentComputation.direct.output: { RentComputation f = λ (param0_102: integer) → #{← RentComputation.f} #{≔ RentComputation.f.output} (#{→ RentComputation.f} { RentComputation f = λ (x_103: integer) → error_empty ⟨#{☛ } true ⊢ #{← RentComputation.g} #{≔ RentComputation.g.output} (#{→ RentComputation.g} (λ (x1_104: integer) → error_empty ⟨#{☛ } true ⊢ x1_104 +! 1⟩)) #{≔ RentComputation.g.input0} (x_103 +! 1)⟩; }.f) #{≔ RentComputation.f.input0} param0_102; }
[LOG] ← RentComputation.direct
[LOG] → RentComputation.f
[LOG] ≔ RentComputation.f.input0: 1
Expand Down

0 comments on commit 7141734

Please sign in to comment.