int main (int argc, char *argv[]) { tests_start (); if (argc >= 2 && strcmp (argv[1], "-a") == 0) { /* it's feasible to run all values on a 32-bit limb, but not a 64-bit */ all (); } else { some (); } tests_end (); exit (0); }
virtual optional<expr> expand(expr const & m, abstract_type_context & ctx) const { check_macro(m); expr const & s = macro_arg(m, 0); expr new_s = ctx.whnf(s); buffer<expr> c_args; expr const & c = get_app_args(new_s, c_args); if (is_constant(c) && const_name(c) == m_constructor_name && m_idx < c_args.size()) { return some_expr(c_args[m_idx]); } else { // expand into recursor expr s_type = ctx.whnf(ctx.infer(s)); buffer<expr> args; expr const & I = get_app_args(s_type, args); if (!is_constant(I) || length(m_ps) != length(const_levels(I))) return none_expr(); expr r = instantiate_univ_params(m_val, m_ps, const_levels(I)); args.push_back(new_s); return some(instantiate_rev(r, args.size(), args.data())); } }
optional<std::tuple<level_param_names, expr, expr>> definition_cache::find(environment const & env, name const & n, expr const & pre_type, expr const & pre_value, bool is_trusted) { entry e; { lock_guard<mutex> lc(m_mutex); if (auto it = m_definitions.find(n)) { e = *it; } else { return optional<std::tuple<level_param_names, expr, expr>>(); } } level_param_names ls; if (e.m_is_trusted == is_trusted && expr_eq_modulo_placeholders_fn()(e.m_pre_type, pre_type) && expr_eq_modulo_placeholders_fn()(e.m_pre_value, pre_value) && get_fingerprint(env) == e.m_fingerprint && check_dependencies(env, e.m_dependencies)) { return some(std::make_tuple(e.m_params, e.m_type, e.m_value)); } else { return optional<std::tuple<level_param_names, expr, expr>>(); } }
int main() { TabSample t; TabFoo f; // MEMBER FUNCTIONS // ---------------- // Test in { using TI = decltype(t.alpha.in(1, 2, 3)); using TF = decltype(f.omega.in(1.0, 2.0, 3.0)); using TT = decltype(t.beta.in("a", "b", "c")); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TF>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TT>::value, "type requirement"); } // Test in with value list { using TI = decltype(t.alpha.in(sqlpp::value_list(std::vector<int>({1, 2, 3})))); using TF = decltype(f.omega.in(sqlpp::value_list(std::vector<float>({1.0, 2.0, 3.0})))); using TT = decltype(t.beta.in(sqlpp::value_list(std::vector<std::string>({"a", "b", "c"})))); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TF>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TT>::value, "type requirement"); } // Test not_in { using TI = decltype(t.alpha.not_in(1, 2, 3)); using TF = decltype(f.omega.not_in(1.0, 2.0, 3.0)); using TT = decltype(t.beta.not_in("a", "b", "c")); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TF>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TT>::value, "type requirement"); } // Test not in with value list { using TI = decltype(t.alpha.not_in(sqlpp::value_list(std::vector<int>({1, 2, 3})))); using TF = decltype(f.omega.not_in(sqlpp::value_list(std::vector<float>({1.0, 2.0, 3.0})))); using TT = decltype(t.beta.not_in(sqlpp::value_list(std::vector<std::string>({"a", "b", "c"})))); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TF>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TT>::value, "type requirement"); } // Test like { using TT = decltype(t.beta.like("%c%")); static_assert(sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TT>::value, "type requirement"); } // Test is_null { using TI = decltype(t.alpha.is_null()); using TF = decltype(f.omega.is_null()); using TT = decltype(t.beta.is_null()); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TF>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TT>::value, "type requirement"); } // Test is_not_null { using TI = decltype(t.alpha.is_not_null()); using TF = decltype(f.omega.is_not_null()); using TT = decltype(t.beta.is_not_null()); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TF>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TT>::value, "type requirement"); } // SUB_SELECT_FUNCTIONS // -------------------- // Test exists { using TI = decltype(exists(select(t.alpha).from(t))); using TT = decltype(exists(select(t.beta).from(t))); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TT>::value, "type requirement"); } // Test any { using TI = decltype(any(select(t.alpha).from(t))); using TT = decltype(any(select(t.beta).from(t))); using TF = decltype(any(select(f.omega).from(t))); static_assert(not sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TF>::value, "tFpe requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_integral_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<TT>::value, "type requirement"); static_assert(sqlpp::is_text_t<TT>::value, "type requirement"); } // Test some { using TI = decltype(some(select(t.alpha).from(t))); using TT = decltype(some(select(t.beta).from(t))); using TF = decltype(some(select(f.omega).from(t))); static_assert(not sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_integral_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<TT>::value, "type requirement"); static_assert(sqlpp::is_text_t<TT>::value, "type requirement"); } // NUMERIC FUNCTIONS // ----------------- // Test avg { using TI = decltype(avg(t.alpha)); using TF = decltype(avg(f.omega)); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_integral_t<TF>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); } // Test count { using TI = decltype(count(t.alpha)); using TT = decltype(count(t.beta)); using TF = decltype(count(f.omega)); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<TF>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<TT>::value, "type requirement"); } // Test max { using TI = decltype(max(t.alpha)); using TF = decltype(max(f.omega)); using TT = decltype(max(t.beta)); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_integral_t<TF>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(sqlpp::is_text_t<TT>::value, "type requirement"); } // Test min { using TI = decltype(min(t.alpha)); using TF = decltype(min(f.omega)); using TT = decltype(min(t.beta)); static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_integral_t<TF>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(sqlpp::is_text_t<TT>::value, "type requirement"); } // Test sum { using TI = decltype(sum(t.alpha)); using TF = decltype(sum(f.omega)); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<TI>::value, "type requirement"); static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_integral_t<TF>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); } // MISC FUNCTIONS // -------------- // test value { using TB = decltype(sqlpp::value(true)); using TI = decltype(sqlpp::value(7)); using TF = decltype(sqlpp::value(1.5)); using TT = decltype(sqlpp::value("cheesecake")); static_assert(not sqlpp::is_named_expression_t<TB>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TB>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TB>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_text_t<TT>::value, "type requirement"); } // test flatten { using TB = decltype(flatten(t.gamma, db)); using TI = decltype(flatten(t.alpha, db)); using TF = decltype(flatten(f.omega, db)); using TT = decltype(flatten(t.beta, db)); static_assert(not sqlpp::is_named_expression_t<TB>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TB>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TB>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_text_t<TT>::value, "type requirement"); } // test verbatim { using TB = decltype(sqlpp::verbatim<sqlpp::boolean>("1")); using TI = decltype(sqlpp::verbatim<sqlpp::bigint>("42")); using TF = decltype(sqlpp::verbatim<sqlpp::floating_point>("1.5")); using TT = decltype(sqlpp::verbatim<sqlpp::text>("cheesecake")); static_assert(not sqlpp::is_named_expression_t<TB>::value, "type requirement"); static_assert(sqlpp::is_boolean_t<TB>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TB>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_text_t<TT>::value, "type requirement"); } // test verbatim_table { using T = decltype(sqlpp::verbatim_table("cheesecake")); static_assert(not sqlpp::is_named_expression_t<T>::value, "type requirement"); static_assert(not sqlpp::is_expression_t<T>::value, "type requirement"); static_assert(sqlpp::is_table_t<T>::value, "type requirement"); } // test verbatim_table alias { SQLPP_ALIAS_PROVIDER_GENERATOR(kaesekuchen); using T = decltype(sqlpp::verbatim_table("cheesecake").as(kaesekuchen)); static_assert(not sqlpp::is_named_expression_t<T>::value, "type requirement"); static_assert(not sqlpp::is_expression_t<T>::value, "type requirement"); static_assert(sqlpp::is_table_t<T>::value, "type requirement"); static_assert(sqlpp::is_alias_t<T>::value, "type requirement"); } return 0; }
optional<environment> mk_no_confusion_type(environment const & env, name const & n) { optional<inductive::inductive_decls> decls = inductive::is_inductive_decl(env, n); if (!decls) throw exception(sstream() << "error in 'no_confusion' generation, '" << n << "' is not an inductive datatype"); if (is_inductive_predicate(env, n)) return optional<environment>(); // type is a proposition name_generator ngen; unsigned nparams = std::get<1>(*decls); declaration ind_decl = env.get(n); declaration cases_decl = env.get(name(n, "cases_on")); level_param_names lps = cases_decl.get_univ_params(); level rlvl = mk_param_univ(head(lps)); levels ilvls = param_names_to_levels(tail(lps)); if (length(ilvls) != length(ind_decl.get_univ_params())) return optional<environment>(); // type does not have only a restricted eliminator expr ind_type = instantiate_type_univ_params(ind_decl, ilvls); name eq_name("eq"); name heq_name("heq"); // All inductive datatype parameters and indices are arguments buffer<expr> args; ind_type = to_telescope(ngen, ind_type, args, some(mk_implicit_binder_info())); if (!is_sort(ind_type) || args.size() < nparams) throw_corrupted(n); lean_assert(!(env.impredicative() && is_zero(sort_level(ind_type)))); unsigned nindices = args.size() - nparams; // Create inductive datatype expr I = mk_app(mk_constant(n, ilvls), args); // Add (P : Type) expr P = mk_local(ngen.next(), "P", mk_sort(rlvl), binder_info()); args.push_back(P); // add v1 and v2 elements of the inductive type expr v1 = mk_local(ngen.next(), "v1", I, binder_info()); expr v2 = mk_local(ngen.next(), "v2", I, binder_info()); args.push_back(v1); args.push_back(v2); expr R = mk_sort(rlvl); name no_confusion_type_name{n, "no_confusion_type"}; expr no_confusion_type_type = Pi(args, R); // Create type former buffer<expr> type_former_args; for (unsigned i = nparams; i < nparams + nindices; i++) type_former_args.push_back(args[i]); type_former_args.push_back(v1); expr type_former = Fun(type_former_args, R); // Create cases_on levels clvls = levels(mk_succ(rlvl), ilvls); expr cases_on = mk_app(mk_app(mk_constant(cases_decl.get_name(), clvls), nparams, args.data()), type_former); cases_on = mk_app(cases_on, nindices, args.data() + nparams); expr cases_on1 = mk_app(cases_on, v1); expr cases_on2 = mk_app(cases_on, v2); type_checker tc(env); expr t1 = tc.infer(cases_on1).first; expr t2 = tc.infer(cases_on2).first; buffer<expr> outer_cases_on_args; unsigned idx1 = 0; while (is_pi(t1)) { buffer<expr> minor1_args; expr minor1 = to_telescope(tc, binding_domain(t1), minor1_args); expr curr_t2 = t2; buffer<expr> inner_cases_on_args; unsigned idx2 = 0; while (is_pi(curr_t2)) { buffer<expr> minor2_args; expr minor2 = to_telescope(tc, binding_domain(curr_t2), minor2_args); if (idx1 != idx2) { // infeasible case, constructors do not match inner_cases_on_args.push_back(Fun(minor2_args, P)); } else { if (minor1_args.size() != minor2_args.size()) throw_corrupted(n); buffer<expr> rtype_hyp; // add equalities for (unsigned i = 0; i < minor1_args.size(); i++) { expr lhs = minor1_args[i]; expr rhs = minor2_args[i]; expr lhs_type = mlocal_type(lhs); expr rhs_type = mlocal_type(rhs); level l = sort_level(tc.ensure_type(lhs_type).first); expr h_type; if (tc.is_def_eq(lhs_type, rhs_type).first) { h_type = mk_app(mk_constant(eq_name, to_list(l)), lhs_type, lhs, rhs); } else { h_type = mk_app(mk_constant(heq_name, to_list(l)), lhs_type, lhs, rhs_type, rhs); } rtype_hyp.push_back(mk_local(ngen.next(), local_pp_name(lhs).append_after("_eq"), h_type, binder_info())); } inner_cases_on_args.push_back(Fun(minor2_args, mk_arrow(Pi(rtype_hyp, P), P))); } idx2++; curr_t2 = binding_body(curr_t2); } outer_cases_on_args.push_back(Fun(minor1_args, mk_app(cases_on2, inner_cases_on_args))); idx1++; t1 = binding_body(t1); } expr no_confusion_type_value = Fun(args, mk_app(cases_on1, outer_cases_on_args)); bool opaque = false; bool use_conv_opt = true; declaration new_d = mk_definition(env, no_confusion_type_name, lps, no_confusion_type_type, no_confusion_type_value, opaque, ind_decl.get_module_idx(), use_conv_opt); environment new_env = module::add(env, check(env, new_d)); return some(add_protected(new_env, no_confusion_type_name)); }
environment mk_no_confusion(environment const & env, name const & n) { optional<environment> env1 = mk_no_confusion_type(env, n); if (!env1) return env; environment new_env = *env1; type_checker tc(new_env); inductive::inductive_decls decls = *inductive::is_inductive_decl(new_env, n); unsigned nparams = std::get<1>(decls); name_generator ngen; declaration no_confusion_type_decl = new_env.get(name{n, "no_confusion_type"}); declaration cases_decl = new_env.get(name(n, "cases_on")); level_param_names lps = no_confusion_type_decl.get_univ_params(); levels ls = param_names_to_levels(lps); expr no_confusion_type_type = instantiate_type_univ_params(no_confusion_type_decl, ls); name eq_name("eq"); name heq_name("heq"); name eq_refl_name{"eq", "refl"}; name heq_refl_name{"heq", "refl"}; buffer<expr> args; expr type = no_confusion_type_type; type = to_telescope(ngen, type, args, some(mk_implicit_binder_info())); lean_assert(args.size() >= nparams + 3); unsigned nindices = args.size() - nparams - 3; // 3 is for P v1 v2 expr range = mk_app(mk_constant(no_confusion_type_decl.get_name(), ls), args); expr P = args[args.size()-3]; expr v1 = args[args.size()-2]; expr v2 = args[args.size()-1]; expr v_type = mlocal_type(v1); level v_lvl = sort_level(tc.ensure_type(v_type).first); expr eq_v = mk_app(mk_constant(eq_name, to_list(v_lvl)), v_type); expr H12 = mk_local(ngen.next(), "H12", mk_app(eq_v, v1, v2), binder_info()); args.push_back(H12); name no_confusion_name{n, "no_confusion"}; expr no_confusion_ty = Pi(args, range); // The gen proof is of the form // (fun H11 : v1 = v1, cases_on Params (fun Indices v1, no_confusion_type Params Indices P v1 v1) Indices v1 // <for-each case> // (fun H : (equations -> P), H (refl) ... (refl)) // ... // ) // H11 is for creating the generalization expr H11 = mk_local(ngen.next(), "H11", mk_app(eq_v, v1, v1), binder_info()); // Create the type former (fun Indices v1, no_confusion_type Params Indices P v1 v1) buffer<expr> type_former_args; for (unsigned i = nparams; i < nparams + nindices; i++) type_former_args.push_back(args[i]); type_former_args.push_back(v1); buffer<expr> no_confusion_type_args; for (unsigned i = 0; i < nparams + nindices; i++) no_confusion_type_args.push_back(args[i]); no_confusion_type_args.push_back(P); no_confusion_type_args.push_back(v1); no_confusion_type_args.push_back(v1); expr no_confusion_type_app = mk_app(mk_constant(no_confusion_type_decl.get_name(), ls), no_confusion_type_args); expr type_former = Fun(type_former_args, no_confusion_type_app); // create cases_on levels clvls = ls; expr cases_on = mk_app(mk_app(mk_constant(cases_decl.get_name(), clvls), nparams, args.data()), type_former); cases_on = mk_app(mk_app(cases_on, nindices, args.data() + nparams), v1); expr cot = tc.infer(cases_on).first; while (is_pi(cot)) { buffer<expr> minor_args; expr minor = to_telescope(tc, binding_domain(cot), minor_args); lean_assert(!minor_args.empty()); expr H = minor_args.back(); expr Ht = mlocal_type(H); buffer<expr> refl_args; while (is_pi(Ht)) { buffer<expr> eq_args; expr eq_fn = get_app_args(binding_domain(Ht), eq_args); if (const_name(eq_fn) == eq_name) { refl_args.push_back(mk_app(mk_constant(eq_refl_name, const_levels(eq_fn)), eq_args[0], eq_args[1])); } else { refl_args.push_back(mk_app(mk_constant(heq_refl_name, const_levels(eq_fn)), eq_args[0], eq_args[1])); } Ht = binding_body(Ht); } expr pr = mk_app(H, refl_args); cases_on = mk_app(cases_on, Fun(minor_args, pr)); cot = binding_body(cot); } expr gen = Fun(H11, cases_on); // Now, we use gen to build the final proof using eq.rec // // eq.rec InductiveType v1 (fun (a : InductiveType), v1 = a -> no_confusion_type Params Indices v1 a) gen v2 H12 H12 // name eq_rec_name{"eq", "rec"}; expr eq_rec = mk_app(mk_constant(eq_rec_name, {head(ls), v_lvl}), v_type, v1); // create eq_rec type_former // (fun (a : InductiveType), v1 = a -> no_confusion_type Params Indices v1 a) expr a = mk_local(ngen.next(), "a", v_type, binder_info()); expr H1a = mk_local(ngen.next(), "H1a", mk_app(eq_v, v1, a), binder_info()); // reusing no_confusion_type_args... we just replace the last argument with a no_confusion_type_args.pop_back(); no_confusion_type_args.push_back(a); expr no_confusion_type_app_1a = mk_app(mk_constant(no_confusion_type_decl.get_name(), ls), no_confusion_type_args); expr rec_type_former = Fun(a, Pi(H1a, no_confusion_type_app_1a)); // finalize eq_rec eq_rec = mk_app(mk_app(eq_rec, rec_type_former, gen, v2, H12), H12); // expr no_confusion_val = Fun(args, eq_rec); bool opaque = false; bool use_conv_opt = true; declaration new_d = mk_definition(new_env, no_confusion_name, lps, no_confusion_ty, no_confusion_val, opaque, no_confusion_type_decl.get_module_idx(), use_conv_opt); new_env = module::add(new_env, check(new_env, new_d)); return add_protected(new_env, no_confusion_name); }
static optional<unsigned> get_fingerprint(entry const & e) { return some(hash(e.first ? 17 : 31, e.second.hash())); }
operator SafeBool::type() const { return SafeBool::makeSafe( some() ); }
static inline some create(std::true_type, std::true_type) { return some(); //return some(T()); }
static optional<unsigned> get_fingerprint(entry const & e) { return some(hash(static_cast<unsigned>(e.m_status), e.m_name.hash())); }
bool Type::can_be_callable() const { return is_any() or (_types.size() and some([&](std::shared_ptr<const Base_type> t) { return t->callable(); })); }
bool Type::can_be_number() const { return some([&](std::shared_ptr<const Base_type> type) { return type->distance(Type::number()._types[0].get()) >= 0; }); }
template <class T> bool Type::can_be_type() const { return _types.size() && some([&](std::shared_ptr<const Base_type> type) { return dynamic_cast<const T*>(type.get()) != nullptr; }); }
static optional<unsigned> get_fingerprint(entry const & e) { return some(hash(e.m_decl_name.hash(), e.m_priority)); }
static optional<unsigned> get_fingerprint(entry const & e) { return some(hash(e.m_accumulate, e.m_tac.hash())); }
int Interpret(int, char* []) { MockDb db = {}; MockDb::_serializer_context_t printer = {}; const auto f = test::TabFoo{}; const auto t = test::TabBar{}; select(t.alpha.as(t.beta)); serialize(insert_into(t).columns(t.beta, t.gamma), printer).str(); { auto i = insert_into(t).columns(t.gamma, t.beta); i.values.add(t.gamma = true, t.beta = "cheesecake"); serialize(i, printer).str(); i.values.add(t.gamma = false, t.beta = sqlpp::tvin("coffee")); i.values.add(t.gamma = false, t.beta = sqlpp::tvin(std::string())); serialize(i, printer).str(); i.values.add(t.gamma = sqlpp::default_value, t.beta = sqlpp::null); serialize(i, printer).str(); } serialize(t.alpha = sqlpp::null, printer).str(); serialize(t.alpha = sqlpp::default_value, printer).str(); serialize(t.alpha, printer).str(); serialize(-t.alpha, printer).str(); serialize(+t.alpha, printer).str(); serialize(-(t.alpha + 7), printer).str(); serialize(t.alpha = 0, printer).str(); serialize(t.alpha = sqlpp::tvin(0), printer).str(); serialize(t.alpha == 0, printer).str(); serialize(t.alpha == sqlpp::tvin(0), printer).str(); serialize(t.alpha != 0, printer).str(); serialize(t.gamma != sqlpp::tvin(false), printer).str(); serialize(t.alpha == 7, printer).str(); serialize(t.delta = sqlpp::tvin(0), printer).str(); serialize(t.beta + "kaesekuchen", printer).str(); serialize(sqlpp::select(), printer).str(); serialize(sqlpp::select().flags(sqlpp::distinct), printer).str(); serialize(select(t.alpha, t.beta).flags(sqlpp::distinct), printer).str(); serialize(select(t.alpha, t.beta), printer).str(); serialize(select(t.alpha, t.beta).from(t), printer).str(); serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3), printer).str(); serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma), printer).str(); serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")), printer).str(); serialize(select(t.alpha, t.beta) .from(t) .where(t.alpha == 3) .group_by(t.gamma) .having(t.beta.like("%kuchen")) .order_by(t.beta.asc()), printer).str(); serialize(select(t.alpha, t.beta) .from(t) .where(t.alpha == 3) .group_by(t.gamma) .having(t.beta.like("%kuchen")) .order_by(t.beta.asc()) .limit(17) .offset(3), printer).str(); serialize(parameter(sqlpp::bigint(), t.alpha), printer).str(); serialize(parameter(t.alpha), printer).str(); serialize(t.alpha == parameter(t.alpha), printer).str(); serialize(t.alpha == parameter(t.alpha) and (t.beta + "gimmick").like(parameter(t.beta)), printer).str(); serialize(insert_into(t), printer).str(); serialize(insert_into(f).default_values(), printer).str(); serialize(insert_into(t).set(t.gamma = true), printer).str(); // serialize(insert_into(t).set(t.gamma = sqlpp::tvin(false)), printer).str(); cannot test this since gamma cannot be // null and a static assert is thrown serialize(update(t), printer).str(); serialize(update(t).set(t.gamma = true), printer).str(); serialize(update(t).set(t.gamma = true).where(t.beta.in("kaesekuchen", "cheesecake")), printer).str(); serialize(update(t).set(t.gamma = true).where(t.beta.in()), printer).str(); serialize(remove_from(t), printer).str(); serialize(remove_from(t).using_(t), printer).str(); serialize(remove_from(t).where(t.alpha == sqlpp::tvin(0)), printer).str(); serialize(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).str(); // functions serialize(sqlpp::value(7), printer).str(); serialize(sqlpp::verbatim<sqlpp::integral>("irgendwas integrales"), printer).str(); serialize(sqlpp::value_list(std::vector<int>({1, 2, 3, 4, 5, 6, 8})), printer).str(); serialize(exists(select(t.alpha).from(t)), printer).str(); serialize(any(select(t.alpha).from(t)), printer).str(); serialize(some(select(t.alpha).from(t)), printer).str(); serialize(count(t.alpha), printer).str(); serialize(min(t.alpha), printer).str(); serialize(max(t.alpha), printer).str(); serialize(avg(t.alpha), printer).str(); serialize(sum(t.alpha), printer).str(); serialize(sqlpp::verbatim_table("whatever"), printer).str(); // alias serialize(t.as(t.alpha), printer).str(); serialize(t.as(t.alpha).beta, printer).str(); // select alias serialize(select(t.alpha).from(t).where(t.beta > "kaesekuchen").as(t.gamma), printer).str(); serialize(t.alpha.is_null(), printer).str(); // join serialize(t.inner_join(t.as(t.alpha)).on(t.beta == t.as(t.alpha).beta), printer).str(); { auto inner = t.inner_join(t.as(t.alpha)).on(t.beta == t.as(t.alpha).beta); serialize(select(t.alpha).from(inner), printer).str(); } // multi_column serialize(multi_column(t.alpha, (t.beta + "cake").as(t.gamma)).as(t.alpha), printer).str(); serialize(multi_column(all_of(t)).as(t), printer).str(); serialize(all_of(t).as(t), printer).str(); // dynamic select { auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); s.selected_columns.add(t.beta); s.selected_columns.add(t.gamma); serialize(s, printer).str(); } { auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); s.select_flags.add(sqlpp::distinct); s.selected_columns.add(t.beta); s.selected_columns.add(t.gamma); serialize(s, printer).str(); } { // Behold, dynamically constructed queries might compile but be illegal SQL auto s = dynamic_select(db).dynamic_flags(sqlpp::distinct).dynamic_columns(t.alpha); s.select_flags.add(sqlpp::all); s.selected_columns.add(without_table_check(t.beta)); s.selected_columns.add(without_table_check(t.gamma)); serialize(s, printer).str(); } // distinct aggregate serialize(count(sqlpp::distinct, t.alpha % 7), printer).str(); serialize(avg(sqlpp::distinct, t.alpha - 7), printer).str(); serialize(sum(sqlpp::distinct, t.alpha + 7), printer).str(); serialize(select(all_of(t)).from(t).unconditionally(), printer).str(); for (const auto& row : db(select(all_of(t)).from(t).unconditionally())) { serialize(row.alpha, printer); serialize(row.beta, printer); serialize(row.gamma, printer); } get_sql_name(t); get_sql_name(t.alpha); flatten(t.alpha == 7, db); auto x = boolean_expression(db, t.alpha == 7); x = sqlpp::boolean_expression<MockDb>(t.beta.like("%cheesecake")); x = x and boolean_expression(db, t.gamma); std::cerr << "----------------------------" << std::endl; printer.reset(); std::cerr << serialize(x, printer).str() << std::endl; printer.reset(); std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in(select(f.epsilon).from(f).unconditionally())), printer).str() << std::endl; printer.reset(); std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in()), printer).str() << std::endl; printer.reset(); std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.not_in()), printer).str() << std::endl; auto schema = db.attach("lorem"); auto s = schema_qualified_table(schema, t).as(sqlpp::alias::x); printer.reset(); std::cerr << serialize(select(all_of(s)).from(s).unconditionally(), printer).str() << std::endl; printer.reset(); std::cerr << serialize(sqlpp::case_when(true).then(t.alpha).else_(t.alpha + 1).as(t.beta), printer).str() << std::endl; return 0; }
static optional<unsigned> get_fingerprint(entry const & e) { return some(e.m_id.hash()); }
static inline some create(B1, B2) { return some(); }