Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
fix(library/module): unfold untrusted macros in imported intro rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Kha committed Mar 27, 2017
1 parent e885332 commit d9fb83d
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/library/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,19 +314,33 @@ struct inductive_modification : public modification {
LEAN_MODIFICATION("ind")

inductive::certified_inductive_decl m_decl;
unsigned m_trust_lvl = LEAN_BELIEVER_TRUST_LEVEL + 1;

inductive_modification(inductive::certified_inductive_decl const & decl) : m_decl(decl) {}

inductive_modification(inductive::certified_inductive_decl const & decl, unsigned trust_lvl) :
m_decl(decl), m_trust_lvl(trust_lvl) {}

void perform(environment & env) const override {
env = m_decl.add(env);
if (m_trust_lvl > env.trust_lvl()) {
auto d = m_decl.get_decl();
d.m_intro_rules = map(d.m_intro_rules, [&](inductive::intro_rule const & r) {
return unfold_untrusted_macros(env, r);
});
env = add_inductive(env, d, m_decl.is_trusted()).first;
} else {
env = m_decl.add(env);
}
}

void serialize(serializer & s) const override {
s << m_decl;
s << m_decl << m_trust_lvl;
}

static std::shared_ptr<modification const> deserialize(deserializer & d) {
return std::make_shared<inductive_modification>(read_certified_inductive_decl(d));
auto decl = read_certified_inductive_decl(d);
unsigned trust_lvl;
d >> trust_lvl;
return std::make_shared<inductive_modification>(std::move(decl), trust_lvl);
}

void get_introduced_exprs(std::vector<task<expr>> & es) const override {
Expand Down Expand Up @@ -450,7 +464,7 @@ environment add_inductive(environment env,
ext.m_module_decls = cons(decl.m_name, ext.m_module_decls);
new_env = update(new_env, ext);
new_env = add_decl_pos_info(new_env, decl.m_name);
return add(new_env, std::make_shared<inductive_modification>(cdecl));
return add(new_env, std::make_shared<inductive_modification>(cdecl, env.trust_lvl()));
}
} // end of namespace module

Expand Down

0 comments on commit d9fb83d

Please sign in to comment.