go/src/cmd/compile/internal/gc/lex.go

2609 lines
50 KiB
Go
Raw Normal View History

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate go tool yacc go.y
//go:generate go run mkbuiltin.go runtime unsafe
package gc
import (
"bytes"
"cmd/internal/obj"
"flag"
"fmt"
"io"
"log"
"os"
"path"
"strconv"
"strings"
"unicode"
"unicode/utf8"
)
var yyprev int
var yylast int
var imported_unsafe bool
var (
goos string
goarch string
goroot string
buildid string
)
cmd/internal/gc: optimize append + write barrier The code generated for x = append(x, v) is roughly: t := x if len(t)+1 > cap(t) { t = grow(t) } t[len(t)] = v len(t)++ x = t We used to generate this code as Go pseudocode during walk. Generate it instead as actual instructions during gen. Doing so lets us apply a few optimizations. The most important is that when, as in the above example, the source slice and the destination slice are the same, the code can instead do: t := x if len(t)+1 > cap(t) { t = grow(t) x = {base(t), len(t)+1, cap(t)} } else { len(x)++ } t[len(t)] = v That is, in the fast path that does not reallocate the array, only the updated length needs to be written back to x, not the array pointer and not the capacity. This is more like what you'd write by hand in C. It's faster in general, since the fast path elides two of the three stores, but it's especially faster when the form of x is such that the base pointer write would turn into a write barrier. No write, no barrier. name old mean new mean delta BinaryTree17 5.68s × (0.97,1.04) 5.81s × (0.98,1.03) +2.35% (p=0.023) Fannkuch11 4.41s × (0.98,1.03) 4.35s × (1.00,1.00) ~ (p=0.090) FmtFprintfEmpty 92.7ns × (0.91,1.16) 86.0ns × (0.94,1.11) -7.31% (p=0.038) FmtFprintfString 281ns × (0.96,1.08) 276ns × (0.98,1.04) ~ (p=0.219) FmtFprintfInt 288ns × (0.97,1.06) 274ns × (0.98,1.06) -4.94% (p=0.002) FmtFprintfIntInt 493ns × (0.97,1.04) 506ns × (0.99,1.01) +2.65% (p=0.009) FmtFprintfPrefixedInt 423ns × (0.97,1.04) 391ns × (0.99,1.01) -7.52% (p=0.000) FmtFprintfFloat 598ns × (0.99,1.01) 566ns × (0.99,1.01) -5.27% (p=0.000) FmtManyArgs 1.89µs × (0.98,1.05) 1.91µs × (0.99,1.01) ~ (p=0.231) GobDecode 14.8ms × (0.98,1.03) 15.3ms × (0.99,1.02) +3.01% (p=0.000) GobEncode 12.3ms × (0.98,1.01) 11.5ms × (0.97,1.03) -5.93% (p=0.000) Gzip 656ms × (0.99,1.05) 645ms × (0.99,1.01) ~ (p=0.055) Gunzip 142ms × (1.00,1.00) 142ms × (1.00,1.00) -0.32% (p=0.034) HTTPClientServer 91.2µs × (0.97,1.04) 90.5µs × (0.97,1.04) ~ (p=0.468) JSONEncode 32.6ms × (0.97,1.08) 32.0ms × (0.98,1.03) ~ (p=0.190) JSONDecode 114ms × (0.97,1.05) 114ms × (0.99,1.01) ~ (p=0.887) Mandelbrot200 6.11ms × (0.98,1.04) 6.04ms × (1.00,1.01) ~ (p=0.167) GoParse 6.66ms × (0.97,1.04) 6.47ms × (0.97,1.05) -2.81% (p=0.014) RegexpMatchEasy0_32 159ns × (0.99,1.00) 171ns × (0.93,1.07) +7.19% (p=0.002) RegexpMatchEasy0_1K 538ns × (1.00,1.01) 550ns × (0.98,1.01) +2.30% (p=0.000) RegexpMatchEasy1_32 138ns × (1.00,1.00) 135ns × (0.99,1.02) -1.60% (p=0.000) RegexpMatchEasy1_1K 869ns × (0.99,1.01) 879ns × (1.00,1.01) +1.08% (p=0.000) RegexpMatchMedium_32 252ns × (0.99,1.01) 243ns × (1.00,1.00) -3.71% (p=0.000) RegexpMatchMedium_1K 72.7µs × (1.00,1.00) 70.3µs × (1.00,1.00) -3.34% (p=0.000) RegexpMatchHard_32 3.85µs × (1.00,1.00) 3.82µs × (1.00,1.01) -0.81% (p=0.000) RegexpMatchHard_1K 118µs × (1.00,1.00) 117µs × (1.00,1.00) -0.56% (p=0.000) Revcomp 920ms × (0.97,1.07) 917ms × (0.97,1.04) ~ (p=0.808) Template 129ms × (0.98,1.03) 114ms × (0.99,1.01) -12.06% (p=0.000) TimeParse 619ns × (0.99,1.01) 622ns × (0.99,1.01) ~ (p=0.062) TimeFormat 661ns × (0.98,1.04) 665ns × (0.99,1.01) ~ (p=0.524) See next CL for combination with a similar optimization for slice. The benchmarks that are slower in this CL are still faster overall with the combination of the two. Change-Id: I2a7421658091b2488c64741b4db15ab6c3b4cb7e Reviewed-on: https://go-review.googlesource.com/9812 Reviewed-by: David Chase <drchase@google.com>
2015-05-06 12:34:30 -04:00
var (
Debug_append int
Debug_panic int
cmd/internal/gc: optimize slice + write barrier The code generated for a slice x[i:j] or x[i:j:k] computes the entire new slice (base, len, cap) and then uses it as the evaluation of the slice expression. If the slice is part of an update x = x[i:j] or x = x[i:j:k], there are opportunities to avoid computing some of these fields. For x = x[0:i], we know that only the len is changing; base can be ignored completely, and cap can be left unmodified. For x = x[0:i:j], we know that only len and cap are changing; base can be ignored completely. For x = x[i:i], we know that the resulting cap is zero, and we don't adjust the base during a slice producing a zero-cap result, so again base can be ignored completely. No write to base, no write barrier. The old slice code was trying to work at a Go syntax level, mainly because that was how you wrote code just once instead of once per architecture. Now the compiler is factored a bit better and we can implement slice during code generation but still have one copy of the code. So the new code is working at that lower level. (It must, to update only parts of the result.) This CL by itself: name old mean new mean delta BinaryTree17 5.81s × (0.98,1.03) 5.71s × (0.96,1.05) ~ (p=0.101) Fannkuch11 4.35s × (1.00,1.00) 4.39s × (1.00,1.00) +0.79% (p=0.000) FmtFprintfEmpty 86.0ns × (0.94,1.11) 82.6ns × (0.98,1.04) -3.86% (p=0.048) FmtFprintfString 276ns × (0.98,1.04) 273ns × (0.98,1.02) ~ (p=0.235) FmtFprintfInt 274ns × (0.98,1.06) 270ns × (0.99,1.01) ~ (p=0.119) FmtFprintfIntInt 506ns × (0.99,1.01) 475ns × (0.99,1.01) -6.02% (p=0.000) FmtFprintfPrefixedInt 391ns × (0.99,1.01) 393ns × (1.00,1.01) ~ (p=0.139) FmtFprintfFloat 566ns × (0.99,1.01) 574ns × (1.00,1.01) +1.33% (p=0.001) FmtManyArgs 1.91µs × (0.99,1.01) 1.87µs × (0.99,1.02) -1.83% (p=0.000) GobDecode 15.3ms × (0.99,1.02) 15.0ms × (0.98,1.05) -1.84% (p=0.042) GobEncode 11.5ms × (0.97,1.03) 11.4ms × (0.99,1.03) ~ (p=0.152) Gzip 645ms × (0.99,1.01) 647ms × (0.99,1.01) ~ (p=0.265) Gunzip 142ms × (1.00,1.00) 143ms × (1.00,1.01) +0.90% (p=0.000) HTTPClientServer 90.5µs × (0.97,1.04) 88.5µs × (0.99,1.03) -2.27% (p=0.014) JSONEncode 32.0ms × (0.98,1.03) 29.6ms × (0.98,1.01) -7.51% (p=0.000) JSONDecode 114ms × (0.99,1.01) 104ms × (1.00,1.01) -8.60% (p=0.000) Mandelbrot200 6.04ms × (1.00,1.01) 6.02ms × (1.00,1.00) ~ (p=0.057) GoParse 6.47ms × (0.97,1.05) 6.37ms × (0.97,1.04) ~ (p=0.105) RegexpMatchEasy0_32 171ns × (0.93,1.07) 152ns × (0.99,1.01) -11.09% (p=0.000) RegexpMatchEasy0_1K 550ns × (0.98,1.01) 530ns × (1.00,1.00) -3.78% (p=0.000) RegexpMatchEasy1_32 135ns × (0.99,1.02) 134ns × (0.99,1.01) -1.33% (p=0.002) RegexpMatchEasy1_1K 879ns × (1.00,1.01) 865ns × (1.00,1.00) -1.58% (p=0.000) RegexpMatchMedium_32 243ns × (1.00,1.00) 233ns × (1.00,1.00) -4.30% (p=0.000) RegexpMatchMedium_1K 70.3µs × (1.00,1.00) 69.5µs × (1.00,1.00) -1.13% (p=0.000) RegexpMatchHard_32 3.82µs × (1.00,1.01) 3.74µs × (1.00,1.00) -1.95% (p=0.000) RegexpMatchHard_1K 117µs × (1.00,1.00) 115µs × (1.00,1.00) -1.69% (p=0.000) Revcomp 917ms × (0.97,1.04) 920ms × (0.97,1.04) ~ (p=0.786) Template 114ms × (0.99,1.01) 117ms × (0.99,1.01) +2.58% (p=0.000) TimeParse 622ns × (0.99,1.01) 615ns × (0.99,1.00) -1.06% (p=0.000) TimeFormat 665ns × (0.99,1.01) 654ns × (0.99,1.00) -1.70% (p=0.000) This CL and previous CL (append) combined: name old mean new mean delta BinaryTree17 5.68s × (0.97,1.04) 5.71s × (0.96,1.05) ~ (p=0.638) Fannkuch11 4.41s × (0.98,1.03) 4.39s × (1.00,1.00) ~ (p=0.474) FmtFprintfEmpty 92.7ns × (0.91,1.16) 82.6ns × (0.98,1.04) -10.89% (p=0.004) FmtFprintfString 281ns × (0.96,1.08) 273ns × (0.98,1.02) ~ (p=0.078) FmtFprintfInt 288ns × (0.97,1.06) 270ns × (0.99,1.01) -6.37% (p=0.000) FmtFprintfIntInt 493ns × (0.97,1.04) 475ns × (0.99,1.01) -3.53% (p=0.002) FmtFprintfPrefixedInt 423ns × (0.97,1.04) 393ns × (1.00,1.01) -7.07% (p=0.000) FmtFprintfFloat 598ns × (0.99,1.01) 574ns × (1.00,1.01) -4.02% (p=0.000) FmtManyArgs 1.89µs × (0.98,1.05) 1.87µs × (0.99,1.02) ~ (p=0.305) GobDecode 14.8ms × (0.98,1.03) 15.0ms × (0.98,1.05) ~ (p=0.237) GobEncode 12.3ms × (0.98,1.01) 11.4ms × (0.99,1.03) -6.95% (p=0.000) Gzip 656ms × (0.99,1.05) 647ms × (0.99,1.01) ~ (p=0.101) Gunzip 142ms × (1.00,1.00) 143ms × (1.00,1.01) +0.58% (p=0.001) HTTPClientServer 91.2µs × (0.97,1.04) 88.5µs × (0.99,1.03) -3.02% (p=0.003) JSONEncode 32.6ms × (0.97,1.08) 29.6ms × (0.98,1.01) -9.10% (p=0.000) JSONDecode 114ms × (0.97,1.05) 104ms × (1.00,1.01) -8.74% (p=0.000) Mandelbrot200 6.11ms × (0.98,1.04) 6.02ms × (1.00,1.00) ~ (p=0.090) GoParse 6.66ms × (0.97,1.04) 6.37ms × (0.97,1.04) -4.41% (p=0.000) RegexpMatchEasy0_32 159ns × (0.99,1.00) 152ns × (0.99,1.01) -4.69% (p=0.000) RegexpMatchEasy0_1K 538ns × (1.00,1.01) 530ns × (1.00,1.00) -1.57% (p=0.000) RegexpMatchEasy1_32 138ns × (1.00,1.00) 134ns × (0.99,1.01) -2.91% (p=0.000) RegexpMatchEasy1_1K 869ns × (0.99,1.01) 865ns × (1.00,1.00) -0.51% (p=0.012) RegexpMatchMedium_32 252ns × (0.99,1.01) 233ns × (1.00,1.00) -7.85% (p=0.000) RegexpMatchMedium_1K 72.7µs × (1.00,1.00) 69.5µs × (1.00,1.00) -4.43% (p=0.000) RegexpMatchHard_32 3.85µs × (1.00,1.00) 3.74µs × (1.00,1.00) -2.74% (p=0.000) RegexpMatchHard_1K 118µs × (1.00,1.00) 115µs × (1.00,1.00) -2.24% (p=0.000) Revcomp 920ms × (0.97,1.07) 920ms × (0.97,1.04) ~ (p=0.998) Template 129ms × (0.98,1.03) 117ms × (0.99,1.01) -9.79% (p=0.000) TimeParse 619ns × (0.99,1.01) 615ns × (0.99,1.00) -0.57% (p=0.011) TimeFormat 661ns × (0.98,1.04) 654ns × (0.99,1.00) ~ (p=0.223) Change-Id: If054d81ab2c71d8d62cf54b5b1fac2af66b387fc Reviewed-on: https://go-review.googlesource.com/9813 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-05-06 12:35:53 -04:00
Debug_slice int
Debug_wb int
cmd/internal/gc: optimize append + write barrier The code generated for x = append(x, v) is roughly: t := x if len(t)+1 > cap(t) { t = grow(t) } t[len(t)] = v len(t)++ x = t We used to generate this code as Go pseudocode during walk. Generate it instead as actual instructions during gen. Doing so lets us apply a few optimizations. The most important is that when, as in the above example, the source slice and the destination slice are the same, the code can instead do: t := x if len(t)+1 > cap(t) { t = grow(t) x = {base(t), len(t)+1, cap(t)} } else { len(x)++ } t[len(t)] = v That is, in the fast path that does not reallocate the array, only the updated length needs to be written back to x, not the array pointer and not the capacity. This is more like what you'd write by hand in C. It's faster in general, since the fast path elides two of the three stores, but it's especially faster when the form of x is such that the base pointer write would turn into a write barrier. No write, no barrier. name old mean new mean delta BinaryTree17 5.68s × (0.97,1.04) 5.81s × (0.98,1.03) +2.35% (p=0.023) Fannkuch11 4.41s × (0.98,1.03) 4.35s × (1.00,1.00) ~ (p=0.090) FmtFprintfEmpty 92.7ns × (0.91,1.16) 86.0ns × (0.94,1.11) -7.31% (p=0.038) FmtFprintfString 281ns × (0.96,1.08) 276ns × (0.98,1.04) ~ (p=0.219) FmtFprintfInt 288ns × (0.97,1.06) 274ns × (0.98,1.06) -4.94% (p=0.002) FmtFprintfIntInt 493ns × (0.97,1.04) 506ns × (0.99,1.01) +2.65% (p=0.009) FmtFprintfPrefixedInt 423ns × (0.97,1.04) 391ns × (0.99,1.01) -7.52% (p=0.000) FmtFprintfFloat 598ns × (0.99,1.01) 566ns × (0.99,1.01) -5.27% (p=0.000) FmtManyArgs 1.89µs × (0.98,1.05) 1.91µs × (0.99,1.01) ~ (p=0.231) GobDecode 14.8ms × (0.98,1.03) 15.3ms × (0.99,1.02) +3.01% (p=0.000) GobEncode 12.3ms × (0.98,1.01) 11.5ms × (0.97,1.03) -5.93% (p=0.000) Gzip 656ms × (0.99,1.05) 645ms × (0.99,1.01) ~ (p=0.055) Gunzip 142ms × (1.00,1.00) 142ms × (1.00,1.00) -0.32% (p=0.034) HTTPClientServer 91.2µs × (0.97,1.04) 90.5µs × (0.97,1.04) ~ (p=0.468) JSONEncode 32.6ms × (0.97,1.08) 32.0ms × (0.98,1.03) ~ (p=0.190) JSONDecode 114ms × (0.97,1.05) 114ms × (0.99,1.01) ~ (p=0.887) Mandelbrot200 6.11ms × (0.98,1.04) 6.04ms × (1.00,1.01) ~ (p=0.167) GoParse 6.66ms × (0.97,1.04) 6.47ms × (0.97,1.05) -2.81% (p=0.014) RegexpMatchEasy0_32 159ns × (0.99,1.00) 171ns × (0.93,1.07) +7.19% (p=0.002) RegexpMatchEasy0_1K 538ns × (1.00,1.01) 550ns × (0.98,1.01) +2.30% (p=0.000) RegexpMatchEasy1_32 138ns × (1.00,1.00) 135ns × (0.99,1.02) -1.60% (p=0.000) RegexpMatchEasy1_1K 869ns × (0.99,1.01) 879ns × (1.00,1.01) +1.08% (p=0.000) RegexpMatchMedium_32 252ns × (0.99,1.01) 243ns × (1.00,1.00) -3.71% (p=0.000) RegexpMatchMedium_1K 72.7µs × (1.00,1.00) 70.3µs × (1.00,1.00) -3.34% (p=0.000) RegexpMatchHard_32 3.85µs × (1.00,1.00) 3.82µs × (1.00,1.01) -0.81% (p=0.000) RegexpMatchHard_1K 118µs × (1.00,1.00) 117µs × (1.00,1.00) -0.56% (p=0.000) Revcomp 920ms × (0.97,1.07) 917ms × (0.97,1.04) ~ (p=0.808) Template 129ms × (0.98,1.03) 114ms × (0.99,1.01) -12.06% (p=0.000) TimeParse 619ns × (0.99,1.01) 622ns × (0.99,1.01) ~ (p=0.062) TimeFormat 661ns × (0.98,1.04) 665ns × (0.99,1.01) ~ (p=0.524) See next CL for combination with a similar optimization for slice. The benchmarks that are slower in this CL are still faster overall with the combination of the two. Change-Id: I2a7421658091b2488c64741b4db15ab6c3b4cb7e Reviewed-on: https://go-review.googlesource.com/9812 Reviewed-by: David Chase <drchase@google.com>
2015-05-06 12:34:30 -04:00
)
// Debug arguments.
// These can be specified with the -d flag, as in "-d nil"
// to set the debug_checknil variable. In general the list passed
// to -d can be comma-separated.
var debugtab = []struct {
name string
val *int
}{
runtime: replace GC programs with simpler encoding, faster decoder Small types record the location of pointers in their memory layout by using a simple bitmap. In Go 1.4 the bitmap held 4-bit entries, and in Go 1.5 the bitmap holds 1-bit entries, but in both cases using a bitmap for a large type containing arrays does not make sense: if someone refers to the type [1<<28]*byte in a program in such a way that the type information makes it into the binary, it would be a waste of space to write a 128 MB (for 4-bit entries) or even 32 MB (for 1-bit entries) bitmap full of 1s into the binary or even to keep one in memory during the execution of the program. For large types containing arrays, it is much more compact to describe the locations of pointers using a notation that can express repetition than to lay out a bitmap of pointers. Go 1.4 included such a notation, called ``GC programs'' but it was complex, required recursion during decoding, and was generally slow. Dmitriy measured the execution of these programs writing directly to the heap bitmap as being 7x slower than copying from a preunrolled 4-bit mask (and frankly that code was not terribly fast either). For some tests, unrollgcprog1 was seen costing as much as 3x more than the rest of malloc combined. This CL introduces a different form for the GC programs. They use a simple Lempel-Ziv-style encoding of the 1-bit pointer information, in which the only operations are (1) emit the following n bits and (2) repeat the last n bits c more times. This encoding can be generated directly from the Go type information (using repetition only for arrays or large runs of non-pointer data) and it can be decoded very efficiently. In particular the decoding requires little state and no recursion, so that the entire decoding can run without any memory accesses other than the reads of the encoding and the writes of the decoded form to the heap bitmap. For recursive types like arrays of arrays of arrays, the inner instructions are only executed once, not n times, so that large repetitions run at full speed. (In contrast, large repetitions in the old programs repeated the individual bit-level layout of the inner data over and over.) The result is as much as 25x faster decoding compared to the old form. Because the old decoder was so slow, Go 1.4 had three (or so) cases for how to set the heap bitmap bits for an allocation of a given type: (1) If the type had an even number of words up to 32 words, then the 4-bit pointer mask for the type fit in no more than 16 bytes; store the 4-bit pointer mask directly in the binary and copy from it. (1b) If the type had an odd number of words up to 15 words, then the 4-bit pointer mask for the type, doubled to end on a byte boundary, fit in no more than 16 bytes; store that doubled mask directly in the binary and copy from it. (2) If the type had an even number of words up to 128 words, or an odd number of words up to 63 words (again due to doubling), then the 4-bit pointer mask would fit in a 64-byte unrolled mask. Store a GC program in the binary, but leave space in the BSS for the unrolled mask. Execute the GC program to construct the mask the first time it is needed, and thereafter copy from the mask. (3) Otherwise, store a GC program and execute it to write directly to the heap bitmap each time an object of that type is allocated. (This is the case that was 7x slower than the other two.) Because the new pointer masks store 1-bit entries instead of 4-bit entries and because using the decoder no longer carries a significant overhead, after this CL (that is, for Go 1.5) there are only two cases: (1) If the type is 128 words or less (no condition about odd or even), store the 1-bit pointer mask directly in the binary and use it to initialize the heap bitmap during malloc. (Implemented in CL 9702.) (2) There is no case 2 anymore. (3) Otherwise, store a GC program and execute it to write directly to the heap bitmap each time an object of that type is allocated. Executing the GC program directly into the heap bitmap (case (3) above) was disabled for the Go 1.5 dev cycle, both to avoid needing to use GC programs for typedmemmove and to avoid updating that code as the heap bitmap format changed. Typedmemmove no longer uses this type information; as of CL 9886 it uses the heap bitmap directly. Now that the heap bitmap format is stable, we reintroduce GC programs and their space savings. Benchmarks for heapBitsSetType, before this CL vs this CL: name old mean new mean delta SetTypePtr 7.59ns × (0.99,1.02) 5.16ns × (1.00,1.00) -32.05% (p=0.000) SetTypePtr8 21.0ns × (0.98,1.05) 21.4ns × (1.00,1.00) ~ (p=0.179) SetTypePtr16 24.1ns × (0.99,1.01) 24.6ns × (1.00,1.00) +2.41% (p=0.001) SetTypePtr32 31.2ns × (0.99,1.01) 32.4ns × (0.99,1.02) +3.72% (p=0.001) SetTypePtr64 45.2ns × (1.00,1.00) 47.2ns × (1.00,1.00) +4.42% (p=0.000) SetTypePtr126 75.8ns × (0.99,1.01) 79.1ns × (1.00,1.00) +4.25% (p=0.000) SetTypePtr128 74.3ns × (0.99,1.01) 77.6ns × (1.00,1.01) +4.55% (p=0.000) SetTypePtrSlice 726ns × (1.00,1.01) 712ns × (1.00,1.00) -1.95% (p=0.001) SetTypeNode1 20.0ns × (0.99,1.01) 20.7ns × (1.00,1.00) +3.71% (p=0.000) SetTypeNode1Slice 112ns × (1.00,1.00) 113ns × (0.99,1.00) ~ (p=0.070) SetTypeNode8 23.9ns × (1.00,1.00) 24.7ns × (1.00,1.01) +3.18% (p=0.000) SetTypeNode8Slice 294ns × (0.99,1.02) 287ns × (0.99,1.01) -2.38% (p=0.015) SetTypeNode64 52.8ns × (0.99,1.03) 51.8ns × (0.99,1.01) ~ (p=0.069) SetTypeNode64Slice 1.13µs × (0.99,1.05) 1.14µs × (0.99,1.00) ~ (p=0.767) SetTypeNode64Dead 36.0ns × (1.00,1.01) 32.5ns × (0.99,1.00) -9.67% (p=0.000) SetTypeNode64DeadSlice 1.43µs × (0.99,1.01) 1.40µs × (1.00,1.00) -2.39% (p=0.001) SetTypeNode124 75.7ns × (1.00,1.01) 79.0ns × (1.00,1.00) +4.44% (p=0.000) SetTypeNode124Slice 1.94µs × (1.00,1.01) 2.04µs × (0.99,1.01) +4.98% (p=0.000) SetTypeNode126 75.4ns × (1.00,1.01) 77.7ns × (0.99,1.01) +3.11% (p=0.000) SetTypeNode126Slice 1.95µs × (0.99,1.01) 2.03µs × (1.00,1.00) +3.74% (p=0.000) SetTypeNode128 85.4ns × (0.99,1.01) 122.0ns × (1.00,1.00) +42.89% (p=0.000) SetTypeNode128Slice 2.20µs × (1.00,1.01) 2.36µs × (0.98,1.02) +7.48% (p=0.001) SetTypeNode130 83.3ns × (1.00,1.00) 123.0ns × (1.00,1.00) +47.61% (p=0.000) SetTypeNode130Slice 2.30µs × (0.99,1.01) 2.40µs × (0.98,1.01) +4.37% (p=0.000) SetTypeNode1024 498ns × (1.00,1.00) 537ns × (1.00,1.00) +7.96% (p=0.000) SetTypeNode1024Slice 15.5µs × (0.99,1.01) 17.8µs × (1.00,1.00) +15.27% (p=0.000) The above compares always using a cached pointer mask (and the corresponding waste of memory) against using the programs directly. Some slowdown is expected, in exchange for having a better general algorithm. The GC programs kick in for SetTypeNode128, SetTypeNode130, SetTypeNode1024, along with the slice variants of those. It is possible that the cutoff of 128 words (bits) should be raised in a followup CL, but even with this low cutoff the GC programs are faster than Go 1.4's "fast path" non-GC program case. Benchmarks for heapBitsSetType, Go 1.4 vs this CL: name old mean new mean delta SetTypePtr 6.89ns × (1.00,1.00) 5.17ns × (1.00,1.00) -25.02% (p=0.000) SetTypePtr8 25.8ns × (0.97,1.05) 21.5ns × (1.00,1.00) -16.70% (p=0.000) SetTypePtr16 39.8ns × (0.97,1.02) 24.7ns × (0.99,1.01) -37.81% (p=0.000) SetTypePtr32 68.8ns × (0.98,1.01) 32.2ns × (1.00,1.01) -53.18% (p=0.000) SetTypePtr64 130ns × (1.00,1.00) 47ns × (1.00,1.00) -63.67% (p=0.000) SetTypePtr126 241ns × (0.99,1.01) 79ns × (1.00,1.01) -67.25% (p=0.000) SetTypePtr128 2.07µs × (1.00,1.00) 0.08µs × (1.00,1.00) -96.27% (p=0.000) SetTypePtrSlice 1.05µs × (0.99,1.01) 0.72µs × (0.99,1.02) -31.70% (p=0.000) SetTypeNode1 16.0ns × (0.99,1.01) 20.8ns × (0.99,1.03) +29.91% (p=0.000) SetTypeNode1Slice 184ns × (0.99,1.01) 112ns × (0.99,1.01) -39.26% (p=0.000) SetTypeNode8 29.5ns × (0.97,1.02) 24.6ns × (1.00,1.00) -16.50% (p=0.000) SetTypeNode8Slice 624ns × (0.98,1.02) 285ns × (1.00,1.00) -54.31% (p=0.000) SetTypeNode64 135ns × (0.96,1.08) 52ns × (0.99,1.02) -61.32% (p=0.000) SetTypeNode64Slice 3.83µs × (1.00,1.00) 1.14µs × (0.99,1.01) -70.16% (p=0.000) SetTypeNode64Dead 134ns × (0.99,1.01) 32ns × (1.00,1.01) -75.74% (p=0.000) SetTypeNode64DeadSlice 3.83µs × (0.99,1.00) 1.40µs × (1.00,1.01) -63.42% (p=0.000) SetTypeNode124 240ns × (0.99,1.01) 79ns × (1.00,1.01) -67.05% (p=0.000) SetTypeNode124Slice 7.27µs × (1.00,1.00) 2.04µs × (1.00,1.00) -71.95% (p=0.000) SetTypeNode126 2.06µs × (0.99,1.01) 0.08µs × (0.99,1.01) -96.23% (p=0.000) SetTypeNode126Slice 64.4µs × (1.00,1.00) 2.0µs × (1.00,1.00) -96.85% (p=0.000) SetTypeNode128 2.09µs × (1.00,1.01) 0.12µs × (1.00,1.00) -94.15% (p=0.000) SetTypeNode128Slice 65.4µs × (1.00,1.00) 2.4µs × (0.99,1.03) -96.39% (p=0.000) SetTypeNode130 2.11µs × (1.00,1.00) 0.12µs × (1.00,1.00) -94.18% (p=0.000) SetTypeNode130Slice 66.3µs × (1.00,1.00) 2.4µs × (0.97,1.08) -96.34% (p=0.000) SetTypeNode1024 16.0µs × (1.00,1.01) 0.5µs × (1.00,1.00) -96.65% (p=0.000) SetTypeNode1024Slice 512µs × (1.00,1.00) 18µs × (0.98,1.04) -96.45% (p=0.000) SetTypeNode124 uses a 124 data + 2 ptr = 126-word allocation. Both Go 1.4 and this CL are using pointer bitmaps for this case, so that's an overall 3x speedup for using pointer bitmaps. SetTypeNode128 uses a 128 data + 2 ptr = 130-word allocation. Both Go 1.4 and this CL are running the GC program for this case, so that's an overall 17x speedup when using GC programs (and I've seen >20x on other systems). Comparing Go 1.4's SetTypeNode124 (pointer bitmap) against this CL's SetTypeNode128 (GC program), the slow path in the code in this CL is 2x faster than the fast path in Go 1.4. The Go 1 benchmarks are basically unaffected compared to just before this CL. Go 1 benchmarks, before this CL vs this CL: name old mean new mean delta BinaryTree17 5.87s × (0.97,1.04) 5.91s × (0.96,1.04) ~ (p=0.306) Fannkuch11 4.38s × (1.00,1.00) 4.37s × (1.00,1.01) -0.22% (p=0.006) FmtFprintfEmpty 90.7ns × (0.97,1.10) 89.3ns × (0.96,1.09) ~ (p=0.280) FmtFprintfString 282ns × (0.98,1.04) 287ns × (0.98,1.07) +1.72% (p=0.039) FmtFprintfInt 269ns × (0.99,1.03) 282ns × (0.97,1.04) +4.87% (p=0.000) FmtFprintfIntInt 478ns × (0.99,1.02) 481ns × (0.99,1.02) +0.61% (p=0.048) FmtFprintfPrefixedInt 399ns × (0.98,1.03) 400ns × (0.98,1.05) ~ (p=0.533) FmtFprintfFloat 563ns × (0.99,1.01) 570ns × (1.00,1.01) +1.37% (p=0.000) FmtManyArgs 1.89µs × (0.99,1.01) 1.92µs × (0.99,1.02) +1.88% (p=0.000) GobDecode 15.2ms × (0.99,1.01) 15.2ms × (0.98,1.05) ~ (p=0.609) GobEncode 11.6ms × (0.98,1.03) 11.9ms × (0.98,1.04) +2.17% (p=0.000) Gzip 648ms × (0.99,1.01) 648ms × (1.00,1.01) ~ (p=0.835) Gunzip 142ms × (1.00,1.00) 143ms × (1.00,1.01) ~ (p=0.169) HTTPClientServer 90.5µs × (0.98,1.03) 91.5µs × (0.98,1.04) +1.04% (p=0.045) JSONEncode 31.5ms × (0.98,1.03) 31.4ms × (0.98,1.03) ~ (p=0.549) JSONDecode 111ms × (0.99,1.01) 107ms × (0.99,1.01) -3.21% (p=0.000) Mandelbrot200 6.01ms × (1.00,1.00) 6.01ms × (1.00,1.00) ~ (p=0.878) GoParse 6.54ms × (0.99,1.02) 6.61ms × (0.99,1.03) +1.08% (p=0.004) RegexpMatchEasy0_32 160ns × (1.00,1.01) 161ns × (1.00,1.00) +0.40% (p=0.000) RegexpMatchEasy0_1K 560ns × (0.99,1.01) 559ns × (0.99,1.01) ~ (p=0.088) RegexpMatchEasy1_32 138ns × (0.99,1.01) 138ns × (1.00,1.00) ~ (p=0.380) RegexpMatchEasy1_1K 877ns × (1.00,1.00) 878ns × (1.00,1.00) ~ (p=0.157) RegexpMatchMedium_32 251ns × (0.99,1.00) 251ns × (1.00,1.01) +0.28% (p=0.021) RegexpMatchMedium_1K 72.6µs × (1.00,1.00) 72.6µs × (1.00,1.00) ~ (p=0.539) RegexpMatchHard_32 3.84µs × (1.00,1.00) 3.84µs × (1.00,1.00) ~ (p=0.378) RegexpMatchHard_1K 117µs × (1.00,1.00) 117µs × (1.00,1.00) ~ (p=0.067) Revcomp 904ms × (0.99,1.02) 904ms × (0.99,1.01) ~ (p=0.943) Template 125ms × (0.99,1.02) 127ms × (0.99,1.01) +1.79% (p=0.000) TimeParse 627ns × (0.99,1.01) 622ns × (0.99,1.01) -0.88% (p=0.000) TimeFormat 655ns × (0.99,1.02) 655ns × (0.99,1.02) ~ (p=0.976) For the record, Go 1 benchmarks, Go 1.4 vs this CL: name old mean new mean delta BinaryTree17 4.61s × (0.97,1.05) 5.91s × (0.98,1.03) +28.35% (p=0.000) Fannkuch11 4.40s × (0.99,1.03) 4.41s × (0.99,1.01) ~ (p=0.212) FmtFprintfEmpty 102ns × (0.99,1.01) 84ns × (0.99,1.02) -18.38% (p=0.000) FmtFprintfString 302ns × (0.98,1.01) 303ns × (0.99,1.02) ~ (p=0.203) FmtFprintfInt 313ns × (0.97,1.05) 270ns × (0.99,1.01) -13.69% (p=0.000) FmtFprintfIntInt 524ns × (0.98,1.02) 477ns × (0.99,1.00) -8.87% (p=0.000) FmtFprintfPrefixedInt 424ns × (0.98,1.02) 386ns × (0.99,1.01) -8.96% (p=0.000) FmtFprintfFloat 652ns × (0.98,1.02) 594ns × (0.97,1.05) -8.97% (p=0.000) FmtManyArgs 2.13µs × (0.99,1.02) 1.94µs × (0.99,1.01) -8.92% (p=0.000) GobDecode 17.1ms × (0.99,1.02) 14.9ms × (0.98,1.03) -13.07% (p=0.000) GobEncode 13.5ms × (0.98,1.03) 11.5ms × (0.98,1.03) -15.25% (p=0.000) Gzip 656ms × (0.99,1.02) 647ms × (0.99,1.01) -1.29% (p=0.000) Gunzip 143ms × (0.99,1.02) 144ms × (0.99,1.01) ~ (p=0.204) HTTPClientServer 88.2µs × (0.98,1.02) 90.8µs × (0.98,1.01) +2.93% (p=0.000) JSONEncode 32.2ms × (0.98,1.02) 30.9ms × (0.97,1.04) -4.06% (p=0.001) JSONDecode 121ms × (0.98,1.02) 110ms × (0.98,1.05) -8.95% (p=0.000) Mandelbrot200 6.06ms × (0.99,1.01) 6.11ms × (0.98,1.04) ~ (p=0.184) GoParse 6.76ms × (0.97,1.04) 6.58ms × (0.98,1.05) -2.63% (p=0.003) RegexpMatchEasy0_32 195ns × (1.00,1.01) 155ns × (0.99,1.01) -20.43% (p=0.000) RegexpMatchEasy0_1K 479ns × (0.98,1.03) 535ns × (0.99,1.02) +11.59% (p=0.000) RegexpMatchEasy1_32 169ns × (0.99,1.02) 131ns × (0.99,1.03) -22.44% (p=0.000) RegexpMatchEasy1_1K 1.53µs × (0.99,1.01) 0.87µs × (0.99,1.02) -43.07% (p=0.000) RegexpMatchMedium_32 334ns × (0.99,1.01) 242ns × (0.99,1.01) -27.53% (p=0.000) RegexpMatchMedium_1K 125µs × (1.00,1.01) 72µs × (0.99,1.03) -42.53% (p=0.000) RegexpMatchHard_32 6.03µs × (0.99,1.01) 3.79µs × (0.99,1.01) -37.12% (p=0.000) RegexpMatchHard_1K 189µs × (0.99,1.02) 115µs × (0.99,1.01) -39.20% (p=0.000) Revcomp 935ms × (0.96,1.03) 926ms × (0.98,1.02) ~ (p=0.083) Template 146ms × (0.97,1.05) 119ms × (0.99,1.01) -18.37% (p=0.000) TimeParse 660ns × (0.99,1.01) 624ns × (0.99,1.02) -5.43% (p=0.000) TimeFormat 670ns × (0.98,1.02) 710ns × (1.00,1.01) +5.97% (p=0.000) This CL is a bit larger than I would like, but the compiler, linker, runtime, and package reflect all need to be in sync about the format of these programs, so there is no easy way to split this into independent changes (at least while keeping the build working at each change). Fixes #9625. Fixes #10524. Change-Id: I9e3e20d6097099d0f8532d1cb5b1af528804989a Reviewed-on: https://go-review.googlesource.com/9888 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Russ Cox <rsc@golang.org>
2015-05-08 01:43:18 -04:00
{"append", &Debug_append}, // print information about append compilation
{"disablenil", &Disable_checknil}, // disable nil checks
{"gcprog", &Debug_gcprog}, // print dump of GC programs
{"nil", &Debug_checknil}, // print information about nil checks
{"panic", &Debug_panic}, // do not hide any compiler panic
runtime: replace GC programs with simpler encoding, faster decoder Small types record the location of pointers in their memory layout by using a simple bitmap. In Go 1.4 the bitmap held 4-bit entries, and in Go 1.5 the bitmap holds 1-bit entries, but in both cases using a bitmap for a large type containing arrays does not make sense: if someone refers to the type [1<<28]*byte in a program in such a way that the type information makes it into the binary, it would be a waste of space to write a 128 MB (for 4-bit entries) or even 32 MB (for 1-bit entries) bitmap full of 1s into the binary or even to keep one in memory during the execution of the program. For large types containing arrays, it is much more compact to describe the locations of pointers using a notation that can express repetition than to lay out a bitmap of pointers. Go 1.4 included such a notation, called ``GC programs'' but it was complex, required recursion during decoding, and was generally slow. Dmitriy measured the execution of these programs writing directly to the heap bitmap as being 7x slower than copying from a preunrolled 4-bit mask (and frankly that code was not terribly fast either). For some tests, unrollgcprog1 was seen costing as much as 3x more than the rest of malloc combined. This CL introduces a different form for the GC programs. They use a simple Lempel-Ziv-style encoding of the 1-bit pointer information, in which the only operations are (1) emit the following n bits and (2) repeat the last n bits c more times. This encoding can be generated directly from the Go type information (using repetition only for arrays or large runs of non-pointer data) and it can be decoded very efficiently. In particular the decoding requires little state and no recursion, so that the entire decoding can run without any memory accesses other than the reads of the encoding and the writes of the decoded form to the heap bitmap. For recursive types like arrays of arrays of arrays, the inner instructions are only executed once, not n times, so that large repetitions run at full speed. (In contrast, large repetitions in the old programs repeated the individual bit-level layout of the inner data over and over.) The result is as much as 25x faster decoding compared to the old form. Because the old decoder was so slow, Go 1.4 had three (or so) cases for how to set the heap bitmap bits for an allocation of a given type: (1) If the type had an even number of words up to 32 words, then the 4-bit pointer mask for the type fit in no more than 16 bytes; store the 4-bit pointer mask directly in the binary and copy from it. (1b) If the type had an odd number of words up to 15 words, then the 4-bit pointer mask for the type, doubled to end on a byte boundary, fit in no more than 16 bytes; store that doubled mask directly in the binary and copy from it. (2) If the type had an even number of words up to 128 words, or an odd number of words up to 63 words (again due to doubling), then the 4-bit pointer mask would fit in a 64-byte unrolled mask. Store a GC program in the binary, but leave space in the BSS for the unrolled mask. Execute the GC program to construct the mask the first time it is needed, and thereafter copy from the mask. (3) Otherwise, store a GC program and execute it to write directly to the heap bitmap each time an object of that type is allocated. (This is the case that was 7x slower than the other two.) Because the new pointer masks store 1-bit entries instead of 4-bit entries and because using the decoder no longer carries a significant overhead, after this CL (that is, for Go 1.5) there are only two cases: (1) If the type is 128 words or less (no condition about odd or even), store the 1-bit pointer mask directly in the binary and use it to initialize the heap bitmap during malloc. (Implemented in CL 9702.) (2) There is no case 2 anymore. (3) Otherwise, store a GC program and execute it to write directly to the heap bitmap each time an object of that type is allocated. Executing the GC program directly into the heap bitmap (case (3) above) was disabled for the Go 1.5 dev cycle, both to avoid needing to use GC programs for typedmemmove and to avoid updating that code as the heap bitmap format changed. Typedmemmove no longer uses this type information; as of CL 9886 it uses the heap bitmap directly. Now that the heap bitmap format is stable, we reintroduce GC programs and their space savings. Benchmarks for heapBitsSetType, before this CL vs this CL: name old mean new mean delta SetTypePtr 7.59ns × (0.99,1.02) 5.16ns × (1.00,1.00) -32.05% (p=0.000) SetTypePtr8 21.0ns × (0.98,1.05) 21.4ns × (1.00,1.00) ~ (p=0.179) SetTypePtr16 24.1ns × (0.99,1.01) 24.6ns × (1.00,1.00) +2.41% (p=0.001) SetTypePtr32 31.2ns × (0.99,1.01) 32.4ns × (0.99,1.02) +3.72% (p=0.001) SetTypePtr64 45.2ns × (1.00,1.00) 47.2ns × (1.00,1.00) +4.42% (p=0.000) SetTypePtr126 75.8ns × (0.99,1.01) 79.1ns × (1.00,1.00) +4.25% (p=0.000) SetTypePtr128 74.3ns × (0.99,1.01) 77.6ns × (1.00,1.01) +4.55% (p=0.000) SetTypePtrSlice 726ns × (1.00,1.01) 712ns × (1.00,1.00) -1.95% (p=0.001) SetTypeNode1 20.0ns × (0.99,1.01) 20.7ns × (1.00,1.00) +3.71% (p=0.000) SetTypeNode1Slice 112ns × (1.00,1.00) 113ns × (0.99,1.00) ~ (p=0.070) SetTypeNode8 23.9ns × (1.00,1.00) 24.7ns × (1.00,1.01) +3.18% (p=0.000) SetTypeNode8Slice 294ns × (0.99,1.02) 287ns × (0.99,1.01) -2.38% (p=0.015) SetTypeNode64 52.8ns × (0.99,1.03) 51.8ns × (0.99,1.01) ~ (p=0.069) SetTypeNode64Slice 1.13µs × (0.99,1.05) 1.14µs × (0.99,1.00) ~ (p=0.767) SetTypeNode64Dead 36.0ns × (1.00,1.01) 32.5ns × (0.99,1.00) -9.67% (p=0.000) SetTypeNode64DeadSlice 1.43µs × (0.99,1.01) 1.40µs × (1.00,1.00) -2.39% (p=0.001) SetTypeNode124 75.7ns × (1.00,1.01) 79.0ns × (1.00,1.00) +4.44% (p=0.000) SetTypeNode124Slice 1.94µs × (1.00,1.01) 2.04µs × (0.99,1.01) +4.98% (p=0.000) SetTypeNode126 75.4ns × (1.00,1.01) 77.7ns × (0.99,1.01) +3.11% (p=0.000) SetTypeNode126Slice 1.95µs × (0.99,1.01) 2.03µs × (1.00,1.00) +3.74% (p=0.000) SetTypeNode128 85.4ns × (0.99,1.01) 122.0ns × (1.00,1.00) +42.89% (p=0.000) SetTypeNode128Slice 2.20µs × (1.00,1.01) 2.36µs × (0.98,1.02) +7.48% (p=0.001) SetTypeNode130 83.3ns × (1.00,1.00) 123.0ns × (1.00,1.00) +47.61% (p=0.000) SetTypeNode130Slice 2.30µs × (0.99,1.01) 2.40µs × (0.98,1.01) +4.37% (p=0.000) SetTypeNode1024 498ns × (1.00,1.00) 537ns × (1.00,1.00) +7.96% (p=0.000) SetTypeNode1024Slice 15.5µs × (0.99,1.01) 17.8µs × (1.00,1.00) +15.27% (p=0.000) The above compares always using a cached pointer mask (and the corresponding waste of memory) against using the programs directly. Some slowdown is expected, in exchange for having a better general algorithm. The GC programs kick in for SetTypeNode128, SetTypeNode130, SetTypeNode1024, along with the slice variants of those. It is possible that the cutoff of 128 words (bits) should be raised in a followup CL, but even with this low cutoff the GC programs are faster than Go 1.4's "fast path" non-GC program case. Benchmarks for heapBitsSetType, Go 1.4 vs this CL: name old mean new mean delta SetTypePtr 6.89ns × (1.00,1.00) 5.17ns × (1.00,1.00) -25.02% (p=0.000) SetTypePtr8 25.8ns × (0.97,1.05) 21.5ns × (1.00,1.00) -16.70% (p=0.000) SetTypePtr16 39.8ns × (0.97,1.02) 24.7ns × (0.99,1.01) -37.81% (p=0.000) SetTypePtr32 68.8ns × (0.98,1.01) 32.2ns × (1.00,1.01) -53.18% (p=0.000) SetTypePtr64 130ns × (1.00,1.00) 47ns × (1.00,1.00) -63.67% (p=0.000) SetTypePtr126 241ns × (0.99,1.01) 79ns × (1.00,1.01) -67.25% (p=0.000) SetTypePtr128 2.07µs × (1.00,1.00) 0.08µs × (1.00,1.00) -96.27% (p=0.000) SetTypePtrSlice 1.05µs × (0.99,1.01) 0.72µs × (0.99,1.02) -31.70% (p=0.000) SetTypeNode1 16.0ns × (0.99,1.01) 20.8ns × (0.99,1.03) +29.91% (p=0.000) SetTypeNode1Slice 184ns × (0.99,1.01) 112ns × (0.99,1.01) -39.26% (p=0.000) SetTypeNode8 29.5ns × (0.97,1.02) 24.6ns × (1.00,1.00) -16.50% (p=0.000) SetTypeNode8Slice 624ns × (0.98,1.02) 285ns × (1.00,1.00) -54.31% (p=0.000) SetTypeNode64 135ns × (0.96,1.08) 52ns × (0.99,1.02) -61.32% (p=0.000) SetTypeNode64Slice 3.83µs × (1.00,1.00) 1.14µs × (0.99,1.01) -70.16% (p=0.000) SetTypeNode64Dead 134ns × (0.99,1.01) 32ns × (1.00,1.01) -75.74% (p=0.000) SetTypeNode64DeadSlice 3.83µs × (0.99,1.00) 1.40µs × (1.00,1.01) -63.42% (p=0.000) SetTypeNode124 240ns × (0.99,1.01) 79ns × (1.00,1.01) -67.05% (p=0.000) SetTypeNode124Slice 7.27µs × (1.00,1.00) 2.04µs × (1.00,1.00) -71.95% (p=0.000) SetTypeNode126 2.06µs × (0.99,1.01) 0.08µs × (0.99,1.01) -96.23% (p=0.000) SetTypeNode126Slice 64.4µs × (1.00,1.00) 2.0µs × (1.00,1.00) -96.85% (p=0.000) SetTypeNode128 2.09µs × (1.00,1.01) 0.12µs × (1.00,1.00) -94.15% (p=0.000) SetTypeNode128Slice 65.4µs × (1.00,1.00) 2.4µs × (0.99,1.03) -96.39% (p=0.000) SetTypeNode130 2.11µs × (1.00,1.00) 0.12µs × (1.00,1.00) -94.18% (p=0.000) SetTypeNode130Slice 66.3µs × (1.00,1.00) 2.4µs × (0.97,1.08) -96.34% (p=0.000) SetTypeNode1024 16.0µs × (1.00,1.01) 0.5µs × (1.00,1.00) -96.65% (p=0.000) SetTypeNode1024Slice 512µs × (1.00,1.00) 18µs × (0.98,1.04) -96.45% (p=0.000) SetTypeNode124 uses a 124 data + 2 ptr = 126-word allocation. Both Go 1.4 and this CL are using pointer bitmaps for this case, so that's an overall 3x speedup for using pointer bitmaps. SetTypeNode128 uses a 128 data + 2 ptr = 130-word allocation. Both Go 1.4 and this CL are running the GC program for this case, so that's an overall 17x speedup when using GC programs (and I've seen >20x on other systems). Comparing Go 1.4's SetTypeNode124 (pointer bitmap) against this CL's SetTypeNode128 (GC program), the slow path in the code in this CL is 2x faster than the fast path in Go 1.4. The Go 1 benchmarks are basically unaffected compared to just before this CL. Go 1 benchmarks, before this CL vs this CL: name old mean new mean delta BinaryTree17 5.87s × (0.97,1.04) 5.91s × (0.96,1.04) ~ (p=0.306) Fannkuch11 4.38s × (1.00,1.00) 4.37s × (1.00,1.01) -0.22% (p=0.006) FmtFprintfEmpty 90.7ns × (0.97,1.10) 89.3ns × (0.96,1.09) ~ (p=0.280) FmtFprintfString 282ns × (0.98,1.04) 287ns × (0.98,1.07) +1.72% (p=0.039) FmtFprintfInt 269ns × (0.99,1.03) 282ns × (0.97,1.04) +4.87% (p=0.000) FmtFprintfIntInt 478ns × (0.99,1.02) 481ns × (0.99,1.02) +0.61% (p=0.048) FmtFprintfPrefixedInt 399ns × (0.98,1.03) 400ns × (0.98,1.05) ~ (p=0.533) FmtFprintfFloat 563ns × (0.99,1.01) 570ns × (1.00,1.01) +1.37% (p=0.000) FmtManyArgs 1.89µs × (0.99,1.01) 1.92µs × (0.99,1.02) +1.88% (p=0.000) GobDecode 15.2ms × (0.99,1.01) 15.2ms × (0.98,1.05) ~ (p=0.609) GobEncode 11.6ms × (0.98,1.03) 11.9ms × (0.98,1.04) +2.17% (p=0.000) Gzip 648ms × (0.99,1.01) 648ms × (1.00,1.01) ~ (p=0.835) Gunzip 142ms × (1.00,1.00) 143ms × (1.00,1.01) ~ (p=0.169) HTTPClientServer 90.5µs × (0.98,1.03) 91.5µs × (0.98,1.04) +1.04% (p=0.045) JSONEncode 31.5ms × (0.98,1.03) 31.4ms × (0.98,1.03) ~ (p=0.549) JSONDecode 111ms × (0.99,1.01) 107ms × (0.99,1.01) -3.21% (p=0.000) Mandelbrot200 6.01ms × (1.00,1.00) 6.01ms × (1.00,1.00) ~ (p=0.878) GoParse 6.54ms × (0.99,1.02) 6.61ms × (0.99,1.03) +1.08% (p=0.004) RegexpMatchEasy0_32 160ns × (1.00,1.01) 161ns × (1.00,1.00) +0.40% (p=0.000) RegexpMatchEasy0_1K 560ns × (0.99,1.01) 559ns × (0.99,1.01) ~ (p=0.088) RegexpMatchEasy1_32 138ns × (0.99,1.01) 138ns × (1.00,1.00) ~ (p=0.380) RegexpMatchEasy1_1K 877ns × (1.00,1.00) 878ns × (1.00,1.00) ~ (p=0.157) RegexpMatchMedium_32 251ns × (0.99,1.00) 251ns × (1.00,1.01) +0.28% (p=0.021) RegexpMatchMedium_1K 72.6µs × (1.00,1.00) 72.6µs × (1.00,1.00) ~ (p=0.539) RegexpMatchHard_32 3.84µs × (1.00,1.00) 3.84µs × (1.00,1.00) ~ (p=0.378) RegexpMatchHard_1K 117µs × (1.00,1.00) 117µs × (1.00,1.00) ~ (p=0.067) Revcomp 904ms × (0.99,1.02) 904ms × (0.99,1.01) ~ (p=0.943) Template 125ms × (0.99,1.02) 127ms × (0.99,1.01) +1.79% (p=0.000) TimeParse 627ns × (0.99,1.01) 622ns × (0.99,1.01) -0.88% (p=0.000) TimeFormat 655ns × (0.99,1.02) 655ns × (0.99,1.02) ~ (p=0.976) For the record, Go 1 benchmarks, Go 1.4 vs this CL: name old mean new mean delta BinaryTree17 4.61s × (0.97,1.05) 5.91s × (0.98,1.03) +28.35% (p=0.000) Fannkuch11 4.40s × (0.99,1.03) 4.41s × (0.99,1.01) ~ (p=0.212) FmtFprintfEmpty 102ns × (0.99,1.01) 84ns × (0.99,1.02) -18.38% (p=0.000) FmtFprintfString 302ns × (0.98,1.01) 303ns × (0.99,1.02) ~ (p=0.203) FmtFprintfInt 313ns × (0.97,1.05) 270ns × (0.99,1.01) -13.69% (p=0.000) FmtFprintfIntInt 524ns × (0.98,1.02) 477ns × (0.99,1.00) -8.87% (p=0.000) FmtFprintfPrefixedInt 424ns × (0.98,1.02) 386ns × (0.99,1.01) -8.96% (p=0.000) FmtFprintfFloat 652ns × (0.98,1.02) 594ns × (0.97,1.05) -8.97% (p=0.000) FmtManyArgs 2.13µs × (0.99,1.02) 1.94µs × (0.99,1.01) -8.92% (p=0.000) GobDecode 17.1ms × (0.99,1.02) 14.9ms × (0.98,1.03) -13.07% (p=0.000) GobEncode 13.5ms × (0.98,1.03) 11.5ms × (0.98,1.03) -15.25% (p=0.000) Gzip 656ms × (0.99,1.02) 647ms × (0.99,1.01) -1.29% (p=0.000) Gunzip 143ms × (0.99,1.02) 144ms × (0.99,1.01) ~ (p=0.204) HTTPClientServer 88.2µs × (0.98,1.02) 90.8µs × (0.98,1.01) +2.93% (p=0.000) JSONEncode 32.2ms × (0.98,1.02) 30.9ms × (0.97,1.04) -4.06% (p=0.001) JSONDecode 121ms × (0.98,1.02) 110ms × (0.98,1.05) -8.95% (p=0.000) Mandelbrot200 6.06ms × (0.99,1.01) 6.11ms × (0.98,1.04) ~ (p=0.184) GoParse 6.76ms × (0.97,1.04) 6.58ms × (0.98,1.05) -2.63% (p=0.003) RegexpMatchEasy0_32 195ns × (1.00,1.01) 155ns × (0.99,1.01) -20.43% (p=0.000) RegexpMatchEasy0_1K 479ns × (0.98,1.03) 535ns × (0.99,1.02) +11.59% (p=0.000) RegexpMatchEasy1_32 169ns × (0.99,1.02) 131ns × (0.99,1.03) -22.44% (p=0.000) RegexpMatchEasy1_1K 1.53µs × (0.99,1.01) 0.87µs × (0.99,1.02) -43.07% (p=0.000) RegexpMatchMedium_32 334ns × (0.99,1.01) 242ns × (0.99,1.01) -27.53% (p=0.000) RegexpMatchMedium_1K 125µs × (1.00,1.01) 72µs × (0.99,1.03) -42.53% (p=0.000) RegexpMatchHard_32 6.03µs × (0.99,1.01) 3.79µs × (0.99,1.01) -37.12% (p=0.000) RegexpMatchHard_1K 189µs × (0.99,1.02) 115µs × (0.99,1.01) -39.20% (p=0.000) Revcomp 935ms × (0.96,1.03) 926ms × (0.98,1.02) ~ (p=0.083) Template 146ms × (0.97,1.05) 119ms × (0.99,1.01) -18.37% (p=0.000) TimeParse 660ns × (0.99,1.01) 624ns × (0.99,1.02) -5.43% (p=0.000) TimeFormat 670ns × (0.98,1.02) 710ns × (1.00,1.01) +5.97% (p=0.000) This CL is a bit larger than I would like, but the compiler, linker, runtime, and package reflect all need to be in sync about the format of these programs, so there is no easy way to split this into independent changes (at least while keeping the build working at each change). Fixes #9625. Fixes #10524. Change-Id: I9e3e20d6097099d0f8532d1cb5b1af528804989a Reviewed-on: https://go-review.googlesource.com/9888 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Russ Cox <rsc@golang.org>
2015-05-08 01:43:18 -04:00
{"slice", &Debug_slice}, // print information about slice compilation
{"typeassert", &Debug_typeassert}, // print information about type assertion inlining
{"wb", &Debug_wb}, // print information about write barriers
}
const (
EOF = -1
)
func usage() {
fmt.Printf("usage: compile [options] file.go...\n")
obj.Flagprint(1)
Exit(2)
}
func hidePanic() {
if Debug_panic == 0 && nsavederrors+nerrors > 0 {
// If we've already complained about things
// in the program, don't bother complaining
// about a panic too; let the user clean up
// the code and try again.
if err := recover(); err != nil {
errorexit()
}
}
}
func doversion() {
p := obj.Expstring()
if p == "X:none" {
p = ""
}
sep := ""
if p != "" {
sep = " "
}
fmt.Printf("compile version %s%s%s\n", obj.Getgoversion(), sep, p)
os.Exit(0)
}
func Main() {
defer hidePanic()
// Allow GOARCH=thearch.thestring or GOARCH=thearch.thestringsuffix,
// but not other values.
p := obj.Getgoarch()
if !strings.HasPrefix(p, Thearch.Thestring) {
log.Fatalf("cannot use %cg with GOARCH=%s", Thearch.Thechar, p)
}
goarch = p
Thearch.Linkarchinit()
Ctxt = obj.Linknew(Thearch.Thelinkarch)
Ctxt.Diag = Yyerror
Ctxt.Bso = &bstdout
bstdout = *obj.Binitw(os.Stdout)
localpkg = mkpkg("")
localpkg.Prefix = "\"\""
// pseudo-package, for scoping
builtinpkg = mkpkg("go.builtin")
builtinpkg.Prefix = "go.builtin" // not go%2ebuiltin
// pseudo-package, accessed by import "unsafe"
unsafepkg = mkpkg("unsafe")
unsafepkg.Name = "unsafe"
// real package, referred to by generated runtime calls
Runtimepkg = mkpkg("runtime")
Runtimepkg.Name = "runtime"
// pseudo-packages used in symbol tables
gostringpkg = mkpkg("go.string")
gostringpkg.Name = "go.string"
gostringpkg.Prefix = "go.string" // not go%2estring
itabpkg = mkpkg("go.itab")
itabpkg.Name = "go.itab"
itabpkg.Prefix = "go.itab" // not go%2eitab
weaktypepkg = mkpkg("go.weak.type")
weaktypepkg.Name = "go.weak.type"
weaktypepkg.Prefix = "go.weak.type" // not go%2eweak%2etype
typelinkpkg = mkpkg("go.typelink")
typelinkpkg.Name = "go.typelink"
typelinkpkg.Prefix = "go.typelink" // not go%2etypelink
trackpkg = mkpkg("go.track")
trackpkg.Name = "go.track"
trackpkg.Prefix = "go.track" // not go%2etrack
typepkg = mkpkg("type")
typepkg.Name = "type"
goroot = obj.Getgoroot()
goos = obj.Getgoos()
Nacl = goos == "nacl"
if Nacl {
flag_largemodel = 1
}
outfile = ""
obj.Flagcount("+", "compiling runtime", &compiling_runtime)
obj.Flagcount("%", "debug non-static initializers", &Debug['%'])
obj.Flagcount("A", "for bootstrapping, allow 'any' type", &Debug['A'])
obj.Flagcount("B", "disable bounds checking", &Debug['B'])
obj.Flagstr("D", "set relative `path` for local imports", &localimport)
obj.Flagcount("E", "debug symbol export", &Debug['E'])
obj.Flagfn1("I", "add `directory` to import search path", addidir)
obj.Flagcount("K", "debug missing line numbers", &Debug['K'])
obj.Flagcount("L", "use full (long) path in error messages", &Debug['L'])
obj.Flagcount("M", "debug move generation", &Debug['M'])
obj.Flagcount("N", "disable optimizations", &Debug['N'])
obj.Flagcount("P", "debug peephole optimizer", &Debug['P'])
obj.Flagcount("R", "debug register optimizer", &Debug['R'])
obj.Flagcount("S", "print assembly listing", &Debug['S'])
obj.Flagfn0("V", "print compiler version", doversion)
obj.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
obj.Flagstr("asmhdr", "write assembly header to `file`", &asmhdr)
obj.Flagstr("buildid", "record `id` as the build id in the export metadata", &buildid)
obj.Flagcount("complete", "compiling complete package (no C or assembly)", &pure_go)
obj.Flagstr("d", "print debug information about items in `list`", &debugstr)
obj.Flagcount("e", "no limit on number of errors reported", &Debug['e'])
obj.Flagcount("f", "debug stack frames", &Debug['f'])
obj.Flagcount("g", "debug code generation", &Debug['g'])
obj.Flagcount("h", "halt on error", &Debug['h'])
obj.Flagcount("i", "debug line number stack", &Debug['i'])
obj.Flagfn1("importmap", "add `definition` of the form source=actual to import map", addImportMap)
obj.Flagstr("installsuffix", "set pkg directory `suffix`", &flag_installsuffix)
obj.Flagcount("j", "debug runtime-initialized variables", &Debug['j'])
obj.Flagcount("l", "disable inlining", &Debug['l'])
obj.Flagcount("live", "debug liveness analysis", &debuglive)
obj.Flagcount("m", "print optimization decisions", &Debug['m'])
obj.Flagcount("nolocalimports", "reject local (relative) imports", &nolocalimports)
obj.Flagstr("o", "write output to `file`", &outfile)
obj.Flagstr("p", "set expected package import `path`", &myimportpath)
obj.Flagcount("pack", "write package file instead of object file", &writearchive)
obj.Flagcount("r", "debug generated wrappers", &Debug['r'])
obj.Flagcount("race", "enable race detector", &flag_race)
obj.Flagcount("s", "warn about composite literals that can be simplified", &Debug['s'])
obj.Flagstr("trimpath", "remove `prefix` from recorded source file paths", &Ctxt.LineHist.TrimPathPrefix)
obj.Flagcount("u", "reject unsafe code", &safemode)
obj.Flagcount("v", "increase debug verbosity", &Debug['v'])
obj.Flagcount("w", "debug type checking", &Debug['w'])
use_writebarrier = 1
obj.Flagcount("wb", "enable write barrier", &use_writebarrier)
obj.Flagcount("x", "debug lexer", &Debug['x'])
obj.Flagcount("y", "debug declarations in canned imports (with -d)", &Debug['y'])
var flag_shared int
var flag_dynlink bool
if Thearch.Thechar == '6' || Thearch.Thechar == '5' {
obj.Flagcount("shared", "generate code that can be linked into a shared library", &flag_shared)
}
if Thearch.Thechar == '6' {
obj.Flagcount("largemodel", "generate code that assumes a large memory model", &flag_largemodel)
flag.BoolVar(&flag_dynlink, "dynlink", false, "support references to Go symbols defined in other shared libraries")
}
obj.Flagstr("cpuprofile", "write cpu profile to `file`", &cpuprofile)
obj.Flagstr("memprofile", "write memory profile to `file`", &memprofile)
obj.Flagint64("memprofilerate", "set runtime.MemProfileRate to `rate`", &memprofilerate)
obj.Flagparse(usage)
if flag_dynlink {
flag_shared = 1
}
Ctxt.Flag_shared = int32(flag_shared)
Ctxt.Flag_dynlink = flag_dynlink
Ctxt.Debugasm = int32(Debug['S'])
Ctxt.Debugvlog = int32(Debug['v'])
if flag.NArg() < 1 {
usage()
}
startProfile()
if flag_race != 0 {
racepkg = mkpkg("runtime/race")
racepkg.Name = "race"
}
// parse -d argument
if debugstr != "" {
cmd/internal/gc: accept comma-separated list of name=value for -d This should obviously have no performance impact. Listing numbers just as a sanity check for the benchmark comparison program: it should (and does) find nothing to report. name old new delta BenchmarkBinaryTree17 18.0s × (0.99,1.01) 17.9s × (0.99,1.00) ~ BenchmarkFannkuch11 4.36s × (1.00,1.00) 4.35s × (1.00,1.00) ~ BenchmarkFmtFprintfEmpty 120ns × (0.99,1.06) 120ns × (0.94,1.05) ~ BenchmarkFmtFprintfString 480ns × (0.99,1.01) 477ns × (1.00,1.00) ~ BenchmarkFmtFprintfInt 451ns × (0.99,1.01) 450ns × (0.99,1.01) ~ BenchmarkFmtFprintfIntInt 766ns × (0.99,1.01) 765ns × (0.99,1.01) ~ BenchmarkFmtFprintfPrefixedInt 569ns × (0.99,1.01) 569ns × (0.99,1.01) ~ BenchmarkFmtFprintfFloat 728ns × (1.00,1.01) 728ns × (1.00,1.00) ~ BenchmarkFmtManyArgs 2.81µs × (1.00,1.01) 2.82µs × (0.99,1.01) ~ BenchmarkGobDecode 39.4ms × (0.99,1.01) 39.1ms × (0.99,1.01) ~ BenchmarkGobEncode 39.4ms × (0.99,1.00) 39.4ms × (0.99,1.01) ~ BenchmarkGzip 660ms × (1.00,1.01) 661ms × (0.99,1.01) ~ BenchmarkGunzip 143ms × (1.00,1.00) 143ms × (1.00,1.00) ~ BenchmarkHTTPClientServer 132µs × (0.99,1.01) 133µs × (0.99,1.01) ~ BenchmarkJSONEncode 57.1ms × (0.99,1.01) 57.3ms × (0.99,1.04) ~ BenchmarkJSONDecode 138ms × (1.00,1.01) 139ms × (0.99,1.00) ~ BenchmarkMandelbrot200 6.02ms × (1.00,1.00) 6.02ms × (1.00,1.00) ~ BenchmarkGoParse 9.79ms × (0.92,1.07) 9.72ms × (0.92,1.11) ~ BenchmarkRegexpMatchEasy0_32 210ns × (1.00,1.01) 209ns × (1.00,1.01) ~ BenchmarkRegexpMatchEasy0_1K 593ns × (0.99,1.01) 592ns × (0.99,1.00) ~ BenchmarkRegexpMatchEasy1_32 182ns × (0.99,1.01) 183ns × (0.98,1.01) ~ BenchmarkRegexpMatchEasy1_1K 1.01µs × (1.00,1.01) 1.01µs × (1.00,1.01) ~ BenchmarkRegexpMatchMedium_32 331ns × (1.00,1.00) 330ns × (1.00,1.00) ~ BenchmarkRegexpMatchMedium_1K 92.6µs × (1.00,1.01) 92.4µs × (1.00,1.00) ~ BenchmarkRegexpMatchHard_32 4.58µs × (0.99,1.05) 4.77µs × (0.95,1.01) ~ BenchmarkRegexpMatchHard_1K 136µs × (1.00,1.01) 136µs × (1.00,1.00) ~ BenchmarkRevcomp 900ms × (0.99,1.06) 906ms × (0.99,1.05) ~ BenchmarkTemplate 171ms × (1.00,1.01) 171ms × (0.99,1.01) ~ BenchmarkTimeParse 637ns × (1.00,1.00) 638ns × (1.00,1.00) ~ BenchmarkTimeFormat 742ns × (1.00,1.00) 745ns × (0.99,1.02) ~ Change-Id: I59ec875715cb176bbffa709546370a6a7fc5a75d Reviewed-on: https://go-review.googlesource.com/9309 Reviewed-by: Austin Clements <austin@google.com>
2015-04-24 11:45:11 -04:00
Split:
for _, name := range strings.Split(debugstr, ",") {
if name == "" {
continue
}
cmd/internal/gc: accept comma-separated list of name=value for -d This should obviously have no performance impact. Listing numbers just as a sanity check for the benchmark comparison program: it should (and does) find nothing to report. name old new delta BenchmarkBinaryTree17 18.0s × (0.99,1.01) 17.9s × (0.99,1.00) ~ BenchmarkFannkuch11 4.36s × (1.00,1.00) 4.35s × (1.00,1.00) ~ BenchmarkFmtFprintfEmpty 120ns × (0.99,1.06) 120ns × (0.94,1.05) ~ BenchmarkFmtFprintfString 480ns × (0.99,1.01) 477ns × (1.00,1.00) ~ BenchmarkFmtFprintfInt 451ns × (0.99,1.01) 450ns × (0.99,1.01) ~ BenchmarkFmtFprintfIntInt 766ns × (0.99,1.01) 765ns × (0.99,1.01) ~ BenchmarkFmtFprintfPrefixedInt 569ns × (0.99,1.01) 569ns × (0.99,1.01) ~ BenchmarkFmtFprintfFloat 728ns × (1.00,1.01) 728ns × (1.00,1.00) ~ BenchmarkFmtManyArgs 2.81µs × (1.00,1.01) 2.82µs × (0.99,1.01) ~ BenchmarkGobDecode 39.4ms × (0.99,1.01) 39.1ms × (0.99,1.01) ~ BenchmarkGobEncode 39.4ms × (0.99,1.00) 39.4ms × (0.99,1.01) ~ BenchmarkGzip 660ms × (1.00,1.01) 661ms × (0.99,1.01) ~ BenchmarkGunzip 143ms × (1.00,1.00) 143ms × (1.00,1.00) ~ BenchmarkHTTPClientServer 132µs × (0.99,1.01) 133µs × (0.99,1.01) ~ BenchmarkJSONEncode 57.1ms × (0.99,1.01) 57.3ms × (0.99,1.04) ~ BenchmarkJSONDecode 138ms × (1.00,1.01) 139ms × (0.99,1.00) ~ BenchmarkMandelbrot200 6.02ms × (1.00,1.00) 6.02ms × (1.00,1.00) ~ BenchmarkGoParse 9.79ms × (0.92,1.07) 9.72ms × (0.92,1.11) ~ BenchmarkRegexpMatchEasy0_32 210ns × (1.00,1.01) 209ns × (1.00,1.01) ~ BenchmarkRegexpMatchEasy0_1K 593ns × (0.99,1.01) 592ns × (0.99,1.00) ~ BenchmarkRegexpMatchEasy1_32 182ns × (0.99,1.01) 183ns × (0.98,1.01) ~ BenchmarkRegexpMatchEasy1_1K 1.01µs × (1.00,1.01) 1.01µs × (1.00,1.01) ~ BenchmarkRegexpMatchMedium_32 331ns × (1.00,1.00) 330ns × (1.00,1.00) ~ BenchmarkRegexpMatchMedium_1K 92.6µs × (1.00,1.01) 92.4µs × (1.00,1.00) ~ BenchmarkRegexpMatchHard_32 4.58µs × (0.99,1.05) 4.77µs × (0.95,1.01) ~ BenchmarkRegexpMatchHard_1K 136µs × (1.00,1.01) 136µs × (1.00,1.00) ~ BenchmarkRevcomp 900ms × (0.99,1.06) 906ms × (0.99,1.05) ~ BenchmarkTemplate 171ms × (1.00,1.01) 171ms × (0.99,1.01) ~ BenchmarkTimeParse 637ns × (1.00,1.00) 638ns × (1.00,1.00) ~ BenchmarkTimeFormat 742ns × (1.00,1.00) 745ns × (0.99,1.02) ~ Change-Id: I59ec875715cb176bbffa709546370a6a7fc5a75d Reviewed-on: https://go-review.googlesource.com/9309 Reviewed-by: Austin Clements <austin@google.com>
2015-04-24 11:45:11 -04:00
val := 1
if i := strings.Index(name, "="); i >= 0 {
var err error
val, err = strconv.Atoi(name[i+1:])
if err != nil {
log.Fatalf("invalid debug value %v", name)
}
cmd/internal/gc: accept comma-separated list of name=value for -d This should obviously have no performance impact. Listing numbers just as a sanity check for the benchmark comparison program: it should (and does) find nothing to report. name old new delta BenchmarkBinaryTree17 18.0s × (0.99,1.01) 17.9s × (0.99,1.00) ~ BenchmarkFannkuch11 4.36s × (1.00,1.00) 4.35s × (1.00,1.00) ~ BenchmarkFmtFprintfEmpty 120ns × (0.99,1.06) 120ns × (0.94,1.05) ~ BenchmarkFmtFprintfString 480ns × (0.99,1.01) 477ns × (1.00,1.00) ~ BenchmarkFmtFprintfInt 451ns × (0.99,1.01) 450ns × (0.99,1.01) ~ BenchmarkFmtFprintfIntInt 766ns × (0.99,1.01) 765ns × (0.99,1.01) ~ BenchmarkFmtFprintfPrefixedInt 569ns × (0.99,1.01) 569ns × (0.99,1.01) ~ BenchmarkFmtFprintfFloat 728ns × (1.00,1.01) 728ns × (1.00,1.00) ~ BenchmarkFmtManyArgs 2.81µs × (1.00,1.01) 2.82µs × (0.99,1.01) ~ BenchmarkGobDecode 39.4ms × (0.99,1.01) 39.1ms × (0.99,1.01) ~ BenchmarkGobEncode 39.4ms × (0.99,1.00) 39.4ms × (0.99,1.01) ~ BenchmarkGzip 660ms × (1.00,1.01) 661ms × (0.99,1.01) ~ BenchmarkGunzip 143ms × (1.00,1.00) 143ms × (1.00,1.00) ~ BenchmarkHTTPClientServer 132µs × (0.99,1.01) 133µs × (0.99,1.01) ~ BenchmarkJSONEncode 57.1ms × (0.99,1.01) 57.3ms × (0.99,1.04) ~ BenchmarkJSONDecode 138ms × (1.00,1.01) 139ms × (0.99,1.00) ~ BenchmarkMandelbrot200 6.02ms × (1.00,1.00) 6.02ms × (1.00,1.00) ~ BenchmarkGoParse 9.79ms × (0.92,1.07) 9.72ms × (0.92,1.11) ~ BenchmarkRegexpMatchEasy0_32 210ns × (1.00,1.01) 209ns × (1.00,1.01) ~ BenchmarkRegexpMatchEasy0_1K 593ns × (0.99,1.01) 592ns × (0.99,1.00) ~ BenchmarkRegexpMatchEasy1_32 182ns × (0.99,1.01) 183ns × (0.98,1.01) ~ BenchmarkRegexpMatchEasy1_1K 1.01µs × (1.00,1.01) 1.01µs × (1.00,1.01) ~ BenchmarkRegexpMatchMedium_32 331ns × (1.00,1.00) 330ns × (1.00,1.00) ~ BenchmarkRegexpMatchMedium_1K 92.6µs × (1.00,1.01) 92.4µs × (1.00,1.00) ~ BenchmarkRegexpMatchHard_32 4.58µs × (0.99,1.05) 4.77µs × (0.95,1.01) ~ BenchmarkRegexpMatchHard_1K 136µs × (1.00,1.01) 136µs × (1.00,1.00) ~ BenchmarkRevcomp 900ms × (0.99,1.06) 906ms × (0.99,1.05) ~ BenchmarkTemplate 171ms × (1.00,1.01) 171ms × (0.99,1.01) ~ BenchmarkTimeParse 637ns × (1.00,1.00) 638ns × (1.00,1.00) ~ BenchmarkTimeFormat 742ns × (1.00,1.00) 745ns × (0.99,1.02) ~ Change-Id: I59ec875715cb176bbffa709546370a6a7fc5a75d Reviewed-on: https://go-review.googlesource.com/9309 Reviewed-by: Austin Clements <austin@google.com>
2015-04-24 11:45:11 -04:00
name = name[:i]
}
cmd/internal/gc: accept comma-separated list of name=value for -d This should obviously have no performance impact. Listing numbers just as a sanity check for the benchmark comparison program: it should (and does) find nothing to report. name old new delta BenchmarkBinaryTree17 18.0s × (0.99,1.01) 17.9s × (0.99,1.00) ~ BenchmarkFannkuch11 4.36s × (1.00,1.00) 4.35s × (1.00,1.00) ~ BenchmarkFmtFprintfEmpty 120ns × (0.99,1.06) 120ns × (0.94,1.05) ~ BenchmarkFmtFprintfString 480ns × (0.99,1.01) 477ns × (1.00,1.00) ~ BenchmarkFmtFprintfInt 451ns × (0.99,1.01) 450ns × (0.99,1.01) ~ BenchmarkFmtFprintfIntInt 766ns × (0.99,1.01) 765ns × (0.99,1.01) ~ BenchmarkFmtFprintfPrefixedInt 569ns × (0.99,1.01) 569ns × (0.99,1.01) ~ BenchmarkFmtFprintfFloat 728ns × (1.00,1.01) 728ns × (1.00,1.00) ~ BenchmarkFmtManyArgs 2.81µs × (1.00,1.01) 2.82µs × (0.99,1.01) ~ BenchmarkGobDecode 39.4ms × (0.99,1.01) 39.1ms × (0.99,1.01) ~ BenchmarkGobEncode 39.4ms × (0.99,1.00) 39.4ms × (0.99,1.01) ~ BenchmarkGzip 660ms × (1.00,1.01) 661ms × (0.99,1.01) ~ BenchmarkGunzip 143ms × (1.00,1.00) 143ms × (1.00,1.00) ~ BenchmarkHTTPClientServer 132µs × (0.99,1.01) 133µs × (0.99,1.01) ~ BenchmarkJSONEncode 57.1ms × (0.99,1.01) 57.3ms × (0.99,1.04) ~ BenchmarkJSONDecode 138ms × (1.00,1.01) 139ms × (0.99,1.00) ~ BenchmarkMandelbrot200 6.02ms × (1.00,1.00) 6.02ms × (1.00,1.00) ~ BenchmarkGoParse 9.79ms × (0.92,1.07) 9.72ms × (0.92,1.11) ~ BenchmarkRegexpMatchEasy0_32 210ns × (1.00,1.01) 209ns × (1.00,1.01) ~ BenchmarkRegexpMatchEasy0_1K 593ns × (0.99,1.01) 592ns × (0.99,1.00) ~ BenchmarkRegexpMatchEasy1_32 182ns × (0.99,1.01) 183ns × (0.98,1.01) ~ BenchmarkRegexpMatchEasy1_1K 1.01µs × (1.00,1.01) 1.01µs × (1.00,1.01) ~ BenchmarkRegexpMatchMedium_32 331ns × (1.00,1.00) 330ns × (1.00,1.00) ~ BenchmarkRegexpMatchMedium_1K 92.6µs × (1.00,1.01) 92.4µs × (1.00,1.00) ~ BenchmarkRegexpMatchHard_32 4.58µs × (0.99,1.05) 4.77µs × (0.95,1.01) ~ BenchmarkRegexpMatchHard_1K 136µs × (1.00,1.01) 136µs × (1.00,1.00) ~ BenchmarkRevcomp 900ms × (0.99,1.06) 906ms × (0.99,1.05) ~ BenchmarkTemplate 171ms × (1.00,1.01) 171ms × (0.99,1.01) ~ BenchmarkTimeParse 637ns × (1.00,1.00) 638ns × (1.00,1.00) ~ BenchmarkTimeFormat 742ns × (1.00,1.00) 745ns × (0.99,1.02) ~ Change-Id: I59ec875715cb176bbffa709546370a6a7fc5a75d Reviewed-on: https://go-review.googlesource.com/9309 Reviewed-by: Austin Clements <austin@google.com>
2015-04-24 11:45:11 -04:00
for _, t := range debugtab {
if t.name == name {
if t.val != nil {
*t.val = val
continue Split
}
}
}
cmd/internal/gc: accept comma-separated list of name=value for -d This should obviously have no performance impact. Listing numbers just as a sanity check for the benchmark comparison program: it should (and does) find nothing to report. name old new delta BenchmarkBinaryTree17 18.0s × (0.99,1.01) 17.9s × (0.99,1.00) ~ BenchmarkFannkuch11 4.36s × (1.00,1.00) 4.35s × (1.00,1.00) ~ BenchmarkFmtFprintfEmpty 120ns × (0.99,1.06) 120ns × (0.94,1.05) ~ BenchmarkFmtFprintfString 480ns × (0.99,1.01) 477ns × (1.00,1.00) ~ BenchmarkFmtFprintfInt 451ns × (0.99,1.01) 450ns × (0.99,1.01) ~ BenchmarkFmtFprintfIntInt 766ns × (0.99,1.01) 765ns × (0.99,1.01) ~ BenchmarkFmtFprintfPrefixedInt 569ns × (0.99,1.01) 569ns × (0.99,1.01) ~ BenchmarkFmtFprintfFloat 728ns × (1.00,1.01) 728ns × (1.00,1.00) ~ BenchmarkFmtManyArgs 2.81µs × (1.00,1.01) 2.82µs × (0.99,1.01) ~ BenchmarkGobDecode 39.4ms × (0.99,1.01) 39.1ms × (0.99,1.01) ~ BenchmarkGobEncode 39.4ms × (0.99,1.00) 39.4ms × (0.99,1.01) ~ BenchmarkGzip 660ms × (1.00,1.01) 661ms × (0.99,1.01) ~ BenchmarkGunzip 143ms × (1.00,1.00) 143ms × (1.00,1.00) ~ BenchmarkHTTPClientServer 132µs × (0.99,1.01) 133µs × (0.99,1.01) ~ BenchmarkJSONEncode 57.1ms × (0.99,1.01) 57.3ms × (0.99,1.04) ~ BenchmarkJSONDecode 138ms × (1.00,1.01) 139ms × (0.99,1.00) ~ BenchmarkMandelbrot200 6.02ms × (1.00,1.00) 6.02ms × (1.00,1.00) ~ BenchmarkGoParse 9.79ms × (0.92,1.07) 9.72ms × (0.92,1.11) ~ BenchmarkRegexpMatchEasy0_32 210ns × (1.00,1.01) 209ns × (1.00,1.01) ~ BenchmarkRegexpMatchEasy0_1K 593ns × (0.99,1.01) 592ns × (0.99,1.00) ~ BenchmarkRegexpMatchEasy1_32 182ns × (0.99,1.01) 183ns × (0.98,1.01) ~ BenchmarkRegexpMatchEasy1_1K 1.01µs × (1.00,1.01) 1.01µs × (1.00,1.01) ~ BenchmarkRegexpMatchMedium_32 331ns × (1.00,1.00) 330ns × (1.00,1.00) ~ BenchmarkRegexpMatchMedium_1K 92.6µs × (1.00,1.01) 92.4µs × (1.00,1.00) ~ BenchmarkRegexpMatchHard_32 4.58µs × (0.99,1.05) 4.77µs × (0.95,1.01) ~ BenchmarkRegexpMatchHard_1K 136µs × (1.00,1.01) 136µs × (1.00,1.00) ~ BenchmarkRevcomp 900ms × (0.99,1.06) 906ms × (0.99,1.05) ~ BenchmarkTemplate 171ms × (1.00,1.01) 171ms × (0.99,1.01) ~ BenchmarkTimeParse 637ns × (1.00,1.00) 638ns × (1.00,1.00) ~ BenchmarkTimeFormat 742ns × (1.00,1.00) 745ns × (0.99,1.02) ~ Change-Id: I59ec875715cb176bbffa709546370a6a7fc5a75d Reviewed-on: https://go-review.googlesource.com/9309 Reviewed-by: Austin Clements <austin@google.com>
2015-04-24 11:45:11 -04:00
log.Fatalf("unknown debug key -d %s\n", name)
}
}
// enable inlining. for now:
// default: inlining on. (debug['l'] == 1)
// -l: inlining off (debug['l'] == 0)
// -ll, -lll: inlining on again, with extra debugging (debug['l'] > 1)
if Debug['l'] <= 1 {
Debug['l'] = 1 - Debug['l']
}
Thearch.Betypeinit()
if Widthptr == 0 {
Fatalf("betypeinit failed")
}
lexinit()
typeinit()
lexinit1()
// TODO(rsc): Restore yytinit?
blockgen = 1
dclcontext = PEXTERN
nerrors = 0
lexlineno = 1
const BOM = 0xFEFF
for _, infile = range flag.Args() {
linehistpush(infile)
curio.infile = infile
var err error
curio.bin, err = obj.Bopenr(infile)
if err != nil {
fmt.Printf("open %s: %v\n", infile, err)
errorexit()
}
curio.peekc = 0
curio.peekc1 = 0
curio.nlsemi = false
curio.eofnl = false
curio.last = 0
// Skip initial BOM if present.
if obj.Bgetrune(curio.bin) != BOM {
obj.Bungetrune(curio.bin)
}
block = 1
iota_ = -1000000
imported_unsafe = false
yyparse()
if nsyntaxerrors != 0 {
errorexit()
}
linehistpop()
if curio.bin != nil {
obj.Bterm(curio.bin)
}
}
testdclstack()
mkpackage(localpkg.Name) // final import not used checks
lexfini()
typecheckok = true
if Debug['f'] != 0 {
frame(1)
}
// Process top-level declarations in phases.
// Phase 1: const, type, and names and types of funcs.
// This will gather all the information about types
// and methods but doesn't depend on any of it.
defercheckwidth()
for l := xtop; l != nil; l = l.Next {
if l.N.Op != ODCL && l.N.Op != OAS && l.N.Op != OAS2 {
typecheck(&l.N, Etop)
}
}
// Phase 2: Variable assignments.
// To check interface assignments, depends on phase 1.
for l := xtop; l != nil; l = l.Next {
if l.N.Op == ODCL || l.N.Op == OAS || l.N.Op == OAS2 {
typecheck(&l.N, Etop)
}
}
resumecheckwidth()
// Phase 3: Type check function bodies.
for l := xtop; l != nil; l = l.Next {
if l.N.Op == ODCLFUNC || l.N.Op == OCLOSURE {
Curfn = l.N
decldepth = 1
saveerrors()
typechecklist(l.N.Nbody, Etop)
checkreturn(l.N)
if nerrors != 0 {
l.N.Nbody = nil // type errors; do not compile
}
}
}
// Phase 4: Decide how to capture closed variables.
// This needs to run before escape analysis,
// because variables captured by value do not escape.
for l := xtop; l != nil; l = l.Next {
if l.N.Op == ODCLFUNC && l.N.Func.Closure != nil {
Curfn = l.N
capturevars(l.N)
}
}
Curfn = nil
if nsavederrors+nerrors != 0 {
errorexit()
}
// Phase 5: Inlining
if Debug['l'] > 1 {
// Typecheck imported function bodies if debug['l'] > 1,
// otherwise lazily when used or re-exported.
for _, n := range importlist {
if n.Func.Inl != nil {
saveerrors()
typecheckinl(n)
}
}
if nsavederrors+nerrors != 0 {
errorexit()
}
}
if Debug['l'] != 0 {
// Find functions that can be inlined and clone them before walk expands them.
visitBottomUp(xtop, func(list []*Node, recursive bool) {
// TODO: use a range statement here if the order does not matter
for i := len(list) - 1; i >= 0; i-- {
n := list[i]
if n.Op == ODCLFUNC {
caninl(n)
inlcalls(n)
}
}
})
}
// Phase 6: Escape analysis.
// Required for moving heap allocations onto stack,
// which in turn is required by the closure implementation,
// which stores the addresses of stack variables into the closure.
// If the closure does not escape, it needs to be on the stack
// or else the stack copier will not update it.
// Large values are also moved off stack in escape analysis;
// because large values may contain pointers, it must happen early.
escapes(xtop)
// Phase 7: Transform closure bodies to properly reference captured variables.
// This needs to happen before walk, because closures must be transformed
// before walk reaches a call of a closure.
for l := xtop; l != nil; l = l.Next {
if l.N.Op == ODCLFUNC && l.N.Func.Closure != nil {
Curfn = l.N
transformclosure(l.N)
}
}
Curfn = nil
// Phase 8: Compile top level functions.
for l := xtop; l != nil; l = l.Next {
if l.N.Op == ODCLFUNC {
funccompile(l.N)
}
}
if nsavederrors+nerrors == 0 {
fninit(xtop)
}
// Phase 9: Check external declarations.
for l := externdcl; l != nil; l = l.Next {
if l.N.Op == ONAME {
typecheck(&l.N, Erv)
}
}
if nerrors+nsavederrors != 0 {
errorexit()
}
dumpobj()
if asmhdr != "" {
dumpasmhdr()
}
if nerrors+nsavederrors != 0 {
errorexit()
}
Flusherrors()
}
var importMap = map[string]string{}
func addImportMap(s string) {
if strings.Count(s, "=") != 1 {
log.Fatal("-importmap argument must be of the form source=actual")
}
i := strings.Index(s, "=")
source, actual := s[:i], s[i+1:]
if source == "" || actual == "" {
log.Fatal("-importmap argument must be of the form source=actual; source and actual must be non-empty")
}
importMap[source] = actual
}
func saveerrors() {
nsavederrors += nerrors
nerrors = 0
}
func arsize(b *obj.Biobuf, name string) int {
var buf [ArhdrSize]byte
if _, err := io.ReadFull(b, buf[:]); err != nil {
return -1
}
aname := strings.Trim(string(buf[0:16]), " ")
if !strings.HasPrefix(aname, name) {
return -1
}
asize := strings.Trim(string(buf[48:58]), " ")
i, _ := strconv.Atoi(asize)
return i
}
func skiptopkgdef(b *obj.Biobuf) bool {
/* archive header */
p := obj.Brdline(b, '\n')
if p == "" {
return false
}
if obj.Blinelen(b) != 8 {
return false
}
if p != "!<arch>\n" {
return false
}
/* symbol table may be first; skip it */
sz := arsize(b, "__.GOSYMDEF")
if sz >= 0 {
obj.Bseek(b, int64(sz), 1)
} else {
obj.Bseek(b, 8, 0)
}
/* package export block is next */
sz = arsize(b, "__.PKGDEF")
if sz <= 0 {
return false
}
return true
}
func addidir(dir string) {
if dir == "" {
return
}
var pp **Idir
for pp = &idirs; *pp != nil; pp = &(*pp).link {
}
*pp = new(Idir)
(*pp).link = nil
(*pp).dir = dir
}
// is this path a local name? begins with ./ or ../ or /
func islocalname(name string) bool {
return strings.HasPrefix(name, "/") ||
Ctxt.Windows != 0 && len(name) >= 3 && isAlpha(int(name[0])) && name[1] == ':' && name[2] == '/' ||
strings.HasPrefix(name, "./") || name == "." ||
strings.HasPrefix(name, "../") || name == ".."
}
func findpkg(name string) (file string, ok bool) {
if islocalname(name) {
if safemode != 0 || nolocalimports != 0 {
return "", false
}
// try .a before .6. important for building libraries:
// if there is an array.6 in the array.a library,
// want to find all of array.a, not just array.6.
file = fmt.Sprintf("%s.a", name)
if _, err := os.Stat(file); err == nil {
return file, true
}
file = fmt.Sprintf("%s.o", name)
if _, err := os.Stat(file); err == nil {
return file, true
}
return "", false
}
// local imports should be canonicalized already.
// don't want to see "encoding/../encoding/base64"
// as different from "encoding/base64".
var q string
_ = q
if path.Clean(name) != name {
Yyerror("non-canonical import path %q (should be %q)", name, q)
return "", false
}
for p := idirs; p != nil; p = p.link {
file = fmt.Sprintf("%s/%s.a", p.dir, name)
if _, err := os.Stat(file); err == nil {
return file, true
}
file = fmt.Sprintf("%s/%s.o", p.dir, name)
if _, err := os.Stat(file); err == nil {
return file, true
}
}
if goroot != "" {
suffix := ""
suffixsep := ""
if flag_installsuffix != "" {
suffixsep = "_"
suffix = flag_installsuffix
} else if flag_race != 0 {
suffixsep = "_"
suffix = "race"
}
file = fmt.Sprintf("%s/pkg/%s_%s%s%s/%s.a", goroot, goos, goarch, suffixsep, suffix, name)
if _, err := os.Stat(file); err == nil {
return file, true
}
file = fmt.Sprintf("%s/pkg/%s_%s%s%s/%s.o", goroot, goos, goarch, suffixsep, suffix, name)
if _, err := os.Stat(file); err == nil {
return file, true
}
}
return "", false
}
func fakeimport() {
importpkg = mkpkg("fake")
cannedimports("fake.o", "$$\n")
}
func importfile(f *Val, line int) {
if _, ok := f.U.(string); !ok {
Yyerror("import statement not a string")
fakeimport()
return
}
if len(f.U.(string)) == 0 {
Yyerror("import path is empty")
fakeimport()
return
}
if isbadimport(f.U.(string)) {
fakeimport()
return
}
// The package name main is no longer reserved,
// but we reserve the import path "main" to identify
// the main package, just as we reserve the import
// path "math" to identify the standard math package.
if f.U.(string) == "main" {
Yyerror("cannot import \"main\"")
errorexit()
}
if myimportpath != "" && f.U.(string) == myimportpath {
Yyerror("import %q while compiling that package (import cycle)", f.U.(string))
errorexit()
}
if f.U.(string) == "unsafe" {
if safemode != 0 {
Yyerror("cannot import package unsafe")
errorexit()
}
importpkg = mkpkg(f.U.(string))
cannedimports("unsafe.o", unsafeimport)
imported_unsafe = true
return
}
path_ := f.U.(string)
if mapped, ok := importMap[path_]; ok {
path_ = mapped
}
if islocalname(path_) {
if path_[0] == '/' {
Yyerror("import path cannot be absolute path")
fakeimport()
return
}
prefix := Ctxt.Pathname
if localimport != "" {
prefix = localimport
}
cleanbuf := prefix
cleanbuf += "/"
cleanbuf += path_
cleanbuf = path.Clean(cleanbuf)
path_ = cleanbuf
if isbadimport(path_) {
fakeimport()
return
}
}
file, found := findpkg(path_)
if !found {
Yyerror("can't find import: %q", f.U.(string))
errorexit()
}
importpkg = mkpkg(path_)
// If we already saw that package, feed a dummy statement
// to the lexer to avoid parsing export data twice.
if importpkg.Imported {
tag := ""
if importpkg.Safe {
tag = "safe"
}
p := fmt.Sprintf("package %s %s\n$$\n", importpkg.Name, tag)
cannedimports(file, p)
return
}
importpkg.Imported = true
var err error
var imp *obj.Biobuf
imp, err = obj.Bopenr(file)
if err != nil {
Yyerror("can't open import: %q: %v", f.U.(string), err)
errorexit()
}
if strings.HasSuffix(file, ".a") {
if !skiptopkgdef(imp) {
Yyerror("import %s: not a package file", file)
errorexit()
}
}
// check object header
p := obj.Brdstr(imp, '\n', 1)
if p != "empty archive" {
if !strings.HasPrefix(p, "go object ") {
Yyerror("import %s: not a go object file", file)
errorexit()
}
q := fmt.Sprintf("%s %s %s %s", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring())
if p[10:] != q {
Yyerror("import %s: object is [%s] expected [%s]", file, p[10:], q)
errorexit()
}
}
// assume files move (get installed)
// so don't record the full path.
linehistpragma(file[len(file)-len(path_)-2:]) // acts as #pragma lib
/*
* position the input right
* after $$ and return
*/
pushedio = curio
curio.bin = imp
curio.peekc = 0
curio.peekc1 = 0
curio.infile = file
curio.nlsemi = false
typecheckok = true
for {
c := getc()
if c == EOF {
break
}
if c != '$' {
continue
}
c = getc()
if c == EOF {
break
}
if c != '$' {
continue
}
return
}
Yyerror("no import in %q", f.U.(string))
unimportfile()
}
func unimportfile() {
if curio.bin != nil {
obj.Bterm(curio.bin)
curio.bin = nil
} else {
lexlineno-- // re correct sys.6 line number
}
curio = pushedio
pushedio.bin = nil
incannedimport = 0
typecheckok = false
}
func cannedimports(file string, cp string) {
lexlineno++ // if sys.6 is included on line 1,
pushedio = curio
curio.bin = nil
curio.peekc = 0
curio.peekc1 = 0
curio.infile = file
curio.cp = cp
curio.nlsemi = false
curio.importsafe = false
typecheckok = true
incannedimport = 1
}
func isfrog(c int) bool {
// complain about possibly invisible control characters
if c < ' ' {
return !isSpace(c) // exclude good white space
}
if 0x7f <= c && c <= 0xa0 { // DEL, unicode block including unbreakable space.
return true
}
return false
}
type Loophack struct {
next *Loophack
v bool
}
var _yylex_lstk *Loophack
func _yylex(yylval *yySymType) int32 {
var c1 int
var escflag int
var v int64
var cp *bytes.Buffer
var s *Sym
var h *Loophack
var str string
prevlineno = lineno
l0:
c := getc()
if isSpace(c) {
if c == '\n' && curio.nlsemi {
ungetc(c)
if Debug['x'] != 0 {
fmt.Printf("lex: implicit semi\n")
}
return ';'
}
goto l0
}
lineno = lexlineno /* start of token */
if c >= utf8.RuneSelf {
/* all multibyte runes are alpha */
cp = &lexbuf
cp.Reset()
goto talph
}
if isAlpha(c) {
cp = &lexbuf
cp.Reset()
goto talph
}
if isDigit(c) {
cp = &lexbuf
cp.Reset()
if c != '0' {
for {
cp.WriteByte(byte(c))
c = getc()
if isDigit(c) {
continue
}
if c == '.' {
goto casedot
}
if c == 'e' || c == 'E' || c == 'p' || c == 'P' {
goto caseep
}
if c == 'i' {
goto casei
}
goto ncu
}
}
cp.WriteByte(byte(c))
c = getc()
if c == 'x' || c == 'X' {
for {
cp.WriteByte(byte(c))
c = getc()
if isDigit(c) {
continue
}
if c >= 'a' && c <= 'f' {
continue
}
if c >= 'A' && c <= 'F' {
continue
}
if lexbuf.Len() == 2 {
Yyerror("malformed hex constant")
}
if c == 'p' {
goto caseep
}
goto ncu
}
}
if c == 'p' { // 0p begins floating point zero
goto caseep
}
c1 = 0
for {
if !isDigit(c) {
break
}
if c < '0' || c > '7' {
c1 = 1 // not octal
}
cp.WriteByte(byte(c))
c = getc()
}
if c == '.' {
goto casedot
}
if c == 'e' || c == 'E' {
goto caseep
}
if c == 'i' {
goto casei
}
if c1 != 0 {
Yyerror("malformed octal constant")
}
goto ncu
}
switch c {
case EOF:
lineno = prevlineno
ungetc(EOF)
return -1
case '_':
cp = &lexbuf
cp.Reset()
goto talph
case '.':
c1 = getc()
if isDigit(c1) {
cp = &lexbuf
cp.Reset()
cp.WriteByte(byte(c))
c = c1
goto casedot
}
if c1 == '.' {
c1 = getc()
if c1 == '.' {
c = LDDD
goto lx
}
ungetc(c1)
c1 = '.'
}
/* "..." */
case '"':
lexbuf.Reset()
lexbuf.WriteString(`"<string>"`)
cp = &strbuf
cp.Reset()
for {
if escchar('"', &escflag, &v) {
break
}
if v < utf8.RuneSelf || escflag != 0 {
cp.WriteByte(byte(v))
} else {
cp.WriteRune(rune(v))
}
}
goto strlit
/* `...` */
case '`':
lexbuf.Reset()
lexbuf.WriteString("`<string>`")
cp = &strbuf
cp.Reset()
for {
c = int(getr())
if c == '\r' {
continue
}
if c == EOF {
Yyerror("eof in string")
break
}
if c == '`' {
break
}
cp.WriteRune(rune(c))
}
goto strlit
/* '.' */
case '\'':
if escchar('\'', &escflag, &v) {
Yyerror("empty character literal or unescaped ' in character literal")
v = '\''
}
if !escchar('\'', &escflag, &v) {
Yyerror("missing '")
ungetc(int(v))
}
x := new(Mpint)
yylval.val.U = x
Mpmovecfix(x, v)
x.Rune = true
if Debug['x'] != 0 {
fmt.Printf("lex: codepoint literal\n")
}
litbuf = "string literal"
return LLITERAL
case '/':
c1 = getc()
if c1 == '*' {
nl := false
for {
c = int(getr())
if c == '\n' {
nl = true
}
for c == '*' {
c = int(getr())
if c == '/' {
if nl {
ungetc('\n')
}
goto l0
}
if c == '\n' {
nl = true
}
}
if c == EOF {
Yyerror("eof in comment")
errorexit()
}
}
}
if c1 == '/' {
c = getlinepragma()
for {
if c == '\n' || c == EOF {
ungetc(c)
goto l0
}
c = int(getr())
}
}
if c1 == '=' {
c = ODIV
goto asop
}
case ':':
c1 = getc()
if c1 == '=' {
c = LCOLAS
yylval.i = int(lexlineno)
goto lx
}
case '*':
c1 = getc()
if c1 == '=' {
c = OMUL
goto asop
}
case '%':
c1 = getc()
if c1 == '=' {
c = OMOD
goto asop
}
case '+':
c1 = getc()
if c1 == '+' {
c = LINC
goto lx
}
if c1 == '=' {
c = OADD
goto asop
}
case '-':
c1 = getc()
if c1 == '-' {
c = LDEC
goto lx
}
if c1 == '=' {
c = OSUB
goto asop
}
case '>':
c1 = getc()
if c1 == '>' {
c = LRSH
c1 = getc()
if c1 == '=' {
c = ORSH
goto asop
}
break
}
if c1 == '=' {
c = LGE
goto lx
}
c = LGT
case '<':
c1 = getc()
if c1 == '<' {
c = LLSH
c1 = getc()
if c1 == '=' {
c = OLSH
goto asop
}
break
}
if c1 == '=' {
c = LLE
goto lx
}
if c1 == '-' {
c = LCOMM
goto lx
}
c = LLT
case '=':
c1 = getc()
if c1 == '=' {
c = LEQ
goto lx
}
case '!':
c1 = getc()
if c1 == '=' {
c = LNE
goto lx
}
case '&':
c1 = getc()
if c1 == '&' {
c = LANDAND
goto lx
}
if c1 == '^' {
c = LANDNOT
c1 = getc()
if c1 == '=' {
c = OANDNOT
goto asop
}
break
}
if c1 == '=' {
c = OAND
goto asop
}
case '|':
c1 = getc()
if c1 == '|' {
c = LOROR
goto lx
}
if c1 == '=' {
c = OOR
goto asop
}
case '^':
c1 = getc()
if c1 == '=' {
c = OXOR
goto asop
}
/*
* clumsy dance:
* to implement rule that disallows
* if T{1}[0] { ... }
* but allows
* if (T{1}[0]) { ... }
* the block bodies for if/for/switch/select
* begin with an LBODY token, not '{'.
*
* when we see the keyword, the next
* non-parenthesized '{' becomes an LBODY.
* loophack is normally false.
* a keyword sets it to true.
* parens push loophack onto a stack and go back to false.
* a '{' with loophack == true becomes LBODY and disables loophack.
*
* i said it was clumsy.
*/
case '(', '[':
if loophack || _yylex_lstk != nil {
h = new(Loophack)
if h == nil {
Flusherrors()
Yyerror("out of memory")
errorexit()
}
h.v = loophack
h.next = _yylex_lstk
_yylex_lstk = h
loophack = false
}
goto lx
case ')', ']':
if _yylex_lstk != nil {
h = _yylex_lstk
loophack = h.v
_yylex_lstk = h.next
}
goto lx
case '{':
if loophack {
if Debug['x'] != 0 {
fmt.Printf("%v lex: LBODY\n", Ctxt.Line(int(lexlineno)))
}
loophack = false
return LBODY
}
goto lx
default:
goto lx
}
ungetc(c1)
lx:
if c > 0xff {
if Debug['x'] != 0 {
fmt.Printf("%v lex: TOKEN %s\n", Ctxt.Line(int(lexlineno)), lexname(c))
}
} else {
if Debug['x'] != 0 {
fmt.Printf("%v lex: TOKEN '%c'\n", Ctxt.Line(int(lexlineno)), c)
}
}
if isfrog(c) {
Yyerror("illegal character 0x%x", uint(c))
goto l0
}
if importpkg == nil && (c == '#' || c == '$' || c == '?' || c == '@' || c == '\\') {
Yyerror("%s: unexpected %c", "syntax error", c)
goto l0
}
return int32(c)
asop:
yylval.i = c // rathole to hold which asop
if Debug['x'] != 0 {
fmt.Printf("lex: TOKEN ASOP %c\n", c)
}
return LASOP
/*
* cp is set to lexbuf and some
* prefix has been stored
*/
talph:
for {
if c >= utf8.RuneSelf {
ungetc(c)
r := rune(getr())
// 0xb7 · is used for internal names
if !unicode.IsLetter(r) && !unicode.IsDigit(r) && (importpkg == nil || r != 0xb7) {
Yyerror("invalid identifier character U+%04x", r)
}
cp.WriteRune(r)
} else if !isAlnum(c) && c != '_' {
break
} else {
cp.WriteByte(byte(c))
}
c = getc()
}
cp = nil
ungetc(c)
s = LookupBytes(lexbuf.Bytes())
switch s.Lexical {
case LIGNORE:
goto l0
case LFOR, LIF, LSWITCH, LSELECT:
loophack = true // see comment about loophack above
}
if Debug['x'] != 0 {
fmt.Printf("lex: %s %s\n", s, lexname(int(s.Lexical)))
}
yylval.sym = s
return int32(s.Lexical)
ncu:
cp = nil
ungetc(c)
str = lexbuf.String()
yylval.val.U = new(Mpint)
mpatofix(yylval.val.U.(*Mpint), str)
if yylval.val.U.(*Mpint).Ovf {
Yyerror("overflow in constant")
Mpmovecfix(yylval.val.U.(*Mpint), 0)
}
if Debug['x'] != 0 {
fmt.Printf("lex: integer literal\n")
}
litbuf = "literal " + str
return LLITERAL
casedot:
for {
cp.WriteByte(byte(c))
c = getc()
if !isDigit(c) {
break
}
}
if c == 'i' {
goto casei
}
if c != 'e' && c != 'E' {
goto caseout
}
caseep:
if importpkg == nil && (c == 'p' || c == 'P') {
// <mantissa>p<base-2-exponent> is allowed in .a/.o imports,
// but not in .go sources. See #9036.
Yyerror("malformed floating point constant")
}
cp.WriteByte(byte(c))
c = getc()
if c == '+' || c == '-' {
cp.WriteByte(byte(c))
c = getc()
}
if !isDigit(c) {
Yyerror("malformed floating point constant exponent")
}
for isDigit(c) {
cp.WriteByte(byte(c))
c = getc()
}
if c == 'i' {
goto casei
}
goto caseout
// imaginary constant
casei:
cp = nil
str = lexbuf.String()
yylval.val.U = new(Mpcplx)
Mpmovecflt(&yylval.val.U.(*Mpcplx).Real, 0.0)
mpatoflt(&yylval.val.U.(*Mpcplx).Imag, str)
if yylval.val.U.(*Mpcplx).Imag.Val.IsInf() {
Yyerror("overflow in imaginary constant")
Mpmovecflt(&yylval.val.U.(*Mpcplx).Real, 0.0)
}
if Debug['x'] != 0 {
fmt.Printf("lex: imaginary literal\n")
}
litbuf = "literal " + str
return LLITERAL
caseout:
cp = nil
ungetc(c)
str = lexbuf.String()
yylval.val.U = newMpflt()
mpatoflt(yylval.val.U.(*Mpflt), str)
if yylval.val.U.(*Mpflt).Val.IsInf() {
Yyerror("overflow in float constant")
Mpmovecflt(yylval.val.U.(*Mpflt), 0.0)
}
if Debug['x'] != 0 {
fmt.Printf("lex: floating literal\n")
}
litbuf = "literal " + str
return LLITERAL
strlit:
yylval.val.U = internString(cp.Bytes())
if Debug['x'] != 0 {
fmt.Printf("lex: string literal\n")
}
litbuf = "string literal"
return LLITERAL
}
var internedStrings = map[string]string{}
func internString(b []byte) string {
s, ok := internedStrings[string(b)] // string(b) here doesn't allocate
if ok {
return s
}
s = string(b)
internedStrings[s] = s
return s
}
func more(pp *string) bool {
p := *pp
for p != "" && isSpace(int(p[0])) {
p = p[1:]
}
*pp = p
return p != ""
}
/*
* read and interpret syntax that looks like
* //line parse.y:15
* as a discontinuity in sequential line numbers.
* the next line of input comes from parse.y:15
*/
func getlinepragma() int {
var cmd, verb, name string
c := int(getr())
if c == 'g' {
cp := &lexbuf
cp.Reset()
cp.WriteByte('g') // already read
for {
c = int(getr())
if c == EOF || c >= utf8.RuneSelf {
return c
}
if c == '\n' {
break
}
cp.WriteByte(byte(c))
}
cp = nil
text := strings.TrimSuffix(lexbuf.String(), "\r")
if strings.HasPrefix(text, "go:cgo_") {
pragcgo(text)
}
cmd = text
verb = cmd
if i := strings.Index(verb, " "); i >= 0 {
verb = verb[:i]
}
if verb == "go:linkname" {
if !imported_unsafe {
Yyerror("//go:linkname only allowed in Go files that import \"unsafe\"")
}
f := strings.Fields(cmd)
if len(f) != 3 {
Yyerror("usage: //go:linkname localname linkname")
return c
}
Lookup(f[1]).Linkname = f[2]
return c
}
if verb == "go:nointerface" && obj.Fieldtrack_enabled != 0 {
nointerface = true
return c
}
if verb == "go:noescape" {
noescape = true
return c
}
if verb == "go:norace" {
norace = true
return c
}
if verb == "go:nosplit" {
nosplit = true
return c
}
if verb == "go:systemstack" {
if compiling_runtime == 0 {
Yyerror("//go:systemstack only allowed in runtime")
}
systemstack = true
return c
}
if verb == "go:nowritebarrier" {
if compiling_runtime == 0 {
Yyerror("//go:nowritebarrier only allowed in runtime")
}
nowritebarrier = true
return c
}
return c
}
if c != 'l' {
return c
}
for i := 1; i < 5; i++ {
c = int(getr())
if c != int("line "[i]) {
return c
}
}
cp := &lexbuf
cp.Reset()
linep := 0
for {
c = int(getr())
if c == EOF {
return c
}
if c == '\n' {
break
}
if c == ' ' {
continue
}
if c == ':' {
linep = cp.Len() + 1
}
cp.WriteByte(byte(c))
}
cp = nil
if linep == 0 {
return c
}
text := strings.TrimSuffix(lexbuf.String(), "\r")
n := 0
for _, c := range text[linep:] {
if c < '0' || c > '9' {
goto out
}
n = n*10 + int(c) - '0'
if n > 1e8 {
Yyerror("line number out of range")
errorexit()
}
}
if n <= 0 {
return c
}
name = text[:linep-1]
linehistupdate(name, n)
return c
out:
return c
}
func getimpsym(pp *string) string {
more(pp) // skip spaces
p := *pp
if p == "" || p[0] == '"' {
return ""
}
i := 0
for i < len(p) && !isSpace(int(p[i])) && p[i] != '"' {
i++
}
sym := p[:i]
*pp = p[i:]
return sym
}
func getquoted(pp *string) (string, bool) {
more(pp) // skip spaces
p := *pp
if p == "" || p[0] != '"' {
return "", false
}
p = p[1:]
i := strings.Index(p, `"`)
if i < 0 {
return "", false
}
*pp = p[i+1:]
return p[:i], true
}
// Copied nearly verbatim from the C compiler's #pragma parser.
// TODO: Rewrite more cleanly once the compiler is written in Go.
func pragcgo(text string) {
var q string
if i := strings.Index(text, " "); i >= 0 {
text, q = text[:i], text[i:]
}
verb := text[3:] // skip "go:"
if verb == "cgo_dynamic_linker" || verb == "dynlinker" {
p, ok := getquoted(&q)
if !ok {
Yyerror("usage: //go:cgo_dynamic_linker \"path\"")
return
}
pragcgobuf += fmt.Sprintf("cgo_dynamic_linker %v\n", plan9quote(p))
return
}
if verb == "dynexport" {
verb = "cgo_export_dynamic"
}
if verb == "cgo_export_static" || verb == "cgo_export_dynamic" {
local := getimpsym(&q)
var remote string
if local == "" {
goto err2
}
if !more(&q) {
pragcgobuf += fmt.Sprintf("%s %v\n", verb, plan9quote(local))
return
}
remote = getimpsym(&q)
if remote == "" {
goto err2
}
pragcgobuf += fmt.Sprintf("%s %v %v\n", verb, plan9quote(local), plan9quote(remote))
return
err2:
Yyerror("usage: //go:%s local [remote]", verb)
return
}
if verb == "cgo_import_dynamic" || verb == "dynimport" {
var ok bool
local := getimpsym(&q)
var p string
var remote string
if local == "" {
goto err3
}
if !more(&q) {
pragcgobuf += fmt.Sprintf("cgo_import_dynamic %v\n", plan9quote(local))
return
}
remote = getimpsym(&q)
if remote == "" {
goto err3
}
if !more(&q) {
pragcgobuf += fmt.Sprintf("cgo_import_dynamic %v %v\n", plan9quote(local), plan9quote(remote))
return
}
p, ok = getquoted(&q)
if !ok {
goto err3
}
pragcgobuf += fmt.Sprintf("cgo_import_dynamic %v %v %v\n", plan9quote(local), plan9quote(remote), plan9quote(p))
return
err3:
Yyerror("usage: //go:cgo_import_dynamic local [remote [\"library\"]]")
return
}
if verb == "cgo_import_static" {
local := getimpsym(&q)
if local == "" || more(&q) {
Yyerror("usage: //go:cgo_import_static local")
return
}
pragcgobuf += fmt.Sprintf("cgo_import_static %v\n", plan9quote(local))
return
}
if verb == "cgo_ldflag" {
p, ok := getquoted(&q)
if !ok {
Yyerror("usage: //go:cgo_ldflag \"arg\"")
return
}
pragcgobuf += fmt.Sprintf("cgo_ldflag %v\n", plan9quote(p))
return
}
}
type yy struct{}
func (yy) Lex(v *yySymType) int {
return int(yylex(v))
}
func (yy) Error(msg string) {
Yyerror("%s", msg)
}
var theparser yyParser
var parsing bool
func yyparse() {
theparser = yyNewParser()
parsing = true
theparser.Parse(yy{})
parsing = false
}
func yylex(yylval *yySymType) int32 {
lx := int(_yylex(yylval))
if curio.nlsemi && lx == EOF {
// Treat EOF as "end of line" for the purposes
// of inserting a semicolon.
lx = ';'
}
switch lx {
case LNAME,
LLITERAL,
LBREAK,
LCONTINUE,
LFALL,
LRETURN,
LINC,
LDEC,
')',
'}',
']':
curio.nlsemi = true
default:
curio.nlsemi = false
}
// Track last two tokens returned by yylex.
yyprev = yylast
yylast = lx
return int32(lx)
}
func getc() int {
c := curio.peekc
if c != 0 {
curio.peekc = curio.peekc1
curio.peekc1 = 0
goto check
}
if curio.bin == nil {
if len(curio.cp) == 0 {
c = 0
} else {
c = int(curio.cp[0])
curio.cp = curio.cp[1:]
}
} else {
loop:
c = obj.Bgetc(curio.bin)
if c == 0xef {
buf, err := curio.bin.Peek(2)
if err != nil {
log.Fatalf("getc: peeking: %v", err)
}
if buf[0] == 0xbb && buf[1] == 0xbf {
yyerrorl(int(lexlineno), "Unicode (UTF-8) BOM in middle of file")
// consume BOM bytes
obj.Bgetc(curio.bin)
obj.Bgetc(curio.bin)
goto loop
}
}
}
check:
switch c {
case 0:
if curio.bin != nil {
Yyerror("illegal NUL byte")
break
}
fallthrough
// insert \n at EOF
case EOF:
if curio.eofnl || curio.last == '\n' {
return EOF
}
curio.eofnl = true
c = '\n'
fallthrough
case '\n':
if pushedio.bin == nil {
lexlineno++
}
}
curio.last = c
return c
}
func ungetc(c int) {
curio.peekc1 = curio.peekc
curio.peekc = c
if c == '\n' && pushedio.bin == nil {
lexlineno--
}
}
func getr() int32 {
var buf [utf8.UTFMax]byte
for i := 0; ; i++ {
c := getc()
if i == 0 && c < utf8.RuneSelf {
return int32(c)
}
buf[i] = byte(c)
if i+1 == len(buf) || utf8.FullRune(buf[:i+1]) {
r, w := utf8.DecodeRune(buf[:i+1])
if r == utf8.RuneError && w == 1 {
lineno = lexlineno
// The string conversion here makes a copy for passing
// to fmt.Printf, so that buf itself does not escape and can
// be allocated on the stack.
Yyerror("illegal UTF-8 sequence % x", string(buf[:i+1]))
}
return int32(r)
}
}
}
func escchar(e int, escflg *int, val *int64) bool {
*escflg = 0
c := int(getr())
switch c {
case EOF:
Yyerror("eof in string")
return true
case '\n':
Yyerror("newline in string")
return true
case '\\':
break
default:
if c == e {
return true
}
*val = int64(c)
return false
}
u := 0
c = int(getr())
var i int
switch c {
case 'x':
*escflg = 1 // it's a byte
i = 2
goto hex
case 'u':
i = 4
u = 1
goto hex
case 'U':
i = 8
u = 1
goto hex
case '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7':
*escflg = 1 // it's a byte
l := int64(c) - '0'
for i := 2; i > 0; i-- {
c = getc()
if c >= '0' && c <= '7' {
l = l*8 + int64(c) - '0'
continue
}
Yyerror("non-octal character in escape sequence: %c", c)
ungetc(c)
}
if l > 255 {
Yyerror("octal escape value > 255: %d", l)
}
*val = l
return false
case 'a':
c = '\a'
case 'b':
c = '\b'
case 'f':
c = '\f'
case 'n':
c = '\n'
case 'r':
c = '\r'
case 't':
c = '\t'
case 'v':
c = '\v'
case '\\':
c = '\\'
default:
if c != e {
Yyerror("unknown escape sequence: %c", c)
}
}
*val = int64(c)
return false
hex:
l := int64(0)
for ; i > 0; i-- {
c = getc()
if c >= '0' && c <= '9' {
l = l*16 + int64(c) - '0'
continue
}
if c >= 'a' && c <= 'f' {
l = l*16 + int64(c) - 'a' + 10
continue
}
if c >= 'A' && c <= 'F' {
l = l*16 + int64(c) - 'A' + 10
continue
}
Yyerror("non-hex character in escape sequence: %c", c)
ungetc(c)
break
}
if u != 0 && (l > utf8.MaxRune || (0xd800 <= l && l < 0xe000)) {
Yyerror("invalid Unicode code point in escape sequence: %#x", l)
l = utf8.RuneError
}
*val = l
return false
}
var syms = []struct {
name string
lexical int
etype int
op int
}{
/* basic types */
{"int8", LNAME, TINT8, OXXX},
{"int16", LNAME, TINT16, OXXX},
{"int32", LNAME, TINT32, OXXX},
{"int64", LNAME, TINT64, OXXX},
{"uint8", LNAME, TUINT8, OXXX},
{"uint16", LNAME, TUINT16, OXXX},
{"uint32", LNAME, TUINT32, OXXX},
{"uint64", LNAME, TUINT64, OXXX},
{"float32", LNAME, TFLOAT32, OXXX},
{"float64", LNAME, TFLOAT64, OXXX},
{"complex64", LNAME, TCOMPLEX64, OXXX},
{"complex128", LNAME, TCOMPLEX128, OXXX},
{"bool", LNAME, TBOOL, OXXX},
{"string", LNAME, TSTRING, OXXX},
{"any", LNAME, TANY, OXXX},
{"break", LBREAK, Txxx, OXXX},
{"case", LCASE, Txxx, OXXX},
{"chan", LCHAN, Txxx, OXXX},
{"const", LCONST, Txxx, OXXX},
{"continue", LCONTINUE, Txxx, OXXX},
{"default", LDEFAULT, Txxx, OXXX},
{"else", LELSE, Txxx, OXXX},
{"defer", LDEFER, Txxx, OXXX},
{"fallthrough", LFALL, Txxx, OXXX},
{"for", LFOR, Txxx, OXXX},
{"func", LFUNC, Txxx, OXXX},
{"go", LGO, Txxx, OXXX},
{"goto", LGOTO, Txxx, OXXX},
{"if", LIF, Txxx, OXXX},
{"import", LIMPORT, Txxx, OXXX},
{"interface", LINTERFACE, Txxx, OXXX},
{"map", LMAP, Txxx, OXXX},
{"package", LPACKAGE, Txxx, OXXX},
{"range", LRANGE, Txxx, OXXX},
{"return", LRETURN, Txxx, OXXX},
{"select", LSELECT, Txxx, OXXX},
{"struct", LSTRUCT, Txxx, OXXX},
{"switch", LSWITCH, Txxx, OXXX},
{"type", LTYPE, Txxx, OXXX},
{"var", LVAR, Txxx, OXXX},
{"append", LNAME, Txxx, OAPPEND},
{"cap", LNAME, Txxx, OCAP},
{"close", LNAME, Txxx, OCLOSE},
{"complex", LNAME, Txxx, OCOMPLEX},
{"copy", LNAME, Txxx, OCOPY},
{"delete", LNAME, Txxx, ODELETE},
{"imag", LNAME, Txxx, OIMAG},
{"len", LNAME, Txxx, OLEN},
{"make", LNAME, Txxx, OMAKE},
{"new", LNAME, Txxx, ONEW},
{"panic", LNAME, Txxx, OPANIC},
{"print", LNAME, Txxx, OPRINT},
{"println", LNAME, Txxx, OPRINTN},
{"real", LNAME, Txxx, OREAL},
{"recover", LNAME, Txxx, ORECOVER},
{"notwithstanding", LIGNORE, Txxx, OXXX},
{"thetruthofthematter", LIGNORE, Txxx, OXXX},
{"despiteallobjections", LIGNORE, Txxx, OXXX},
{"whereas", LIGNORE, Txxx, OXXX},
{"insofaras", LIGNORE, Txxx, OXXX},
}
// lexinit initializes known symbols and the basic types.
func lexinit() {
for _, s := range syms {
lex := s.lexical
s1 := Lookup(s.name)
s1.Lexical = uint16(lex)
if etype := s.etype; etype != Txxx {
if etype < 0 || etype >= len(Types) {
Fatalf("lexinit: %s bad etype", s.name)
}
s2 := Pkglookup(s.name, builtinpkg)
t := Types[etype]
if t == nil {
t = typ(etype)
t.Sym = s2
if etype != TANY && etype != TSTRING {
dowidth(t)
}
Types[etype] = t
}
s2.Lexical = LNAME
s2.Def = typenod(t)
s2.Def.Name = new(Name)
continue
}
if etype := s.op; etype != OXXX {
s2 := Pkglookup(s.name, builtinpkg)
s2.Lexical = LNAME
s2.Def = Nod(ONAME, nil, nil)
s2.Def.Sym = s2
s2.Def.Etype = uint8(etype)
}
}
// logically, the type of a string literal.
// types[TSTRING] is the named type string
// (the type of x in var x string or var x = "hello").
// this is the ideal form
// (the type of x in const x = "hello").
idealstring = typ(TSTRING)
idealbool = typ(TBOOL)
s := Pkglookup("true", builtinpkg)
s.Def = Nodbool(true)
s.Def.Sym = Lookup("true")
s.Def.Name = new(Name)
s.Def.Type = idealbool
s = Pkglookup("false", builtinpkg)
s.Def = Nodbool(false)
s.Def.Sym = Lookup("false")
s.Def.Name = new(Name)
s.Def.Type = idealbool
s = Lookup("_")
s.Block = -100
s.Def = Nod(ONAME, nil, nil)
s.Def.Sym = s
Types[TBLANK] = typ(TBLANK)
s.Def.Type = Types[TBLANK]
nblank = s.Def
s = Pkglookup("_", builtinpkg)
s.Block = -100
s.Def = Nod(ONAME, nil, nil)
s.Def.Sym = s
Types[TBLANK] = typ(TBLANK)
s.Def.Type = Types[TBLANK]
Types[TNIL] = typ(TNIL)
s = Pkglookup("nil", builtinpkg)
var v Val
v.U = new(NilVal)
s.Def = nodlit(v)
s.Def.Sym = s
s.Def.Name = new(Name)
}
func lexinit1() {
// t = interface { Error() string }
rcvr := typ(TSTRUCT)
rcvr.Type = typ(TFIELD)
rcvr.Type.Type = Ptrto(typ(TSTRUCT))
rcvr.Funarg = true
in := typ(TSTRUCT)
in.Funarg = true
out := typ(TSTRUCT)
out.Type = typ(TFIELD)
out.Type.Type = Types[TSTRING]
out.Funarg = true
f := typ(TFUNC)
*getthis(f) = rcvr
*Getoutarg(f) = out
*getinarg(f) = in
f.Thistuple = 1
f.Intuple = 0
f.Outnamed = false
f.Outtuple = 1
t := typ(TINTER)
t.Type = typ(TFIELD)
t.Type.Sym = Lookup("Error")
t.Type.Type = f
// error type
s := Lookup("error")
s.Lexical = LNAME
s1 := Pkglookup("error", builtinpkg)
errortype = t
errortype.Sym = s1
s1.Lexical = LNAME
s1.Def = typenod(errortype)
// byte alias
s = Lookup("byte")
s.Lexical = LNAME
s1 = Pkglookup("byte", builtinpkg)
bytetype = typ(TUINT8)
bytetype.Sym = s1
s1.Lexical = LNAME
s1.Def = typenod(bytetype)
s1.Def.Name = new(Name)
// rune alias
s = Lookup("rune")
s.Lexical = LNAME
s1 = Pkglookup("rune", builtinpkg)
runetype = typ(TINT32)
runetype.Sym = s1
s1.Lexical = LNAME
s1.Def = typenod(runetype)
s1.Def.Name = new(Name)
}
func lexfini() {
var s *Sym
var lex int
var etype int
var i int
for i = 0; i < len(syms); i++ {
lex = syms[i].lexical
if lex != LNAME {
continue
}
s = Lookup(syms[i].name)
s.Lexical = uint16(lex)
etype = syms[i].etype
if etype != Txxx && (etype != TANY || Debug['A'] != 0) && s.Def == nil {
s.Def = typenod(Types[etype])
s.Def.Name = new(Name)
s.Origpkg = builtinpkg
}
etype = syms[i].op
if etype != OXXX && s.Def == nil {
s.Def = Nod(ONAME, nil, nil)
s.Def.Sym = s
s.Def.Etype = uint8(etype)
s.Origpkg = builtinpkg
}
}
// backend-specific builtin types (e.g. int).
for i = range Thearch.Typedefs {
s = Lookup(Thearch.Typedefs[i].Name)
if s.Def == nil {
s.Def = typenod(Types[Thearch.Typedefs[i].Etype])
s.Def.Name = new(Name)
s.Origpkg = builtinpkg
}
}
// there's only so much table-driven we can handle.
// these are special cases.
s = Lookup("byte")
if s.Def == nil {
s.Def = typenod(bytetype)
s.Def.Name = new(Name)
s.Origpkg = builtinpkg
}
s = Lookup("error")
if s.Def == nil {
s.Def = typenod(errortype)
s.Def.Name = new(Name)
s.Origpkg = builtinpkg
}
s = Lookup("rune")
if s.Def == nil {
s.Def = typenod(runetype)
s.Def.Name = new(Name)
s.Origpkg = builtinpkg
}
s = Lookup("nil")
if s.Def == nil {
var v Val
v.U = new(NilVal)
s.Def = nodlit(v)
s.Def.Sym = s
s.Def.Name = new(Name)
s.Origpkg = builtinpkg
}
s = Lookup("iota")
if s.Def == nil {
s.Def = Nod(OIOTA, nil, nil)
s.Def.Sym = s
s.Origpkg = builtinpkg
}
s = Lookup("true")
if s.Def == nil {
s.Def = Nodbool(true)
s.Def.Sym = s
s.Def.Name = new(Name)
s.Origpkg = builtinpkg
}
s = Lookup("false")
if s.Def == nil {
s.Def = Nodbool(false)
s.Def.Sym = s
s.Def.Name = new(Name)
s.Origpkg = builtinpkg
}
nodfp = Nod(ONAME, nil, nil)
nodfp.Type = Types[TINT32]
nodfp.Xoffset = 0
nodfp.Class = PPARAM
nodfp.Sym = Lookup(".fp")
}
var lexn = map[int]string{
LANDAND: "ANDAND",
LANDNOT: "ANDNOT",
LASOP: "ASOP",
LBREAK: "BREAK",
LCASE: "CASE",
LCHAN: "CHAN",
LCOLAS: "COLAS",
LCOMM: "<-",
LCONST: "CONST",
LCONTINUE: "CONTINUE",
LDDD: "...",
LDEC: "DEC",
LDEFAULT: "DEFAULT",
LDEFER: "DEFER",
LELSE: "ELSE",
LEQ: "EQ",
LFALL: "FALL",
LFOR: "FOR",
LFUNC: "FUNC",
LGE: "GE",
LGO: "GO",
LGOTO: "GOTO",
LGT: "GT",
LIF: "IF",
LIMPORT: "IMPORT",
LINC: "INC",
LINTERFACE: "INTERFACE",
LLE: "LE",
LLITERAL: "LITERAL",
LLSH: "LSH",
LLT: "LT",
LMAP: "MAP",
LNAME: "NAME",
LNE: "NE",
LOROR: "OROR",
LPACKAGE: "PACKAGE",
LRANGE: "RANGE",
LRETURN: "RETURN",
LRSH: "RSH",
LSELECT: "SELECT",
LSTRUCT: "STRUCT",
LSWITCH: "SWITCH",
LTYPE: "TYPE",
LVAR: "VAR",
}
func lexname(lex int) string {
if s, ok := lexn[lex]; ok {
return s
}
return fmt.Sprintf("LEX-%d", lex)
}
var yytfix = map[string]string{
"$end": "EOF",
"LASOP": "op=",
"LBREAK": "break",
"LCASE": "case",
"LCHAN": "chan",
"LCOLAS": ":=",
"LCONST": "const",
"LCONTINUE": "continue",
"LDDD": "...",
"LDEFAULT": "default",
"LDEFER": "defer",
"LELSE": "else",
"LFALL": "fallthrough",
"LFOR": "for",
"LFUNC": "func",
"LGO": "go",
"LGOTO": "goto",
"LIF": "if",
"LIMPORT": "import",
"LINTERFACE": "interface",
"LMAP": "map",
"LNAME": "name",
"LPACKAGE": "package",
"LRANGE": "range",
"LRETURN": "return",
"LSELECT": "select",
"LSTRUCT": "struct",
"LSWITCH": "switch",
"LTYPE": "type",
"LVAR": "var",
"LANDAND": "&&",
"LANDNOT": "&^",
"LBODY": "{",
"LCOMM": "<-",
"LDEC": "--",
"LINC": "++",
"LEQ": "==",
"LGE": ">=",
"LGT": ">",
"LLE": "<=",
"LLT": "<",
"LLSH": "<<",
"LRSH": ">>",
"LOROR": "||",
"LNE": "!=",
// spell out to avoid confusion with punctuation in error messages
"';'": "semicolon or newline",
"','": "comma",
}
func init() {
yyErrorVerbose = true
for i, s := range yyToknames {
// Apply yytfix if possible.
if fix, ok := yytfix[s]; ok {
yyToknames[i] = fix
} else if len(s) == 3 && s[0] == '\'' && s[2] == '\'' {
// Turn 'x' into x.
yyToknames[i] = s[1:2]
}
}
}
func pkgnotused(lineno int, path string, name string) {
// If the package was imported with a name other than the final
// import path element, show it explicitly in the error message.
// Note that this handles both renamed imports and imports of
// packages containing unconventional package declarations.
// Note that this uses / always, even on Windows, because Go import
// paths always use forward slashes.
elem := path
if i := strings.LastIndex(elem, "/"); i >= 0 {
elem = elem[i+1:]
}
if name == "" || elem == name {
yyerrorl(int(lineno), "imported and not used: %q", path)
} else {
yyerrorl(int(lineno), "imported and not used: %q as %s", path, name)
}
}
func mkpackage(pkgname string) {
if localpkg.Name == "" {
if pkgname == "_" {
Yyerror("invalid package name _")
}
localpkg.Name = pkgname
} else {
if pkgname != localpkg.Name {
Yyerror("package %s; expected %s", pkgname, localpkg.Name)
}
for _, s := range localpkg.Syms {
if s.Def == nil {
continue
}
if s.Def.Op == OPACK {
// throw away top-level package name leftover
// from previous file.
// leave s->block set to cause redeclaration
// errors if a conflicting top-level name is
// introduced by a different file.
if !s.Def.Used && nsyntaxerrors == 0 {
pkgnotused(int(s.Def.Lineno), s.Def.Name.Pkg.Path, s.Name)
}
s.Def = nil
continue
}
if s.Def.Sym != s {
// throw away top-level name left over
// from previous import . "x"
if s.Def.Name != nil && s.Def.Name.Pack != nil && !s.Def.Name.Pack.Used && nsyntaxerrors == 0 {
pkgnotused(int(s.Def.Name.Pack.Lineno), s.Def.Name.Pack.Name.Pkg.Path, "")
s.Def.Name.Pack.Used = true
}
s.Def = nil
continue
}
}
}
if outfile == "" {
p := infile
if i := strings.LastIndex(p, "/"); i >= 0 {
p = p[i+1:]
}
if Ctxt.Windows != 0 {
if i := strings.LastIndex(p, `\`); i >= 0 {
p = p[i+1:]
}
}
if i := strings.LastIndex(p, "."); i >= 0 {
p = p[:i]
}
suffix := ".o"
if writearchive > 0 {
suffix = ".a"
}
outfile = p + suffix
}
}