Skip to content

editoast: use type SupportedSignalingSystem everywhere - #16982

Merged
woshilapin merged 2 commits into
devfrom
wsl/editoast-use-type-SupportedSignalingSystem-everywhere
Sep 25, 2026
Merged

woshilapin merged 2 commits into
devfrom
wsl/editoast-use-type-SupportedSignalingSystem-everywhere

Conversation

@woshilapin

Copy link
Copy Markdown
Contributor

In some places, we were converting to String with no real added value. Let’s keep HashSet<SupportedSignalingSystem> everywhere, avoiding conversions.

One of the inconvenient is the implementation of Hash for some of the struct that contains it (HashSet doesn’t implement Hash). With the help of educe, we can plug a custom function to hash such a HashSet. And we consider create a bitmask of all the present variant, using the discriminant of the variant’s enum. This should be unique, even if the order of the iteration is different.

@woshilapin
woshilapin requested review from hhirtz and leovalais May 29, 2026 14:21
@github-actions github-actions Bot added the area:editoast Work on Editoast Service label May 29, 2026
Comment thread editoast/schemas/Cargo.toml
Comment thread editoast/schemas/src/rolling_stock/supported_signaling_system.rs Outdated
Comment thread editoast/schemas/src/rolling_stock/supported_signaling_system.rs Outdated
@woshilapin
woshilapin force-pushed the wsl/editoast-use-type-SupportedSignalingSystem-everywhere branch 2 times, most recently from c2c82f0 to 4eac28f Compare May 29, 2026 22:22
Comment thread editoast/schemas/src/rolling_stock/supported_signaling_system.rs Outdated
@woshilapin
woshilapin force-pushed the wsl/editoast-use-type-SupportedSignalingSystem-everywhere branch from 20656d0 to dc89962 Compare June 2, 2026 07:55
@github-actions github-actions Bot added area:front Work on Standard OSRD Interface modules kind:api-change labels Jun 2, 2026
@github-actions

github-actions Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ API changes

This Pull Request introduces some changes in the API:

  • please own it: notify or even prepare dedicated PR(s) to consumer projects

@woshilapin
woshilapin marked this pull request as ready for review June 2, 2026 08:04
@woshilapin
woshilapin requested a review from a team as a code owner June 2, 2026 08:04
@woshilapin
woshilapin force-pushed the wsl/editoast-use-type-SupportedSignalingSystem-everywhere branch from dc89962 to 204cb54 Compare June 2, 2026 08:40

@hhirtz hhirtz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not sure adding more macro is a good step towards lower compilation times though... 🤔

Comment thread editoast/schemas/src/rolling_stock/supported_signaling_system.rs
Comment thread editoast/schemas/src/rolling_stock/supported_signaling_system.rs Outdated

@leovalais leovalais left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread editoast/schemas/src/rolling_stock/supported_signaling_system.rs Outdated
@woshilapin
woshilapin force-pushed the wsl/editoast-use-type-SupportedSignalingSystem-everywhere branch from 204cb54 to deee42f Compare August 6, 2026 08:39
@woshilapin
woshilapin requested a review from hhirtz September 24, 2026 12:56
@woshilapin
woshilapin force-pushed the wsl/editoast-use-type-SupportedSignalingSystem-everywhere branch 2 times, most recently from 8b3edd3 to fb7c1a6 Compare September 24, 2026 13:12

@hhirtz hhirtz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! more typing is good, but i think this solution is overengineered

first commit message says:

The function that hashes a HashSet<SupportedSignalingSystemVariant>
is not trivial

but it is though? if you inline the discriminant functions you see it's just a 1-statement for loop and a call to hash. i don't think it calls for 4 tests with proptest... although i agree it's fun to play with, editoast isn't a playground for it

It looks like if we impl Ord for SupportedSignalingSystemVariant, we don't need the custom hashing function and the second commit becomes a lot simpler?

Comment thread editoast/schemas/src/rolling_stock.rs Outdated
Also, on all the pathfinding API, we don’t need a full-fledge
`SupportedSignalingSystem`, but only the variant is enough (for
example, we don’t need the braking curves of ETCS). So we derive a
`SignalingSystemVariant` for those API, with the help of `strum`. It
will be used in a future commit.

Also provides hashing functions that will be used to hash
`HashSet<SupportedSignalingSystem>` (and the corresponding `*Variant`).
We create a bitmask of all the present variants, using the discriminant
of the variant’s enum. This should be unique, even if the order of the
iteration is different.

The function that hashes a `HashSet<SupportedSignalingSystemVariant>`
is not trivial, and is supposed to respect a few properties. `proptest`
is a library that basically do controlled fuzzing, which can help assert
those properties.

Signed-off-by: Jean SIMARD <woshilapin@tuziwo.info>
@woshilapin
woshilapin force-pushed the wsl/editoast-use-type-SupportedSignalingSystem-everywhere branch from cadd7e4 to 6feda36 Compare September 25, 2026 13:07
@woshilapin

Copy link
Copy Markdown
Contributor Author

Thank you! more typing is good, but i think this solution is overengineered

The reason I had the discriminant function extracted is for documentation purpose. A discriminant does mean something specific in the enum ecosystem. And the function was not exposed anyway, so it stayed an internal implementation detail. That said, I’m not going to die on that hill, since we already have a comment in the implementation of the hashing function, explaining what are those magic numbers. So I inlined it.

first commit message says:

The function that hashes a HashSet<SupportedSignalingSystemVariant>
is not trivial

but it is though? if you inline the discriminant functions you see it's just a 1-statement for loop and a call to hash. i don't think it calls for 4 tests with proptest... although i agree it's fun to play with, editoast isn't a playground for it

I disagree. The complexity does not lie in the implementation itself (indeed, it’s a few lines of code), the complexity lies in the fact that this implementation does respect the properties a Hash function must enforce. So I do believe having property testing makes sense here.

It looks like if we impl Ord for SupportedSignalingSystemVariant, we don't need the custom hashing function and the second commit becomes a lot simpler?

I’m not comfortable implementing Ord on a enum where it has no reasonable semantic meaning.

In some places, we were converting to `String` with no real added value.
Let’s keep `HashSet<SupportedSignalingSystem>` everywhere, avoiding
conversions.

One of the inconvenient is the implementation of `Hash` for some of
the `struct` that contains it (`HashSet` doesn’t implement `Hash`).
With the help of `educe`, we can plug a custom function to hash such a
`HashSet`.

Signed-off-by: Jean SIMARD <woshilapin@tuziwo.info>
@woshilapin
woshilapin force-pushed the wsl/editoast-use-type-SupportedSignalingSystem-everywhere branch from 6feda36 to 82fbefc Compare September 25, 2026 13:58
@woshilapin
woshilapin added this pull request to the merge queue Sep 25, 2026
Merged via the queue into dev with commit 41d5a56 Sep 25, 2026
40 checks passed
@woshilapin
woshilapin deleted the wsl/editoast-use-type-SupportedSignalingSystem-everywhere branch September 25, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:editoast Work on Editoast Service area:front Work on Standard OSRD Interface modules kind:api-change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants