Skip to content

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

Open
@mraleph

Description

@mraleph

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)

Activity

added
area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
type-performanceIssue relates to performance or code size
vm-aot-code-sizeRelated to improvements in AOT code size
on Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.type-performanceIssue relates to performance or code sizevm-aot-code-sizeRelated to improvements in AOT code size

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mraleph

        Issue actions

          remove redundant casts in expressions like (x as A) as B where B is a subtype of A · Issue #43296 · dart-lang/sdk