2014-06-18 17:36:21 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "kernel/expr.h"
|
2014-07-14 03:12:58 +00:00
|
|
|
#include "kernel/expr_sets.h"
|
2014-09-10 22:20:45 +00:00
|
|
|
#include "kernel/type_checker.h"
|
2014-12-19 22:40:15 +00:00
|
|
|
#include "library/util.h"
|
2014-09-10 17:24:35 +00:00
|
|
|
#include "frontends/lean/local_decls.h"
|
2014-12-19 22:40:15 +00:00
|
|
|
|
2014-06-18 17:36:21 +00:00
|
|
|
namespace lean {
|
|
|
|
class parser;
|
2014-09-19 19:42:22 +00:00
|
|
|
/** \brief Parse optional '[persistent]' modifier.
|
|
|
|
return true if it is was found, and paremeter \c persistent to true.
|
|
|
|
*/
|
|
|
|
bool parse_persistent(parser & p, bool & persistent);
|
|
|
|
|
2014-06-18 17:36:21 +00:00
|
|
|
void check_atomic(name const & n);
|
2014-10-12 00:13:33 +00:00
|
|
|
void check_in_context(parser const & p);
|
2014-07-08 02:15:46 +00:00
|
|
|
bool is_root_namespace(name const & n);
|
|
|
|
name remove_root_prefix(name const & n);
|
2014-10-11 17:58:15 +00:00
|
|
|
/** \brief Return the local levels in \c ls that are not tagged as variables.
|
|
|
|
A local level is tagged as variable if it associated with a variable.
|
|
|
|
*/
|
|
|
|
levels collect_local_nonvar_levels(parser & p, level_param_names const & ls);
|
2014-10-11 22:33:31 +00:00
|
|
|
/** \brief Collect local constants occurring in \c type and \c value, sort them, and store in ctx_ps */
|
|
|
|
void collect_locals(expr const & type, expr const & value, parser const & p, buffer<expr> & ctx_ps);
|
2014-12-03 20:56:30 +00:00
|
|
|
name_set collect_univ_params_ignoring_tactics(expr const & e, name_set const & ls = name_set());
|
2014-10-11 22:33:31 +00:00
|
|
|
/** \brief Copy the local names to \c ps, then sort \c ps (using the order in which they were declared). */
|
|
|
|
void sort_locals(expr_struct_set const & locals, parser const & p, buffer<expr> & ps);
|
|
|
|
/** \brief Remove from \c ps local constants that are tagged as variables. */
|
|
|
|
void remove_local_vars(parser const & p, buffer<expr> & ps);
|
2014-10-30 02:47:14 +00:00
|
|
|
/** \brief Remove from \c ls any universe level that is tagged as variable in \c p */
|
|
|
|
levels remove_local_vars(parser const & p, levels const & ls);
|
2014-07-14 04:04:01 +00:00
|
|
|
list<expr> locals_to_context(expr const & e, parser const & p);
|
2014-10-11 22:33:31 +00:00
|
|
|
/** \brief Create the term <tt>(as_atomic (@n.{ls} @params[0] ... @params[num_params-1]))</tt>
|
|
|
|
When we declare \c n inside of a context, the parameters and universes are fixed.
|
2014-10-09 02:19:27 +00:00
|
|
|
That is, when the user writes \c n inside the section she is really getting the term returned by this function.
|
|
|
|
*/
|
2014-10-11 22:33:31 +00:00
|
|
|
expr mk_local_ref(name const & n, levels const & ctx_ls, unsigned num_ctx_params, expr const * ctx_params);
|
|
|
|
inline expr mk_local_ref(name const & n, levels const & ctx_ls, buffer<expr> const & ctx_params) {
|
|
|
|
return mk_local_ref(n, ctx_ls, ctx_params.size(), ctx_params.data());
|
2014-10-10 22:21:08 +00:00
|
|
|
}
|
2014-10-09 05:21:29 +00:00
|
|
|
/** \brief Return true iff \c e is a term of the form
|
2014-10-11 22:33:31 +00:00
|
|
|
<tt>(as_atomic (@n.{ls} @l_1 ... @l_n))</tt> where
|
2014-10-09 05:21:29 +00:00
|
|
|
\c n is a constant and l_i's are local constants.
|
|
|
|
|
2014-10-11 22:33:31 +00:00
|
|
|
\remark is_local_ref(mk_local_ref(n, ls, num_ps, ps)) always hold.
|
2014-10-09 05:21:29 +00:00
|
|
|
*/
|
2014-10-11 22:33:31 +00:00
|
|
|
bool is_local_ref(expr const & e);
|
|
|
|
/** \brief Given a term \c e s.t. is_local_ref(e) is true, remove all local constants in \c to_remove.
|
2014-10-09 05:21:29 +00:00
|
|
|
That is, if \c e is of the form
|
2014-10-11 22:33:31 +00:00
|
|
|
<tt>(as_atomic (@n.{u_1 ... u_k} @l_1 ... @l_n))</tt>
|
2014-10-09 05:21:29 +00:00
|
|
|
Then, return a term s.t.
|
|
|
|
1) any l_i s.t. mlocal_name(l_i) in \c locals_to_remove is removed.
|
|
|
|
2) any level u_j in \c lvls_to_remove is removed
|
|
|
|
*/
|
2014-10-11 22:33:31 +00:00
|
|
|
expr update_local_ref(expr const & e, name_set const & lvls_to_remove, name_set const & locals_to_remove);
|
2014-10-09 02:19:27 +00:00
|
|
|
|
2014-07-14 04:41:44 +00:00
|
|
|
/** \brief Fun(locals, e), but also propagate \c e position to result */
|
|
|
|
expr Fun(buffer<expr> const & locals, expr const & e, parser & p);
|
|
|
|
/** \brief Pi(locals, e), but also propagate \c e position to result */
|
|
|
|
expr Pi(buffer<expr> const & locals, expr const & e, parser & p);
|
2014-07-14 05:27:36 +00:00
|
|
|
/** \brief Similar to Fun(locals, e, p), but the types are marked as 'as-is' (i.e., they are not processed by the elaborator. */
|
|
|
|
expr Fun_as_is(buffer<expr> const & locals, expr const & e, parser & p);
|
|
|
|
/** \brief Similar to Pi(locals, e, p), but the types are marked as 'as-is' (i.e., they are not processed by the elaborator. */
|
|
|
|
expr Pi_as_is(buffer<expr> const & locals, expr const & e, parser & p);
|
2014-07-29 02:04:57 +00:00
|
|
|
/** \brief Create the resultant universe level using the levels computed during introduction rule elaboration */
|
|
|
|
level mk_result_level(environment const & env, buffer<level> const & r_lvls);
|
|
|
|
/** \brief Return true if \c u occurs in \c l */
|
|
|
|
bool occurs(level const & u, level const & l);
|
2014-09-10 17:24:35 +00:00
|
|
|
|
|
|
|
/** \brief Convert the universe metavariables in \c e in new universe parameters.
|
|
|
|
The substitution \c s is updated with the mapping metavar -> new param.
|
|
|
|
The set of parameter names \c ps and the buffer \c new_ps are also updated.
|
|
|
|
*/
|
|
|
|
expr univ_metavars_to_params(environment const & env, local_decls<level> const & lls, substitution & s,
|
|
|
|
name_set & ps, buffer<name> & new_ps, expr const & e);
|
2014-09-10 18:19:14 +00:00
|
|
|
|
|
|
|
/** \brief Instantiate metavariable application \c meta (?M ...) using \c subst */
|
|
|
|
expr instantiate_meta(expr const & meta, substitution & subst);
|
|
|
|
|
|
|
|
/** \brief Return a 'failed to synthesize placholder' justification for the given
|
|
|
|
metavariable application \c m of the form (?m l_1 ... l_k) */
|
|
|
|
justification mk_failed_to_synthesize_jst(environment const & env, expr const & m);
|
2014-09-13 17:21:10 +00:00
|
|
|
|
|
|
|
/** \brief Return a justification for \c v_type being definitionally equal to \c t,
|
|
|
|
<tt> v : v_type</tt>, the expressiong \c src is used to extract position information.
|
|
|
|
*/
|
|
|
|
justification mk_type_mismatch_jst(expr const & v, expr const & v_type, expr const & t, expr const & src);
|
|
|
|
inline justification mk_type_mismatch_jst(expr const & v, expr const & v_type, expr const & t) {
|
|
|
|
return mk_type_mismatch_jst(v, v_type, t, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Given a metavariable application (?m l_1 ... l_n), apply \c s to the types of
|
|
|
|
?m and local constants l_i
|
|
|
|
Return the updated expression and a justification for all substitutions.
|
|
|
|
*/
|
|
|
|
pair<expr, justification> update_meta(expr const & meta, substitution s);
|
2014-11-24 07:00:59 +00:00
|
|
|
|
|
|
|
/** \brief Auxiliary function for check/eval/find_decl */
|
|
|
|
std::tuple<expr, level_param_names> parse_local_expr(parser & p);
|
|
|
|
|
|
|
|
optional<name> is_uniquely_aliased(environment const & env, name const & n);
|
|
|
|
|
|
|
|
/** \brief Get declaration 'short-name' that can uniquely identify it. */
|
|
|
|
name get_decl_short_name(name const & d, environment const & env);
|
2014-11-30 03:08:37 +00:00
|
|
|
|
|
|
|
/** \brief Open 'num' notation and aliases. */
|
|
|
|
environment open_num_notation(environment const & env);
|
|
|
|
/** \brief Open 'std.prec' aliases */
|
|
|
|
environment open_prec_aliases(environment const & env);
|
|
|
|
/** \brief Open 'std.priority' aliases */
|
|
|
|
environment open_priority_aliases(environment const & env);
|
2014-06-18 17:36:21 +00:00
|
|
|
}
|