diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index 1c1bdee8747..7876b1cfc59 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -306,32 +306,15 @@ fn crate_link_metas(&ast::crate c) -> link_metas { // This calculates CMH as defined above fn crate_meta_extras_hash(sha1 sha, &ast::crate crate) -> str { - // FIXME (#487) Move this sorting stuff into middle::attr - fn lteq(&@ast::meta_item ma, &@ast::meta_item mb) -> bool { - fn key(&@ast::meta_item m) -> ast::ident { - alt (m.node) { - case (ast::meta_word(?name)) { - name - } - case (ast::meta_name_value(?name, _)) { - name - } - case (ast::meta_list(?name, _)) { - name - } - } - } - ret key(ma) <= key(mb); - } fn len_and_str(&str s) -> str { ret #fmt("%u_%s", str::byte_len(s), s); } + + auto cmh_items = { + auto cmh_items = crate_link_metas(crate).cmh_items; + attr::sort_meta_items(cmh_items) + }; - let vec[mutable @ast::meta_item] v = [mutable ]; - for (@ast::meta_item mi in crate_link_metas(crate).cmh_items) { - v += [mutable mi]; - } - sort::quick_sort(lteq, v); sha.reset(); - for (@ast::meta_item m_ in v) { + for (@ast::meta_item m_ in cmh_items) { auto m = m_; alt (m.node) { case (ast::meta_name_value(?key, ?value)) { diff --git a/src/comp/middle/attr.rs b/src/comp/middle/attr.rs index 119b81ba82d..33914cb9b86 100644 --- a/src/comp/middle/attr.rs +++ b/src/comp/middle/attr.rs @@ -8,6 +8,7 @@ export find_linkage_metas; export find_attrs_by_name; export contains; +export sort_meta_items; // From a list of crate attributes get only the meta_items that impact crate // linkage @@ -103,6 +104,39 @@ fn contains(&vec[@ast::meta_item] haystack, @ast::meta_item needle) -> bool { ret false; } +fn sort_meta_items(&vec[@ast::meta_item] items) -> vec[@ast::meta_item] { + fn lteq(&@ast::meta_item ma, &@ast::meta_item mb) -> bool { + fn key(&@ast::meta_item m) -> ast::ident { + alt (m.node) { + case (ast::meta_word(?name)) { + name + } + case (ast::meta_name_value(?name, _)) { + name + } + case (ast::meta_list(?name, _)) { + name + } + } + } + ret key(ma) <= key(mb); + } + + // This is sort of stupid here, converting to a vec of mutables and back + let vec[mutable @ast::meta_item] v = [mutable ]; + for (@ast::meta_item mi in items) { + v += [mutable mi]; + } + + std::sort::quick_sort(lteq, v); + + let vec[@ast::meta_item] v2 = []; + for (@ast::meta_item mi in v) { + v2 += [mi] + } + ret v2; +} + // // Local Variables: // mode: rust