From ef0fe384a0e20cfe94de39ac5a384607beb7d697 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Mon, 2 Feb 2026 15:25:40 +0000 Subject: [PATCH 1/7] WIP librt.time --- mypy/typeshed/stubs/librt/librt/time.pyi | 1 + mypyc/codegen/emitmodule.py | 8 +- mypyc/ir/deps.py | 1 + mypyc/lib-rt/time/librt_time.c | 99 ++++++++++++++++++++++++ mypyc/lib-rt/time/librt_time.h | 62 +++++++++++++++ mypyc/primitives/librt_time_ops.py | 14 ++++ mypyc/primitives/registry.py | 1 + mypyc/test-data/irbuild-time.test | 44 +++++++++++ mypyc/test/test_irbuild.py | 1 + 9 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 mypy/typeshed/stubs/librt/librt/time.pyi create mode 100644 mypyc/lib-rt/time/librt_time.c create mode 100644 mypyc/lib-rt/time/librt_time.h create mode 100644 mypyc/primitives/librt_time_ops.py create mode 100644 mypyc/test-data/irbuild-time.test diff --git a/mypy/typeshed/stubs/librt/librt/time.pyi b/mypy/typeshed/stubs/librt/librt/time.pyi new file mode 100644 index 0000000000000..f0bb23fff8d00 --- /dev/null +++ b/mypy/typeshed/stubs/librt/librt/time.pyi @@ -0,0 +1 @@ +def time() -> float: ... diff --git a/mypyc/codegen/emitmodule.py b/mypyc/codegen/emitmodule.py index 2b0693ea2f2dd..da82f14e92f2e 100644 --- a/mypyc/codegen/emitmodule.py +++ b/mypyc/codegen/emitmodule.py @@ -56,7 +56,7 @@ short_id_from_name, ) from mypyc.errors import Errors -from mypyc.ir.deps import LIBRT_BASE64, LIBRT_STRINGS, SourceDep +from mypyc.ir.deps import LIBRT_BASE64, LIBRT_STRINGS, LIBRT_TIME, SourceDep from mypyc.ir.func_ir import FuncIR from mypyc.ir.module_ir import ModuleIR, ModuleIRs, deserialize_modules from mypyc.ir.ops import DeserMaps, LoadLiteral @@ -632,6 +632,8 @@ def generate_c_for_modules(self) -> list[tuple[str, str]]: ext_declarations.emit_line("#include ") if any(LIBRT_STRINGS in mod.dependencies for mod in self.modules.values()): ext_declarations.emit_line("#include ") + if any(LIBRT_TIME in mod.dependencies for mod in self.modules.values()): + ext_declarations.emit_line("#include