Skip to content

[record_use] Correctness: Scope const instance recording to annotations only #2719

@dcharkes

Description

@dcharkes

The current behavior of recording all const instantiations of an annotated class undermines this workflow. The report generated by record_use contains both

  1. annotation usages (@MyAnnotation(...)), and
  2. const instantiations of the same class in regular code.

For use cases where we are only interested in annotations (or rather, the classes or method calls that have the annotations that weren't tree-shaken out), the instantiations in running Dart code are noise.

For the use cases where we are interested in all instances only having the const instances lacks the counter part of the non-const instances constructed by constructor calls. This provides a non-true view of all instances.

Proposed solution

Refine the scope of instance recording to only record const instances that are used as metadata annotations.

We should then also rename it to record-annotations rather than record-const-instances.

Alternative considered

Try to collect all constructor invocations of a certain type, including their const arguments. This is better served as putting a record-use annotation on the constructors to record call sites. However, then you'd miss the const instances, as the the compiler does not track constructor calls for const instances. The workaround is to make the constructors non-const, but that's undesirable. Since the main use case is annotations anyway, let's not try to do this.

@HosseinYousefi This covers your JniGen use case right?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions