Skip to content

Support Go1.12 #900

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 27 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
62c39c2
Target Go 1.12, update version to GopherJS 1.12-wip.
hajimehoshi Mar 2, 2019
a395e60
compiler/natives/src/internal/cpu: Add CacheLinePadSize
hajimehoshi Mar 2, 2019
f022788
compiler/natives/src/reflect: Update function signatures
hajimehoshi Mar 2, 2019
80a8d4e
compiler/natives/src/syscall: Add Syscall18
hajimehoshi Mar 2, 2019
9576d72
compiler/natives/src/syscall: Rename syscall
hajimehoshi Mar 2, 2019
756c79f
Update circle.yml
hajimehoshi Mar 2, 2019
96c95ab
compiler/natives/src/internal/syscall/unix: Add fstatatTrap
hajimehoshi Mar 3, 2019
6b3d4d1
go generate
hajimehoshi Mar 2, 2019
f65c39d
compiler/natives/src/syscall: Define syscall functions for Darwin
hajimehoshi Mar 3, 2019
9793ddf
compiler/natives/src/crypto/rand: Add func batched
hajimehoshi Mar 3, 2019
c0c4111
compiler/natives/src: Fix some test failures
hajimehoshi Mar 3, 2019
3a29d97
compiler/natives/src: Fix test failures
hajimehoshi Mar 3, 2019
250c084
compiler/natives/src/reflect: Fix failure tests
hajimehoshi Mar 3, 2019
57d7708
tests: Add new failure tests in Go 1.12
hajimehoshi Mar 3, 2019
cf99cfe
Address on reviews
hajimehoshi Mar 4, 2019
158447e
Address on reviews
hajimehoshi Mar 5, 2019
db381e3
Fix circle.yml
hajimehoshi Mar 5, 2019
35239cf
Fix testing issues on macOS
hajimehoshi Mar 5, 2019
2ea661b
reflect: Reimplement mapiter functions
hajimehoshi Mar 5, 2019
4711f47
Remove filename suffixes _js
hajimehoshi Mar 9, 2019
a2f6a71
Add .std_test_pkg_exlusions
hajimehoshi Mar 9, 2019
9da6e14
Test internal/fmtsort
hajimehoshi Mar 9, 2019
3844e18
Add more testable standard libs
hajimehoshi Mar 10, 2019
e34c676
Fix .std_test_pkg_exclusions
hajimehoshi Mar 10, 2019
18df411
go generate
hajimehoshi Mar 9, 2019
8471480
compiler/natives/src/reflect: Add comments
hajimehoshi Mar 27, 2019
09ef6f4
compiler: Update version to 1.12-1
hajimehoshi Mar 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions .std_test_pkg_exclusions
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
context
crypto
crypto/internal/randutil
crypto/internal/subtle
crypto/internal/cipherhw
crypto/tls
crypto/x509/pkix
debug/gosym
Expand All @@ -16,8 +15,8 @@ go/types
hash
image/color/palette
image/internal/imageutil
internal/bytealg
internal/cpu
internal/goroot
internal/nettrace
internal/poll
internal/race
Expand All @@ -29,6 +28,7 @@ internal/syscall/windows/sysdll
internal/testenv
internal/testlog
internal/trace
internal/x/net/nettest
log
log/syslog
net
Expand All @@ -52,6 +52,7 @@ runtime
runtime/cgo
runtime/debug
runtime/internal/atomic
runtime/internal/math
runtime/internal/sys
runtime/pprof
runtime/pprof/internal/profile
Expand All @@ -62,22 +63,3 @@ testing
testing/internal/testdeps
testing/iotest
unsafe
vendor/golang_org/x/crypto/chacha20poly1305
vendor/golang_org/x/crypto/cryptobyte
vendor/golang_org/x/crypto/cryptobyte/asn1
vendor/golang_org/x/crypto/curve25519
vendor/golang_org/x/crypto/internal/chacha20
vendor/golang_org/x/crypto/poly1305
vendor/golang_org/x/net/dns/dnsmessage
vendor/golang_org/x/net/http/httpguts
vendor/golang_org/x/net/http/httpproxy
vendor/golang_org/x/net/http2/hpack
vendor/golang_org/x/net/idna
vendor/golang_org/x/net/internal/nettest
vendor/golang_org/x/net/nettest
vendor/golang_org/x/text/secure
vendor/golang_org/x/text/secure/bidirule
vendor/golang_org/x/text/transform
vendor/golang_org/x/text/unicode
vendor/golang_org/x/text/unicode/bidi
vendor/golang_org/x/text/unicode/norm
6 changes: 3 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- checkout
- run: git clone https://github.com/creationix/nvm $HOME/.nvm && cd $HOME/.nvm && git checkout v0.33.9 && echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV && echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
- run: nvm install 10.0.0 && nvm alias default 10.0.0
- run: cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.11.5.linux-amd64.tar.gz | sudo tar -xz
- run: cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.12.linux-amd64.tar.gz | sudo tar -xz
- run: echo 'export PATH="$PATH:/usr/local/go/bin:$HOME/go/bin"' >> $BASH_ENV
- run: go get -t -d -v ./...
- run: go install -v
Expand All @@ -22,8 +22,8 @@ jobs:
- run: go generate github.com/gopherjs/gopherjs/compiler/prelude
- run: diff -u <(echo -n) <(git status --porcelain)
- run: diff -u <(echo -n) <(gofmt -d .)
- run: go tool vet *.go # Go package in root directory.
- run: for d in */; do echo $d; done | grep -v tests/ | grep -v third_party/ | xargs go tool vet # All subdirectories except "tests", "third_party".
- run: go vet . # Go package in root directory.
- run: for d in */; do echo ./$d...; done | grep -v ./doc | grep -v ./tests | grep -v ./node | xargs go vet # All subdirectories except "doc", "tests", "node*".
- run: diff -u <(echo -n) <(go list ./compiler/natives/src/...) # All those packages should have // +build js.
- run: gopherjs install -v net/http # Should build successfully (can't run tests, since only client is supported).
- run: ulimit -s 10000 && gopherjs test --minify -v --short github.com/gopherjs/gopherjs/tests/... $(go list std | grep -v -x -f .std_test_pkg_exclusions)
Expand Down
2 changes: 1 addition & 1 deletion compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

var sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8}
var reservedKeywords = make(map[string]bool)
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_11___ // Compile error on other Go versions, because they're not supported.
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_12___ // Compile error on other Go versions, because they're not supported.

func init() {
for _, keyword := range []string{"abstract", "arguments", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "undefined", "var", "void", "volatile", "while", "with", "yield"} {
Expand Down
16 changes: 8 additions & 8 deletions compiler/gopherjspkg/fs_vfsdata.go

Large diffs are not rendered by default.

323 changes: 189 additions & 134 deletions compiler/natives/fs_vfsdata.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions compiler/natives/src/crypto/rand/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@ func (r *rngReader) Read(b []byte) (n int, err error) {

return 0, errors.New("crypto/rand not available in this environment")
}

func batched(f func([]byte) bool, readMax int) func([]byte) bool {
return func(buf []byte) bool {
for len(buf) > readMax {
if !f(buf[:readMax]) {
return false
}
buf = buf[readMax:]
}
return len(buf) == 0 || f(buf)
}
}
15 changes: 15 additions & 0 deletions compiler/natives/src/internal/bytealg/bytealg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build js

package bytealg

func Equal(a, b []byte) bool {
if len(a) != len(b) {
return false
}
for i, c := range a {
if c != b[i] {
return false
}
}
return true
}
8 changes: 8 additions & 0 deletions compiler/natives/src/internal/cpu/cpu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build js

package cpu

const (
CacheLineSize = 0
CacheLinePadSize = 0
)
5 changes: 0 additions & 5 deletions compiler/natives/src/internal/cpu/cpu_js.go

This file was deleted.

58 changes: 58 additions & 0 deletions compiler/natives/src/internal/fmtsort/fmtsort_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// +build js

package fmtsort_test

import (
"math"
"reflect"
"testing"

"internal/fmtsort"
)

// needsSkip reports whether the kind doesn't work for sorting on GopherJS.
func needsSkip(k reflect.Kind) bool {
switch k {
case reflect.Ptr, reflect.Chan:
return true
}
return false
}

// Note: sync with the original TestCompare.
func TestCompare(t *testing.T) {
for _, test := range compareTests {
for i, v0 := range test {
for j, v1 := range test {
if needsSkip(v0.Kind()) {
continue
}
if needsSkip(v1.Kind()) {
continue
}

c := fmtsort.Compare(v0, v1)
var expect int
switch {
case i == j:
expect = 0
// NaNs are tricky.
if typ := v0.Type(); (typ.Kind() == reflect.Float32 || typ.Kind() == reflect.Float64) && math.IsNaN(v0.Float()) {
expect = -1
}
case i < j:
expect = -1
case i > j:
expect = 1
}
if c != expect {
t.Errorf("%s: compare(%v,%v)=%d; expect %d", v0.Type(), v0, v1, c, expect)
}
}
}
}
}

func TestOrder(t *testing.T) {
t.Skip("known issue: nil key doesn't work")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package unix

const randomTrap = 0
const fstatatTrap = 0

func IsNonblock(fd int) (nonblocking bool, err error) {
return false, nil
Expand Down
18 changes: 18 additions & 0 deletions compiler/natives/src/math/bits/bits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build js

package bits

type _err string

func (e _err) Error() string {
return string(e)
}

// RuntimeError implements runtime.Error.
func (e _err) RuntimeError() {
}

var (
overflowError error = _err("runtime error: integer overflow")
divideError error = _err("runtime error: integer divide by zero")
)
2 changes: 1 addition & 1 deletion compiler/natives/src/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func Trunc(x float64) float64 {
if x == posInf || x == negInf || x != x || 1/x == negInf {
return x
}
return float64(int(x))
return Copysign(float64(int(x)), x)
}

var buf struct {
Expand Down
8 changes: 8 additions & 0 deletions compiler/natives/src/math/math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

package math_test

import (
"testing"
)

// Slighly higher tolerances than upstream, otherwise TestGamma fails.
// TODO: Is there a better way to fix TestGamma? It's weird that only one test
// requires increasing tolerances. Perhaps there's a better fix? Maybe we
Expand All @@ -10,3 +14,7 @@ package math_test
// is fine?
func close(a, b float64) bool { return tolerance(a, b, 4e-14) }
func veryclose(a, b float64) bool { return tolerance(a, b, 6e-15) }

func testExp(t *testing.T, Exp func(float64) float64, name string) {
t.Skip("inaccurate")
}
65 changes: 57 additions & 8 deletions compiler/natives/src/reflect/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,20 +550,67 @@ type mapIter struct {
m *js.Object
keys *js.Object
i int

// last is the last object the iterator indicates. If this object exists, the functions that return the
// current key or value returns this object, regardless of the current iterator. It is because the current
// iterator might be stale due to key deletion in a loop.
last *js.Object
}

func (iter *mapIter) skipUntilValidKey() {
for iter.i < iter.keys.Length() {
k := iter.keys.Index(iter.i)
if iter.m.Get(k.String()) != js.Undefined {
break
}
// The key is already deleted. Move on the next item.
iter.i++
}
}

func mapiterinit(t *rtype, m unsafe.Pointer) unsafe.Pointer {
return unsafe.Pointer(&mapIter{t, js.InternalObject(m), js.Global.Call("$keys", js.InternalObject(m)), 0, nil})
}

func mapiterinit(t *rtype, m unsafe.Pointer) *byte {
return (*byte)(unsafe.Pointer(&mapIter{t, js.InternalObject(m), js.Global.Call("$keys", js.InternalObject(m)), 0}))
func mapiterkey(it unsafe.Pointer) unsafe.Pointer {
iter := (*mapIter)(it)
var kv *js.Object
if iter.last != nil {
kv = iter.last
} else {
iter.skipUntilValidKey()
if iter.i == iter.keys.Length() {
return nil
}
k := iter.keys.Index(iter.i)
kv = iter.m.Get(k.String())

// Record the key-value pair for later accesses.
iter.last = kv
}
return unsafe.Pointer(js.Global.Call("$newDataPointer", kv.Get("k"), jsType(PtrTo(iter.t.Key()))).Unsafe())
}

func mapiterkey(it *byte) unsafe.Pointer {
iter := (*mapIter)(unsafe.Pointer(it))
k := iter.keys.Index(iter.i)
return unsafe.Pointer(js.Global.Call("$newDataPointer", iter.m.Get(k.String()).Get("k"), jsType(PtrTo(iter.t.Key()))).Unsafe())
func mapitervalue(it unsafe.Pointer) unsafe.Pointer {
iter := (*mapIter)(it)
var kv *js.Object
if iter.last != nil {
kv = iter.last
} else {
iter.skipUntilValidKey()
if iter.i == iter.keys.Length() {
return nil
}
k := iter.keys.Index(iter.i)
kv = iter.m.Get(k.String())
iter.last = kv
}
return unsafe.Pointer(js.Global.Call("$newDataPointer", kv.Get("v"), jsType(PtrTo(iter.t.Elem()))).Unsafe())
}

func mapiternext(it *byte) {
iter := (*mapIter)(unsafe.Pointer(it))
func mapiternext(it unsafe.Pointer) {
iter := (*mapIter)(it)
iter.last = nil
iter.i++
}

Expand Down Expand Up @@ -1030,6 +1077,8 @@ func (v Value) IsNil() bool {
return v.object() == js.InternalObject(false)
case Interface:
return v.object() == js.Global.Get("$ifaceNil")
case UnsafePointer:
return v.object().Unsafe() == 0
default:
panic(&ValueError{"reflect.Value.IsNil", k})
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/natives/src/reflect/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func TestStructOfWithInterface(t *testing.T) {
t.Skip("StructOf")
}

func TestStructOfTooManyFields(t *testing.T) {
t.Skip("StructOf")
}

var deepEqualTests = []DeepEqualTest{
// Equalities
{nil, nil, true},
Expand Down
4 changes: 4 additions & 0 deletions compiler/natives/src/strings/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ func TestBuilderAllocs(t *testing.T) {
func TestBuilderGrow(t *testing.T) {
t.Skip("runtime.ReadMemStats, testing.AllocsPerRun not supported in GopherJS")
}

func TestCompareStrings(t *testing.T) {
t.Skip("unsafeString not supported in GopherJS")
}
34 changes: 34 additions & 0 deletions compiler/natives/src/syscall/syscall_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// +build js

package syscall

import (
"github.com/gopherjs/gopherjs/js"
)

func funcPC(f func()) uintptr {
if js.InternalObject(f) == js.InternalObject(libc_write_trampoline) {
return SYS_WRITE
}
return uintptr(minusOne)
}

func syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
return Syscall(trap, a1, a2, a3)
}

func syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
return Syscall6(trap, a1, a2, a3, a4, a5, a6)
}

func syscall6X(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
panic("syscall6X is not implemented")
}

func rawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
return RawSyscall(trap, a1, a2, a3)
}

func rawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
return RawSyscall6(trap, a1, a2, a3, a4, a5, a6)
}
Loading