WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
191811
Make lossy LayoutUnit constructors explicit
https://bugs.webkit.org/show_bug.cgi?id=191811
Summary
Make lossy LayoutUnit constructors explicit
Ross Kirsling
Reported
2018-11-17 14:11:33 PST
Make unsigned LayoutUnit constructors explicit
Attachments
Patch
(7.17 KB, patch)
2018-11-17 14:14 PST
,
Ross Kirsling
no flags
Details
Formatted Diff
Diff
Patch
(26.89 KB, patch)
2018-11-17 17:43 PST
,
Ross Kirsling
ews-watchlist
: commit-queue-
Details
Formatted Diff
Diff
Archive of layout-test-results from ews101 for mac-sierra
(341.44 KB, application/zip)
2018-11-17 18:35 PST
,
EWS Watchlist
no flags
Details
Archive of layout-test-results from ews106 for mac-sierra-wk2
(350.52 KB, application/zip)
2018-11-17 18:44 PST
,
EWS Watchlist
no flags
Details
Archive of layout-test-results from ews116 for mac-sierra
(315.80 KB, application/zip)
2018-11-17 18:49 PST
,
EWS Watchlist
no flags
Details
Archive of layout-test-results from ews200 for win-future
(1.37 MB, application/zip)
2018-11-17 19:09 PST
,
EWS Watchlist
no flags
Details
Patch
(33.45 KB, patch)
2018-11-19 23:57 PST
,
Ross Kirsling
ews-watchlist
: commit-queue-
Details
Formatted Diff
Diff
Archive of layout-test-results from ews102 for mac-sierra
(428.07 KB, application/zip)
2018-11-20 00:50 PST
,
EWS Watchlist
no flags
Details
Archive of layout-test-results from ews106 for mac-sierra-wk2
(479.30 KB, application/zip)
2018-11-20 00:56 PST
,
EWS Watchlist
no flags
Details
Patch
(190.65 KB, patch)
2018-11-21 16:43 PST
,
Ross Kirsling
no flags
Details
Formatted Diff
Diff
Patch
(141.81 KB, patch)
2018-11-23 15:01 PST
,
Ross Kirsling
no flags
Details
Formatted Diff
Diff
Patch
(139.58 KB, patch)
2018-11-23 23:21 PST
,
Ross Kirsling
no flags
Details
Formatted Diff
Diff
Patch
(143.13 KB, patch)
2018-11-24 00:16 PST
,
Ross Kirsling
no flags
Details
Formatted Diff
Diff
Patch
(150.56 KB, patch)
2019-01-07 15:06 PST
,
Ross Kirsling
no flags
Details
Formatted Diff
Diff
Patch for landing
(150.68 KB, patch)
2019-05-20 15:30 PDT
,
Ross Kirsling
no flags
Details
Formatted Diff
Diff
Patch for landing
(151.55 KB, patch)
2019-05-20 17:55 PDT
,
Ross Kirsling
no flags
Details
Formatted Diff
Diff
Show Obsolete
(15)
View All
Add attachment
proposed patch, testcase, etc.
Ross Kirsling
Comment 1
2018-11-17 14:14:59 PST
Created
attachment 355205
[details]
Patch
Ross Kirsling
Comment 2
2018-11-17 17:43:07 PST
Created
attachment 355215
[details]
Patch
Ross Kirsling
Comment 3
2018-11-17 18:01:07 PST
Turns out this patch is relatively small, as long as we leave LayoutUnit(int) implicit. If this is acceptable, then I think
bug 191538
can simply be closed.
EWS Watchlist
Comment 4
2018-11-17 18:35:18 PST
Comment hidden (obsolete)
Comment on
attachment 355215
[details]
Patch
Attachment 355215
[details]
did not pass mac-ews (mac): Output:
https://webkit-queues.webkit.org/results/10049860
Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 5
2018-11-17 18:35:20 PST
Comment hidden (obsolete)
Created
attachment 355219
[details]
Archive of layout-test-results from ews101 for mac-sierra The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews101 Port: mac-sierra Platform: Mac OS X 10.12.6
EWS Watchlist
Comment 6
2018-11-17 18:44:46 PST
Comment hidden (obsolete)
Comment on
attachment 355215
[details]
Patch
Attachment 355215
[details]
did not pass mac-wk2-ews (mac-wk2): Output:
https://webkit-queues.webkit.org/results/10049861
Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 7
2018-11-17 18:44:47 PST
Comment hidden (obsolete)
Created
attachment 355220
[details]
Archive of layout-test-results from ews106 for mac-sierra-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews106 Port: mac-sierra-wk2 Platform: Mac OS X 10.12.6
EWS Watchlist
Comment 8
2018-11-17 18:49:31 PST
Comment hidden (obsolete)
Comment on
attachment 355215
[details]
Patch
Attachment 355215
[details]
did not pass mac-debug-ews (mac): Output:
https://webkit-queues.webkit.org/results/10049818
Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 9
2018-11-17 18:49:33 PST
Comment hidden (obsolete)
Created
attachment 355221
[details]
Archive of layout-test-results from ews116 for mac-sierra The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews116 Port: mac-sierra Platform: Mac OS X 10.12.6
EWS Watchlist
Comment 10
2018-11-17 19:09:06 PST
Comment hidden (obsolete)
Comment on
attachment 355215
[details]
Patch
Attachment 355215
[details]
did not pass win-ews (win): Output:
https://webkit-queues.webkit.org/results/10049969
Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 11
2018-11-17 19:09:09 PST
Comment hidden (obsolete)
Created
attachment 355222
[details]
Archive of layout-test-results from ews200 for win-future The attached test failures were seen while running run-webkit-tests on the win-ews. Bot: ews200 Port: win-future Platform: CYGWIN_NT-6.1-2.9.0-0.318-5-3-x86_64-64bit
Ross Kirsling
Comment 12
2018-11-19 23:57:26 PST
Created
attachment 355317
[details]
Patch
EWS Watchlist
Comment 13
2018-11-20 00:50:38 PST
Comment hidden (obsolete)
Comment on
attachment 355317
[details]
Patch
Attachment 355317
[details]
did not pass mac-ews (mac): Output:
https://webkit-queues.webkit.org/results/10085371
Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 14
2018-11-20 00:50:40 PST
Comment hidden (obsolete)
Created
attachment 355318
[details]
Archive of layout-test-results from ews102 for mac-sierra The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews102 Port: mac-sierra Platform: Mac OS X 10.12.6
EWS Watchlist
Comment 15
2018-11-20 00:56:52 PST
Comment hidden (obsolete)
Comment on
attachment 355317
[details]
Patch
Attachment 355317
[details]
did not pass mac-wk2-ews (mac-wk2): Output:
https://webkit-queues.webkit.org/results/10085374
Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 16
2018-11-20 00:56:54 PST
Comment hidden (obsolete)
Created
attachment 355321
[details]
Archive of layout-test-results from ews106 for mac-sierra-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews106 Port: mac-sierra-wk2 Platform: Mac OS X 10.12.6
Ross Kirsling
Comment 17
2018-11-20 23:51:49 PST
It seems I was a little confused earlier. Although there are few cases of implicit LayoutUnit(unsigned) and LayoutUnit(double) in use, there are hundreds of cases of implicit LayoutUnit(float). The misleading part was that we can successfully compile without addressing them (since floats will end up using the implicit LayoutUnit(int) constructor), but naturally this has unpredictable effects on runtime behavior. So to handle this properly without a decrease in ergonomics, we still need all of those templates, and definitely will want to introduce that "0_lu" literal first.
Ross Kirsling
Comment 18
2018-11-21 16:43:37 PST
Created
attachment 355445
[details]
Patch
Ross Kirsling
Comment 19
2018-11-23 15:01:06 PST
Created
attachment 355537
[details]
Patch
Ross Kirsling
Comment 20
2018-11-23 23:21:25 PST
Created
attachment 355553
[details]
Patch
Ross Kirsling
Comment 21
2018-11-24 00:16:31 PST
Created
attachment 355556
[details]
Patch
Ross Kirsling
Comment 22
2018-11-24 00:18:41 PST
The new title here is more accurate description of the sole benefit I can see to this: to ensure that conversions from float/double don't just magically happen. We can do this by adding either templates or float overloads to LayoutPoint, LayoutSize, LayoutRect, and the like. This patch demonstrates the former; the latter would be a somewhat larger patch. Templates might be more opaque but they do support double, say, at the same time. This patch is now just a third of the size of the original; I'm hoping it's reviewable as is, mainly since I'm not sure if anything in the patch would be desired independent of the motivation to make LayoutUnit explicit. Outside of the templates, every change should involve constructing or converting a LayoutUnit lvalue from a float-valued expression, e.g.: - LayoutUnit foo = ...; => LayoutUnit foo { ... }; - return ...; => return LayoutUnit(...); - std::max<LayoutUnit>(..., ...) => std::max(LayoutUnit(...), ...) - LayoutPoint(..., ...) => { LayoutUnit(...), ... }
Ross Kirsling
Comment 23
2018-11-24 00:34:51 PST
(Alternatively, if the consensus is that this isn't really an improvement, then please let me know and I will happily step aside. 😅)
Ross Kirsling
Comment 24
2018-11-25 16:41:02 PST
(In reply to Ross Kirsling from
comment #22
)
> We can do this by adding either templates or float overloads to LayoutPoint, > LayoutSize, LayoutRect, and the like. > This patch demonstrates the former; the latter would be a somewhat larger > patch. > Templates might be more opaque but they do support double, say, at the same > time.
Sorry, my earlier explanation is kind of insufficient. The real reason float overloads would be a larger patch and potentially undesirable going forward is because of cases like this:
> LayoutPoint(someLayoutUnit(), someInt())
The intention would be to have the int get implicitly converted to LayoutUnit (and use LayoutPoint(LayoutUnit, LayoutUnit)), but the compiler complains that it's actually ambiguous, since perhaps we wanted both parameters to be implicitly converted to float (and use LayoutPoint(float, float)). Hence this effort really probably only makes sense with the template approach. --- Furthermore, this effort doesn't work if we mark *everything but* LayoutUnit(int) as explicit, for the reason I mentioned in
comment 17
-- if you forget to explicitly convert float to LayoutUnit, you won't get an error as desired; you'll just end up using implicit LayoutUnit(int) without realizing it, which is a strictly worse situation. Given that we don't want to make LayoutUnit(int) explicit, since that particular implicit conversion is clearly a feature, then the best we could really do is *just* mark the lossy constructors as explicit (i.e. at least float and double; debatably also unsigned long [long], though they're unused anyway). That way, when you forget to convert float to LayoutUnit, the compiler asks "were you intending to use LayoutUnit(int) or LayoutUnit(unsigned) or...?" And that's precisely the patch here. --- Whether implicit lossy conversion from floating-point types is enough of a concern to justify all this...is a question for the reviewers. (I kind of wish I could've reached that explanation without putting in the level of time and effort that I did, but hey, it's been educational. 😂)
Ross Kirsling
Comment 25
2018-12-01 16:45:42 PST
Any chance for a review here? :) It may suffice to read comments 22 through 24; the code only needs to be read if the approach is deemed desirable.
Ross Kirsling
Comment 26
2018-12-10 17:04:41 PST
I'm guessing that the unspoken consensus here is a moderate preference for the status quo? I'll tentatively plan to close this as WONTFIX at the end of the week unless I hear otherwise. :)
Simon Fraser (smfr)
Comment 27
2018-12-10 17:18:07 PST
I think this is a good change, but haven't had a chance to review it. I'd like to hear from Zalan.
Ross Kirsling
Comment 28
2018-12-10 17:27:01 PST
(In reply to Simon Fraser (smfr) from
comment #27
)
> I think this is a good change, but haven't had a chance to review it. I'd > like to hear from Zalan.
Cool! Sorry for assuming prematurely. 😅
Konstantin Tokarev
Comment 29
2018-12-18 10:11:01 PST
If we want to make float to integer conversion explicit in terms of floor/ceil/round/truncate, I think we should have ctor LayoutUnit(floor, ConversionPolicy) here and no operator=(floor)
zalan
Comment 30
2018-12-23 17:15:54 PST
(In reply to Simon Fraser (smfr) from
comment #27
)
> I think this is a good change, but haven't had a chance to review it. I'd > like to hear from Zalan.
I've been wanting to do this but never had a chance (and didn't have a compelling reason to introduce such an intrusive change). I don't mind landing this.
Ross Kirsling
Comment 31
2019-01-07 15:03:07 PST
(In reply to Konstantin Tokarev from
comment #29
)
> If we want to make float to integer conversion explicit in terms of > floor/ceil/round/truncate, I think we should have ctor LayoutUnit(floor, > ConversionPolicy) here and no operator=(floor)
There are a couple of cons to this approach: 1. All of LayoutUnit's constructors clamp to int, so it seems quite natural/unambiguous that operator=(float) would follow suit. 2. The introduction of operator=(float) was aiming to reduce both the size of the diff and the burden of using these explicit constructors -- in particular, there are about 120 existing locations that would need to be updated. (In reply to zalan from
comment #30
)
> (In reply to Simon Fraser (smfr) from
comment #27
) > > I think this is a good change, but haven't had a chance to review it. I'd > > like to hear from Zalan. > I've been wanting to do this but never had a chance (and didn't have a > compelling reason to introduce such an intrusive change). I don't mind > landing this.
Thanks Zalan! I'll upload a rebased version of the current patch.
Ross Kirsling
Comment 32
2019-01-07 15:06:56 PST
Created
attachment 358535
[details]
Patch
Ross Kirsling
Comment 33
2019-02-06 18:53:17 PST
Any further thoughts here perchance?
Ross Kirsling
Comment 34
2019-05-19 15:53:30 PDT
Ping? Happy to give this another rebase if there's still interest.
Antti Koivisto
Comment 35
2019-05-20 12:56:24 PDT
r=me
Ross Kirsling
Comment 36
2019-05-20 15:30:35 PDT
Created
attachment 370273
[details]
Patch for landing
Ross Kirsling
Comment 37
2019-05-20 17:55:50 PDT
Created
attachment 370288
[details]
Patch for landing
WebKit Commit Bot
Comment 38
2019-05-20 18:36:18 PDT
Comment on
attachment 370288
[details]
Patch for landing Clearing flags on attachment: 370288 Committed
r245543
: <
https://trac.webkit.org/changeset/245543
>
WebKit Commit Bot
Comment 39
2019-05-20 18:36:20 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 40
2019-05-20 18:37:20 PDT
<
rdar://problem/50969679
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug