| 1195 | } |
| 1196 | |
| 1197 | static std::optional<Inequality> ExtractOneFromComparison(const Expression& guarantee) { |
| 1198 | auto call = guarantee.call(); |
| 1199 | if (!call) return std::nullopt; |
| 1200 | |
| 1201 | if (auto cmp = Comparison::Get(call->function_name)) { |
| 1202 | // not_equal comparisons are not very usable as guarantees |
| 1203 | if (*cmp == Comparison::NOT_EQUAL) return std::nullopt; |
| 1204 | |
| 1205 | auto target = call->arguments[0].field_ref(); |
| 1206 | if (!target) return std::nullopt; |
| 1207 | |
| 1208 | auto bound = call->arguments[1].literal(); |
| 1209 | if (!bound) return std::nullopt; |
| 1210 | if (!bound->is_scalar()) return std::nullopt; |
| 1211 | |
| 1212 | return Inequality{*cmp, /*target=*/*target, *bound, /*nullable=*/false}; |
| 1213 | } |
| 1214 | |
| 1215 | return std::nullopt; |
| 1216 | } |
| 1217 | |
| 1218 | /// The given expression simplifies to `value` if the inequality |
| 1219 | /// target is not nullable. Otherwise, it simplifies to either a |