[Native] Migrate configuration diagnostics to printf#12155
[Native] Migrate configuration diagnostics to printf#12155simonrozsival wants to merge 4 commits into
Conversation
Convert host environment and integer parsing diagnostics to #12140 printf helpers while preserving MonoVM formatting branches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
There was a problem hiding this comment.
Pull request overview
Migrates native configuration and integer-parsing diagnostics in the CoreCLR/NativeAOT code paths from std::format-style logging to the printf-checked log_*f() helpers introduced in #12140, reducing formatted-template instantiations while keeping MonoVM behavior unchanged.
Changes:
- Convert
HostEnvironmentdiagnostics inhost-environment.hhtolog_debugf()/log_warnf()with%sformatting andoptional_string()for null safety. - Convert
string_segment::to_integer()diagnostics instrings.hhto runtime-guardedlog_errorf()for CoreCLR/NativeAOT (MonoVM retains existinglog_error()+{}formatting). - Add an explicit
shared/log_types.hhinclude for non-MonoVM builds instrings.hhto avoid reliance on caller include order.
Show a summary per file
| File | Description |
|---|---|
| src/native/common/include/runtime-base/strings.hh | Adds non-MonoVM logging header include and migrates integer-parsing diagnostics to log_errorf() under runtime guards. |
| src/native/clr/include/host/host-environment.hh | Migrates CoreCLR/NativeAOT host environment debug/warn diagnostics to printf-style log_*f() calls. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 1
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
|
/review |
|
✅ Android PR Reviewer completed successfully! |
There was a problem hiding this comment.
🤖 Code Review — ✅ LGTM (with 1 minor suggestion)
Clean, well-scoped continuation of the printf-logging migration (#12139). Verified independently against the diff and full file context.
What I checked
%ssafety —optional_string()returnsconst char*and theto_integerparse buffersis explicitly NUL-terminated before logging, so all%sconversions are well-defined.- Format widths —
%zuforsize_t start_index,%dfor theint base, and%lld/%llufor the range bounds all match their argument types. The double casts (int64_t→long long,uint64_t→unsigned long long) correctly bridge the fixed-width types to theprintfpromotion types across ABIs. - Range semantics — signed/unsigned min/max printing preserves the original
std::formatoutput for both signed and unsignedT. - Forward declaration — the manual
log_errorfdeclaration exactly matches the canonical one inshared/log_types.hh(signature +format(printf,2,3)attribute), andLogCategoriesis in scope viahelpers.hh→java-interop-util.h. - Behavior parity — errno handling, conversion logic, and XDG directory diagnostics are unchanged.
Notes
- 💡 One inline suggestion about the duplicated forward declaration (drift risk) — non-blocking.
- CI shows
pending/no checks yet, expected since this PR targets thedev/simonrozsival/nativeaot-printf-loggingbase branch (dependency on #12140). Not mergeable until #12140 lands and CI is green.
Nice reduction in template instantiation with measured object-size wins. 👍
Generated by Android PR Reviewer for #12155 · 77.7 AIC · ⌖ 12.8 AIC · ⊞ 6.8K
Comment /review to run again
|
|
||
| #include <shared/helpers.hh> | ||
| namespace xamarin::android { | ||
| void log_errorf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); |
There was a problem hiding this comment.
🤖 💡 Native C++ — This forward declaration of log_errorf duplicates the canonical one in shared/log_types.hh. Deliberately avoiding that heavyweight include is reasonable, but if the signature ever changes the two can silently diverge (the mismatch only surfaces in translation units that include both headers). Consider adding a short comment pointing at the canonical declaration, e.g. // Forward-declared to avoid including shared/log_types.hh; keep in sync with it.
(Rule: Native C++ — reduce duplication drift)
Summary
Continue the printf-style logging migration introduced by #12140 for native configuration and parsing diagnostics.
This PR converts CoreCLR/NativeAOT host-environment messages and the shared MonoVM/CoreCLR/NativeAOT integer-parsing messages to the printf helpers from #12140. Shared code now has one logging path instead of runtime-specific format branches.
Base/dependency: #12140 must merge first. This PR targets
dev/simonrozsival/nativeaot-printf-loggingso its diff contains only this migration.Part of #12139.
Scope
Only two files change:
src/native/clr/include/host/host-environment.hhsrc/native/common/include/runtime-base/strings.hhThese files do not overlap #12141, #12142, #12145, #12148, #12150, or #12153.
Changes
Host environment diagnostics
host-environment.hhis shared by CoreCLR and NativeAOT, but not MonoVM.%sformatting;%sformatting;optional_string()handling for null C-string inputs.Integer parsing diagnostics
strings.hhis shared by all three runtimes. Its variable diagnostics now uselog_errorf()without runtime-specific branches:%zuforsize_t;%lld/%lluvalues;%dbase;The header forward-declares only
log_errorf()instead of including the heavyweight formatting declarations fromshared/log_types.hh.Behavior preserved
%slogging;Runtime behavior
log_errorf()implementation for shared parsing diagnosticsMeasured impact
Representative Android arm64 Release objects compiled before the MonoVM path was unified:
host-environment.cc.otiming-internal.cc.oThese call sites did not contain explicit
std::formatexpressions, so the impact is smaller than #12150/#12153; the change prevents their formatted logging templates from being instantiated.Non-goals
Validation
git diff --check;72cad5d01.