Skip to content

[record_use] Correctness: Non-obvious const argument values (differences between backends) #2889

@dcharkes

Description

@dcharkes

The VM promotes a non-const value to const, dart2js does not.

$ diff pkg/vm/testcases/transformations/record_use/complex.dart.json.expect pkg/compiler/test/record_use/golden/complex.json.expect

3a4,7
>       "type": "String",
>       "value": "somestring"
>     },
>     {
25a39
>             0,
27,28c41
<             null,
<             0
---
>             1

The string argument is recorded as non-const in dart2js but as the string in the VM.

class OtherClass {
  String string = 'somestring';

  @RecordUse()
  static Future<String> generate(
    AssetBundle bundle,
    List args,
    String string,
    AnotherClass object,
    int index,
  ) async {
    final message = await bundle.byIndex(string: string, index: index);
    return message.generateString(args, object: object);
  }
}

This leads to inconsistencies between compilers.

We either need to

  1. restrict recording to only things from const sources, or
  2. accept differences between backends - based on best-effort.

If we go for (2), we need to specify what a backend at minimum needs to provide to be compliant.
Otherwise we risk someone testing with the VM compiler, thinking tree-shaking works, and inflating their web targets.

Also, if we go for (2), we need to be smarter about testing. We'd need some bool RecordedUses.containsAll(RecordedUses other) method so that we can use the minimum requirements to be compliant.

cc @goderbauer

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions