Skip to content

Commit

Permalink
Remove all of the encoding/gob support code
Browse files Browse the repository at this point in the history
I originally introduced all of this here as a concession to trying to
HashiCorp trying to get cty values to round-trip through the various
very magical gob-based wire interfaces in Terraform v0.11 and earlier,
back when they thought cty and what became "HCL 2" would just be a drop-in
replacement for HCL 1 and the various different competing representations
of dynamic values.

However, in practice none of that ever actually worked out and instead
Terraform now natively uses cty JSON/msgpack and other such mechanisms for
its wire protocols, making this gob handling code redundant.

This stuff caused various maintenance headaches and panic bugs which make
them a burden to retain. Although this is technically a breaking change
to the public cty API, in practice this stuff was only here to allow
Terraform to use it _indirectly_ as a side-effect of passing values into
the encoding/gob package, and so I'm treating it as if it had been an
internal implementation detail even though in principle it could've been
depended on externally. If anyone was doing that, I'm sorry; I suggest
copying the relevant support code into your own package instead if you
wish to continue using cty with gob.
  • Loading branch information
apparentlymart committed Jun 3, 2022
1 parent 65ead44 commit 97bafac
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 423 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 1.10.1 (Unreleased)
# 1.11.0 (Unreleased)

## Upgrade Notes

This release contains some changes to some aspects of the API that are either legacy or de-facto internal (from before the Go toolchain had an explicit idea of that). Any external module using these will experience these as breaking changes, but we know of no such caller and so are admitting these without a major release in the interests of not creating churn for users of the main API.

* **`encoding/gob` support utilities removed**: we added these as a concession to HashiCorp who wanted to try to send `cty` values over some legacy protocols/formats used by legacy versions of HashiCorp Terraform. In the end those efforts were not successful for other reasons and so no Terraform release ever relied on this functionality.

`encoding/gob` support has been burdensome due to how its unmarshaler interface is defined and so `cty` values and types are no longer automatically compatible with `encoding/gob`. Callers should instead use explicitly-implemented encodings, such as the built-in JSON and msgpack encodings or external libraries which use the public `cty` API to encode and decode.

# 1.10.0 (November 2, 2021)

Expand Down
204 changes: 0 additions & 204 deletions cty/gob.go

This file was deleted.

69 changes: 0 additions & 69 deletions cty/gob_test.go

This file was deleted.

76 changes: 0 additions & 76 deletions cty/set/gob.go

This file was deleted.

17 changes: 1 addition & 16 deletions cty/set_internals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,6 @@ func TestSetHashBytes(t *testing.T) {
"12",
nil,
},
{
// This weird case is an intentionally-invalid number value that
// mimics the incorrect result of a gob round-trip of a cty.Number
// value. For more information, see the function
// gobDecodeFixNumberPtr. Unfortunately the set internals need to
// be tolerant of this situation because gob-decoding a set
// causes this situation to arise before we have had an opportunity
// to run gobDecodeFixNumberPtr yet.
Value{
ty: Number,
v: *big.NewFloat(13),
},
"13",
nil,
},
{
StringVal(""),
`""`,
Expand Down Expand Up @@ -178,7 +163,7 @@ func TestSetHashBytes(t *testing.T) {
}

for _, test := range tests {
t.Run(gobDecodeFixNumberPtrVal(test.value).GoString(), func(t *testing.T) {
t.Run(test.value.GoString(), func(t *testing.T) {
gotRaw, gotMarks := makeSetHashBytes(test.value)
got := string(gotRaw)
if got != test.want {
Expand Down
Loading

0 comments on commit 97bafac

Please sign in to comment.