xref: /llvm-project/llvm/docs/CodeReview.rst (revision 41248b598b8b18febc62ea61938870def2421126)
1ba5d92ebSDavid Spickett.. _code_review_policy:
2ba5d92ebSDavid Spickett
34d0339aeSHal Finkel=====================================
44d0339aeSHal FinkelLLVM Code-Review Policy and Practices
54d0339aeSHal Finkel=====================================
64d0339aeSHal Finkel
74d0339aeSHal FinkelLLVM's code-review policy and practices help maintain high code quality across
84d0339aeSHal Finkelthe project. Specifically, our code review process aims to:
94d0339aeSHal Finkel
104d0339aeSHal Finkel * Improve readability and maintainability.
114d0339aeSHal Finkel * Improve robustness and prevent the introduction of defects.
124d0339aeSHal Finkel * Best leverage the experience of other contributors for each proposed change.
134d0339aeSHal Finkel * Help grow and develop new contributors, through mentorship by community leaders.
144d0339aeSHal Finkel
154d0339aeSHal FinkelIt is important for all contributors to understand our code-review
164d0339aeSHal Finkelpractices and participate in the code-review process.
174d0339aeSHal Finkel
184d0339aeSHal FinkelGeneral Policies
194d0339aeSHal Finkel================
204d0339aeSHal Finkel
214d0339aeSHal FinkelWhat Code Should Be Reviewed?
224d0339aeSHal Finkel-----------------------------
234d0339aeSHal Finkel
244d0339aeSHal FinkelAll developers are required to have significant changes reviewed before they
254d0339aeSHal Finkelare committed to the repository.
264d0339aeSHal Finkel
274d0339aeSHal FinkelMust Code Be Reviewed Prior to Being Committed?
284d0339aeSHal Finkel-----------------------------------------------
294d0339aeSHal Finkel
304d0339aeSHal FinkelCode can be reviewed either before it is committed or after. We expect
314d0339aeSHal Finkelsignificant patches to be reviewed before being committed. Smaller patches
324d0339aeSHal Finkel(or patches where the developer owns the component) that meet
334d0339aeSHal Finkellikely-community-consensus requirements (as apply to all patch approvals) can
344d0339aeSHal Finkelbe committed prior to an explicit review. In situations where there is any
354d0339aeSHal Finkeluncertainty, a patch should be reviewed prior to being committed.
364d0339aeSHal Finkel
374d0339aeSHal FinkelPlease note that the developer responsible for a patch is also
384d0339aeSHal Finkelresponsible for making all necessary review-related changes, including
394d0339aeSHal Finkelthose requested during any post-commit review.
404d0339aeSHal Finkel
410918f44eSPhilip Reames.. _post_commit_review:
420918f44eSPhilip Reames
434d0339aeSHal FinkelCan Code Be Reviewed After It Is Committed?
444d0339aeSHal Finkel-------------------------------------------
454d0339aeSHal Finkel
464d0339aeSHal FinkelPost-commit review is encouraged, and can be accomplished using any of the
474d0339aeSHal Finkeltools detailed below. There is a strong expectation that authors respond
484d0339aeSHal Finkelpromptly to post-commit feedback and address it. Failure to do so is cause for
490918f44eSPhilip Reamesthe patch to be :ref:`reverted <revert_policy>`.
504d0339aeSHal Finkel
517d3e9578SMehdi AminiIf a community member expresses a concern about a recent commit, and this
527d3e9578SMehdi Aminiconcern would have been significant enough to warrant a conversation during
537d3e9578SMehdi Aminipre-commit review (including around the need for more design discussions),
547d3e9578SMehdi Aminithey may ask for a revert to the original author who is responsible to revert
557d3e9578SMehdi Aminithe patch promptly. Developers often disagree, and erring on the side of the
567d3e9578SMehdi Aminideveloper asking for more review prevents any lingering disagreement over
577d3e9578SMehdi Aminicode in the tree. This does not indicate any fault from the patch author,
587d3e9578SMehdi Aminithis is inherent to our post-commit review practices.
597d3e9578SMehdi AminiReverting a patch ensures that design discussions can happen without blocking
607d3e9578SMehdi Aminiother development; it's entirely possible the patch will end up being reapplied
617d3e9578SMehdi Aminiessentially as-is once concerns have been resolved.
627d3e9578SMehdi Amini
637d3e9578SMehdi AminiBefore being recommitted, the patch generally should undergo further review.
647d3e9578SMehdi AminiThe community member who identified the problem is expected to engage
657d3e9578SMehdi Aminiactively in the review. In cases where the problem is identified by a buildbot,
667d3e9578SMehdi Aminia community member with access to hardware similar to that on the buildbot is
677d3e9578SMehdi Aminiexpected to engage in the review.
684d0339aeSHal Finkel
694d0339aeSHal FinkelPlease note: The bar for post-commit feedback is not higher than for pre-commit
704d0339aeSHal Finkelfeedback. Don't delay unnecessarily in providing feedback. However, if you see
714d0339aeSHal Finkelsomething after code has been committed about which you would have commented
724d0339aeSHal Finkelpre-commit (had you noticed it earlier), please feel free to provide that
734d0339aeSHal Finkelfeedback at any time.
744d0339aeSHal Finkel
754d0339aeSHal FinkelThat having been said, if a substantial period of time has passed since the
764d0339aeSHal Finkeloriginal change was committed, it may be better to create a new patch to
774d0339aeSHal Finkeladdress the issues than comment on the original commit. The original patch
784d0339aeSHal Finkelauthor, for example, might no longer be an active contributor to the project.
794d0339aeSHal Finkel
804d0339aeSHal FinkelWhat Tools Are Used for Code Review?
814d0339aeSHal Finkel------------------------------------
824d0339aeSHal Finkel
8363b29114STobias HietaPre-commit code reviews are conducted on GitHub with Pull Requests. See
8463b29114STobias Hieta:ref:`GitHub <github-reviews>` documentation.
854d0339aeSHal Finkel
864d0339aeSHal FinkelWhen Is an RFC Required?
874d0339aeSHal Finkel------------------------
884d0339aeSHal Finkel
894d0339aeSHal FinkelSome changes are too significant for just a code review. Changes that should
904d0339aeSHal Finkelchange the LLVM Language Reference (e.g., adding new target-independent
914d0339aeSHal Finkelintrinsics), adding language extensions in Clang, and so on, require an RFC
923f176135SJan Svoboda(Request for Comment) topic on the `LLVM Discussion Forums <https://discourse.llvm.org>`_
933f176135SJan Svobodafirst. For changes that promise significant impact on users and/or downstream
943f176135SJan Svobodacode bases, reviewers can request an RFC achieving consensus before proceeding
953f176135SJan Svobodawith code review. That having been said, posting initial patches can help with
964d0339aeSHal Finkeldiscussions on an RFC.
974d0339aeSHal Finkel
984d0339aeSHal FinkelCode-Review Workflow
994d0339aeSHal Finkel====================
1004d0339aeSHal Finkel
1014d0339aeSHal FinkelCode review can be an iterative process, which continues until the patch is
1024d0339aeSHal Finkelready to be committed. Specifically, once a patch is sent out for review, it
1034d0339aeSHal Finkelneeds an explicit approval before it is committed. Do not assume silent
1044d0339aeSHal Finkelapproval, or solicit objections to a patch with a deadline.
1054d0339aeSHal Finkel
10693471466SDavid Blaikie.. note::
10793471466SDavid Blaikie   If you are using a Pull Request for purposes other than review
10893471466SDavid Blaikie   (eg: precommit CI results, convenient web-based reverts, etc)
1092709bafbSDavid Blaikie   `skip-precommit-approval <https://github.com/llvm/llvm-project/labels?q=skip-precommit-approval>`_
11093471466SDavid Blaikie   label to the PR.
11193471466SDavid Blaikie
1124d0339aeSHal FinkelAcknowledge All Reviewer Feedback
1134d0339aeSHal Finkel---------------------------------
1144d0339aeSHal Finkel
1154d0339aeSHal FinkelAll comments by reviewers should be acknowledged by the patch author. It is
1164d0339aeSHal Finkelgenerally expected that suggested changes will be incorporated into a future
1174d0339aeSHal Finkelrevision of the patch unless the author and/or other reviewers can articulate a
1184d0339aeSHal Finkelgood reason to do otherwise (and then the reviewers must agree). If a new patch
1194d0339aeSHal Finkeldoes not address all outstanding feedback, the author should explicitly state
1204d0339aeSHal Finkelthat when providing the updated patch. When using the web-based code-review
1214d0339aeSHal Finkeltool, such notes can be provided in the "Diff" description (which is different
1224d0339aeSHal Finkelfrom the description of the "Differential Revision" as a whole used for the
1234d0339aeSHal Finkelcommit message).
1244d0339aeSHal Finkel
1254d0339aeSHal FinkelIf you suggest changes in a code review, but don't wish the suggestion to be
1264d0339aeSHal Finkelinterpreted this strongly, please state so explicitly.
1274d0339aeSHal Finkel
12893d0f822SVitaly Buka.. note::
12993d0f822SVitaly Buka   After responding to reviewer comments,
13093d0f822SVitaly Buka   press `Re-request review <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/requesting-a-pull-request-review#:~:text=After%20your%20pull%20request%20is%20reviewed>`_
13193d0f822SVitaly Buka   to bring the Pull Request to the reviewers' attention.
13293d0f822SVitaly Buka
1334d0339aeSHal FinkelAim to Make Efficient Use of Everyone's Time
1344d0339aeSHal Finkel--------------------------------------------
1354d0339aeSHal Finkel
1364d0339aeSHal FinkelAim to limit the number of iterations in the review process. For example, when
1374d0339aeSHal Finkelsuggesting a change, if you want the author to make a similar set of changes at
1384d0339aeSHal Finkelother places in the code, please explain the requested set of changes so that
1394d0339aeSHal Finkelthe author can make all of the changes at once. If a patch will require
1404d0339aeSHal Finkelmultiple steps prior to approval (e.g., splitting, refactoring, posting data
1414d0339aeSHal Finkelfrom specific performance tests), please explain as many of these up front as
1424d0339aeSHal Finkelpossible. This allows the patch author and reviewers to make the most efficient
1434d0339aeSHal Finkeluse of their time.
1444d0339aeSHal Finkel
145a1c6dc22SDavid Spickett.. _lgtm_how_a_patch_is_accepted:
146a1c6dc22SDavid Spickett
1474d0339aeSHal FinkelLGTM - How a Patch Is Accepted
1484d0339aeSHal Finkel------------------------------
1494d0339aeSHal Finkel
1504d0339aeSHal FinkelA patch is approved to be committed when a reviewer accepts it, and this is
1514d0339aeSHal Finkelalmost always associated with a message containing the text "LGTM" (which
152a1c6dc22SDavid Spickettstands for Looks Good To Me).
153a1c6dc22SDavid Spickett
154a1c6dc22SDavid SpickettOnly approval from a single reviewer is required, unless the pull request
155a1c6dc22SDavid Spicketthas required reviewers. In which case, you must have approval from all of those
156a1c6dc22SDavid Spickettreviewers.
1574d0339aeSHal Finkel
1584d0339aeSHal FinkelWhen providing an unqualified LGTM (approval to commit), it is the
159*41248b59SAndrzej Warzyńskiresponsibility of the reviewer to have reviewed all of the prior discussion and
1604d0339aeSHal Finkelfeedback from all reviewers ensuring that all feedback has been addressed and
1614d0339aeSHal Finkelthat all other reviewers will almost surely be satisfied with the patch being
1624d0339aeSHal Finkelapproved. If unsure, the reviewer should provide a qualified approval, (e.g.,
1634d0339aeSHal Finkel"LGTM, but please wait for @someone, @someone_else"). You may also do this if
1644d0339aeSHal Finkelyou are fairly certain that a particular community member will wish to review,
1654d0339aeSHal Finkeleven if that person hasn't done so yet.
1664d0339aeSHal Finkel
167*41248b59SAndrzej WarzyńskiIf additional feedback is provided after acceptance (by the same reviewer or
168*41248b59SAndrzej Warzyńskianother), the author should use their best judgement in deciding whether that
169*41248b59SAndrzej Warzyńskifeedback can be incorporated into the change without comment (say a typo) or
170*41248b59SAndrzej Warzyńskirequires further review discussion. More substantial comments (e.g., about the
171*41248b59SAndrzej Warzyńskidesign) will usually require further discussion. If unsure, ask the reviewer.
172*41248b59SAndrzej Warzyński
1734d0339aeSHal FinkelNote that, if a reviewer has requested a particular community member to review,
1744d0339aeSHal Finkeland after a week that community member has yet to respond, feel free to ping
1754d0339aeSHal Finkelthe patch (which literally means submitting a comment on the patch with the
1764d0339aeSHal Finkelword, "Ping."), or alternatively, ask the original reviewer for further
1774d0339aeSHal Finkelsuggestions.
1784d0339aeSHal Finkel
1794d0339aeSHal FinkelIf it is likely that others will want to review a recently-posted patch,
1804d0339aeSHal Finkelespecially if there might be objections, but no one else has done so yet, it is
1814d0339aeSHal Finkelalso polite to provide a qualified approval (e.g., "LGTM, but please wait for a
1824d0339aeSHal Finkelcouple of days in case others wish to review"). If approval is received very
1834d0339aeSHal Finkelquickly, a patch author may also elect to wait before committing (and this is
1844d0339aeSHal Finkelcertainly considered polite for non-trivial patches). Especially given the
1854d0339aeSHal Finkelglobal nature of our community, this waiting time should be at least 24 hours.
1864d0339aeSHal FinkelPlease also be mindful of weekends and major holidays.
1874d0339aeSHal Finkel
1884d0339aeSHal FinkelOur goal is to ensure community consensus around design decisions and
1894d0339aeSHal Finkelsignificant implementation choices, and one responsibility of a reviewer, when
1904d0339aeSHal Finkelproviding an overall approval for a patch, is to be reasonably sure that such
1914d0339aeSHal Finkelconsensus exists. If you're not familiar enough with the community to know,
1924d0339aeSHal Finkelthen you shouldn't be providing final approval to commit. A reviewer providing
1934d0339aeSHal Finkelfinal approval should have commit access to the LLVM project.
1944d0339aeSHal Finkel
1954d0339aeSHal FinkelEvery patch should be reviewed by at least one technical expert in the areas of
1964d0339aeSHal Finkelthe project affected by the change.
1974d0339aeSHal Finkel
1984d0339aeSHal FinkelSplitting Requests and Conditional Acceptance
1994d0339aeSHal Finkel---------------------------------------------
2004d0339aeSHal Finkel
2014d0339aeSHal FinkelReviewers may request certain aspects of a patch to be broken out into separate
2024d0339aeSHal Finkelpatches for independent review. Reviewers may also accept a patch
2034d0339aeSHal Finkelconditioned on the author providing a follow-up patch addressing some
2044d0339aeSHal Finkelparticular issue or concern (although no committed patch should leave the
2054d0339aeSHal Finkelproject in a broken state). Moreover, reviewers can accept a patch conditioned on
2064d0339aeSHal Finkelthe author applying some set of minor updates prior to committing, and when
2074d0339aeSHal Finkelapplicable, it is polite for reviewers to do so.
2084d0339aeSHal Finkel
2094d0339aeSHal FinkelDon't Unintentionally Block a Review
2104d0339aeSHal Finkel------------------------------------
2114d0339aeSHal Finkel
2124d0339aeSHal FinkelIf you review a patch, but don't intend for the review process to block on your
2134d0339aeSHal Finkelapproval, please state that explicitly. Out of courtesy, we generally wait on
2144d0339aeSHal Finkelcommitting a patch until all reviewers are satisfied, and if you don't intend
2154d0339aeSHal Finkelto look at the patch again in a timely fashion, please communicate that fact in
2164d0339aeSHal Finkelthe review.
2174d0339aeSHal Finkel
2184d0339aeSHal FinkelWho Can/Should Review Code?
2194d0339aeSHal Finkel===========================
2204d0339aeSHal Finkel
2214d0339aeSHal FinkelNon-Experts Should Review Code
2224d0339aeSHal Finkel------------------------------
2234d0339aeSHal Finkel
2244d0339aeSHal FinkelYou do not need to be an expert in some area of the code base to review patches;
2254d0339aeSHal Finkelit's fine to ask questions about what some piece of code is doing. If it's not
2264d0339aeSHal Finkelclear to you what is going on, you're unlikely to be the only one. Please
2274d0339aeSHal Finkelremember that it is not in the long-term best interest of the community to have
2284d0339aeSHal Finkelcomponents that are only understood well by a small number of people. Extra
2294d0339aeSHal Finkelcomments and/or test cases can often help (and asking for comments in the test
2304d0339aeSHal Finkelcases is fine as well).
2314d0339aeSHal Finkel
2324d0339aeSHal FinkelMoreover, authors are encouraged to interpret questions as a reason to reexamine
2334d0339aeSHal Finkelthe readability of the code in question. Structural changes, or further
2344d0339aeSHal Finkelcomments, may be appropriate.
2354d0339aeSHal Finkel
2364d0339aeSHal FinkelIf you're new to the LLVM community, you might also find this presentation helpful:
2374d0339aeSHal Finkel.. _How to Contribute to LLVM, A 2019 LLVM Developers' Meeting Presentation: https://youtu.be/C5Y977rLqpw
2384d0339aeSHal Finkel
2394d0339aeSHal FinkelA good way for new contributors to increase their knowledge of the code base is
2404d0339aeSHal Finkelto review code. It is perfectly acceptable to review code and explicitly
2414d0339aeSHal Finkeldefer to others for approval decisions.
2424d0339aeSHal Finkel
2434d0339aeSHal FinkelExperts Should Review Code
2444d0339aeSHal Finkel--------------------------
2454d0339aeSHal Finkel
2464d0339aeSHal FinkelIf you are an expert in an area of the compiler affected by a proposed patch,
247c0719d8cSAaron Ballmanthen you are highly encouraged to review the code. If you are a relevant
248c0719d8cSAaron Ballmanmaintainer, and no other experts are reviewing a patch, you must either help
249c0719d8cSAaron Ballmanarrange for an expert to review the patch or review it yourself.
2504d0339aeSHal Finkel
2514d0339aeSHal FinkelCode Reviews, Speed, and Reciprocity
2524d0339aeSHal Finkel------------------------------------
2534d0339aeSHal Finkel
2544d0339aeSHal FinkelSometimes code reviews will take longer than you might hope, especially for
2554d0339aeSHal Finkellarger features. Common ways to speed up review times for your patches are:
2564d0339aeSHal Finkel
2574d0339aeSHal Finkel* Review other people's patches. If you help out, everybody will be more
2584d0339aeSHal Finkel  willing to do the same for you; goodwill is our currency.
2594d0339aeSHal Finkel* Ping the patch. If it is urgent, provide reasons why it is important to you to
2604d0339aeSHal Finkel  get this patch landed and ping it every couple of days. If it is
2614d0339aeSHal Finkel  not urgent, the common courtesy ping rate is one week. Remember that you're
2624d0339aeSHal Finkel  asking for valuable time from other professional developers.
2630ab44fd2SAaron Ballman* Ask for help on Discord. Developers on Discord will be able to either help
2640ab44fd2SAaron Ballman  you directly, or tell you who might be a good reviewer.
2654d0339aeSHal Finkel* Split your patch into multiple smaller patches that build on each other. The
2664d0339aeSHal Finkel  smaller your patch is, the higher the probability that somebody will take a quick
2674d0339aeSHal Finkel  look at it. When doing this, it is helpful to add "[N/M]" (for 1 <= N <= M) to
2684d0339aeSHal Finkel  the title of each patch in the series, so it is clear that there is an order
2694d0339aeSHal Finkel  and what that order is.
2704d0339aeSHal Finkel
2714d0339aeSHal FinkelDevelopers should participate in code reviews as both reviewers and
2724d0339aeSHal Finkelauthors. If someone is kind enough to review your code, you should return the
2734d0339aeSHal Finkelfavor for someone else. Note that anyone is welcome to review and give feedback
2744d0339aeSHal Finkelon a patch, but approval of patches should be consistent with the policy above.
275