fix: do not invoke add_extern for declarations marked with implementedBy

This commit is contained in:
Leonardo de Moura 2022-01-14 20:27:50 -08:00
parent 9499cea2a5
commit 6ea0aaf35a
3 changed files with 8 additions and 5 deletions

View file

@ -20,6 +20,7 @@ Author: Leonardo de Moura
#include "library/compiler/erase_irrelevant.h"
#include "library/compiler/specialize.h"
#include "library/compiler/eager_lambda_lifting.h"
#include "library/compiler/implemented_by_attribute.h"
#include "library/compiler/lambda_lifting.h"
#include "library/compiler/extract_closed.h"
#include "library/compiler/reduce_arity.h"
@ -185,7 +186,9 @@ environment compile(environment const & env, options const & opts, names cs) {
if (length(cs) == 1) {
name c = get_real_name(head(cs));
if (skip_code_generation(env, c)) {
if (has_implemented_by_attribute(env, c))
return env;
if (is_extern_or_init_constant(env, c)) {
/* Generate boxed version for extern/native constant if needed. */
return ir::add_extern(env, c);
}

View file

@ -31,8 +31,8 @@ bool is_extern_constant(environment const & env, name const & c) {
return static_cast<bool>(get_extern_attr_data(env, c));
}
bool skip_code_generation(environment const & env, name const & c) {
if (is_extern_constant(env, c) || has_implemented_by_attribute(env, c)) {
bool is_extern_or_init_constant(environment const & env, name const & c) {
if (is_extern_constant(env, c)) {
return true;
} else if (auto info = env.find(c)) {
// `declarations marked with `init`
@ -81,7 +81,7 @@ bool get_extern_borrowed_info(environment const & env, name const & c, buffer<bo
}
optional<expr> get_extern_constant_ll_type(environment const & env, name const & c) {
if (skip_code_generation(env, c)) {
if (is_extern_or_init_constant(env, c)) {
unsigned arity = 0;
expr type = env.get(c).get_type();
type_checker::state st(env);

View file

@ -9,7 +9,7 @@ Authors: Leonardo de Moura
#include "kernel/environment.h"
namespace lean {
bool is_extern_constant(environment const & env, name const & c);
bool skip_code_generation(environment const & env, name const & c);
bool is_extern_or_init_constant(environment const & env, name const & c);
optional<expr> get_extern_constant_ll_type(environment const & env, name const & c);
optional<unsigned> get_extern_constant_arity(environment const & env, name const & c);
typedef object_ref extern_attr_data_value;