Improve type information for default parameters

NEW
Unassigned

Status

()

P3
normal
2 years ago
11 months ago

People

(Reporter: jandem, Unassigned)

Tracking

(Blocks: 2 bugs, {perf})

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

2 years ago
See bug 1306450. The following pattern is quite common:

  if (x === undefined)
      x = 0;

ES6 default arguments use similar bytecode:

  function f(x = 0) {}

IonBuilder has code to optimize TypeSets when using these comparisons, but it doesn't handle this case. After the if-statement, we should be able to remove |undefined| from x's TypeSet, with some analysis.
Keywords: perf
Blocks: 1307395
Summary: Improve type information for optional arguments → Improve type information for default parameters
Assignee: nobody → evilpies
Assignee: evilpies → nobody
Is this still a problem? I think I get the correct information for this trivial example.

> function f(x) {
>    if (x === undefined)
>        x = 0;
>    return x;
> }
>
> function g(x = 0) {
>    return x;
> }
>
> f()
> g()
This example is probably too trivial. We want good type information even when the call to f or g is not inlined and the method is called with no parameter, undefined and some number like 0.

So even when type of x is undefined or a number the type inside the body (or after the if) is still a number.
You need to log in before you can comment on or make changes to this bug.