Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-generate identifiers for record_use #56043

Open
Tracked by #55555
mosuem opened this issue Jun 19, 2024 · 1 comment
Open
Tracked by #55555

Auto-generate identifiers for record_use #56043

mosuem opened this issue Jun 19, 2024 · 1 comment
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...).

Comments

@mosuem
Copy link
Member

mosuem commented Jun 19, 2024

With the upcoming record_use feature, users can record usage of certain Dart objects by placing @RecordUse annotations on the objects. To retrieve the recordings, they need to provide the identifier of the object, a 3-tuple of URI, parent class, and name. This is a source of errors, as typos can be made, and the identifiers have to be updated whenever the annotations are placed elsewhere.

To alleviate this, we could auto-generate the IDs, for example using macros. Example:

//in lib/src/myfile.dart
class MyClass {
  @RecordUse
  static bool isPositive(int i) => i > 0; 
}

@RecordUse
class MyAnnotation {
  const MyAnnotation();
}

//in lib/src/ids.g.dart
const MyClass_isPositive_ID = Identifier(
  uri: 'package:mypackage/lib/src/myfile.dart',
  parent: 'MyClass',
  name: 'isPositive',
);

const MyAnnotation_ID = Identifier(
  uri: 'package:mypackage/lib/src/myfile.dart',
  name: 'MyAnnotation',
);

//in hook/link.dart
import '../lib/src/ids.g.dart';

void main(List<String> arguments){
  link(arguments, (config, output) async {
    final uses = config.recordedUses;
    
    final args = uses.constArgumentsTo(MyClass_isPositive_ID));

    final fields = uses.instanceReferencesTo(MyAnnotation_ID);

    ... // Do something with the information, such as tree-shaking native assets
  });
}

cc @dcharkes @mkustermann @jakemac53

@mosuem mosuem added the area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). label Jun 19, 2024
@jakemac53
Copy link
Contributor

jakemac53 commented Jun 20, 2024

I don't know anything about the referenced record_use feature - but yes generating these identifiers should be trivial using a macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...).
Projects
None yet
Development

No branches or pull requests

2 participants