Skip to content

Conversation

@ahomescu
Copy link
Contributor

@ahomescu ahomescu commented Nov 21, 2025

Rename identically-named identifier (appending a suffix) for identifiers with different definitions, e.g.

    pub const EINPROGRESS: ::core::ffi::c_int = 115;
    pub const EINPROGRESS: ::core::ffi::c_int = 115 as ::core::ffi::c_int;

from libxml2. The transform now renames the second definition to EINPROGRESS_1 and updates all uses.

This is a copy of #1463 since GitHub closed that one after I reordered the branches.

@ahomescu ahomescu force-pushed the ahomescu/fix_reorganize_collisions branch from 774e1be to c5185d5 Compare November 21, 2025 02:33
@ahomescu ahomescu changed the base branch from master to ahomescu/ci_cache_key_runner November 21, 2025 02:35
Copy link
Contributor

@kkysen kkysen left a comment

Choose a reason for hiding this comment

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

Do we want to keep these as separate definitions when their values are the same? Is it better to try to fix this from the transpiler side?

@fw-immunant
Copy link
Contributor

Do we want to keep these as separate definitions when their values are the same? Is it better to try to fix this from the transpiler side?

I don't have a preference on whether we merge definitions like these, but separately it would be nice to improve this on the transpiler side, because its root cause is the same as why our handling of switch cases emits integers rather than uses of consts when cases reference #define'd values. But that fix could be a bit tricky; we'd need some special handling to keep types in agreement everywhere.

Base automatically changed from ahomescu/ci_cache_key_runner to master November 21, 2025 19:44
@ahomescu ahomescu force-pushed the ahomescu/fix_reorganize_collisions branch from c5185d5 to f8b7c3b Compare November 21, 2025 22:13
@ahomescu
Copy link
Contributor Author

I didn't touch the transpiler because afaict the two values of EINPROGRESS in the example come in as completely different clang AST nodes. If you want to unify the two implementations, go for it, but that does feel like a more significant refactoring to me. Meanwhile, I think the current refactoring fix is also worthwhile to land (otherwise we might hit the problem in other places as well).

@kkysen
Copy link
Contributor

kkysen commented Nov 21, 2025

Maybe there should be a warning about this? Is it at all possible to check if the actual values are the same and merge them in that case? Or maybe run remove redundant casts first.

@kkysen kkysen changed the title Fix name collisions in reorganize_definitions refactor: Fix name collisions in reorganize_definitions Nov 21, 2025
@ahomescu
Copy link
Contributor Author

Maybe there should be a warning about this?

I could add a warning, sure.

Is it at all possible to check if the actual values are the same and merge them in that case?

We would basically need to run a compile-time evaluator for that, and that's if the expressions are even constant in the first place.

Or maybe run remove redundant casts first.

Sure, but that only fixes the subset where casts are the problem. What about e.g. comparing 42 with 42 + 0?

@kkysen
Copy link
Contributor

kkysen commented Nov 21, 2025

Or maybe run remove redundant casts first.

Sure, but that only fixes the subset where casts are the problem. What about e.g. comparing 42 with 42 + 0?

Yeah, we definitely need the general fix as done here, but I think the majority of these that the transpiler produces will be from casts. So we should do that, too (run remove redundant casts first).

Allow multiple different definitions of the same identifier.
Disambiguate them by appending a numeric _N suffix to each
identifier after the 0-th one.
@ahomescu ahomescu force-pushed the ahomescu/fix_reorganize_collisions branch from f8b7c3b to 0bba09a Compare November 21, 2025 23:58
@ahomescu
Copy link
Contributor Author

I added a warning.

@ahomescu ahomescu merged commit df2af7f into master Nov 22, 2025
5 checks passed
@kkysen kkysen deleted the ahomescu/fix_reorganize_collisions branch November 22, 2025 00:28
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.

5 participants