From fce192be2036dac64b80f396229f2800832368d7 Mon Sep 17 00:00:00 2001 From: Denis Merigoux Date: Wed, 11 Oct 2023 09:37:36 +0200 Subject: [PATCH 1/2] Improve trace printing --- compiler/shared_ast/interpreter.ml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/compiler/shared_ast/interpreter.ml b/compiler/shared_ast/interpreter.ml index 4e1a516be..fec990110 100644 --- a/compiler/shared_ast/interpreter.ml +++ b/compiler/shared_ast/interpreter.ml @@ -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 ""; - true - | _ -> false - end) in Message.emit_log "%s%a %a: @{%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) -> @@ -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 From 74684899c8e2c665e23ab197e9cbf26eb924a119 Mon Sep 17 00:00:00 2001 From: Denis Merigoux Date: Wed, 11 Oct 2023 10:00:09 +0200 Subject: [PATCH 2/2] If you've in debug mode we can argue you want to see functions --- tests/test_scope/good/scope_call3.catala_en | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_scope/good/scope_call3.catala_en b/tests/test_scope/good/scope_call3.catala_en index 680a3b07a..db952fd07 100644 --- a/tests/test_scope/good/scope_call3.catala_en +++ b/tests/test_scope/good/scope_call3.catala_en @@ -32,7 +32,7 @@ $ catala Interpret -t -s HousingComputation --debug [DEBUG] Translating to default calculus... [DEBUG] Typechecking again... [DEBUG] Starting interpretation... -[LOG] ≔ HousingComputation.f: +[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: └─┐ @@ -47,14 +47,14 @@ $ catala Interpret -t -s HousingComputation --debug │ ‾ [LOG] → RentComputation.direct [LOG] ≔ RentComputation.direct.input: {RentComputation_in} -[LOG] ≔ RentComputation.g: -[LOG] ≔ RentComputation.f: +[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 = ; } +[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