Add 'external-effect' pragma support to all the backends.
Call sites targeting a procedure annotated with `external-effect` will not produce any code, including the argument which will not be evaluated. However, the single parameter will be treated as 'live' for the purposes of any global analysis the backends do. This is useful for things like protobuf shaking where a user may want to retain certain protobuf messages without actually emitting the code that retains those messages. Today this functionality is available internally in the vm and wasm SDK libraries. dart2js has similar functionality represented via the opaqueTrue and opaqueFalse booleans (which will cause conditional branches to get shaken after analysis). This will replace dart2js's opaque(True/False). This also adds validation to the frontend to ensure a method annotated with 'external-effect' is well-formed. Change-Id: If1c4096673e655c58fe7638840a16125003e7809 Tested: Backend tests for codegen were added. A frontend test was added for the validation. A language test was added to confirm the behavior. Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476020 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Nate Biggs <natebiggs@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
d29b88d152
commit
3d2d6492c1
@@ -148,3 +148,12 @@ corresponding to the category the recognized method belongs to, as defined in
|
||||
The pragmas must match exactly the set of recognized methods. This enables
|
||||
kernel-level analyses and optimizations to query whether a method is recognized
|
||||
by the VM. The correspondence is checked when running in debug mode.
|
||||
|
||||
### Declaring an external effect method
|
||||
|
||||
```dart
|
||||
@pragma('external-effect')
|
||||
external void effect(Object? o);
|
||||
```
|
||||
|
||||
Declares a special static external method `effect` which the compiler will treat as live code when performing any analysis of the program. For example, a type referenced from this call that would otherwise be tree-shaken will no longer be tree-shaken. To reduce code size the call itself (and its arguments) are dropped in the compiled output though.
|
||||
|
||||
@@ -22,6 +22,7 @@ These pragmas are part of the VM's API and are safe for use in external code.
|
||||
| `vm:deeply-immutable` | [Specifying a class and all its subtypes are deeply immutable](deeply_immutable.md) |
|
||||
| `vm:align-loops` | Tells compiler to align all loop headers inside the function to an architecture specific boundary: currently 32 bytes on X64 and ARM64 (except Apple Silicon, which explicitly discourages aligning branch targets) |
|
||||
| `vm:no-sanitize-thread` | Disable ThreadSanitizer instrumentation |
|
||||
| `external-effect` | Declares a static method which will be treated as live code when performing any analysis of the program. The call itself (and its arguments) are then dropped from the running program.
|
||||
|
||||
## Unsafe pragmas for general use
|
||||
|
||||
|
||||
Reference in New Issue
Block a user