Skip to content

Commit ff37ad0

Browse files
committed
Remove PFunction.enclosingClassName
1 parent c992e4e commit ff37ad0

File tree

7 files changed

+44
-52
lines changed

7 files changed

+44
-52
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import static com.oracle.graal.python.nodes.BuiltinNames.BYTEARRAY;
3535
import static com.oracle.graal.python.nodes.BuiltinNames.BYTES;
3636
import static com.oracle.graal.python.nodes.BuiltinNames.CLASSMETHOD;
37-
import static com.oracle.graal.python.nodes.BuiltinNames.INSTANCEMETHOD;
3837
import static com.oracle.graal.python.nodes.BuiltinNames.COMPLEX;
3938
import static com.oracle.graal.python.nodes.BuiltinNames.DICT;
4039
import static com.oracle.graal.python.nodes.BuiltinNames.DICT_ITEMITERATOR;
@@ -47,6 +46,7 @@
4746
import static com.oracle.graal.python.nodes.BuiltinNames.FLOAT;
4847
import static com.oracle.graal.python.nodes.BuiltinNames.FROZENSET;
4948
import static com.oracle.graal.python.nodes.BuiltinNames.GETSET_DESCRIPTOR;
49+
import static com.oracle.graal.python.nodes.BuiltinNames.INSTANCEMETHOD;
5050
import static com.oracle.graal.python.nodes.BuiltinNames.INT;
5151
import static com.oracle.graal.python.nodes.BuiltinNames.LIST;
5252
import static com.oracle.graal.python.nodes.BuiltinNames.MAP;
@@ -181,7 +181,6 @@
181181
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetItemsizeNode;
182182
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroNode;
183183
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode;
184-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
185184
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsAcceptableBaseNode;
186185
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
187186
import com.oracle.graal.python.lib.CanBeDoubleNode;
@@ -2028,59 +2027,51 @@ PZip zip(VirtualFrame frame, Object cls, Object[] args,
20282027
@Builtin(name = "function", minNumOfPositionalArgs = 3, maxNumOfPositionalArgs = 6, constructsClass = PythonBuiltinClassType.PFunction, isPublic = false)
20292028
@GenerateNodeFactory
20302029
public abstract static class FunctionNode extends PythonBuiltinNode {
2031-
@Child private GetNameNode getNameNode;
2032-
20332030
@Specialization
2034-
public PFunction function(Object cls, PCode code, PDict globals, String name, @SuppressWarnings("unused") PNone defaultArgs, @SuppressWarnings("unused") PNone closure) {
2035-
return factory().createFunction(name, getTypeName(cls), code, globals, null);
2031+
public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, String name, @SuppressWarnings("unused") PNone defaultArgs,
2032+
@SuppressWarnings("unused") PNone closure) {
2033+
return factory().createFunction(name, code, globals, null);
20362034
}
20372035

20382036
@Specialization
2039-
public PFunction function(Object cls, PCode code, PDict globals, @SuppressWarnings("unused") PNone name, @SuppressWarnings("unused") PNone defaultArgs, PTuple closure,
2037+
public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, @SuppressWarnings("unused") PNone name, @SuppressWarnings("unused") PNone defaultArgs,
2038+
PTuple closure,
20402039
@Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode) {
2041-
return factory().createFunction("<lambda>", getTypeName(cls), code, globals, PCell.toCellArray(getObjectArrayNode.execute(closure)));
2040+
return factory().createFunction("<lambda>", code, globals, PCell.toCellArray(getObjectArrayNode.execute(closure)));
20422041
}
20432042

20442043
@Specialization
2045-
public PFunction function(Object cls, PCode code, PDict globals, @SuppressWarnings("unused") PNone name, @SuppressWarnings("unused") PNone defaultArgs,
2044+
public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, @SuppressWarnings("unused") PNone name, @SuppressWarnings("unused") PNone defaultArgs,
20462045
@SuppressWarnings("unused") PNone closure,
20472046
@SuppressWarnings("unused") @Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode) {
2048-
return factory().createFunction("<lambda>", getTypeName(cls), code, globals, null);
2047+
return factory().createFunction("<lambda>", code, globals, null);
20492048
}
20502049

20512050
@Specialization
2052-
public PFunction function(Object cls, PCode code, PDict globals, String name, @SuppressWarnings("unused") PNone defaultArgs, PTuple closure,
2051+
public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, String name, @SuppressWarnings("unused") PNone defaultArgs, PTuple closure,
20532052
@Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode) {
2054-
return factory().createFunction(name, getTypeName(cls), code, globals, PCell.toCellArray(getObjectArrayNode.execute(closure)));
2053+
return factory().createFunction(name, code, globals, PCell.toCellArray(getObjectArrayNode.execute(closure)));
20552054
}
20562055

20572056
@Specialization
2058-
public PFunction function(Object cls, PCode code, PDict globals, String name, PTuple defaultArgs, @SuppressWarnings("unused") PNone closure,
2057+
public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, String name, PTuple defaultArgs, @SuppressWarnings("unused") PNone closure,
20592058
@Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode) {
20602059
// TODO split defaults of positional args from kwDefaults
2061-
return factory().createFunction(name, getTypeName(cls), code, globals, getObjectArrayNode.execute(defaultArgs), null, null);
2060+
return factory().createFunction(name, code, globals, getObjectArrayNode.execute(defaultArgs), null, null);
20622061
}
20632062

20642063
@Specialization
2065-
public PFunction function(Object cls, PCode code, PDict globals, String name, PTuple defaultArgs, PTuple closure,
2064+
public PFunction function(@SuppressWarnings("unused") Object cls, PCode code, PDict globals, String name, PTuple defaultArgs, PTuple closure,
20662065
@Shared("getObjectArrayNode") @Cached GetObjectArrayNode getObjectArrayNode) {
20672066
// TODO split defaults of positional args from kwDefaults
2068-
return factory().createFunction(name, getTypeName(cls), code, globals, getObjectArrayNode.execute(defaultArgs), null, PCell.toCellArray(getObjectArrayNode.execute(closure)));
2067+
return factory().createFunction(name, code, globals, getObjectArrayNode.execute(defaultArgs), null, PCell.toCellArray(getObjectArrayNode.execute(closure)));
20692068
}
20702069

20712070
@Fallback
20722071
@SuppressWarnings("unused")
2073-
public PFunction function(Object cls, Object code, Object globals, Object name, Object defaultArgs, Object closure) {
2072+
public PFunction function(@SuppressWarnings("unused") Object cls, Object code, Object globals, Object name, Object defaultArgs, Object closure) {
20742073
throw raise(TypeError, ErrorMessages.FUNC_CONSTRUCTION_NOT_SUPPORTED, cls, code, globals, name, defaultArgs, closure);
20752074
}
2076-
2077-
private String getTypeName(Object typeObj) {
2078-
if (getNameNode == null) {
2079-
CompilerDirectives.transferToInterpreterAndInvalidate();
2080-
getNameNode = insert(TypeNodes.GetNameNode.create());
2081-
}
2082-
return getNameNode.execute(typeObj);
2083-
}
20842075
}
20852076

20862077
// builtin-function(method-def, self, module)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ public Object doIt(VirtualFrame frame, PFunction func) {
443443
public synchronized PFunction convertToBuiltin(PFunction func) {
444444
FunctionRootNode rootNode = (FunctionRootNode) CodeNodes.GetCodeRootNode.getUncached().execute(func.getCode());
445445
rootNode.setPythonInternal(true);
446+
func.setBuiltin(true);
446447
return func;
447448
}
448449
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,30 @@
5454
public final class PFunction extends PythonObject {
5555
private String name;
5656
private String qualname;
57-
private final String enclosingClassName;
5857
private final Assumption codeStableAssumption;
5958
private final Assumption defaultsStableAssumption;
6059
private final PythonObject globals;
60+
@CompilationFinal private boolean isBuiltin;
6161
@CompilationFinal(dimensions = 1) private final PCell[] closure;
6262
@CompilationFinal private PCode code;
6363
@CompilationFinal(dimensions = 1) private Object[] defaultValues;
6464
@CompilationFinal(dimensions = 1) private PKeyword[] kwDefaultValues;
6565

66-
public PFunction(PythonLanguage lang, String name, String qualname, String enclosingClassName, PCode code, PythonObject globals, PCell[] closure) {
67-
this(lang, name, qualname, enclosingClassName, code, globals, PythonUtils.EMPTY_OBJECT_ARRAY, PKeyword.EMPTY_KEYWORDS, closure);
66+
public PFunction(PythonLanguage lang, String name, String qualname, PCode code, PythonObject globals, PCell[] closure) {
67+
this(lang, name, qualname, code, globals, PythonUtils.EMPTY_OBJECT_ARRAY, PKeyword.EMPTY_KEYWORDS, closure);
6868
}
6969

70-
public PFunction(PythonLanguage lang, String name, String qualname, String enclosingClassName, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
71-
PCell[] closure) {
72-
this(lang, name, qualname, enclosingClassName, code, globals, defaultValues, kwDefaultValues, closure, Truffle.getRuntime().createAssumption(), Truffle.getRuntime().createAssumption());
70+
public PFunction(PythonLanguage lang, String name, String qualname, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues, PCell[] closure) {
71+
this(lang, name, qualname, code, globals, defaultValues, kwDefaultValues, closure, Truffle.getRuntime().createAssumption(), Truffle.getRuntime().createAssumption());
7372
}
7473

75-
public PFunction(PythonLanguage lang, String name, String qualname, String enclosingClassName, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
76-
PCell[] closure, Assumption codeStableAssumption, Assumption defaultsStableAssumption) {
74+
public PFunction(PythonLanguage lang, String name, String qualname, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues, PCell[] closure,
75+
Assumption codeStableAssumption, Assumption defaultsStableAssumption) {
7776
super(PythonBuiltinClassType.PFunction, PythonBuiltinClassType.PFunction.getInstanceShape(lang));
7877
this.name = name;
7978
this.qualname = qualname;
8079
assert code != null;
8180
this.code = code;
82-
this.enclosingClassName = enclosingClassName;
8381
this.globals = globals;
8482
this.defaultValues = defaultValues == null ? PythonUtils.EMPTY_OBJECT_ARRAY : defaultValues;
8583
this.kwDefaultValues = kwDefaultValues == null ? PKeyword.EMPTY_KEYWORDS : kwDefaultValues;
@@ -120,6 +118,14 @@ public PCell[] getClosure() {
120118
return closure;
121119
}
122120

121+
public boolean isBuiltin() {
122+
return isBuiltin;
123+
}
124+
125+
public void setBuiltin(boolean builtin) {
126+
isBuiltin = builtin;
127+
}
128+
123129
@Override
124130
public final String toString() {
125131
CompilerAsserts.neverPartOfCompilation();
@@ -137,10 +143,6 @@ public void setCode(PCode code) {
137143
this.code = code;
138144
}
139145

140-
public String getEnclosingClassName() {
141-
return enclosingClassName;
142-
}
143-
144146
public Object[] getDefaults() {
145147
return defaultValues;
146148
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/BuiltinMethodBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static boolean isBuiltinFunction(PBuiltinMethod self) {
8181
}
8282

8383
static boolean isBuiltinFunction(PMethod self) {
84-
return self.getSelf() instanceof PythonModule && self.getFunction() instanceof PFunction && ((PFunction) self.getFunction()).getEnclosingClassName() == null;
84+
return self.getSelf() instanceof PythonModule && self.getFunction() instanceof PFunction && ((PFunction) self.getFunction()).isBuiltin();
8585
}
8686

8787
@Specialization(guards = "isBuiltinFunction(self)")

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/FunctionDefinitionNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public Object execute(VirtualFrame frame) {
134134
code = factory().createCode(callTarget);
135135
}
136136

137-
PFunction func = withDocString(frame, factory().createFunction(functionName, qualname, enclosingClassName, code, PArguments.getGlobals(frame),
137+
PFunction func = withDocString(frame, factory().createFunction(functionName, qualname, code, PArguments.getGlobals(frame),
138138
defaultValues, kwDefaultValues, closure, codeStableAssumption, defaultsStableAssumption));
139139

140140
// Processing annotated arguments.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/GeneratorFunctionDefinitionNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public PFunction execute(VirtualFrame frame) {
8585
}
8686
}
8787
PCell[] closure = getClosureFromGeneratorOrFunctionLocals(frame);
88-
return withDocString(frame, factory().createFunction(functionName, qualname, enclosingClassName, getGeneratorCode(), PArguments.getGlobals(frame), defaultValues, kwDefaultValues, closure));
88+
return withDocString(frame, factory().createFunction(functionName, qualname, getGeneratorCode(), PArguments.getGlobals(frame), defaultValues, kwDefaultValues, closure));
8989
}
9090

9191
public GeneratorFunctionRootNode getGeneratorFunctionRootNode(PythonLanguage language) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -582,23 +582,21 @@ public final PBuiltinMethod createBuiltinMethod(Object self, PBuiltinFunction fu
582582
return createBuiltinMethod(PythonBuiltinClassType.PBuiltinMethod, self, function);
583583
}
584584

585-
public final PFunction createFunction(String name, String enclosingClassName, PCode code, PythonObject globals, PCell[] closure) {
586-
return trace(new PFunction(getLanguage(), name, name, enclosingClassName, code, globals, closure));
585+
public final PFunction createFunction(String name, PCode code, PythonObject globals, PCell[] closure) {
586+
return trace(new PFunction(getLanguage(), name, name, code, globals, closure));
587587
}
588588

589-
public final PFunction createFunction(String name, String qualname, String enclosingClassName, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
590-
PCell[] closure) {
591-
return trace(new PFunction(getLanguage(), name, qualname, enclosingClassName, code, globals, defaultValues, kwDefaultValues, closure));
589+
public final PFunction createFunction(String name, String qualname, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues, PCell[] closure) {
590+
return trace(new PFunction(getLanguage(), name, qualname, code, globals, defaultValues, kwDefaultValues, closure));
592591
}
593592

594-
public final PFunction createFunction(String name, String enclosingClassName, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
595-
PCell[] closure) {
596-
return trace(new PFunction(getLanguage(), name, name, enclosingClassName, code, globals, defaultValues, kwDefaultValues, closure));
593+
public final PFunction createFunction(String name, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues, PCell[] closure) {
594+
return trace(new PFunction(getLanguage(), name, name, code, globals, defaultValues, kwDefaultValues, closure));
597595
}
598596

599-
public final PFunction createFunction(String name, String qualname, String enclosingClassName, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
600-
PCell[] closure, Assumption codeStableAssumption, Assumption defaultsStableAssumption) {
601-
return trace(new PFunction(getLanguage(), name, qualname, enclosingClassName, code, globals, defaultValues, kwDefaultValues, closure,
597+
public final PFunction createFunction(String name, String qualname, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues, PCell[] closure,
598+
Assumption codeStableAssumption, Assumption defaultsStableAssumption) {
599+
return trace(new PFunction(getLanguage(), name, qualname, code, globals, defaultValues, kwDefaultValues, closure,
602600
codeStableAssumption, defaultsStableAssumption));
603601
}
604602

0 commit comments

Comments
 (0)