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 better code for "is type" check #9971

Closed
DartBot opened this issue Apr 17, 2013 · 6 comments
Closed

dart2js better code for "is type" check #9971

DartBot opened this issue Apr 17, 2013 · 6 comments
Labels
closed-obsolete Closed as the reported issue is no longer relevant web-dart2js

Comments

@DartBot
Copy link

DartBot commented Apr 17, 2013

This issue was originally filed by @bp74


What steps will reproduce the problem?

I tried to optimize the dart2js output for a hot function in my code. The generated code get's a lot better if i add a type check. But the code for the type check itself is not optimal. The code below shows the code of a simple type check for class "foo":

var x = [new foo()];
void main() {
 if (x[0] is! foo) print("is not foo");
}


$.main = function() {
  var t1 = $.$index$as($.get$x(), 0);
  if (typeof t1 !== "object" || t1 === null || !$.getInterceptor(t1).$isfoo)
    $.Primitives_printString("is not foo");
};
    
$.getInterceptor = function(receiver) {
  if (typeof receiver == "number") {
    if (Math.floor(receiver) == receiver) return $.JSInt.prototype;
    return $.JSDouble.prototype;
  }
  if (typeof receiver == "string") return $.JSString.prototype;
  if (receiver == null) return $.JSNull.prototype;
  if (typeof receiver == "function") return $.JSFunction.prototype;
  if (typeof receiver == "boolean") return $.JSBool.prototype;
  if (receiver.constructor == Array) return $.JSArray.prototype;
  if (typeof receiver != "object") return receiver;
  if (receiver instanceof $.Object) return receiver;
  if (Object.getPrototypeOf(receiver) === Object.prototype) return $.Interceptor.prototype;
  return $.getNativeInterceptor(receiver);
};


What is the expected output? What do you see instead?

if (typeof t1 !== "object" || t1 === null || !$.getInterceptor(t1).$isfoo)

Is the call to getInterceptor really needed? Most of the if-checks in getInterceptor will fail because it is guaranteed that "typeof receiver" is an object and receiver is surely not null. Do i need an interceptor at all, would it be okay to just check "t1.$isFoo" ?

What version of the product are you using? On what operating system?

Dart Editor version 0.1.2_r21625
Dart SDK version 0.1.2.0_r21623

Please provide any additional information below.

@sethladd
Copy link
Contributor

Added Area-Dart2JS, C3, Triaged labels.

@kasperl
Copy link

kasperl commented Apr 22, 2013

Added this to the Later milestone.

@rakudrama
Copy link
Member

In the general case the getInterceptor call is needed when there may be DOM objects floating around. For example, a DOM Storage object in JavaScript materializes the keys and values as properties. So it is possible for the Storage object to "accidentally" be truthy for "t1.$isfoo" following a statement like

  window.localStorage['$isfoo'] = '1'

dart2js should definitely be generating a faster, specialized version of getInterceptor.
Before we can do this, we should make the getInterceptor call explicit in the SSA graph (Issue #9732)


Marked this as being blocked by #9732.

@kasperl
Copy link

kasperl commented May 23, 2013

Added TriageForM5 label.

@kasperl
Copy link

kasperl commented May 28, 2013

Removed TriageForM5 label.

@DartBot
Copy link
Author

DartBot commented Oct 30, 2013

This comment was originally written by ngeoffray@google.com


The getInterceptor call gets removed now, so I'll assume this bug as staled.


Added AssumedStale label.

@DartBot DartBot added Type-Defect web-dart2js closed-obsolete Closed as the reported issue is no longer relevant labels Oct 30, 2013
@DartBot DartBot added this to the Later milestone Oct 30, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-obsolete Closed as the reported issue is no longer relevant web-dart2js
Projects
None yet
Development

No branches or pull requests

4 participants