Discussion:
[dart-misc] dart2js stripping out needed fields, with mirror use
Michael Bullington
2015-07-04 03:23:35 UTC
Permalink
Hello!

I'm currently working on (finishing up) a project that makes Dart libraries
usable from JS. You can find the project here
<http://github.com/DirectMyFile/calzone.dart>, documentation is lacking at
the moment. The main project using it right now is sdk-dslink-javascript,
an updated JavaScript SDK for the IoT DSA platform. The IoT DSA platform
was shown earlier this year at the Dart Summit.

I'm attempting to create some mirror code that will keep everything needed
for the code to function dynamically from JavaScript, and here is my
progress so far.

main(List<String> args) {
var a = new Symbol(args.length.toString());


reflectClass(a).getField(a);
reflectClass(a).invoke(a, []);
currentMirrorSystem().findLibrary(a).getField(a);
}

With this code (along with @MirrorsUsed for slightly less output), all
classes, methods, and functions are retained. However, static fields are
not retained in the dart2js output (for classes or libraries). Mangled name
definitions are generated for them, but the resulting name doesn't link to
any actual value.

Is there a way to make dart2js keep the value of the fields also in it's
output?

Any help or general direction would be appreciated, thank you,

Michael Bullington
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
'Stephan Herhut' via Dart Misc
2015-07-07 09:13:31 UTC
Permalink
Hi Michael,

I tried this locally and at least for the MirrorsUsed annotation I tried
they are retained. For a static field 'foofield' with value 1, I get a
mangled names entry of

lt:"foofield"

and a top-level value of

$.lt=1

Dart semantics require the right hand side to be computed on first access.
If the value is a primitive, this is not observable, so those are computed
directly. However, if the compiler cannot prove that the expression on the
right hand side has no observable sideeffects, it has to defer their
computation until later. Therefore, the field is encoded as a lazy value
with a getter. In non-minified code you should find a line like

[..., "Boo_foofield", "$get$Boo_foofield", "foofield", function() {
return new Y.Boo();
}, ...]

for a static field foofield in class Boo. In minified code the minified
names from the mangled names map are used.

At runtime, there will be a $.Boo_foofield but its value is not set until
the getter $get$Boo_foofield has been called for the first time.

If none if this is in your generated output, I would need to see your
MirrorsUsed annotation to track down the issue.

Stephan
Post by Michael Bullington
Hello!
I'm currently working on (finishing up) a project that makes Dart
libraries usable from JS. You can find the project here
<http://github.com/DirectMyFile/calzone.dart>, documentation is lacking
at the moment. The main project using it right now is
sdk-dslink-javascript, an updated JavaScript SDK for the IoT DSA platform.
The IoT DSA platform was shown earlier this year at the Dart Summit.
I'm attempting to create some mirror code that will keep everything needed
for the code to function dynamically from JavaScript, and here is my
progress so far.
main(List<String> args) {
var a = new Symbol(args.length.toString());
reflectClass(a).getField(a);
reflectClass(a).invoke(a, []);
currentMirrorSystem().findLibrary(a).getField(a);
}
classes, methods, and functions are retained. However, static fields are
not retained in the dart2js output (for classes or libraries). Mangled name
definitions are generated for them, but the resulting name doesn't link to
any actual value.
Is there a way to make dart2js keep the value of the fields also in it's
output?
Any help or general direction would be appreciated, thank you,
Michael Bullington
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Michael Bullington
2015-07-07 21:23:45 UTC
Permalink
Hello Stephan!

Right now, this is my MirrorsUsed annotation.

@MirrorsUsed(
targets: const [
"dslink.pk",
"dslink.common",
"dslink.requester",
"dslink.responder",
"dslink.client",
"dslink.utils.Scheduler",
"dslink.utils.Interval",
"dslink.utils.DSLinkJSON",
"dslink.utils.updateLogLevel",
"dslink.utils.buildEnumType",
"dslink.utils.buildActionIO",
"dart.async.Completer",
"dart.async.Future",
"dart.collection.LinkedHashMap",
"dart.typed_data.ByteData",
"dslink.stub.NodeStub"
],
override: '*'
)
import "dart:mirrors";

The issue I'm having is, say, with the Permission class. dslink.common has
a class called Permission, and in it is a static field called WRITE. This
field is not referenced by any code except supposedly the mirror code.

In my output's mangled names (unminified), I do have the following:

Permission_WRITE: "WRITE"

However, I don't have a $.Permission_WRITE, or a $.$get_$Permission_WRITE
in the output.

