-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cty: Fix various quirks of handling sets with unknown values
Early in the implementation of cty I made an oversight which has, unfortunately, played out as a variety of incorrect behaviors throughout the cty functions: when a set contains unknown values, those unknown values can potentially be standing in for values that are equal to others in the set, and thus the effective length of the set can't be predicted. Previously the Length function would return, in effect, the maximum possible size of the set, which would result if all of the values represented by the unknowns are non-equal. The caller might then get a different known result from a call with unknowns than from a subsequent call with those unknowns replaced with known values, which violates the guarantees that cty intends to make when handling unknown values. This changeset therefore starts by addressing that root bug: Length will now return an unknown number if called on a set containing unknown values, correctly representing that the final length is unpredictable. This in turn had some downstream consequences for other functionality. In particular, it should not have been possible to convert a set whose length is unknown to a list, because it's not possible for a list to have an unknown length. Therefore this changeset also includes a fix to the convert package so that an unknown-length set converts to an unknown list, which also addresses the related problem that a conversion from a set to list can't predict where the unknown values will appear in the sort order and thus can't predict the list indices even for the known elements. The rest of the changes here are similar adjustments to account for the possibility of an unknown set length, in most cases similarly returning an unknown result. This changeset causes a difference in observable behavior from the previous version, but it's not considered to be a breaking change because the previous behavior was defective. With that said, callers that were inadvertently depending on the defective behavior will find that their calling application now behaves slightly differently, and so may wish to make adjustments if the defective prior behavior was actually desirable for some unusual situation. As a pragmatic accommodation for existing callers, the Value.LengthInt function is now defined as returning the maximum possible length in situations where the length is unknown. This aligns with the number of iterations a caller would encounter using an ElementIterator on such a value, and also reflects a suitable capacity to use when allocating a Go slice to append iterated elements into.
- Loading branch information
1 parent
b645bd6
commit 88189cd
Showing
12 changed files
with
328 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.