Skip to content
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

dart2js: used-type inference for hidden native classes during codegen #1525

Closed
rakudrama opened this issue Feb 4, 2012 · 20 comments
Closed
Assignees
Labels
type-enhancement A request for a change that isn't a bug web-dart2js

Comments

@rakudrama
Copy link
Member

Instances of hidden native classes can reach the Dart program via four paths:

(1) returned from a native method or getter,
  e.g. aha = document.getElementById();

(2) passed to functions which escape to the native world
  e.g. element.addEventListenter((e) => doIt());

(3) passed to methods on objects which escape to the native world.

(4) anything transitively reachable from the results of (2), (3) also escapes.

For dart:dom and dart:html we only need to consider (1) and (2), since all objects in class (3) have been typedef-ed as callback functions, and all callbacks return simple types.

This analysis will prevent the gratuitous generation of code like the following since in most programs, Float64Array will be determined to be unused:

// ********** Code for _Float64ArrayJs **************
var _Float64ArrayJs = {};
$dynamic("get$length").Float64Array = function() {
  return this.length;
}
$dynamic("$index").Float64Array = function(index) {
  return this[index];
}

@rakudrama
Copy link
Member Author

Marked this as blocking #1519.

@rakudrama
Copy link
Member Author

Additional to the above, exception types need to be marked.
The issue is how do we know from the Dart source for the dart:dom or dart:html library which exceptions are raised?

Exaample: Swarm contains this code because IDBDatabaseException is marked as used by the blanket 'mark all native types rule'.
The code could be eliminated if we knew the

// ********** Code for _IDBDatabaseExceptionJs **************
$dynamic("get$name").IDBDatabaseException = function() { return this.name; };

There are ~35 IDL operations that are marked in the IDL as raising this exception, but this information is not currently carried to the Dart code.

We could use the 'dummy code' feature to generate a reference.

class _IDBRequestJs implements IDBRequest {

   IDBAny get result() native 'return this.result' { throw new _IDBDatabaseExceptionJs(); }
}

_IDBDatabaseExceptionJs might not have a constructor.
We would probably need to generate a named generative constructor.

@rakudrama
Copy link
Member Author

Additional to the above, there is one callback with an imprecise argument type.

module storage {
    interface [
        Conditional=SQL_DATABASE,
        Callback
    ] DatabaseCallback {
        boolean handleEvent(in Database database);
        boolean handleEvent(in DatabaseSync database);
    };
}

-->
typedef bool DatabaseCallback(var database);

This could be made precise by making Database and DatabaseSync extend a common marker interface.
WebSQL is probably in decline so we could simply accept imprecise analysis for this case.

@anders-sandholm
Copy link
Contributor

Removed Area-Frog label.
Added Area-Dart2JS, FromAreaFrog labels.
Marked this as blocking #1519.
Unmarked this as blocking #-1519.

@kasperl
Copy link

kasperl commented Jun 12, 2012

Is this a DOM issue?


Removed Area-Dart2JS, FromAreaFrog labels.
Added Area-DOM label.
Changed the title to: "used-type inference for hidden native classes".

@rakudrama
Copy link
Member Author

This is a dart2js issue - the compiler emits code for native classes that cannot exist in the given program. There is sufficient information in the library to eliminate many of these.

I prototyped an analysis in Frog. The results are listed in a document called

"Investigation: Frog used-type analysis for native classes"


Removed Area-DOM label.
Added Area-Dart2JS label.

@kasperl
Copy link

kasperl commented Sep 3, 2012

Added this to the Later milestone.

@kasperl
Copy link

kasperl commented Oct 17, 2012

Removed this from the Later milestone.
Marked this as blocking #1519.
Unmarked this as blocking #1519.

@kasperl
Copy link

kasperl commented Oct 17, 2012

Added this to the M2 milestone.

@kasperl
Copy link

kasperl commented Oct 17, 2012

Removed Priority-Medium label.
Added Priority-Low label.

@rakudrama
Copy link
Member Author

Kasper: Why did you move the priority to Low? This is a key piece to reducing the size cost of dart:html.

@kasperl
Copy link

kasperl commented Oct 29, 2012

Removed Priority-Low label.
Added Priority-High label.

@peter-ahe-google
Copy link
Contributor

Nicolas, Stephen, are you guys looking at this?


cc @rakudrama.

@DartBot
Copy link

DartBot commented Nov 8, 2012

This comment was originally written by ngeoffray@google.com


Yes, Stephen is working on this, and we're looking at the interaction with dart2js's enqueuer.

@peter-ahe-google
Copy link
Contributor

Set owner to @rakudrama.

@rakudrama
Copy link
Member Author

First part of this has been implemented in r14977.
It can be used via the command line flag --enable-native-live-type-analysis.
This is a resolution based liveness analysis.

The libraries now need to be correctly annotated before this can be the default.

After that, codegen based analysis should be implemented to improve on the resolution based results.

@rakudrama
Copy link
Member Author

Libraries have been mostly annotated r15569 r15705

Feature enabled by default r15660

I'm moving this issue to M3 for the codegen based analysis.


Removed this from the M2 milestone.
Added this to the M3 milestone.
Removed Type-Defect, Priority-High labels.
Added Type-Enhancement, Priority-Medium labels.
Changed the title to: "used-type inference for hidden native classes during codegen".

@kasperl
Copy link

kasperl commented Feb 4, 2013

Removed this from the M3 milestone.
Added this to the M4 milestone.
Changed the title to: "dart2js: used-type inference for hidden native classes during codegen".

@rakudrama
Copy link
Member Author

Removed this from the M4 milestone.
Added this to the M5 milestone.

@sigmundch
Copy link
Member

@rakudrama - seems like this is now been done for quite some time? I'm closing the issue assuming so, but please reopen if not.

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug web-dart2js
Projects
None yet
Development

No branches or pull requests

7 participants