checked.proto 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. // Copyright 2022 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.api.expr.v1alpha1;
  16. import "google/api/expr/v1alpha1/syntax.proto";
  17. import "google/protobuf/empty.proto";
  18. import "google/protobuf/struct.proto";
  19. option cc_enable_arenas = true;
  20. option go_package = "google.golang.org/genproto/googleapis/api/expr/v1alpha1;expr";
  21. option java_multiple_files = true;
  22. option java_outer_classname = "DeclProto";
  23. option java_package = "com.google.api.expr.v1alpha1";
  24. // Protos for representing CEL declarations and typed checked expressions.
  25. // A CEL expression which has been successfully type checked.
  26. message CheckedExpr {
  27. // A map from expression ids to resolved references.
  28. //
  29. // The following entries are in this table:
  30. //
  31. // - An Ident or Select expression is represented here if it resolves to a
  32. // declaration. For instance, if `a.b.c` is represented by
  33. // `select(select(id(a), b), c)`, and `a.b` resolves to a declaration,
  34. // while `c` is a field selection, then the reference is attached to the
  35. // nested select expression (but not to the id or or the outer select).
  36. // In turn, if `a` resolves to a declaration and `b.c` are field selections,
  37. // the reference is attached to the ident expression.
  38. // - Every Call expression has an entry here, identifying the function being
  39. // called.
  40. // - Every CreateStruct expression for a message has an entry, identifying
  41. // the message.
  42. map<int64, Reference> reference_map = 2;
  43. // A map from expression ids to types.
  44. //
  45. // Every expression node which has a type different than DYN has a mapping
  46. // here. If an expression has type DYN, it is omitted from this map to save
  47. // space.
  48. map<int64, Type> type_map = 3;
  49. // The source info derived from input that generated the parsed `expr` and
  50. // any optimizations made during the type-checking pass.
  51. SourceInfo source_info = 5;
  52. // The expr version indicates the major / minor version number of the `expr`
  53. // representation.
  54. //
  55. // The most common reason for a version change will be to indicate to the CEL
  56. // runtimes that transformations have been performed on the expr during static
  57. // analysis. In some cases, this will save the runtime the work of applying
  58. // the same or similar transformations prior to evaluation.
  59. string expr_version = 6;
  60. // The checked expression. Semantically equivalent to the parsed `expr`, but
  61. // may have structural differences.
  62. Expr expr = 4;
  63. }
  64. // Represents a CEL type.
  65. message Type {
  66. // List type with typed elements, e.g. `list<example.proto.MyMessage>`.
  67. message ListType {
  68. // The element type.
  69. Type elem_type = 1;
  70. }
  71. // Map type with parameterized key and value types, e.g. `map<string, int>`.
  72. message MapType {
  73. // The type of the key.
  74. Type key_type = 1;
  75. // The type of the value.
  76. Type value_type = 2;
  77. }
  78. // Function type with result and arg types.
  79. message FunctionType {
  80. // Result type of the function.
  81. Type result_type = 1;
  82. // Argument types of the function.
  83. repeated Type arg_types = 2;
  84. }
  85. // Application defined abstract type.
  86. message AbstractType {
  87. // The fully qualified name of this abstract type.
  88. string name = 1;
  89. // Parameter types for this abstract type.
  90. repeated Type parameter_types = 2;
  91. }
  92. // CEL primitive types.
  93. enum PrimitiveType {
  94. // Unspecified type.
  95. PRIMITIVE_TYPE_UNSPECIFIED = 0;
  96. // Boolean type.
  97. BOOL = 1;
  98. // Int64 type.
  99. //
  100. // Proto-based integer values are widened to int64.
  101. INT64 = 2;
  102. // Uint64 type.
  103. //
  104. // Proto-based unsigned integer values are widened to uint64.
  105. UINT64 = 3;
  106. // Double type.
  107. //
  108. // Proto-based float values are widened to double values.
  109. DOUBLE = 4;
  110. // String type.
  111. STRING = 5;
  112. // Bytes type.
  113. BYTES = 6;
  114. }
  115. // Well-known protobuf types treated with first-class support in CEL.
  116. enum WellKnownType {
  117. // Unspecified type.
  118. WELL_KNOWN_TYPE_UNSPECIFIED = 0;
  119. // Well-known protobuf.Any type.
  120. //
  121. // Any types are a polymorphic message type. During type-checking they are
  122. // treated like `DYN` types, but at runtime they are resolved to a specific
  123. // message type specified at evaluation time.
  124. ANY = 1;
  125. // Well-known protobuf.Timestamp type, internally referenced as `timestamp`.
  126. TIMESTAMP = 2;
  127. // Well-known protobuf.Duration type, internally referenced as `duration`.
  128. DURATION = 3;
  129. }
  130. // The kind of type.
  131. oneof type_kind {
  132. // Dynamic type.
  133. google.protobuf.Empty dyn = 1;
  134. // Null value.
  135. google.protobuf.NullValue null = 2;
  136. // Primitive types: `true`, `1u`, `-2.0`, `'string'`, `b'bytes'`.
  137. PrimitiveType primitive = 3;
  138. // Wrapper of a primitive type, e.g. `google.protobuf.Int64Value`.
  139. PrimitiveType wrapper = 4;
  140. // Well-known protobuf type such as `google.protobuf.Timestamp`.
  141. WellKnownType well_known = 5;
  142. // Parameterized list with elements of `list_type`, e.g. `list<timestamp>`.
  143. ListType list_type = 6;
  144. // Parameterized map with typed keys and values.
  145. MapType map_type = 7;
  146. // Function type.
  147. FunctionType function = 8;
  148. // Protocol buffer message type.
  149. //
  150. // The `message_type` string specifies the qualified message type name. For
  151. // example, `google.plus.Profile`.
  152. string message_type = 9;
  153. // Type param type.
  154. //
  155. // The `type_param` string specifies the type parameter name, e.g. `list<E>`
  156. // would be a `list_type` whose element type was a `type_param` type
  157. // named `E`.
  158. string type_param = 10;
  159. // Type type.
  160. //
  161. // The `type` value specifies the target type. e.g. int is type with a
  162. // target type of `Primitive.INT`.
  163. Type type = 11;
  164. // Error type.
  165. //
  166. // During type-checking if an expression is an error, its type is propagated
  167. // as the `ERROR` type. This permits the type-checker to discover other
  168. // errors present in the expression.
  169. google.protobuf.Empty error = 12;
  170. // Abstract, application defined type.
  171. AbstractType abstract_type = 14;
  172. }
  173. }
  174. // Represents a declaration of a named value or function.
  175. //
  176. // A declaration is part of the contract between the expression, the agent
  177. // evaluating that expression, and the caller requesting evaluation.
  178. message Decl {
  179. // Identifier declaration which specifies its type and optional `Expr` value.
  180. //
  181. // An identifier without a value is a declaration that must be provided at
  182. // evaluation time. An identifier with a value should resolve to a constant,
  183. // but may be used in conjunction with other identifiers bound at evaluation
  184. // time.
  185. message IdentDecl {
  186. // Required. The type of the identifier.
  187. Type type = 1;
  188. // The constant value of the identifier. If not specified, the identifier
  189. // must be supplied at evaluation time.
  190. Constant value = 2;
  191. // Documentation string for the identifier.
  192. string doc = 3;
  193. }
  194. // Function declaration specifies one or more overloads which indicate the
  195. // function's parameter types and return type.
  196. //
  197. // Functions have no observable side-effects (there may be side-effects like
  198. // logging which are not observable from CEL).
  199. message FunctionDecl {
  200. // An overload indicates a function's parameter types and return type, and
  201. // may optionally include a function body described in terms of
  202. // [Expr][google.api.expr.v1alpha1.Expr] values.
  203. //
  204. // Functions overloads are declared in either a function or method
  205. // call-style. For methods, the `params[0]` is the expected type of the
  206. // target receiver.
  207. //
  208. // Overloads must have non-overlapping argument types after erasure of all
  209. // parameterized type variables (similar as type erasure in Java).
  210. message Overload {
  211. // Required. Globally unique overload name of the function which reflects
  212. // the function name and argument types.
  213. //
  214. // This will be used by a [Reference][google.api.expr.v1alpha1.Reference]
  215. // to indicate the `overload_id` that was resolved for the function
  216. // `name`.
  217. string overload_id = 1;
  218. // List of function parameter [Type][google.api.expr.v1alpha1.Type]
  219. // values.
  220. //
  221. // Param types are disjoint after generic type parameters have been
  222. // replaced with the type `DYN`. Since the `DYN` type is compatible with
  223. // any other type, this means that if `A` is a type parameter, the
  224. // function types `int<A>` and `int<int>` are not disjoint. Likewise,
  225. // `map<string, string>` is not disjoint from `map<K, V>`.
  226. //
  227. // When the `result_type` of a function is a generic type param, the
  228. // type param name also appears as the `type` of on at least one params.
  229. repeated Type params = 2;
  230. // The type param names associated with the function declaration.
  231. //
  232. // For example, `function ex<K,V>(K key, map<K, V> map) : V` would yield
  233. // the type params of `K, V`.
  234. repeated string type_params = 3;
  235. // Required. The result type of the function. For example, the operator
  236. // `string.isEmpty()` would have `result_type` of `kind: BOOL`.
  237. Type result_type = 4;
  238. // Whether the function is to be used in a method call-style `x.f(...)`
  239. // or a function call-style `f(x, ...)`.
  240. //
  241. // For methods, the first parameter declaration, `params[0]` is the
  242. // expected type of the target receiver.
  243. bool is_instance_function = 5;
  244. // Documentation string for the overload.
  245. string doc = 6;
  246. }
  247. // Required. List of function overloads, must contain at least one overload.
  248. repeated Overload overloads = 1;
  249. }
  250. // The fully qualified name of the declaration.
  251. //
  252. // Declarations are organized in containers and this represents the full path
  253. // to the declaration in its container, as in `google.api.expr.Decl`.
  254. //
  255. // Declarations used as
  256. // [FunctionDecl.Overload][google.api.expr.v1alpha1.Decl.FunctionDecl.Overload]
  257. // parameters may or may not have a name depending on whether the overload is
  258. // function declaration or a function definition containing a result
  259. // [Expr][google.api.expr.v1alpha1.Expr].
  260. string name = 1;
  261. // Required. The declaration kind.
  262. oneof decl_kind {
  263. // Identifier declaration.
  264. IdentDecl ident = 2;
  265. // Function declaration.
  266. FunctionDecl function = 3;
  267. }
  268. }
  269. // Describes a resolved reference to a declaration.
  270. message Reference {
  271. // The fully qualified name of the declaration.
  272. string name = 1;
  273. // For references to functions, this is a list of `Overload.overload_id`
  274. // values which match according to typing rules.
  275. //
  276. // If the list has more than one element, overload resolution among the
  277. // presented candidates must happen at runtime because of dynamic types. The
  278. // type checker attempts to narrow down this list as much as possible.
  279. //
  280. // Empty if this is not a reference to a
  281. // [Decl.FunctionDecl][google.api.expr.v1alpha1.Decl.FunctionDecl].
  282. repeated string overload_id = 3;
  283. // For references to constants, this may contain the value of the
  284. // constant if known at compile time.
  285. Constant value = 4;
  286. }