Skip to content

remove redundant casts in expressions like (x as A) as B where B is a subtype of A #43296

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
mraleph opened this issue Sep 2, 2020 · 0 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-performance Issue relates to performance or code size vm-aot-code-size Related to improvements in AOT code size

Comments

@mraleph
Copy link
Member

mraleph commented Sep 2, 2020

Flutter contains the following pattern of super-calls:

class MultiChildRenderObjectElement extends RenderObjectElement {
  @override
  MultiChildRenderObjectWidget get widget => super.widget as MultiChildRenderObjectWidget;
}

abstract class RenderObjectElement extends Element {
  @override
  RenderObjectWidget get widget => super.widget as RenderObjectWidget;
}

abstract class Element extends DiagnosticableTree implements BuildContext {
  @override
  Widget get widget => _widget;
  Widget _widget;
}

If the chain fully inlined we get the following graph:

v139 <- LoadField(v2 . _widget@246042623) T{Widget?}
AssertAssignable:14(v139 T{Widget?}, v125, ' in type cast', instantiator_type_args(v0), function_type_args(v0)) T{RenderObjectWidget?}
AssertAssignable:14(v139 T{RenderObjectWidget?}, v71, ' in type cast', instantiator_type_args(v0), function_type_args(v0))

Here the second assert assignable can "consume" the first one.

(@rakudrama brought my attention to these chains in dart-lang/language#1189)

@mraleph mraleph added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-performance Issue relates to performance or code size vm-aot-code-size Related to improvements in AOT code size labels Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-performance Issue relates to performance or code size vm-aot-code-size Related to improvements in AOT code size
Projects
None yet
Development

No branches or pull requests

1 participant