[webkit-dev] Compile-time assertions for object sizes

2011-09-29 Thread Andreas Kling
Dear WebKittens,

I'd like to add some compile-time assertions for the sizes of various
objects. The motivation comes a patch fixing bloat in InlineBox[1].

There are two major problems with this:

1. The sizes will differ on 32- and 64-bit platforms.
2. The sizes will differ based on compiler flags.

One idea is to add a file that would only be built on (for example) 64-bit
Mac and then at least that bot would break if an object changes size. That's
obviously not ideal though.

Any suggestions? :)

-Kling

[1] https://bugs.webkit.org/show_bug.cgi?id=64914
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] Compile-time assertions for object sizes

2011-09-29 Thread David Levin
On Thu, Sep 29, 2011 at 12:11 PM, Simon Fraser simon.fra...@apple.comwrote:


 On Sep 29, 2011, at 11:40 AM, Andreas Kling wrote:

  Dear WebKittens,
 
  I'd like to add some compile-time assertions for the sizes of various
 objects. The motivation comes a patch fixing bloat in InlineBox[1].
 
  There are two major problems with this:
 
  1. The sizes will differ on 32- and 64-bit platforms.
  2. The sizes will differ based on compiler flags.
 
  One idea is to add a file that would only be built on (for example)
 64-bit Mac and then at least that bot would break if an object changes size.
 That's obviously not ideal though.
 
  Any suggestions? :)

 You could group the bits together into a struct:

  struct {
m_foo: 1;
m_bar: 1;
...
  } m_bits;

 COMPILE_ASSERT(sizeof(m_bits) = sizeof(uint32_t), Too_many_bits);

 This wouldn't' be sensitive to architecture.

 Simon


Perhaps you'll find some inspiration in
http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/wtf/SizeLimits.cppwhere
this is done for a few structs in wtf.

I tried to use sizeof(int*) where I needed to deal with 32 vs 64 pointer
issues and I put in an ifdef for a debug related size thing.

dave
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] Compile-time assertions for object sizes

2011-09-29 Thread Simon Fraser

On Sep 29, 2011, at 11:40 AM, Andreas Kling wrote:

 Dear WebKittens,
 
 I'd like to add some compile-time assertions for the sizes of various 
 objects. The motivation comes a patch fixing bloat in InlineBox[1].
 
 There are two major problems with this:
 
 1. The sizes will differ on 32- and 64-bit platforms.
 2. The sizes will differ based on compiler flags.
 
 One idea is to add a file that would only be built on (for example) 64-bit 
 Mac and then at least that bot would break if an object changes size. That's 
 obviously not ideal though.
 
 Any suggestions? :)

You could group the bits together into a struct:

  struct {
m_foo: 1;
m_bar: 1;
...
  } m_bits;

COMPILE_ASSERT(sizeof(m_bits) = sizeof(uint32_t), Too_many_bits);

This wouldn't' be sensitive to architecture.

Simon

___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] Compile-time assertions for object sizes

2011-09-29 Thread Andreas Kling
On Thu, Sep 29, 2011 at 9:11 PM, Simon Fraser simon.fra...@apple.comwrote:


 On Sep 29, 2011, at 11:40 AM, Andreas Kling wrote:

  Dear WebKittens,
 
  I'd like to add some compile-time assertions for the sizes of various
 objects. The motivation comes a patch fixing bloat in InlineBox[1].
 
  There are two major problems with this:
 
  1. The sizes will differ on 32- and 64-bit platforms.
  2. The sizes will differ based on compiler flags.
 
  One idea is to add a file that would only be built on (for example)
 64-bit Mac and then at least that bot would break if an object changes size.
 That's obviously not ideal though.
 
  Any suggestions? :)

 You could group the bits together into a struct:

  struct {
m_foo: 1;
m_bar: 1;
...
  } m_bits;

 COMPILE_ASSERT(sizeof(m_bits) = sizeof(uint32_t), Too_many_bits);

 This wouldn't' be sensitive to architecture.



Good idea in general, though it doesn't work for InlineBox since its bits
are spread across public, protected and private.
I'm not sure it's worth losing those classifications for the sake of the
anti-bloat mechanism.

-Kling
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] Compile-time assertions for object sizes

2011-09-29 Thread Darin Adler
On Sep 29, 2011, at 1:40 PM, Andreas Kling wrote:

 Good idea in general, though it doesn't work for InlineBox since its bits are 
 spread across public, protected and private.
 I'm not sure it's worth losing those classifications for the sake of the 
 anti-bloat mechanism.

We wouldn’t have to lose those classifications. We’d just have to lose our 
convention that all public are grouped together, etc. We can intersperse 
public/protected/private keywords between bitfield definitions.

-- Darin

___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] Compile-time assertions for object sizes

2011-09-29 Thread Andreas Kling
On Thu, Sep 29, 2011 at 10:43 PM, Darin Adler da...@apple.com wrote:

 On Sep 29, 2011, at 1:40 PM, Andreas Kling wrote:

  Good idea in general, though it doesn't work for InlineBox since its bits
 are spread across public, protected and private.
  I'm not sure it's worth losing those classifications for the sake of the
 anti-bloat mechanism.

 We wouldn’t have to lose those classifications. We’d just have to lose our
 convention that all public are grouped together, etc. We can intersperse
 public/protected/private keywords between bitfield definitions.


Right, but those keywords would pertain to the struct containing the
bitfields, not InlineBox itself. Or maybe I'm misunderstanding you?

-Kling
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] Compile-time assertions for object sizes

2011-09-29 Thread Darin Adler
On Sep 29, 2011, at 1:48 PM, Andreas Kling wrote:

 Right, but those keywords would pertain to the struct containing the 
 bitfields, not InlineBox itself. Or maybe I'm misunderstanding you?

Yes, I was wrong, you are right.

I had lost the thread. I’m not sure we need to group bit fields in a struct.

I think it is practical to write the size assertions in a way that works both 
in 32- and 64-bit. David Levin found some good techniques that he used in 
SizeLimits.cpp.

-- Darin

___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] Compile-time assertions for object sizes

2011-09-29 Thread Antti Koivisto
On Thu, Sep 29, 2011 at 9:40 PM, Andreas Kling kl...@webkit.org wrote:

 One idea is to add a file that would only be built on (for example) 64-bit
 Mac and then at least that bot would break if an object changes size. That's
 obviously not ideal though.


I like that approach as it allows you to explicitly assert against byte
counts. Other approaches are more abstract and so easier to dismiss when
checking in a bloaty patch. It also documents the byte sizes and makes
progressions explicit too.


   antti
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev