dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.06k stars 1.56k forks source link

Functions annotated with @pragma("vm:keep-name") should also not have obfuscated named parameters #53882

Open sstrickl opened 10 months ago

sstrickl commented 10 months ago

When writing tests that check class and function names (e.g., by doing string comparison of runtime types), @pragma("vm:keep-name") can be used to annotate those classes and functions so that the names won't be obfuscated when obfuscation is enabled.

However, the named parameters of a function are still obfuscated, even if the function is annotated with @pragma("vm:keep-names"), which is reflected when the type of the function is converted to a string for comparison. Is this on purpose, or just not considered when @pragma("vm:keep-name") was added?

See https://github.com/dart-lang/sdk/issues/53879 for context.

/cc @alexmarkov @mkustermann

sstrickl commented 10 months ago

That is, the fix I'm submitting for that issue checks the value of -Dtest_runner.configuration to skip the type check that incldues named parameters, after I noticed it still failed when adding @pragma("vm:keep-names") to the associated function, but it'd be nicer to have the pragma to explicitly mark the parameter names (and function name) as unobfuscated instead of having the test fail if run with an obfuscating VM but not under the test framework.

mkustermann commented 10 months ago

However, the named parameters of a function are still obfuscated, even if the function is annotated with @pragma("vm:keep-names"), which is reflected when the type of the function is converted to a string for comparison. Is this on purpose, or just not considered when @pragma("vm:keep-name") was added?

The annotation only affects class/function symbol names - it doesn't prevent tree shaking, it doesn't allow calling those symbols as entry points. So there's no obvious reason why the names of named parameters cannot be obfuscated, made mandatory, or even removed.

a-siva commented 10 months ago

@sstrickl I guess you are working on this.