Skip to content

Final round of refactoring ported from the original generics branch. #1335

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

Merged
merged 5 commits into from
Aug 3, 2024

Conversation

nevkontakte
Copy link
Member

  • Factor out unimplemented function body generation into a helper.
  • Remove an unnecessary special case for methods with array-pointer receivers.
  • Move method translation logic into its own method, similar to the existing one for standalone functions.
  • Assign identities to all function literals and use them as funcRefs. This unifies translation logic between named and literal functions and reduces the number of arguments we have to pass around.
  • Add some comments to the existing code.

Updates #1013

(based on commit d15130f)

This special case doesn't seem to serve any purpose that I can discern.
My best guess is that it was necessary at some point, but the compiler
has changed to not need it anymore.

The compiler seems to wrap the returned value in a pointer-type at a
call site as appropriate anyway and defining this method on the value
type doesn't seem correct.
 - Move it into a separate function, similar to
   translateStandaloneFunction().
 - Add some comments explaining quirks of GopherJS's method
   implementation.

(based on commit ccda918)
@nevkontakte nevkontakte requested a review from flimzy July 31, 2024 19:21
@nevkontakte nevkontakte enabled auto-merge July 31, 2024 22:16
The main change is that we assign explicit names to all function objects
that correspond to Go functions (named and literals). Function name is
declared as `var f = function nameHere() { ... }` and is visible inside
the function scope only. Doing so serves two purposes:

 - It is an identifier which we can use when saving state of a blocked
   function to know which function to call upon resumption.
 - It shows up in the stack trace, which helps distinguish
   similarly-named functions. For methods, we include the receiver type
   in the identifier to make A.String and B.String easily
   distinguishable.

The main trick is that we synthesize names for the function literals,
which are anonymous as far as go/types is concerned. The upstream Go
compiler does something very similar.

(based on commit 4d24395)
JS function names are subtly different from what vanilla Go may expect,
unless gopherjs#1085 is implemented.
It turns out that a combination of
d5771cc and 22c65b8
subtly changes how node outputs stack trace in a way that breaks my
workarounds in the reflect package.

Instead of further fumbling, I am going to disable the offending tests
temporarily, and I have a proper fix for gopherjs#1085 in the works, which will
allow us to re-enable them along with a few other tests.
@nevkontakte nevkontakte merged commit 1ebb325 into gopherjs:master Aug 3, 2024
10 checks passed
@nevkontakte nevkontakte deleted the gng7 branch August 3, 2024 15:58
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.

2 participants