feat: optionally use WASM function names for compiled methods - #168
feat: optionally use WASM function names for compiled methods#168andreas-karlsson wants to merge 2 commits into
Conversation
|
@andreas-karlsson quick note, please make sure you remove AI tools(co-authored) from the final commit as per policy for this repo. |
494e31d to
6cdaa60
Compare
6cdaa60 to
3173a98
Compare
|
@andreaTP I'm happy with the implementation so have promoted the PR for review. I haven't tried it with different compiler toolchains though, and I'm not sure I understand the need? If we see this as a feature to just get better readable output when inspecting stacktraces etc. then I don't think we can do better than replacing every disallowed char with an underscore. The possibility to extract the original func id remains as an escape hatch to retrieve the exact function name. |
|
@andreas-karlsson thanks a lot for this PR and for keeping improving the codebase!
To validate it actually improves readability or produce something that is useful.
This means that, once we get a function name, coming, for example, from Rust we won't be able to re-construct the original name by running I recall that Rust mangled function names easily become less readable if mangled again. |
|
Thanks @andreaTP, always happy to help! And this is something we'd need for our latest developments.
Indeed, and that is the sticking point. Is this a feature to get best effort (human) readable stacktraces, or is it intended for tooling? I think both are difficult to achieve at once. If we introduce escaping, mangled names will definitely look even more mangled. I think we have the following options:
Or do you see another option? If we want to keep it open we can include a naming strategy option instead to allow both? |
|
Here's a concrete proposal for a more generic solution. We add withNamingStrategy and introduce the enum
So far this only applies to methods but I think later it should also be done for locals and args. The above options should still be compatible. Let me know if you'd prefer a PR in this direction. |
|
Thanks for the update @andreas-karlsson ! I think we are going in the right direction, sharing a couple of things that come to mind:
What about making the mangling completely configurable user side(e.g. a SPI or similar)? is it a too big of a change? and providing a few default classes already. |
|
I got excited about opening this up to user-defined naming and different encodings, but thinking it through I now believe there are two separate problems here. Class files have proper debugging name tables for parameters and locals (MethodParameters, LocalVariableTable). They're informational — unverified, and with no uniqueness requirement — so they can carry names essentially as-is. There's no equivalent for method names, but the answer to that isn't to smuggle a debug section into the method names themselves. The hard constraint is that the WASM name section may contain duplicates, so any naming scheme has to add extraneous information to disambiguate. The natural choice is the WASM function id. That's also what gives tooling the most to work with: from the id you can look up the original name in the name section and demangle it properly — strictly better fidelity than anything we could encode into a method name. From a pure tooling perspective the best method name is arguably just the id, as in WASM itself, and So the question I'm posing is narrower: do we want something more recognizable alongside the id? Thread dumps are a key production debugging tool and have no standard symbolization step, so the method name is all you get. For that we could replace "func" with a sanitized name when one is available — the contract being that the name part is a human hint and tools should never parse it. They operate on the id. Given that, I'd drop the naming-strategy/SPI direction for now; there's nothing for a custom strategy to recover that the id doesn't already give you. And since debug names stay off by default, generated names are unchanged for existing users — so this should be safe in a minor release. |
Summary
Adds a
withUseDebugNames(boolean)compiler option that, when enabled, incorporates WASM function names from the module's name section into compiled JVM method names (e.g.foo_0instead offunc_0). This improves readability of stack traces, profiler output, and error messages.. ; [ / < >) are sanitized to_(see JVM Spec §4.2.2)extractFuncIdreplaces the previousstartsWith("func_")checks, handling both named and unnamed methodsUsage
Closes #167
Test plan