Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addrs: Central implementation of sets and maps with UniqueKeyer address types #31238

Merged
merged 3 commits into from
Jun 16, 2022

Commits on Jun 14, 2022

  1. go.mod: Now targeting the Go 1.18 language

    This means we can now use type parameter syntax where appropriate.
    
    This commit also includes an upgrade to the golang.org/x/tools module,
    in order to get a newer version of "stringer" that supports the type
    parameters syntax.
    apparentlymart committed Jun 14, 2022
    Configuration menu
    Copy the full SHA
    73d3b7d View commit details
    Browse the repository at this point in the history
  2. addrs: Generic types for maps and sets of addresses

    The addrs.Set type previously snuck in accidentally as part of the work
    to add addrs.UniqueKey and addrs.UniqueKeyer, because without support for
    generic types the addrs.Set type was a bit of a safety hazard due to not
    being able to enforce particular address types at compile time.
    
    However, with Go 1.18 adding support for type parameters we can now turn
    addrs.Set into a generic type over any specific addrs.UniqueKeyer type,
    and complement it with an addrs.Map type which supports addrs.UniqueKeyer
    keys as a way to encapsulate the handling of maps with UniqueKey keys that
    we currently do inline in various other parts of Terraform.
    
    This doesn't yet introduce any callers of these types, but we'll convert
    existing users of addrs.UniqueKeyer gradually in subsequent commits.
    apparentlymart committed Jun 14, 2022
    Configuration menu
    Copy the full SHA
    b60c19d View commit details
    Browse the repository at this point in the history

Commits on Jun 15, 2022

  1. refactoring: Use addrs.Map for maps with addresses as keys

    We introduced the addrs.UniqueKey and addrs.UniqueKeyer mechanics as part
    of implementing the ValidateMoves and ApplyMoves functions, as a way to
    better encapsulate the solution to the problem that lots of our address
    types aren't comparable and so cannot be used directly as map keys.
    
    However, exposing addrs.UniqueKey handling directly in the logic adds
    various noise to the algorithms and, in particular, obscures the fact that
    MoveResults.Changes and MoveResult.Blocked both have different map key
    types.
    
    Here then we'll use the new addrs.Map helper type, which encapsulates the
    idea of a map from an addrs.UniqueKeyer type to an arbitrary value type,
    using the unique keys as the map keys internally. This does unfortunately
    mean that we lose the conventional Go map access syntax and have to use
    a method-based API instead, but I (subjectively) think that's an okay
    compromise in return for avoiding the need to keep track inline of which
    addrs.UniqueKey values correspond with which real addresses.
    
    This is intended as an entirely-mechanical change, with equivalent
    behavior to what it replaced. If anything here is doing something
    materially different than what it replaced then that's a mistake.
    apparentlymart committed Jun 15, 2022
    Configuration menu
    Copy the full SHA
    d6475f5 View commit details
    Browse the repository at this point in the history