Skip to content

Conversation

@albinahlback
Copy link
Collaborator

Background

With #2438, I enabled warnings when global functions were defined without a prior prototype given. This intends to warns users that

  • A global function is defined without it being defined in a header;
  • A global function should be declared static.

Moreover, declaring prototypes inside source files should be considered a bad habit. Typically in FLINT, prototypes are given inside source files for:

  • When an internal function is defined in another source file;
  • Forward declarations (which is usually a good use case).

However, when giving the prototype inside a source file, no check is done for ABI compatibilities. Hence, things may break.

This PR

In this PR, I declare a lot of functions static. Moreover, I implement */impl.h headers, intended for declaring internal functions and use them where necessary.

However, this PR is not complete, and I will continue working on doing all modules (now I have only done it up until GR) and all tests (so that I can push -Wmissing-prototypes to the tests).

@albinahlback
Copy link
Collaborator Author

I used dev/check_prototypes to list all prototypes given in the source files. Some exceptions exists, which I have listed in there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is completely unused in FLINT.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially a useful algorithm. Maybe @pascalmolin can document it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this file and entrywise_not_is_zero.c. Not sure why they exist.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were added at some point because the author needed them. It's possible that they are used externally. We can perhaps deprecate them and remove them in the next next release?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was also unused? @fredrik-johansson can you just verify that this has no use case for FLINT? I recall it existing in some comment somewhere.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is useful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at some point Dan wanted to do arithmetic on fmpz_mpoly in factored form, but this function is not very interesting on its own. OK to delete.

@albinahlback albinahlback force-pushed the prototype_fixes branch 2 times, most recently from 17ac6c3 to 5fd7ecb Compare October 30, 2025 15:20
@fredrik-johansson
Copy link
Collaborator

Could you please do this as several independent PRs, where each PR does one kind of change?

@fredrik-johansson
Copy link
Collaborator

I'm really not convinced that the impl.h headers are an improvement. In the cases I looked at, we could just decide whether the functions should be static or not.

