]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: initialize sparse slice literals dynamically
authorKeith Randall <khr@google.com>
Mon, 26 Nov 2018 22:33:32 +0000 (14:33 -0800)
committerKeith Randall <khr@golang.org>
Mon, 26 Nov 2018 22:50:48 +0000 (22:50 +0000)
commit6fff980cf1f9af9f4b11e7fc7ead4987cc5fc560
treef1cfe6e6af658a8dc55bd42240b6c4f68b452dce
parent1602e497012a27071e200d54ebfe13ca23d1f8af
cmd/compile: initialize sparse slice literals dynamically

When a slice composite literal is sparse, initialize it dynamically
instead of statically.

s := []int{5:5, 20:20}

To initialize the backing store for s, use 2 constant writes instead
of copying from a static array with 21 entries.

This CL also fixes pathologies in the compiler when the slice is
*very* sparse.

Fixes #23780

Change-Id: Iae95c6e6f6a0e2994675cbc750d7a4dd6436b13b
Reviewed-on: https://go-review.googlesource.com/c/151319
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/syntax.go
test/fixedbugs/issue23780.go [new file with mode: 0644]