Imprecise type annotation in dart2js

49 views
Skip to first unread message

Thomas

unread,
Aug 13, 2015, 4:50:12 AM8/13/15
to Dart Compiler Developers

Hej,


we are currently working on a static type inference for Dart and in this respect also take a look at the dart2js compiler code base. While this is work in progress, we have found the following case, which we think is a somewhat imprecise type annotation (i.e., the annotated static type for ' mirrorSystemGetNameNodes' does not provide a property which is later accessed whilst the actual type provides it) in dart2js:


> // pkg/compiler/lib/src/mirror_renamer/renamer.dart

> class MirrorRenamerImpl implements MirrorRenamer {

> // imprecise annotated type, proposed fix: replace by List<Send> and <Send>[], respectively

> List<Node> mirrorSystemGetNameNodes = <Node>[];

> ...

> void registerStaticSend(Element currentElement, Element target, Send node) {

> ...

> // only place where mirrorSystemGetNameNodes is modified

> mirrorSystemGetNameNodes.add(node);

> ...

> mirrorSystemGetNameNodes.forEach((node) {

> // annotated type is List<Node>, but Node does not provide properties selector/receiver

> renames[node.selector] = renames[getNameFunctionNode.name];

> renames[node.receiver] = '';


> // pkg/compiler/lib/src/tree/nodes.dart

> abstract class Node extends NullTreeElementMixin implements Spannable {

> // no property defined for name selector or receiver

> ...

>

> abstract class Expression extends Node {

> // no property defined for name selector or receiver

> ...

>

> class Send extends Expression with StoredTreeElementMixin {

> final Node receiver;

> final Node selector;

> ...


> // pkg/compiler/lib/src/mirror_renamer/mirror_renamer.dart

> class MirrorRenamer {

> void registerStaticSend(Element currentElement, Element target, Node node) {}

> ...


> // pkg/compiler/lib/src/dart_backend/placeholder_collector.dart

> ...

> visitStaticSend(Send node) {

> Element element = elements[node];

> // only call for method with this name

> collector.mirrorRenamer.registerStaticSend(

> collector.currentElement, element, node);


Our proposed fix would be, as noted in the comments, to replace 'List<Node>' by 'List<Send>' and '<Node>[]' by '<Send>[]'.


Kind regards

Thomas Heinze

Peter Ahé

unread,
Aug 13, 2015, 4:55:32 AM8/13/15
to Thomas, Dart Compiler Developers
Using Node rather than Send was chosen because it makes it easier to support error handling and new types of nodes. It does mean that some types are less precise, but it also means less fighting with the type system. Something you can spend a lot of time doing when the language gets a new feature you didn't anticipate. For example, that throw becomes an expression instead of a statement.

To unsubscribe from this group and stop receiving emails from it, send an email to compiler-dev...@dartlang.org.
Reply all
Reply to author
Forward
0 new messages