Conversation
the venom-direct codegen for convert() forked the legacy conversion logic and dropped two kinds of knowledge in the port: the per-target input type allowlists (GH 5019, GH 5111) and the truncating (rather than floor) division used to compute the int->decimal clamp bounds (GH 5110). the result was a cluster of accepts-invalid bugs -- programs which legacy rejects with TypeMismatch compiled to bytecode -- and an off-by-one lower clamp which admits one extra negative value whose scaled result lands below the decimal type's lower bound, producing an out-of-range decimal at runtime. this is the third round of such fixes in this file (after GH 4987 and GH 5019); patching individual instances does not converge. instead, extract the conversion matrix and the numeric clamp bounds into a new backend-neutral module, vyper/builtins/_convert_rules.py, used by both pipelines: legacy's @_input_types decorator delegates to it, and venom's lower_convert() validates against it at dispatch before lowering. the checks the venom helpers had accreted piecemeal (GH 4987) are removed in favor of the single dispatch-time validation; value-dependent checks (literal ranges, literal bytestring downcasts) stay in codegen. the module deliberately imports only from vyper.semantics and vyper.utils so that either backend (and potentially the frontend typechecker, in the future) can use it without import cycles. note: the existing conversion matrix tests did not catch these divergences because several output formats (ir_dict, metadata, abi) run the legacy codegen even under --experimental-codegen, so the test harness's multi-format compilation lets legacy validation mask venom bugs. the new regression tests compile bytecode-only.
conversion legality is a language rule, but it was only enforced at codegen time, separately by each pipeline. call the shared validate_convertibility() from Convert.infer_arg_types so illegal conversions are rejected at semantic analysis for every backend. codegen-level validation stays in place as defense-in-depth, so the legacy pipeline is undisturbed. no semantics change -- only where the error is raised. programs that compile today keep compiling; illegal conversions now surface at typechecking (same exception types) instead of codegen, including for analysis-only consumers.
|
note that this doesn't touch the legacy pipeline as per charles ask, so it's redundant and it meant to demonstrate the shape for where things could more logically belong. this pr assumes a buy-in and some further careful cleanup work. |
Sporarum
left a comment
There was a problem hiding this comment.
Nice work !
To me the most important change is to move the check actually in the type checker, currently it looks like it was just moved to a shared helper
(I explain in more details in one of the comments)
|
Addressed in
Validation:
|
|
Addressed the fresh convert feedback in ba43a56. Changes: added a Convert class docstring explaining the target-to-source direction, moved exact FlagT <-> uint256 handling into the target-keyed source-type lookup, clarified that the Venom codegen path relies on typechecker rejection, and left an explicit comment at the infer_arg_types validation point. Focused validation: |
|
Please add a test that checks that |
|
Addressed in banteg/vyper@287a21415. Changes:
Validation:
|
|
@banteg merge conflict, i'm guessing due to the new flag->bytes32 rule |
# Conflicts: # vyper/builtins/_convert.py
|
Resolved in banteg/vyper@93d90c2f0 with a normal merge commit from current upstream The conflict was the upstream
Validation:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93d90c2f01
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
handed reins back to the bot |
Keep the bool source-type tuple direct and rely on the CI compiler matrix when testing oversized dynamic bytes, avoiding redundant backend parametrization inside the test.
|
Addressed the fresh review feedback in 01189b8 after merging current master normally (a44cdc3): simplified the bool source tuple, restored CI-matrix backend coverage for the oversized-Bytes test, marked and documented the semantic-analysis compatibility break, and linked #5126 from #4572. Validation: focused convert suites 11,287 passed per backend; full functional syntax+builtins 13,737 passed / 16 xfailed per backend; |
|
Remaining review feedback is addressed in
Validation: |
|
Addressed the complete August 7 changes-requested review in 87f5371. I confirmed that five source-map entries were always overridden; only BytesT and StringT remained, so the map is removed and those two cases are inline. The Venom clamp variables now use out_lo/out_hi, and bool is the final explicit integer-source branch with an unreachable panic after it. Validation: the full conversion suites passed under legacy and Venom (11,287 each), and make lint plus git diff --check passed. The PR description is refreshed and all four review threads are resolved. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Refreshed against master in 363ae3e. Since #5127 already added The workflows on this exact head, including the test suite, are waiting for maintainer approval ( |
|
The fuzzing-lane follow-up is now #5270 (draft, with this PR as its merge prerequisite). Enabling Venom exposes the negative integer-to-decimal boundary defect on current master. All 48 affected boundary cases pass with this fix, and all 15,750 reverting conversion cases pass on current master with #5270's harness changes and this PR's source patch applied. The new lane keeps those assertions strict. |
What I did
Remove duplicate
convert()legality checks from legacy and Venom lowering, and share numeric clamp bounds, including the negative decimal boundary fix for #5110.Current master already validates type pairs in
Convert.infer_arg_typesthrough_convert_rules.validate_convertibility(merged in #5127). This PR uses that implementation instead of adding a second semantic matrix. It does not claim a new change to analysis-only rejection timing.How I did it
Keep the shared semantic validator as the authority for legal source/target pairs. Remove redundant backend type restrictions, retain value-dependent bounds checks and the runtime length check for unbounded bytes, and share integer/decimal clamp calculations through
_convert_bounds.py.The conversion-matrix test checks the shared validator against the existing test oracle. Direct literal inference and full-compile behavior remain covered.
How to verify it
Conversion syntax and functional suites pass on both pipelines: 11,287 passed per backend.
The Venom unbounded bytes/string/dynamic-array runtime suite also passes: 209 passed.
make lintpasses.Commit message
Description for the changelog
Fix the negative decimal conversion clamp boundary and share conversion bounds between backends.
Cute Animal Picture