2014-09-19 20:30:08 +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 <memory>
|
|
|
|
#include "kernel/type_checker.h"
|
2015-02-08 01:31:53 +00:00
|
|
|
#include "kernel/default_converter.h"
|
2014-09-19 20:30:08 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2015-03-05 06:12:49 +00:00
|
|
|
enum class reducible_status { Reducible, Quasireducible, Semireducible, Irreducible };
|
2014-09-19 20:30:08 +00:00
|
|
|
/** \brief Mark the definition named \c n as reducible or not.
|
|
|
|
|
|
|
|
The method throws an exception if \c n is
|
|
|
|
- not a definition
|
|
|
|
- a theorem
|
|
|
|
- an opaque definition that was not defined in main module
|
|
|
|
|
|
|
|
"Reducible" definitions can be freely unfolded by automation (i.e., elaborator, simplifier, etc).
|
|
|
|
We should view it as a hint to automation.
|
|
|
|
*/
|
|
|
|
environment set_reducible(environment const & env, name const & n, reducible_status s, bool persistent = true);
|
|
|
|
|
2015-03-05 06:12:49 +00:00
|
|
|
reducible_status get_reducible_status(environment const & env, name const & n);
|
2014-09-19 20:30:08 +00:00
|
|
|
|
2015-03-05 06:12:49 +00:00
|
|
|
bool is_at_least_quasireducible(environment const & env, name const & n);
|
|
|
|
|
|
|
|
struct reducible_entry;
|
|
|
|
|
|
|
|
class reducible_state {
|
|
|
|
name_map<reducible_status> m_status;
|
|
|
|
public:
|
|
|
|
void add(reducible_entry const & e);
|
|
|
|
reducible_status get_status(name const & n) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief Unfold only constants marked as reducible */
|
|
|
|
class unfold_reducible_converter : public default_converter {
|
|
|
|
reducible_state m_state;
|
|
|
|
public:
|
|
|
|
unfold_reducible_converter(environment const & env, bool relax_main_opaque, bool memoize);
|
|
|
|
virtual bool is_opaque(declaration const & d) const;
|
|
|
|
};
|
2014-09-19 20:30:08 +00:00
|
|
|
|
2015-03-05 06:12:49 +00:00
|
|
|
/** \brief Unfold only constants marked as reducible or quasireducible */
|
|
|
|
class unfold_quasireducible_converter : public default_converter {
|
|
|
|
reducible_state m_state;
|
2015-02-08 01:31:53 +00:00
|
|
|
public:
|
2015-03-05 06:12:49 +00:00
|
|
|
unfold_quasireducible_converter(environment const & env, bool relax_main_opaque, bool memoize);
|
2015-02-08 01:31:53 +00:00
|
|
|
virtual bool is_opaque(declaration const & d) const;
|
|
|
|
};
|
|
|
|
|
2015-03-05 06:12:49 +00:00
|
|
|
/** \brief Unfold only constants marked as reducible, quasireducible, or semireducible */
|
|
|
|
class unfold_semireducible_converter : public default_converter {
|
|
|
|
reducible_state m_state;
|
2015-02-08 01:31:53 +00:00
|
|
|
public:
|
2015-03-05 06:12:49 +00:00
|
|
|
unfold_semireducible_converter(environment const & env, bool relax_main_opaque, bool memoize);
|
2015-02-08 01:31:53 +00:00
|
|
|
virtual bool is_opaque(declaration const & d) const;
|
|
|
|
};
|
|
|
|
|
2015-03-05 06:12:49 +00:00
|
|
|
enum reducible_behavior { UnfoldReducible, UnfoldQuasireducible, UnfoldSemireducible };
|
2015-01-09 02:47:44 +00:00
|
|
|
|
2014-09-19 20:30:08 +00:00
|
|
|
/** \brief Create a type checker that takes the "reducibility" hints into account. */
|
|
|
|
std::unique_ptr<type_checker> mk_type_checker(environment const & env, name_generator const & ngen,
|
2015-03-05 06:12:49 +00:00
|
|
|
bool relax_main_opaque = true, reducible_behavior r = UnfoldSemireducible,
|
2014-10-23 20:09:59 +00:00
|
|
|
bool memoize = true);
|
2015-01-09 02:47:44 +00:00
|
|
|
std::unique_ptr<type_checker> mk_type_checker(environment const & env, bool relax_main_opaque,
|
2015-03-05 06:12:49 +00:00
|
|
|
reducible_behavior r = UnfoldSemireducible);
|
2014-09-23 00:30:29 +00:00
|
|
|
|
2014-11-24 03:03:39 +00:00
|
|
|
/** \brief Create a type checker that treats all definitions as opaque. */
|
|
|
|
std::unique_ptr<type_checker> mk_opaque_type_checker(environment const & env, name_generator const & ngen);
|
|
|
|
|
2014-09-23 00:30:29 +00:00
|
|
|
void initialize_reducible();
|
|
|
|
void finalize_reducible();
|
2015-01-29 18:37:15 +00:00
|
|
|
void open_reducible(lua_State * L);
|
2014-09-19 20:30:08 +00:00
|
|
|
}
|