1. 11 Sep, 2019 2 commits
    • Huan Du's avatar
      reflect: fix panic in DeepEqual when checking a cycle · 4dc11ae2
      Huan Du authored
      Before this change, when DeepEqual checks values with cycle, it may
      panic due to stack overflow.
      
      Here is a sample to reproduce the issue.
      
          makeCycleMap := func() interface{} {
              cycleMap := map[string]interface{}{}
              cycleMap["foo"] = cycleMap
              return cycleMap
          }
      
          m1 := makeCycleMap()
          m2 := makeCycleMap()
          reflect.DeepEqual(m1, m2) // stack overflow
      
      The root cause is that DeepEqual fails to cache interface values
      in visited map, which is used to detect cycle. DeepEqual calls
      CanAddr to check whether a value should be cached or not. However,
      all values referenced by interface don't have flagAddr thus all these
      values are not cached.
      
      THe fix is to remove CanAddr calls and use underlying ptr in value
      directly. As ptr is only read-only in DeepEqual for caching, it's
      safe to do so. We don't use UnsafeAddr this time, because this method
      panics when CanAddr returns false.
      
      Fixes #33907
      
      Change-Id: I2aa88cc060a2c2192b1d34c129c0aad4bd5597e7
      Reviewed-on: https://go-review.googlesource.com/c/go/+/191940
      Run-TryBot: Ian Lance Taylor <iant@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      4dc11ae2
    • Marko Kungla's avatar
      reflect: enhance docs for IsZero and IsValid · a5026af5
      Marko Kungla authored
      Make it clear that IsValid checks that we have valid
      reflect.Value and not the value of `v`
      
      fixes #34152
      
      Change-Id: Ib3d359eeb3a82bf733b9ed17c777fc4c143bc29c
      Reviewed-on: https://go-review.googlesource.com/c/go/+/193841Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      a5026af5
  2. 10 Sep, 2019 13 commits
  3. 09 Sep, 2019 10 commits
  4. 08 Sep, 2019 2 commits
  5. 07 Sep, 2019 7 commits
  6. 06 Sep, 2019 6 commits
    • Matthew Dempsky's avatar
      cmd/compile: rewrite untyped constant conversion logic · 581526ce
      Matthew Dempsky authored
      This CL detangles the hairy mess that was convlit+defaultlit. In
      particular, it makes the following changes:
      
      1. convlit1 now follows the standard typecheck behavior of setting
      "n.Type = nil" if there's an error. Notably, this means for a lot of
      test cases, we now avoid reporting useless follow-on error messages.
      For example, after reporting that "1 << s + 1.0" has an invalid shift,
      we no longer also report that it can't be assigned to string.
      
      2. Previously, assignconvfn had some extra logic for trying to
      suppress errors from convlit/defaultlit so that it could provide its
      own errors with better context information. Instead, this extra
      context information is now passed down into convlit1 directly.
      
      3. Relatedly, this CL also removes redundant calls to defaultlit prior
      to assignconv. As a consequence, when an expression doesn't make sense
      for a particular assignment (e.g., assigning an untyped string to an
      integer), the error messages now say "untyped string" instead of just
      "string". This is more consistent with go/types behavior.
      
      4. defaultlit2 is now smarter about only trying to convert pairs of
      untyped constants when it's likely to succeed. This allows us to
      report better error messages for things like 3+"x"; instead of "cannot
      convert 3 to string" we now report "mismatched types untyped number
      and untyped string".
      
      Passes toolstash-check.
      
      Change-Id: I26822a02dc35855bd0ac774907b1cf5737e91882
      Reviewed-on: https://go-review.googlesource.com/c/go/+/187657
      Run-TryBot: Matthew Dempsky <mdempsky@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
      581526ce
    • Matthew Dempsky's avatar
      cmd/compile: use CTNIL for pointer-typed OLITERALs · ad1f2c96
      Matthew Dempsky authored
      We used to be more aggressive about constant folding in the frontend,
      handling expressions that the Go spec does not consider constant;
      e.g., "(*int)(unsafe.Pointer(uintptr(200)))". However, that led to a
      lot of subtle Go spec conformance issues, so we've since abandoned
      that effort (CL 151320), leaving SSA to handle these cases instead.
      
      As such, the only time we now end up with pointer-typed OLITERALs is
      when "nil" is implicitly converted to a pointer-typed variable.
      Instead of representing these OLITERALs with an CTINT of 0, we can
      just use CTNIL.
      
      Saves a few bytes of memory and lines of code.
      
      Change-Id: Ibc5c756b992fdc89c3bdaf4fda3aa352e8e2b101
      Reviewed-on: https://go-review.googlesource.com/c/go/+/193437
      Run-TryBot: Matthew Dempsky <mdempsky@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
      ad1f2c96
    • Matthew Dempsky's avatar
      Revert "cmd/compile: improve errors for invalid conversions of consts" · e6ba19f9
      Matthew Dempsky authored
      This reverts commit 2da9c3e0.
      
      Reason for revert: while the new error messages are more informative,
      they're not strictly correct. This CL also conflicts with CL 187657.
      
      Change-Id: I1c36cf7e86c2f35ee83a4f98918ee38aa1f59965
      Reviewed-on: https://go-review.googlesource.com/c/go/+/193977
      Run-TryBot: Matthew Dempsky <mdempsky@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
      e6ba19f9
    • Mihai Borobocea's avatar
      text/template: refer to sorted map keys as "ordered" not "comparable" in docs · 8a8cf5bf
      Mihai Borobocea authored
      Consistent with the spec's definition of "ordered" and "comparable".
      
      Fixes #34147
      
      Change-Id: Id13186df5343588d80eaebfeb23092596a846d51
      Reviewed-on: https://go-review.googlesource.com/c/go/+/193840Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      Reviewed-by: default avatarRob Pike <r@golang.org>
      8a8cf5bf
    • Matthew Dempsky's avatar
      cmd/compile: rename Etype to ctxType · 5e43856a
      Matthew Dempsky authored
      golang.org/cl/150140 renamed the other Efoo constants to ctxFoo, but
      forgot about Etype.
      
      gorename -from '"cmd/compile/internal/gc".Etype -to ctxType
      
      Change-Id: I142dd42ca84a398f8d2316d75ead3331c023b820
      Reviewed-on: https://go-review.googlesource.com/c/go/+/193958
      Run-TryBot: Matthew Dempsky <mdempsky@google.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
      5e43856a
    • K. "pestophagous" Heller's avatar
      cmd/compile: improve errors for invalid conversions of consts · 2da9c3e0
      K. "pestophagous" Heller authored
      Follow-up to Change-Id: If6e52c59eab438599d641ecf6f110ebafca740a9
      
      This addresses the remaining tech debt on issue 21979.
      
      The aforementioned previous CL silenced one of two mostly redundant
      compiler errors. However, the silenced error was the more expressive
      error. This CL now imbues the surviving error with the same level
      of expressiveness as the old semi-redundant error.
      
      Fixes #21979
      
      Change-Id: I3273d48c88bbab073fabe53421d801df621ce321
      Reviewed-on: https://go-review.googlesource.com/c/go/+/191079
      Run-TryBot: Robert Griesemer <gri@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
      2da9c3e0