1 =====================================
2 LLVM Code-Review Policy and Practices
3 =====================================
5 LLVM's code-review policy and practices help maintain high code quality across
6 the project. Specifically, our code review process aims to:
8 * Improve readability and maintainability.
9 * Improve robustness and prevent the introduction of defects.
10 * Best leverage the experience of other contributors for each proposed change.
11 * Help grow and develop new contributors, through mentorship by community leaders.
13 It is important for all contributors to understand our code-review
14 practices and participate in the code-review process.
19 What Code Should Be Reviewed?
20 -----------------------------
22 All developers are required to have significant changes reviewed before they
23 are committed to the repository.
25 Must Code Be Reviewed Prior to Being Committed?
26 -----------------------------------------------
28 Code can be reviewed either before it is committed or after. We expect
29 significant patches to be reviewed before being committed. Smaller patches
30 (or patches where the developer owns the component) that meet
31 likely-community-consensus requirements (as apply to all patch approvals) can
32 be committed prior to an explicit review. In situations where there is any
33 uncertainty, a patch should be reviewed prior to being committed.
35 Please note that the developer responsible for a patch is also
36 responsible for making all necessary review-related changes, including
37 those requested during any post-commit review.
39 .. _post_commit_review:
41 Can Code Be Reviewed After It Is Committed?
42 -------------------------------------------
44 Post-commit review is encouraged, and can be accomplished using any of the
45 tools detailed below. There is a strong expectation that authors respond
46 promptly to post-commit feedback and address it. Failure to do so is cause for
47 the patch to be :ref:`reverted <revert_policy>`.
49 If a community member expresses a concern about a recent commit, and this
50 concern would have been significant enough to warrant a conversation during
51 pre-commit review (including around the need for more design discussions),
52 they may ask for a revert to the original author who is responsible to revert
53 the patch promptly. Developers often disagree, and erring on the side of the
54 developer asking for more review prevents any lingering disagreement over
55 code in the tree. This does not indicate any fault from the patch author,
56 this is inherent to our post-commit review practices.
57 Reverting a patch ensures that design discussions can happen without blocking
58 other development; it's entirely possible the patch will end up being reapplied
59 essentially as-is once concerns have been resolved.
61 Before being recommitted, the patch generally should undergo further review.
62 The community member who identified the problem is expected to engage
63 actively in the review. In cases where the problem is identified by a buildbot,
64 a community member with access to hardware similar to that on the buildbot is
65 expected to engage in the review.
67 Please note: The bar for post-commit feedback is not higher than for pre-commit
68 feedback. Don't delay unnecessarily in providing feedback. However, if you see
69 something after code has been committed about which you would have commented
70 pre-commit (had you noticed it earlier), please feel free to provide that
73 That having been said, if a substantial period of time has passed since the
74 original change was committed, it may be better to create a new patch to
75 address the issues than comment on the original commit. The original patch
76 author, for example, might no longer be an active contributor to the project.
78 What Tools Are Used for Code Review?
79 ------------------------------------
81 Pre-commit code reviews are conducted on GitHub with Pull Requests. See
82 :ref:`GitHub <github-reviews>` documentation.
84 When Is an RFC Required?
85 ------------------------
87 Some changes are too significant for just a code review. Changes that should
88 change the LLVM Language Reference (e.g., adding new target-independent
89 intrinsics), adding language extensions in Clang, and so on, require an RFC
90 (Request for Comment) email on the project's ``*-dev`` mailing list first. For
91 changes that promise significant impact on users and/or downstream code bases,
92 reviewers can request an RFC achieving consensus before proceeding with code
93 review. That having been said, posting initial patches can help with
94 discussions on an RFC.
99 Code review can be an iterative process, which continues until the patch is
100 ready to be committed. Specifically, once a patch is sent out for review, it
101 needs an explicit approval before it is committed. Do not assume silent
102 approval, or solicit objections to a patch with a deadline.
104 Acknowledge All Reviewer Feedback
105 ---------------------------------
107 All comments by reviewers should be acknowledged by the patch author. It is
108 generally expected that suggested changes will be incorporated into a future
109 revision of the patch unless the author and/or other reviewers can articulate a
110 good reason to do otherwise (and then the reviewers must agree). If a new patch
111 does not address all outstanding feedback, the author should explicitly state
112 that when providing the updated patch. When using the web-based code-review
113 tool, such notes can be provided in the "Diff" description (which is different
114 from the description of the "Differential Revision" as a whole used for the
117 If you suggest changes in a code review, but don't wish the suggestion to be
118 interpreted this strongly, please state so explicitly.
120 Aim to Make Efficient Use of Everyone's Time
121 --------------------------------------------
123 Aim to limit the number of iterations in the review process. For example, when
124 suggesting a change, if you want the author to make a similar set of changes at
125 other places in the code, please explain the requested set of changes so that
126 the author can make all of the changes at once. If a patch will require
127 multiple steps prior to approval (e.g., splitting, refactoring, posting data
128 from specific performance tests), please explain as many of these up front as
129 possible. This allows the patch author and reviewers to make the most efficient
132 LGTM - How a Patch Is Accepted
133 ------------------------------
135 A patch is approved to be committed when a reviewer accepts it, and this is
136 almost always associated with a message containing the text "LGTM" (which
137 stands for Looks Good To Me). Only approval from a single reviewer is required.
139 When providing an unqualified LGTM (approval to commit), it is the
140 responsibility of the reviewer to have reviewed all of the discussion and
141 feedback from all reviewers ensuring that all feedback has been addressed and
142 that all other reviewers will almost surely be satisfied with the patch being
143 approved. If unsure, the reviewer should provide a qualified approval, (e.g.,
144 "LGTM, but please wait for @someone, @someone_else"). You may also do this if
145 you are fairly certain that a particular community member will wish to review,
146 even if that person hasn't done so yet.
148 Note that, if a reviewer has requested a particular community member to review,
149 and after a week that community member has yet to respond, feel free to ping
150 the patch (which literally means submitting a comment on the patch with the
151 word, "Ping."), or alternatively, ask the original reviewer for further
154 If it is likely that others will want to review a recently-posted patch,
155 especially if there might be objections, but no one else has done so yet, it is
156 also polite to provide a qualified approval (e.g., "LGTM, but please wait for a
157 couple of days in case others wish to review"). If approval is received very
158 quickly, a patch author may also elect to wait before committing (and this is
159 certainly considered polite for non-trivial patches). Especially given the
160 global nature of our community, this waiting time should be at least 24 hours.
161 Please also be mindful of weekends and major holidays.
163 Our goal is to ensure community consensus around design decisions and
164 significant implementation choices, and one responsibility of a reviewer, when
165 providing an overall approval for a patch, is to be reasonably sure that such
166 consensus exists. If you're not familiar enough with the community to know,
167 then you shouldn't be providing final approval to commit. A reviewer providing
168 final approval should have commit access to the LLVM project.
170 Every patch should be reviewed by at least one technical expert in the areas of
171 the project affected by the change.
173 Splitting Requests and Conditional Acceptance
174 ---------------------------------------------
176 Reviewers may request certain aspects of a patch to be broken out into separate
177 patches for independent review. Reviewers may also accept a patch
178 conditioned on the author providing a follow-up patch addressing some
179 particular issue or concern (although no committed patch should leave the
180 project in a broken state). Moreover, reviewers can accept a patch conditioned on
181 the author applying some set of minor updates prior to committing, and when
182 applicable, it is polite for reviewers to do so.
184 Don't Unintentionally Block a Review
185 ------------------------------------
187 If you review a patch, but don't intend for the review process to block on your
188 approval, please state that explicitly. Out of courtesy, we generally wait on
189 committing a patch until all reviewers are satisfied, and if you don't intend
190 to look at the patch again in a timely fashion, please communicate that fact in
193 Who Can/Should Review Code?
194 ===========================
196 Non-Experts Should Review Code
197 ------------------------------
199 You do not need to be an expert in some area of the code base to review patches;
200 it's fine to ask questions about what some piece of code is doing. If it's not
201 clear to you what is going on, you're unlikely to be the only one. Please
202 remember that it is not in the long-term best interest of the community to have
203 components that are only understood well by a small number of people. Extra
204 comments and/or test cases can often help (and asking for comments in the test
205 cases is fine as well).
207 Moreover, authors are encouraged to interpret questions as a reason to reexamine
208 the readability of the code in question. Structural changes, or further
209 comments, may be appropriate.
211 If you're new to the LLVM community, you might also find this presentation helpful:
212 .. _How to Contribute to LLVM, A 2019 LLVM Developers' Meeting Presentation: https://youtu.be/C5Y977rLqpw
214 A good way for new contributors to increase their knowledge of the code base is
215 to review code. It is perfectly acceptable to review code and explicitly
216 defer to others for approval decisions.
218 Experts Should Review Code
219 --------------------------
221 If you are an expert in an area of the compiler affected by a proposed patch,
222 then you are highly encouraged to review the code. If you are a relevant code
223 owner, and no other experts are reviewing a patch, you must either help arrange
224 for an expert to review the patch or review it yourself.
226 Code Reviews, Speed, and Reciprocity
227 ------------------------------------
229 Sometimes code reviews will take longer than you might hope, especially for
230 larger features. Common ways to speed up review times for your patches are:
232 * Review other people's patches. If you help out, everybody will be more
233 willing to do the same for you; goodwill is our currency.
234 * Ping the patch. If it is urgent, provide reasons why it is important to you to
235 get this patch landed and ping it every couple of days. If it is
236 not urgent, the common courtesy ping rate is one week. Remember that you're
237 asking for valuable time from other professional developers.
238 * Ask for help on IRC. Developers on IRC will be able to either help you
239 directly, or tell you who might be a good reviewer.
240 * Split your patch into multiple smaller patches that build on each other. The
241 smaller your patch is, the higher the probability that somebody will take a quick
242 look at it. When doing this, it is helpful to add "[N/M]" (for 1 <= N <= M) to
243 the title of each patch in the series, so it is clear that there is an order
244 and what that order is.
246 Developers should participate in code reviews as both reviewers and
247 authors. If someone is kind enough to review your code, you should return the
248 favor for someone else. Note that anyone is welcome to review and give feedback
249 on a patch, but approval of patches should be consistent with the policy above.