FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add ConditionalExpr support to `constant_fold_expr` [2/2] by BobTheBuidler · Pull Request #19984 · python/mypy · GitHub

Repository navigation

feat: add ConditionalExpr support to constant_fold_expr [2/2] - #19984

Draft
BobTheBuidler wants to merge 6 commits into
python:masterfrom
BobTheBuidler:patch-14
Draft

BobTheBuidler wants to merge 6 commits into
python:masterfrom
BobTheBuidler:patch-14

Conversation

Copy link
Copy Markdown
Contributor

This PR adds ConditionalExpr support to constant_fold_expr

BobTheBuidler changed the title [mypyc] feat: add ConditionalExpr support to constant_fold_expr feat: add ConditionalExpr support to constant_fold_expr [1/1] Oct 2, 2025

This comment has been minimized.

JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you add an irbuild test and a run test?

Copy link
Copy Markdown
Contributor Author

Hmm that's weird, it looks like the constant for the base folded correctly, as did the 2 branch values, but not the overall expression

________________________ testConditionalConstantFolding ________________________
[gw3] linux -- Python 3.10.18 /home/runner/work/mypy/mypy/.tox/py/bin/python
data: /home/runner/work/mypy/mypy/mypyc/test-data/irbuild-constant-fold.test:482:
Failed: Invalid source code output (/home/runner/work/mypy/mypy/mypyc/test-data/irbuild-constant-fold.test, line 482)
----------------------------- Captured stderr call -----------------------------
Expected:
  def f():
      a :: str (diff)
  L0:
      a = "t" (diff)
Actual:
  def f():
      r0 :: bit (diff)
      r1, r2, r3, a :: str (diff)
  L0:
      r0 = 2 != 0 (diff)
      if r0 goto L1 else goto L2 :: bool (diff)
  L1: (diff)
      r1 = 't' (diff)
      r2 = r1 (diff)
      goto L3 (diff)
  L2: (diff)
      r3 = 'f' (diff)
      r2 = r3 (diff)
  L3: (diff)
      a = r2 (diff)
      return 1 (diff)

Alignment of first line difference:
  E:     a :: str
  A:     r0 :: bit
         ^

Copy link
Copy Markdown
Contributor Author

I mean... I guess it did constant fold all of the necessary values... And I think with the code like this the C compiler can optimize away the if check in some cases (ex: ints), but not all (ex: strings)

This comment has been minimized.

BobTheBuidler marked this pull request as draft October 2, 2025 19:50

Copy link
Copy Markdown
Contributor Author

Oh, I know why! Let's put this on hold until #19982 is merged, so I can use the @folding_candidate decorator

BobTheBuidler changed the title feat: add ConditionalExpr support to constant_fold_expr [1/1] feat: add ConditionalExpr support to constant_fold_expr [2/2] Oct 3, 2025

github-actions Bot commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL