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

Issue 1680263002: Support for dart:typed_data (Closed)

Created:
4 years, 10 months ago by vsm
Modified:
4 years, 10 months ago
CC:
dev-compiler+reviews_dartlang.org, devoncarew
Base URL:
https://github.com/dart-lang/dev_compiler.git@master
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Patch Set 1 #

Patch Set 2 : Cleanup and comments #

Patch Set 3 : Refine comment #

Total comments: 22

Patch Set 4 : Address comments, rebase #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1109 lines, -791 lines) Patch
M lib/runtime/dart/_internal.js View 1 chunk +40 lines, -25 lines 0 comments Download
M lib/runtime/dart/_native_typed_data.js View 55 chunks +483 lines, -289 lines 0 comments Download
M lib/runtime/dart/_runtime.js View 1 2 3 7 chunks +23 lines, -9 lines 0 comments Download
M lib/runtime/dart/collection.js View 8 chunks +235 lines, -234 lines 0 comments Download
M lib/runtime/dart/convert.js View 4 chunks +7 lines, -7 lines 0 comments Download
M lib/runtime/dart/html.js View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M lib/runtime/dart/typed_data.js View 16 chunks +16 lines, -16 lines 0 comments Download
M lib/src/codegen/js_codegen.dart View 1 2 3 7 chunks +89 lines, -28 lines 0 comments Download
M lib/src/codegen/js_interop.dart View 1 2 1 chunk +17 lines, -6 lines 0 comments Download
M lib/src/codegen/module_builder.dart View 1 2 3 1 chunk +1 line, -2 lines 0 comments Download
M test/browser/language_tests.js View 1 2 3 2 chunks +22 lines, -35 lines 0 comments Download
M test/codegen/expect/collection/src/unmodifiable_wrappers.txt View 1 2 3 1 chunk +2 lines, -2 lines 0 comments Download
M test/codegen/expect/collection/src/wrappers.txt View 1 2 3 1 chunk +2 lines, -2 lines 0 comments Download
M test/codegen/expect/dom/dom.js View 1 chunk +5 lines, -1 line 0 comments Download
M test/codegen/expect/language-all.js View Binary file 0 comments Download
M test/codegen/expect/lib-typed_data-all.js View 13 chunks +122 lines, -122 lines 0 comments Download
M test/codegen/expect/sunflower/dom.js View 1 chunk +5 lines, -1 line 0 comments Download
M tool/input_sdk/private/classes.dart View 1 2 3 4 chunks +16 lines, -7 lines 0 comments Download
M tool/input_sdk/private/native_typed_data.dart View 1 1 chunk +0 lines, -1 line 0 comments Download
M tool/input_sdk/private/operations.dart View 1 chunk +2 lines, -1 line 0 comments Download
M tool/input_sdk/private/rtti.dart View 1 2 3 2 chunks +21 lines, -2 lines 0 comments Download

Messages

Total messages: 8 (3 generated)
vsm
4 years, 10 months ago (2016-02-09 20:54:58 UTC) #3
Jennifer Messerly
LGTM, with one comment about the change to setType/realRuntimeType which I don't think should be ...
4 years, 10 months ago (2016-02-10 00:20:30 UTC) #4
vsm
Landing, but still need to shake out the runtime type tagging. https://codereview.chromium.org/1680263002/diff/40001/lib/src/codegen/js_codegen.dart File lib/src/codegen/js_codegen.dart (right): ...
4 years, 10 months ago (2016-02-11 22:36:06 UTC) #5
vsm
Committed patchset #4 (id:60001) manually as 955a581d309369461b36fc83dac0b42b5d7ebd7b (presubmit successful).
4 years, 10 months ago (2016-02-11 22:36:36 UTC) #7
Jennifer Messerly
4 years, 10 months ago (2016-02-11 23:04:57 UTC) #8
Message was sent while issue was closed.
I can take a shot at cleaning this up if you want?

I'm trying to avoid redundant storage of data, which means more overhead...

https://codereview.chromium.org/1680263002/diff/40001/tool/input_sdk/private/...
File tool/input_sdk/private/classes.dart (right):

