Skip to content

Gotta land some of this stuff... #539

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 4 commits into from
Feb 23, 2017

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Feb 22, 2017

My patch queue is getting quite large, as I refactor templates in bindgen, so I figure I should land the stuff that is in good shape sooner rather than later :-P

This stuff tweaks the named template parameter analysis, adds some edge kinds, stuff like that. This is still not used by codegen, yet. I have another branch where I de-dupe named types and all of that, and there is only two tests failing now, but still some clean up needed.

This also contains the expanded documentation for te named template parameter analysis that I promised.

See each commit message for details.

r? @emilio

The all_template_parameters method gets the complete set of template parameters
that can affect a given item.

Note that this item doesn't need to be a template declaration itself for `Some`
to be returned from this method (in contrast to `self_template_params`). If this
item is a member of a template declaration, then the parent's template
parameters are included here. See the example in TemplateDeclaration's doc
comment for details.
Rather than determining whether any given template parameter is used at all
globally, determine the set of template parameters used by any given IR node.
// Rc<RefCell<ItemSet>> to make the borrow checker happy, but it
// isn't clear that the added indirection wouldn't outweigh the cost
// of malloc'ing a new ItemSet here. Ideally, `HashMap` would have a
// `split_entries` method analogous to `slice::split_at_mut`...
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 am fixing this unnecessary malloc thrashing in a follow up, before we turn this analysis on by default.

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Looks fine, I only have minor comments. r=me :)

if each_self_params.is_empty() {
None
} else {
Some(each_self_params.into_iter()
Copy link
Contributor

Choose a reason for hiding this comment

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

huh, almost magical.

/// |Decl. | self_template_params | num_self_template_params | all_template_parameters|
/// +------+----------------------+--------------------------+------------------------+
/// |Foo | Some([T, U]) | Some(2) | Some([T, U]) |
/// |Bar | Some([V]) | Some(1) | Some([T, U, V]) |
Copy link
Contributor

Choose a reason for hiding this comment

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

This made me think... Do we handle shadowing? (Not that is a blocker, nor that we do now, but if we did that'd be awesome :P)

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'll make a note to add a test.

for (arg, param) in args.iter().zip(params.iter()) {
if self.used[&decl].contains(param) {
if self.ctx.resolve_item(*arg).is_named() {
self.used.get_mut(&id).unwrap().insert(*arg);
Copy link
Contributor

Choose a reason for hiding this comment

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

i believe you should be able to use the self.used[&id].insert(*arg) syntax here too?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was originally like that, but for some reason type inference was inferring an immutable indexing operation, rather than a mutable one.

/me shrugs

let new_size = self.used.len();
new_size != original_size
let new_len = self.used[&id].len();
assert!(new_len >= original_len);
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I'd be really scared if this didn't hold, but better safe than sorry.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, just a sanity check, more for future modifications than for the code as it is now.

//!
//! A monotone function `f` is a function where if `x <= y`, then it holds that
//! `f(x) <= f(y)`. It should be clear that running a monotone function to a
//! fix-point on a finite lattice will always terminate: `f` can only "move"
Copy link
Contributor

Choose a reason for hiding this comment

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

+1000 for the comment/code ratio, this is awesome :)

Copy link
Member Author

Choose a reason for hiding this comment

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

:)

@fitzgen
Copy link
Member Author

fitzgen commented Feb 23, 2017

@bors-servo r=emilio

@bors-servo
Copy link

📌 Commit 7e22fca has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit 7e22fca with merge 051b16a...

bors-servo pushed a commit that referenced this pull request Feb 23, 2017
Gotta land some of this stuff...

My patch queue is getting quite large, as I refactor templates in bindgen, so I figure I should land the stuff that is in good shape sooner rather than later :-P

This stuff tweaks the named template parameter analysis, adds some edge kinds, stuff like that. This is still not used by codegen, yet. I have another branch where I de-dupe named types and all of that, and there is only two tests failing now, but still some clean up needed.

This also contains the expanded documentation for te named template parameter analysis that I promised.

See each commit message for details.

r? @emilio
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: emilio
Pushing 051b16a to master...

@bors-servo bors-servo merged commit 7e22fca into rust-lang:master Feb 23, 2017
@fitzgen fitzgen deleted the gotta-land-some-of-this-stuff branch February 23, 2017 18:04
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.

4 participants