Skip to content

Commit

Permalink
Handle gengtype annotations in rust-constexpr.cc
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* backend/rust-constexpr.cc:
	Include gt-rust-rust-constexpr.h.
	(struct constexpr_call_hasher): Rename to ...
	(struct rust_constexpr_call_hasher): ... here.
	(struct constexpr_fundef_hasher): Rename to ...
	(struct rust_constexpr_fundef_hasher): ... here.
	* config-lang.in: Add rust-constexpr.cc to gtfiles.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 authored and philberty committed Aug 18, 2023
1 parent b1dd53f commit 79a7f07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions gcc/rust/backend/rust-constexpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct GTY ((for_user)) constexpr_call
bool manifestly_const_eval;
};

struct constexpr_call_hasher : ggc_ptr_hash<constexpr_call>
struct rust_constexpr_call_hasher : ggc_ptr_hash<constexpr_call>
{
static hashval_t hash (constexpr_call *);
static bool equal (constexpr_call *, constexpr_call *);
Expand Down Expand Up @@ -201,7 +201,7 @@ struct constexpr_ctx
bool manifestly_const_eval;
};

struct constexpr_fundef_hasher : ggc_ptr_hash<constexpr_fundef>
struct rust_constexpr_fundef_hasher : ggc_ptr_hash<constexpr_fundef>
{
static hashval_t hash (const constexpr_fundef *);
static bool equal (const constexpr_fundef *, const constexpr_fundef *);
Expand All @@ -210,15 +210,16 @@ struct constexpr_fundef_hasher : ggc_ptr_hash<constexpr_fundef>
/* This table holds all constexpr function definitions seen in
the current translation unit. */

static GTY (()) hash_table<constexpr_fundef_hasher> *constexpr_fundef_table;
static GTY (())
hash_table<rust_constexpr_fundef_hasher> *constexpr_fundef_table;

/* Utility function used for managing the constexpr function table.
Return true if the entries pointed to by P and Q are for the
same constexpr function. */

inline bool
constexpr_fundef_hasher::equal (const constexpr_fundef *lhs,
const constexpr_fundef *rhs)
rust_constexpr_fundef_hasher::equal (const constexpr_fundef *lhs,
const constexpr_fundef *rhs)
{
return lhs->decl == rhs->decl;
}
Expand All @@ -227,7 +228,7 @@ constexpr_fundef_hasher::equal (const constexpr_fundef *lhs,
Return a hash value for the entry pointed to by Q. */

inline hashval_t
constexpr_fundef_hasher::hash (const constexpr_fundef *fundef)
rust_constexpr_fundef_hasher::hash (const constexpr_fundef *fundef)
{
return DECL_UID (fundef->decl);
}
Expand Down Expand Up @@ -343,12 +344,12 @@ uid_sensitive_constexpr_evaluation_checker::evaluation_restricted_p () const
/* A table of all constexpr calls that have been evaluated by the
compiler in this translation unit. */

static GTY (()) hash_table<constexpr_call_hasher> *constexpr_call_table;
static GTY (()) hash_table<rust_constexpr_call_hasher> *constexpr_call_table;

/* Compute a hash value for a constexpr call representation. */

inline hashval_t
constexpr_call_hasher::hash (constexpr_call *info)
rust_constexpr_call_hasher::hash (constexpr_call *info)
{
return info->hash;
}
Expand All @@ -358,15 +359,15 @@ constexpr_call_hasher::hash (constexpr_call *info)
Otherwise, return false. */

bool
constexpr_call_hasher::equal (constexpr_call *lhs, constexpr_call *rhs)
rust_constexpr_call_hasher::equal (constexpr_call *lhs, constexpr_call *rhs)
{
if (lhs == rhs)
return true;
if (lhs->hash != rhs->hash)
return false;
if (lhs->manifestly_const_eval != rhs->manifestly_const_eval)
return false;
if (!constexpr_fundef_hasher::equal (lhs->fundef, rhs->fundef))
if (!rust_constexpr_fundef_hasher::equal (lhs->fundef, rhs->fundef))
return false;
return rs_tree_equal (lhs->bindings, rhs->bindings);
}
Expand All @@ -377,7 +378,8 @@ static void
maybe_initialize_constexpr_call_table (void)
{
if (constexpr_call_table == NULL)
constexpr_call_table = hash_table<constexpr_call_hasher>::create_ggc (101);
constexpr_call_table
= hash_table<rust_constexpr_call_hasher>::create_ggc (101);
}

/* During constexpr CALL_EXPR evaluation, to avoid issues with sharing when
Expand Down Expand Up @@ -3462,7 +3464,7 @@ eval_call_expression (const constexpr_ctx *ctx, tree t, bool lval,
constexpr_call *entry = NULL;
if (depth_ok && !non_constant_args && ctx->strict)
{
new_call.hash = constexpr_fundef_hasher::hash (new_call.fundef);
new_call.hash = rust_constexpr_fundef_hasher::hash (new_call.fundef);
new_call.hash = iterative_hash_object (new_call.bindings, new_call.hash);
new_call.hash
= iterative_hash_object (ctx->manifestly_const_eval, new_call.hash);
Expand Down Expand Up @@ -4583,7 +4585,7 @@ register_constexpr_fundef (const constexpr_fundef &value)
/* Create the constexpr function table if necessary. */
if (constexpr_fundef_table == NULL)
constexpr_fundef_table
= hash_table<constexpr_fundef_hasher>::create_ggc (101);
= hash_table<rust_constexpr_fundef_hasher>::create_ggc (101);

constexpr_fundef **slot = constexpr_fundef_table->find_slot (
const_cast<constexpr_fundef *> (&value), INSERT);
Expand Down Expand Up @@ -6474,7 +6476,9 @@ fold_non_dependent_init (tree t, tsubst_flags_t /*=tf_warning_or_error*/,
return maybe_constant_init (t, object, manifestly_const_eval);
}

// #include "gt-rust-rust-constexpr.h"

} // namespace Compile
} // namespace Rust

using namespace Rust::Compile;

#include "gt-rust-rust-constexpr.h"
2 changes: 1 addition & 1 deletion gcc/rust/config-lang.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ build_by_default="no"

target_libs="target-libgrust"

gtfiles="\$(srcdir)/rust/rust-lang.cc"
gtfiles="\$(srcdir)/rust/rust-lang.cc \$(srcdir)/rust/backend/rust-constexpr.cc"

0 comments on commit 79a7f07

Please sign in to comment.