cue icon indicating copy to clipboard operation
cue copied to clipboard

cue: support producing CUE_STATS_FILE via the Go API

Open verdverm opened this issue 11 months ago • 2 comments

Is your feature request related to a problem? Please describe.

CUE_STATS_FILE can be set be end users of the CLI to get helpful info about how their code runs in the evaluator. Users of the SDK cannot make use of this (accurately) because some of the stats API requires access to internal packages

https://github.com/cue-lang/cue/blob/901604a413b7a00bdd25d00049c46bfc9ebd8385/cmd/cue/cmd/root.go#L118

Describe the solution you'd like

CUE_STATS_FILE to work via the SDK

Describe alternatives you've considered

It doesn't seem possible to access stats directly because much of it requires access to the adt package

Additional context

hof user asked why this doesn't work with hof

verdverm avatar Dec 28 '24 04:12 verdverm

I've brought up the same to Marcel in the past, this would indeed be nice to have. We just have to be careful to clearly document that the structure of the stats is unstable and may change with future CUE versions. We could make the struct fully opaque to hide the fields from the user entirely, or use a map[string]any, although that also makes using the stats directly in Go rather annoying. I'd be fine with exposing a plain struct with exported fields as long as the documentation is clear.

mvdan avatar Dec 31 '24 09:12 mvdan

Also to add a bit of clarification: this needs some design to decide if the stats should be collected...

  1. globally; probably not, as that would not mesh well with concurrent or long lived programs
  2. per cue.Context from its creation; for example, via added methods on the cue.Context type
  3. per operation, like one call to Unify; however, it's unclear how that could be done in a backwards-compatible way

Currently the cmd/cue tool produces a global stats file from start to finish, which is OK because most of the work it does relates to a single CUE context. And at a high level, its commands like vet or export can be thought of as one operation. However, the Go API is way more flexible.

mvdan avatar Jul 21 '25 14:07 mvdan

For the sake of tracking this work better, let's use https://github.com/cue-lang/cue/issues/2856 going forward. I've added all relevant info there now.

mvdan avatar Dec 17 '25 08:12 mvdan