this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/value: support more types and rename ConvertToContext

It is always tricky to remember how to derive the
various contexts from one another. And because this
would introduce cyclic dependencies, it is not
generally possible to add methods to the types.
Finally, exposing methods would also expose internal
types on public ones.

To make this more convenient, we allow more types
in ConvertToContext and rename it to Context,
as it is not always a conversion.

This also gets rid of Impl.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I2f39034887fcafe7267dc30223c00bad7145345c
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1208686
Reviewed-by: Matthew Sackman <matthew@cue.works>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+18 -13
+1 -1
encoding/gocode/gocodec/codec.go
··· 47 47 // 48 48 // Note: calling this with a *cue.Runtime value is deprecated. 49 49 func New[Ctx *cue.Runtime | *cue.Context](ctx Ctx, c *Config) *Codec { 50 - return &Codec{runtime: value.ConvertToContext(ctx)} 50 + return &Codec{runtime: value.Context(ctx)} 51 51 } 52 52 53 53 // ExtractType extracts a CUE value from a Go type.
-5
internal/core/adt/context.go
··· 202 202 return n.ctx.inDisjunct > 0 203 203 } 204 204 205 - // Impl is for internal use only. This will go. 206 - func (c *OpContext) Impl() Runtime { 207 - return c.Runtime 208 - } 209 - 210 205 func (c *OpContext) Pos() token.Pos { 211 206 if c.src == nil { 212 207 return token.NoPos
+16 -5
internal/value/value.go
··· 27 27 "cuelang.org/go/internal/types" 28 28 ) 29 29 30 - func ConvertToContext[Ctx *cue.Runtime | *cue.Context](ctx Ctx) *cue.Context { 31 - if ctx, ok := any(ctx).(*cue.Runtime); ok { 32 - (*runtime.Runtime)(ctx).Init() 30 + // Context returns the cue.Context of the given argument. 31 + func Context[Ctx *cue.Runtime | *cue.Context | cue.Value | *adt.OpContext](ctx Ctx) *cue.Context { 32 + switch x := any(ctx).(type) { 33 + case *cue.Runtime: 34 + (*runtime.Runtime)(x).Init() 35 + return (*cue.Context)(x) 36 + case *cue.Context: 37 + return x 38 + case cue.Value: 39 + r, _ := ToInternal(x) 40 + return (*cue.Context)(r) 41 + case *adt.OpContext: 42 + r := x.Runtime.(*runtime.Runtime) 43 + return (*cue.Context)(r) 33 44 } 34 - return (*cue.Context)(ctx) 45 + panic("unreachable") 35 46 } 36 47 37 48 func ToInternal(v cue.Value) (*runtime.Runtime, *adt.Vertex) { ··· 42 53 43 54 // Make wraps cue.MakeValue. 44 55 func Make(ctx *adt.OpContext, v adt.Value) cue.Value { 45 - return (*cue.Context)(ctx.Impl().(*runtime.Runtime)).Encode(v) 56 + return Context(ctx).Encode(v) 46 57 } 47 58 48 59 // UnifyBuiltin returns the given Value unified with the given builtin template.
+1 -2
pkg/list/list.go
··· 339 339 } 340 340 } 341 341 342 - r, _ := value.ToInternal(n) 343 - ctx := (*cue.Context)(r) 342 + ctx := value.Context(n) 344 343 345 344 if err := n.Unify(ctx.Encode(nmatch)).Err(); err != nil { 346 345 return false, pkg.ValidationError{B: &adt.Bottom{