Skip to content

Commit 4e4fa4b

Browse files
authored
Merge pull request #1048 from nevkontakte/wip-go1.17
Support go1.17 slice to array pointer conversion.
2 parents 4c9dc65 + 1a3e1be commit 4e4fa4b

File tree

10 files changed

+421
-232
lines changed

10 files changed

+421
-232
lines changed

circle.yml

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# CircleCI configuration for GopherJS.
2-
#
2+
#
33
# This configuration has one build_and_test workflow designed to run on all commits
44
# and pull requests. It consists of three jobs:
5-
#
5+
#
66
# - build: Builds and runs GopherJS unit tests, as well as lits, smoke tests, etc.
77
# This job is designed to provide quickest feedback on the most important
88
# functionality. It should not include anything heavyweight and should be kept
99
# under 2-3 minutes of runtime.
10-
#
10+
#
1111
# - gopherjs_tests: Runs standard library and GopherJS package tests using GopherJS
1212
# *itself*. This is the most comprehensive test suite we have and it is sharded
1313
# into 4 parallel instances for faster execution.
14-
#
14+
#
1515
# - gorepo_tests: Runs language tests from the Go compiler test suite. The objective
1616
# of these tests is to ensure conformance of GopherJS to the upstream Go to the
1717
# highest degree possible, considering differences in the runtime.
18-
#
18+
#
1919
# If all tests passed, it is reasonably to assume that the version is more or less
2020
# bug-free (although as of summer 2021 our test coverage is not ideal).
21-
#
21+
#
2222
# For convenience of upgrades, NVM, Node.js and Go versions are specified as
2323
# parameters at the top of the config. Increasing the version and ensuring that the
2424
# workflow passes is sufficient to verify GopherJS compatibility with that version.
25-
#
25+
#
2626
# Versions of Node modules GopherJS depends on are specified in package.json and can
2727
# be changed there (remember to run `npm install` to update the lock file).
2828

@@ -39,10 +39,10 @@ workflows:
3939
jobs:
4040
- build
4141
- gopherjs_tests:
42-
requires:
42+
requires:
4343
- build
4444
- gorepo_tests:
45-
requires:
45+
requires:
4646
- build
4747

4848
parameters:
@@ -70,14 +70,14 @@ jobs:
7070
- run:
7171
name: Check gofmt
7272
command: diff -u <(echo -n) <(gofmt -d .)
73-
- run:
73+
- run:
7474
name: Check go vet
7575
command: |
76-
set -e
76+
set -e
7777
# Go package in root directory.
78-
go vet .
78+
go vet .
7979
# All subdirectories except "doc", "tests", "node*".
80-
for d in */; do echo ./$d...; done | grep -v ./doc | grep -v ./tests | grep -v ./node | xargs go vet
80+
for d in */; do echo ./$d...; done | grep -v ./doc | grep -v ./tests | grep -v ./node | xargs go vet
8181
- run:
8282
name: Check natives build tags
8383
command: diff -u <(echo -n) <(go list ./compiler/natives/src/...) # All those packages should have // +build js.
@@ -126,7 +126,7 @@ jobs:
126126
- run:
127127
name: Compare GOPATH and Go Modules output
128128
command: diff -u <(sed 's/todomvc_gomod.js.map/todomvc_ignored.js.map/' /tmp/todomvc_gomod.js) <(sed 's/todomvc_gopath.js.map/todomvc_ignored.js.map/' /tmp/todomvc_gopath.js)
129-
129+
130130
gopherjs_tests:
131131
executor: gopherjs
132132
parallelism: 4
@@ -148,8 +148,9 @@ jobs:
148148
set -e
149149
# Convert test output into junit format for CircleCI.
150150
mkdir -p ~/test-reports/
151-
go-junit-report --full-class-name < /tmp/test-gopherjs.txt > ~/test-reports/gopherjs.xml
151+
go-junit-report --full-class-name < /tmp/test-gopherjs.txt > ~/test-reports/gopherjs-${CIRCLE_NODE_INDEX}.xml
152152
exit "$status"
153+
no_output_timeout: "1h" # Packages like math/big take a while to run all tests.
153154
- store_test_results:
154155
path: ~/test-reports/
155156

@@ -203,7 +204,7 @@ commands:
203204
echo 'export SOURCE_MAP_SUPPORT=true' >> $BASH_ENV
204205
# Make nodejs able to require installed modules from any working path.
205206
echo export "NODE_PATH='$(npm root)'" >> "${BASH_ENV}"
206-
- run:
207+
- run:
207208
name: Install required Go packages
208209
command: go mod download -x
209210
install_gopherjs:

