Skip to content

Conversation

@NikLeberg
Copy link
Contributor

I've extended our solution to #1347 with the capability to handle a range of constant record elements.
I don't think a slice i.e. association subkind A_SLICE is possible here. So I've left that out.
Cheers, Nik

@NikLeberg NikLeberg force-pushed the ranged_int_fold branch 2 times, most recently from e382d60 to 40d8503 Compare November 28, 2025 11:11
@NikLeberg
Copy link
Contributor Author

CI found another issue. I forgot to check if the tree node is already a T_LITERAL, T_STRING or T_REF and skip the eval if this is the case. I already pushed a fixup.

But now I'm not terribly happy about the function name:

static tree_t simp_case_choice(tree_t t, simp_ctx_t *ctx);

Because it suggests that it handles the whole choice. But it only handles the name or left/right subnode. But naming wise in simp.c all functions handle parts of VHDL syntax and not tree specific nodes.
Maybe a new function in eval.c would be better?

tree_t eval_try_fold_locally_static(tree_t expr, unit_registry_t *ur, mir_context_t *mc);

What would you prefer?

@nickg
Copy link
Owner

nickg commented Nov 29, 2025

But naming wise in simp.c all functions handle parts of VHDL syntax and not tree specific nodes.

Well most are but there are some exceptions.

What would you prefer?

How about simp_static_expr() but otherwise keep it the same.

Comment on lines +964 to +966
tree_t rf = simp_case_choice(r, ctx);
if (r != rf)
tree_set_right(range, rf);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tree_t rf = simp_case_choice(r, ctx);
if (r != rf)
tree_set_right(range, rf);
tree_set_right(range, simp_case_choice(r, ctx));

(and elsewhere)

There's no harm in setting it to the same value and looks less noisy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd agree and that was actually how I initially did it. But with that I get several crashes of Fatal: Write to object in frozen arena. Is there something else I need to account for?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that happens because simp_case is called from simp_tree_global as well simp_tree_local (I can't remember why) and the T_ALTERNATIVE won't necessarily have a writable copy during elaboration.

I think you could probably fix that by moving this logic to a new simp_case_alternative() that's called from simp_tree_local only for T_ALTERNATIVE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants