Skip to content

Commit e065e68

Browse files
committed
Narrow code cloning fix to owner-aware compiler snapshots
Merge main and remove the construction provenance, external-bytecode policy, and frozen decode framework. Snapshot live code in the internal compiler adapter through its owning PyCode, recursively preserving access to monitoring metadata and current filenames. AI assistance: OpenAI Codex performed source research, implementation, review response drafting, and guarded static validation. Runtime and C-API tests were not run. Assisted-by: OpenAI Codex: model version unavailable
2 parents eaa75b1 + a20e9cd commit e065e68

92 files changed

Lines changed: 4594 additions & 1496 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.cspell.dict/rustpython.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pyperformance
3737
pytype
3838
qsbr
3939
rustix
40+
rustpythonw
4041
struc
4142
unscanned
4243
zelf

‎.cspell.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
"implicits",
9898
"inity",
9999
"interps",
100+
"isxidcontinue",
101+
"isxidstart",
100102
"jitted",
101103
"jitting",
102104
"kwonly",

‎Lib/test/test_audit.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def test_block_add_hook(self):
5858
def test_block_add_hook_baseexception(self):
5959
self.do_test("test_block_add_hook_baseexception")
6060

61-
@unittest.expectedFailure # TODO: RUSTPYTHON
6261
def test_marshal(self):
6362
import_helper.import_module("marshal")
6463

@@ -69,7 +68,6 @@ def test_pickle(self):
6968

7069
self.do_test("test_pickle")
7170

72-
@unittest.expectedFailure # TODO: RUSTPYTHON
7371
def test_monkeypatch(self):
7472
self.do_test("test_monkeypatch")
7573

@@ -80,7 +78,6 @@ def test_open(self):
8078
def test_cantrace(self):
8179
self.do_test("test_cantrace")
8280

83-
@unittest.expectedFailure # TODO: RUSTPYTHON
8481
def test_mmap(self):
8582
self.do_test("test_mmap")
8683

‎Lib/test/test_bytes.py‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,6 @@ def g():
19201920
# self.assertGreater(alloc, len(b))
19211921
self.assertGreaterEqual(alloc, len(b)) # NOTE: RUSTPYTHON patched
19221922

1923-
@unittest.expectedFailure # TODO: RUSTPYTHON
19241923
def test_extend(self):
19251924
orig = b'hello'
19261925
a = bytearray(orig)
@@ -2647,14 +2646,6 @@ class ByteArraySubclassWithSlotsTest(SubclassTest, unittest.TestCase):
26472646
basetype = bytearray
26482647
type2test = ByteArraySubclassWithSlots
26492648

2650-
@unittest.expectedFailure # TODO: RUSTPYTHON
2651-
def test_copy(self):
2652-
return super().test_copy()
2653-
2654-
@unittest.expectedFailure # TODO: RUSTPYTHON
2655-
def test_pickle(self):
2656-
return super().test_pickle()
2657-
26582649
class BytesSubclassTest(SubclassTest, unittest.TestCase):
26592650
basetype = bytes
26602651
type2test = BytesSubclass

‎Lib/test/test_cmd_line.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ def test_empty_PYTHONPATH_issue16309(self):
497497
# for empty and unset PYTHONPATH
498498
self.assertEqual(out1, out2)
499499

500-
@unittest.expectedFailure # TODO: RUSTPYTHON
501500
def test_displayhook_unencodable(self):
502501
for encoding in ('ascii', 'latin-1', 'utf-8'):
503502
env = os.environ.copy()

‎Lib/test/test_deque.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,6 @@ def test_copy_pickle(self):
856856
self.assertEqual(e.z, d.z)
857857
self.assertNotHasAttr(e, 'y')
858858

859-
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: 'Deque' object has no attribute 'x'
860859
def test_pickle_recursive(self):
861860
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
862861
for d in Deque('abc'), Deque('abc', 3):

‎Lib/test/test_dict.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,6 @@ def test_reversed_dict_after_clear_and_restore(self):
14241424
for it in iterators:
14251425
self.assertEqual(list(it), [])
14261426

