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

reimplement purity check in a more principled way #3490

Closed
nikomatsakis opened this issue Sep 13, 2012 · 1 comment
Closed

reimplement purity check in a more principled way #3490

nikomatsakis opened this issue Sep 13, 2012 · 1 comment
Labels
A-lifetimes Area: Lifetimes / regions A-type-system Area: Type system C-cleanup Category: PRs that clean code up or issues documenting cleanup.

Comments

@nikomatsakis
Copy link
Contributor

Purity checking is currently done via some rather ad-hoc rules in borrowck. The actual effect system that's being enforced is a BIT subtle. I would prefer to implement a separate purityck later that is modeling the underlying effect system more directly. This would not only be less complex in the implementation, it would give me more confidence we are enforcing the rules we want to enforce.

Here is an example of some code which may or may not be safe:

use std;

fn main()
{
    let a = ~[1, 4, 3, 5, 2];
    let mut compare_count = 0;

    std::sort::quick_sort(|x, y| { compare_count += 1; *x < *y }, a);

    error!("%d comparisons", compare_count);
    error!("%?", a);
}

To answer whether it's safe requires me to (1) reconstruct the mental model of purity I had in mind; (2) check whether this conforms. I'm deferring step (1) for the moment until I get back to this bug.

Here are some further notes I wrote down at some point regarding how our rules map to an underlyling effect system.

@thestinger
Copy link
Contributor

Closing, since pure is removed from the language.

RalfJung pushed a commit to RalfJung/rust that referenced this issue Apr 20, 2024
share code between win-to-unix and unix-to-win path conversion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-type-system Area: Type system C-cleanup Category: PRs that clean code up or issues documenting cleanup.
Projects
None yet
Development

No branches or pull requests

2 participants