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

Feature request: compile time assertions #47898

Open
dnfield opened this issue Dec 11, 2021 · 0 comments
Open

Feature request: compile time assertions #47898

dnfield opened this issue Dec 11, 2021 · 0 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. vm-aot-code-size Related to improvements in AOT code size

Comments

@dnfield
Copy link
Contributor

dnfield commented Dec 11, 2021

I would really like to be able to write code like this:

/// A class used only in debug mode.
@pragma('unretained', const bool.fromEnvironment('dart.vm.product'))
class DebugInformationHolder {}

class Foo {
  @pragma('unretained', const bool.fromEnvironment('dart.vm.product') || const bool.fromEnrivonment('dart.vm.profile'))
  bool _debugSomethingOrOther = true;
}

I would like this annotation to be able to be applied to methods, constructors, fields, getters/setters, or class definitions. I am not really concerned with whether it is a pragma or its own annotation.

I would like this annotation to do nothing at runtime, but trigger a compile time error if annotated code ended up in the final binary (e.g. after the VM optimizer pass in gen_snapshot). Ideally, it would also show the call graph(s) that led to that code being retained.

This is a similar request to #28113, but I want this to trigger compilation errors, not analysis warnings.

This is a similar request to #35303, but I want this to trigger compilation errors, since I should never be referring to this code at all in release mode and I don't even want placeholder objects.

These errors should be ignorable in cases where a library writer has annotated something but an application author decides to explicitly invoke it in the forbidden mode anyway.

@dnfield dnfield added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. vm-aot-code-size Related to improvements in AOT code size labels Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. vm-aot-code-size Related to improvements in AOT code size
Projects
None yet
Development

No branches or pull requests

1 participant