Skip to content
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

gh-115816: Improve internal symbols API in optimizer #116028

Merged
merged 15 commits into from
Feb 28, 2024

Conversation

gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Feb 28, 2024

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

LGTM in general just some references stuff

return;
}
PyTypeObject *typ = Py_TYPE(const_val);
if (sym->typ != NULL && sym->typ != typ) {
Copy link
Member

Choose a reason for hiding this comment

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

Could be simplified to

Suggested change
if (sym->typ != NULL && sym->typ != typ) {
if (sym->typ != typ) {

as Py_TYPE(const_val) cannot be NULL.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see this was a bug I introduced. Sorry.

Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out this "fix" was wrong -- we're not checking whether typ is NULL, we're checking whether sym->typ isn't NULL. If it's NULL, setting the constant should be allowed. Running the tests with PYTHONUOPSOPTIMIZE=1 revealed this. :-)

Python/optimizer_symbols.c Show resolved Hide resolved
Python/optimizer_symbols.c Show resolved Hide resolved
Python/optimizer_symbols.c Show resolved Hide resolved
@gvanrossum
Copy link
Member Author

Hold on, test_capi.test_opt fails with PYTHONUOPSOPTIMIZE=1 and unless I'm seeing a ghost again I introduced this failure.

@gvanrossum gvanrossum enabled auto-merge (squash) February 28, 2024 17:18
@gvanrossum gvanrossum merged commit e2a3e4b into python:main Feb 28, 2024
46 of 50 checks passed
@gvanrossum gvanrossum deleted the new-symbols branch February 28, 2024 17:56
@gvanrossum gvanrossum mentioned this pull request Feb 28, 2024
32 tasks
gvanrossum added a commit to gvanrossum/cpython that referenced this pull request Feb 28, 2024
gvanrossum added a commit that referenced this pull request Feb 28, 2024
This undoes the *temporary* default disabling of the T2 optimizer pass in gh-115860.

- Add a new test that reproduces Brandt's example from gh-115859; it indeed crashes before gh-116028 with PYTHONUOPSOPTIMIZE=1
- Re-enable the optimizer pass in T2, stop checking PYTHONUOPSOPTIMIZE
- Rename the env var to disable T2 entirely to PYTHON_UOPS_OPTIMIZE (must be explicitly set to 0 to disable)
- Fix skipIf conditions on tests in test_opt.py accordingly
- Export sym_is_bottom() (for debugging)
- Fix various things in the `_BINARY_OP_` specializations in the abstract interpreter:
  - DECREF(temp)
  - out-of-space check after sym_new_const()
  - add sym_matches_type() checks, so even if we somehow reach a binary op with symbolic constants of the wrong type on the stack we won't trigger the type assert
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull request Mar 4, 2024
…6028)

- Any `sym_set_...` call that attempts to set conflicting information
  cause the symbol to become `bottom` (contradiction).
- All `sym_is...` and similar calls return false or NULL for `bottom`.
- Everything's tested.
- The tests still pass with `PYTHONUOPSOPTIMIZE=1`.
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull request Mar 4, 2024
This undoes the *temporary* default disabling of the T2 optimizer pass in pythongh-115860.

- Add a new test that reproduces Brandt's example from pythongh-115859; it indeed crashes before pythongh-116028 with PYTHONUOPSOPTIMIZE=1
- Re-enable the optimizer pass in T2, stop checking PYTHONUOPSOPTIMIZE
- Rename the env var to disable T2 entirely to PYTHON_UOPS_OPTIMIZE (must be explicitly set to 0 to disable)
- Fix skipIf conditions on tests in test_opt.py accordingly
- Export sym_is_bottom() (for debugging)
- Fix various things in the `_BINARY_OP_` specializations in the abstract interpreter:
  - DECREF(temp)
  - out-of-space check after sym_new_const()
  - add sym_matches_type() checks, so even if we somehow reach a binary op with symbolic constants of the wrong type on the stack we won't trigger the type assert
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
…6028)

- Any `sym_set_...` call that attempts to set conflicting information
  cause the symbol to become `bottom` (contradiction).
- All `sym_is...` and similar calls return false or NULL for `bottom`.
- Everything's tested.
- The tests still pass with `PYTHONUOPSOPTIMIZE=1`.
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
This undoes the *temporary* default disabling of the T2 optimizer pass in pythongh-115860.

- Add a new test that reproduces Brandt's example from pythongh-115859; it indeed crashes before pythongh-116028 with PYTHONUOPSOPTIMIZE=1
- Re-enable the optimizer pass in T2, stop checking PYTHONUOPSOPTIMIZE
- Rename the env var to disable T2 entirely to PYTHON_UOPS_OPTIMIZE (must be explicitly set to 0 to disable)
- Fix skipIf conditions on tests in test_opt.py accordingly
- Export sym_is_bottom() (for debugging)
- Fix various things in the `_BINARY_OP_` specializations in the abstract interpreter:
  - DECREF(temp)
  - out-of-space check after sym_new_const()
  - add sym_matches_type() checks, so even if we somehow reach a binary op with symbolic constants of the wrong type on the stack we won't trigger the type assert
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…6028)

- Any `sym_set_...` call that attempts to set conflicting information
  cause the symbol to become `bottom` (contradiction).
- All `sym_is...` and similar calls return false or NULL for `bottom`.
- Everything's tested.
- The tests still pass with `PYTHONUOPSOPTIMIZE=1`.
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
This undoes the *temporary* default disabling of the T2 optimizer pass in pythongh-115860.

- Add a new test that reproduces Brandt's example from pythongh-115859; it indeed crashes before pythongh-116028 with PYTHONUOPSOPTIMIZE=1
- Re-enable the optimizer pass in T2, stop checking PYTHONUOPSOPTIMIZE
- Rename the env var to disable T2 entirely to PYTHON_UOPS_OPTIMIZE (must be explicitly set to 0 to disable)
- Fix skipIf conditions on tests in test_opt.py accordingly
- Export sym_is_bottom() (for debugging)
- Fix various things in the `_BINARY_OP_` specializations in the abstract interpreter:
  - DECREF(temp)
  - out-of-space check after sym_new_const()
  - add sym_matches_type() checks, so even if we somehow reach a binary op with symbolic constants of the wrong type on the stack we won't trigger the type assert
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.

None yet

2 participants