Files
sdk/pkg/dart2wasm/test/ir_tests/pure_function.dart
T
Martin Kustermann f99f5b1a2b [dart2wasm] Allow marking functions as pure functions
If a function doesn't have an effect we can now mark it via
`@pragma('wasm:pure-function')`. We'll then emit this as metadata
in the `binaryen.remove.if.unused` custom section.

This allows `wasm-opt` to remove calls to such functions if the result
of the call isn't used.

For now we mark a few string functions as pure.

Closes https://github.com/dart-lang/sdk/issues/62665

Change-Id: I8d38fb5894fd98248dc4d648d99c8cdcddc271a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/481802
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2026-02-23 01:39:37 -08:00

28 lines
626 B
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.
// functionFilter=runApp|foo
// tableFilter=NoMatch
// globalFilter=NoMatch
// typeFilter=NoMatch
// compilerOption=-O2
void main() => runApp();
@pragma('wasm:never-inline')
void runApp() {
foo('1');
foo('2');
print(foo('3'));
print(foo('4'));
}
@pragma('wasm:never-inline')
@pragma('wasm:pure-function')
dynamic foo(String arg) {
'foo($arg)'.length;
'bar($arg)'.length;
return arg.length;
}