Skip to content

Commit ea54efe

Browse files
committed
Make _Unbound special in all loaded built-in modules
1 parent df60f02 commit ea54efe

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

runtime/bytecode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void rewriteBytecode(Thread* thread, const Function& function) {
340340
RawObject module = function.moduleObject();
341341
bool is_builtin_module =
342342
module.isModule() &&
343-
Module::cast(module).id() == thread->runtime()->builtinsModuleId();
343+
Module::cast(module).id() <= runtime->lastBuiltinModuleId();
344344
for (word i = 0; i < num_opcodes;) {
345345
BytecodeOp op = nextBytecodeOp(bytecode, &i);
346346
word previous_index = i - 1;

runtime/runtime.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,10 @@ void Runtime::initializeModules(Thread* thread) {
21852185
"failed to initialize built-in module %s",
21862186
Symbols::predefinedSymbolAt(id));
21872187
}
2188+
last_builtin_module_id_ =
2189+
Module::cast(
2190+
findModuleById(kRequiredModules[ARRAYSIZE(kRequiredModules) - 1]))
2191+
.id();
21882192
}
21892193

21902194
RawObject Runtime::initialize(Thread* thread) {

runtime/runtime.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ class Runtime {
297297
builtins_module_id_ = builtins_module_id;
298298
}
299299

300+
word lastBuiltinModuleId() { return last_builtin_module_id_; }
301+
300302
RawObject moduleDunderGetattribute() { return module_dunder_getattribute_; }
301303
RawObject objectDunderClass() { return object_dunder_class_; }
302304
RawObject objectDunderEq() { return object_dunder_eq_; }
@@ -954,6 +956,9 @@ class Runtime {
954956
// The ID of builtins module.
955957
// TODO(T64005113): Remove this once we mark individual functions.
956958
word builtins_module_id_ = -1;
959+
// The ID of the last built-in module initialized by the runtime. Used to
960+
// give special properties to built-in modules.
961+
word last_builtin_module_id_ = -1;
957962

958963
// Internal-only types, for which the Layout has a different described type
959964
RawObject large_bytes_ = NoneType::object();

0 commit comments

Comments
 (0)