Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(transport): remove module_name_repetitions #2284

Open
mxinden opened this issue Dec 12, 2024 · 8 comments
Open

chore(transport): remove module_name_repetitions #2284

mxinden opened this issue Dec 12, 2024 · 8 comments
Labels
good first issue Good for newcomers p3 Backlog

Comments

@mxinden
Copy link
Collaborator

mxinden commented Dec 12, 2024

We allow the clippy lint module_name_repetitions:

#![allow(clippy::module_name_repetitions)] // This lint doesn't work here.

We e.g. prefix various types in the ecn module with Ecn:

/// The number of packets to use for testing a path for ECN capability.
pub const ECN_TEST_COUNT: usize = 10;
/// The number of packets to use for testing a path for ECN capability when exchanging
/// Initials during the handshake. This is a lower number than [`ECN_TEST_COUNT`] to avoid
/// unnecessarily delaying the handshake; we would otherwise double the PTO [`ECN_TEST_COUNT`]
/// times.
const ECN_TEST_COUNT_INITIAL_PHASE: usize = 3;
/// The state information related to testing a path for ECN capability.
/// See RFC9000, Appendix A.4.
#[derive(Debug, PartialEq, Clone, Copy)]
enum EcnValidationState {

As discussed in #2270 (comment), I suggest removing the allow and instead fix the module name repetition.

@mxinden mxinden added good first issue Good for newcomers p3 Backlog labels Dec 12, 2024
@mansf-osk
Copy link
Collaborator

I'll start working on this! Are there any places where we don't want to get rid of the module name repetitions? As far as I can see we allow them in a lot of modules, just going by this quick search.

Maybe it makes sense to remove the crate-wide allow attributes (as the one referenced above) and leave be or possibly add local allow's where it makes sense to keep the module name repetitions?

@mxinden
Copy link
Collaborator Author

mxinden commented Jan 3, 2025

@mansf-osk I suggest starting with a single module, e.g. neqo-transport/src/ecn.rs.

Small pull requests reduce the likelihood of merge conflicts and make reviewing easier.

Maybe it makes sense to remove the crate-wide allow attributes (as the one referenced above) and leave be or possibly add local allow's where it makes sense to keep the module name repetitions?

Happy for the crate-wide #![allow(clippy::module_name_repetitions)] to be replaced by the missing local allows with the first pull request.

@larseggert
Copy link
Collaborator

Just so I understand, we would rename e.g. EcnInfo to Ecn::Info, i.e. prefix with the module name? (Because otherwise Info is a bit generic.)

@mxinden
Copy link
Collaborator Author

mxinden commented Jan 4, 2025

It would be defined as:

// neqo-transport/src/ecn.rs

pub struct Info {
  // ...
}

and it would be used as:

// Some other file.

use ecn;

fn my_func() {
  let ecn_info = ecn::Info::new();
}

Just like in the standard library where it is std::io::Error and not std::io::IoError.

Does that make sense @larseggert?

@mansf-osk
Copy link
Collaborator

I'd like some feedback on the following before eventually tackling more of this refactor!

The way we did it in #2311 (like in Max's example above) we would eventually end up losing lots of explicit imports that we have right now. I'm not that big a fan of that personally, so I'd like to use aliases instead, as is also suggested in the discussions around that lint's RFC. I especially like the following sentiment in that comment:

"Essentially, this pushes resolving overlaps between names to the client of an API (where the overlaps are actually created) rather than the provider of an API (who would otherwise have to guess at which overlaps will occur)."

Going by the example above it would look like that:

use ecn::{Info as EcnInfo, Config as EcnConfig}

fn my_func() {
    let ecn_info = EcnInfo::new();
    let ecn_config = EcnConfig::new();
    // ...
}

That way we still have the prefix for clarity where we consume the API while also adhering to the lint and not losing all our explicit imports. As I see it this is the most canonical way to implement that lint.

Thoughts?

@larseggert
Copy link
Collaborator

larseggert commented Jan 16, 2025

WFM, but it requires the importer to not be lazy and leave the import named as-is. If the importer was lazy, your example would look like this, which I think would be bad:

use ecn::{Info, Config}

fn my_func() {
    let ecn_info = Info::new();
    let ecn_config = Config::new();
    // ...
}

@mxinden
Copy link
Collaborator Author

mxinden commented Jan 16, 2025

The way we did it in #2311 (like in Max's example above) we would eventually end up losing lots of explicit imports that we have right now. I'm not that big a fan of that personally, so I'd like to use aliases instead, as is also suggested in the discussions around that lint's RFC.

I don't think "losing lots of explicit imports" is a problem.

In my eyes importing a module (e.g. use ecn;) only is simpler,

use ecn;

fn my_func() {
  let ecn_info = ecn::Info::new();
  let ecn_config = ecn::Config::new();
}

than the aliasing:

use ecn::{Info as EcnInfo, Config as EcnConfig}

fn my_func() {
    let ecn_info = EcnInfo::new();
    let ecn_config = EcnConfig::new();
}

@mansf-osk
Copy link
Collaborator

Thanks for the feedback, I'll keep it as is then. Will put the refactor in my backlog and chip away at it when I have bandwidth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers p3 Backlog
Projects
None yet
Development

No branches or pull requests

3 participants