Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: c2bbe4b52e8274f4073c477ee3f38ed24bc8a595
https://github.com/WebKit/WebKit/commit/c2bbe4b52e8274f4073c477ee3f38ed24bc8a595
Author: Anne van Kesteren <[email protected]>
Date: 2026-10-15 (Thu, 15 Oct 2026)
Changed paths:
M Tools/Scripts/webkitpy/style/checkers/cpp.py
M Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
M Websites/webkit.org/code-style.md
Log Message:
-----------
Make check-webkit-style flag smart pointer get() calls that aren't needed
https://bugs.webkit.org/show_bug.cgi?id=327528
rdar://190015574
Reviewed by Ryosuke Niwa.
Smart pointers can be constructed from other smart pointers and passed to
is<>(), downcast<>(),
dynamicDowncast<>(), and uncheckedDowncast<>() directly, but new code often
calls get() first.
Add readability/redundant_get, which flags get() on a smart pointer that
initializes another
smart pointer or is passed to one of those casts, when the smart pointer itself
would do. Not
every smart pointer can be constructed from every other: a CheckedPtr can be
constructed from a
WeakPtr or a std::unique_ptr but not from a RefPtr, a WeakPtr from a Ref but
not from a
CheckedPtr, and a RetainPtr not from a WeakObjCPtr, whose get() returns a
strong reference. So
the check looks up how the operand of get() is declared, in the file and its
primary header, and
only flags a construction or cast that takes that type. When there's no
declaration to go on, it
only flags the casts and RefPtr and Ref constructions, which nearly always take
the smart pointer
itself.
The check skips WTF, which implements these constructors and casts in terms of
get(), and the
casts in JavaScriptCore, where get() mostly unwraps a WriteBarrier or a Strong.
It also leaves
out places where get() is often needed: ThreadSafeWeakPtr's get() returns a
strong reference, so
x.get()-> and if (x.get()) need it, many protect(x.get()) calls unwrap types
like NakedPtr and
std::reference_wrapper that protect() doesn't take, and for two Refs, a.get()
== b.get()
compares the objects where a == b compares the pointers.
Of the 6,444 matches on main, 5,544 are built on macOS. Removing get() from
each and compiling
showed that 5,438 (98%) don't need it.
Also add the rule to the code style guidelines.
Canonical link: https://commits.webkit.org/323811@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications