Files
opentf/internal/lang/grapheval/request_tracker.go
Martin Atkins 72a32f726d lang/eval: Beginnings of a different way to handle config eval
In "package tofu" today we try to do everything using a generic acyclic
graph model and generic graph walk, which _works_ but tends to make every
other part of the problem very hard to follow because we rely a lot on
sidecar shared mutable data structures to propagate results between the
isolated operations.

This is the beginning of an experimental new way to do it where the "graph"
is implied by a model that more closely represents how the language itself
works, with explicit modelling of the relationships between different
types of objects and letting results flow directly from one object to
another without any big shared mutable state.

There's still a lot to do before this is actually complete enough to
evaluate whether it's a viable new design, but I'm considering this a good
starting checkpoint since there's enough here to run a simple test of
propagating data all the way from input variables to output values via
intermediate local values.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-27 10:15:41 -07:00

46 lines
1.7 KiB
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package grapheval
import (
"iter"
"github.com/apparentlymart/go-workgraph/workgraph"
"github.com/opentofu/opentofu/internal/tfdiags"
)
// RequestTracker is implemented by types that know how to provide user-friendly
// descriptions for all active requests in a particular context for error
// reporting purposes.
//
// This is designed to allow delaying at least some of the work required to
// build user-friendly error messages about eval-request-related problems until
// an error actually occurs, because we don't need this information at all in
// the happy path.
//
// Use [ContextWithRequestTracker] to associate a request tracker with a
// [context.Context], and then pass contexts derived from that one to the
// other functions in this package that perform self-dependency and unresolved
// request detection to allow those operations to return better diagnostic
// messages when those situations occur.
type RequestTracker interface {
// ActiveRequests returns an iterable sequence of all active requests
// known to the tracker, along with the [RequestInfo] for each one.
ActiveRequests() iter.Seq2[workgraph.RequestID, RequestInfo]
}
type RequestInfo struct {
// Name is a short, user-friendly name for whatever this request was trying
// to calculate.
Name string
// SourceRange is an optional source range for something in the
// configuration that caused this request to be made. Leave this nil
// for requests that aren't clearly related to a specific element in
// the given configuration.
SourceRange *tfdiags.SourceRange
}