Skip to content

[FileFormats] accept a tuple of replacements in create_unique_names - #3147

Open
blegat wants to merge 1 commit into
bl/juliac-trace-onlyfrom
bl/juliac-unique-names
Open

blegat wants to merge 1 commit into
bl/juliac-trace-onlyfrom
bl/juliac-unique-names

Conversation

@blegat

@blegat blegat commented Nov 16, 2026

Copy link
Copy Markdown
Member

If the tracing does not contain a case where two variables have the same name. When you then try to write a MOF file with names clash you get an error because you are missing methods (this happens in the JuMPy tests for instance).
The reason is that replacements is a Vector{Function} so in the following:

new_name = _replace(
original_name != "" ? original_name : "x$(index.value)",
replacements,
)
if new_name in added_names
# We found a duplicate name. We could just append a string like "_",
# but we're going to be clever and loop through the integers to name
# them appropriately. Thus, if we have three variables named x,
# we'll end up with variables named x, x_1, and x_2.
i = 1
tmp_name = string(new_name, "_", i)

new_name is inferred to Any. During tracing, since the names are different we don't enter the if clause and since new_name is inferred to Any, JuliaC don't know which methods is needed for string so then when we run the executable with a model containing duplicate names, we enter that if clause and we don't have the method we need.

We could require of the user to add duplicate names in tracing but this seems like an instance where the tradeoff is in favor if instead fixing it here. MOF also always calls this method with replacements = () so it's not like Vector{Function} is preventing the compiler to over specialize.

@blegat
blegat added this pull request to stack #3148 November 16, 2026 08:02
With a Vector{Function}, the replaced names are inferred as Any so the renaming
of duplicate names is dynamically dispatched, which a trimmed binary may not
contain. The default is now an empty tuple, with which names are inferred to be
Strings.
@blegat
blegat force-pushed the bl/juliac-unique-names branch from 840a40e to 93d095d Compare November 16, 2026 08:09

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant