Skip to content
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

feat: store local name in debug mode binary #2437

Merged
merged 14 commits into from
Aug 21, 2022

Conversation

HerrCai0907
Copy link
Member

The goal of PR is to output local variant name into wasm custom section and wat file for easier debug.

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

src/module.ts Outdated Show resolved Hide resolved
src/compiler.ts Outdated Show resolved Hide resolved
src/compiler.ts Outdated Show resolved Hide resolved
src/compiler.ts Outdated Show resolved Hide resolved
src/module.ts Outdated Show resolved Hide resolved
@dcodeIO
Copy link
Member

dcodeIO commented Aug 16, 2022

One question that remains is whether local names should also be set when optimizing. From what I've seen, when optimizations are enabled and locals are merged or moved around, the names don't match anymore, which is not so much a problem in a binary, but is weird in optimized text format outputs which then don't make sense anymore. Could be prevented by only setting the names when !options.willOptimize or so.

@dcodeIO
Copy link
Member

dcodeIO commented Aug 16, 2022

Or rather look for options.debug? Hmm. What do you folks think?

@MaxGraey
Copy link
Member

Or rather look for options.debug? Hmm. What do you folks think?

I think it's better

@HerrCai0907
Copy link
Member Author

Or rather look for options.debug? Hmm. What do you folks think?

I think it's better

I don't find options.debug.
Of course It's possible to add a new field to store this information, but I think the relationship between debug and willOptimize can be confusing and we need to add some warning for the usage like --debug -O2

@dcodeIO
Copy link
Member

dcodeIO commented Aug 16, 2022

Ah, you are right, there is no parameter for debug info yet. I guess for now willOptimize is fine as it is only true if optimizeLevel = shrinkLevel = 0.

@dcodeIO
Copy link
Member

dcodeIO commented Aug 16, 2022

What this doesn't solve, btw, just to note, is that scoped variables are shared. Say in

{
  let a = 1;
}
{
  let b = 2;
}

there is only one concrete local since a is freed and reused. Somewhat by design currently.

@HerrCai0907
Copy link
Member Author

Is it possible to ignore free temp local in !options.willOptimize mode?

@dcodeIO
Copy link
Member

dcodeIO commented Aug 16, 2022

Currently there is an unfortunate cross-dependency I believe that is introduced by a few places where code is re-compiled. What happens there is:

  1. Compile the code the first time, sharing locals as needed
  2. Free shared locals
  3. Compile the code again, relying on shared locals obtaining the same indexes

Now, if locals weren't shared, re-compilation would produce garbage locals I think. I guess this would have to be tackled prior in order to guarantee proper names. Generally good to fix this eventually I think, and always use a dedicated local per name that isn't freed.

src/compiler.ts Outdated Show resolved Hide resolved
src/compiler.ts Outdated Show resolved Hide resolved
src/module.ts Outdated Show resolved Hide resolved
@MaxGraey MaxGraey requested a review from dcodeIO August 20, 2022 13:27
src/module.ts Outdated Show resolved Hide resolved
@MaxGraey MaxGraey merged commit 6968448 into AssemblyScript:main Aug 21, 2022
@MaxGraey
Copy link
Member

Thanks!

@HerrCai0907 HerrCai0907 deleted the feat/add-local-name branch August 21, 2022 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants