Skip to content

Commit

Permalink
syntax: Implement recursive sorting of meta items. Closes #607
Browse files Browse the repository at this point in the history
  • Loading branch information
z0w0 committed Feb 16, 2013
1 parent 9ad8a1f commit fe9f1d1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
16 changes: 11 additions & 5 deletions src/librustc/back/link.rs
Expand Up @@ -497,8 +497,7 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,

let cmh_items = attr::sort_meta_items(cmh_items);

symbol_hasher.reset();
for cmh_items.each |m| {
fn hash(symbol_hasher: &hash::State, m: &@ast::meta_item) {
match m.node {
ast::meta_name_value(ref key, value) => {
symbol_hasher.write_str(len_and_str((*key)));
Expand All @@ -507,13 +506,20 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
ast::meta_word(ref name) => {
symbol_hasher.write_str(len_and_str((*name)));
}
ast::meta_list(_, _) => {
// FIXME (#607): Implement this
fail!(~"unimplemented meta_item variant");
ast::meta_list(ref name, ref mis) => {
symbol_hasher.write_str(len_and_str((*name)));
for mis.each |m_| {
hash(symbol_hasher, m_);
}
}
}
}

symbol_hasher.reset();
for cmh_items.each |m| {
hash(symbol_hasher, m);
}

for dep_hashes.each |dh| {
symbol_hasher.write_str(len_and_str(*dh));
}
Expand Down
30 changes: 20 additions & 10 deletions src/libsyntax/attr.rs
Expand Up @@ -192,13 +192,15 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
}
_ => false
},
ast::meta_list(*) => {

// ~[Fixme-sorting]
// FIXME (#607): Needs implementing
// This involves probably sorting the list by name and
// meta_item variant
fail!(~"unimplemented meta_item variant")
ast::meta_list(ref na, misa) => match b.node {
ast::meta_list(ref nb, misb) => {
if na != nb { return false; }
for misa.each |&mi| {
if !contains(misb, mi) { return false; }
}
true
}
_ => false
}
}
}
Expand Down Expand Up @@ -253,8 +255,6 @@ pub fn last_meta_item_list_by_name(items: ~[@ast::meta_item], name: ~str)

/* Higher-level applications */

// FIXME (#607): This needs to sort by meta_item variant in addition to
// the item name (See [Fixme-sorting])
pub fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
pure fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool {
pure fn key(m: &ast::meta_item) -> ~str {
Expand All @@ -270,7 +270,17 @@ pub fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
// This is sort of stupid here, converting to a vec of mutables and back
let mut v: ~[@ast::meta_item] = items;
std::sort::quick_sort(v, lteq);
v

// There doesn't seem to be a more optimal way to do this
do v.map |&m| {
match m.node {
ast::meta_list(n, mis) => @spanned {
node: ast::meta_list(n, sort_meta_items(mis)),
.. *m
},
_ => m
}
}
}

pub fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ~str) ->
Expand Down

6 comments on commit fe9f1d1

@graydon
Copy link
Contributor

Choose a reason for hiding this comment

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

r+

@bors
Copy link
Contributor

@bors bors commented on fe9f1d1 Feb 17, 2013

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on fe9f1d1 Feb 17, 2013

Choose a reason for hiding this comment

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

merging z0w0/rust/issue-607 = fe9f1d1 into auto

@bors
Copy link
Contributor

@bors bors commented on fe9f1d1 Feb 17, 2013

Choose a reason for hiding this comment

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

z0w0/rust/issue-607 = fe9f1d1 merged ok, testing candidate = 9ea05a4

@bors
Copy link
Contributor

@bors bors commented on fe9f1d1 Feb 17, 2013

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on fe9f1d1 Feb 17, 2013

Choose a reason for hiding this comment

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

fast-forwarding incoming to auto = 9ea05a4

Please sign in to comment.