Skip to content

Commit 9f560e7

Browse files
committed
Intrinsify the remainder of unicodedata module
1 parent 8f9c9e5 commit 9f560e7

File tree

7 files changed

+13
-100
lines changed

7 files changed

+13
-100
lines changed

graalpython/com.oracle.graal.python.frozen/freeze_modules.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def add_graalpython_core():
125125
"_weakref",
126126
"java",
127127
"pip_hook",
128-
"unicodedata",
129128
"_nt",
130129
]:
131130
modname = f"graalpy.{os.path.basename(name)}"

graalpython/com.oracle.graal.python.test/src/tests/test_startup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
'_frozen_importlib_external',
5050
'__graalpython__',
5151
'_weakref',
52-
'unicodedata',
5352
'_sre',
5453
'_sysconfig',
5554
'java',

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import static com.oracle.graal.python.nodes.BuiltinNames.T_NT;
3333
import static com.oracle.graal.python.nodes.BuiltinNames.T_STDERR;
3434
import static com.oracle.graal.python.nodes.BuiltinNames.T_SYS;
35-
import static com.oracle.graal.python.nodes.BuiltinNames.T_UNICODEDATA;
3635
import static com.oracle.graal.python.nodes.BuiltinNames.T_ZIPIMPORT;
3736
import static com.oracle.graal.python.nodes.BuiltinNames.T__SRE;
3837
import static com.oracle.graal.python.nodes.BuiltinNames.T__SYSCONFIG;
@@ -428,7 +427,6 @@ private static TruffleString[] getCoreFiles() {
428427
List<TruffleString> coreFiles = List.of(
429428
T___GRAALPYTHON__,
430429
T__WEAKREF,
431-
T_UNICODEDATA,
432430
T__SRE,
433431
T__SYSCONFIG,
434432
T_JAVA,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import static com.oracle.graal.python.nodes.BuiltinNames.J_UNICODEDATA;
4444
import static com.oracle.graal.python.nodes.BuiltinNames.T_UNICODEDATA;
45+
import static com.oracle.graal.python.nodes.BuiltinNames.T___GRAALPYTHON__;
4546
import static com.oracle.graal.python.runtime.exception.PythonErrorType.KeyError;
4647
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
4748
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
@@ -62,12 +63,15 @@
6263
import com.oracle.graal.python.builtins.PythonBuiltins;
6364
import com.oracle.graal.python.builtins.objects.PNone;
6465
import com.oracle.graal.python.builtins.objects.module.PythonModule;
66+
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
6567
import com.oracle.graal.python.nodes.ErrorMessages;
6668
import com.oracle.graal.python.nodes.PRaiseNode;
6769
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6870
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
6971
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
7072
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
73+
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
74+
import com.oracle.graal.python.runtime.object.PFactory;
7175
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7276
import com.oracle.truffle.api.dsl.Bind;
7377
import com.oracle.truffle.api.dsl.Cached;
@@ -117,6 +121,11 @@ public void postInitialize(Python3Core core) {
117121
super.postInitialize(core);
118122
PythonModule self = core.lookupBuiltinModule(T_UNICODEDATA);
119123
self.setAttribute(toTruffleStringUncached("unidata_version"), toTruffleStringUncached(getUnicodeVersion()));
124+
PyObjectCallMethodObjArgs.executeUncached(core.lookupBuiltinModule(T___GRAALPYTHON__), toTruffleStringUncached("import_current_as_named_module_with_delegate"),
125+
/* module_name= */ T_UNICODEDATA,
126+
/* delegate_name= */ toTruffleStringUncached("_cpython_unicodedata"),
127+
/* delegate_attributes= */ PFactory.createList(core.getLanguage(), new Object[]{toTruffleStringUncached("ucd_3_2_0")}),
128+
/* owner_globals= */ GetOrCreateDictNode.executeUncached(self));
120129
}
121130

122131
static final int NORMALIZER_FORM_COUNT = 4;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/FrozenModules.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ private static final class Map {
105105
private static final PythonFrozenModule GRAALPY__WEAKREF = new PythonFrozenModule("GRAALPY__WEAKREF", null, false);
106106
private static final PythonFrozenModule GRAALPY_JAVA = new PythonFrozenModule("GRAALPY_JAVA", null, false);
107107
private static final PythonFrozenModule GRAALPY_PIP_HOOK = new PythonFrozenModule("GRAALPY_PIP_HOOK", null, false);
108-
private static final PythonFrozenModule GRAALPY_UNICODEDATA = new PythonFrozenModule("GRAALPY_UNICODEDATA", null, false);
109108
private static final PythonFrozenModule GRAALPY__NT = new PythonFrozenModule("GRAALPY__NT", null, false);
110109
}
111110

@@ -243,8 +242,6 @@ public static final PythonFrozenModule lookup(String name) {
243242
return Map.GRAALPY_JAVA;
244243
case "graalpy.pip_hook":
245244
return Map.GRAALPY_PIP_HOOK;
246-
case "graalpy.unicodedata":
247-
return Map.GRAALPY_UNICODEDATA;
248245
case "graalpy._nt":
249246
return Map.GRAALPY__NT;
250247
default:

graalpython/lib-graalpython/__graalpython__.py

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def import_current_as_named_module(module, name, owner_globals=None):
6262

6363

6464
@builtin
65-
def lazy_attributes_from_delegate(module, delegate_name, attributes, owner_module, on_import_error):
65+
def lazy_attributes_from_delegate(module, delegate_name, attributes, owner_module):
6666
"""
6767
used to lazily load attributes defined in another module via the __getattr__ mechanism.
6868
This will only cache the attributes in the caller module.
@@ -76,14 +76,7 @@ def lazy_attributes_from_delegate(module, delegate_name, attributes, owner_modul
7676

7777
def __getattr__(attr):
7878
if attr in attributes:
79-
try:
80-
delegate_module = __import__(delegate_name)
81-
except ImportError:
82-
if on_import_error and (attr in on_import_error):
83-
return on_import_error[attr]
84-
else:
85-
raise
86-
79+
delegate_module = __import__(delegate_name)
8780
new_globals = dict(**delegate_module.__dict__)
8881
new_globals = { key: new_globals[key] for key in attributes }
8982
new_globals.update(**owner_module.__dict__)
@@ -99,46 +92,9 @@ def __getattr__(attr):
9992

10093

10194
@builtin
102-
def auto_wrap_methods(module, delegate_name, delegate_attributes, owner_globals):
103-
func_type = type(import_current_as_named_module)
104-
105-
new_globals = dict(**owner_globals)
106-
107-
for attr in owner_globals:
108-
if attr.startswith("__"):
109-
continue
110-
elif not isinstance(owner_globals[attr], func_type):
111-
continue
112-
elif attr not in delegate_attributes:
113-
raise AttributeError("attribute '{}' not allowed in module '{}', permitted values are: '{}'".format(
114-
attr, __name__, delegate_attributes
115-
))
116-
117-
if attr in delegate_attributes:
118-
def make_wrapper(attribute, method):
119-
@__graalpython__.builtin
120-
def wrapper(module, *args, **kwargs):
121-
try:
122-
return method(*args, **kwargs)
123-
except NotImplementedError:
124-
delegate_module = __import__(delegate_name)
125-
return getattr(delegate_module, attribute)(*args, **kwargs)
126-
return wrapper
127-
128-
new_globals[attr] = make_wrapper(attr, owner_globals[attr])
129-
130-
return new_globals
131-
132-
133-
@builtin
134-
def import_current_as_named_module_with_delegate(module, module_name, delegate_name, delegate_attributes=None,
135-
owner_globals=None, wrap_methods=True, on_import_error=None):
95+
def import_current_as_named_module_with_delegate(module, module_name, delegate_name, delegate_attributes, owner_globals=None):
13696
owner_module = import_current_as_named_module(module_name, owner_globals=owner_globals)
137-
if wrap_methods and owner_globals:
138-
wrapped_globals = auto_wrap_methods(delegate_name, delegate_attributes, owner_globals)
139-
owner_module.__dict__.update(**wrapped_globals)
140-
if delegate_attributes:
141-
lazy_attributes_from_delegate(delegate_name, delegate_attributes, owner_module, on_import_error)
97+
lazy_attributes_from_delegate(delegate_name, delegate_attributes, owner_module)
14298

14399

144100
@builtin

graalpython/lib-graalpython/unicodedata.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)