Skip to content

Commit 686062d

Browse files
committed
fix error messages and call to __prepare__
1 parent 593e23d commit 686062d

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
import com.oracle.graal.python.nodes.SpecialMethodNames;
138138
import com.oracle.graal.python.nodes.argument.ReadArgumentNode;
139139
import com.oracle.graal.python.nodes.attributes.DeleteAttributeNode;
140+
import com.oracle.graal.python.nodes.attributes.GetAttributeNode;
140141
import com.oracle.graal.python.nodes.attributes.GetAttributeNode.GetAnyAttributeNode;
141142
import com.oracle.graal.python.nodes.attributes.GetAttributeNode.GetFixedAttributeNode;
142143
import com.oracle.graal.python.nodes.attributes.HasInheritedAttributeNode;
@@ -173,7 +174,6 @@
173174
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
174175
import com.oracle.graal.python.nodes.object.GetClassNode;
175176
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
176-
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
177177
import com.oracle.graal.python.nodes.subscript.SetItemNode;
178178
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
179179
import com.oracle.graal.python.nodes.util.CannotCastException;
@@ -193,17 +193,16 @@
193193
import com.oracle.graal.python.util.Supplier;
194194
import com.oracle.truffle.api.Assumption;
195195
import com.oracle.truffle.api.CallTarget;
196+
import com.oracle.truffle.api.CompilerAsserts;
196197
import com.oracle.truffle.api.CompilerDirectives;
197198
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
198199
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
199200
import com.oracle.truffle.api.RootCallTarget;
200-
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
201201
import com.oracle.truffle.api.TruffleLanguage.Env;
202202
import com.oracle.truffle.api.TruffleLanguage.LanguageReference;
203203
import com.oracle.truffle.api.debug.Debugger;
204204
import com.oracle.truffle.api.dsl.Cached;
205205
import com.oracle.truffle.api.dsl.Cached.Shared;
206-
import com.oracle.truffle.api.dsl.CachedContext;
207206
import com.oracle.truffle.api.dsl.Fallback;
208207
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
209208
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -1968,6 +1967,7 @@ PTuple update(PTuple bases, Object[] arguments, int nargs,
19681967
@Cached GetClassNode getMroClass,
19691968
@Cached(parameters = "__MRO_ENTRIES__") LookupAttributeInMRONode getMroEntries,
19701969
@Cached CallBinaryMethodNode callMroEntries) {
1970+
CompilerAsserts.neverPartOfCompilation();
19711971
ArrayList<Object> newBases = null;
19721972
for (int i = 0; i < nargs; i++) {
19731973
Object base = arguments[i];
@@ -2026,6 +2026,7 @@ Object calculate(Object metatype, PTuple bases,
20262026
@Cached GetClassNode getClass,
20272027
@Cached IsSubtypeNode isSubType,
20282028
@Cached IsSubtypeNode isSubTypeReverse) {
2029+
CompilerAsserts.neverPartOfCompilation();
20292030
/*
20302031
* Determine the proper metatype to deal with this, and check for metatype conflicts
20312032
* while we're at it. Note that if some other metatype wins to contract, it's possible
@@ -2055,25 +2056,25 @@ Object calculate(Object metatype, PTuple bases,
20552056
public abstract static class BuildClassNode extends PythonVarargsBuiltinNode {
20562057
@TruffleBoundary
20572058
private static Object buildJavaClass(Object func, String name, Object base) {
2058-
Object module = AbstractImportNode.importModule(BuiltinNames.__GRAALPYTHON__);
2059+
Object module = PythonLanguage.getContext().getCore().lookupBuiltinModule(BuiltinNames.__GRAALPYTHON__);
20592060
Object buildFunction = PythonObjectLibrary.getUncached().lookupAttribute(module, null, "build_java_class");
20602061
return CallNode.getUncached().execute(buildFunction, func, name, base);
20612062
}
20622063

20632064
@Specialization
20642065
protected Object doItNonFunction(VirtualFrame frame, Object function, Object[] arguments, PKeyword[] keywords,
2065-
@CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef,
20662066
@Cached PythonObjectFactory factory,
20672067
@Cached CalculateMetaclassNode calculateMetaClass,
2068-
@Cached(parameters = "__PREPARE__") LookupAttributeInMRONode getPrepare,
2069-
@Cached GetClassNode getGetItemClass,
2068+
@Cached("create(__PREPARE__)") GetAttributeNode getPrepare,
20702069
@Cached(parameters = "__GETITEM__") LookupAttributeInMRONode getGetItem,
2070+
@Cached GetClassNode getGetItemClass,
20712071
@Cached CallVarargsMethodNode callPrep,
20722072
@Cached CallVarargsMethodNode callType,
20732073
@Cached CallUnaryMethodNode callBody,
20742074
@Cached UpdateBasesNode update,
20752075
@Cached SetItemNode setOrigBases,
2076-
@Cached GetClassNode getClass) {
2076+
@Cached GetClassNode getClass,
2077+
@Cached IsBuiltinClassProfile noAttributeProfile) {
20772078

20782079
if (arguments.length < 1) {
20792080
throw raise(PythonErrorType.TypeError, "__build_class__: not enough arguments");
@@ -2119,14 +2120,14 @@ class InitializeBuildClass {
21192120
PythonUtils.arraycopy(keywords, i + 1, mkw, i, mkw.length - i);
21202121

21212122
// metaclass is explicitly given, check if it's indeed a class
2122-
isClass = IsTypeNode.getUncached().equals(meta);
2123+
isClass = IsTypeNode.getUncached().execute(meta);
21232124
break;
21242125
}
21252126
}
21262127
if (meta == null) {
21272128
// if there are no bases, use type:
21282129
if (bases.getSequenceStorage().length() == 0) {
2129-
meta = contextRef.get().getCore().lookupType(PythonBuiltinClassType.PythonClass);
2130+
meta = PythonLanguage.getContext().getCore().lookupType(PythonBuiltinClassType.PythonClass);
21302131
} else {
21312132
// else get the type of the first base
21322133
meta = getClass.execute(bases.getSequenceStorage().getItemNormalized(0));
@@ -2140,23 +2141,22 @@ class InitializeBuildClass {
21402141
meta = calculateMetaClass.execute(meta, bases);
21412142
}
21422143
// else: meta is not a class, so we cannot do the metaclass calculation, so we
2143-
// will
2144-
// use the explicitly given object as it is
2144+
// will use the explicitly given object as it is
21452145
}
21462146
}
21472147
InitializeBuildClass init = new InitializeBuildClass();
21482148

2149-
Object prep = getPrepare.execute(init.meta);
21502149
Object ns;
2151-
if (PGuards.isNoValue(prep)) {
2150+
try {
2151+
Object prep = getPrepare.executeObject(frame, init.meta);
2152+
ns = callPrep.execute(frame, prep, new Object[]{name, init.bases}, init.mkw);
2153+
} catch (PException p) {
2154+
p.expectAttributeError(noAttributeProfile);
21522155
ns = factory.createDict();
2153-
} else {
2154-
Object[] args = PGuards.isFunction(prep) ? new Object[]{name, init.bases} : new Object[]{init.meta, name, init.bases};
2155-
ns = callPrep.execute(frame, prep, args, init.mkw);
21562156
}
21572157
if (PGuards.isNoValue(getGetItem.execute(getGetItemClass.execute(ns)))) {
21582158
if (init.isClass) {
2159-
throw raise(PythonErrorType.TypeError, "%p.__prepare__() must return a mapping, not %p", init.meta, ns);
2159+
throw raise(PythonErrorType.TypeError, "%N.__prepare__() must return a mapping, not %p", init.meta, ns);
21602160
} else {
21612161
throw raise(PythonErrorType.TypeError, "<metaclass>.__prepare__() must return a mapping, not %p", ns);
21622162
}

0 commit comments

Comments
 (0)