Skip to content

Commit 9b8021f

Browse files
author
Michal Medvecky
committed
functions qualified names calculation is not from Scope anymore
1 parent cdd3ec8 commit 9b8021f

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags_bytecode_dsl/test_funcattrs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ test.test_funcattrs.FunctionPropertiesTest.test___closure__ @ linux-x86_64
1414
test.test_funcattrs.FunctionPropertiesTest.test___code__ @ linux-x86_64
1515
test.test_funcattrs.FunctionPropertiesTest.test___globals__ @ linux-x86_64
1616
test.test_funcattrs.FunctionPropertiesTest.test___name__ @ linux-x86_64
17+
test.test_funcattrs.FunctionPropertiesTest.test___qualname__ @ linux-x86_64
1718
test.test_funcattrs.FunctionPropertiesTest.test_blank_func_defaults @ linux-x86_64
1819
test.test_funcattrs.FunctionPropertiesTest.test_cell_new @ linux-x86_64
1920
test.test_funcattrs.FunctionPropertiesTest.test_copying___code__ @ linux-x86_64

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags_bytecode_dsl/test_inspect.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,19 @@ test.test_inspect.test_inspect.TestGetattrStatic.test_no_dict_no_slots @ linux-x
9292
test.test_inspect.test_inspect.TestGetattrStatic.test_no_dict_no_slots_instance_member @ linux-x86_64
9393
test.test_inspect.test_inspect.TestGetattrStatic.test_property @ linux-x86_64
9494
test.test_inspect.test_inspect.TestGetattrStatic.test_slots @ linux-x86_64
95+
test.test_inspect.test_inspect.TestGetcallargsFunctions.test_keyword_only @ linux-x86_64
9596
test.test_inspect.test_inspect.TestGetcallargsFunctions.test_multiple_features @ linux-x86_64
9697
test.test_inspect.test_inspect.TestGetcallargsFunctions.test_plain @ linux-x86_64
9798
test.test_inspect.test_inspect.TestGetcallargsFunctions.test_varargs @ linux-x86_64
9899
test.test_inspect.test_inspect.TestGetcallargsFunctions.test_varkw @ linux-x86_64
99100
test.test_inspect.test_inspect.TestGetcallargsFunctions.test_varkw_only @ linux-x86_64
101+
test.test_inspect.test_inspect.TestGetcallargsMethods.test_keyword_only @ linux-x86_64
100102
test.test_inspect.test_inspect.TestGetcallargsMethods.test_multiple_features @ linux-x86_64
101103
test.test_inspect.test_inspect.TestGetcallargsMethods.test_plain @ linux-x86_64
102104
test.test_inspect.test_inspect.TestGetcallargsMethods.test_varargs @ linux-x86_64
103105
test.test_inspect.test_inspect.TestGetcallargsMethods.test_varkw @ linux-x86_64
104106
test.test_inspect.test_inspect.TestGetcallargsMethods.test_varkw_only @ linux-x86_64
107+
test.test_inspect.test_inspect.TestGetcallargsUnboundMethods.test_keyword_only @ linux-x86_64
105108
test.test_inspect.test_inspect.TestGetcallargsUnboundMethods.test_multiple_features @ linux-x86_64
106109
test.test_inspect.test_inspect.TestGetcallargsUnboundMethods.test_plain @ linux-x86_64
107110
test.test_inspect.test_inspect.TestGetcallargsUnboundMethods.test_varargs @ linux-x86_64

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags_bytecode_dsl/test_reprlib.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test.test_reprlib.ReprTests.test_container @ linux-x86_64
99
test.test_reprlib.ReprTests.test_descriptors @ linux-x86_64
1010
test.test_reprlib.ReprTests.test_frozenset @ linux-x86_64
1111
test.test_reprlib.ReprTests.test_instance @ linux-x86_64
12+
test.test_reprlib.ReprTests.test_lambda @ linux-x86_64
1213
test.test_reprlib.ReprTests.test_nesting @ linux-x86_64
1314
test.test_reprlib.ReprTests.test_numbers @ linux-x86_64
1415
test.test_reprlib.ReprTests.test_range @ linux-x86_64

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
*/
4141
package com.oracle.graal.python.compiler.bytecode_dsl;
4242

