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

Nondeterminism as an effect #3094

Closed
bblum opened this issue Aug 2, 2012 · 12 comments
Closed

Nondeterminism as an effect #3094

bblum opened this issue Aug 2, 2012 · 12 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-concurrency Area: Concurrency E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.

Comments

@bblum
Copy link
Contributor

bblum commented Aug 2, 2012

@eholk and I theorise that 'safe' Rust, for not having mutable shared state, currently has two methods for causing nondeterminism - select/fail (fail is basically isomorphic to select in terms of semantics, though implemented differently under the hood), and I/O.

It would be really, really slick if we could prove that one-to-one message-passing is deterministic, and then, pending an effect system, could label all relevant library functions with #[effect(nondeterminism)]. Enterprising users could then #[forbid] it, and be off to... well, NOT be off to the races.

@eholk
Copy link
Contributor

eholk commented Aug 2, 2012

Nondeterministic computations obviously introduce nondeterminism too, such as in if rand() % 2 == 0 { ch.send(5) }.

Also, recv_timeout, which is again isomorphic to select.

@bblum
Copy link
Contributor Author

bblum commented Aug 3, 2012

do we have a random number generator that uses global state? I didn't know we had one, but I'd consider that to be IO ;)

@eholk
Copy link
Contributor

eholk commented Aug 3, 2012

Oh, right. Yeah, just imagine that rand is implemented by opening /dev/random and reading from it.

@dckc
Copy link
Contributor

dckc commented Oct 19, 2012

Ah... interesting... I've sort of started to audit the library for sources of non-determinism (aka ambient authority). Ideally, libraries would have none; only programs would. If I can achieve this with [forbid...], then that's certainly a start. I'll have to look into it some more...

@thestinger
Copy link
Contributor

Hash tables have unique random keys for the hashing algorithm which determines the order of the key-value pairs. That's going to be a big barrier to implementing anything like this.

@dckc
Copy link
Contributor

dckc commented Mar 29, 2013

Ah. Right.

Back when I saw the hashtable DOS issue, I asked whether E is vulnerable and learned that its hash tables carry an array of the keys (in the order that they were added or something) in order to iterate over them deterministically.

I wonder how much of the rust community would consider this cost-effective.

@thestinger
Copy link
Contributor

They can't contain an array of the keys without using unsafe, so it's not just a performance issue.

I don't think it would be acceptable to increase the size of hash tables by ~50% for an array though since there are other map types available without that property (TreeMap, for example).

There will eventually be a linked hash table type that provides iteration in the order the keys were inserted, but regular hash tables will be much more widely used in the rest of the standard library.

@lkuper
Copy link
Contributor

lkuper commented May 20, 2013

One way to approach this would be to implement a Kahn process network on top of tasks/pipes and thereby get determinism. It would consist of some number of independent tasks, only communicating with each other over pipes. You'd want to launch all the tasks together at the start, and have all the pipes be open the whole time, so that a try_send couldn't fail due to a pipe being closed. try_recv is already blocking, which matches the semantics of KPNs. importantly, each task could only be waiting on one try_recv at a time. You'd have to leave out select, as @bblum pointed out.

@emberian
Copy link
Member

Visiting for triage; carry on.

@thestinger
Copy link
Contributor

Triage bump.

@flaper87
Copy link
Contributor

Triage bump

@thestinger
Copy link
Contributor

A proposal for an effects system and the specific effects would need to go through the RFC process. This issue isn't actionable because it would need to go through an RFC even if fully implemented.

bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
Replace `.unwrap_or` with `.map_or` in few places
RalfJung pushed a commit to RalfJung/rust that referenced this issue Sep 30, 2023
RalfJung pushed a commit to RalfJung/rust that referenced this issue Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-concurrency Area: Concurrency E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Projects
None yet
Development

No branches or pull requests

7 participants