cap str/bytes node expansion in container and dict.fromkeys inference#3127
cap str/bytes node expansion in container and dict.fromkeys inference#3127kali834x wants to merge 2 commits into
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3127 +/- ##
=======================================
Coverage 93.62% 93.62%
=======================================
Files 92 92
Lines 11381 11385 +4
=======================================
+ Hits 10655 10659 +4
Misses 726 726
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
DanielNoord
left a comment
There was a problem hiding this comment.
Please add a test for this :)
|
Added tests in tests/brain/test_brain.py covering list/set/tuple/frozenset and dict.fromkeys: the oversized concat case declines (Instance / empty Dict) and the small-string case still infers its exact contents. |
|
Can you fix merge conflicts and the |
0830bae to
198e6aa
Compare
|
Rebased onto main, the conflict was just the ChangeLog entry. pre-commit passes locally with the updated hooks. |
Type of Changes
Description
_container_generic_transform(forlist/set/tuple/frozenset) andinfer_dict_fromkeysbuild oneConstnode per character when their argument infers to astr/bytesconstant, with no size cap. the multiply guard inconst_infer_binary_opbounds"x" * n, but string concatenation ("a" + "b") is not size-bounded and neither is a large literal, solist(("a" * 10 ** 8) + "b")walks the whole string and materializes ~100 millionConstnodes (tens of GB) during inference of otherwise untrusted source. cap both sites the same way_multiply_seq_by_intalready caps sequence repetition: fall back to the default inference once the string exceeds1e8characters, before the nodes are built. small calls (list("abc"),dict.fromkeys("ab")) keep inferring their exact contents.