Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Issue 2191163003: Add compile time assert to help catch new fields (Closed)

Created:
4 years, 4 months ago by Bryan McQuade
Modified:
4 years, 1 month ago
CC:
chromium-reviews, csharrison+watch_chromium.org, loading-reviews+metrics_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@fixequal
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Add compile time assert to help catch new fields. We recently encountered a case where a field in PageLoadTiming wasn't included in the operator== and IsEmpty implementations. This compile-time assert is intended to make developers aware that they need to update the implementations of these functions any time they add a new field to PageLoadTiming. BUG=632832

Patch Set 1 #

Patch Set 2 : fix comment #

Patch Set 3 : fix comment #

Total comments: 1

Patch Set 4 : add comment #

Total comments: 4

Patch Set 5 : address kinuko comments #

Patch Set 6 : address kinuko comments #

Patch Set 7 : remove comment #

Unified diffs Side-by-side diffs Delta from patch set Stats (+19 lines, -0 lines) Patch
M chrome/common/page_load_metrics/page_load_timing.cc View 1 2 3 4 5 6 1 chunk +19 lines, -0 lines 0 comments Download

Messages

Total messages: 36 (28 generated)
kinuko
https://codereview.chromium.org/2191163003/diff/40001/chrome/common/page_load_metrics/page_load_timing.cc File chrome/common/page_load_metrics/page_load_timing.cc (right): https://codereview.chromium.org/2191163003/diff/40001/chrome/common/page_load_metrics/page_load_timing.cc#newcode29 chrome/common/page_load_metrics/page_load_timing.cc:29: "Make sure to update IsEmpty and operator== to reflect ...
4 years, 4 months ago (2016-08-01 15:38:00 UTC) #11
Bryan McQuade
On 2016/08/01 at 15:38:00, kinuko wrote: > https://codereview.chromium.org/2191163003/diff/40001/chrome/common/page_load_metrics/page_load_timing.cc > File chrome/common/page_load_metrics/page_load_timing.cc (right): > > https://codereview.chromium.org/2191163003/diff/40001/chrome/common/page_load_metrics/page_load_timing.cc#newcode29 ...
4 years, 4 months ago (2016-08-02 14:33:56 UTC) #15
kinuko
lgtm % some nits https://codereview.chromium.org/2191163003/diff/60001/chrome/common/page_load_metrics/page_load_timing.cc File chrome/common/page_load_metrics/page_load_timing.cc (right): https://codereview.chromium.org/2191163003/diff/60001/chrome/common/page_load_metrics/page_load_timing.cc#newcode18 chrome/common/page_load_metrics/page_load_timing.cc:18: // operator== and IsEmpty below ...
4 years, 4 months ago (2016-08-02 16:09:00 UTC) #18
Bryan McQuade
Thanks! I've addressed these comments. I decided to go forward with this change. csharrison, can ...
4 years, 3 months ago (2016-09-07 11:13:17 UTC) #28
Charlie Harrison
Curious, have you considered using a presubmit here? Even a dead simple warning like "You ...
4 years, 3 months ago (2016-09-07 15:03:11 UTC) #33
Bryan McQuade
On 2016/09/07 at 15:03:11, csharrison wrote: > Curious, have you considered using a presubmit here? ...
4 years, 3 months ago (2016-09-07 15:08:09 UTC) #34
Charlie Harrison
On 2016/09/07 15:08:09, Bryan McQuade wrote: > On 2016/09/07 at 15:03:11, csharrison wrote: > > ...
4 years, 3 months ago (2016-09-07 15:12:44 UTC) #35
Bryan McQuade
4 years, 3 months ago (2016-09-08 11:55:26 UTC) #36
On 2016/09/07 at 15:12:44, csharrison wrote:
> On 2016/09/07 15:08:09, Bryan McQuade wrote:
> > On 2016/09/07 at 15:03:11, csharrison wrote:
> > > Curious, have you considered using a presubmit here? Even a dead simple
> > warning like "You updated PageLoadTiming, did you update operator==... y/N"
> > might be just as effective as this.
> > 
> > That's an interesting idea that I hadn't considered - thanks for suggesting
it!
> > I think I prefer auditing this directly at compile time, both because the
> > presubmit might be noisy (presumably it would fire on any change to
> > page_load_metrics.h, even if we aren't adding TimeDelta fields - that's a
bit
> > confusing), because it's possible to bypass presubmits (hopefully nobody
does
> > so, but it's possible), and because presubmits trigger much later in the
> > development process than compile time assertions. Given that this is
reasonably
> > simple and self contained in one anonymous namespace block, I think this
> > approach strikes the best overall balance between the various options. What
do
> > you think?
> 
> I would personally prefer a presubmit, as this code is confusing and seems
fragile if any part of PageLoadTiming internals changes (or the time classes
change).
> 
> However, I don't feel strongly enough to block this, so lgtm if you prefer
this way.

Yeah, it's a good point - I will take a look at the presubmit and see what's
possible there. Will follow up soon.

Powered by Google App Engine
This is Rietveld 408576698