Skip to content

Include original function names into GopherJS source maps. #1338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nevkontakte
Copy link
Member

Previously GopherJS only emitted mapping between original and generated source locations. With this change it also includes original function names, which fixes #1085.

Before:

$ go install github.com/gopherjs/gopherjs && gopherjs run -m main.go
    at Object.CL (/runtime/gopherjs__runtime.go:450:3)
    at AO (/runtime/debug/stack.go:24:4)
    at Object.AN (/runtime/debug/stack.go:16:3)
    at D (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:14:3)
    at E (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:18:3)
    at $init (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:17:7)
    at $goroutine (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.3435578257:7:1727)
    at $runScheduled (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.3435578257:7:2359)
    at $schedule (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.3435578257:7:2574)
    at $go (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.3435578257:7:2210)
...

After:

$ go install github.com/gopherjs/gopherjs && gopherjs run -m main.go
    at runtime.Stack (/runtime/gopherjs__runtime.go:450:3)
    at runtime/debug.Stack (/runtime/debug/stack.go:24:4)
    at runtime/debug.PrintStack (/runtime/debug/stack.go:16:3)
    at main.x (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:14:3)
    at main.main (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:18:3)
    at $init (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:17:7)
    at $goroutine (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.2187228924:7:1727)
    at $runScheduled (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.2187228924:7:2359)
    at $schedule (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.2187228924:7:2574)
    at $go (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.2187228924:7:2210)
...

While working on this, I moved sourcemap hinting logic into its own package and added some tests. The implementation could still use some improvements, but it should be a significant improvement in the majority of cases.

@nevkontakte nevkontakte force-pushed the gng8 branch 2 times, most recently from 1843b57 to 8c118fc Compare August 5, 2024 13:17
@nevkontakte nevkontakte enabled auto-merge August 5, 2024 13:18
@nevkontakte nevkontakte disabled auto-merge August 5, 2024 13:32
@nevkontakte
Copy link
Member Author

Hmm, those Windows errors are unexpected. I'll look into them a bit later.

@IngwiePhoenix
Copy link
Contributor

Wanted to see if I could help, since my main dev environment lives on Windows.

But...

The logs for this run have expired and are no longer available.

Do you have them copied, by chance?

The main change in this commit is an ability to use identifier name
mapping, which we use to show original function names in the source map.

This addresses the long-standing gopherjs#1085,
where GopherJS call stacks were somewhat difficult to interpret due to
function name mangling, especially in minified form. Now we emit an
additional source map hit with the original function name, which Node is
able to pick up.

While at it, I moved source map hinting logic into its own package with
tests and added some documentation on how it works. Now it should be
easy to extend this mechanism for even richer source maps if we want to.
The tests that were previously failing should work again with the new
function name source maps. There are only two caveats at this point:

 - For some reasons a function that's currently executing deferrals
   doesn't map to its original name.
 - Synthetic names for literal functions differ in format slightly from
   vanilla Go, which still breaks the test in net/http. The difference
   is minor enough it's not forth fixing though.
@IngwiePhoenix
Copy link
Contributor

# github.com/gopherjs/gopherjs/build/cache
Error: build\cache\cache.go:114:48: too many arguments in call to compiler.WriteArchive
	have (*compiler.Archive, time.Time, *os.File)
	want (*compiler.Archive, io.Writer)
github.com/gopherjs/gopherjs/build
Error: Process completed with exit code 1.

Change seems to be here: d63a9b8#diff-d3cde2dec4b7c2263747b17d43f704418e6657b49583254628bcad1d1052471bR325

Curious, because I don't know much of GopherJS' internals, this seems to be part of the "official" Go compiler itself. Is it hardforked or something...? Would love to know a little more, if you have the time. ^^

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include original function names in the source map
3 participants