@@ -404,301 +404,6 @@ int nmod_mpolyun_equal(
return 1;
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit uneasy about outright deleting this kind of mpoly code. It sometimes helps understand the (poorly documented) code that is actually used. Could you ifdef it out instead, with a comment like "This code is unused. TODO: delete it when the surrounding code is adequately tested and commented."? I think I've already done this elsewhere.

Comment on lines -30 to -39
/*
Display a relation for debugging purposes
*/
void qsieve_display_relation(qs_t qs_inf, relation_t a)
{
slong i;

flint_printf("%wu ", a.lp);

for (i = 0; i < qs_inf->small_primes; i++)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

Comment on lines 904 to 912

void nmod_mpolyu_msub(nmod_mpolyu_t R, nmod_mpolyu_t A, nmod_mpolyu_t B,
nmod_mpoly_t c, slong e, const nmod_mpoly_ctx_t ctx)
{
slong i, j, k;
nmod_mpoly_t T;

nmod_mpolyu_fit_length(R, A->length + B->length, ctx);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

Comment on lines 22 to 40
void _n_fq_poly_rem_basecase_(
ulong * Q,
ulong * A,
const ulong * AA, slong Alen,
const ulong * B, slong Blen,
const ulong * invB,
const fq_nmod_ctx_t ctx,
n_poly_stack_t St)
{
slong i;
slong d = fq_nmod_ctx_degree(ctx);
nmod_t mod = fq_nmod_ctx_mod(ctx);
ulong * tmp = n_poly_stack_vec_init(St, d*(3 + N_FQ_POLY_DIVREM_BASECASE_ITCH));
ulong * u = tmp + d*N_FQ_POLY_DIVREM_BASECASE_ITCH;
ulong * q0 = u + d;
ulong * q1 = q0 + d;

if (A != AA)
_nmod_vec_set(A, AA, d*Alen);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header

Comment on lines 16 to 23
int fq_zech_mpoly_repack_bits(fq_zech_mpoly_t A, const fq_zech_mpoly_t B,
flint_bitcnt_t Abits, const fq_zech_mpoly_ctx_t ctx)
{
slong i;
int success;
fq_zech_mpoly_t T;

Abits = mpoly_fix_bits(Abits, ctx->minfo);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 0

Comment on lines 145 to 147

/* if the coefficient doesn't exist, a new one is created (and set to zero) */
fq_zech_mpoly_struct * _fq_zech_mpolyu_get_coeff(fq_zech_mpolyu_t A,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 0

Comment on lines 88 to 90
void fq_zech_mpoly_evaluate_all_ui(fq_zech_t eval, const fq_zech_mpoly_t A,
fq_zech_struct * const * vals, const fq_zech_mpoly_ctx_t ctx)
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 0

Comment on lines 407 to 410
void fq_nmod_mpoly_to_mpolyuu_perm_deflate(
fq_nmod_mpolyu_t A,
const fq_nmod_mpoly_ctx_t uctx,
const fq_nmod_mpoly_t B,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 0

Comment on lines 17 to 24
fmpzi_norm_approx_d_2exp(slong * exp, const fmpzi_t x)
{
double a, b;
slong aexp, bexp;
int e;

a = fmpz_get_d_2exp(&aexp, fmpzi_realref(x));
b = fmpz_get_d_2exp(&bexp, fmpzi_imagref(x));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 0

Comment on lines 17 to 21
/*
assuming that the conversion can be done, set poly1 and poly1_shift
so that poly2 is poly1 * X^poly1_shift
TODO: handle multiprecision exponents
*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to header

Comment on lines 169 to 172
void fmpz_mod_mpolyu_repack_bits_inplace(
fmpz_mod_mpolyu_t A,
flint_bitcnt_t bits,
const fmpz_mod_mpoly_ctx_t ctx)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 0

Comment on lines 161 to 163
void fmpz_mod_mpolyu_one(fmpz_mod_mpolyu_t A, const fmpz_mod_mpoly_ctx_t uctx)
{
fmpz_mod_mpolyu_fit_length(A, WORD(1), uctx);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 0

Comment on lines 16 to 19
/*
E = A(v = alpha)
A is in R[v][x]
E is in R[x]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 0

Comment on lines 551 to 556
void fmpz_mod_mpoly_univar_set(
fmpz_mod_mpoly_univar_t A,
const fmpz_mod_mpoly_univar_t B,
const fmpz_mod_mpoly_ctx_t ctx)
{
slong i;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 0

Comment on lines 35 to 37
void
_acb_dirichlet_theta_arb_series(acb_t res, const dirichlet_group_t G, const dirichlet_char_t chi, const arb_t xt, slong len, slong prec)
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header

Comment on lines 1441 to 1445
acb_dirichlet_platt_isolate_local_hardy_z_zeros(
arf_interval_ptr res, const fmpz_t n, slong len, slong prec)
{
if (len <= 0 || fmpz_sizeinbase(n, 10) < 5)
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header

Comment on lines 1074 to 1078
slong
_acb_dirichlet_platt_isolate_local_hardy_z_zeros(
arf_interval_ptr res, const fmpz_t n, slong len,
const fmpz_t T, slong A, slong B,
const arb_t h, const fmpz_t J, slong K, slong sigma_grid,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header

Comment on lines 113 to 115
void
acb_dft_inverse_cyc(acb_ptr w, acb_srcptr v, slong len, slong prec)
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header

Comment on lines 60 to 69
void
mag_rsqrt_re_quadrant1_lower(mag_t res, const mag_t x, const mag_t y)
{
if (mag_is_zero(x))
{
mag_one(res);
mag_mul_2exp_si(res, res, -1);
}
else
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 0

@albinahlback
Copy link
Collaborator Author

@fredrik-johansson everything should be fixed accordingly now.

@albinahlback albinahlback merged commit 88eb14c into flintlib:main Nov 1, 2025
14 checks passed
@albinahlback albinahlback deleted the prototype_fixes branch November 1, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants