Duplicate code detection across OCaml packages
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(lint): replace Printf/Format with Fmt in block and bpsec

+53 -60
+53 -60
lib/normalize.ml
··· 187 187 E_setfield 188 188 (convert_expr env e, longident_to_string lid, convert_expr env v) 189 189 | Pexp_array items -> E_array (List.map (convert_expr env) items) 190 - | Pexp_letop { let_; ands; body } -> 191 - (* Desugar let* x = e in body → ( let* ) e (fun x -> body) *) 192 - let let_op = E_ident let_.pbop_op.txt in 193 - let let_rhs = convert_expr env let_.pbop_exp in 194 - let ands_pre = 195 - List.map 196 - (fun bop -> 197 - ( E_ident bop.Parsetree.pbop_op.txt, 198 - convert_expr env bop.pbop_exp, 199 - bop.Parsetree.pbop_pat )) 200 - ands 201 - in 202 - (* Bind all patterns, then convert body *) 203 - let let_pat = convert_pat env let_.pbop_pat in 204 - let ands_bound = 205 - List.map 206 - (fun (op, rhs, raw_pat) -> (op, rhs, convert_pat env raw_pat)) 207 - ands_pre 208 - in 209 - let body = convert_expr env body in 210 - let body = 211 - List.fold_right 212 - (fun (op, rhs, pat) acc -> 213 - E_apply 214 - ( op, 215 - [ 216 - (Asttypes.Nolabel, rhs); 217 - ( Asttypes.Nolabel, 218 - E_fun 219 - ( [ Param_val (Asttypes.Nolabel, None, pat) ], 220 - Body_expr acc ) ); 221 - ] )) 222 - ands_bound body 223 - in 224 - E_apply 225 - ( let_op, 226 - [ 227 - (Asttypes.Nolabel, let_rhs); 228 - ( Asttypes.Nolabel, 229 - E_fun 230 - ([ Param_val (Asttypes.Nolabel, None, let_pat) ], Body_expr body) 231 - ); 232 - ] ) 190 + | Pexp_letop { let_; ands; body } -> convert_letop env let_ ands body 233 191 | Pexp_letmodule (_, _, e) -> convert_expr env e 234 192 | Pexp_letexception (_, e) -> convert_expr env e 235 193 | Pexp_send (e, { txt; _ }) -> E_send (convert_expr env e, txt) 236 194 | Pexp_new { txt; _ } -> E_ident (longident_to_string txt) 237 195 | _ -> E_other 196 + 197 + (* Desugar let* x = e in body → ( let* ) e (fun x -> body) *) 198 + and convert_letop env (let_ : Parsetree.binding_op) 199 + (ands : Parsetree.binding_op list) body = 200 + let let_op = E_ident let_.pbop_op.txt in 201 + let let_rhs = convert_expr env let_.pbop_exp in 202 + let ands_pre = 203 + List.map 204 + (fun bop -> 205 + ( E_ident bop.Parsetree.pbop_op.txt, 206 + convert_expr env bop.pbop_exp, 207 + bop.Parsetree.pbop_pat )) 208 + ands 209 + in 210 + let let_pat = convert_pat env let_.pbop_pat in 211 + let ands_bound = 212 + List.map 213 + (fun (op, rhs, raw_pat) -> (op, rhs, convert_pat env raw_pat)) 214 + ands_pre 215 + in 216 + let body = convert_expr env body in 217 + let mk_apply op rhs pat acc = 218 + E_apply 219 + ( op, 220 + [ 221 + (Asttypes.Nolabel, rhs); 222 + ( Asttypes.Nolabel, 223 + E_fun ([ Param_val (Asttypes.Nolabel, None, pat) ], Body_expr acc) 224 + ); 225 + ] ) 226 + in 227 + let body = 228 + List.fold_right 229 + (fun (op, rhs, pat) acc -> mk_apply op rhs pat acc) 230 + ands_bound body 231 + in 232 + mk_apply let_op let_rhs let_pat body 238 233 239 234 and convert_param env (p : Parsetree.function_param) = 240 235 match p.pparam_desc with ··· 758 753 | E_apply (f, args) -> 759 754 buf_tag buf 4; 760 755 hash_expr buf f; 761 - buf_list buf 762 - (fun (l, e) -> 763 - buf_label buf l; 764 - hash_expr buf e) 765 - args 756 + buf_list buf (hash_arg buf) args 766 757 | E_match (e, cases) -> 767 758 buf_tag buf 5; 768 759 hash_expr buf e; ··· 780 771 buf_opt buf (hash_expr buf) e 781 772 | E_record (fs, base) -> 782 773 buf_tag buf 9; 783 - buf_list buf 784 - (fun (n, e) -> 785 - buf_str buf n; 786 - hash_expr buf e) 787 - fs; 774 + buf_list buf (hash_field buf) fs; 788 775 buf_opt buf (hash_expr buf) base 789 776 | E_field (e, n) -> 790 777 buf_tag buf 10; ··· 849 836 | Body_cases cases -> 850 837 buf_tag buf 1; 851 838 buf_list buf (hash_case buf) cases 839 + 840 + and hash_arg buf (l, e) = 841 + buf_label buf l; 842 + hash_expr buf e 843 + 844 + and hash_field buf (n, e) = 845 + buf_str buf n; 846 + hash_expr buf e 852 847 853 848 and hash_case buf { cpat; guard; rhs } = 854 849 hash_pat buf cpat; ··· 1039 1034 Fmt.str "_cse%d" n 1040 1035 in 1041 1036 let rec extract e = 1042 - let sz = expr_size e in 1043 - if sz >= 2 then begin 1037 + if expr_size e < 2 then e 1038 + else 1044 1039 let h = hash e in 1045 1040 let count = try Hashtbl.find counts h with Not_found -> 0 in 1046 - if count >= 2 then ( 1041 + if count < 2 then extract_descend e 1042 + else 1047 1043 match Hashtbl.find_opt seen h with 1048 1044 | Some name -> E_ident name 1049 1045 | None -> ··· 1051 1047 let name = cse_fresh () in 1052 1048 Hashtbl.replace seen h name; 1053 1049 bindings := { bpat = P_var name; bexpr = e' } :: !bindings; 1054 - E_ident name) 1055 - else extract_descend e 1056 - end 1057 - else e 1050 + E_ident name 1058 1051 and extract_descend = function 1059 1052 | (E_ident _ | E_const _ | E_other) as e -> e 1060 1053 | E_let (rf, bs, body) ->