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

[WIP] Make into schedule drop for the destination again #65385

Closed

Conversation

matthewjasper
Copy link
Contributor

#61430 triggered some degenerate behavior in llvm where it would inline functions far too aggressively.

This is marked as WIP because it doesn't really solve the problem in general. I've opened this PR more so that there's a place to discuss fixes.

Minimized example of the problem

Uncommenting the #[inline] will cause this to take a long time to compile on nightly, since llvm will inline all of the next calls into one enormous function that it spends a very long time handling.

pub trait Iterator {
    type Item;
    
    fn next(&mut self) -> Self::Item;
}

pub struct Empty;

impl Iterator for Empty {
    type Item = ();
    fn next(&mut self) {}
}

pub struct Chain<A, B=Empty> {
    a: A,
    b: B,
    state: ChainState,
}

#[allow(dead_code)]
enum ChainState {
    Both,
    Front,
    Back,
}

impl<A, B> Iterator for Chain<A, B> where
    A: Iterator,
    B: Iterator<Item = A::Item>
{
    type Item = A::Item;

    //#[inline]
    //^ uncomment me for degenerate llvm behvaiour with `-O`
    fn next(&mut self) -> A::Item {
        let ret;
        match self.state {
            ChainState::Both => {
                let _x = self.a.next();
                self.state = ChainState::Back;
                ret = self.b.next()
            },
            ChainState::Front => ret = self.a.next(),
            ChainState::Back => ret = self.b.next(),
        };
        ret
    }
}

type Chain2<T> = Chain<Chain<T>>;
type Chain4<T> = Chain2<Chain2<T>>;
type Chain8<T> = Chain4<Chain4<T>>;
type Chain16<T> = Chain8<Chain8<T>>;

pub fn call_next(x: &mut Chain16<Empty>) {
    x.next()
}

Closes #47949

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 13, 2019
@matthewjasper
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Oct 13, 2019

⌛ Trying commit ac5531a84c6549f74a7d1ba772cf2ffafca4a03f with merge 657db25f5495ead2ced9bac02891196b47dac8a3...

@Centril
Copy link
Contributor

Centril commented Oct 13, 2019

@bors retry try

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 13, 2019
@bors
Copy link
Contributor

bors commented Oct 13, 2019

⌛ Trying commit ac5531a84c6549f74a7d1ba772cf2ffafca4a03f with merge 9a46f242f60618bf42c2d0ae1d088307b9464ba1...

@bors
Copy link
Contributor

bors commented Oct 14, 2019

☀️ Try build successful - checks-azure
Build commit: 9a46f242f60618bf42c2d0ae1d088307b9464ba1 (9a46f242f60618bf42c2d0ae1d088307b9464ba1)

@rust-timer
Copy link
Collaborator

Queued 9a46f242f60618bf42c2d0ae1d088307b9464ba1 with parent c27f756, future comparison URL.

@@ -54,7 +54,6 @@ impl<A, B> Iterator for Chain<A, B> where
{
type Item = A::Item;

#[inline]
Copy link
Contributor

Choose a reason for hiding this comment

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

With lto (thin or fat), these attributes shouldn't really make much of a difference. Is the performance regression still there when these are present ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These attributes were the cause of the perf regression

Copy link
Contributor

@gnzlbg gnzlbg Oct 14, 2019

Choose a reason for hiding this comment

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

How is that possible? The PR that introduced the regression did not add these attributes, so they must have already been there, right ? Without that PR, these attributes were not introducing that regression, so something else in that PR caused it.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 9a46f242f60618bf42c2d0ae1d088307b9464ba1, comparison URL.

@mati865
Copy link
Contributor

mati865 commented Oct 14, 2019

Still regresses badly, especially deeply-nested-opt.

@matthewjasper matthewjasper added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 19, 2019
@JohnCSimon
Copy link
Member

Ping from triage -
@mati865 Can you please post the status of this PR? Also you have some merge conflicts.
cc: @eddyb @gnzlbg

Thanks!

@mati865
Copy link
Contributor

mati865 commented Oct 26, 2019

You probably mean to ask @matthewjasper

@JohnCSimon
Copy link
Member

Ping from triage -
@matthewjasper Can you please post the status of this PR? Also you have some merge conflicts.
cc: @eddyb @gnzlbg

Thanks!

@matthewjasper matthewjasper force-pushed the drop-on-into-panic-otp branch from ac5531a to 98c3371 Compare November 2, 2019 10:34
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-02T10:36:23.2144980Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-02T10:36:23.2344152Z ##[command]git config gc.auto 0
2019-11-02T10:36:23.2417877Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-02T10:36:23.2473935Z ##[command]git config --get-all http.proxy
2019-11-02T10:36:23.2622235Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/65385/merge:refs/remotes/pull/65385/merge
---
2019-11-02T10:42:03.1811906Z    Compiling serde_json v1.0.40
2019-11-02T10:42:04.6769286Z    Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
2019-11-02T10:42:14.4485428Z     Finished release [optimized] target(s) in 1m 15s
2019-11-02T10:42:14.4558727Z tidy check
2019-11-02T10:42:14.8431677Z tidy error: /checkout/src/librustc_mir/dataflow/move_paths/builder.rs:359: TODO is deprecated; use FIXME
2019-11-02T10:42:16.4383434Z some tidy checks failed
2019-11-02T10:42:16.4387518Z Found 485 error codes
2019-11-02T10:42:16.4387619Z Found 0 error codes with no tests
2019-11-02T10:42:16.4388749Z Done!
2019-11-02T10:42:16.4388749Z Done!
2019-11-02T10:42:16.4388807Z 
2019-11-02T10:42:16.4388834Z 
2019-11-02T10:42:16.4389736Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2019-11-02T10:42:16.4389866Z 
2019-11-02T10:42:16.4389911Z 
2019-11-02T10:42:16.4399907Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-11-02T10:42:16.4400001Z Build completed unsuccessfully in 0:01:18
2019-11-02T10:42:16.4400001Z Build completed unsuccessfully in 0:01:18
2019-11-02T10:42:16.4450592Z == clock drift check ==
2019-11-02T10:42:16.4457950Z   local time: Sat Nov  2 10:42:16 UTC 2019
2019-11-02T10:42:16.5813137Z   network time: Sat, 02 Nov 2019 10:42:16 GMT
2019-11-02T10:42:16.5818945Z == end clock drift check ==
2019-11-02T10:42:17.9651889Z 
2019-11-02T10:42:17.9770797Z ##[error]Bash exited with code '1'.
2019-11-02T10:42:17.9795221Z ##[section]Starting: Checkout
2019-11-02T10:42:17.9796977Z ==============================================================================
2019-11-02T10:42:17.9797056Z Task         : Get sources
2019-11-02T10:42:17.9797099Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@matthewjasper matthewjasper force-pushed the drop-on-into-panic-otp branch from 98c3371 to 7d7dc00 Compare November 2, 2019 12:16
@matthewjasper
Copy link
Contributor Author

Trying one more time before I close this and work on a different approach
@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Nov 2, 2019

⌛ Trying commit 7d7dc00 with merge 8712d90...

bors added a commit that referenced this pull request Nov 2, 2019
[WIP] Make `into` schedule drop for the destination again

#61430 triggered some degenerate behavior in llvm where it would inline functions far too aggressively.

This is marked as WIP because it doesn't really solve the problem in general. I've opened this PR more so that there's a place to discuss fixes.

<details>

<summary>Minimized example of the problem</summary>

Uncommenting the `#[inline]` will cause this to take a long time to compile on nightly, since llvm will inline all of the next calls into one enormous function that it spends a very long time handling.

```rust
pub trait Iterator {
    type Item;

    fn next(&mut self) -> Self::Item;
}

pub struct Empty;

impl Iterator for Empty {
    type Item = ();
    fn next(&mut self) {}
}

pub struct Chain<A, B=Empty> {
    a: A,
    b: B,
    state: ChainState,
}

#[allow(dead_code)]
enum ChainState {
    Both,
    Front,
    Back,
}

impl<A, B> Iterator for Chain<A, B> where
    A: Iterator,
    B: Iterator<Item = A::Item>
{
    type Item = A::Item;

    //#[inline]
    //^ uncomment me for degenerate llvm behvaiour with `-O`
    fn next(&mut self) -> A::Item {
        let ret;
        match self.state {
            ChainState::Both => {
                let _x = self.a.next();
                self.state = ChainState::Back;
                ret = self.b.next()
            },
            ChainState::Front => ret = self.a.next(),
            ChainState::Back => ret = self.b.next(),
        };
        ret
    }
}

type Chain2<T> = Chain<Chain<T>>;
type Chain4<T> = Chain2<Chain2<T>>;
type Chain8<T> = Chain4<Chain4<T>>;
type Chain16<T> = Chain8<Chain8<T>>;

pub fn call_next(x: &mut Chain16<Empty>) {
    x.next()
}
```

</details>

Closes #47949
@bors
Copy link
Contributor

bors commented Nov 2, 2019

☀️ Try build successful - checks-azure
Build commit: 8712d90 (8712d9047a7c1d95447f71ae89b1596bb953d798)

@rust-timer
Copy link
Collaborator

Queued 8712d90 with parent f39205b, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 8712d90, comparison URL.

@matthewjasper matthewjasper deleted the drop-on-into-panic-otp branch November 3, 2019 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panics in destructors can cause the return value to be leaked
9 participants