Add guards to prevent lowering eval-form polynomial constants#3056
Merged
Conversation
Collaborator
Author
|
Actually, I see that this is more or less precisely what #2902 was trying to solve. That PR appears abandoned, so I will add the extra guards from that PR to this one. |
3631e0d to
1d9b1b0
Compare
Collaborator
Author
|
Ready for review. |
j2kun
approved these changes
Jun 11, 2026
3f24492 to
dc06e55
Compare
Collaborator
Author
|
Applied suggested changes and squashed. |
dc06e55 to
17c5ef9
Compare
j2kun
approved these changes
Jun 12, 2026
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PolyMulToNTT can create EVAL-form constants, but the PolynomialToModArith lowering didn't look at the form when lowering the constants, resulting in bogus lowerings (e.g., the constant polynomial f(x)=5 with the EVAL tag would be lowered to the tensor [5, 0, 0, ..., 0]). This PR adds guards to prevent such lowerings. It also adds support for lowering eval-form constants in one special case, namely when the constant is a degree-zero polynomial, because the NTT of a degree-zero polynomial with constant-term
cis [c, c, c, c, ...., c].Note that there are discussions about changing the behavior of PolyMulToNTT so that constants are forced into COEFF form, which forces PolyMulToNTT to insert explicit NTTs, which would subsequently be removed by an sccf pass. Until we get that working, I'm keeping the behavior of PolyMulToNTT on constants unchanged.
I realized that this is more or less what #2902 was trying to do, so I incorporated those changes here. Here's the rundown:
LeadingTermOp. add defensive guards for eval/coeff forms #2902 added guards for those ops as well. This is the safe thing to do, although the current code never emitted EVAL-form inputs to these ops.The implementation of the degree-zero NTT was done by AI.