all: adjustments package to work with new evaluator

encoding/openapi:
- need to use UnifyAccept
- alternative mechansim to recognize formats

encoding/protobuf:
- remove generation of close() calls.

tools/trim:
- need to use UnifyAccept
- a few more changes due to subtle differences

cue/load:
- using new internal API mostly to remove
  dependencies.

error updates:
- changes due to fixes in the evaluator
- error messages are worse for now
  (especially locations)
- Kubernets quick is now failing, but this is due
  to cue correctly catching errors.

Change-Id: I24efdd5eedcf6cd48bae4a6207f96afbdd895c5f
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6658
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/encoding/openapi/types.go b/encoding/openapi/types.go
index b86c3ac..a216a08 100644
--- a/encoding/openapi/types.go
+++ b/encoding/openapi/types.go
@@ -21,7 +21,6 @@
 	"github.com/cockroachdb/apd/v2"
 
 	"cuelang.org/go/cue/ast"
-	"cuelang.org/go/cue/format"
 	"cuelang.org/go/cue/literal"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/internal/legacy/cue"
@@ -45,6 +44,11 @@
 	`time.Format ("2006-01-02T15:04:05.999999999Z07:00")`: "date-time",
 
 	// TODO:  password.
+
+	">=-2147483648 & <=2147483647 & int":                                                                   "int32",
+	">=-9223372036854775808 & <=9223372036854775807 & int":                                                 "int64",
+	">=-340282346638528859811704183484516925440 & <=340282346638528859811704183484516925440":               "float",
+	">=-1.797693134862315708145274237317043567981e+308 & <=1.797693134862315708145274237317043567981e+308": "double",
 }
 
 func extractFormat(v cue.Value) string {
@@ -65,12 +69,8 @@
 		expr = inst.ImportPath + "." + strings.Join(ref, ".")
 		expr += arg
 	} else {
-		// TODO: have some function to extract normalized builtin types.
-		b, err := format.Node(v.Syntax(cue.Final()))
-		if err != nil {
-			return ""
-		}
-		expr = string(b)
+		expr = fmt.Sprint(v.Eval())
+		expr += arg
 	}
 	if s, ok := cueToOpenAPI[expr]; ok {
 		return s