Skip to content

Type inference should have a representation of "any self-interceptor" #25646

@asgerf

Description

@asgerf

It is very important for dart2js to eliminate getInterceptor calls. When the type of x is known to be a self-interceptor, getInterceptor(x) can be replaced with just x.

However, the least upper bound of all self-interceptors does not have a compact representation as a TypeMask, because they have no common superclass other than Object, and Object is also the superclass of Interceptor.

Like the nullable bit in FlatTypeMask, we could have a bit indicating if it might be intercepted.

Below is an example of suboptimal code generated for an Angular2 benchmark.

rec.set$previousValue(v0);
rec.set$currentValue(null);
interceptor = J.getInterceptor$x(rec);
if (records.containsKey(interceptor.get$key(rec)))
  records.remove$1(0, interceptor.get$key(rec));

There is no need to get an interceptor after successfully calling a non-intercepted method on rec. The type refinement after the call has no effect because the refined type is too large to fit in a union type, so we lose the fact that it is a self-interceptor.

The example above can be fixed with a local analysis, but we still lose out on interprocedural information (e.g. knowing that a method returns a self-interceptor).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions