Skip to content

Commit

Permalink
sagemathgh-37667: Fix noexcept clauses (sagemath#37560)
Browse files Browse the repository at this point in the history
    
In sagemath#36507 I added a lot of `noexcept` clauses guided by a warning which
is not quite right (see
cython/cython#5999 (comment)).

A new warning in 3.0.9 shows the mistake (incorrectly added `noexcept`
clauses). This broke some doctests (sagemath#37560) and a workaround was
implemented for 10.3 (sagemath#37583) since we were too close to release.

This PR now does the proper fix, removing all the incorrect `noexcept`,
and also adding a few missing `noexcept`.

Note: if one tries this PR with cython <= 3.0.8 it seems it's wrong in
the sense that it will show 40k more warnings after the PR. These are
*incorrect* warnings.

If one uses cython 3.0.9 each of these 40k lines give a correct warning
before this PR and an incorrect warnings after the PR, and there is no
way to avoid 40k warnings.

To confirm this PR is a good one, one needs to use cython 3.0.9 +
cython/cython#6087 or wait for cython 3.0.10. In
this case, the warnings are correct and one will get 40k warnings before
the PR and no warning after the PR.

The last commit reverts the workaround from sagemath#37583 so we don't silence
these warnings on `cython()` now that we have our own code right.

@vbraun: this is "almost trivial" but touches too many files. Could we
merge it in beta0 to avoid conflicts? I did this "kind of" automatically
and I've been testing it for two weeks in almost all my builds. The
changes made should not affect behaviour at all in the legacy mode we
are using cython.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
    
URL: sagemath#37667
Reported by: Gonzalo Tornaría
Reviewer(s): Gonzalo Tornaría, Matthias Köppe
  • Loading branch information
Release Manager committed Mar 31, 2024
2 parents 18deddf + bcc326d commit c51d90d
Show file tree
Hide file tree
Showing 656 changed files with 5,167 additions and 5,171 deletions.
4 changes: 2 additions & 2 deletions src/sage/algebras/clifford_algebra_element.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ from sage.modules.with_basis.indexed_element cimport IndexedFreeModuleElement
from sage.data_structures.bitset cimport FrozenBitset

cdef class CliffordAlgebraElement(IndexedFreeModuleElement):
cdef CliffordAlgebraElement _mul_self_term(self, FrozenBitset supp, coeff) noexcept
cdef CliffordAlgebraElement _mul_term_self(self, FrozenBitset supp, coeff) noexcept
cdef CliffordAlgebraElement _mul_self_term(self, FrozenBitset supp, coeff)
cdef CliffordAlgebraElement _mul_term_self(self, FrozenBitset supp, coeff)

cdef class ExteriorAlgebraElement(CliffordAlgebraElement):
pass
Expand Down
14 changes: 7 additions & 7 deletions src/sage/algebras/clifford_algebra_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ cdef class CliffordAlgebraElement(IndexedFreeModuleElement):
"""
return repr_from_monomials(self.list(), self._parent._latex_term, True)

cdef _mul_(self, other) noexcept:
cdef _mul_(self, other):
"""
Return ``self`` multiplied by ``other``.
Expand Down Expand Up @@ -176,7 +176,7 @@ cdef class CliffordAlgebraElement(IndexedFreeModuleElement):

return self.__class__(self.parent(), d)

cdef CliffordAlgebraElement _mul_self_term(self, FrozenBitset supp, coeff) noexcept:
cdef CliffordAlgebraElement _mul_self_term(self, FrozenBitset supp, coeff):
r"""
Multiply ``self * term`` with the ``term`` having support ``supp``
and coefficient ``coeff``.
Expand Down Expand Up @@ -224,7 +224,7 @@ cdef class CliffordAlgebraElement(IndexedFreeModuleElement):

return type(self)(self._parent, {supp: coeff}) * self

cdef CliffordAlgebraElement _mul_term_self(self, FrozenBitset supp, coeff) noexcept:
cdef CliffordAlgebraElement _mul_term_self(self, FrozenBitset supp, coeff):
r"""
Multiply ``term * self`` with the ``term`` having support ``supp``
and coefficient ``coeff``.
Expand Down Expand Up @@ -400,7 +400,7 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement):
"""
An element of an exterior algebra.
"""
cdef _mul_(self, other) noexcept:
cdef _mul_(self, other):
"""
Return ``self`` multiplied by ``other``.
Expand Down Expand Up @@ -520,7 +520,7 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement):

return self.__class__(P, d)

cdef CliffordAlgebraElement _mul_self_term(self, FrozenBitset supp, coeff) noexcept:
cdef CliffordAlgebraElement _mul_self_term(self, FrozenBitset supp, coeff):
r"""
Multiply ``self * term`` with the ``term`` having support ``supp``
and coefficient ``coeff``.
Expand Down Expand Up @@ -610,7 +610,7 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement):
del d[k]
return type(self)(self._parent, d)

cdef CliffordAlgebraElement _mul_term_self(self, FrozenBitset supp, coeff) noexcept:
cdef CliffordAlgebraElement _mul_term_self(self, FrozenBitset supp, coeff):
r"""
Multiply ``term * self`` with the ``term`` having support ``supp``
and coefficient ``coeff``.
Expand Down Expand Up @@ -939,7 +939,7 @@ cdef class CohomologyRAAGElement(CliffordAlgebraElement):
:class:`~sage.groups.raag.CohomologyRAAG`
"""
cdef _mul_(self, other) noexcept:
cdef _mul_(self, other):
"""
Return ``self`` multiplied by ``other``.
Expand Down
24 changes: 12 additions & 12 deletions src/sage/algebras/exterior_algebra_groebner.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ from sage.structure.parent cimport Parent
from sage.structure.element cimport MonoidElement

cdef long degree(FrozenBitset X) noexcept
cdef CliffordAlgebraElement build_monomial(Parent E, FrozenBitset supp) noexcept
cdef CliffordAlgebraElement build_monomial(Parent E, FrozenBitset supp)

cdef class GBElement:
cdef CliffordAlgebraElement elt
Expand All @@ -24,25 +24,25 @@ cdef class GroebnerStrategy:
cdef Integer rank
cdef public tuple groebner_basis

cdef inline GBElement build_elt(self, CliffordAlgebraElement f) noexcept
cdef inline GBElement prod_GB_term(self, GBElement f, FrozenBitset t) noexcept
cdef inline GBElement prod_term_GB(self, FrozenBitset t, GBElement f) noexcept
cdef inline GBElement build_elt(self, CliffordAlgebraElement f)
cdef inline GBElement prod_GB_term(self, GBElement f, FrozenBitset t)
cdef inline GBElement prod_term_GB(self, FrozenBitset t, GBElement f)
cdef inline bint build_S_poly(self, GBElement f, GBElement g) noexcept

cdef inline FrozenBitset leading_support(self, CliffordAlgebraElement f) noexcept
cdef inline partial_S_poly_left(self, GBElement f, GBElement g) noexcept
cdef inline partial_S_poly_right(self, GBElement f, GBElement g) noexcept
cdef set preprocessing(self, list P, list G) noexcept
cdef list reduction(self, list P, list G) noexcept
cdef inline FrozenBitset leading_support(self, CliffordAlgebraElement f)
cdef inline partial_S_poly_left(self, GBElement f, GBElement g)
cdef inline partial_S_poly_right(self, GBElement f, GBElement g)
cdef set preprocessing(self, list P, list G)
cdef list reduction(self, list P, list G)

cpdef CliffordAlgebraElement reduce(self, CliffordAlgebraElement f) noexcept
cpdef CliffordAlgebraElement reduce(self, CliffordAlgebraElement f)
cdef bint reduce_single(self, CliffordAlgebraElement f, CliffordAlgebraElement g) except -1
cdef int reduced_gb(self, list G) except -1

# These are the methods that determine the ordering of the monomials.
# These must be implemented in subclasses. Declare them as "inline" there.
cdef Integer bitset_to_int(self, FrozenBitset X) noexcept
cdef FrozenBitset int_to_bitset(self, Integer n) noexcept
cdef Integer bitset_to_int(self, FrozenBitset X)
cdef FrozenBitset int_to_bitset(self, Integer n)

cdef class GroebnerStrategyNegLex(GroebnerStrategy):
pass
Expand Down
36 changes: 18 additions & 18 deletions src/sage/algebras/exterior_algebra_groebner.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cdef inline long degree(FrozenBitset X) noexcept:
return bitset_len(X._bitset)


cdef inline CliffordAlgebraElement build_monomial(Parent E, FrozenBitset supp) noexcept:
cdef inline CliffordAlgebraElement build_monomial(Parent E, FrozenBitset supp):
"""
Helper function for the fastest way to build a monomial.
"""
Expand Down Expand Up @@ -130,14 +130,14 @@ cdef class GroebnerStrategy:
else:
self.side = 2

cdef inline FrozenBitset leading_support(self, CliffordAlgebraElement f) noexcept:
cdef inline FrozenBitset leading_support(self, CliffordAlgebraElement f):
"""
Return the leading support of the exterior algebra element ``f``.
"""
cdef dict mc = <dict> f._monomial_coefficients
return self.int_to_bitset(max(self.bitset_to_int(k) for k in mc))

cdef inline partial_S_poly_left(self, GBElement f, GBElement g) noexcept:
cdef inline partial_S_poly_left(self, GBElement f, GBElement g):
r"""
Compute one half of the `S`-polynomial for ``f`` and ``g``.
Expand All @@ -154,7 +154,7 @@ cdef class GroebnerStrategy:
ret.elt._monomial_coefficients[k] *= inv
return ret

cdef inline partial_S_poly_right(self, GBElement f, GBElement g) noexcept:
cdef inline partial_S_poly_right(self, GBElement f, GBElement g):
r"""
Compute one half of the `S`-polynomial for ``f`` and ``g``.
Expand All @@ -171,7 +171,7 @@ cdef class GroebnerStrategy:
ret.elt._monomial_coefficients[k] *= inv
return ret

cdef inline GBElement build_elt(self, CliffordAlgebraElement f) noexcept:
cdef inline GBElement build_elt(self, CliffordAlgebraElement f):
"""
Convert ``f`` into a ``GBElement``.
"""
Expand All @@ -181,7 +181,7 @@ cdef class GroebnerStrategy:
cdef Integer r = <Integer> max(self.bitset_to_int(k) for k in mc)
return GBElement(f, self.int_to_bitset(r), r)

cdef inline GBElement prod_GB_term(self, GBElement f, FrozenBitset t) noexcept:
cdef inline GBElement prod_GB_term(self, GBElement f, FrozenBitset t):
"""
Return the GBElement corresponding to ``f * t``.
Expand All @@ -193,7 +193,7 @@ cdef class GroebnerStrategy:
cdef FrozenBitset ls = <FrozenBitset> f.ls._union(t)
return GBElement(<CliffordAlgebraElement> ret, ls, self.bitset_to_int(ls))

cdef inline GBElement prod_term_GB(self, FrozenBitset t, GBElement f) noexcept:
cdef inline GBElement prod_term_GB(self, FrozenBitset t, GBElement f):
"""
Return the GBElement corresponding to ``t * f``.
Expand All @@ -220,7 +220,7 @@ cdef class GroebnerStrategy:

return (<FrozenBitset> f.ls.intersection(g.ls)).isempty()

cdef inline set preprocessing(self, list P, list G) noexcept:
cdef inline set preprocessing(self, list P, list G):
"""
Perform the preprocessing step.
"""
Expand Down Expand Up @@ -266,7 +266,7 @@ cdef class GroebnerStrategy:
break
return L

cdef inline list reduction(self, list P, list G) noexcept:
cdef inline list reduction(self, list P, list G):
"""
Perform the reduction of ``P`` mod ``G`` in ``E``.
"""
Expand Down Expand Up @@ -451,7 +451,7 @@ cdef class GroebnerStrategy:
cdef list G = [self.build_elt(f) for f in self.groebner_basis]
self.reduced_gb(G)

cpdef CliffordAlgebraElement reduce(self, CliffordAlgebraElement f) noexcept:
cpdef CliffordAlgebraElement reduce(self, CliffordAlgebraElement f):
"""
Reduce ``f`` modulo the ideal with Gröbner basis ``G``.
Expand Down Expand Up @@ -533,10 +533,10 @@ cdef class GroebnerStrategy:
iaxpy(-coeff, gp._monomial_coefficients, f._monomial_coefficients)
return was_reduced

cdef Integer bitset_to_int(self, FrozenBitset X) noexcept:
cdef Integer bitset_to_int(self, FrozenBitset X):
raise NotImplementedError

cdef FrozenBitset int_to_bitset(self, Integer n) noexcept:
cdef FrozenBitset int_to_bitset(self, Integer n):
raise NotImplementedError

def sorted_monomials(self, as_dict=False):
Expand Down Expand Up @@ -615,7 +615,7 @@ cdef class GroebnerStrategyNegLex(GroebnerStrategy):
"""
Gröbner basis strategy implementing neglex ordering.
"""
cdef inline Integer bitset_to_int(self, FrozenBitset X) noexcept:
cdef inline Integer bitset_to_int(self, FrozenBitset X):
"""
Convert ``X`` to an :class:`Integer`.
"""
Expand All @@ -626,7 +626,7 @@ cdef class GroebnerStrategyNegLex(GroebnerStrategy):
elt = bitset_next(X._bitset, elt + 1)
return ret

cdef inline FrozenBitset int_to_bitset(self, Integer n) noexcept:
cdef inline FrozenBitset int_to_bitset(self, Integer n):
"""
Convert a nonnegative integer ``n`` to a :class:`FrozenBitset`.
"""
Expand All @@ -646,7 +646,7 @@ cdef class GroebnerStrategyDegRevLex(GroebnerStrategy):
"""
Gröbner basis strategy implementing degree revlex ordering.
"""
cdef inline Integer bitset_to_int(self, FrozenBitset X) noexcept:
cdef inline Integer bitset_to_int(self, FrozenBitset X):
"""
Convert ``X`` to an :class:`Integer`.
"""
Expand All @@ -665,7 +665,7 @@ cdef class GroebnerStrategyDegRevLex(GroebnerStrategy):
elt = bitset_next(X._bitset, elt + 1)
return Integer(sum(n.binomial(i) for i in range(deg+1)) - t - 1)

cdef inline FrozenBitset int_to_bitset(self, Integer n) noexcept:
cdef inline FrozenBitset int_to_bitset(self, Integer n):
"""
Convert a nonnegative integer ``n`` to a :class:`FrozenBitset`.
"""
Expand All @@ -687,7 +687,7 @@ cdef class GroebnerStrategyDegLex(GroebnerStrategy):
"""
Gröbner basis strategy implementing degree lex ordering.
"""
cdef inline Integer bitset_to_int(self, FrozenBitset X) noexcept:
cdef inline Integer bitset_to_int(self, FrozenBitset X):
"""
Convert ``X`` to an :class:`Integer`.
"""
Expand All @@ -706,7 +706,7 @@ cdef class GroebnerStrategyDegLex(GroebnerStrategy):
elt = bitset_next(X._bitset, elt + 1)
return Integer(sum(n.binomial(i) for i in range(deg+1)) - t - 1)

cdef inline FrozenBitset int_to_bitset(self, Integer n) noexcept:
cdef inline FrozenBitset int_to_bitset(self, Integer n):
"""
Convert a nonnegative integer ``n`` to a :class:`FrozenBitset`.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement):
cdef Matrix __matrix
cdef FiniteDimensionalAlgebraElement __inverse

cpdef FiniteDimensionalAlgebraElement unpickle_FiniteDimensionalAlgebraElement(A, vec, mat) noexcept
cpdef FiniteDimensionalAlgebraElement unpickle_FiniteDimensionalAlgebraElement(A, vec, mat)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ from sage.rings.integer import Integer

from cpython.object cimport PyObject_RichCompare as richcmp

cpdef FiniteDimensionalAlgebraElement unpickle_FiniteDimensionalAlgebraElement(A, vec, mat) noexcept:
cpdef FiniteDimensionalAlgebraElement unpickle_FiniteDimensionalAlgebraElement(A, vec, mat):
"""
Helper for unpickling of finite dimensional algebra elements.
Expand Down Expand Up @@ -365,7 +365,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement):
return self._vector.ncols()

# (Rich) comparison
cpdef _richcmp_(self, right, int op) noexcept:
cpdef _richcmp_(self, right, int op):
"""
EXAMPLES::
Expand Down Expand Up @@ -400,7 +400,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement):
"""
return richcmp(self._vector, <FiniteDimensionalAlgebraElement>right._vector, op)

cpdef _add_(self, other) noexcept:
cpdef _add_(self, other):
"""
EXAMPLES::
Expand All @@ -411,7 +411,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement):
"""
return self._parent.element_class(self._parent, self._vector + <FiniteDimensionalAlgebraElement>other._vector)

cpdef _sub_(self, other) noexcept:
cpdef _sub_(self, other):
"""
EXAMPLES::
Expand All @@ -422,7 +422,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement):
"""
return self._parent.element_class(self._parent, self._vector - <FiniteDimensionalAlgebraElement>other._vector)

cpdef _mul_(self, other) noexcept:
cpdef _mul_(self, other):
"""
EXAMPLES::
Expand All @@ -434,7 +434,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement):
"""
return self._parent.element_class(self._parent, self._vector * <FiniteDimensionalAlgebraElement>(other)._matrix)

cpdef _lmul_(self, Element other) noexcept:
cpdef _lmul_(self, Element other):
"""
TESTS::
Expand All @@ -450,7 +450,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement):
.format(self.parent(), other.parent()))
return self._parent.element_class(self._parent, self._vector * other)

cpdef _rmul_(self, Element other) noexcept:
cpdef _rmul_(self, Element other):
"""
TESTS::
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cdef _fmat(fvars, Nk_ij, one, a, b, c, d, x, y) noexcept
cpdef _backward_subs(factory, bint flatten=*) noexcept
cpdef executor(tuple params) noexcept
cpdef _solve_for_linear_terms(factory, list eqns=*) noexcept
cdef _fmat(fvars, Nk_ij, one, a, b, c, d, x, y)
cpdef _backward_subs(factory, bint flatten=*)
cpdef executor(tuple params)
cpdef _solve_for_linear_terms(factory, list eqns=*)
Loading

0 comments on commit c51d90d

Please sign in to comment.