New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 798464 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
OoO until Feb 4th
Closed: Jan 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Task



Sign in to add a comment

bindings: Consider moving from Nullable<T> to Optional<T>

Project Member Reported by raphael....@intel.com, Jan 2 2018

Issue description

This came up in https://chromium-review.googlesource.com/c/chromium/src/+/831497.

Nullable<T> is bindings-specific and does not seem to offer any advantage over WTF::Optional<T> and its //base counterpart, so we should look at what it'd take to deprecate it and replace all usages with Optional<T>.

From https://chromium-review.googlesource.com/c/chromium/src/+/831497#message-f77341977e1590cf2d3002fdf13cd814555fa80a:
"Getting to the level of tracing support that Nullable has isn't too hard (TraceTraits lets you retrofit tracing on types that can't know about Oilpan internally)"
 
Cc: peria@chromium.org
At the moment, we can't use Optional<T> with Oilpan's container types, which means 'sequence<long>?' becomes

    Optional<Vector<int32_t>>

while 'sequence<Document>?' would have to become

    HeapVector<Document>*

this is confusing, but correct. Is that OK with others?
We could also make it possible to write Optional<HeapVector<>>. I don't know of any reason it won't work technically, we just currently ban it to avoid misuse (e.g. putting it in an Oilpan object and then slipping past some of the tracing safety checks).
Cc: keishi@chromium.org
+cc: keishi@

What do you think of supporting base::Optional<blink::HeapVector<T>> ?  Any thoughts, opinions, and/or concerns?
Cc: haraken@chromium.org
FWIW I've got a patch here removing Nullable<T> from the tree and dropping all Oilpan checks from WTF::Optional<T>, we just need to decide whether the latter is the way to go.

Comment 6 by keishi@chromium.org, Jan 26 2018

We discussed this offline with haraken. Using Optional looks OK. We can remove OptionalGarbageCollected check from blink_gc_plugin and then replace Nullable with Optional. raphael, if you have the blink_gc_plugin patch ready please put it up for review. If not I could make the change for you.
Thanks for the follow-up.

Curiously enough, I've never hit the OptionalGarbageCollected checks here in my builds, possibly because I don't think we currently use Nullable<T> for GC types, and HeapVector<T> does not derive from GarbageCollected/GarbageCollectedMixin, but rather only has the IS_GARBAGE_COLLECTED_TYPE macro in its body. In this case, I wonder if it makes sense to remove that check from blink_gc_plugin or just leave it as-is.

Comment 8 by keishi@chromium.org, Jan 26 2018

If blink_gc_plugin doesn't block your CL then no worries. Please CC me on your CL and I'll look into how we should tighten up the blink_gc_plugin checks.
Project Member

Comment 9 by bugdroid1@chromium.org, Jan 27 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/dd1b0228d93b79bb627f1f26091d9ab9ed0fd25e

commit dd1b0228d93b79bb627f1f26091d9ab9ed0fd25e
Author: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Date: Sat Jan 27 14:52:56 2018

wtf, oilpan: Remove GC checks from WTF::Optional<T>.

Architecturally, there is nothing really preventing garbage-collected types
from being used with Optional<T> other than avoiding misuse.

Relax the existing checks by removing the ones in place in Optional.h
itself, but keep OptionalGarbageCollected in //tools/clang/blink_gc_plugin.

In practice, this is a relaxation of the rules that:
* Allows Optional<HeapVector<T>> (and other Oilpan containers). These
  containers do not inherit from GarbageCollected or GarbageCollectedMixin,
  but do have the IS_GARBAGE_COLLECTED_TYPE() macro in their declarations.
  As we are moving to replace the binding layer's Nullable<T> with wtf's
  Optional<T>, doing so makes things uniform by letting Optional<> be used
  with both Vector and HeapVector types so that Web IDL's

      sequence<long>?

  and

      sequence<Document>?

  are both translated into C++ as Optional<T>.

* Types that do inherit from GarbageCollected or GarbageCollectedMixin are
  still disallowed by the checks in blink_gc_plugin since none of the
  changes to get rid of Nullable<T> require them to be turned off or
  relaxed. Web IDL's

      Document?

  is still represented as Document* in C++.

TraceTrait<T> had to be augmented with a specialization for Optional<T>, as
we may need to Trace() its inner type if it's a GC container type.

