main.mx raw
1 // A shift whose left operand is an untyped constant takes the type the
2 // context gives it, never the count's type.
3 //
4 // stage4 typed `1 << c` (c a byte) as uint8, so the emitter's overshift
5 // select - Go says a count >= the operand width shifts to zero - rejected
6 // every count >= 8 and the result was 0: `bytes.TrimRight(s, "\r\n")` never
7 // trimmed, so the mediaproxy header loop ran past the blank line and every
8 // fetch failed with "read header: EOF" once the peer closed. legacy (go/ssa)
9 // types the shift from its context and answered correctly.
10 package main
11
12 import "fmt"
13
14 func byteCount(c byte) (r uint32) { return 1 << (c % 32) }
15 func byteCountTy(c byte) (r uint32) { return uint32(1) << (c % 32) }
16 func sixtyFour(c byte) (r uint64) { return 1 << (c % 64) }
17 func fromCount(c byte) (r uint32) { return 1 << c }
18 func addZero(c byte) (r uint32) { return 1<<(c%32) + 0 }
19 func arg64(x uint64) (r uint64) { return x }
20 func viaArg(c byte) (r uint64) { return arg64(1 << (c % 64)) }
21 func viaSlice(c byte) (r uint64) { s := []uint64{1 << (c % 64)}; return s[0] }
22 func viaMap(c byte) (r uint64) { m := map[string]uint64{"a": 1 << (c % 64)}; return m["a"] }
23 func viaIf(c byte) (r uint64) { if v := uint64(1) << (c % 64); v > 0 { return v }; return 0 }
24
25 // Package scope carries no initializer any more: the zero values are declared
26 // and assigned at the top of main, in dependency order (pkgVal reads pkgShift).
27 var pkgShift byte
28 var pkgVal uint64
29
30 func initGlobals() {
31 pkgShift = 13
32 pkgVal = 1 << (pkgShift % 32)
33 }
34
35 func main() {
36 initGlobals()
37 var c byte = 13
38 var big byte = 40
39 if byteCount(c) != 8192 || byteCountTy(c) != 8192 || fromCount(c) != 8192 || addZero(c) != 8192 {
40 panic("32-bit forms")
41 }
42 if sixtyFour(big) != 1<<40 || viaArg(big) != 1<<40 {
43 panic("64-bit context")
44 }
45 var assigned uint64 = 1 << (c % 32)
46 if assigned != 8192 {
47 panic("var declaration")
48 }
49 var multiA, multiB uint64 = 1 << (c % 32), 1 << (big % 32)
50 if multiA != 8192 || multiB != 256 {
51 panic("multi var declaration")
52 }
53 if viaSlice(big) != 1<<40 {
54 panic("slice literal element")
55 }
56 if viaMap(big) != 1<<40 {
57 panic("map literal value")
58 }
59 if viaIf(big) != 1<<40 {
60 panic("if initializer")
61 }
62 if pkgVal != 8192 {
63 panic("package variable")
64 }
65 fmt.Printf("ok\n")
66 fmt.Printf("shift %d %d %d %d %d %d\n", byteCount(c), sixtyFour(big), assigned, multiB, viaSlice(big), pkgVal)
67 }
68