1. 27 Aug, 2019 13 commits
    • tnclong's avatar
      text/template: avoid allocating a new common in copy · 4a4f752c
      tnclong authored
      Template.New calls t.init, which allocates several items that
      are immediately rewritten by copy, so avoid the call to New
      
      Change-Id: I16c7cb001bbcd14cf547c1a2db2734a2f8214e7e
      Reviewed-on: https://go-review.googlesource.com/c/go/+/182757
      Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarDaniel Martí <mvdan@mvdan.cc>
      4a4f752c
    • Stefan Baebler's avatar
      net/url: fail TestParseErrors test when getting an unwanted error · 32b9e568
      Stefan Baebler authored
      The TestParseErrors test function was not strict with unwanted errors
      received from url.Parse(). It was not failing in such cases, now it does.
      
      Change-Id: I18a26a68c1136f5c762989a76e04b47e33dd35f1
      GitHub-Last-Rev: c33f9842f7908f27012859e25caa79388cc2785a
      GitHub-Pull-Request: golang/go#32954
      Reviewed-on: https://go-review.googlesource.com/c/go/+/185080Reviewed-by: default avatarEmmanuel Odeke <emm.odeke@gmail.com>
      Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      32b9e568
    • Alex Brainman's avatar
      net: do not call Windows TransmitFile for large files · b963149d
      Alex Brainman authored
      TransmitFile does not allow for number of bytes that can be
      transmitted to be larger than 2147483646. See
      
      https://docs.microsoft.com/en-us/windows/win32/api/mswsock/nf-mswsock-transmitfile
      
      for details. So adjust sendFile accordingly.
      
      No test added, because this would require creating large file
      (more than 2GB file).
      
      Fixes #33193.
      
      Change-Id: I82e0cb104d112264e4ea363bb20b6d02ac30b38e
      Reviewed-on: https://go-review.googlesource.com/c/go/+/187037
      Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarEmmanuel Odeke <emm.odeke@gmail.com>
      b963149d
    • Dong-hee Na's avatar
      text/template: replace bytes.Buffer with strings.Builder · 997086b7
      Dong-hee Na authored
      After Go.1.10+ strings.Builder is known as more efficient in
      concatenating and building strings than bytes.Buffer.
      
      In this CL,
      there is a minor logic fix for getting advantage of strings.builder.
      
      name               old time/op    new time/op    delta
      DefinedTemplate-8     543ns ± 3%     512ns ± 2%   -5.73%  (p=0.000 n=8+8)
      
      name               old alloc/op   new alloc/op   delta
      DefinedTemplate-8      192B ± 0%      160B ± 0%  -16.67%  (p=0.000 n=8+8)
      
      name               old allocs/op  new allocs/op  delta
      DefinedTemplate-8      5.00 ± 0%      5.00 ± 0%     ~     (all equal)
      
      Change-Id: Icda0054d146e6c5e32ed8a4d13221bb6850d31b4
      Reviewed-on: https://go-review.googlesource.com/c/go/+/175261
      Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarEmmanuel Odeke <emm.odeke@gmail.com>
      Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      997086b7
    • Jonathan Amsterdam's avatar
      errors: document Is and As methods · fc4663d5
      Jonathan Amsterdam authored
      Add brief descriptions of why one might implement
      an Is or As method.
      
      Fixes #33364.
      
      Change-Id: I81a091bf564c654ddb9ef3997e780451a01efb7a
      Reviewed-on: https://go-review.googlesource.com/c/go/+/191338Reviewed-by: default avatarEmmanuel Odeke <emm.odeke@gmail.com>
      Reviewed-by: default avatarAndrew Bonventre <andybons@golang.org>
      Run-TryBot: Jonathan Amsterdam <jba@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      fc4663d5
    • Daniel Martí's avatar
      encoding/json: fix the broken "overwriting of data" tests · 95c3c430
      Daniel Martí authored
      Because TestUnmarshal actually allocates a new value to decode into
      using ptr's pointer type, any existing data is thrown away. This was
      harmless in alomst all of the test cases, minus the "overwriting of
      data" ones added in 2015 in CL 12209.
      
      I spotted that nothing covered decoding a JSON array with few elements
      into a slice which already had many elements. I initially assumed that
      the code was buggy or that some code could be removed, when in fact
      there simply wasn't any code covering the edge case.
      
      Move those two tests to TestPrefilled, which already served a very
      similar purpose. Remove the map case, as TestPrefilled already has
      plenty of prefilled map cases. Moreover, we no longer reset an entire
      map when decoding, as per the godoc:
      
      	To unmarshal a JSON object into a map, Unmarshal first
      	establishes a map to use. If the map is nil, Unmarshal allocates
      	a new map. Otherwise Unmarshal reuses the existing map, keeping
      	existing entries.
      
      Finally, to ensure that ptr is used correctly in the future, make
      TestUnmarshal error if it's anything other than a pointer to a zero
      value. That is, the only correct use should be new(type). Don't rename
      the ptr field, as that would be extremely noisy and cause unwanted merge
      conflicts.
      
      Change-Id: I41e3ecfeae42d877ac5443a6bd622ac3d6c8120c
      Reviewed-on: https://go-review.googlesource.com/c/go/+/185738
      Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarEmmanuel Odeke <emm.odeke@gmail.com>
      95c3c430
    • Daniel Martí's avatar
      cmd/compile: initial rulegen rewrite · 1a53915c
      Daniel Martí authored
      rulegen.go produces plaintext Go code directly, which was fine for a
      while. However, that's started being a bottleneck for making code
      generation more complex, as we can only generate code directly one line
      at a time.
      
      Some workarounds were used, like multiple layers of buffers to generate
      chunks of code, to then use strings.Contains to see whether variables
      need to be defined or not. However, that's error-prone, verbose, and
      difficult to work with.
      
      A better approach is to generate an intermediate syntax tree in memory,
      which we can inspect and modify easily. For example, we could run a
      number of "passes" on the syntax tree before writing to disk, such as
      removing unused variables, simplifying logic, or moving declarations
      closer to their uses.
      
      This is the first step in that direction, without changing any of the
      generated code. We didn't use go/ast directly, as it's too complex for
      our needs. In particular, we only need a few kinds of simple statements,
      but we do want to support arbitrary expressions. As such, define a
      simple set of statement structs, and add thin layers for printer.Fprint
      and ast.Inspect.
      
      A nice side effect of this change, besides removing some buffers and
      string handling, is that we can now avoid passing so many parameters
      around. And, while we add over a hundred lines of code, the tricky
      pieces of code are now a bit simpler to follow.
      
      While at it, apply some cleanups, such as replacing isVariable with
      token.IsIdentifier, and consistently using log.Fatalf.
      
      Follow-up CLs will start improving the generated code, also simplifying
      the rulegen code itself. I've added some TODOs for the low-hanging fruit
      that I intend to work on right after.
      
      Updates #30810.
      
      Change-Id: Ic371c192b29c85dfc4a001be7fbcbeec85facc9d
      Reviewed-on: https://go-review.googlesource.com/c/go/+/177539
      Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarKeith Randall <khr@golang.org>
      1a53915c
    • Javier Revillas's avatar
      net/http: fix a typo in comments · cd33d271
      Javier Revillas authored
      HTTP is an initialism, not an acronym, where you pronounce each letter as a
      word. It's "an H", not "a H".
      
      Running `find src/net/http -type f | xargs grep -n 'an HTTP' | wc -l` shows
      that the "an HTTP" form is used 67 times across the `net/http` package.
      Furthermore, `find src/net/http -type f | xargs grep -n 'a HTTP' | wc -l`
      yields only 4 results.
      
      Change-Id: I219c292a9e2c9bf7a009dbfe82ea8b15874685e9
      GitHub-Last-Rev: 6ebd095023af47444b6b0fc5b6d7b26d85f4c7b7
      GitHub-Pull-Request: golang/go#33810
      Reviewed-on: https://go-review.googlesource.com/c/go/+/191700Reviewed-by: default avatarToshihiro Shiino <shiino.toshihiro@gmail.com>
      Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      cd33d271
    • LE Manh Cuong's avatar
      cmd/compile: remove adjustctx from inline test · 324cf21f
      LE Manh Cuong authored
      After golang.org/cl/33895, function adjustctx can not be inlined,
      cost 82 exceeds budget 80
      
      Change-Id: Ie559ed80ea2c251add940a99f11b2983f6cbddbc
      Reviewed-on: https://go-review.googlesource.com/c/go/+/187977
      Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarKeith Randall <khr@golang.org>
      324cf21f
    • zdjones's avatar
      cmd/compile: handle sign/zero extensions in prove, via update method · 69ff0ba7
      zdjones authored
      Array accesses with index types smaller than the machine word size may
      involve a sign or zero extension of the index value before bounds
      checking. Currently, this defeats prove because the facts about the
      original index value don't flow through the sign/zero extension.
      
      This CL fixes this by looking back through value-preserving sign/zero
      extensions when adding facts via Update and, where appropriate, applying
      the same facts using the pre-extension value. This fix is enhanced by
      also looking back through value-preserving extensions within
      ft.isNonNegative to infer whether the extended value is known to be
      non-negative. Without this additional isNonNegative enhancement, this
      logic is rendered significantly less effective by the limitation
      discussed in the next paragraph.
      
      In Update, the application of facts to pre-extension values is limited
      to cases where the domain of the new fact is consistent with the type of
      the pre-extension value. There may be cases where this cross-domain
      passing of facts is valid, but distinguishing them from the invalid
      cases is difficult for me to reason about and to implement.
      Assessing which cases to allow requires details about the context and
      inferences behind the fact being applied which are not available
      within Update. Additional difficulty arises from the fact that the SSA
      does not curently differentiate extensions added by the compiler for
      indexing operations, extensions added by the compiler for implicit
      conversions, or explicit extensions from the source.
      
      Examples of some cases that would need to be filtered correctly for
      cross-domain facts:
      
      (1) A uint8 is zero-extended to int for indexing (a value-preserving
      zeroExt). When, if ever, can signed domain facts learned about the int be
      applied to the uint8?
      
      (2) An int8 is sign-extended to int16 (value-preserving) for an equality
      comparison. Equality comparison facts are currently always learned in both
      the signed and unsigned domains. When, if ever, can the unsigned facts
      learned about the int16, from the int16 != int16 comparison, be applied
      to the original int8?
      
      This is an alternative to CL 122695 and CL 174309. Compared to CL 122695,
      this CL differs in that the facts added about the pre-extension value will
      pass through the Update method, where additional inferences are processed
      (e.g. fence-post implications, see #29964). CL 174309 is limited to bounds
      checks, so is narrower in application, and makes the code harder to read.
      
      Fixes #26292.
      Fixes #29964.
      Fixes #15074
      
      Removes 238 bounds checks from std/cmd.
      
      Change-Id: I1f87c32ee672bfb8be397b27eab7a4c2f304893f
      Reviewed-on: https://go-review.googlesource.com/c/go/+/174704
      Run-TryBot: Zach Jones <zachj1@gmail.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarGiovanni Bajo <rasky@develer.com>
      69ff0ba7
    • Sergei Zagurskii's avatar
      reflect: optimize directlyAssignable to avoid rtype.Name call · 8057c088
      Sergei Zagurskii authored
      directlyAssignable invoked rtype.Name() just to compare its result
      to empty string. We really only need to check whether rtype has
      name. It can be done much cheaper, by checking tflagNamed.
      
      Benchmark: https://play.golang.org/p/V2BzESPuf2w
      name                   old time/op  new time/op  delta
      DirectlyAssignable-12  32.7ns ± 6%   6.6ns ± 6%  -79.80%  (p=0.008 n=5+5)
      
      Fixes #32186
      
      Change-Id: I1a2a167dbfddf319fba3015cb6a011bf010f99a8
      Reviewed-on: https://go-review.googlesource.com/c/go/+/178518
      Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      8057c088
    • Robert Griesemer's avatar
      cmd/compile/internal/syntax: better error recovery after missing expression · dca0d03b
      Robert Griesemer authored
      Don't skip closing parentheses of any kind after a missing
      expression. They are likely part of the lexical construct
      enclosing the expression.
      
      Fixes #33386.
      
      Change-Id: Ic0abc2037ec339a345ec357ccc724b7ad2a64c00
      Reviewed-on: https://go-review.googlesource.com/c/go/+/188502Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
      dca0d03b
    • Jason A. Donenfeld's avatar
      ld: fix up header copy and paste error · 1a423bec
      Jason A. Donenfeld authored
      Some constants were added above the initial copyright blurb, and then
      later a new copyright blurb was added on top of that. So we wound up
      with two header sections, one of which contained a useful comment that
      became obscured. This commit fixes up that mistake.
      
      Change-Id: I8b9b8c34495cdceae959e151e8ccdee3137f6ca4
      Reviewed-on: https://go-review.googlesource.com/c/go/+/191841
      Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      1a423bec
  2. 26 Aug, 2019 13 commits
  3. 25 Aug, 2019 3 commits
  4. 24 Aug, 2019 1 commit
  5. 23 Aug, 2019 4 commits
  6. 22 Aug, 2019 3 commits
  7. 21 Aug, 2019 3 commits