1427-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: RuntimeError not raised
14281427
def test_reversed_dict_keys_changed_during_iteration(self):
14291428
d = dict.fromkeys(range(10))
14301429
for i in range(7):

‎Lib/test/test_enum.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,6 @@ class ThreePart(Enum):
17791779
self.assertIs(ThreePart((3, 3.0, 'three')), ThreePart.THREE)
17801780
self.assertIs(ThreePart(3, 3.0, 'three'), ThreePart.THREE)
17811781

1782-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: <test.test_enum.IntStooges object at 0x55c70c38a240> is not <IntStooges.MOE: 3>
17831782
@reraise_if_not_enum(IntStooges)
17841783
def test_intenum_from_bytes(self):
17851784
self.assertIs(IntStooges.from_bytes(b'\x00\x03', 'big'), IntStooges.MOE)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import unittest
2+
from collections import deque
3+
from copy import copy
4+
from test.support import threading_helper
5+
6+
threading_helper.requires_working_threading(module=True)
7+
8+
9+
class TestDeque(unittest.TestCase):
10+
def test_copy_race(self):
11+
# gh-144809: Test that deque copy is thread safe. It previously
12+
# could raise a "deque mutated during iteration" error.
13+
d = deque(range(100))
14+
15+
def mutate():
16+
for i in range(1000):
17+
d.append(i)
18+
if len(d) > 200:
19+
d.popleft()
20+
21+
def copy_loop():
22+
for _ in range(1000):
23+
copy(d)
24+
25+
threading_helper.run_concurrently([mutate, copy_loop])
26+
27+
def test_index_race_in_ac(self):
28+
# gh-150750: There was a c_default specified as `Py_SIZE(self)`,
29+
# it was used without a critical section.
30+
31+
d = deque(range(100))
32+
33+
def index():
34+
for _ in range(10000):
35+
try:
36+
d.index(50)
37+
except ValueError:
38+
pass
39+
40+
def mutate():
41+
for _ in range(10000):
42+
d.append(0)
43+
d.clear()
44+
d.extend(range(100))
45+
d.appendleft(-1)
46+
47+
threading_helper.run_concurrently(
48+
[index, *[mutate for _ in range(3)]],
49+
)
50+
51+
52+
if __name__ == "__main__":
53+
unittest.main()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import unittest
2+
3+
from test.support import threading_helper
4+
5+
import cProfile
6+
import pstats
7+
8+
9+
NTHREADS = 10
10+
INSERT_PER_THREAD = 1000
11+
12+
13+
@threading_helper.requires_working_threading()
14+
class TestCProfile(unittest.TestCase):
15+
def test_cprofile_racing_list_insert(self):
16+
def list_insert(lst):
17+
for i in range(INSERT_PER_THREAD):
18+
lst.insert(0, i)
19+
20+
lst = []
21+
22+
with cProfile.Profile() as pr:
23+
threading_helper.run_concurrently(
24+
worker_func=list_insert, nthreads=NTHREADS, args=(lst,)
25+
)
26+
pr.create_stats()
27+
ps = pstats.Stats(pr)
28+
stats_profile = ps.get_stats_profile()
29+
list_insert_profile = stats_profile.func_profiles[
30+
"<method 'insert' of 'list' objects>"
31+
]
32+
# Even though there is no explicit recursive call to insert,
33+
# cProfile may record some calls as recursive due to limitations
34+
# in its handling of multithreaded programs. This issue is not
35+
# directly related to FT Python itself; however, it tends to be
36+
# more noticeable when using FT Python. Therefore, consider only
37+
# the calls section and disregard the recursive part.
38+
list_insert_ncalls = list_insert_profile.ncalls.split("/")[0]
39+
self.assertEqual(
40+
int(list_insert_ncalls), NTHREADS * INSERT_PER_THREAD
41+
)
42+
43+
self.assertEqual(len(lst), NTHREADS * INSERT_PER_THREAD)

0 commit comments

Comments
 (0)