compiler/expressions.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,6 @@ func (fc *funcContext) translateExpr(expr ast.Expr) *expression {
426426
return fc.formatExpr("$equal(%e, %e, %s)", e.X, e.Y, fc.typeName(t))
427427
case *types.Interface:
428428
return fc.formatExpr("$interfaceIsEqual(%s, %s)", fc.translateImplicitConversion(e.X, t), fc.translateImplicitConversion(e.Y, t))
429-
case *types.Pointer:
430-
if _, ok := u.Elem().Underlying().(*types.Array); ok {
431-
return fc.formatExpr("$equal(%s, %s, %s)", fc.translateImplicitConversion(e.X, t), fc.translateImplicitConversion(e.Y, t), fc.typeName(u.Elem()))
432-
}
433429
case *types.Basic:
434430
if isBoolean(u) {
435431
if b, ok := analysis.BoolValue(e.X, fc.pkgCtx.Info.Info); ok && b {
@@ -1031,7 +1027,7 @@ func (fc *funcContext) translateConversion(expr ast.Expr, desiredType types.Type
10311027
case t.Kind() == types.UnsafePointer:
10321028
if unary, isUnary := expr.(*ast.UnaryExpr); isUnary && unary.Op == token.AND {
10331029
if indexExpr, isIndexExpr := unary.X.(*ast.IndexExpr); isIndexExpr {
1034-
return fc.formatExpr("$sliceToArray(%s)", fc.translateConversionToSlice(indexExpr.X, types.NewSlice(types.Typ[types.Uint8])))
1030+
return fc.formatExpr("$sliceToNativeArray(%s)", fc.translateConversionToSlice(indexExpr.X, types.NewSlice(types.Typ[types.Uint8])))
10351031
}
10361032
if ident, isIdent := unary.X.(*ast.Ident); isIdent && ident.Name == "_zero" {
10371033
return fc.formatExpr("new Uint8Array(0)")
@@ -1075,8 +1071,14 @@ func (fc *funcContext) translateConversion(expr ast.Expr, desiredType types.Type
10751071
break
10761072
}
10771073

1078-
switch u := t.Elem().Underlying().(type) {
1074+
switch ptrElType := t.Elem().Underlying().(type) {
10791075
case *types.Array: // (*[N]T)(expr) — converting expr to a pointer to an array.
1076+
if _, ok := exprType.Underlying().(*types.Slice); ok {
1077+
// GopherJS interprets pointer to an array as the array object itself
1078+
// due to its reference semantics, so the bellow coversion is correct.
1079+
return fc.formatExpr("$sliceToGoArray(%e, %s)", expr, fc.typeName(t))
1080+
}
1081+
// TODO(nevkontakte): Is this just for aliased types (e.g. `type a [4]byte`)?
10801082
return fc.translateExpr(expr)
10811083
case *types.Struct: // (*StructT)(expr) — converting expr to a pointer to a struct.
10821084
if fc.pkgCtx.Pkg.Path() == "syscall" && types.Identical(exprType, types.Typ[types.UnsafePointer]) {
@@ -1086,7 +1088,7 @@ func (fc *funcContext) translateConversion(expr ast.Expr, desiredType types.Type
10861088
// indeed pointing at a byte array.
10871089
array := fc.newVariable("_array")
10881090
target := fc.newVariable("_struct")
1089-
return fc.formatExpr("(%s = %e, %s = %e, %s, %s)", array, expr, target, fc.zeroValue(t.Elem()), fc.loadStruct(array, target, u), target)
1091+
return fc.formatExpr("(%s = %e, %s = %e, %s, %s)", array, expr, target, fc.zeroValue(t.Elem()), fc.loadStruct(array, target, ptrElType), target)
10901092
}
10911093
// Convert between structs of different types but identical layouts,
10921094
// for example:
@@ -1152,7 +1154,7 @@ func (fc *funcContext) translateImplicitConversion(expr ast.Expr, desiredType ty
11521154

11531155
switch desiredType.Underlying().(type) {
11541156
case *types.Slice:
1155-
return fc.formatExpr("$subslice(new %1s(%2e.$array), %2e.$offset, %2e.$offset + %2e.$length)", fc.typeName(desiredType), expr)
1157+
return fc.formatExpr("$convertSliceType(%1e, %2s)", expr, fc.typeName(desiredType))
11561158

11571159
case *types.Interface:
11581160
if typesutil.IsJsObject(exprType) {

0 commit comments

Comments
 (0)