GithubHelp home page GithubHelp logo

Comments (5)

tkaitchuck avatar tkaitchuck commented on June 12, 2024 1

In other words, the feature compile-time-rng means the lack of randomness.

It does not. You misunderstand the design. The flag merely indicates the source of the seed for the generator of the random keys used in the maps. If your map is created by HashMap::default() it will always (regardless of flags) have a unique set of keys. So even if there were no other flags anywhere on your path, each hashmap would have a unique set of keys.

You can alter this behavior, but not using flags. See the documentation here:
https://docs.rs/ahash/0.8.1/ahash/random_state/struct.RandomState.html
and here:
https://docs.rs/ahash/0.8.1/ahash/random_state/trait.RandomSource.html

from ahash.

schungx avatar schungx commented on June 12, 2024

I have recently been hit by this.

I have specified default-features = false and compile-time-rng for ahash, only to find that it didn't work. After a lot of trouble-shooting, I discovered that another dependency crate has ahash deep down its dependency tree (I used cargo tree to find it), and that ahash has default. Which means the default features get merged into my ahash.

There is no easy solution to this. Even renaming the crate to, say, ahash2 doesn't prevent this merging of features. It must be separated into different source repo's in order to bypass this.

from ahash.

tkaitchuck avatar tkaitchuck commented on June 12, 2024

I am not sure how this can be observed externally, or in what sense it violates policies.

To clarify the difference between either of the flags being set or neither is just where the fixed random seeds come from. If runtime-rng is on they are statically initialized to values from getrandom. If compile-time-rng is enabled they are from constants embedded at compile time. If neither are enabled, fixed constants are used. There are two apis which are enabled if either compile-time-rng or runtime-rng are enabled. So if runtime-rng is turned on by another package, there is no change to the API surface.

Depending on which flag is set it will either use getrandom or a random constant for the fixed seeds. But that is an internal implementation detail that can't be observed in any way. (How could you tell the difference between two sources of random numbers?)

This could be noticed because getrandom is downloaded a dependency. But that would happen no matter what if there is another package depending on the runtime-rng feature.

So, @schungx I am not sure what you mean by "only to find that it didn't work". What didn't work?

In theory if both flags are enabled I could have the compile-time-rng generated fixed constants in the code, but then at runtime immediately replace them with values from getrandom. But what would be the point? It would just embed random constants into the binary that are never used.

from ahash.

schungx avatar schungx commented on June 12, 2024

So, @schungx I am not sure what you mean by "only to find that it didn't work". What didn't work?

What I mean is that the features are not strictly additive. As one overrides the other. That's not additive.

In other words, the feature compile-time-rng means the lack of randomness. Remember the lack of functionality is by itself a functionality, if that lack is depended upon. You cannot merge a "minus", so that makes it non-additive.

I have seen a crate being very careful to only specify compile-time-rng because it needs one and won't work without a random generator. Yes, this is a niche use case.

However, some dependency down the tree also uses ahash with default, which is runtime-rng. This overrides the other feature when cargo merges them.

So that crate no longer works properly and this is very hard to debug. In fact, many non-additive cargo feature issues are hard to debug .

from ahash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.