From c3e69e17645a16d981827f8a8ef07e85d732aac1 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sat, 3 Jun 2023 18:28:37 -0700 Subject: [PATCH] Make name mangling stateless again. The assignment of mangled names is too complex when compiling several distinct programs in the same JAR execution because it causes them to interact with each other by changing the number of reactors that have the same name. We can patch this up, but it is safer and easier to just eliminate the global variables. It will make the generated code uglier, but maybe life is too short to worry about that. --- .../generator/c/TypeParameterizedReactor.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java index 758e1ec6cf..a9be5739c5 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -18,9 +18,6 @@ */ public record TypeParameterizedReactor(Reactor reactor, Map typeArgs) { - private static final Map uniqueNames = new HashMap<>(); - private static final Map nameCounts = new HashMap<>(); - /** * Construct the TPR corresponding to the given instantiation which syntactically appears within * the definition corresponding to {@code parent}. @@ -94,18 +91,9 @@ public InferredType resolveType(InferredType t) { * Return a name that is unique to this TypeParameterizedReactor (up to structural equality) and * that is prefixed with exactly one underscore and that does not contain any upper-case letters. */ - public synchronized String uniqueName() { - String name = reactor.getName().toLowerCase(); - if (uniqueNames.containsKey(this)) return uniqueNames.get(this); - if (nameCounts.containsKey(name)) { - int currentCount = nameCounts.get(name); - nameCounts.put(name, currentCount + 1); - uniqueNames.put(this, "_" + name + currentCount); - return uniqueName(); - } - nameCounts.put(name, 1); - uniqueNames.put(this, "_" + name); - return uniqueName(); + public String uniqueName() { + var resolved = ASTUtils.toDefinition(reactor); + return "_" + resolved.getName().toLowerCase() + (typeArgs.hashCode() + resolved.eResource().getURI().hashCode() * 31); } @Override