| 252 | } // namespace |
| 253 | |
| 254 | ProgramOptimizerFactory CreateConstantFoldingOptimizer( |
| 255 | absl_nullable std::shared_ptr<google::protobuf::Arena> arena, |
| 256 | absl_nullable std::shared_ptr<google::protobuf::MessageFactory> message_factory) { |
| 257 | return |
| 258 | [shared_arena = std::move(arena), |
| 259 | shared_message_factory = std::move(message_factory)]( |
| 260 | PlannerContext& context, |
| 261 | const Ast&) -> absl::StatusOr<std::unique_ptr<ProgramOptimizer>> { |
| 262 | // If one was explicitly provided during planning or none was explicitly |
| 263 | // provided during configuration, request one from the planning context. |
| 264 | // Otherwise use the one provided during configuration. |
| 265 | google::protobuf::Arena* absl_nonnull arena = |
| 266 | context.HasExplicitArena() || shared_arena == nullptr |
| 267 | ? context.MutableArena() |
| 268 | : shared_arena.get(); |
| 269 | google::protobuf::MessageFactory* absl_nonnull message_factory = |
| 270 | context.HasExplicitMessageFactory() || |
| 271 | shared_message_factory == nullptr |
| 272 | ? context.MutableMessageFactory() |
| 273 | : shared_message_factory.get(); |
| 274 | return std::make_unique<ConstantFoldingExtension>( |
| 275 | context.descriptor_pool(), shared_arena, arena, |
| 276 | shared_message_factory, message_factory, context.type_reflector()); |
| 277 | }; |
| 278 | } |
| 279 | |
| 280 | } // namespace cel::runtime_internal |