Skip to content

Commit 0bb568f

Browse files
author
Michal Medvecky
committed
remove original scope qualified names access and caching
1 parent 9b8021f commit 0bb568f

File tree

2 files changed

+46
-56
lines changed

2 files changed

+46
-56
lines changed

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

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static class BytecodeDSLCompilerContext {
9898
public final int futureLineNumber;
9999
public final ParserCallbacksImpl errorCallback;
100100
public final ScopeEnvironment scopeEnvironment;
101-
public final Map<Scope, String> qualifiedNames;
101+
// public final Map<Scope, String> qualifiedNames;
102102

103103
public BytecodeDSLCompilerContext(PythonLanguage language, PythonContext context, ModTy mod, Source source, int optimizationLevel,
104104
EnumSet<FutureFeature> futureFeatures, int futureLineNumber, ParserCallbacksImpl errorCallback, ScopeEnvironment scopeEnvironment) {
@@ -111,7 +111,7 @@ public BytecodeDSLCompilerContext(PythonLanguage language, PythonContext context
111111
this.futureLineNumber = futureLineNumber;
112112
this.errorCallback = errorCallback;
113113
this.scopeEnvironment = scopeEnvironment;
114-
this.qualifiedNames = new HashMap<>();
114+
// this.qualifiedNames = new HashMap<>();
115115
}
116116

117117
public String maybeMangle(String privateName, Scope scope, String name) {
@@ -133,52 +133,42 @@ String getClassName(Scope s) {
133133
return null;
134134
}
135135

136-
String getQualifiedName(Scope scope) {
137-
if (qualifiedNames.containsKey(scope)) {
138-
return qualifiedNames.get(scope);
139-
} else {
140-
String qualifiedName = computeQualifiedName(scope);
141-
qualifiedNames.put(scope, qualifiedName);
142-
return qualifiedName;
143-
}
144-
}
145-
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-
156-
private String computeQualifiedName(Scope scope) {
157-
return computeQualifiedName(scope.getName(), scope);
158-
}
159-
160-
private String computeQualifiedName(String qualifiedName, Scope scope) {
161-
Scope parentScope = scopeEnvironment.lookupParent(scope);
162-
if (parentScope != null && parentScope != scopeEnvironment.getTopScope()) {
163-
if (parentScope.isTypeParam()) {
164-
parentScope = scopeEnvironment.lookupParent(parentScope);
165-
if (parentScope == null || scopeEnvironment.lookupParent(parentScope) == null) {
166-
return qualifiedName;
167-
}
168-
}
169-
if (!((scope.isFunction() || scope.isClass()) && parentScope.getUseOfName(mangle(scope, qualifiedName)).contains(Scope.DefUse.GlobalExplicit))) {
170-
// Qualify the name, unless it's a function/class and the parent declared the
171-
// name as a global (in which case the function/class doesn't belong to the
172-
// parent).
173-
if (parentScope.isFunction()) {
174-
qualifiedName = getQualifiedName(parentScope) + ".<locals>." + qualifiedName;
175-
} else {
176-
qualifiedName = getQualifiedName(parentScope) + "." + qualifiedName;
177-
}
178-
}
179-
}
180-
181-
return qualifiedName;
182-
}
136+
// String getQualifiedName(Scope scope) {
137+
// if (qualifiedNames.containsKey(scope)) {
138+
// return qualifiedNames.get(scope);
139+
// } else {
140+
// String qualifiedName = computeQualifiedName(scope);
141+
// qualifiedNames.put(scope, qualifiedName);
142+
// return qualifiedName;
143+
// }
144+
// }
145+
//
146+
// private String computeQualifiedName(Scope scope) {
147+
// return computeQualifiedName(scope.getName(), scope);
148+
// }
149+
//
150+
// private String computeQualifiedName(String qualifiedName, Scope scope) {
151+
// Scope parentScope = scopeEnvironment.lookupParent(scope);
152+
// if (parentScope != null && parentScope != scopeEnvironment.getTopScope()) {
153+
// if (parentScope.isTypeParam()) {
154+
// parentScope = scopeEnvironment.lookupParent(parentScope);
155+
// if (parentScope == null || scopeEnvironment.lookupParent(parentScope) == null) {
156+
// return qualifiedName;
157+
// }
158+
// }
159+
// if (!((scope.isFunction() || scope.isClass()) && parentScope.getUseOfName(mangle(scope, qualifiedName)).contains(Scope.DefUse.GlobalExplicit))) {
160+
// // Qualify the name, unless it's a function/class and the parent declared the
161+
// // name as a global (in which case the function/class doesn't belong to the
162+
// // parent).
163+
// if (parentScope.isFunction()) {
164+
// qualifiedName = getQualifiedName(parentScope) + ".<locals>." + qualifiedName;
165+
// } else {
166+
// qualifiedName = getQualifiedName(parentScope) + "." + qualifiedName;
167+
// }
168+
// }
169+
// }
170+
//
171+
// return qualifiedName;
172+
// }
183173
}
184174
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ private static TruffleString[] orderedTruffleStringArray(HashMap<String, Integer
334334
private String getNewScopeQualName(String name, CompilationScope scopeType) {
335335
RootNodeCompiler parent = this.parent;
336336
if (parent != null && !parent.isRoot) {
337-
if (parent.scopeType == TypeParams && parent.parent != null && !parent.parent.isRoot) {
337+
if (parent.scopeType == TypeParams && parent.parent != null && parent.parent.parent != null) {
338338
parent = parent.parent;
339-
if (parent.parent.parent != null && parent.parent.parent.isRoot) {
339+
if (parent.parent.parent != null && parent.parent.parent.parent == null) {
340340
return name;
341341
}
342342
}
@@ -355,6 +355,8 @@ private String getNewScopeQualName(String name, CompilationScope scopeType) {
355355
}
356356

357357
private BytecodeDSLCompilerResult compileRootNode(String name, ArgumentInfo argumentInfo, SourceRange sourceRange, BytecodeParser<Builder> parser) {
358+
qualName = getNewScopeQualName(name, scopeType);
359+
358360
BytecodeRootNodes<PBytecodeDSLRootNode> nodes = PBytecodeDSLRootNodeGen.create(ctx.language, BytecodeConfig.WITH_SOURCE, parser);
359361
List<PBytecodeDSLRootNode> nodeList = nodes.getNodes();
360362
assert nodeList.size() == 1;
@@ -393,8 +395,6 @@ private BytecodeDSLCompilerResult compileRootNode(String name, ArgumentInfo argu
393395
}
394396
}
395397

396-
qualName = getNewScopeQualName(name, scopeType);
397-
398398
BytecodeDSLCodeUnit codeUnit = new BytecodeDSLCodeUnit(toTruffleStringUncached(name), toTruffleStringUncached(qualName),
399399
argumentInfo.argCount, argumentInfo.kwOnlyArgCount, argumentInfo.positionalOnlyArgCount,
400400
flags, orderedTruffleStringArray(names),
@@ -930,7 +930,7 @@ public BytecodeDSLCompilerResult compileClassDefBody(StmtTy.ClassDef node) {
930930
endStoreLocal("__module__", b);
931931

932932
beginStoreLocal("__qualname__", b);
933-
emitPythonConstant(toTruffleStringUncached(ctx.getQualifiedName(scope)), b);
933+
emitPythonConstant(toTruffleStringUncached(this.qualName), b);
934934
endStoreLocal("__qualname__", b);
935935

936936
if (node.isGeneric()) {
@@ -1145,7 +1145,7 @@ public BytecodeDSLCompilerResult visit(ExprTy.SetComp node) {
11451145

11461146
@Override
11471147
public BytecodeDSLCompilerResult visit(ExprTy.GeneratorExp node) {
1148-
return buildComprehensionCodeUnit(node, node.generators, "<generator>",
1148+
return buildComprehensionCodeUnit(node, node.generators, "<genexpr>",
11491149
null,
11501150
(statementCompiler, collection) -> emitYield((statementCompiler_) -> node.element.accept(statementCompiler_), statementCompiler));
11511151
}
@@ -2138,7 +2138,7 @@ public Void visit(ExprTy.GeneratorExp node) {
21382138
boolean newStatement = beginSourceSection(node, b);
21392139

21402140
b.beginCallUnaryMethod();
2141-
emitMakeFunction(node, "<generator>", COMPREHENSION_ARGS);
2141+
emitMakeFunction(node, "<genexpr>", COMPREHENSION_ARGS);
21422142
node.generators[0].iter.accept(this);
21432143
b.endCallUnaryMethod();
21442144

0 commit comments

Comments
 (0)