govendor fetch github.com/hashicorp/hcl2/...

This includes a number of upstream fixes, but in particular fixes a race
on evaluating the same splat expression concurrently for multiple separate
EvalContexts.
This commit is contained in:
Martin Atkins 2018-05-23 17:01:24 -07:00
parent d236a9e4cd
commit d9a26bae26
3 changed files with 47 additions and 26 deletions

View File

@ -2,6 +2,7 @@ package hclsyntax
import (
"fmt"
"sync"
"github.com/hashicorp/hcl2/hcl"
"github.com/zclconf/go-cty/cty"
@ -1169,7 +1170,7 @@ func (e *SplatExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
// both to tuples/lists and to other values, and in the latter case
// the value will be treated as an implicit single-value list. We'll
// deal with that here first.
if !(sourceVal.Type().IsTupleType() || sourceVal.Type().IsListType()) {
if !(sourceVal.Type().IsTupleType() || sourceVal.Type().IsListType() || sourceVal.Type().IsSetType()) {
sourceVal = cty.ListVal([]cty.Value{sourceVal})
}
@ -1226,13 +1227,24 @@ func (e *SplatExpr) StartRange() hcl.Range {
// assigns it a value.
type AnonSymbolExpr struct {
SrcRange hcl.Range
values map[*hcl.EvalContext]cty.Value
// values and its associated lock are used to isolate concurrent
// evaluations of a symbol from one another. It is the calling application's
// responsibility to ensure that the same splat expression is not evalauted
// concurrently within the _same_ EvalContext, but it is fine and safe to
// do cuncurrent evaluations with distinct EvalContexts.
values map[*hcl.EvalContext]cty.Value
valuesLock sync.RWMutex
}
func (e *AnonSymbolExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
if ctx == nil {
return cty.DynamicVal, nil
}
e.valuesLock.RLock()
defer e.valuesLock.RUnlock()
val, exists := e.values[ctx]
if !exists {
return cty.DynamicVal, nil
@ -1243,6 +1255,9 @@ func (e *AnonSymbolExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics
// setValue sets a temporary local value for the expression when evaluated
// in the given context, which must be non-nil.
func (e *AnonSymbolExpr) setValue(ctx *hcl.EvalContext, val cty.Value) {
e.valuesLock.Lock()
defer e.valuesLock.Unlock()
if e.values == nil {
e.values = make(map[*hcl.EvalContext]cty.Value)
}
@ -1253,6 +1268,9 @@ func (e *AnonSymbolExpr) setValue(ctx *hcl.EvalContext, val cty.Value) {
}
func (e *AnonSymbolExpr) clearValue(ctx *hcl.EvalContext) {
e.valuesLock.Lock()
defer e.valuesLock.Unlock()
if e.values == nil {
return
}

View File

@ -243,6 +243,9 @@ func spaceAfterToken(subject, before, after *Token) bool {
// No extra spaces within templates
return false
case after.Type == hclsyntax.TokenOBrack && (subject.Type == hclsyntax.TokenIdent || subject.Type == hclsyntax.TokenNumberLit || tokenBracketChange(subject) < 0):
return false
case subject.Type == hclsyntax.TokenMinus:
// Since a minus can either be subtraction or negation, and the latter
// should _not_ have a space after it, we need to use some heuristics

48
vendor/vendor.json vendored
View File

@ -1891,68 +1891,68 @@
{
"checksumSHA1": "dJPromzLdd492RQjE/09klKRXGs=",
"path": "github.com/hashicorp/hcl2/ext/dynblock",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "IAfC0Xri1iCRgbbiDBgs6ue8/Ic=",
"path": "github.com/hashicorp/hcl2/ext/typeexpr",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "BRJaQcKriVKEirVC7YxBxPufQF0=",
"path": "github.com/hashicorp/hcl2/gohcl",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "v1JCFNvhLqF3ErYcxkJJPboKO8c=",
"path": "github.com/hashicorp/hcl2/hcl",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "ekhg+MJLLGkJQdh/tZ4A3EZwpNY=",
"checksumSHA1": "6H/LBmIYL/dNjKvlbB2hAsxm2rw=",
"path": "github.com/hashicorp/hcl2/hcl/hclsyntax",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "G40fCmu1bSWXv4Hw5JXwEUTVThk=",
"path": "github.com/hashicorp/hcl2/hcl/json",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "c3Lb2st15sopmoLrjLQp+XyaZjE=",
"path": "github.com/hashicorp/hcl2/hcldec",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "sySYF9Ew71VS/LfrG+s/0jK+1VQ=",
"path": "github.com/hashicorp/hcl2/hcled",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "IzmftuG99BqNhbFGhxZaGwtiMtM=",
"path": "github.com/hashicorp/hcl2/hclparse",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "v5qx2XghQ+EtvFLa4a0Efjiwt9I=",
"path": "github.com/hashicorp/hcl2/hcltest",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "9UCSLRG+TEAsNKOZJUaJj/7d6r8=",
"checksumSHA1": "C82otWNczU2S3azjxsjdGH9zW+Y=",
"path": "github.com/hashicorp/hcl2/hclwrite",
"revision": "bbbd0ef30d601e5ecf89e492d0842170f144db85",
"revisionTime": "2018-05-22T22:06:42Z"
"revision": "81d22773002de532651a19acb91b4e1fe2b44cb2",
"revisionTime": "2018-05-23T23:56:29Z"
},
{
"checksumSHA1": "M09yxoBoCEtG7EcHR8aEWLzMMJc=",