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

Make implicit boolean conversions explicit #106008

Closed
brandtbucher opened this issue Jun 23, 2023 · 3 comments
Closed

Make implicit boolean conversions explicit #106008

brandtbucher opened this issue Jun 23, 2023 · 3 comments
Assignees
Labels
3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@brandtbucher
Copy link
Member

brandtbucher commented Jun 23, 2023

...as discussed in faster-cpython/ideas#568.

By adding a dedicated instruction for converting values to bool, we can easily specialize the conditions of all remaining branches in the bytecode while keeping the branches themselves as "dumb" and simple as possible.

This is one of the few remaining common cases where a little specilization will give us a lot of useful information (such as "this branch won't execute arbitrary code") for higher tiers of optimization. Plus, the most common specializations (such as for bool or None) will be effectively no-ops.

Linked PRs

@brandtbucher brandtbucher added performance Performance or resource usage interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.13 bugs and security fixes labels Jun 23, 2023
@brandtbucher brandtbucher self-assigned this Jun 23, 2023
@pablogsal
Copy link
Member

pablogsal commented Jul 3, 2023

@brandtbucher Apparently this PR introduced a refleak in test_grammar:

Raised RLIMIT_NOFILE: 256 -> 1024
0:00:00 load avg: 14.52 Run tests sequentially
0:00:00 load avg: 14.52 [1/1] test_grammar
beginning 9 repetitions
123456789
.........
test_grammar leaked [2, 2, 2, 2] references, sum=8
test_grammar leaked [2, 2, 2, 2] memory blocks, sum=8
test_grammar failed (reference leak)

== Tests result: FAILURE ==

1 test failed:
    test_grammar

Total duration: 349 ms
Tests result: FAILURE

The previous commit builds correctly:

❯ git checkout HEAD^
Previous HEAD position was 7b2d94d8751 GH-106008: Make implicit boolean conversions explicit (GH-106003)
HEAD is now at 6e9f83d9aee GH-106250: Support insts using one cache entry and no oparg (GH-106252)

❯ make -j -s
...

❯ ./python.exe -m test test_grammar -R :
Raised RLIMIT_NOFILE: 256 -> 1024
0:00:00 load avg: 11.57 Run tests sequentially
0:00:00 load avg: 11.57 [1/1] test_grammar
beginning 9 repetitions
123456789
.........

== Tests result: SUCCESS ==

1 test OK.

Total duration: 342 ms
Tests result: SUCCESS

can you take a look?

@brandtbucher
Copy link
Member Author

Huh. Yeah, I'll take a look.

@brandtbucher brandtbucher reopened this Jul 3, 2023
@brandtbucher
Copy link
Member Author

Ah, I think I found it.

carljm added a commit to carljm/cpython that referenced this issue Jul 5, 2023
* main: (39 commits)
  pythongh-102542 Remove unused bytes object and bytes slicing (python#106433)
  Clarify state of CancelledError in doc (python#106453)
  pythongh-64595: Fix regression in file write logic in Argument Clinic (python#106449)
  pythongh-104683: Rename Lib/test/clinic.test as Lib/test/clinic.test.c (python#106443)
  tp_flags docs: fix indentation (python#106420)
  pythongh-104050: Partially annotate Argument Clinic CLanguage class (python#106437)
  pythongh-106368: Add tests for formatting helpers in Argument Clinic (python#106415)
  pythongh-104050: Annotate Argument Clinic parameter permutation helpers (python#106431)
  pythongh-104050: Annotate toplevel functions in clinic.py (python#106435)
  pythongh-106320: Fix specialize.c compilation by including pycore_pylifecycle.h (python#106434)
  Add some codeowners for `Tools/clinic/` (python#106430)
  pythongh-106217: Truncate the issue body size of `new-bugs-announce-notifier` (python#106423)
  pythongh-61215: Rename `wait_until_any_call` to `wait_until_any_call_with` (python#106414)
  pythongh-106162: array: suppress warning in test_array (python#106404)
  pythongh-106320: Remove _PyInterpreterState_HasFeature() (python#106425)
  pythonGH-106360: Support very basic superblock introspection (python#106422)
  pythongh-106406: Fix _Py_IsInterpreterFinalizing() in _winapi.c (python#106408)
  pythongh-106396: Special-case empty format spec to gen empty JoinedStr node (python#106401)
  pythongh-106368: Add tests for permutation helpers in Argument Clinic (python#106407)
  pythonGH-106008: Fix refleak when peepholing `None` comparisons (python#106367)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
Projects
None yet
Development

No branches or pull requests

2 participants