Skip to content

Go 1.8 support (version bump to GopherJS 1.8-1). #552

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 20 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0ff5023
Target Go 1.8 final, update version to GopherJS 1.8-1.
dmitshur Dec 4, 2016
bc37a63
Update test main template to match current version in Go 1.8.
dmitshur Dec 13, 2016
01f15b4
build: Remove custom file overrides for hash/crc32 package.
dmitshur Dec 13, 2016
ead0eba
tests: Remove directory no longer in Go repository.
dmitshur Dec 13, 2016
65cbe62
tests: Skip all actions except ones we explicitly support.
dmitshur Dec 13, 2016
4a9226b
tests: Triage new Go repository tests added/modified in Go 1.8.
dmitshur Dec 13, 2016
e6dec35
compiler/natives/src/{runtime,sync}: Add stub for SetMutexProfileFrac…
dmitshur Dec 13, 2016
e3c80b5
compiler/natives/src/internal/testenv: Override HasExec to say no for…
dmitshur Dec 14, 2016
b10af79
compiler/natives/src/math: Implement {Cos,Sin,Tan}h.
dmitshur Dec 13, 2016
5e896be
compiler/natives/src/math: Slightly increase tolerances in tests to f…
dmitshur Dec 13, 2016
3303ee8
compiler/natives/src/io: Skip test that relies on unimplemented runti…
dmitshur Dec 14, 2016
40ff6ca
compiler/natives/src/reflect: Implement safe Swapper.
dmitshur Dec 14, 2016
a362c44
compiler/natives/src/reflect: Disable failing deepEqualTests testcases.
dmitshur Dec 14, 2016
12846d3
compiler/natives/src/database/sql/driver: Disable failing valueConver…
dmitshur Dec 14, 2016
8980111
tests: Improve description of issue5856 test.
dmitshur Dec 16, 2016
ad3bc12
build: Remove external dependency osext.
dmitshur Jan 5, 2017
0c82c68
compiler/natives/src/runtime/debug: Implement noop SetMaxStack.
dmitshur Jan 19, 2017
b36bf38
build, compiler/natives/src/os: Remove syscalling os.Executable imple…
dmitshur Feb 16, 2017
1d7ed2c
compiler/natives: Regenerate.
dmitshur Dec 13, 2016
16fddcc
tests: Remove fixedbugs/issue8613.go from knownFails.
dmitshur Feb 16, 2017
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
20 changes: 16 additions & 4 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/gopherjs/gopherjs/compiler"
"github.com/gopherjs/gopherjs/compiler/natives"
"github.com/kardianos/osext"
"github.com/neelance/sourcemap"
)

Expand Down Expand Up @@ -85,6 +84,8 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
}

switch path {
case "os":
pkg.GoFiles = stripExecutable(pkg.GoFiles) // Need to strip executable implementation files, because some of them contain package scope variables that perform (indirectly) syscalls on init.
case "runtime":
pkg.GoFiles = []string{"error.go"}
case "runtime/internal/sys":
Expand All @@ -95,8 +96,6 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
pkg.GoFiles = []string{"rand.go", "util.go"}
case "crypto/x509":
pkg.CgoFiles = nil
case "hash/crc32":
pkg.GoFiles = []string{"crc32.go", "crc32_generic.go"}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yey.


if len(pkg.CgoFiles) > 0 {
Expand Down Expand Up @@ -124,6 +123,19 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
}

// stripExecutable strips all executable implementation .go files.
// They have "executable_" prefix.
func stripExecutable(goFiles []string) []string {
var s []string
for _, f := range goFiles {
if strings.HasPrefix(f, "executable_") {
continue
}
s = append(s, f)
}
return s
}

// ImportDir is like Import but processes the Go package found in the named
// directory.
func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
Expand Down Expand Up @@ -490,7 +502,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {

if pkg.PkgObj != "" {
var fileInfo os.FileInfo
gopherjsBinary, err := osext.Executable()
gopherjsBinary, err := os.Executable()
if err == nil {
fileInfo, err = os.Stat(gopherjsBinary)
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ machine:

dependencies:
pre:
- cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath
- cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath
post:
- mv ./gopherjs $HOME/bin
- npm install --global node-gyp
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_7___ // compile error on earlier Go versions
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_8___ // 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
287 changes: 178 additions & 109 deletions compiler/natives/fs_vfsdata.go

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions compiler/natives/src/database/sql/driver/driver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// +build js

package driver

var valueConverterTests = []valueConverterTest{
{Bool, "true", true, ""},
{Bool, "True", true, ""},
{Bool, []byte("t"), true, ""},
{Bool, true, true, ""},
{Bool, "1", true, ""},
{Bool, 1, true, ""},
{Bool, int64(1), true, ""},
{Bool, uint16(1), true, ""},
{Bool, "false", false, ""},
{Bool, false, false, ""},
{Bool, "0", false, ""},
{Bool, 0, false, ""},
{Bool, int64(0), false, ""},
{Bool, uint16(0), false, ""},
{c: Bool, in: "foo", err: "sql/driver: couldn't convert \"foo\" into type bool"},
{c: Bool, in: 2, err: "sql/driver: couldn't convert 2 into type bool"},
{DefaultParameterConverter, now, now, ""},
{DefaultParameterConverter, (*int64)(nil), nil, ""},
{DefaultParameterConverter, &answer, answer, ""},
{DefaultParameterConverter, &now, now, ""},
//{DefaultParameterConverter, i(9), int64(9), ""}, // TODO: Fix.
{DefaultParameterConverter, f(0.1), float64(0.1), ""},
{DefaultParameterConverter, b(true), true, ""},
//{DefaultParameterConverter, bs{1}, []byte{1}, ""}, // TODO: Fix.
{DefaultParameterConverter, s("a"), "a", ""},
{DefaultParameterConverter, is{1}, nil, "unsupported type driver.is, a slice of int"},
}
26 changes: 26 additions & 0 deletions compiler/natives/src/internal/testenv/testenv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// +build js

package testenv

import (
"runtime"
"strings"
)

// HasExec reports whether the current system can start new processes
// using os.StartProcess or (more commonly) exec.Command.
func HasExec() bool {
switch runtime.GOOS {
case "nacl":
return false
case "darwin":
if strings.HasPrefix(runtime.GOARCH, "arm") {
return false
}
}
switch runtime.GOARCH {
case "js":
return false
}
return true
}
4 changes: 4 additions & 0 deletions compiler/natives/src/io/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ func TestMultiWriter_WriteStringSingleAlloc(t *testing.T) {
func TestMultiReaderFlatten(t *testing.T) {
t.Skip()
}

func TestMultiReaderFreesExhaustedReaders(t *testing.T) {
t.Skip("test relies on runtime.SetFinalizer, which GopherJS does not implement")
}
12 changes: 12 additions & 0 deletions compiler/natives/src/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func Cos(x float64) float64 {
return math.Call("cos", x).Float()
}

func Cosh(x float64) float64 {
return math.Call("cosh", x).Float()
}

func Dim(x, y float64) float64 {
return dim(x, y)
}
Expand Down Expand Up @@ -172,6 +176,10 @@ func Sin(x float64) float64 {
return math.Call("sin", x).Float()
}

func Sinh(x float64) float64 {
return math.Call("sinh", x).Float()
}

func Sincos(x float64) (sin, cos float64) {
return Sin(x), Cos(x)
}
Expand All @@ -184,6 +192,10 @@ func Tan(x float64) float64 {
return math.Call("tan", x).Float()
}

func Tanh(x float64) float64 {
return math.Call("tanh", x).Float()
}

func Trunc(x float64) float64 {
if x == posInf || x == negInf || x != x || 1/x == negInf {
return x
Expand Down
12 changes: 12 additions & 0 deletions compiler/natives/src/math/math_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build js

package math_test

// 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
// should override TestGamma specifically and not the package-wide tolerances,
// because this will cause many other tests to be less accurate. Or maybe this
// is fine?
func close(a, b float64) bool { return tolerance(a, b, 4e-14) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still wondering where exactly we're losing precision. I guess it is because we're using some JS native math functions which are implemented slightly differently than the Go ones. Investigate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea what's going on here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made #589 to track this.

func veryclose(a, b float64) bool { return tolerance(a, b, 6e-15) }
6 changes: 6 additions & 0 deletions compiler/natives/src/os/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package os

import (
"errors"

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

Expand All @@ -24,3 +26,7 @@ func init() {
}

func runtime_beforeExit() {}

func executable() (string, error) {
return "", errors.New("Executable not implemented for GOARCH=js")
}
67 changes: 67 additions & 0 deletions compiler/natives/src/reflect/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package reflect_test

import (
"math"
"reflect"
"testing"
)
Expand Down Expand Up @@ -85,3 +86,69 @@ func TestStructOfDirectIface(t *testing.T) {
func TestStructOfWithInterface(t *testing.T) {
t.Skip("StructOf")
}

var deepEqualTests = []DeepEqualTest{
// Equalities
{nil, nil, true},
{1, 1, true},
{int32(1), int32(1), true},
{0.5, 0.5, true},
{float32(0.5), float32(0.5), true},
{"hello", "hello", true},
{make([]int, 10), make([]int, 10), true},
{&[3]int{1, 2, 3}, &[3]int{1, 2, 3}, true},
{Basic{1, 0.5}, Basic{1, 0.5}, true},
{error(nil), error(nil), true},
{map[int]string{1: "one", 2: "two"}, map[int]string{2: "two", 1: "one"}, true},
{fn1, fn2, true},

// Inequalities
{1, 2, false},
{int32(1), int32(2), false},
{0.5, 0.6, false},
{float32(0.5), float32(0.6), false},
{"hello", "hey", false},
{make([]int, 10), make([]int, 11), false},
{&[3]int{1, 2, 3}, &[3]int{1, 2, 4}, false},
{Basic{1, 0.5}, Basic{1, 0.6}, false},
{Basic{1, 0}, Basic{2, 0}, false},
{map[int]string{1: "one", 3: "two"}, map[int]string{2: "two", 1: "one"}, false},
{map[int]string{1: "one", 2: "txo"}, map[int]string{2: "two", 1: "one"}, false},
{map[int]string{1: "one"}, map[int]string{2: "two", 1: "one"}, false},
{map[int]string{2: "two", 1: "one"}, map[int]string{1: "one"}, false},
{nil, 1, false},
{1, nil, false},
{fn1, fn3, false},
{fn3, fn3, false},
{[][]int{{1}}, [][]int{{2}}, false},
{math.NaN(), math.NaN(), false},
{&[1]float64{math.NaN()}, &[1]float64{math.NaN()}, false},
{&[1]float64{math.NaN()}, self{}, true},
{[]float64{math.NaN()}, []float64{math.NaN()}, false},
{[]float64{math.NaN()}, self{}, true},
{map[float64]float64{math.NaN(): 1}, map[float64]float64{1: 2}, false},
{map[float64]float64{math.NaN(): 1}, self{}, true},

// Nil vs empty: not the same.
{[]int{}, []int(nil), false},
{[]int{}, []int{}, true},
{[]int(nil), []int(nil), true},
{map[int]int{}, map[int]int(nil), false},
{map[int]int{}, map[int]int{}, true},
{map[int]int(nil), map[int]int(nil), true},

// Mismatched types
{1, 1.0, false},
{int32(1), int64(1), false},
{0.5, "hello", false},
{[]int{1, 2, 3}, [3]int{1, 2, 3}, false},
{&[3]interface{}{1, 2, 4}, &[3]interface{}{1, 2, "s"}, false},
{Basic{1, 0.5}, NotBasic{1, 0.5}, false},
{map[uint]string{1: "one", 2: "two"}, map[int]string{2: "two", 1: "one"}, false},

// Possible loops.
{&loop1, &loop1, true},
//{&loop1, &loop2, true}, // TODO: Fix.
{&loopy1, &loopy1, true},
//{&loopy1, &loopy2, true}, // TODO: Fix.
}
29 changes: 29 additions & 0 deletions compiler/natives/src/reflect/swapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// +build js

package reflect

func Swapper(slice interface{}) func(i, j int) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reflect.Swapper, interesting addition. I guess this is because of sort?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is to enable the new way of sorting in 1.8.

https://beta.golang.org/pkg/sort/#example_Slice

v := ValueOf(slice)
if v.Kind() != Slice {
panic(&ValueError{Method: "Swapper", Kind: v.Kind()})
}
// Fast path for slices of size 0 and 1. Nothing to swap.
switch v.Len() {
case 0:
return func(i, j int) { panic("reflect: slice index out of range") }
case 1:
return func(i, j int) {
if i != 0 || j != 0 {
panic("reflect: slice index out of range")
}
}
}
tmp := New(v.Type().Elem()).Elem()
return func(i, j int) {
v1 := v.Index(i)
v2 := v.Index(j)
tmp.Set(v1)
v1.Set(v2)
v2.Set(tmp)
}
}
7 changes: 7 additions & 0 deletions compiler/natives/src/runtime/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
package debug

func setGCPercent(int32) int32 {
// Not implemented. Return initial setting.
return 100
}

func setMaxStack(bytes int) int {
// Not implemented. Return initial setting.
// The initial setting is 1 GB on 64-bit systems, 250 MB on 32-bit systems.
return 250000000
}
5 changes: 5 additions & 0 deletions compiler/natives/src/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ var MemProfileRate int = 512 * 1024
func SetBlockProfileRate(rate int) {
}

func SetMutexProfileFraction(rate int) int {
// TODO: Investigate this. If it's possible to implement, consider doing so, otherwise remove this comment.
return 0
}

func Stack(buf []byte, all bool) int {
s := js.Global.Get("Error").New().Get("stack")
if s == js.Undefined {
Expand Down
5 changes: 5 additions & 0 deletions compiler/natives/src/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ func runtime_Semacquire(s *uint32) {
*s--
}

// SemacquireMutex is like Semacquire, but for profiling contended Mutexes.
// Mutex profiling is not supported, so just use the same implementation.
// TODO: Investigate this. If it's possible to implement, consider doing so, otherwise remove this comment.
var runtime_SemacquireMutex = runtime_Semacquire

func runtime_Semrelease(s *uint32) {
*s++

Expand Down
8 changes: 4 additions & 4 deletions compiler/version_check.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// +build !go1.8
// +build go1.7
// +build !go1.9
// +build go1.8

package compiler

const ___GOPHERJS_REQUIRES_GO_VERSION_1_7___ = true
const ___GOPHERJS_REQUIRES_GO_VERSION_1_8___ = true

// Version is the GopherJS compiler version string.
const Version = "1.7-1"
const Version = "1.8-1"
2 changes: 1 addition & 1 deletion doc/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ path | ✅ yes |
reflect | ✅ yes | except StructOf (pending)
regexp | ✅ yes |
-- syntax | ✅ yes |
runtime | ☑️ partially |
runtime | ☑️ partially | SetMutexProfileFraction, SetFinalizer unsupported
-- cgo | ❌ no |
-- debug | ❌ no |
-- pprof | ❌ no |
Expand Down
Loading