In my down times of other work I've been plugging away at trying to reduce some of the warnings in blink with regards to 64 bit to 32 bit truncation.Now the main issues left are those with Vector and String. I thought I'd ask about guidance here before I attempt any patches.Vector and String are using unsigned as the backing store size of the data but on an API level they are kind of incongruent.For example String takes an unsigned value yet returns a size_t for find.Likewise for Vector there is an implicit expansion to size_t on the size() API.These cause all kinds of truncation errors because consumers of the API might be using unsigned indexes but the return value is a size_t.
Thoughts on this? I'm on the fence either way. The API could either solely use size_t (although I don't know for what purpose) or they could be converted to unsigned (32 bit always, perhaps there are perf benefits?)
With my OO hat on I'd argue that VectorBufferBase should really be defined having a template class attribute for the storage. But that is likely overkill.
I found an old bug yosin@ opened up before.dave.
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architecture-dev+unsub...@chromium.org.
To post to this group, send email to platform-architecture-dev@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CAHXv1w%3D1_WPgAcKqAH%2BBpjoKtRTSVXbxcuDNTaAPJbJ6SjF4nA%40mail.gmail.com.
On Tue, Jun 12, 2018 at 9:44 AM, Dave Tapuska <dtap...@chromium.org> wrote:In my down times of other work I've been plugging away at trying to reduce some of the warnings in blink with regards to 64 bit to 32 bit truncation.Now the main issues left are those with Vector and String. I thought I'd ask about guidance here before I attempt any patches.Vector and String are using unsigned as the backing store size of the data but on an API level they are kind of incongruent.For example String takes an unsigned value yet returns a size_t for find.Likewise for Vector there is an implicit expansion to size_t on the size() API.These cause all kinds of truncation errors because consumers of the API might be using unsigned indexes but the return value is a size_t.Just compile warnings, or are you seeing actual problems at runtime? I had a vague impression that we never allocate a StringImpl or vector buffer that is >4 GiB large.Thoughts on this? I'm on the fence either way. The API could either solely use size_t (although I don't know for what purpose) or they could be converted to unsigned (32 bit always, perhaps there are perf benefits?)I'd lean mildly toward unsigned in general. I think some of those were changed to correspond more closely with STL types, but I doubt it makes much of a difference.With my OO hat on I'd argue that VectorBufferBase should really be defined having a template class attribute for the storage. But that is likely overkill.There isn't enough template magic yet in Vector/VectorBuffer/VectorBufferBase/PartitionAllocator/etc? :P
I found an old bug yosin@ opened up before.dave.
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CAHXv1wmC9OxFwXv1YeugN8CB9htzLy%2Bf8zOxi3Ho7nQkShiLFQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CAOuvq20TZ0GpVS%2BaFQYJFp_e4bh%3DtbGg4VmVy837e9GNbDGyag%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CABg10jw4mYCw56LFsMnR7HO2DCntc7zRKKvVVVPPU6ryv-2uEQ%40mail.gmail.com.
I would say let's use just unsigned. unsigned is our size_t, essentially.
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CAFJcur90sE-1VAcdryiQ1gDcpAeJedB3gMb%3D5DW6MxZGTfu6iw%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/fad2e748-8623-425f-acae-6e3d6a283665%40chromium.org.
Size_t is an unsigned type. So you have the exact same overflow problems with using uint32_t.
The guidance actually shows that we really should be using int64_t in these cases.
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CAAHOzFAqzSpgOsdoethwRAC1-ohGC2WtfV6w4DY_G1kdA2aWLw%40mail.gmail.com.
On Sat, Jul 21, 2018 at 6:05 PM Dave Tapuska <dtap...@chromium.org> wrote:Size_t is an unsigned type. So you have the exact same overflow problems with using uint32_t.size_t is not designed to be used in scenarios where overflow is possible. It's supposed to be able to contain the size of any memory-allocated sequence of units on your platform, and be used to iterate through them. If used in that way, overflow should never occur, so overflow being undefined is not a problem.
Hi Peter,WTF containers use unsigned int (aka uint32_t) intentionally. AFAIK using size_t in WTF containers is NOT acceptable for us, as it would churn the performance numbers. I haven't tried to measure the effect myself, though.
On Mon, Jul 23, 2018 at 3:08 PM Peter Kasting <pkas...@chromium.org> wrote:Here's a possible route forward that could satisfy everyone:* Introduce a wtf_size_t type alias. Rewrite everything in terms of this alias.* Perf test with the alias set to e.g. size_t vs. uint32_t.* If there aren't significant losses from using size_t, then it's trivial to use a plugin to mechanically rewrite wtf_size_t to size_t and be done without having taken much more work than to use size_t to start with.* If there are significant losses, then the type alias definition point becomes the place where this can be documented, and the use of types in the code will be clear as to the intent -- since one of the advantages of size_t over uint32_t is that its meaning is more specific and clear.WDYT?I don't disagree on your plan, but I personally don't have time to do this,
and it seems like the plan has a limited benefit with a lot of cost (merely conversions to wtf_size_t would require a lot of effort),
so it doesn't look beneficial for us overall.
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CAAHOzFC1M%2B%3DQT3RNXcGyiL3jhB%3DSdNiFdSe%2Bxsa-%3DYrsX33QxQ%40mail.gmail.com.
Peter just so my interpretation is correct you expect StringView and friends would change to be wtf_size_t based right? That will be a big undertaking.
Just help me understand: What are the main practical reasons for banning uint32_t?
I'd disagree with changing the type of the internal storage of String / Vector etc from uint32_t to size_t. WTF is a fundamental library of Blink and thus must be extremely optimized for performance and memory. Even though it doesn't show regressions in some representative benchmarks, I'd prefer NOT making the change unless we have a very strong reason to do so (e.g., using size_t matters for security).
I'm open for ideas about the type used in their APIs though. I think we have three options.a) uint32_tb) size_tc) wtf_size_t (alias of uint32_t)Today we're using b), and the type mismatch between the internal implementation and the external API is exactly the problem Dave is addressing now. So b) is not an option.
On Mon, Jul 23, 2018 at 9:20 AM Kentaro Hara <har...@chromium.org> wrote:I'd disagree with changing the type of the internal storage of String / Vector etc from uint32_t to size_t. WTF is a fundamental library of Blink and thus must be extremely optimized for performance and memory. Even though it doesn't show regressions in some representative benchmarks, I'd prefer NOT making the change unless we have a very strong reason to do so (e.g., using size_t matters for security).OK.I'm open for ideas about the type used in their APIs though. I think we have three options.a) uint32_tb) size_tc) wtf_size_t (alias of uint32_t)Today we're using b), and the type mismatch between the internal implementation and the external API is exactly the problem Dave is addressing now. So b) is not an option.If the problem being addressed is warnings, it seems like it would be sufficient to insert explicit casts in the implementation when an incoming size_t needs to be truncated. Would that make (b) work?
That's the route the Chromium style guide suggests, it's less effort than changing consumers of these APIs to use a different type if they're already using size_t, and it's reasonably future-proof (since changing to use size_t someday would only require modifying the implementations of these classes and not the API or users thereof).I guess I'm still not clear on why this isn't a viable path forward.PK
On Mon, Jul 23, 2018 at 7:13 PM Peter Kasting <pkas...@chromium.org> wrote:On Mon, Jul 23, 2018 at 9:20 AM Kentaro Hara <har...@chromium.org> wrote:I'd disagree with changing the type of the internal storage of String / Vector etc from uint32_t to size_t. WTF is a fundamental library of Blink and thus must be extremely optimized for performance and memory. Even though it doesn't show regressions in some representative benchmarks, I'd prefer NOT making the change unless we have a very strong reason to do so (e.g., using size_t matters for security).OK.I'm open for ideas about the type used in their APIs though. I think we have three options.a) uint32_tb) size_tc) wtf_size_t (alias of uint32_t)Today we're using b), and the type mismatch between the internal implementation and the external API is exactly the problem Dave is addressing now. So b) is not an option.If the problem being addressed is warnings, it seems like it would be sufficient to insert explicit casts in the implementation when an incoming size_t needs to be truncated. Would that make (b) work?Then we need to use checked casts (because it would not be a good idea to implicitly cast size_t to uint32_t).
I would certainly expect a checked_cast route to cause perf regressions, and I wouldn't go that route. static_cast is better here.PK
So... I think we have the following options:a) internal type = size_t, external type = size_t (We need to prove that this doesn't regress anything.)b) internal type = uint32_t, external type = size_t (We need to introduce checked_cast. We confirmed that this is not acceptable for performance.)c) internal type = uint32_t, external type = uint32_t (This is not nice per coding guideline.)d) internal type = uint32_t, external type = wtf_size_t (defined as uint32_t)