3d2d6492c1
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>
52 lines
1.1 KiB
Dart
52 lines
1.1 KiB
Dart
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
@pragma('external-effect')
|
|
external int a;
|
|
|
|
@pragma('external-effect')
|
|
external int get b;
|
|
|
|
@pragma('external-effect')
|
|
external set c(int value);
|
|
|
|
@pragma('external-effect')
|
|
void d(Object? o) {}
|
|
|
|
@pragma('external-effect')
|
|
external void e(Object o);
|
|
|
|
const z = 'external-effect';
|
|
|
|
@pragma(z)
|
|
external void f(Object? o);
|
|
|
|
class A {
|
|
@pragma('external-effect')
|
|
external void a(Object? o);
|
|
|
|
@pragma('external-effect')
|
|
external static int b(Object? o);
|
|
|
|
@pragma('external-effect')
|
|
external static void c(Object? o, Object? x);
|
|
|
|
@pragma('external-effect')
|
|
external static void d(int i);
|
|
|
|
@pragma('external-effect')
|
|
external static void e([Object? o = const Object()]);
|
|
|
|
@pragma('external-effect')
|
|
external static void f({required Object? o});
|
|
|
|
@pragma('external-effect')
|
|
external static void g({Object? o = 3});
|
|
|
|
@pragma('external-effect')
|
|
external static void h<T>(T? t);
|
|
}
|
|
|
|
void main() {}
|