1. 18 Sep, 2019 6 commits
    • Matthew Dempsky's avatar
      cmd/compile: optimize switch on strings · 85fc7653
      Matthew Dempsky authored
      When compiling expression switches, we try to optimize runs of
      constants into binary searches. The ordering used isn't visible to the
      application, so it's unimportant as long as we're consistent between
      sorting and searching.
      
      For strings, it's much cheaper to compare string lengths than strings
      themselves, so instead of ordering strings by "si <= sj", we currently
      order them by "len(si) < len(sj) || len(si) == len(sj) && si <= sj"
      (i.e., the lexicographical ordering on the 2-tuple (len(s), s)).
      
      However, it's also somewhat cheaper to compare strings for equality
      (i.e., ==) than for ordering (i.e., <=). And if there were two or
      three string constants of the same length in a switch statement, we
      might unnecessarily emit ordering comparisons.
      
      For example, given:
      
          switch s {
          case "", "1", "2", "3": // ordered by length then content
              goto L
          }
      
      we currently compile this as:
      
          if len(s) < 1 || len(s) == 1 && s <= "1" {
              if s == "" { goto L }
              else if s == "1" { goto L }
          } else {
              if s == "2" { goto L }
              else if s == "3" { goto L }
          }
      
      This CL switches to using a 2-level binary search---first on len(s),
      then on s itself---so that string ordering comparisons are only needed
      when there are 4 or more strings of the same length. (4 being the
      cut-off for when using binary search is actually worthwhile.)
      
      So the above switch instead now compiles to:
      
          if len(s) == 0 {
              if s == "" { goto L }
          } else if len(s) == 1 {
              if s == "1" { goto L }
              else if s == "2" { goto L }
              else if s == "3" { goto L }
          }
      
      which is better optimized by walk and SSA. (Notably, because there are
      only two distinct lengths and no more than three strings of any
      particular length, this example ends up falling back to simply using
      linear search.)
      
      Test case by khr@ from CL 195138.
      
      Fixes #33934.
      
      Change-Id: I8eeebcaf7e26343223be5f443d6a97a0daf84f07
      Reviewed-on: https://go-review.googlesource.com/c/go/+/195340
      Run-TryBot: Matthew Dempsky <mdempsky@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      Reviewed-by: default avatarKeith Randall <khr@golang.org>
      85fc7653
    • Robert Griesemer's avatar
      math/big: avoid MinExp exponent wrap-around in 'x' Text format · 770fac45
      Robert Griesemer authored
      Fixes #34343.
      
      Change-Id: I74240c8f431f6596338633a86a7a5ee1fce70a65
      Reviewed-on: https://go-review.googlesource.com/c/go/+/196057
      Run-TryBot: Robert Griesemer <gri@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      770fac45
    • Robert Griesemer's avatar
      go/parser: return partial result from ParseExpr in case of error · 99aa56a4
      Robert Griesemer authored
      Remove redundant code and improve documentation in the process.
      
      Fixes #34211.
      
      Change-Id: I9a6d1467f1a2c98a163f41f9df147fc6500c6fad
      Reviewed-on: https://go-review.googlesource.com/c/go/+/196077Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      99aa56a4
    • Matthew Dempsky's avatar
      cmd/compile: remove toolstash bandage · d55cf5b8
      Matthew Dempsky authored
      Change-Id: Ic33dfccf06681470bec19f66653fda67d9901095
      Reviewed-on: https://go-review.googlesource.com/c/go/+/196118Reviewed-by: default avatarKeith Randall <khr@golang.org>
      d55cf5b8
    • Matthew Dempsky's avatar
      cmd/compile: remove OCASE and rename OXCASE to OCASE · 2fc6366f
      Matthew Dempsky authored
      We used to use OXCASE to represent general, possibly multi-valued
      cases, and then desugar these during walk into single-value cases
      represented by OCASE.
      
      In CL 194660, we switched to eliminated the desugaring step and
      instead handle the multi-valued cases directly, which eliminates the
      need for an OCASE Op. Instead, we can simply remove OCASE, and rename
      OXCASE to just OCASE.
      
      Passes toolstash-check.
      
      Change-Id: I3cc184340f9081d37453927cca1c059267fdbc12
      Reviewed-on: https://go-review.googlesource.com/c/go/+/196117Reviewed-by: default avatarKeith Randall <khr@golang.org>
      2fc6366f
    • Matthew Dempsky's avatar
      cmd/compile: tweak OIF construction for binarySearch · 1b2c7948
      Matthew Dempsky authored
      When emitting base cases, previously we would emit:
      
          if c1 { s1 }
          if c2 { s2 }
          if c3 { s3 }
      
      With this CL, we instead emit:
      
          if c1 { s1 }
          else if c2 { s2 }
          else if c3 { s3 }
      
      Most of the time, this doesn't make a difference, because s1/s2/s3 are
      typically "goto" statements. But for type switches, we currently emit:
      
          if hash == 271 { if _, ok := iface.(T1); ok { goto t1case } }
          if hash == 314 { if _, ok := iface.(T2); ok { goto t2case } }
      
      That is, the if bodies can fallthrough, even though it's impossible
      for them to match any of the subsequent cases.
      
      Change-Id: I453d424d0b5e40060a703738bbb374523f1c403c
      Reviewed-on: https://go-review.googlesource.com/c/go/+/195339
      Run-TryBot: Matthew Dempsky <mdempsky@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarKeith Randall <khr@golang.org>
      1b2c7948
  2. 17 Sep, 2019 12 commits
  3. 16 Sep, 2019 16 commits
  4. 15 Sep, 2019 2 commits
    • Austin Clements's avatar
      misc/wasm: fix argv/envp layout · 142c002e
      Austin Clements authored
      The wasm_exec.js wrapper tries to set up the argv and envp following
      the UNIX conventions, but doesn't get it quite right, which can cause
      runtime.goenv to crash if you get unlucky.
      
      The main problem was that the envp array wasn't terminated with a nil
      pointer, so the runtime didn't know when to stop reading the array.
      This CL adds that nil pointer to the end of the envp array.
      
      The other problem was harmless, but confusing. In the UNIX convention,
      the argv array consists of argc pointers followed by a nil pointer,
      followed by the envp array. However, wasm_exec.js put the environment
      variable count between the two pointer arrays rather than a nil
      pointer. The runtime never looks at this slot, so it didn't matter,
      but the break from convention left Cherry and I trying to debug why it
      *wasn't* losing any environment variables before we realized that that
      layouts happened to be close enough to work. This CL switches to the
      UNIX convention of simply terminating the argv array with a nil
      pointer.
      
      Change-Id: Ic9a4cd9eabb5dfa599a809b960f9e579b9f1f4db
      Reviewed-on: https://go-review.googlesource.com/c/go/+/193417
      Run-TryBot: Austin Clements <austin@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
      Reviewed-by: default avatarRichard Musiol <neelance@gmail.com>
      142c002e
    • Ben Shi's avatar
      go/parser: fix ignored errors in ParseExprFrom · d12c62d1
      Ben Shi authored
      This CL fixes a bug in ParseExprFrom which makes
      error messages ignored when there are 10+ errors
      in a single expression.
      
      fixes #34241
      fixes #34274
      
      Change-Id: I29a82d3e3e726279005eb6fbcd7ee3aebffaa679
      Reviewed-on: https://go-review.googlesource.com/c/go/+/194638
      Run-TryBot: Ben Shi <powerman1st@163.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
      d12c62d1
  5. 14 Sep, 2019 1 commit
  6. 13 Sep, 2019 3 commits
    • Tim Cooper's avatar
      log: add Lmsgprefix flag · 8cc57c0c
      Tim Cooper authored
      The Lmsgprefix flag moves the logger's prefix from the
      beginning of the line to after the log header. For example,
      a logger with the prefix "LOG " and LstdFlags would output:
      
          LOG 2009/11/10 23:00:00 entry text
      
      Adding the Lmsgprefix flag would output:
      
          2009/11/10 23:00:00 LOG entry text
      
      Fixes #32062
      
      Change-Id: I9f7c9739abeb53c424112aaeed33444eeefdfbbc
      Reviewed-on: https://go-review.googlesource.com/c/go/+/186182
      Run-TryBot: Rob Pike <r@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarRob Pike <r@golang.org>
      8cc57c0c
    • Jay Conrod's avatar
      cmd/go: fix link error for -coverpkg in GOPATH mode · 24781a1f
      Jay Conrod authored
      If a generated test main package transitively depends on a main
      package, the main package will now always be rebuilt as a library and
      will not be compiled with '-p main'.
      
      This expands the fix for #30907, which only applied to packages with
      the BuildInfo set (main packages built in module mode). Linking
      multiple packages with BuildInfo caused link errors, but it appears
      these errors apply to some symbols in GOPATH mode.
      
      Fixes #34114
      
      Change-Id: Ic1e53437942269a950dd7e45d163707922c92edd
      Reviewed-on: https://go-review.googlesource.com/c/go/+/195279
      Run-TryBot: Jay Conrod <jayconrod@google.com>
      Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      24781a1f
    • Joel Sing's avatar
      cmd/link: simplify determineLinkMode · 79877e5f
      Joel Sing authored
      Simplify determineLinkMode by calling mustLinkExternal upfront,
      then doing a first pass for LinkModeAuto, followed by a second pass
      that determines if the link mode is valid.
      
      Change-Id: I9d7668107c159f8fe330b8c05fee035bbe9875fd
      Reviewed-on: https://go-review.googlesource.com/c/go/+/195078Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      Run-TryBot: Ian Lance Taylor <iant@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      79877e5f