Skip to content

web runtimes should enforce int types on bit operations #45438

Open
@rakudrama

Description

@rakudrama

The DDC and dart2js runtimes implement the bit operations like & and << on (JavaScript) Number rather than on Dart int.
They should be upgraded to enforce int receiver and argument types. The lack of enforcement is a hold-over from Dart 1, where the extra cost of int checks would be too expensive. The enforcement is now mostly static.

The lack of enforcement does not affect statically typed code since the int interface enforces the receiver and argument types at compile time.

Dynamic code fails to check both the receiver and argument for being int, allowing non-integer floating point numbers into the calculation (where they are truncated according to the JavaScript ToInt32 operation).

The main benefit of better enforcement of the int types would be more uniform behaviour in testing, e.g. #45419.

The main disadvantage is that there will be performance regressions on paths that do the extra checks, and these regressions would need to be fixed

  • dynamic calls
  • calls that are not lowered to more basic operations (more of an issue with shifts that bit-wise operations)

DDC would need to go first, since the extra checks should not be a surprise in production.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-dart2jsweb-dev-compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions