Skip to content

Cannot move upvars through multiple closures #2338

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

Closed
brson opened this issue May 3, 2012 · 4 comments
Closed

Cannot move upvars through multiple closures #2338

brson opened this issue May 3, 2012 · 4 comments
Labels
A-type-system Area: Type system
Milestone

Comments

@brson
Copy link
Contributor

brson commented May 3, 2012

    let q = ~10;
    let addr = ptr::addr_of(*q);
    let f = fn@() -> *int {
        fn@() -> *int {
            ptr::addr_of(*q)
        }()
    };
    assert addr == f();

This fails because q ends up being a copy. Even adding capture clauses to both functions does not work because q cannot be moved out of the first closure.

This results in some subtle behavior with functional control structures, particularly since the copy happens implicitly. For example, in my rewrite of core::comm I have a requirement that a particular variable not be copied. This has to carefully be verified through tests to prevent the compiler from inserting copies and prevents me from using nice-looking functional code.

I don't know how to fix this. Probably the easiest thing is to disallow this pattern by requiring the copies to be explicit.

@brson
Copy link
Contributor Author

brson commented May 3, 2012

Of course, requiring an explicit copy capture clause makes using higher-order functions for flow control a lot less appealing.

@pnkfelix
Copy link
Member

I'm having trouble reproducing this bug. (There have been a number syntactic changes to the language since it was filed.)

@pnkfelix
Copy link
Member

In particular, the interface to addr_of has changed so that it now takes a &T instead of a T. I tried porting the example by replacing the addr_of(*q) with addr_of(q), but I do not see the assertion fail. So I am not sure

  1. if this problem has been resolved by some other means in the meantime, or
  2. if I am misunderstanding the scenario that is being tested above, or
  3. if the change to the addr_of API somehow defines away the problem being considered in the above scenario.

@nikomatsakis
Copy link
Contributor

If there was ever a bug here (which is unclear to me), I think that this no longer applies due to the moves-based-on-type rules. I'm closing. @brson let me know if you disagree.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
This commit adds an implementation for the `benchcomp visualize`
command. Currently, there is one visualization, "error_on_regression",
which causes `benchcomp` or `benchcomp visualize` to terminate with a
return code of 1 if there was a regression in any of the metrics.

Users can specify the following in their config file:

    visualize:
    - type: error_on_regression
      variant_pairs:
      - [variant_1, variant_2]
      - [variant_1, variant_3]
      checks:
      - metric: runtime
        test: "lambda old, new: new / old > 1.1"
      - metric: passed
        test: "lambda old, new: False if not old else not new"

This says to check whether any benchmark regressed when run under
variant_2 compared to variant_1. A benchmark is considered to have
regressed if the value of the 'runtime' metric under variant_2 is 10%
higher than the value under variant_1. Furthermore, the benchmark is
also considered to have regressed if it was previously passing, but is
now failing. These same checks are performed on all benchmarks run under
variant_3 compared to variant_1. If any of those lambda functions
returns True, then benchcomp will terminate with a return code of 1.

This commit fixes rust-lang#2338.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

3 participants