You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new valueOrError template function is introduced to safely extract values from std::optional. This is a good practice for clang-tidy compliance, but reviewers should verify that all call sites where .value() was replaced actually had proper error handling and that the new function provides the same guarantees.
//! Returns the value of an optional, or throws via NVF_ERROR if nullopt. This//! is to satisfy clang-tidy bugprone-unchecked-optional-access. Use this when//! you have already ensured that the optional is engaged.template<typenameT>constT&valueOrError(conststd::optional<T>&opt) {
NVF_ERROR(opt.has_value());
return*opt;
}
template<typenameT>T&valueOrError(std::optional<T>&opt) {
NVF_ERROR(opt.has_value());
return*opt;
}
template<typenameT>TvalueOrError(std::optional<T>&&opt) {
NVF_ERROR(opt.has_value());
returnstd::move(opt).value();
}
The local valueOrError template function that was previously defined in arith.cpp has been removed since it's now available in base.h. Reviewers should ensure this doesn't break any compilation or that there are no other references to this local version.
Val* castOp(DataType dtype, Val* v1) {
auto orig_dtype = valueOrError(v1->getDataType());
if (dtype == orig_dtype) {
Include style changes Headers are being converted from angle-bracket includes (#include <...>) to quoted includes (#include "...") and reordered according to Google C++ style guide. While this is generally good practice, reviewers should verify that the quoted includes are appropriate for internal headers and that the new ordering doesn't cause any dependency issues.
Refactored include directives across the csrc/ops directory to follow Google C++ style guidelines by switching from angle brackets (<>) to quoted includes (""), and reordering includes to group them as: own header first (for .cpp files), then C++ standard library headers, then third-party headers, then project headers (alphabetically within each group).
Additionally, centralized the valueOrError helper function by moving it from csrc/ops/arith.cpp to csrc/base.h and applying it consistently across the codebase to replace manual std::optional checks. This addresses clang-tidy's bugprone-unchecked-optional-access warnings.
Key changes:
Switched all ops headers to quoted includes and reordered per Google C++ style
Moved valueOrError template function to csrc/base.h (now provides three overloads for const&, non-const&, and rvalue references)
Applied valueOrError throughout the codebase to replace .value() calls and manual has_value() checks
Modernized code by replacing std::all_of, std::find, and std::transform with their std::ranges equivalents in several files
Used designated initializers in csrc/device_lower/pass/allocation.cpp
Confidence Score: 5/5
This PR is safe to merge with minimal risk
This is a pure refactoring PR that improves code consistency and style without changing any logic. The changes are mechanical (include reordering, replacing manual optional checks with a helper function, using ranges algorithms) and have been tested with lintrunner as stated in the PR description. All modifications preserve the exact same behavior.
No files require special attention
Important Files Changed
Filename
Overview
csrc/base.h
Added valueOrError helper function to centralize optional value extraction, moved from ops/arith.cpp
csrc/device_lower/pass/allocation.cpp
Replaced std::all_of with std::ranges::all_of, std::find with std::ranges::find, applied valueOrError helper, used designated initializers
csrc/ops/arith.cpp
Switched to quoted includes, reordered per Google C++ style (own header, C++ libs, project headers), removed local valueOrError definition
csrc/ops/arith.h
Switched to quoted includes, reordered alphabetically per Google C++ style
csrc/ops/composite.cpp
Switched to quoted includes, reordered per Google C++ style (own header, C++ libs, third-party, project headers)
csrc/ops/utils.cpp
Switched to quoted includes, reordered per Google C++ style, applied valueOrError helper, replaced std::transform with std::ranges::transform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing