Skip to content

recovering from adding all native types #35119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sigmundch opened this issue Nov 9, 2018 · 5 comments
Open

recovering from adding all native types #35119

sigmundch opened this issue Nov 9, 2018 · 5 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. P2 A bug or feature request we're likely to work on web-dart2js

Comments

@sigmundch
Copy link
Member

When we find code like js_util.getProperty during resolution, we assume that all native types may be used and enqueue them.

Would it be possible to treat native types again as part of the work-queue during codegen, so that if js_util.getProperty was tree-shaken, all those native types are also omitted?

@sigmundch sigmundch added web-dart2js P2 A bug or feature request we're likely to work on labels Nov 9, 2018
@matanlurey
Copy link
Contributor

To be clear, if @jmesserly's #35084 ends up "solving this", we don't consider this to be necessary. Just an FYI!

@rakudrama
Copy link
Member

Even if js_util.getProperty is retained in the program, we should make it generic so that the given or inferred type parameter can constrain the type, something like:

getProperty(o, name) => JS('Object|Null', '#[#]', o, name);

-->

T getProperty<T>(o, name) => JS<T>('', '#[#]', o, name);

The trick is to defer the native impact of the inline JS code to when getProperty is used.
This could be achieved by summaries, i.e. make 'creates(T)' part of the summary of getProperty.
How T is bound by the uses of getProperty would constrain the native types retained.
This should work with inlining, since getProperty(o, 'x') is often inlined and compiles to o.x.

@matanlurey
Copy link
Contributor

QQ @rakudrama or @sigmundch:

If I create the following "type":

@JS()
@anonymous
abstract class JSUnknown {}

... and I write something like:

JSUnknown p = getProperty(o, 'foo');

... will that be enough not to bring in native types?

@rakudrama
Copy link
Member

@matanlurey Not today, it is 'game over' at JS('Object... in the current snippet.

If you know that o is a JavaScript object you might be able to do something like

@JS()
@anonymous
class JSUnknown {
  external JSUnknown get foo;
}
...
JSUnknown jsO = o;
JSUnknown p = jsO.foo;

That won't help if 'foo' is computed, but it might work for some uses.

@matanlurey
Copy link
Contributor

In my particular case, I do know all of the static members, so I think I can do that. Thanks!

@vsmenon vsmenon added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. P2 A bug or feature request we're likely to work on web-dart2js
Projects
None yet
Development

No branches or pull requests

4 participants