Skip to content

Conversation

robertbastian
Copy link
Member

@robertbastian robertbastian commented Sep 18, 2025

1.90 improves dead code detection, so I had to do some cleanups to pass CI.

Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

I am happy that DCE is more aggressive, but I think it's swinging a bit far, and we really should avoid reaching for allow(dead_code).

I didn't comment everywhere there was a problem because there were too many.

// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

mod fixtures;
use serde::{Deserialize, Serialize};
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: make the change smaller by keeping the fixture definitions in the separate file, and just not including them in the file where they are not used

Copy link
Member Author

Choose a reason for hiding this comment

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

the problem is that multiple bench files include the same fixtures module, and some fixtures are unused in each benchmark. this puts the fixtures for each benchmark in the benchmark

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see, that's terrible...

I think well commented allow(dead_code) in a central file might be better

Copy link
Member Author

Choose a reason for hiding this comment

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

there's no shared code so this is better

#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::time_zones))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[yoke(prove_covariance_manually)]
#[allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

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

Issue: allowing dead code is bad; why do you need if?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is the one place where I don't know why, Rust says it's never constructed so it doesn't seem to detect when it's constructed from deserialization through Yoke

Copy link
Member

Choose a reason for hiding this comment

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

If that's so, it sounds like a bug, potentially a bad bug if rustc ever tries to use the same heuristic to strip symbols from the binary or something

Copy link
Member Author

Choose a reason for hiding this comment

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

definitely not the same "heuristics", DCE happens way later when types and source locations are long gone

//! <https://github.com/unicode-cldr/cldr-core/blob/master/supplemental/currencyData.json>
use serde::Deserialize;
use std::collections::BTreeMap;
Copy link
Member

Choose a reason for hiding this comment

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

Issue: if we're not using these, it's a bug. Ideally the datagen code would have been added in the same PR as the safe serde code, but that doesn't mean we should just delete the impls. Please at least make them cfg test with a little test?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea what these are, I'm certainly not going to start writing tests for them.

One of these files is not even included as module anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

They are for parsing supplemental currency data. I've been asking for @younies to finish up the currency component and he probably added these impls but doesn't use them yet, but we will be needing them.

//! TODO(#5613): Even though these markers are no longer exported, we need them in order to export
//! semantic skeleton data markers. This should be refactored to skip the intermediate data struct.
#![allow(dead_code)] // so many unused fields
Copy link
Member

Choose a reason for hiding this comment

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

Issue: I want to eventually get rid of this whole file. If fields are actually dead, delete them?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did do that whole work, but it's super messy because you end up with structs with single or even no fields, and I think it makes the tests a lot harder to parse because you lose a lot of semantics of what these are. So I reverted to this.

Copy link
Member

Choose a reason for hiding this comment

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

I haven't seen all of what we'd be losing?

Cfg(test) isn't sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

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

let's keep this massive cleanup for a different PR please

Copy link
Member Author

Choose a reason for hiding this comment

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

Cfg(test) isn't sufficient?

there are fields here that are used in code, there are fields here that are used only in tests, there are fields here that are unused. to properly clean this up, the tests need to be rewritten

Copy link
Member

@sffc sffc Sep 19, 2025

Choose a reason for hiding this comment

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

These blanket allows make future improvements harder because we won't notice when we actually can delete code

A file containing code we actually want to delete is like the worst file to put a blanket suppression


#[cfg(any(feature = "use_wasm", feature = "use_icu4c"))]
pub(crate) mod code_point_prop {
#[derive(serde::Deserialize)]
Copy link
Member

Choose a reason for hiding this comment

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

Issue: again, cldr_serde is the one place where I think we should keep the whole struct. Also, it's not completely dead code: it makes the Deserialize impls check that those fields are well formed.

Copy link
Member Author

Choose a reason for hiding this comment

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

eh, I don't think we generally assert fields that we don't use, I don't think it's that valuable

}

#[derive(serde::Serialize, serde::Deserialize)]
#[expect(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

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

Nit: comment why

Copy link
Member Author

@robertbastian robertbastian Sep 19, 2025

Choose a reason for hiding this comment

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

because we test the derive macro but never construct these

Copy link
Member

Choose a reason for hiding this comment

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

I meant add a comment in the code

Copy link
Member Author

Choose a reason for hiding this comment

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

so I put a comment on the DeriveTest structs saying "only tests derive macro"?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Copy link
Member

Choose a reason for hiding this comment

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

#[expect(dead_code)] // tests derive macro

Copy link
Member Author

Choose a reason for hiding this comment

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

seems stupid but if you insist

@robertbastian robertbastian requested a review from sffc September 19, 2025 08:23
Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

Please make allow dead_code as narrow as possible, on individual fields even, and leave code comments each time explaining why it is needed

@robertbastian
Copy link
Member Author

leave code comments each time explaining why it is needed

yeah I'm just not going to do that for the legacy datetime stuff

if this is a blocker then I'll close this PR and we can update the toolchain once that code has been cleaned up

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