43+
import static com.oracle.graal.python.compiler.CompilationScope.AsyncFunction;
4344
import static com.oracle.graal.python.compiler.CompilationScope.Class;
45+
import static com.oracle.graal.python.compiler.CompilationScope.TypeParams;
4446
import static com.oracle.graal.python.compiler.SSTUtils.checkCaller;
4547
import static com.oracle.graal.python.compiler.SSTUtils.checkCompare;
4648
import static com.oracle.graal.python.compiler.SSTUtils.checkForbiddenArgs;
@@ -99,6 +101,7 @@
99101
import com.oracle.graal.python.pegparser.ParserCallbacks.WarningType;
100102
import com.oracle.graal.python.pegparser.scope.Scope;
101103
import com.oracle.graal.python.pegparser.scope.Scope.DefUse;
104+
import com.oracle.graal.python.pegparser.scope.ScopeEnvironment;
102105
import com.oracle.graal.python.pegparser.sst.AliasTy;
103106
import com.oracle.graal.python.pegparser.sst.ArgTy;
104107
import com.oracle.graal.python.pegparser.sst.ArgumentsTy;
@@ -187,6 +190,9 @@ public final class RootNodeCompiler implements BaseBytecodeDSLVisitor<BytecodeDS
187190
* {@link com.oracle.graal.python.pegparser.scope.ScopeEnvironment#maybeMangle(String, Scope, String)}.
188191
*/
189192
private final String privateName;
193+
private final RootNodeCompiler parent;
194+
private final boolean isRoot;
195+
private String qualName;
190196

191197
// Immutable after construction
192198
private final HashMap<String, Integer> varnames;
@@ -215,6 +221,12 @@ public RootNodeCompiler(BytecodeDSLCompilerContext ctx, RootNodeCompiler parent,
215221
this.startNode = rootNode;
216222
this.scope = ctx.scopeEnvironment.lookupScope(scopeKey);
217223
this.scopeType = getScopeType(scope, scopeKey);
224+
if (parent == null) {
225+
this.isRoot = true;
226+
} else {
227+
this.isRoot = false;
228+
}
229+
this.parent = parent;
218230
if (privateName != null) {
219231
this.privateName = privateName;
220232
} else if (scopeType == Class) {
@@ -319,6 +331,29 @@ private static TruffleString[] orderedTruffleStringArray(HashMap<String, Integer
319331
return orderedKeys(map, new TruffleString[0], PythonUtils::toTruffleStringUncached);
320332
}
321333

334+
private String getNewScopeQualName(String name, CompilationScope scopeType) {
335+
RootNodeCompiler parent = this.parent;
336+
if (parent != null && !parent.isRoot) {
337+
if (parent.scopeType == TypeParams && parent.parent != null && !parent.parent.isRoot) {
338+
parent = parent.parent;
339+
if (parent.parent.parent != null && parent.parent.parent.isRoot) {
340+
return name;
341+
}
342+
}
343+
if (!(EnumSet.of(CompilationScope.Function, AsyncFunction, Class).contains(scopeType) &&
344+
parent.scope.getUseOfName(ScopeEnvironment.mangle(parent.privateName, name)).contains(Scope.DefUse.GlobalExplicit))) {
345+
String base;
346+
if (EnumSet.of(CompilationScope.Function, AsyncFunction, CompilationScope.Lambda).contains(parent.scopeType)) {
347+
base = parent.qualName + ".<locals>";
348+
} else {
349+
base = parent.qualName;
350+
}
351+
return base + "." + name;
352+
}
353+
}
354+
return name;
355+
}
356+
322357
private BytecodeDSLCompilerResult compileRootNode(String name, ArgumentInfo argumentInfo, SourceRange sourceRange, BytecodeParser<Builder> parser) {
323358
BytecodeRootNodes<PBytecodeDSLRootNode> nodes = PBytecodeDSLRootNodeGen.create(ctx.language, BytecodeConfig.WITH_SOURCE, parser);
324359
List<PBytecodeDSLRootNode> nodeList = nodes.getNodes();
@@ -358,7 +393,9 @@ private BytecodeDSLCompilerResult compileRootNode(String name, ArgumentInfo argu
358393
}
359394
}
360395

361-
BytecodeDSLCodeUnit codeUnit = new BytecodeDSLCodeUnit(toTruffleStringUncached(name), toTruffleStringUncached(ctx.getQualifiedName(name, scope)),
396+
qualName = getNewScopeQualName(name, scopeType);
397+
398+
BytecodeDSLCodeUnit codeUnit = new BytecodeDSLCodeUnit(toTruffleStringUncached(name), toTruffleStringUncached(qualName),
362399
argumentInfo.argCount, argumentInfo.kwOnlyArgCount, argumentInfo.positionalOnlyArgCount,
363400
flags, orderedTruffleStringArray(names),
364401
orderedTruffleStringArray(varnames),
@@ -3672,7 +3709,7 @@ private void emitMakeFunction(BytecodeDSLCodeUnit codeUnit, Object scopeKey, Str
36723709
ArgumentsTy argsForDefaults, List<ParamAnnotation> annotations) {
36733710
TruffleString functionName = toTruffleStringUncached(name);
36743711
Scope targetScope = ctx.scopeEnvironment.lookupScope(scopeKey);
3675-
TruffleString qualifiedName = toTruffleStringUncached(ctx.getQualifiedName(name, targetScope));
3712+
TruffleString qualifiedName = codeUnit.qualname;
36763713

36773714
// Register these in the Python constants list.
36783715
addConstant(qualifiedName);

0 commit comments

Comments
 (0)