add defensive guards for eval/coeff forms#2902
Open
toprakmurat wants to merge 1 commit intogoogle:mainfrom
Open
add defensive guards for eval/coeff forms#2902toprakmurat wants to merge 1 commit intogoogle:mainfrom
toprakmurat wants to merge 1 commit intogoogle:mainfrom
Conversation
crockeea
reviewed
Apr 27, 2026
Collaborator
crockeea
left a comment
There was a problem hiding this comment.
I think a COEFF constraint on ConvertBasisOp is missing.
|
|
||
| auto typeInfo = res.value(); | ||
|
|
||
| if (typeInfo.polynomialType.getForm() != Form::COEFF) { |
Collaborator
There was a problem hiding this comment.
Constant ops should be allowed to output eval-form polys; see https://github.com/google/heir/blob/main/lib/Dialect/Polynomial/Transforms/PolyMulToNTT.cpp#L526 and #2751. The source of truth here is https://github.com/google/heir/blob/main/lib/Dialect/Polynomial/Transforms/PolyMulToNTT.cpp#L59.
| op, "failed to construct common conversion info"); | ||
| auto typeInfo = res.value(); | ||
|
|
||
| if (typeInfo.polynomialType.getForm() != Form::COEFF) { |
Collaborator
There was a problem hiding this comment.
Ditto here; see https://github.com/google/heir/blob/main/lib/Dialect/Polynomial/Transforms/PolyMulToNTT.cpp#L59. As a CONST op, this output a polynomial in either form.
| op, "failed to construct common conversion info"); | ||
| auto typeInfo = res.value(); | ||
|
|
||
| if (typeInfo.polynomialType.getForm() != Form::COEFF) { |
Collaborator
There was a problem hiding this comment.
LeadingTerm op doesn't output a poly, does it?
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.
Fixes #2849
This PR adds strict
getForm()checks to all polynomial-to-mod-arith lowerings that assume a specific polynomial form (COEFForEVAL).Previously, operations that only make mathematical sense in
COEFFform (e.g.,FromTensorOp,LeadingTermOp) would silently miscompile if fed anEVALform polynomial. These conversion patterns now return anotifyMatchFailureif the input form is incorrect.Changes made:
Added
Form::COEFFchecks to:ConvertFromTensor,ConvertConstant,ConvertMonomial,ConvertMonicMonomialMul,ConvertLeadingTerm,ConvertApplyCoefficientwise, andConvertNTT.Added a
Form::EVALcheck to:ConvertINTT.(Note: I think that the first part of #2849 was previously implemented via the
ConvertMulEvalFormstruct, so no additional changes were needed for that requirement).