-
Notifications
You must be signed in to change notification settings - Fork 85
Replace eager show with lazy pretty during analysis
#1797
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
base: master
Are you sure you want to change the base?
Changes from all commits
46f80fc
1e89a9b
31b2e1c
c2a588f
fd4bd85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,8 +42,8 @@ module ListMatrix: SparseMatrixFunctor = | |||||||||||||||||||||
| type t = V.t list (* List of rows *) | ||||||||||||||||||||||
| [@@deriving eq, ord, hash] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| let show x = | ||||||||||||||||||||||
| List.fold_left (^) "" (List.map (fun x -> (V.show x)) x) | ||||||||||||||||||||||
| let pretty = | ||||||||||||||||||||||
| GoblintCil.Pretty.(docList ~sep:nil (V.pretty ())) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| let copy m = m | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -328,7 +328,7 @@ module ListMatrix: SparseMatrixFunctor = | |||||||||||||||||||||
| let normalized_v = V.map_f_preserves_zero (fun x -> x /: value) v_after_elim in | ||||||||||||||||||||||
| Some (insert_v_according_to_piv m normalized_v idx pivot_positions) | ||||||||||||||||||||||
| in | ||||||||||||||||||||||
| if M.tracing then M.trace "rref_vec" "rref_vec: m:\n%s, v: %s => res:\n%s" (show m) (V.show v) (match res with None -> "None" | Some r -> show r); | ||||||||||||||||||||||
| if M.tracing then M.trace "rref_vec" "rref_vec: m:\n%a, v: %a => res:\n%a" pretty m V.pretty v (GoblintCil.Pretty.docOpt (pretty ())) res; | ||||||||||||||||||||||
| res | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| let rref_vec m v = timing_wrap "rref_vec" (rref_vec m) v | ||||||||||||||||||||||
|
|
@@ -422,7 +422,7 @@ module ListMatrix: SparseMatrixFunctor = | |||||||||||||||||||||
| let res = map2i (fun i x y -> if i < r then | ||||||||||||||||||||||
| V.map2_f_preserves_zero (fun u j -> u +: y *: j) x a_r | ||||||||||||||||||||||
| else x) a col_b in | ||||||||||||||||||||||
| if M.tracing then M.trace "linear_disjunct_cases" "case_two: \na:\n%s, r:%d,\n col_b: %s, a_r: %s, => res:\n%s" (show a) r (V.show col_b) (V.show a_r) (show res); | ||||||||||||||||||||||
| if M.tracing then M.trace "linear_disjunct_cases" "case_two: \na:\n%a, r:%d,\n col_b: %a, a_r: %a, => res:\n%a" pretty a r V.pretty col_b V.pretty a_r pretty res; | ||||||||||||||||||||||
| res | ||||||||||||||||||||||
| in | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -445,14 +445,14 @@ module ListMatrix: SparseMatrixFunctor = | |||||||||||||||||||||
| | [], [] -> (acclist,acc) | ||||||||||||||||||||||
| in | ||||||||||||||||||||||
| let resl,rest = sub_and_last_aux ([],None) c1 c2 in | ||||||||||||||||||||||
| if M.tracing then M.trace "linear_disjunct_cases" "sub_and_last: ridx: %d c1: %s, c2: %s, resultlist: %s, result_pivot: %s" ridx (V.show col1) (V.show col2) (String.concat "," (List.map (fun (i,v) -> Printf.sprintf "(%d,%s)" i (A.to_string v)) resl)) (match rest with None -> "None" | Some (i,v1,v2) -> Printf.sprintf "(%d,%s,%s)" i (A.to_string v1) (A.to_string v2)); | ||||||||||||||||||||||
| if M.tracing then M.trace "linear_disjunct_cases" "sub_and_last: ridx: %d c1: %a, c2: %a, resultlist: %s, result_pivot: %s" ridx V.pretty col1 V.pretty col2 (String.concat "," (List.map (fun (i,v) -> Printf.sprintf "(%d,%s)" i (A.to_string v)) resl)) (match rest with None -> "None" | Some (i,v1,v2) -> Printf.sprintf "(%d,%s,%s)" i (A.to_string v1) (A.to_string v2)); (* TODO: avoid eager arguments *) | ||||||||||||||||||||||
|
||||||||||||||||||||||
| if M.tracing then M.trace "linear_disjunct_cases" "sub_and_last: ridx: %d c1: %a, c2: %a, resultlist: %s, result_pivot: %s" ridx V.pretty col1 V.pretty col2 (String.concat "," (List.map (fun (i,v) -> Printf.sprintf "(%d,%s)" i (A.to_string v)) resl)) (match rest with None -> "None" | Some (i,v1,v2) -> Printf.sprintf "(%d,%s,%s)" i (A.to_string v1) (A.to_string v2)); (* TODO: avoid eager arguments *) | |
| if M.tracing then ( | |
| let resultlist_str = String.concat "," (List.map (fun (i,v) -> Printf.sprintf "(%d,%s)" i (A.to_string v)) resl) in | |
| let result_pivot_str = match rest with | |
| | None -> "None" | |
| | Some (i,v1,v2) -> Printf.sprintf "(%d,%s,%s)" i (A.to_string v1) (A.to_string v2) | |
| in | |
| M.trace "linear_disjunct_cases" "sub_and_last: ridx: %d c1: %a, c2: %a, resultlist: %s, result_pivot: %s" | |
| ridx V.pretty col1 V.pretty col2 resultlist_str result_pivot_str | |
| ); (* TODO: avoid eager arguments *) |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trace call has eager computation in its arguments. The A.to_string calls and rev_matrix res computation will be executed even when tracing is disabled. As noted in the TODO comment, these eager arguments should be avoided to improve performance when tracing is disabled.
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trace call has eager computation in its arguments. The rev_matrix result computation will be executed even when tracing is disabled. As noted in the TODO comment, this eager argument should be avoided to improve performance when tracing is disabled.
| if M.tracing then M.trace "linear_disjunct" "result so far: \n%a, currentrowindex: %d, currentcolindex: %d, m1: \n%a, m2:\n%a" | |
| pretty (rev_matrix result) currentrowindex currentcolindex pretty m1 pretty m2; (* TODO: avoid eager rev_matrix *) | |
| if M.tracing then ( | |
| let rev_res = rev_matrix result in | |
| M.trace "linear_disjunct" "result so far: \n%a, currentrowindex: %d, currentcolindex: %d, m1: \n%a, m2:\n%a" | |
| pretty rev_res currentrowindex currentcolindex pretty m1 pretty m2 | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
V.of_arraycall is eagerly executed for each element even when the pretty-printing may not be needed. As noted in the TODO comment, this conversion should be avoided. Consider restructuring to delay the conversion or use a more efficient approach.