Thank you,
Michael
Post by 'Stephan Herhut' via Dart Misc
Hi Michael,
I tried this locally and at least for the MirrorsUsed annotation I tried
they are retained. For a static field 'foofield' with value 1, I get a
mangled names entry of
lt:"foofield"
and a top-level value of
$.lt=1
Dart semantics require the right hand side to be computed on first access.
If the value is a primitive, this is not observable, so those are computed
directly. However, if the compiler cannot prove that the expression on the
right hand side has no observable sideeffects, it has to defer their
computation until later. Therefore, the field is encoded as a lazy value
with a getter. In non-minified code you should find a line like
[..., "Boo_foofield", "$get$Boo_foofield", "foofield", function() {
return new Y.Boo();
}, ...]
for a static field foofield in class Boo. In minified code the minified
names from the mangled names map are used.
At runtime, there will be a $.Boo_foofield but its value is not set until
the getter $get$Boo_foofield has been called for the first time.
If none if this is in your generated output, I would need to see your
MirrorsUsed annotation to track down the issue.
Stephan
Post by Michael Bullington
Hello!
I'm currently working on (finishing up) a project that makes Dart
libraries usable from JS. You can find the project here
<http://github.com/DirectMyFile/calzone.dart>, documentation is lacking
at the moment. The main project using it right now is
sdk-dslink-javascript, an updated JavaScript SDK for the IoT DSA platform.
The IoT DSA platform was shown earlier this year at the Dart Summit.
I'm attempting to create some mirror code that will keep everything
needed for the code to function dynamically from JavaScript, and here is my
progress so far.
main(List<String> args) {
var a = new Symbol(args.length.toString());
reflectClass(a).getField(a);
reflectClass(a).invoke(a, []);
currentMirrorSystem().findLibrary(a).getField(a);
}
classes, methods, and functions are retained. However, static fields are
not retained in the dart2js output (for classes or libraries). Mangled name
definitions are generated for them, but the resulting name doesn't link to
any actual value.
Is there a way to make dart2js keep the value of the fields also in it's
output?
Any help or general direction would be appreciated, thank you,
Michael Bullington
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
'Stephan Herhut' via Dart Misc
2015-07-09 09:11:55 UTC
Permalink
Hi Michael,

after looking at the code in question, I saw that it was a final const
field you were trying to reflect. const fields are not normally emitted, as
the compiler inlines the constant value anyway. However, they should
clearly be accessible through reflection. I have filed a bug on your behalf
at http://dartbug.com/23811 and also proposed a fix. It should become
available in a dev release soon.

