Skip to content

Commit cdd3ec8

Browse files
author
Michal Medvecky
committed
we get qualified names from names provided rather than scope name
1 parent 740cb40 commit cdd3ec8

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/BytecodeDSLCompiler.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,21 @@ String getQualifiedName(Scope scope) {
143143
}
144144
}
145145

146+
String getQualifiedName(String name, Scope scope) {
147+
if (qualifiedNames.containsKey(scope)) {
148+
return qualifiedNames.get(scope);
149+
} else {
150+
String qualifiedName = computeQualifiedName(name, scope);
151+
qualifiedNames.put(scope, qualifiedName);
152+
return qualifiedName;
153+
}
154+
}
155+
146156
private String computeQualifiedName(Scope scope) {
147-
String qualifiedName = scope.getName();
157+
return computeQualifiedName(scope.getName(), scope);
158+
}
159+
160+
private String computeQualifiedName(String qualifiedName, Scope scope) {
148161
Scope parentScope = scopeEnvironment.lookupParent(scope);
149162
if (parentScope != null && parentScope != scopeEnvironment.getTopScope()) {
150163
if (parentScope.isTypeParam()) {
@@ -153,14 +166,14 @@ private String computeQualifiedName(Scope scope) {
153166
return qualifiedName;
154167
}
155168
}
156-
if (!((scope.isFunction() || scope.isClass()) && parentScope.getUseOfName(mangle(scope, scope.getName())).contains(Scope.DefUse.GlobalExplicit))) {
169+
if (!((scope.isFunction() || scope.isClass()) && parentScope.getUseOfName(mangle(scope, qualifiedName)).contains(Scope.DefUse.GlobalExplicit))) {
157170
// Qualify the name, unless it's a function/class and the parent declared the
158171
// name as a global (in which case the function/class doesn't belong to the
159172
// parent).
160173
if (parentScope.isFunction()) {
161-
qualifiedName = getQualifiedName(parentScope) + ".<locals>." + scope.getName();
174+
qualifiedName = getQualifiedName(parentScope) + ".<locals>." + qualifiedName;
162175
} else {
163-
qualifiedName = getQualifiedName(parentScope) + "." + scope.getName();
176+
qualifiedName = getQualifiedName(parentScope) + "." + qualifiedName;
164177
}
165178
}
166179
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ private BytecodeDSLCompilerResult compileRootNode(String name, ArgumentInfo argu
358358
}
359359
}
360360

361-
BytecodeDSLCodeUnit codeUnit = new BytecodeDSLCodeUnit(toTruffleStringUncached(name), toTruffleStringUncached(ctx.getQualifiedName(scope)),
361+
BytecodeDSLCodeUnit codeUnit = new BytecodeDSLCodeUnit(toTruffleStringUncached(name), toTruffleStringUncached(ctx.getQualifiedName(name, scope)),
362362
argumentInfo.argCount, argumentInfo.kwOnlyArgCount, argumentInfo.positionalOnlyArgCount,
363363
flags, orderedTruffleStringArray(names),
364364
orderedTruffleStringArray(varnames),
@@ -3672,7 +3672,7 @@ private void emitMakeFunction(BytecodeDSLCodeUnit codeUnit, Object scopeKey, Str
36723672
ArgumentsTy argsForDefaults, List<ParamAnnotation> annotations) {
36733673
TruffleString functionName = toTruffleStringUncached(name);
36743674
Scope targetScope = ctx.scopeEnvironment.lookupScope(scopeKey);
3675-
TruffleString qualifiedName = toTruffleStringUncached(ctx.getQualifiedName(targetScope));
3675+
TruffleString qualifiedName = toTruffleStringUncached(ctx.getQualifiedName(name, targetScope));
36763676

36773677
// Register these in the Python constants list.
36783678
addConstant(qualifiedName);

0 commit comments

Comments
 (0)