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

Go 1.11 support. #853

Merged
merged 23 commits into from Aug 25, 2018

Conversation

Projects
None yet
3 participants
@dmitshur
Member

dmitshur commented Aug 23, 2018

The go1.11 branch is now ready for review and testing. It requires Go 1.11 RC 2.

Please report any issues and opportunities to improve code. If there are no major issues discovered, the plan is to merge it when Go 1.11 (final) is released.

Fixes #836.

dmitshur added some commits Jun 26, 2018

natives/internal/cpu: Define CacheLineSize constant for GOARCH=js.
In Go 1.11, internal/cpu package is being used in more places
(including runtime), so it's no longer viable to avoid importing it.
Instead, fix the build by defining the CacheLineSize constant for js
architecture.

Set its value to 0 because it's not helpful in the context of GopherJS
to set it to a larger value. Internal field alignment isn't a factor.

Fixes:

	$ gopherjs build runtime
	internal/cpu/cpu.go:20:16: undeclared name: CacheLineSize
	internal/cpu/cpu.go:37:16: undeclared name: CacheLineSize
	internal/cpu/cpu.go:50:14: undeclared name: CacheLineSize
	internal/cpu/cpu.go:62:14: undeclared name: CacheLineSize
	internal/cpu/cpu.go:70:15: undeclared name: CacheLineSize
	internal/cpu/cpu.go:95:15: undeclared name: CacheLineSize
	internal/cpu/cpu.go:101:19: undeclared name: CacheLineSize
	internal/cpu/cpu.go:118:19: undeclared name: CacheLineSize
natives/sync: Update sync.WaitGroup fields.
sync.WaitGroup struct fields have changed in Go 1.11.
Update to the new ones.

Fixes:

	$ gopherjs build sync
	sync/waitgroup.go:34:49: cannot use &wg.state1[2] (value of type *byte) as *uint32 value in return statement
	sync/waitgroup.go:36:52: cannot use &wg.state1[0] (value of type *byte) as *uint32 value in return statement
natives/unicode: Update signature of to.
In Go 1.11, the responsibility of function to has been increased to
additionally report whether caseRange contained a mapping for r.
Update our modified copy of it to fix the build.

Fixes:

	$ gopherjs build unicode
	unicode/letter.go:248:9: cannot assign 1 values to 2 variables
	unicode/letter.go:305:20: cannot initialize 2 variables with 1 values
	unicode/letter.go:296:20: cannot initialize 2 variables with 1 values
	unicode/letter.go:287:20: cannot initialize 2 variables with 1 values

Follows golang/go@05f8b44.
natives/reflect: Sort exported methods first; add xcount to uncommonT…
…ype.

What was previously an unused blank identifier field of type uint16 in
Go 1.10 has become the xcount field in Go 1.11. Update our uncommonType
to match.

Also remove the unused uint32 field at the end. In normal Go, it's used
for padding and to keep the struct size fixed size. GopherJS doesn't
need that, because it doesn't support unsafe memory operations.

Fixes:

	$ gopherjs build reflect
	reflect/type.go:2603:5: invalid operation: ut (variable of type *uncommonType) has no field or method xcount
	reflect/type.go:643:7: invalid operation: t (variable of type *uncommonType) has no field or method xcount
	reflect/type.go:646:88: invalid operation: t (variable of type *uncommonType) has no field or method xcount
	reflect/type.go:646:97: invalid operation: t (variable of type *uncommonType) has no field or method xcount

Follows golang/go@86a3389.
Updates golang/go#22075.
natives/reflect: Use 'embedded' rather than 'anonymous'.
These have been renamed in Go 1.11. Update our code to match upstream.

Fixes:

	$ gopherjs build reflect
	reflect/reflect.go:153:6: unknown field offsetAnon in struct literal
	reflect/reflect.go:995:12: invalid operation: field (variable of type *structField) has no field or method anon

Follows golang/go@47be3d4.
natives/internal/syscall/unix: Define randomTrap; override IsNonblock.
In Go 1.11, the internal/syscall/unix package is also imported by
package os. It becomes a good idea to make it compile under GopherJS
by providing mock implementations of GetRandom and IsNonblock functions,
ones that don't try to make syscalls.

Fixes:

	$ GOOS=linux gopherjs build reflect
	internal/syscall/unix/getrandom_linux.go:29:5: undeclared name: randomTrap
	internal/syscall/unix/getrandom_linux.go:38:34: undeclared name: randomTrap

	$ gopherjs test --short reflect

	github.com/gopherjs/gopherjs/test.649712895:1412
	          throw new Error(msg);
	                ^
	Error: runtime error: native function not implemented: internal/syscall/unix.syscall_fcntl
	    at $callDeferred (github.com/gopherjs/gopherjs/test.649712895:1412:17)
	    at $panic (github.com/gopherjs/gopherjs/test.649712895:1451:3)
	    at throw$1 (github.com/gopherjs/gopherjs/runtime.go:221:3)
	    at syscall_fcntl (github.com/gopherjs/gopherjs/test.649712895:10092:3)
	    at Object.IsNonblock (/internal/syscall/unix/nonblocking.go:18:3)
	    at NewFile (/os/file_unix.go:83:6)
	    at Object.$init (github.com/gopherjs/gopherjs/test.649712895:11582:16)
	    at $init (github.com/gopherjs/gopherjs/test.649712895:48713:11)
	    at $goroutine (github.com/gopherjs/gopherjs/test.649712895:1471:19)
	    at $runScheduled (github.com/gopherjs/gopherjs/test.649712895:1511:7)
	    at $schedule (github.com/gopherjs/gopherjs/test.649712895:1527:5)
	    at $go (github.com/gopherjs/gopherjs/test.649712895:1503:3)
	    at Object.<anonymous> (github.com/gopherjs/gopherjs/test.649712895:48734:1)
	    at Object.<anonymous> (github.com/gopherjs/gopherjs/test.649712895:48737:4)
	    at Module._compile (internal/modules/cjs/loader.js:702:30)
	    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
	    at Module.load (internal/modules/cjs/loader.js:612:32)
	    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
	    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
	    at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
	    at startup (internal/bootstrap/node.js:238:19)
	    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
	FAIL	reflect	0.517s
natives/testing: Update frameSkip signature and implementation.
The scope of frameSkip helper has changed in Go 1.11.
Update the function signature and implementation to match.

This change helps GopherJS with running tests.
natives/strings: Skip TestBuilderGrow.
The test has started relying on testing.AllocsPerRun and
runtime.ReadMemStats in Go 1.11, which are not supported
by GopherJS. Skip the test, just like TestBuilderAllocs.

Fixes:

	$ gopherjs test --short strings
	--- FAIL: TestBuilderGrow (0.24s)
	    test.992502099:29524: growLen=100: got 0 allocs during Write; want 1
	    test.992502099:29524: growLen=1000: got 0 allocs during Write; want 1
	    test.992502099:29524: growLen=10000: got 0 allocs during Write; want 1
	    test.992502099:29524: growLen=100000: got 0 allocs during Write; want 1
	FAIL
	FAIL  strings     1.501s
natives/math: Use Go implementation for extreme Ldexp inputs.
In Go 1.11, there has been an improvement made to Ldexp for some
extreme values. The previous Math.pow-using algorithm doesn't produce
correct results. Use the Go implementation of ldexp for those values.

Continue to use the current Math.pow approach for other inputs because
it's much faster:

	$ gopherjs test -v --run=none --bench=Ldexp math
	BenchmarkLdexp 	2000000000	         0.44 ns/op

Compared to using the Go implementation for all inputs, without the
Math.pow fast path:

	$ gopherjs test -v --run=none --bench=Ldexp math
	BenchmarkLdexp 	 5000000	       203 ns/op

Follows golang/go@4b265fb.
Updates golang/go#23407.
natives/syscall: Implement rawSyscallNoError, unsetenv_c.
Go 1.11 added the rawSyscallNoError wrapper function which is used
for Linux syscalls that don't return an error and converted all
applicable occurences of RawSyscall to use it instead.
This change implements it for GopherJS on Linux.

Also implement unsetenv_c, analogous to setenv_c, so that os.Unsetenv
can be supported with Node.js, just like os.Setenv already was.

Fixes:

	$ GOOS=linux gopherjs test --short io
	Error: runtime error: native function not implemented: syscall.rawSyscallNoError
	FAIL	io	1.036s

	$ goexec -compiler=gopherjs 'os.Unsetenv("TEST")'
	Error: runtime error: native function not implemented: syscall.unsetenv_c

Follows golang/go@36951a9.
Updates golang/go#22924.

@dmitshur dmitshur referenced this pull request Aug 23, 2018

Closed

Go 1.11 support. #836

dvic and others added some commits Jul 21, 2018

natives/runtime: Add pkgpath method for _type. (#846)
The relevant upstream change is golang/go@cda1947.
A no-op implementation here is okay because the entire _type struct
is already no-op.
natives/crypto/internal/subtle: Implement for GopherJS.
Package crypto/internal/subtle is new to Go 1.11.
It's a copy of golang.org/x/crypto/internal/subtle,
added in golang/go@75d15a2.

There are two implementations: one uses unsafe, another uses reflect.
We can't use either because they both rely on pointer arithmetics,
which GopherJS doesn't support.

Create a custom impementation of AnyOverlap that makes use of
GopherJS slice internals.

Fixes crypto/des and crypto/rc4 tests.
natives/runtime: Update TypeAssertionError instantiation.
In the relevant upstream change is golang/go@cda1947,
fields of TypeAssertionError are changed from string to *_type.
This change follows suit and updates the instantiation of the
TypeAssertionError type in $assertType of compiler/prelude to
use the new definition. This happens when a type assertion fails.

Add test coverage for the runtime error string, since it wasn't
covered before.

Fixes fixedbugs/issue16130.go and fixedbugs/issue26094.go tests.
natives/reflect: Skip new failing test.
This is a new testcase in Go 1.11, related to golang/go@9558ba2
and golang/gofrontend@023c3d4. Resolving it requires further
investigation. Skip the failing test for now with a TODO comment,
because there may not be enough time to resolve it before the
Go 1.11 release. It can be addressed after.
Regenerate.
Done with latest vfsgen, including change in shurcooL/vfsgen@02ddb05
(there was a minor gofmt change for Go 1.11):

	go generate ./...

dmitshur added a commit to gopherjs/gopherjs.github.io that referenced this pull request Aug 25, 2018

playground: Regenerate with GopherJS 1.11-1 and Go 1.11.
Done on darwin/amd64 environment.

Regenerate with:

	go generate github.com/gopherjs/gopherjs.github.io/playground

Follows gopherjs/gopherjs#853.
@dmitshur

There haven't been any major issues discovered/reported, nor any opportunities to improve code suggested. Merging.

@dmitshur dmitshur merged commit 0210a2f into master Aug 25, 2018

1 check passed

ci/circleci Your tests passed on CircleCI!
Details

@dmitshur dmitshur deleted the go1.11 branch Aug 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment