Skip to content

Various standard library and compiler fixes to support Go 1.18 #1120

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 10 commits into from
Jun 10, 2022

Conversation

nevkontakte
Copy link
Member

@nevkontakte nevkontakte commented Jun 7, 2022

This set of changes resolves most (although not all) standard library test failures found by the CI. The list of changes include:

  • reflect: Provide stubs for string-optimized map access methods used by reflection.
  • prelude: correctly handle slice to array pointer conversion when the array is shorter than the original slice.
  • net/netip: do not use internal/intern optimization, which relies on unsupported unsafe features.
  • strings: support Clone() method.
  • math: use JavaScript NaN literal as a math.NaN() return value to address errors in the internal/fuzz package tests.
  • net/http: update a reference to a renamed variable.

Additionally this PR improves compiler panic handling that helped me debug some of the issues in this PR and temporarily excludes encoding/xml package from the test set, since it uses generics in tests. The package itself, however, works correctly and we will bring the tests back once generics support is implemented.

Updates #1092.

Corresponding upstream change:
golang/go@23832ba.

Our implementation is not, in fact, optimized, but at least it is
correct.
The JavaScript typed array that backs Go array must be shrunk to match
the expected Go type. If this is not done, copying the converted array
into an array of the same (expected) size causes a "source too large"
runtime exception.
The optimization this package implements relies heavily on finalizers,
which GopherJS doesn't support. As such it would create a memory leak
rather than an actual optimization. Until we decide that we can use
WeakMap API, this package can't be safely supported.

The only current use of this package is in the `net/netip` package and
this commit adds overlays that replace uses of the intern package with
direct use of strings.
In GopherJS this function is a no-op, since we don't have access to
low-level memory management. We also have to disable the corresponding
test, since it uses unsafe features we don't support.
Apparently, under V8 division by zero literal and by zero assigned to a
variable yields bitwise-different values of NaN, which broke some tests
in `internal/fuzz`. Using an actual NaN value from the JavaScript
runtime fixes the issue.

Isolated example: https://jsfiddle.net/j3rtaz0o/1/. Note that Firefox
doesn't seem to exhibit this issue.
This package uses generics in its tests, which we currently don't
support. This causes the compiler to crash.
@nevkontakte nevkontakte requested a review from flimzy June 7, 2022 12:49
@paralin
Copy link
Contributor

paralin commented Jun 9, 2022

Seems to build & run fine for me, thanks for your work on this.

@nevkontakte nevkontakte merged commit 6d4ada3 into gopherjs:go1.18 Jun 10, 2022
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