28 auto& world = type->world();
36 return world.call(
quant::star, optional_app->arg());
41 if (
auto quant_app =
Axm::isa<quant>(arg))
return world.app(callee, quant_app->arg());
53template<
class ConjOrDisj>
55 assert(!args.empty());
56 auto& world = args.front()->world();
57 return std::accumulate(args.begin() + 1, args.end(), args.front(), [&world](
const Def* lhs,
const Def* rhs) {
58 return world.call<ConjOrDisj, false>(Defs{lhs, rhs});
63 auto& world = type->world();
64 world.DLOG(
"conj {}:{} ({})", type, callee, arg);
68 case 0:
return world.lit_tt();
81 if (lhs_range && rhs_range)
return Lit::as(lhs_range->arg()->proj(0)) <
Lit::as(rhs_range->arg()->proj(0));
83 if (lhs_range)
return false;
84 if (rhs_range)
return true;
86 return lhs->
gid() < rhs->
gid();
90 std::stable_sort(args.begin(), args.end(), &
compare_re);
92 auto new_end = std::unique(args.begin(), args.end());
93 args.erase(new_end, args.end());
110 auto ranges_begin = args.begin();
113 if (ranges_begin == args.end())
return;
115 std::set<const Def*> to_remove;
117 auto& world = (*ranges_begin)->world();
119 std::transform(ranges_begin, args.end(), std::back_inserter(old_ranges),
get_range);
122 old_ranges, [&world](
auto&&... args) { world.DLOG(std::forward<
decltype(args)>(args)...); });
125 args.erase(ranges_begin, args.end());
126 std::transform(new_ranges.begin(), new_ranges.end(), std::back_inserter(args),
app_range{world});
131template<cls A, cls B>
137 auto check_arg_equiv = [](
const Def* lhs,
const Def* rhs) {
140 if (
auto rng_rhs =
Axm::isa<range>(not_rhs->arg()))
return rng_lhs == rng_rhs;
145 return check_arg_equiv(lhs, rhs) || check_arg_equiv(rhs, lhs);
149 Ranges lhs_ranges, rhs_ranges;
150 auto only_ranges = std::ranges::views::filter([](
auto d) {
return Axm::isa<range>(
d); });
151 std::ranges::transform(lhs | only_ranges, std::back_inserter(lhs_ranges),
get_range);
152 std::ranges::transform(rhs | only_ranges, std::back_inserter(rhs_ranges),
get_range);
153 return std::ranges::includes(lhs_ranges, rhs_ranges) || std::ranges::includes(rhs_ranges, lhs_ranges);
157 auto& world = type->world();
160 case 0:
return world.lit_ff();
163 auto contains_any = [](
auto args) {
164 return std::ranges::find_if(args, [](
const Def* ax) ->
bool {
return Axm::isa<any>(ax); })
168 auto new_args = detail::flatten_in_arg<disj>(arg);
169 if (contains_any(new_args))
return world.annex<
any>();
173 const Def* to_remove =
nullptr;
174 for (
const auto* cls0 : new_args) {
175 for (
const auto* cls1 : new_args)
180 auto rngs = detail::flatten_in_arg<disj>(disj_rhs->arg());
187 erase(new_args, to_remove);
188 world.DLOG(
"final ranges {, }", new_args);
191 if (new_args.size() > 1)
return world.call<
disj,
false>(new_args);
192 return new_args.back();
199 auto& world = type->world();
200 auto [lhs, rhs] = arg->
projs<2>();
202 if (!lhs->isa<
Var>() && !rhs->isa<
Var>())
203 if (lhs->as<
Lit>()->
get() > rhs->as<
Lit>()->
get())
return world.raw_app(type, callee, {rhs, lhs});
211 for (
const auto* disj_arg :
disj->args())
221 .
error(arg->
loc(),
"regex.not_ must only be used with regex.disj and regex.range: {} {}", callee, arg)
222 .
error(unwanted->loc(),
"found unwanted: {}", unwanted);
static auto isa(const Def *def)
auto projs(F f) const
Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (other...
constexpr u32 gid() const noexcept
Global id - unique number for this Def.
virtual const Def * arity() const
Error & error(Loc loc, const char *s, Args &&... args)
static std::optional< T > isa(const Def *def)
static T as(const Def *def)
A variable introduced by a binder (mutable).
This is a thin wrapper for absl::InlinedVector<T, N, A> which is a drop-in replacement for std::vecto...
The World represents the whole program and manages creation of MimIR nodes (Defs).
std::pair< std::uint64_t, std::uint64_t > Range
std::optional< Range > merge_ranges(Range a, Range b) noexcept
void merge_ranges(DefVec &args)
void make_vector_unique(DefVec &args)
const Def * any_unwanted(const Def *arg)
auto get_range(const Def *rng) -> Range
bool is_in_range(Range range, nat_t needle)
const Def * normalize_conj(const Def *type, const Def *callee, const Def *arg)
const Def * normalize_range(const Def *type, const Def *callee, const Def *arg)
const Def * normalize_disj(const Def *type, const Def *, const Def *arg)
const Def * normalize_quant(const Def *type, const Def *callee, const Def *arg)
const Def * normalize_not(const Def *, const Def *callee, const Def *arg)
bool compare_re(const Def *lhs, const Def *rhs)
const Def * make_binary_tree(Defs args)
bool equals_any(const Def *cls0, const Def *cls1)
Vector< const Def * > DefVec
Vector< T, N, A >::size_type erase(Vector< T, N, A > &c, const U &value) noexcept
#define MIM_regex_NORMALIZER_IMPL
const Def * operator()(Range rng)