@@ -538,40 +538,45 @@ end) : Ir.Backend_impl.Lowered_backend = struct
538538 let kernel_log_param = Some (" const int&" , " log_id" )
539539 let log_involves_file_management = false
540540
541- let pp_log_statement ~log_param_c_expr_doc ~base_message_literal ~args_docs =
541+ let pp_log_statement ~log_param_c_expr_doc ~base_message_literal : base ~args_docs =
542542 let open PPrint in
543543 (* Metal os_log handles newlines directly. Prefix with captured_log_prefix and log_id for
544544 consistency. *)
545- let base_message_literal =
546- let with_ = if for_log_trace_tree then " $" else " \\ n" in
547- let res = String. substr_replace_all base_message_literal ~pattern: " \n " ~with_ in
548- if for_log_trace_tree && String. is_suffix res ~suffix: " $" then
549- String. drop_suffix res 1 ^ " \\ n"
550- else res
545+ let base = if String. is_suffix base ~suffix: " \n " then String. drop_suffix base 1 else base in
546+ let base =
547+ let with_ =
548+ (* if for_log_trace_tree then *) " $"
549+ (* else "\\n" *)
550+ in
551+ String. substr_replace_all base ~pattern: " \n " ~with_
551552 in
552- let format_string_literal = ! Utils. captured_log_prefix ^ " %d: " ^ base_message_literal in
553- let all_args =
554- match log_param_c_expr_doc with
555- | Some doc -> doc :: args_docs
556- | None -> args_docs (* Should not happen if kernel_log_param is Some *)
557- in
558- group
559- (string metal_log_object_name ^^ string " .log("
560- ^^ dquotes (string format_string_literal)
561- ^^ comma ^^ space
562- ^^ separate (comma ^^ space) all_args
563- ^^ rparen ^^ semi)
553+ let format_string_literal = " %d: " ^ base in
554+ let all_args = Option. value_exn ~here: [% here] log_param_c_expr_doc :: args_docs in
555+ if List. length all_args > 7 then
556+ (* TODO: failsafe for "newComputePipelineStateWithFunction:options:reflection:error:
557+ failed: Compiler encountered an internal error" *)
558+ group
559+ (string metal_log_object_name
560+ ^^ string " .log_debug(\" Exceeded max of 7 logging args\" )"
561+ ^^ semi)
562+ else
563+ group
564+ (string metal_log_object_name ^^ string " .log_debug("
565+ ^^ dquotes (string format_string_literal)
566+ ^^ comma ^^ space
567+ ^^ separate (comma ^^ space) all_args
568+ ^^ rparen ^^ semi)
564569 end
565570
566571 let % diagn_sexp compile_metal_source ~name ~source ~device =
567572 let options = Me.CompileOptions. init () in
568573 if Utils. debug_log_from_routines () then (
569574 Me.CompileOptions. set_language_version options Me.CompileOptions.LanguageVersion. version_3_2;
570- Me.CompileOptions. set_enable_logging options true
571- ) else (
575+ Me.CompileOptions. set_enable_logging options true )
576+ else
572577 Me.CompileOptions. set_language_version options Me.CompileOptions.LanguageVersion. version_3_0
573- (* Logging is disabled by default in CompileOptions, so no need to explicitly set it to false *)
574- );
578+ (* Logging is disabled by default in CompileOptions, so no need to explicitly set it to
579+ false * ) ;
575580
576581 if Utils. with_runtime_debug () then (
577582 let metal_file = Utils. build_file (name ^ " .metal" ) in
0 commit comments