Skip to content

Add a memoized function and use it throughout rustc #17983

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 2 commits into from Oct 15, 2014
Merged

Add a memoized function and use it throughout rustc #17983

merged 2 commits into from Oct 15, 2014

Conversation

ghost
Copy link

@ghost ghost commented Oct 12, 2014

No description provided.

@ghost
Copy link
Author

ghost commented Oct 12, 2014

I'm not super sold on the current syntax and would much prefer for this to be an attribute but that is not possible at the moment.

fn $name:ident(
$($param_name:ident: $param_ty:ty),*
) -> $output_ty:ty $block:block,
$cache_map:expr,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe these could be moved to be first, so that they're close to the function declaration (as it stands, one has to navigate around a possibly-long function body to find them, made harder by formatting it without indentation).

Copy link
Author

Choose a reason for hiding this comment

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

@huonw Good idea, thanks!

@ghost
Copy link
Author

ghost commented Oct 13, 2014

@huonw @pcwalton I changed it to be a function instead. r?

@ghost ghost changed the title Add a memoize! macro and use it throughout rustc Add a memoized function and use it throughout rustc Oct 13, 2014
@ghost ghost changed the title Add a memoized function and use it throughout rustc Add a memoized function and use it throughout rustc Oct 13, 2014
pub fn memoized<T: Clone, U: Clone, M: MutableMap<T, U>>(
cache: &RefCell<M>,
f: &|&: T| -> U,
arg: T
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better for this argument to be before the closure, to improve readability.

@ghost
Copy link
Author

ghost commented Oct 14, 2014

@huonw Comments addressed.

@bors bors closed this Oct 15, 2014
@bors bors merged commit dbc4a4b into rust-lang:master Oct 15, 2014
@ghost ghost deleted the memoize-things branch October 16, 2014 22:27
lnicola pushed a commit to lnicola/rust that referenced this pull request Aug 29, 2024
…s, r=Veykril

Consider field attributes when converting from tuple to named struct and the opposite

Fixes rust-lang#17983.

I tried to use the `SourceChangeBuilder::make_mut()` API, but it duplicated the attribute...
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.

2 participants