Skip to content

Commit

Permalink
Make name mangling stateless again.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
petervdonovan committed Jun 4, 2023
1 parent a06d23b commit cd4b98b
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
public record TypeParameterizedReactor(Reactor reactor, Map<String, Type> typeArgs) {

private static final Map<TypeParameterizedReactor, String> uniqueNames = new HashMap<>();
private static final Map<String, Integer> nameCounts = new HashMap<>();

/**
* Construct the TPR corresponding to the given instantiation which syntactically appears within
* the definition corresponding to {@code parent}.
Expand Down Expand Up @@ -95,17 +92,8 @@ public InferredType resolveType(InferredType t) {
* 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();
var resolved = ASTUtils.toDefinition(reactor);
return "_" + resolved.getName().toLowerCase() + (typeArgs.hashCode() + resolved.eResource().getURI().hashCode() * 31);
}

@Override
Expand Down

0 comments on commit cd4b98b

Please sign in to comment.