this repo has no description
0
fork

Configure Feed

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

mod/modfile,internal/mod: clean up now that #2733 is fixed

Using a cue.Value concurrently is now supported in the API.

Also remove the TODO about mixing values from different contexts;
that restriction has also been removed from the API docs.

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

+3 -21
+1 -6
internal/mod/modresolve/resolve.go
··· 173 173 174 174 var ( 175 175 configSchemaOnce sync.Once // guards the creation of _configSchema 176 - // TODO remove this mutex when https://cuelang.org/issue/2733 is fixed. 177 - configSchemaMutex sync.Mutex // guards any use of _configSchema 178 - _configSchema cue.Value 176 + _configSchema cue.Value 179 177 ) 180 178 181 179 //go:embed schema.cue ··· 208 206 } 209 207 _configSchema = schemav 210 208 }) 211 - configSchemaMutex.Lock() 212 - defer configSchemaMutex.Unlock() 213 - 214 209 v := _configSchema.Context().CompileBytes(configFile, cue.Filename(filename)) 215 210 if err := v.Err(); err != nil { 216 211 return nil, errors.Wrapf(err, token.NoPos, "invalid registry configuration file")
+2 -15
mod/modfile/modfile.go
··· 113 113 } 114 114 115 115 var ( 116 - moduleSchemaOnce sync.Once // guards the creation of _moduleSchema 117 - // TODO remove this mutex when https://cuelang.org/issue/2733 is fixed. 118 - moduleSchemaMutex sync.Mutex // guards any use of _moduleSchema 119 - _schemas schemaInfo 116 + moduleSchemaOnce sync.Once // guards the creation of _modules 117 + _schemas schemaInfo 120 118 ) 121 119 122 120 type schemaInfo struct { ··· 127 125 // moduleSchemaDo runs f with information about all the schema versions 128 126 // present in schema.cue. It does this within a mutex because it is 129 127 // not currently allowed to use cue.Value concurrently. 130 - // TODO remove the mutex when https://cuelang.org/issue/2733 is fixed. 131 128 func moduleSchemaDo[T any](f func(*schemaInfo) (T, error)) (T, error) { 132 129 moduleSchemaOnce.Do(func() { 133 130 // It is important that this cue.Context not be used for building any other cue.Value, 134 131 // such as in [Parse] or [ParseLegacy]. 135 132 // A value holds memory as long as the context it was built with is kept alive for, 136 133 // and this context is alive forever via the _schemas global. 137 - // 138 - // TODO(mvdan): this violates the documented API rules in the cue package: 139 - // 140 - // Only values created from the same Context can be involved in the same operation. 141 - // 142 - // However, this appears to work in practice, and all alternatives right now would be 143 - // either too costly or awkward. We want to lift that API restriction, and this works OK, 144 - // so leave it as-is for the time being. 145 134 ctx := cuecontext.New() 146 135 schemav := ctx.CompileString(moduleSchemaData, cue.Filename(schemaFile)) 147 136 if err := schemav.Decode(&_schemas); err != nil { 148 137 panic(fmt.Errorf("internal error: invalid CUE module.cue schema: %v", errors.Details(err, nil))) 149 138 } 150 139 }) 151 - moduleSchemaMutex.Lock() 152 - defer moduleSchemaMutex.Unlock() 153 140 return f(&_schemas) 154 141 } 155 142