https://codereview.chromium.org/1680263002/diff/40001/tool/input_sdk/private/...
tool/input_sdk/private/classes.dart:355: // invoked on the generic type (e.g.,
JSArray<dynamic>, not JSArray<int>).
On 2016/02/11 22:36:06, vsm wrote:
> On 2016/02/10 00:20:30, John Messerly wrote:
> > Given a generic type T, it's possible to get its raw type R, then from that
> you
> > can get its extension type. This is all handled by dart.generic
> > 
> > So it shouldn't be necessary to put this here. We can already find the type
> for
> > List<int> and such, AFAIK. I'll add some code that should work on the other
> end.
> 
> I need this to go the other way around - i.e., to map the raw object back to
the
> generic type.

I'm 99% sure this should not be needed. In JavaScript:

    obj.__proto__.contstructor == type

so you don't need the _extensionType field. That's what I'm saying.

https://codereview.chromium.org/1680263002/diff/40001/tool/input_sdk/private/...
File tool/input_sdk/private/rtti.dart (right):

https://codereview.chromium.org/1680263002/diff/40001/tool/input_sdk/private/...
tool/input_sdk/private/rtti.dart:101: result = $obj.runtimeType;
On 2016/02/11 22:36:06, vsm wrote:
> On 2016/02/10 00:20:30, John Messerly wrote:
> > huh, the old code here looks broken. Shouldn't this go through:
> > 
> >     obj[dartx.runtimeType] ?
> > 
> > I'm not sure how user-defined Iterable/List types can work otherwise:
> > 
> > class MyIterable extends Iterable {
> >   get runtimeType => String; // Take that, type system! ;-)
> > }
> 
> For object properties, we either:
> 
> (1) use the unsymbolized name (obj.runtimeType)
> 
> or
> 
> (2) use staticDispatch (dart.runtimeType(obj))
> 
> The latter does the right thing on null.  There was bug here - we need to do
> staticDispatch on potential extension types - fixed in codegen.

yeah, I mean, this is a bug in how the hand-coded runtime code here is written.
Compiler would've generated the right thing.

I don't think my example about will work. Anyway, I'll file a bug.

https://codereview.chromium.org/1680263002/diff/40001/tool/input_sdk/private/...
tool/input_sdk/private/rtti.dart:136: result = $obj[$_extensionType];
On 2016/02/11 22:36:06, vsm wrote:
> On 2016/02/10 00:20:30, John Messerly wrote:
> > Fallback to the constructor should find our type, that was set via
`setType`.
> > That should be the extension type already. For example we set type to
> > `JSArray<T>` for Dart lists.
> > 
> > It may not be entirely obvious, but for JSArray<T> we set up the prototype
> chain
> > is like:
> > 
> >     obj --> JSArray<T>.prototype --> Array.prototype.
> > 
> > In one operation, we simultaneously record the correct Dart "real runtime
> type",
> > as well as getting the correctly typed (closing over "T") methods for
> > JSArray<T>, and in general, all of our operations (realRuntimeType, but
> anything
> > using reflection) will find the correct Dart metadata. Method tearoffs, etc.
> > 
> > If we don't set this up, things can go wrong:
> > * when we look up signatures/metadata it will break.
> > * we'd JSArray<dynamic> members which would be no good.
> > 
> > Because of the inheritance relationship, obj[_extensionType] will point back
> to
> > JSArray, from any JSArray.
> > 
> > 
> 
> Hmm, I think there are (at least) 3 interesting cases here:
> 
> (1) A generic extension type where we explicitly call setType.  E.g., <int>[1,
> 2, 3]
> Here, the constructor is set up as you say.  Printing the real runtime type
> shows JSArray<int> - good!
> 
> (2) A generic extension type where we don't call setType.  E.g., [1, 2, 3] or
a
> list we get from a JS API.
> Here, the constructor is Array.  Printing the real runtime type shows
> JSObject<Array> - a little weird.

This shouldn't happen. setType must be called for a generic type. Without that,
you'll get the wrong generic methods, which is a much worse problem.

How are we getting generic types from JS? JS doesn't have reified generics ...
apologies if I'm super confused.

> 
> (3) A non-generic extension type where we don't call setType (we can't as we
get
> it back from the DOM).   E.g., a Uint8List.
> Here, the constructor is the native Uint8Array.  
> 
> In latter two cases, the _extensionType field maps back to the right type.

Since "setType" is how you populate _extensionType, I'm confused. :)

If I understand case (3), you want to map Array -> JSArray? Was that not working
before?

If it wasn't, the change here seems okay, but I don't get why you needed a
change to `setType`. That is what worries me.

Powered by Google App Engine
This is Rietveld 408576698