Bug:  798464 
Change-Id: I12cad41976219654985f5a8d560e7db3f4cedf82
Reviewed-on: https://chromium-review.googlesource.com/888918
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: Keishi Hattori <keishi@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Cr-Commit-Position: refs/heads/master@{#532217}
[modify] https://crrev.com/dd1b0228d93b79bb627f1f26091d9ab9ed0fd25e/third_party/WebKit/Source/platform/heap/TraceTraits.h
[modify] https://crrev.com/dd1b0228d93b79bb627f1f26091d9ab9ed0fd25e/third_party/WebKit/Source/platform/wtf/Optional.h

Project Member

Comment 10 by bugdroid1@chromium.org, Jan 29 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/26e51bf801d50e6dcac576440f0cbf9ce0e447d3

commit 26e51bf801d50e6dcac576440f0cbf9ce0e447d3
Author: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Date: Mon Jan 29 11:06:38 2018

bindings: Move UnionTypeConversionMode to V8BindingForCore.h.

We want to remove Nullable.h, but UnionTypeConversionMode needs to remain.
Move it to V8BindingForCore.h, as the enum is generally used in ToImpl()
calls.

While here, document it a little bit.

Bug:  798464 
Change-Id: Iecbb481114ad934264dcfb0efffc248bcc420981
Reviewed-on: https://chromium-review.googlesource.com/891019
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Cr-Commit-Position: refs/heads/master@{#532387}
[modify] https://crrev.com/26e51bf801d50e6dcac576440f0cbf9ce0e447d3/third_party/WebKit/Source/bindings/core/v8/Nullable.h
[modify] https://crrev.com/26e51bf801d50e6dcac576440f0cbf9ce0e447d3/third_party/WebKit/Source/bindings/core/v8/V8BindingForCore.h

Project Member

Comment 11 by bugdroid1@chromium.org, Jan 30 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/5e4bfc34f885d3b4954b71a92366023f972a2d3a

commit 5e4bfc34f885d3b4954b71a92366023f972a2d3a
Author: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Date: Tue Jan 30 08:12:22 2018

bindings: Drop Nullable<T> in favor of WTF::Optional<T>

Nullable<T> is bindings-specific and does not seem to offer any advantage
over WTF::Optional<T> and its //base counterpart, which are more widely used
and maintained.

Using Optional<T> with a garbage-collected type remains forbidden, but using
it with a GC container type such as HeapVector is OK.

Most of the changes in this CL are fairly mechanical: replace includes and
adjust to API differences (.value() instead of .Get(), WTF::nullopt instead
of nullptr etc). Everything should remain the same in terms of
functionality.

Bug:  798464 
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I988f7cb4a941439cb9a6ab0d2c3bc26c78e59f00
Reviewed-on: https://chromium-review.googlesource.com/891178
Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532809}
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/bindings.gni
[delete] https://crrev.com/31534c861804a7de0951f9014905995bdf5fcbe0/third_party/WebKit/Source/bindings/core/v8/Nullable.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/scripts/v8_methods.py
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/scripts/v8_types.py
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/scripts/v8_union.py
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/templates/methods.cpp.tmpl
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/V8TestObject.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/array_buffer_or_array_buffer_view_or_dictionary.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/boolean_or_element_sequence.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/boolean_or_string_or_unrestricted_double.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/boolean_or_test_callback_interface.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/byte_string_or_node_list.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/byte_string_sequence_sequence_or_byte_string_byte_string_record.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/double_or_double_or_null_sequence.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/double_or_double_sequence.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/double_or_long_or_boolean_sequence.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/double_or_string.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/double_or_string_or_double_or_string_sequence.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/element_sequence_or_byte_string_double_or_string_record.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/float_or_boolean.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/long_or_boolean.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/long_or_test_dictionary.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/long_sequence_or_event.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/nested_union_type.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/node_or_node_list.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/string_or_array_buffer_or_array_buffer_view.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/string_or_double.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/string_or_string_sequence.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/test_enum_or_double.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/test_enum_or_test_enum_sequence.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/test_interface_2_or_uint8_array.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/test_interface_garbage_collected_or_string.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/test_interface_or_long.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/test_interface_or_test_interface_empty.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/unrestricted_double_or_string.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/unsigned_long_long_or_boolean_or_test_callback_interface.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/core/xml_http_request_or_string.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/bindings/tests/results/modules/boolean_or_string.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/css/cssom/CSSStyleValue.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/css/cssom/CSSStyleValue.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/html/media/AutoplayPolicy.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/html/media/AutoplayPolicy.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/html/media/HTMLMediaElement.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/html/media/HTMLMediaElement.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/testing/DictionaryTest.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/testing/DictionaryTest.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/testing/RecordTest.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/testing/RecordTest.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/testing/SequenceTest.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/core/testing/SequenceTest.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/device_orientation/DeviceOrientationData.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/device_orientation/DeviceOrientationData.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/indexeddb/IDBDatabase.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/indexeddb/IDBOpenDBRequest.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/indexeddb/IDBVersionChangeEvent.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/indexeddb/IDBVersionChangeEvent.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/webdatabase/SQLTransaction.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/webdatabase/SQLTransaction.h
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
[modify] https://crrev.com/5e4bfc34f885d3b4954b71a92366023f972a2d3a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h

Labels: M-66
Owner: raphael....@intel.com
Status: Fixed (was: Available)

Sign in to add a comment