Skip to content

Commit

Permalink
HIR ConstEval - Catch panics (slightly), add execution numbers to logs
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Jan 3, 2024
1 parent e80d3d7 commit 144ed3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/hir_conv/constant_evaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,8 @@ namespace HIR {

using namespace ::MIR::eval;

unsigned int Evaluator::s_next_eval_index = 0;

Evaluator::CsePtr::~CsePtr()
{
if( m_inner ) {
Expand Down Expand Up @@ -1735,7 +1737,7 @@ namespace HIR {
void Evaluator::run_statement(::MIR::eval::CallStackEntry& local_state, const ::MIR::Statement& stmt)
{
const auto& state = local_state.state;
DEBUG("F" << local_state.frame_index << " " << state << stmt);
DEBUG("E" << this->eval_index << " F" << local_state.frame_index << " " << state << stmt);

TU_MATCH_HDRA( (stmt), { )
TU_ARMA(Assign, e) {
Expand Down Expand Up @@ -2137,7 +2139,7 @@ namespace HIR {
unsigned Evaluator::run_terminator(::MIR::eval::CallStackEntry& local_state, const ::MIR::Terminator& terminator)
{
const auto& state = local_state.state;
DEBUG("F" << local_state.frame_index << " " << state << terminator);
DEBUG("E" << this->eval_index << " F" << local_state.frame_index << " " << state << terminator);

TU_MATCH_HDRA( (terminator), {)
default:
Expand Down Expand Up @@ -2426,6 +2428,17 @@ namespace HIR {

// TODO: Set m_const during parse and check here

if( !fcn.m_code && !fcn.m_code.m_mir ) {
if( fcn.m_linkage.name == "" ) {
}
else if( fcn.m_linkage.name == "panic_impl" ) {
MIR_TODO(state, "panic in constant evaluation");
}
else {
MIR_TODO(state, "Call extern function `" << fcn.m_linkage.name << "`");
}
}

// Call by invoking evaluate_constant on the function
const auto* mir = this->resolve.m_crate.get_or_gen_mir( ::HIR::ItemPath(*fcnp), fcn );
MIR_ASSERT(state, mir, "No MIR for function " << fcnp);
Expand Down
4 changes: 4 additions & 0 deletions src/hir_conv/constant_evaluation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ struct Evaluator
Span root_span;
StaticTraitResolve resolve;
Newval& nvs;
unsigned int eval_index;
unsigned int num_frames;
// Note: Pointer is needed to maintain internal reference stability
::std::vector<CsePtr> call_stack;

static unsigned s_next_eval_index;

public:
Evaluator(const Span& sp, const ::HIR::Crate& crate, Newval& nvs):
root_span(sp),
resolve(crate),
nvs( nvs )
, eval_index(s_next_eval_index++)
, num_frames(0)
{
}
Expand Down

0 comments on commit 144ed3d

Please sign in to comment.