blob: 1effa6abc5e398458717b0379b911c7757feca28 [file] [log] [blame] [view]
Nigel Tao187a4792023-09-28 22:30:441# What’s Up With DCHECKs
2
3This is a transcript of [What's Up With
4That](https://www.youtube.com/playlist?list=PL9ioqAuyl6ULIdZQys3fwRxi3G3ns39Hq)
5Episode 2, a 2022 video discussion between [Sharon ([email protected])
6and Peter ([email protected])](https://www.youtube.com/watch?v=MpwbWSEDfjM).
7
8The transcript was automatically generated by speech-to-text software. It may
9contain minor errors.
10
11---
12
13You've seen DCHECKs around and been asked to use them in code review, but what
14are they? What's the difference between a CHECK and a DCHECK? How do you use
15them? Here to answer that is special guest is Peter, who works on UI and
16improving crash reports.
17
18Notes:
Daniel Verkamp1de516f2023-10-10 22:17:0919
Nigel Tao187a4792023-09-28 22:30:4420- https://docs.google.com/document/d/146LoJ1E3N3E6fb4zDh92HPQc6yhRpNI7DSKlJjaYlLw/edit
21
22Links:
Daniel Verkamp1de516f2023-10-10 22:17:0923
24- [What's Up With Pointers]
Nigel Tao187a4792023-09-28 22:30:4425
26---
27
2800:00 SHARON: Hello, and welcome to What's Up With That?, the series that
29demystifies all things Chrome. I'm your host, Sharon. And today, we're talking
30about DCHECKs. You've seen them around. You've probably been told to add one in
31code review before. But what are they? What are they for, and what do they do?
32Our guest today is Peter, who works on desktop UI and Core UI. He's also
33working on improving Chrome's crash reports, which includes DCHECKs. Today
34he'll help us answer, what's up with DCHECKs? Welcome, Peter.
35
3600:30 PETER: Thanks for having me.
37
3800:32 SHARON: Yeah. Thanks for being here. So the most obvious question to
39start with, what is a DCHECK?
40
4100:39 PETER: So a CHECK and a DCHECK are both sort of things that make sure
42that what you think is true is true. Right? So this should never be called with
43an empty vector. You might add a CHECK for it, or you might add a DCHECK for
Daniel Verkamp1de516f2023-10-10 22:17:0944it. And it's sort of similar to asserts, which you may have hit during earlier
Nigel Tao187a4792023-09-28 22:30:4445programming outside of Chrome. And what it means is when this line gets hit, we
46check and see if it's true. And if it's not true, we crash. DCHECKs differ from
47CHECKs in that they are traditionally only in debug builds, or local
48development builds, or on our try-bots. So they have zero overhead when Chrome
49hits stable, because the CHECK just won't be there.
50
Daniel Verkamp1de516f2023-10-10 22:17:095101:24 SHARON: OK. So I guess the D stands for Debug. That make sense.
Nigel Tao187a4792023-09-28 22:30:4452
5301:28 PETER: Yeah. I want debug to turn into developer, because now we have
54them by default if you're no longer - if you're doing a release build, and
55you're not turning them off, and you're not doing an official build, you get
56them.
57
5801:42 SHARON: OK. Well, you heard it here first, or maybe you heard it before.
59I heard it here first. So you mentioned asserts. So something that I've seen a
60couple times in Chrome, and also is part of the standard library, is
61`static_assert`. So how is that similar or different to DCHECKs? And why do we
62use or not use them?
63
6402:00 PETER: Right. So `static_assert`s are - and you're going to have to ask
65C++ experts, who can probably take some of the sharp edges off of this - but
66it's basically, if you can assert something in compile time, then you can use a
67`static_assert`, which means that you don't have to hit a code path where it's
68wrong. It sort of has to always hold true. And whenever you can use a
69`static_assert`, use a `static_assert`, because it's free. And basically, you
70can't compile the program if it's not true.
71
7202:31 SHARON: OK. That's good to know, because I definitely thought that was
73one of the C++ standard library things we should avoid, because we have a
74similar thing in Chromium. But I guess that's not the case.
75
7602:41 PETER: Yeah. Assert is the one that is - OK, so this is a little
77complicated, right? `static_assert` is a language feature, not a library
78feature. And someone will tell me that I'm wrong about something about this.
79Asserts are just sort of a poorer version of DCHECKs. So they won't go through
80our crash handling. It won't print the pretty stacks, et cetera.
81`static_assert`s, on the other hand, are a compile time feature. And we don't,
82as far as I know, have our own wrapper around it. We just use `static_assert`.
83So what you would maybe use this for is like if you have a constant - like, say
84you have an array, and the code makes an assumption that some constant is the
85size of this array, you can assert that in compile time, and that would be a
86good use of a `static_assert`.
87
8803:26 SHARON: OK. Cool. So you mentioned that some things have changed with how
89DCHECKs work. So can you give us a brief overview of the history of DCHECKs -
90what they used to be, people who have been using them for a while, how might
91they have changed from the idea of what they have as a DCHECK in their mind?
92
9303:43 PETER: Sure. So this is as best I know. I'm just sort of extrapolating
94from what I've seen. And what I think originally was true is that a CHECK used
95to be this logging statement, where you essentially compile the file name and
96the line number. And if this ever hits, then we'll log some stuff and then
97crash. Right? Which comes with a little bit of overhead, especially on size,
98that you basically take the file name and line number for every instance, and
99that generates a bunch of strings and numbers that essentially add to Chrome's
100binary size. I don't know how many steps between that and where we currently
101are. But right now, our CHECKs are just, if condition is false, crash, which
102means that you won't, out of the CHECK, get file name and line number. We'll
103get those out of debugging symbols. And you also won't get any of the logging
104messages that you can add to the end of a CHECK, which means that your debug
105info will be poorer, but it will be cheaper to use. So they've gotten from
106being pretty heavy CHECKs to being really cheap.
107
10805:01 SHARON: OK. So that kind of leads us into the question that I think most
109people want to have answered, which is, when should I use a DCHECK? When should
110I use a CHECK? When should I use neither?
111
11205:13 PETER: I would say that historically, we've said CHECKs are expensive.
113Don't use them unless you sort of have to. And I don't think that holds true
114anymore. So basically, unless you are in really performance-critical code, then
115use a CHECK. If there's anything that you care about where the program state
116will be unpredictable from this point on if it's not true, CHECK it. It's not
117that expensive. Right? We have a lot of code where we push a string onto a
118vector, and that never gets flagged in code review. And it's probably like 10
119times more expensive, if not 100 times more expensive, than adding a CHECK. The
120exception to that is if you're in a really hot loop where you don't want to
121dereference a pointer, then a CHECK might add some cost. And the other is if
122the condition that you're trying to validate is really expensive. It's not the
123CHECK itself that's expensive. It's the thing you're evaluating. And if that's
124expensive, then you might not afford doing a CHECK. If you don't know that it's
125expensive, it's probably not expensive.
126
12706:20 SHARON: Can you give us an example of something expensive to evaluate for
128a CHECK?
129
13006:24 PETER: Right. So say that you have something in video code that for every
Daniel Verkamp1de516f2023-10-10 22:17:09131video frame, for every pixel validates the alpha value is opaque, or something.
Nigel Tao187a4792023-09-28 22:30:44132That would probably make video conferencing a little bit worse performance.
133Another thing would just be if you have to traverse a graph on every frame, and
134it will sort of jump all over memory to see if some reachability problem in
135your graph is true, that's going to be a lot more expensive. But CHECKing that
136index is less than some vector bounds, I think that should fall under cheap.
137And -
138
13907:02 SHARON: OK.
140
14107:02 PETER: culturally, we've tried to avoid doing a lot of these. And I think
142it's just hurting us.
143
14407:09 SHARON: OK. So since most places we should use CHECKs, are there any
145places where a DCHECK would be better then? Or any time you would have normally
Daniel Verkamp1de516f2023-10-10 22:17:09146previously used a DCHECK, you should just make that a CHECK?
Nigel Tao187a4792023-09-28 22:30:44147
14807:23 PETER: So we have a new construct that's called `EXPENSIVE_DCHECK`s, or
Daniel Verkamp1de516f2023-10-10 22:17:09149if `EXPENSIVE_DCHECKS_ARE_ON`, I think we should add a corresponding macro for
Nigel Tao187a4792023-09-28 22:30:44150`EXPENSIVE_DCHECK`. And then you should be able to just say, either it's
151expensive and has to be a DCHECK, so use `EXPENSIVE_DCHECK`; otherwise, use
152CHECK. And my hunch would be like 95% of what we have as DCHECKs would probably
153serve us better as CHECKs. But your code owner and reviewer might disagree with
154that. And it's not yet documented policy that we say CHECKs are cheap; just add
155a billion of them. But I would like to get there eventually.
156
15708:04 SHARON: OK. So if you put in a CHECK, and your reviewer tells them this
158should be a DCHECK, the person writing the CL can point them to this video, and
159then they can discuss from there.
160
16108:13 PETER: I mean, yeah, you can either say Peter disagrees with you, or I
162can get further along this and say we make policy that CHECKs are cheap, so
163they are preferable. So a lot of foot-shooters with DCHECKs is that you expect
164this property to hold true, but you never effectively CHECK it. And that can
165lead to all sorts of bad stuff, right? Like if you're trying to DCHECK that
166some origin for some frame makes some assumptions of site iso - I don't know
167site isolation well enough to say this. But basically, if you're DCHECKing that
168the code that you're running runs under some sort of permissions, then that is
169effectively unchecked in stable, right? And we do care about those properties,
170and it would be really good if we crashed rather than leaked information
171between sites.
172
17309:12 SHARON: Right.
174
17509:14 PETER: Yeah.
176
17709:16 SHARON: So that seems like a good tie-in for the fact that within some
178security people, they don't have the most positive impression of DCHECKs, shall
179we say? So a couple examples of this, for listeners who maybe aren't familiar
180with this, is one person previously on security saying DCHECKs are pronounced
181as "code that's not tested". Someone else I told about this episode - I said,
182we're going to talk about DCHECKs - they immediately said, is it going to be
183about why DCHECKs are bad? So amongst the Chrome security folks, they are not a
184huge fan of DCHECKs. Can you tell us maybe why that is?
185
18609:51 PETER: So if we go back a little bit in time, it used to be that DCHECKs
187were only built for developers if they do a debug build. And Chrome has gotten
188so big that you don't want to do a debug build or the UI is incredibly slow.
189Unfortunately, it's sort of not that great an experience to work in a debug
190build. So people work in a release build. That doesn't mean that they don't
191care about the things they put under DCHECK. It just means they want to go on
192with their lives and not wait x minutes for the browser to launch, or however
193bad it is nowadays. And that means that they, unfortunately, lose coverage for
194the DCHECKs. So this means that if your code is not exercised well under tests,
195then this is completely not enforced. But it's slightly better than a comment,
196in that you're really expecting this thing to hold true, and that's clearly an
197expectation. But how good is the expectation if you don't look at it? So last
198year, I believe, we made it so that DCHECKs are on by default if you're not
199doing an official build. And this included release builds. So now, it's like at
200least if you're doing development and you hit this condition, it's going to
201explode, which is really good, because then you can find a lot of issues, and
202we can prevent a lot of issues from ever happening in the first place. It is
203really hard for you, as a developer, to make the assumption that if this
204invariant is ever false, I will find it during development, and it will never
205happen in the wild. And DCHECKs are essentially either, I will find this
206locally before I submit it, or all bets are off; or it is I don't care that
207much if this thing doesn't hold true, which is sort of a weird assertion to
208make. So I think we're in this little awkward in-between state. And this
209in-between state, remember, mostly exists as a performance optimization from
210when CHECKs used to be a lot more expensive, in terms of code size. So did I
211cover most of this?
212
21312:06 SHARON: Yeah. I think, based on that, I think it's pretty easy to see why
214people who are more concerned about security are not a fan of this.
215
21612:13 PETER: I mean, if you care about it, especially if it causes privacy or
217security or user-harm sort of things, just CHECK. Just CHECK, right? If it
218makes your code animate a thing slightly weirder, like it will just jump to the
Daniel Verkamp1de516f2023-10-10 22:17:09219end position instead of going through your fancy little... whatever. Maybe you can
Nigel Tao187a4792023-09-28 22:30:44220make that a DCHECK. Maybe it doesn't matter. Like it's wrong, but it's not that
221bad. But most of the cases, you DCHECK something, where it's like the program
222is going to be in some indeterminate state, and we actually care about if it's
223ever false. So maybe we can afford to make it a CHECK. Maybe we should look
224more about our sort of vector pushbacks than we should look at our CHECKs, and
225then just have more CHECKs. More CHECKs. Because it's also like when things
226break, it's a lot cheaper to debug a DCHECK than your program is in some
227indeterminate state, because it was allowed to pass through a DCHECK that you
228thought was - and when you read the code, unless you're used to reading it as
229DCHECKs - oh, that just didn't get enforced - it's sort of hard to try to
230figure out why the thing was doing the wrong thing in the first place.
231
23213:22 SHARON: OK. How is this as a summary? When in doubt, CHECK it out.
233
23413:27 PETER: I like that. I like that. And you might get pushback by reviewers,
235who aren't on my side of the fence yet. And then you can decide on which hill
236you want to die on, at least until we've made policy to just not complain about
237DCHECKs, or not complain about CHECKs.
238
23913:45 SHARON: All right. That sounds good. So you mentioned stuff failing in
240the wild. And for people who might not know, do you want to just briefly
241explain what failing in the wild means?
242
24313:54 PETER: OK. So there's two things. Just failing in the wild just means
244that when this thing rolls out to Canary, Dev, Beta, Stable, if you have a
245CHECK that will crash and generate a crash report as if you had a memory bug,
246but it crashes in a deterministic way, at a deterministic spot - so you can
247find out exactly what assumption was violated. Say that this should never be
248called with a null pointer. Then you can say, look at this line where it
249crashed. It clearly got hit with a null pointer. And then you can try to figure
250out, from the stack, why that happened, rather than after you post this pointer
251to a task, it crashes somewhere completely irrelevant from the actual call
252site. Well, so in the wild specifically means it generates a crash report so
253you can look at it, or in the wild means it crashes at a user computer rather
254than - in the wildness outside of development. And as for the other part of in
255the wild, it's that we have started running non-crashy DCHECKs for a percentage
256of Windows Canary. And we're looking to expand that. And we're gathering
257information, basically, about which assertions or invariants that we have are
258violated in practice in the wild, even though we don't think that they should
259be. And that will sort of also culturally move the needle so that we do care
260about DCHECKs. And when we care about DCHECKs, sort of similarly to how we care
261about CHECKs, is it really that important to make the big distinction between
262the two? Except for the case where you have really expensive DCHECKs, they
263might still be worth keeping separate. And those will be things like, if you do
264things for - say that you zero out memory or something for every memory block
265that you allocate and free, or you do things for every audio sample, or for
266every video frame pixel, those sort of things. And then we can sort of keep
267expensive stuff gated out from CHECKs. And then maybe we don't need this
268in-between where people don't know whether they can trust a DCHECK or not.
269
27016:04 SHARON: So you mentioned that certain release builds now have DCHECKs
271enabled. So for those in the wild versus regular CHECKs in the wild, if those
272happen to fail, do the reports for those look the same? Are they in the same
273place? Can they be treated the same?
274
27516:20 PETER: Yeah. Well, they are uploaded to the same crash-reporting thing.
276They show up under a special branch. And you likely will get bugs filed to you
277if they hit very frequently, just like you would with crashes. There's a sort
Daniel Verkamp1de516f2023-10-10 22:17:09278of slight difference, in that they say DumpWithoutCrashing. And that's just
Nigel Tao187a4792023-09-28 22:30:44279sort of a rollout strategy for us. Because if we made DCHECK builds incredibly
280crashy, because they hit more than CHECKs, then we can never roll this thing
281out. Or it gets a lot scarier for us to put this on 5% of a new platform that
282we haven't tested. But as it is right now, the first DCHECK that gets hit for
283every process gets a crash dump uploaded.
284
Daniel Verkamp1de516f2023-10-10 22:17:0928517:07 SHARON: OK. So I've been definitely told to use DumpWithoutCrashing at
Nigel Tao187a4792023-09-28 22:30:44286certain points in CLs, where it's like, OK, we think that this shouldn't
287happen. But if it does, we don't necessarily want to crash the browser because
288of it. With the changes you've mentioned to DCHECKs happening, should those
Daniel Verkamp1de516f2023-10-10 22:17:09289just be CHECKs instead now or should those still be DumpWithoutCrashing?
Nigel Tao187a4792023-09-28 22:30:44290
Daniel Verkamp1de516f2023-10-10 22:17:0929117:29 PETER: So if you want DumpWithoutCrashing, and you made those a DCHECK,
Nigel Tao187a4792023-09-28 22:30:44292then you would only have coverage in the Canary channels that we are testing.
293Right? So if you want to get dump reports from the platforms that we're not
294currently testing, including all the way up to Stable, you probably still want
Daniel Verkamp1de516f2023-10-10 22:17:09295to keep that a DumpWithoutCrashing. You want to make sure that you're not
Nigel Tao187a4792023-09-28 22:30:44296using the sort of - you want to make sure that you triage these, because you
Daniel Verkamp1de516f2023-10-10 22:17:09297don't want to keep these generating crash dumps forever. You should still
Nigel Tao187a4792023-09-28 22:30:44298treat them as if they were crashes. And I think the same thing should hold true
299for DCHECKs. You should only add them for an invariant that you care about
300being violated, right? So as it is violated, you should either figure out why
301your invariant was wrong, or you should try to fix the breakage. And you can
302probably add more information to logging to figure out why that happened.
303
30418:41 SHARON: So when you have a CHECK, and it crashes in the wild, you get a
305stack trace. And that's what you have to work on to figure out what went wrong
306for debugging. Right? So what are some things that you can do, as a developer,
307to make these CHECKs a bit more useful for you - ways to incorporate other
308information that you can use to help yourself debug?
309
31019:01 PETER: So some of the stuff that we have is we have something called
311crash keys, which are essentially, you can write a piece of string data,
312essentially - there's probably some other data types - and if you write those
Daniel Verkamp1de516f2023-10-10 22:17:09313before you're running DumpWithoutCrashing, or before you hit a CHECK, or
Nigel Tao187a4792023-09-28 22:30:44314before you hit a DCHECK, then those will be uploaded along the crash dump. And
315if you talk to someone who knows where to find them, you can basically go in
Daniel Verkamp1de516f2023-10-10 22:17:09316under a crash report, and then under Fields, Product data, or something like
Nigel Tao187a4792023-09-28 22:30:44317that, you should be able to find your key-value pair. And if you have
318information in there, you'll be able to look at it. The other thing that I like
319to do, which is probably the more obvious thing, is if you have somewhat of a
320hypothesis that this thing should only fail if a or b or c is not true, then
321you can add CHECKs for those. Like, if a CHECK is failing, you can add more
322CHECKs to see why the CHECK was failing. In general, you're not going to get as
323much out of a mini-dump that you want. You're not going to have the full heap
324available to you, because that would be a mega-dump. You can usually find
325whatever is on the stack if you go in with a debugger. And I know that you
326wanted to lead me into talking about CHECK\_GT and CHECK\_EQ, which are
327essentially, if you want to check that x is greater than y, then you should use
328CHECK\_GT(x,y). The problem with those, in this sort of context, is that,
329similarly to CHECKs - so CHECK\_GT gets compiled into, basically, if not x is
330greater than y, crash. So unfortunately, the values of x and y are optimized
331out when you're doing an official build.
332
33321:02 SHARON: So this makes me think of some stuff we mentioned in the last
334episode, which was with Dana. Check it out if you haven't. But one of the types
335we mentioned there was SafeRef, which enforces a certain condition. And if that
336fails - so in the case of a SafeRef, it ensures that the value you have there
337is not null. And if that's ever not true, then you do get a crash similar to if
338a CHECK fails. So in general, would you say it's better practice to enforce and
339make sure your assumptions are held in these other, more structural ways than
340relying on CHECKs instead?
341
34221:41 PETER: So let me see if I can get at what you actually want out of that
343one. So if we look at - there's a RawRef type, right? So what's good with the
344RawRef is that you have a type that annotates that this thing cannot possibly
345be null. So if you assign to it, and you're assigning a null pointer, your
346program is going to crash, and you don't need to think about whether you throw
347a null pointer in or not. If you keep passing a RawRef around, then that's
348essentially you passing around a non-null pointer. And therefore, you don't
Daniel Verkamp1de516f2023-10-10 22:17:09349have to check that it's not `nullptr` in every step of the way. You only
Nigel Tao187a4792023-09-28 22:30:44350need to do it when you're - I mean, the type will do it for you, but it only
351needs to happen when you're converting from a pointer to a ref, essentially, or
352a RawRef. And what's so good about that is now you have the - previously, you
Daniel Verkamp1de516f2023-10-10 22:17:09353might just CHECK that this isn't called with `nullptr` or whatever. But then
Nigel Tao187a4792023-09-28 22:30:44354you would do that for four or five arguments. And you'd be like, null pointer
355CHECKs are this part of the function body. And then it just gets super-noisy.
356But if you're using the RawRef types, then the semantics of the type will
357enforce that for you. And you don't have to think about that when reading the
358code, because usually when you read the code, you're going to be like, it's a
359pointer. Can it be null or not? What does it point to? And this thing will at
360least tell you, it can't be null. And you still have the question of, what does
361it point to? And that's fine. So I like enforcing this through types more than
362checking those assumptions, and then checking inside of what happens. If you
363were assigned to this RawRef, then it's going to crash in the constructor if
364you have a null pointer. And then based on that stack trace, if we have good
365stack data, you're going to know at what line you created the RawRef. And
366therefore, it's equivalent to checking for not null pointer, because you can
367trust the type to do the checking. And since I know Dana made this, I can
368probably with 200% certainty say that it's a CHECK and not a DCHECK. But we do
369have a couple of other places where you have a WeakPtr that shouldn't be
370dereferenced on the wrong sequence. And those are complicated words. And that,
371unfortunately, is a DCHECK. So we're hitting some sort of - I don't know if
372that CHECK is actually expensive, or if it should be a CHECK, or if it could be
373a CHECK. I think, especially, if you're in core types, the size overhead of
374adding a CHECK is negligible, because all of the users of it benefit from that
375CHECK. So unless it's incredibly -
376
37724:28 SHARON: What do you mean by core types?
378
Daniel Verkamp1de516f2023-10-10 22:17:0937924:30 PETER: Say that you make a `scoped_refptr` or something, that ref pointer is
Nigel Tao187a4792023-09-28 22:30:44380used everywhere. So if you CHECKed in the destructor, then you're validating
Daniel Verkamp1de516f2023-10-10 22:17:09381all of the clients of your `scoped_refptr`. So for one CHECK, you get the
Nigel Tao187a4792023-09-28 22:30:44382price of a lot of CHECKing. Whereas if in your client code you're validating
383some parameters of an API call that only gets called once, then that's one
384CHECK you add for one case. But if you're re-use, then your CHECK gets a lot
385more value. And it's also easier to get parameters wrong sometimes if you have
386500 clients that are calling your API. You can't trust all of them to get it
387right. Whereas if you're just developing your feature, and it's only used by
388your feature, then you can be a little bit more certain with how it's being
389called. I would say, still add CHECKs, because code evolves over time. It's
390sort of like how you can add unit tests to make sure that no one breaks your
391code in the future. If you add CHECKs, then no one can break your code in the
392future.
393
39425:37 SHARON: Mm-hmm. OK. So you mentioned a few things about how CHECKs and
395DCHECKs are changing. [AUDIO OUT] what is currently in the works, and what is
396the long-term goal and plan for CHECKs and DCHECKs.
397
39825:53 PETER: So currently what's in the work is we've made sure that some
399libraries that we use, like Abseil and WebRTC, which is a first-party
400third-party library, that they both use Chrome's crashing report system, which
401means that you get more predictable crash stacks because it's using the
Daniel Verkamp1de516f2023-10-10 22:17:09402IMMEDIATE\_CRASH macro. But also, you get the fatal logging field that I talked
Nigel Tao187a4792023-09-28 22:30:44403about. That gets logged as part of crash dumps. So you hopefully have more
404glanceable, actionable crash reports whenever a CHECK is violated inside of
405Abseil, or in WebRTC, as it were. And then upcoming is we want to make sure
406that we keep an eye out for our DCHECKs on other platforms, such as Mac. I know
407that there's some issues with getting that fatal log field in the GPU process,
408and I'm working on fixing that as well. So hopefully, it just means more
409reports for the things you care about and easier to action on reports. That's
410what we're hoping.
411
41227:03 SHARON: If people think that this sounds really cool, want to have some
413more involvement, or want to ask more questions, what's a good place for them
414to do that?
415
41627:11 PETER: I like Slack as a thing for this. So the #cxx channel on Slack,
417the #base channel on Slack, the #halp channel on Slack is really good. #halp is
418really, I think, unintimidating. You can just throw whatever question you have
419in there, and I happen to be around there. If you can find out what my last
420name is through sheer force of will, you can send me an email to my Chromium
421username. What else would we have? I think if they want to get involved, just
422add CHECKs to your code. That's a really good way to do it. Just make sure that
423your code does what you expect it to in more cases.
424
42527:48 SHARON: Maybe if you have a CL, and you're just doing some drive-by
426cleanup, you can turn some DCHECKs into CHECKs also?
427
42827:56 PETER: If your reviewer is cool with that, I'm cool with that. Otherwise,
429you can just try to hope for us making that policy that we use CHECKs - if it's
430something we care about, we use a CHECK instead of a DCHECK, unless we have a
431really good reason to use a DCHECK. And that would be performance.
432
43328:15 SHARON: That sounds good. And one last question is, what do you want
434people to take away as their main takeaway from this discussion?
435
43628:26 PETER: I think validating code assumptions is really valuable. So you
437think that you're pretty smart when you're writing something, or you remember -
438I mean, you're sometimes kind of smart when you're writing something. And
439you're like, this can't possibly be wrong. And in practice, looking at crash
440reports, these things are wrong all the time. So please validate any
441assumptions that you make. It's also, I would say, better than a comment,
442because it's a comment that doesn't get outdated without you noticing it. So, I
443think, validate your assumptions to make sure that your code is more robust.
444And validate properties you care about. And don't be afraid to use CHECKs.
445
44629:13 SHARON: All right. That sounds like a good summary. Thank you very much
447for being here, Peter. It was great to learn about DCHECKs.
448
44929:18 PETER: Yeah. Thanks for having me.
450
45129:24 SHARON: Action. Hello.
452
45329:26 PETER: Oh. Take four.
454
45529:29 SHARON: [LAUGHS] Take four. And action.
Daniel Verkamp1de516f2023-10-10 22:17:09456
457[What's Up With Pointers]: https://www.youtube.com/watch?v=MpwbWSEDfjM