Stephan
Post by Michael Bullington
Hello Stephan!
Right now, this is my MirrorsUsed annotation.
@MirrorsUsed(
targets: const [
"dslink.pk",
"dslink.common",
"dslink.requester",
"dslink.responder",
"dslink.client",
"dslink.utils.Scheduler",
"dslink.utils.Interval",
"dslink.utils.DSLinkJSON",
"dslink.utils.updateLogLevel",
"dslink.utils.buildEnumType",
"dslink.utils.buildActionIO",
"dart.async.Completer",
"dart.async.Future",
"dart.collection.LinkedHashMap",
"dart.typed_data.ByteData",
"dslink.stub.NodeStub"
],
override: '*'
)
import "dart:mirrors";
The issue I'm having is, say, with the Permission class. dslink.common has
a class called Permission, and in it is a static field called WRITE. This
field is not referenced by any code except supposedly the mirror code.
Permission_WRITE: "WRITE"
However, I don't have a $.Permission_WRITE, or a $.$get_$Permission_WRITE
in the output.
Thank you,
Michael
Post by 'Stephan Herhut' via Dart Misc
Hi Michael,
I tried this locally and at least for the MirrorsUsed annotation I tried
they are retained. For a static field 'foofield' with value 1, I get a
mangled names entry of
lt:"foofield"
and a top-level value of
$.lt=1
Dart semantics require the right hand side to be computed on first
access. If the value is a primitive, this is not observable, so those are
computed directly. However, if the compiler cannot prove that the
expression on the right hand side has no observable sideeffects, it has to
defer their computation until later. Therefore, the field is encoded as a
lazy value with a getter. In non-minified code you should find a line like
[..., "Boo_foofield", "$get$Boo_foofield", "foofield", function() {
return new Y.Boo();
}, ...]
for a static field foofield in class Boo. In minified code the minified
names from the mangled names map are used.
At runtime, there will be a $.Boo_foofield but its value is not set until
the getter $get$Boo_foofield has been called for the first time.
If none if this is in your generated output, I would need to see your
MirrorsUsed annotation to track down the issue.
Stephan
Post by Michael Bullington
Hello!
I'm currently working on (finishing up) a project that makes Dart
libraries usable from JS. You can find the project here
<http://github.com/DirectMyFile/calzone.dart>, documentation is lacking
at the moment. The main project using it right now is
sdk-dslink-javascript, an updated JavaScript SDK for the IoT DSA platform.
The IoT DSA platform was shown earlier this year at the Dart Summit.
I'm attempting to create some mirror code that will keep everything
needed for the code to function dynamically from JavaScript, and here is my
progress so far.
main(List<String> args) {
var a = new Symbol(args.length.toString());
reflectClass(a).getField(a);
reflectClass(a).invoke(a, []);
currentMirrorSystem().findLibrary(a).getField(a);
}
classes, methods, and functions are retained. However, static fields are
not retained in the dart2js output (for classes or libraries). Mangled name
definitions are generated for them, but the resulting name doesn't link to
any actual value.
Is there a way to make dart2js keep the value of the fields also in it's
output?
Any help or general direction would be appreciated, thank you,
Michael Bullington
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to
http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Michael Bullington
2015-07-10 22:03:27 UTC
Permalink
I updated to the latest build of dart2js with your commit, and it works
now! Thank you.
Post by 'Stephan Herhut' via Dart Misc
Hi Michael,
after looking at the code in question, I saw that it was a final const
field you were trying to reflect. const fields are not normally emitted, as
the compiler inlines the constant value anyway. However, they should
clearly be accessible through reflection. I have filed a bug on your behalf
at http://dartbug.com/23811 and also proposed a fix. It should become
available in a dev release soon.
Stephan
Post by Michael Bullington
Hello Stephan!
Right now, this is my MirrorsUsed annotation.
@MirrorsUsed(
targets: const [
"dslink.pk",
"dslink.common",
"dslink.requester",
"dslink.responder",
"dslink.client",
"dslink.utils.Scheduler",
"dslink.utils.Interval",
"dslink.utils.DSLinkJSON",
"dslink.utils.updateLogLevel",
"dslink.utils.buildEnumType",
"dslink.utils.buildActionIO",
"dart.async.Completer",
"dart.async.Future",
"dart.collection.LinkedHashMap",
"dart.typed_data.ByteData",
"dslink.stub.NodeStub"
],
override: '*'
)
import "dart:mirrors";
The issue I'm having is, say, with the Permission class. dslink.common
has a class called Permission, and in it is a static field called WRITE.
This field is not referenced by any code except supposedly the mirror code.
Permission_WRITE: "WRITE"
However, I don't have a $.Permission_WRITE, or a
$.$get_$Permission_WRITE in the output.
Thank you,
Michael
Post by 'Stephan Herhut' via Dart Misc
Hi Michael,
I tried this locally and at least for the MirrorsUsed annotation I tried
they are retained. For a static field 'foofield' with value 1, I get a
mangled names entry of
lt:"foofield"
and a top-level value of
$.lt=1
Dart semantics require the right hand side to be computed on first
access. If the value is a primitive, this is not observable, so those are
computed directly. However, if the compiler cannot prove that the
expression on the right hand side has no observable sideeffects, it has to
defer their computation until later. Therefore, the field is encoded as a
lazy value with a getter. In non-minified code you should find a line like
[..., "Boo_foofield", "$get$Boo_foofield", "foofield", function() {
return new Y.Boo();
}, ...]
for a static field foofield in class Boo. In minified code the minified
names from the mangled names map are used.
At runtime, there will be a $.Boo_foofield but its value is not set
until the getter $get$Boo_foofield has been called for the first time.
If none if this is in your generated output, I would need to see your
MirrorsUsed annotation to track down the issue.
Stephan
Post by Michael Bullington
Hello!
I'm currently working on (finishing up) a project that makes Dart
libraries usable from JS. You can find the project here
<http://github.com/DirectMyFile/calzone.dart>, documentation is
lacking at the moment. The main project using it right now is
sdk-dslink-javascript, an updated JavaScript SDK for the IoT DSA platform.
The IoT DSA platform was shown earlier this year at the Dart Summit.
I'm attempting to create some mirror code that will keep everything
needed for the code to function dynamically from JavaScript, and here is my
progress so far.
main(List<String> args) {
var a = new Symbol(args.length.toString());
reflectClass(a).getField(a);
reflectClass(a).invoke(a, []);
currentMirrorSystem().findLibrary(a).getField(a);
}
classes, methods, and functions are retained. However, static fields are
not retained in the dart2js output (for classes or libraries). Mangled name
definitions are generated for them, but the resulting name doesn't link to
any actual value.
Is there a way to make dart2js keep the value of the fields also in
it's output?
Any help or general direction would be appreciated, thank you,
Michael Bullington
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to
http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Loading...