Skip to content

bpo-43693: Turn localspluskinds into an object #26749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 21, 2021

Conversation

gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Jun 15, 2021

This makes memory management for code objects cleaner (no more special casing for ownership of the kinds array).

https://bugs.python.org/issue43693

@@ -359,6 +359,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.11a1 3454 (compute cell offsets relative to locals bpo-43693)
# Python 3.11a1 3455 (add MAKE_CELL bpo-43693)
# Python 3.11a1 3456 (interleave cell args bpo-43693)
# Python 3.11a1 3457 (Change localsplus to a bytes object bpo-43693)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we're not using up too many magic numbers during pre-alpha...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are our options?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are our options?

Going back to the first magic number for 3.11a1. Everything is for the same bpo issue it seems.

@gvanrossum gvanrossum marked this pull request as draft June 15, 2021 23:36
@gvanrossum
Copy link
Member Author

@ericsnowcurrently I think I have one failing test left, test_ctypes. In particular:

======================================================================
FAIL: test_frozentable (ctypes.test.test_values.PythonValuesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/guido/cpython/Lib/ctypes/test/test_values.py", line 87, in test_frozentable
    self.assertEqual(items, expected, "PyImport_FrozenModules example "
AssertionError: Lists differ: [('__hello__', 133), ('__phello__', -133), ('__phello__.spam', 133)] != [('__hello__', 128), ('__phello__', -128), ('__phello__.spam', 128)]

First differing element 0:
('__hello__', 133)
('__hello__', 128)

- [('__hello__', 133), ('__phello__', -133), ('__phello__.spam', 133)]
?                 ^^                    ^^                        ^^

+ [('__hello__', 128), ('__phello__', -128), ('__phello__.spam', 128)]
?                 ^^                    ^^                        ^^
 : PyImport_FrozenModules example in Doc/library/ctypes.rst may be out of date

----------------------------------------------------------------------

Have you run into this?

@ericsnowcurrently
Copy link
Member

Yeah, you have to update the test to match the new memory size

@gvanrossum gvanrossum added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 16, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @gvanrossum for commit b09738c 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 16, 2021
@gvanrossum
Copy link
Member Author

I don't see how these changes could make test_ssl fail (only on Mac), and when I run that test myself it passes. I assume it's flakey.

@gvanrossum
Copy link
Member Author

Happy buildbots, except refleaks on AMD64 Windows8.1 is still churning.

@gvanrossum gvanrossum marked this pull request as ready for review June 16, 2021 14:21
Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly LGTM

I've left a few comments for some slight adjustments but otherwise everything looks correct. Thanks for taking the time to do this. FWIW, I now see the value of using PyBytesObject instead of a raw array like I had, so thanks for educating me! 😄

I'm approving the PR now, assuming that you'll make the relevant changes (or ask) before merging.

Python/compile.c Outdated
Comment on lines 7192 to 7193
static PyObject *
compute_localsplus_info(struct compiler *c, PyObject *names)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems strange to pass one in and return the other. Perhaps create both in this function?

Suggested change
static PyObject *
compute_localsplus_info(struct compiler *c, PyObject *names)
static int
compute_localsplus_info(struct compiler *c, int nlocalsplus, PyObject **pnames, PyObject **pkinds)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and something like "init_localsplus_info" is probably a better name with the shift in responsibility for this function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems strange to pass one in and return the other. Perhaps create both in this function?

I find the C idiom for returning multiple values pretty awkward, so I'll just allocate both before passing them into the function.

@gvanrossum
Copy link
Member Author

gvanrossum commented Jun 18, 2021

While all the tests pass here, when I try them at home, I get a crash in test_descr, both on Mac and Windows. I need to understand better what's going on there. Maybe I just need to merge a later version of main. But I'm out of time for now.

@gvanrossum
Copy link
Member Author

Oh wait, I get the same crash on main. Something's wrong!

@gvanrossum
Copy link
Member Author

gvanrossum commented Jun 19, 2021

So, using git bisect I've narrowed it down to GH-26595:

commit e117c0283705943189e6b1aef668a1f68f3f00a4 (HEAD)
Author: Mark Shannon <[email protected]>
Date:   Thu Jun 10 00:46:01 2021

    [bpo-44337](https://bugs.python.org/issue44337): Port LOAD_ATTR to PEP 659 adaptive interpreter (GH-26595)
    
    * Specialize LOAD_ATTR with  LOAD_ATTR_SLOT and LOAD_ATTR_SPLIT_KEYS
    
    * Move dict-common.h to internal/pycore_dict.h
    
    * Add LOAD_ATTR_WITH_HINT specialized opcode.
    
    * Quicken in function if loopy
    
    * Specialize LOAD_ATTR for module attributes.
    
    * Add specialization stats

I can repro this on my Mac using the following sequence:

$ ./python.exe -m test test_unittest test_doctest test_descr
0:00:00 load avg: 2.28 Run tests sequentially
0:00:00 load avg: 2.28 [1/3] test_unittest
0:00:02 load avg: 2.28 [2/3] test_doctest
0:00:02 load avg: 2.17 [3/3] test_descr
Fatal Python error: Segmentation fault

Current thread 0x0000000111041e00 (most recent call first):
  File "<frozen importlib._bootstrap>", line 306 in _module_repr
  File "/Users/guido/cpython/Lib/test/test_descr.py", line 3696 in test_uninitialized_modules
  File "/Users/guido/cpython/Lib/unittest/case.py", line 549 in _callTestMethod
  File "/Users/guido/cpython/Lib/unittest/case.py", line 592 in run
  File "/Users/guido/cpython/Lib/unittest/case.py", line 652 in __call__
  File "/Users/guido/cpython/Lib/unittest/suite.py", line 122 in run
  File "/Users/guido/cpython/Lib/unittest/suite.py", line 84 in __call__
  File "/Users/guido/cpython/Lib/unittest/suite.py", line 122 in run
  File "/Users/guido/cpython/Lib/unittest/suite.py", line 84 in __call__
  File "/Users/guido/cpython/Lib/test/support/testresult.py", line 169 in run
  File "/Users/guido/cpython/Lib/test/support/__init__.py", line 960 in _run_suite
  File "/Users/guido/cpython/Lib/test/support/__init__.py", line 1083 in run_unittest
  File "/Users/guido/cpython/Lib/test/test_descr.py", line 5734 in test_main
  File "/Users/guido/cpython/Lib/test/libregrtest/runtest.py", line 246 in _runtest_inner2
  File "/Users/guido/cpython/Lib/test/libregrtest/runtest.py", line 282 in _runtest_inner
  File "/Users/guido/cpython/Lib/test/libregrtest/runtest.py", line 154 in _runtest
  File "/Users/guido/cpython/Lib/test/libregrtest/runtest.py", line 194 in runtest
  File "/Users/guido/cpython/Lib/test/libregrtest/main.py", line 423 in run_tests_sequential
  File "/Users/guido/cpython/Lib/test/libregrtest/main.py", line 521 in run_tests
  File "/Users/guido/cpython/Lib/test/libregrtest/main.py", line 694 in _main
  File "/Users/guido/cpython/Lib/test/libregrtest/main.py", line 641 in main
  File "/Users/guido/cpython/Lib/test/libregrtest/main.py", line 719 in main
  File "/Users/guido/cpython/Lib/test/__main__.py", line 2 in <module>
  File "/Users/guido/cpython/Lib/runpy.py", line 86 in _run_code
  File "/Users/guido/cpython/Lib/runpy.py", line 196 in _run_module_as_main

Extension modules: _testcapi, xxsubtype (total: 2)
Segmentation fault: 11

The same three tests also cause a crash on Windows, with roughly the same traceback.

@markshannon Can you repro this on your Linux machine?

@markshannon
Copy link
Member

Repro what?
Your PR is green. The buildbots seem OK.

@gvanrossum
Copy link
Member Author

gvanrossum commented Jun 21, 2021

@markshannon

Repro what?
Your PR is green. The buildbots seem OK.

I know, but when I try this at home, on both Windows and Mac, I get a crash (details in my previous comment):

$ ./python.exe -m test test_unittest test_doctest test_descr

I've painstakingly bisected this behavior down to your PR GH-26595. If I back up in git to the PR before that, that command passes. Any commit on master after that PR, it also fails (including HEAD).

And this is both on Mac and on Windows, so I can't blame it on environmental issues -- the two environments are just too different.

So I beg you to take this serious. I suspect something odd happens in the LOAD_ATTR cache.

Could it be that the CI tests set PYTHONHASHSEED to a fixed value that happens to avoid the crash?

@gvanrossum
Copy link
Member Author

@markshannon
To help pin this down further, I bisected at the test level. Here is the minimal file to pass as --matchfile FILE flag to the test runner:

unittest.test.test_discovery.TestDiscovery.test_discovery_failed_discovery
unittest.test.testmock.testpatch.PatchTest.test_patch_wont_create_by_default
test.test_doctest.TestDocTestFinder.test_empty_namespace_package
test.test_doctest.TestDocTestFinder.test_issue35753
test.test_descr.ClassPropertiesAndMethods.test_uninitialized_modules

@gvanrossum
Copy link
Member Author

gvanrossum commented Jun 21, 2021

There LOAD_ATTR issue is unrelated (discussed offline, we understand it and Mark will fix), so assuming the tests pass after the merge with origin/main I'll land this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants