Skip to content

Commit fd11e89

Browse files
authored
[mypyc] Mark librt.time.time() non-experimental (#21310)
It is highly unlikely ABI for this module will change. We should start using this ourselves, as we do a lot of performance logging in mypy.
1 parent aa9b516 commit fd11e89

5 files changed

Lines changed: 2 additions & 42 deletions

File tree

mypyc/lib-rt/time/librt_time.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <sys/time.h>
1313
#endif
1414

15-
#ifdef MYPYC_EXPERIMENTAL
16-
1715
// Internal function that returns a C double for mypyc primitives
1816
// Returns high-precision time in seconds (like time.time())
1917
static double
@@ -74,18 +72,12 @@ time_time(PyObject *self, PyObject *const *args, size_t nargs) {
7472
return PyFloat_FromDouble(result);
7573
}
7674

77-
#endif
78-
7975
static PyMethodDef librt_time_module_methods[] = {
80-
#ifdef MYPYC_EXPERIMENTAL
8176
{"time", (PyCFunction)time_time, METH_FASTCALL,
8277
PyDoc_STR("Return the current time in seconds since the Unix epoch as a floating point number.")},
83-
#endif
8478
{NULL, NULL, 0, NULL}
8579
};
8680

87-
#ifdef MYPYC_EXPERIMENTAL
88-
8981
static int
9082
time_abi_version(void) {
9183
return LIBRT_TIME_ABI_VERSION;
@@ -96,12 +88,9 @@ time_api_version(void) {
9688
return LIBRT_TIME_API_VERSION;
9789
}
9890

99-
#endif
100-
10191
static int
10292
librt_time_module_exec(PyObject *m)
10393
{
104-
#ifdef MYPYC_EXPERIMENTAL
10594
// Export mypyc internal C API via capsule
10695
static void *time_api[LIBRT_TIME_API_LEN] = {
10796
(void *)time_abi_version,
@@ -112,7 +101,6 @@ librt_time_module_exec(PyObject *m)
112101
if (PyModule_Add(m, "_C_API", c_api_object) < 0) {
113102
return -1;
114103
}
115-
#endif
116104
return 0;
117105
}
118106

mypyc/lib-rt/time/librt_time.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#ifndef LIBRT_TIME_H
22
#define LIBRT_TIME_H
33

4-
#ifdef MYPYC_EXPERIMENTAL
5-
64
#include <Python.h>
75

86
#define LIBRT_TIME_ABI_VERSION 1
97
#define LIBRT_TIME_API_VERSION 1
108
#define LIBRT_TIME_API_LEN 3
119

12-
#endif // MYPYC_EXPERIMENTAL
13-
1410
#endif // LIBRT_TIME_H

mypyc/lib-rt/time/librt_time_api.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
#include "librt_time_api.h"
22

3-
#ifndef MYPYC_EXPERIMENTAL
4-
5-
int
6-
import_librt_time(void)
7-
{
8-
// All librt.time features are experimental for now, so don't set up the API here
9-
return 0;
10-
}
11-
12-
#else // MYPYC_EXPERIMENTAL
13-
143
void *LibRTTime_API[LIBRT_TIME_API_LEN] = {0};
154

165
int
@@ -45,5 +34,3 @@ import_librt_time(void)
4534
}
4635
return 0;
4736
}
48-
49-
#endif // MYPYC_EXPERIMENTAL

mypyc/lib-rt/time/librt_time_api.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@
66
int
77
import_librt_time(void);
88

9-
#ifdef MYPYC_EXPERIMENTAL
10-
119
extern void *LibRTTime_API[LIBRT_TIME_API_LEN];
1210

1311
#define LibRTTime_ABIVersion (*(int (*)(void)) LibRTTime_API[0])
1412
#define LibRTTime_APIVersion (*(int (*)(void)) LibRTTime_API[1])
1513
#define LibRTTime_time (*(double (*)(void)) LibRTTime_API[2])
1614

17-
#endif // MYPYC_EXPERIMENTAL
18-
1915
#endif // LIBRT_TIME_API_H

mypyc/test-data/run-librt-time.test

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[case testTimeBasic_librt_experimental]
1+
[case testTimeBasic_librt]
22
import time as stdlib_time
33
from librt.time import time
44

@@ -28,14 +28,7 @@ def test_time_comparable_to_stdlib() -> None:
2828
# but keep it relatively high to avoid test flakiness in CI)
2929
assert abs(our_time - std_time) < 0.25
3030

31-
[case testTimeNotAvailableInNonExperimentalBuild_librt_time]
32-
# This also ensures librt.time can be built without experimental features
33-
import librt.time
34-
35-
def test_time_not_available() -> None:
36-
assert not hasattr(librt.time, "time")
37-
38-
[case testTimeUsedAtTopLevelOnly_librt_experimental]
31+
[case testTimeUsedAtTopLevelOnly_librt]
3932
from librt.time import time
4033

4134
# The only reference to time() is at module top level

0 commit comments

Comments
 (0)