Skip to content

Implement recursive sorting of meta items and hashing of list meta items #4978

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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