Skip to content

Simplify iterator logic for Fuse #24233

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

Merged
merged 1 commit into from
Apr 12, 2015
Merged

Conversation

frewsxcv
Copy link
Member

@frewsxcv frewsxcv commented Apr 9, 2015

No description provided.

@rust-highfive
Copy link
Contributor

r? @brson

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

@bluss
Copy link
Member

bluss commented Apr 10, 2015

It doesn't simplify, it just writes the same thing in a shorter way. Does it matter that we use an extra closure here that the optimizier needs to re-inline? Because of the likely code size increase (in code given to llvm), I think this is a net negative unfortunately. Sorry to be negative about your minor fix, I'm just trying to weigh the change's merits.

@frewsxcv
Copy link
Member Author

It doesn't simplify, it just writes the same thing in a shorter way.

I think it is cleaner and more idiomatic. I am utilizing Option::or_else in the way it was intended to be used.

Because of the likely code size increase

Compare the LLVM IR for these two examples:

They're identical as far as I know, and one of them uses a closure, so I'm not convinced code will increase.

@lambda-fairy
Copy link
Contributor

As scott mentioned on IRC, a better rewrite would be:

let x = self.iter.next();
if x.is_none() {
    self.done = true;
}
x

as that makes the intention clear.

@frewsxcv frewsxcv force-pushed the cleanup-fuse-iterator branch from bebd57d to b4cbeda Compare April 12, 2015 02:48
@frewsxcv
Copy link
Member Author

@lfairy Good idea, just force pushed with that change

None
}
x => x
let next = self.iter.next();
Copy link
Contributor

Choose a reason for hiding this comment

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

Uhhhh next_back...?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, fixed

@frewsxcv frewsxcv force-pushed the cleanup-fuse-iterator branch from b4cbeda to a5c8e41 Compare April 12, 2015 05:05
x => x
let next = self.iter.next_back();
if next.is_none() {
self.done = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, what about just self.done = next.is_none()? No branch at all, but unconditional mutation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think writing self.done = true makes explicit the transition from false -> true.

But I'm not too attached to the idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was about to say the same thing as @lfairy , but I too don't feel too strongly about it, especially considering how small of a change this commit is

Copy link
Contributor

Choose a reason for hiding this comment

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

Anytime I see a done variable I instantly go to "this is a one-transition boolean", personally.

Copy link
Member Author

Choose a reason for hiding this comment

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

Force pushed with that change

@frewsxcv frewsxcv force-pushed the cleanup-fuse-iterator branch from a5c8e41 to 5c80b7a Compare April 12, 2015 05:40
@Gankra
Copy link
Contributor

Gankra commented Apr 12, 2015

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 12, 2015

📌 Commit 5c80b7a has been approved by Gankro

@bluss
Copy link
Member

bluss commented Apr 12, 2015

If the IR is identical, it's because it's after optimization, I was thinking of the size of llvm's input from rustc from the beginning. Now with the closure gone, the point is moot and that's well.

@cristicbz
Copy link
Contributor

I think this change breaks the fuse() impl. Before done would only be set to true if next() returned None. Now it would be set to false again if it isn't.

You want the rewrite @lfairy posted with the self.done inside the if.

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 12, 2015
@frewsxcv
Copy link
Member Author

Now it would be set to false again if it isn't.

@cristicbz Can you give me an example where it would be set to false again?

@cristicbz
Copy link
Contributor

Never mind, sorry, I didn't read it properly---I missed the big if self.done.

bors added a commit that referenced this pull request Apr 12, 2015
@bors
Copy link
Collaborator

bors commented Apr 12, 2015

⌛ Testing commit 5c80b7a with merge c3f77c7...

@bors
Copy link
Collaborator

bors commented Apr 12, 2015

⛄ The build was interrupted to prioritize another pull request.

bors added a commit that referenced this pull request Apr 12, 2015
@bors bors merged commit 5c80b7a into rust-lang:master Apr 12, 2015
@frewsxcv frewsxcv deleted the cleanup-fuse-iterator branch June 1, 2015 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants