this repo has no description
0
fork

Configure Feed

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

internal/core/adt: remove CallContext.Args method

Remove the transitional CallContext.Args method and update all
callers to use CallContext.Value instead.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I3d481008357717e74d5b711f1fc0d380750aa1c9
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1232331
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+22 -53
-7
internal/core/adt/call.go
··· 54 54 } 55 55 } 56 56 57 - // Args return the pre-evaluated arguments. This function is only used for 58 - // transitioning and will be removed at some point. Use [CallContext.Value] 59 - // instead. 60 - func (c CallContext) Args() []Value { 61 - return c.args 62 - } 63 - 64 57 // Arg returns the nth argument expression. The value is evaluated and any 65 58 // cycle information is accumulated in the context. This allows cycles in 66 59 // arguments to be detected.
+17 -39
internal/core/compile/builtin.go
··· 88 88 Result: adt.IntKind, 89 89 Func: func(call adt.CallContext) adt.Expr { 90 90 c := call.OpContext() 91 - args := call.Args() 92 91 93 - v := args[0] 92 + v := call.Value(0) 94 93 if x, ok := v.(*adt.Vertex); ok { 95 94 switch x.BaseValue.(type) { 96 95 case nil: ··· 137 136 Result: adt.StructKind, 138 137 Func: func(call adt.CallContext) adt.Expr { 139 138 c := call.OpContext() 140 - args := call.Args() 141 - 142 - s, ok := args[0].(*adt.Vertex) 139 + s, ok := call.Value(0).(*adt.Vertex) 143 140 if !ok { 144 141 return c.NewErrf("struct argument must be concrete") 145 142 } ··· 171 168 return c.NewErrf("argument must be a struct or list literal") 172 169 } 173 170 174 - // must be literal struct 175 - args := call.Args() 176 - 177 - s, ok := args[0].(*adt.Vertex) 171 + // argument must be literal struct 172 + s, ok := call.Value(0).(*adt.Vertex) 178 173 if !ok { 179 174 return c.NewErrf("struct argument must be concrete") 180 175 } ··· 204 199 } 205 200 206 201 // must be literal struct 207 - args := call.Args() 208 202 209 203 // Note that we could have an embedded scalar here, so having a struct 210 204 // or list does not guarantee that the result is that as well. ··· 212 206 // #Def: 1 213 207 // a: __reclose({ #Def }) 214 208 // 215 - if s, ok := args[0].(*adt.Vertex); ok && s.ShouldRecursivelyClose() { 209 + arg := call.Value(0) 210 + if s, ok := arg.(*adt.Vertex); ok && s.ShouldRecursivelyClose() { 216 211 s.ClosedRecursive = true 217 212 } 218 213 219 - return args[0] 214 + return arg 220 215 }, 221 216 } 222 217 ··· 226 221 Result: adt.IntKind, 227 222 Func: func(call adt.CallContext) adt.Expr { 228 223 c := call.OpContext() 229 - args := call.Args() 230 - 231 - seq := c.RawElems(args[0]) 224 + seq := c.RawElems(call.Value(0)) 232 225 a := []adt.Value{} 233 226 for c := range seq { 234 227 a = append(a, c) ··· 247 240 NonConcrete: true, 248 241 Func: func(call adt.CallContext) adt.Expr { 249 242 c := call.OpContext() 250 - args := call.Args() 251 243 252 244 d := []adt.Disjunct{} 253 - for c := range c.RawElems(args[0]) { 245 + for c := range c.RawElems(call.Value(0)) { 254 246 d = append(d, adt.Disjunct{Val: c, Default: false}) 255 247 } 256 248 if len(d) == 0 { ··· 285 277 Result: adt.IntKind, 286 278 Func: func(call adt.CallContext) adt.Expr { 287 279 c := call.OpContext() 288 - args := call.Args() 289 - 290 280 const name = "argument to div builtin" 291 - 292 - return intDivOp(c, (*adt.OpContext).IntDiv, name, args) 281 + return intDivOp(c, (*adt.OpContext).IntDiv, name, call.Value(0), call.Value(1)) 293 282 }, 294 283 } 295 284 ··· 299 288 Result: adt.IntKind, 300 289 Func: func(call adt.CallContext) adt.Expr { 301 290 c := call.OpContext() 302 - args := call.Args() 303 291 304 292 const name = "argument to mod builtin" 305 293 306 - return intDivOp(c, (*adt.OpContext).IntMod, name, args) 294 + return intDivOp(c, (*adt.OpContext).IntMod, name, call.Value(0), call.Value(1)) 307 295 }, 308 296 } 309 297 ··· 313 301 Result: adt.IntKind, 314 302 Func: func(call adt.CallContext) adt.Expr { 315 303 c := call.OpContext() 316 - args := call.Args() 317 - 318 304 const name = "argument to quo builtin" 319 - 320 - return intDivOp(c, (*adt.OpContext).IntQuo, name, args) 305 + return intDivOp(c, (*adt.OpContext).IntQuo, name, call.Value(0), call.Value(1)) 321 306 }, 322 307 } 323 308 ··· 327 312 Result: adt.IntKind, 328 313 Func: func(call adt.CallContext) adt.Expr { 329 314 c := call.OpContext() 330 - args := call.Args() 331 - 332 315 const name = "argument to rem builtin" 333 - 334 - return intDivOp(c, (*adt.OpContext).IntRem, name, args) 316 + return intDivOp(c, (*adt.OpContext).IntRem, name, call.Value(0), call.Value(1)) 335 317 }, 336 318 } 337 319 338 320 type intFunc func(c *adt.OpContext, x, y *adt.Num) adt.Value 339 321 340 - func intDivOp(c *adt.OpContext, fn intFunc, name string, args []adt.Value) adt.Value { 341 - a := c.Num(args[0], name) 342 - b := c.Num(args[1], name) 343 - 322 + func intDivOp(c *adt.OpContext, fn intFunc, name string, av, bv adt.Value) adt.Value { 323 + a := c.Num(av, name) 324 + b := c.Num(bv, name) 344 325 if c.HasErr() { 345 326 return nil 346 327 } 347 - 348 328 return fn(c, a, b) 349 329 } 350 330 ··· 353 333 Params: []adt.Param{topParam}, 354 334 Result: adt.TopKind, 355 335 Func: func(call adt.CallContext) adt.Expr { 356 - args := call.Args() 357 - 358 336 if call.Pos().Experiment().Testing { 359 - return args[0] 337 + return call.Value(0) 360 338 } else { 361 339 return call.OpContext().NewErrf("testing experiment disabled") 362 340 }
+5 -7
internal/core/compile/validator.go
··· 31 31 NonConcrete: true, 32 32 Func: func(call adt.CallContext) adt.Expr { 33 33 c := call.OpContext() 34 - args := call.Args() 35 34 36 35 if !c.IsValidator { 37 36 return c.NewErrf("matchN is a validator and should not be used as a function") 38 37 } 39 38 40 - self := finalizeSelf(c, args[0]) 39 + self := finalizeSelf(c, call.Value(0)) 41 40 if err := bottom(c, self); err != nil { 42 41 return adt.StaticBoolFalse 43 42 } 44 43 45 44 var errs []*adt.Bottom 46 45 var count, possibleCount int64 47 - for check := range c.Elems(args[2]) { 46 + for check := range c.Elems(call.Value(2)) { 48 47 v := adt.Unify(c, self, check) 49 48 if err := adt.Validate(c, v, finalCfg); err == nil { 50 49 // TODO: is it always true that the lack of an error signifies ··· 58 57 } 59 58 } 60 59 61 - bound := args[1] 60 + bound := call.Value(1) 62 61 // TODO: consider a mode to require "all" to pass, for instance by 63 62 // supporting the value null or "all". 64 63 ··· 90 89 NonConcrete: true, 91 90 Func: func(call adt.CallContext) adt.Expr { 92 91 c := call.OpContext() 93 - args := call.Args() 94 92 95 93 if !c.IsValidator { 96 94 return c.NewErrf("matchIf is a validator and should not be used as a function") 97 95 } 98 96 99 - self := finalizeSelf(c, args[0]) 97 + self := finalizeSelf(c, call.Value(0)) 100 98 if err := bottom(c, self); err != nil { 101 99 return adt.StaticBoolFalse 102 100 } 103 - ifSchema, thenSchema, elseSchema := args[1], args[2], args[3] 101 + ifSchema, thenSchema, elseSchema := call.Value(1), call.Value(2), call.Value(3) 104 102 v := adt.Unify(c, self, ifSchema) 105 103 var chosenSchema adt.Value 106 104 if err := adt.Validate(c, v, finalCfg); err == nil {