Rollup merge of #66889 - dtolnay:fmt6, r=rkruppe
Make python-generated source files compatible with rustfmt This PR adjusts the generators for src/libcore/num/dec2flt/table.rs, src/libcore/unicode/printable.rs, and src/libcore/unicode/tables.rs to make it so running `rustfmt` on the generated files no longer needs to apply any changes. This involves tweaking the python scripts where reasonable to better match rustfmt's style, and adding `#[rustfmt::skip]` to big constant tables that there's no point having rustfmt rewrap. r? @Dylan-DPC
This commit is contained in:
commit
2e83c6d114
15
src/etc/dec2flt_table.py
Normal file → Executable file
15
src/etc/dec2flt_table.py
Normal file → Executable file
@ -111,14 +111,18 @@ def print_proper_powers():
|
||||
print("pub const MIN_E: i16 = {};".format(MIN_E))
|
||||
print("pub const MAX_E: i16 = {};".format(MAX_E))
|
||||
print()
|
||||
print("#[rustfmt::skip]")
|
||||
typ = "([u64; {0}], [i16; {0}])".format(len(powers))
|
||||
print("pub const POWERS: ", typ, " = ([", sep='')
|
||||
print("pub const POWERS: ", typ, " = (", sep='')
|
||||
print(" [")
|
||||
for z in powers:
|
||||
print(" 0x{:x},".format(z.sig))
|
||||
print("], [")
|
||||
print(" 0x{:x},".format(z.sig))
|
||||
print(" ],")
|
||||
print(" [")
|
||||
for z in powers:
|
||||
print(" {},".format(z.exp))
|
||||
print("]);")
|
||||
print(" {},".format(z.exp))
|
||||
print(" ],")
|
||||
print(");")
|
||||
|
||||
|
||||
def print_short_powers(num_bits, significand_size):
|
||||
@ -127,6 +131,7 @@ def print_short_powers(num_bits, significand_size):
|
||||
max_e = int(ceil(log(max_sig, 5)))
|
||||
e_range = range(max_e)
|
||||
typ = "[f{}; {}]".format(num_bits, len(e_range))
|
||||
print("#[rustfmt::skip]")
|
||||
print("pub const F", num_bits, "_SHORT_POWERS: ", typ, " = [", sep='')
|
||||
for e in e_range:
|
||||
print(" 1e{},".format(e))
|
||||
|
File diff suppressed because it is too large
Load Diff
6
src/libcore/unicode/printable.py
Normal file → Executable file
6
src/libcore/unicode/printable.py
Normal file → Executable file
@ -111,16 +111,19 @@ def compress_normal(normal):
|
||||
return compressed
|
||||
|
||||
def print_singletons(uppers, lowers, uppersname, lowersname):
|
||||
print("#[rustfmt::skip]")
|
||||
print("const {}: &[(u8, u8)] = &[".format(uppersname))
|
||||
for u, c in uppers:
|
||||
print(" ({:#04x}, {}),".format(u, c))
|
||||
print("];")
|
||||
print("#[rustfmt::skip]")
|
||||
print("const {}: &[u8] = &[".format(lowersname))
|
||||
for i in range(0, len(lowers), 8):
|
||||
print(" {}".format(" ".join("{:#04x},".format(l) for l in lowers[i:i+8])))
|
||||
print("];")
|
||||
|
||||
def print_normal(normal, normalname):
|
||||
print("#[rustfmt::skip]")
|
||||
print("const {}: &[u8] = &[".format(normalname))
|
||||
for v in normal:
|
||||
print(" {}".format(" ".join("{:#04x},".format(i) for i in v)))
|
||||
@ -170,8 +173,7 @@ def main():
|
||||
// NOTE: The following code was generated by "src/libcore/unicode/printable.py",
|
||||
// do not edit directly!
|
||||
|
||||
fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8],
|
||||
normal: &[u8]) -> bool {
|
||||
fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], normal: &[u8]) -> bool {
|
||||
let xupper = (x >> 8) as u8;
|
||||
let mut lowerstart = 0;
|
||||
for &(upper, lowercount) in singletonuppers {
|
||||
|
@ -1,8 +1,7 @@
|
||||
// NOTE: The following code was generated by "src/libcore/unicode/printable.py",
|
||||
// do not edit directly!
|
||||
|
||||
fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8],
|
||||
normal: &[u8]) -> bool {
|
||||
fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], normal: &[u8]) -> bool {
|
||||
let xupper = (x >> 8) as u8;
|
||||
let mut lowerstart = 0;
|
||||
for &(upper, lowercount) in singletonuppers {
|
||||
@ -70,6 +69,7 @@ pub(crate) fn is_printable(x: char) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
const SINGLETONS0U: &[(u8, u8)] = &[
|
||||
(0x00, 1),
|
||||
(0x03, 5),
|
||||
@ -113,6 +113,7 @@ const SINGLETONS0U: &[(u8, u8)] = &[
|
||||
(0xfe, 3),
|
||||
(0xff, 9),
|
||||
];
|
||||
#[rustfmt::skip]
|
||||
const SINGLETONS0L: &[u8] = &[
|
||||
0xad, 0x78, 0x79, 0x8b, 0x8d, 0xa2, 0x30, 0x57,
|
||||
0x58, 0x8b, 0x8c, 0x90, 0x1c, 0x1d, 0xdd, 0x0e,
|
||||
@ -152,6 +153,7 @@ const SINGLETONS0L: &[u8] = &[
|
||||
0xff, 0x53, 0x67, 0x75, 0xc8, 0xc9, 0xd0, 0xd1,
|
||||
0xd8, 0xd9, 0xe7, 0xfe, 0xff,
|
||||
];
|
||||
#[rustfmt::skip]
|
||||
const SINGLETONS1U: &[(u8, u8)] = &[
|
||||
(0x00, 6),
|
||||
(0x01, 1),
|
||||
@ -189,6 +191,7 @@ const SINGLETONS1U: &[(u8, u8)] = &[
|
||||
(0xf9, 6),
|
||||
(0xfa, 2),
|
||||
];
|
||||
#[rustfmt::skip]
|
||||
const SINGLETONS1L: &[u8] = &[
|
||||
0x0c, 0x27, 0x3b, 0x3e, 0x4e, 0x4f, 0x8f, 0x9e,
|
||||
0x9e, 0x9f, 0x06, 0x07, 0x09, 0x36, 0x3d, 0x3e,
|
||||
@ -212,6 +215,7 @@ const SINGLETONS1L: &[u8] = &[
|
||||
0xa4, 0xaa, 0xaf, 0xb0, 0xc0, 0xd0, 0x0c, 0x72,
|
||||
0xa3, 0xa4, 0xcb, 0xcc, 0x6e, 0x6f,
|
||||
];
|
||||
#[rustfmt::skip]
|
||||
const NORMAL0: &[u8] = &[
|
||||
0x00, 0x20,
|
||||
0x5f, 0x22,
|
||||
@ -355,6 +359,7 @@ const NORMAL0: &[u8] = &[
|
||||
0x1b, 0x03,
|
||||
0x0f, 0x0d,
|
||||
];
|
||||
#[rustfmt::skip]
|
||||
const NORMAL1: &[u8] = &[
|
||||
0x5e, 0x22,
|
||||
0x7b, 0x05,
|
||||
|
@ -2,19 +2,16 @@
|
||||
|
||||
#![allow(missing_docs, non_upper_case_globals, non_snake_case, clippy::unreadable_literal)]
|
||||
|
||||
use crate::unicode::version::UnicodeVersion;
|
||||
use crate::unicode::bool_trie::{BoolTrie, SmallBoolTrie};
|
||||
use crate::unicode::version::UnicodeVersion;
|
||||
|
||||
/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
|
||||
/// `char` and `str` methods are based on.
|
||||
#[unstable(feature = "unicode_version", issue = "49726")]
|
||||
pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {
|
||||
major: 12,
|
||||
minor: 1,
|
||||
micro: 0,
|
||||
_priv: (),
|
||||
};
|
||||
pub const UNICODE_VERSION: UnicodeVersion =
|
||||
UnicodeVersion { major: 12, minor: 1, micro: 0, _priv: () };
|
||||
pub(crate) mod general_category {
|
||||
#[rustfmt::skip]
|
||||
const Cc_table: &super::SmallBoolTrie = &super::SmallBoolTrie {
|
||||
r1: &[
|
||||
0, 1, 0
|
||||
@ -28,6 +25,7 @@ pub(crate) mod general_category {
|
||||
Cc_table.lookup(c)
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
const N_table: &super::BoolTrie = &super::BoolTrie {
|
||||
r1: [
|
||||
0x03ff000000000000, 0x0000000000000000, 0x720c000000000000, 0x0000000000000000,
|
||||
@ -138,10 +136,10 @@ pub(crate) mod general_category {
|
||||
pub fn N(c: char) -> bool {
|
||||
N_table.lookup(c)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub(crate) mod derived_property {
|
||||
#[rustfmt::skip]
|
||||
const Alphabetic_table: &super::BoolTrie = &super::BoolTrie {
|
||||
r1: [
|
||||
0x0000000000000000, 0x07fffffe07fffffe, 0x0420040000000000, 0xff7fffffff7fffff,
|
||||
@ -327,6 +325,7 @@ pub(crate) mod derived_property {
|
||||
Alphabetic_table.lookup(c)
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
const Case_Ignorable_table: &super::BoolTrie = &super::BoolTrie {
|
||||
r1: [
|
||||
0x0400408000000000, 0x0000000140000000, 0x0190a10000000000, 0x0000000000000000,
|
||||
@ -464,6 +463,7 @@ pub(crate) mod derived_property {
|
||||
Case_Ignorable_table.lookup(c)
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
const Cased_table: &super::BoolTrie = &super::BoolTrie {
|
||||
r1: [
|
||||
0x0000000000000000, 0x07fffffe07fffffe, 0x0420040000000000, 0xff7fffffff7fffff,
|
||||
@ -565,6 +565,7 @@ pub(crate) mod derived_property {
|
||||
Cased_table.lookup(c)
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
const Grapheme_Extend_table: &super::BoolTrie = &super::BoolTrie {
|
||||
r1: [
|
||||
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
|
||||
@ -689,6 +690,7 @@ pub(crate) mod derived_property {
|
||||
Grapheme_Extend_table.lookup(c)
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
const Lowercase_table: &super::BoolTrie = &super::BoolTrie {
|
||||
r1: [
|
||||
0x0000000000000000, 0x07fffffe00000000, 0x0420040000000000, 0xff7fffff80000000,
|
||||
@ -789,6 +791,7 @@ pub(crate) mod derived_property {
|
||||
Lowercase_table.lookup(c)
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
const Uppercase_table: &super::BoolTrie = &super::BoolTrie {
|
||||
r1: [
|
||||
0x0000000000000000, 0x0000000007fffffe, 0x0000000000000000, 0x000000007f7fffff,
|
||||
@ -889,10 +892,10 @@ pub(crate) mod derived_property {
|
||||
pub fn Uppercase(c: char) -> bool {
|
||||
Uppercase_table.lookup(c)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub(crate) mod property {
|
||||
#[rustfmt::skip]
|
||||
const White_Space_table: &super::SmallBoolTrie = &super::SmallBoolTrie {
|
||||
r1: &[
|
||||
0, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
@ -912,20 +915,19 @@ pub(crate) mod property {
|
||||
pub fn White_Space(c: char) -> bool {
|
||||
White_Space_table.lookup(c)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub(crate) mod conversions {
|
||||
pub fn to_lower(c: char) -> [char; 3] {
|
||||
match bsearch_case_table(c, to_lowercase_table) {
|
||||
None => [c, '\0', '\0'],
|
||||
None => [c, '\0', '\0'],
|
||||
Some(index) => to_lowercase_table[index].1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_upper(c: char) -> [char; 3] {
|
||||
match bsearch_case_table(c, to_uppercase_table) {
|
||||
None => [c, '\0', '\0'],
|
||||
None => [c, '\0', '\0'],
|
||||
Some(index) => to_uppercase_table[index].1,
|
||||
}
|
||||
}
|
||||
@ -934,6 +936,7 @@ pub(crate) mod conversions {
|
||||
table.binary_search_by(|&(key, _)| key.cmp(&c)).ok()
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
const to_lowercase_table: &[(char, [char; 3])] = &[
|
||||
('\u{41}', ['\u{61}', '\0', '\0']), ('\u{42}', ['\u{62}', '\0', '\0']), ('\u{43}',
|
||||
['\u{63}', '\0', '\0']), ('\u{44}', ['\u{64}', '\0', '\0']), ('\u{45}', ['\u{65}', '\0',
|
||||
@ -1558,6 +1561,7 @@ pub(crate) mod conversions {
|
||||
('\u{1e920}', ['\u{1e942}', '\0', '\0']), ('\u{1e921}', ['\u{1e943}', '\0', '\0'])
|
||||
];
|
||||
|
||||
#[rustfmt::skip]
|
||||
const to_uppercase_table: &[(char, [char; 3])] = &[
|
||||
('\u{61}', ['\u{41}', '\0', '\0']), ('\u{62}', ['\u{42}', '\0', '\0']), ('\u{63}',
|
||||
['\u{43}', '\0', '\0']), ('\u{64}', ['\u{44}', '\0', '\0']), ('\u{65}', ['\u{45}', '\0',
|
||||
@ -2228,5 +2232,4 @@ pub(crate) mod conversions {
|
||||
('\u{1e940}', ['\u{1e91e}', '\0', '\0']), ('\u{1e941}', ['\u{1e91f}', '\0', '\0']),
|
||||
('\u{1e942}', ['\u{1e920}', '\0', '\0']), ('\u{1e943}', ['\u{1e921}', '\0', '\0'])
|
||||
];
|
||||
|
||||
}
|
||||
|
@ -81,8 +81,8 @@ PREAMBLE = """\
|
||||
|
||||
#![allow(missing_docs, non_upper_case_globals, non_snake_case, clippy::unreadable_literal)]
|
||||
|
||||
use crate::unicode::version::UnicodeVersion;
|
||||
use crate::unicode::bool_trie::{{BoolTrie, SmallBoolTrie}};
|
||||
use crate::unicode::version::UnicodeVersion;
|
||||
""".format(year=datetime.datetime.now().year)
|
||||
|
||||
# Mapping taken from Table 12 from:
|
||||
@ -555,6 +555,8 @@ def generate_table(
|
||||
if is_pub:
|
||||
pub_string = "pub "
|
||||
|
||||
yield "\n"
|
||||
yield " #[rustfmt::skip]\n"
|
||||
yield " %sconst %s: %s = &[\n" % (pub_string, name, decl_type)
|
||||
|
||||
data = []
|
||||
@ -568,7 +570,7 @@ def generate_table(
|
||||
for table_line in generate_table_lines("".join(data).split(","), 8):
|
||||
yield table_line
|
||||
|
||||
yield "\n ];\n\n"
|
||||
yield "\n ];\n"
|
||||
|
||||
|
||||
def compute_trie(raw_data, chunk_size):
|
||||
@ -634,6 +636,9 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=False):
|
||||
pub_string = ""
|
||||
if is_pub:
|
||||
pub_string = "pub "
|
||||
|
||||
yield "\n"
|
||||
yield " #[rustfmt::skip]\n"
|
||||
yield " %sconst %s: &super::BoolTrie = &super::BoolTrie {\n" % (pub_string, name)
|
||||
yield " r1: [\n"
|
||||
data = ("0x%016x" % chunk for chunk in chunks[:0x800 // chunk_size])
|
||||
@ -678,7 +683,7 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=False):
|
||||
yield fragment
|
||||
yield "\n ],\n"
|
||||
|
||||
yield " };\n\n"
|
||||
yield " };\n"
|
||||
|
||||
|
||||
def generate_small_bool_trie(name, codepoint_ranges, is_pub=False):
|
||||
@ -700,6 +705,8 @@ def generate_small_bool_trie(name, codepoint_ranges, is_pub=False):
|
||||
if is_pub:
|
||||
pub_string = "pub "
|
||||
|
||||
yield "\n"
|
||||
yield " #[rustfmt::skip]\n"
|
||||
yield (" %sconst %s: &super::SmallBoolTrie = &super::SmallBoolTrie {\n"
|
||||
% (pub_string, name))
|
||||
|
||||
@ -717,7 +724,7 @@ def generate_small_bool_trie(name, codepoint_ranges, is_pub=False):
|
||||
yield fragment
|
||||
yield "\n ],\n"
|
||||
|
||||
yield " };\n\n"
|
||||
yield " };\n"
|
||||
|
||||
|
||||
def generate_property_module(mod, grouped_categories, category_subset):
|
||||
@ -726,7 +733,7 @@ def generate_property_module(mod, grouped_categories, category_subset):
|
||||
Generate Rust code for module defining properties.
|
||||
"""
|
||||
|
||||
yield "pub(crate) mod %s {\n" % mod
|
||||
yield "pub(crate) mod %s {" % mod
|
||||
for cat in sorted(category_subset):
|
||||
if cat in ("Cc", "White_Space"):
|
||||
generator = generate_small_bool_trie("%s_table" % cat, grouped_categories[cat])
|
||||
@ -736,9 +743,10 @@ def generate_property_module(mod, grouped_categories, category_subset):
|
||||
for fragment in generator:
|
||||
yield fragment
|
||||
|
||||
yield "\n"
|
||||
yield " pub fn %s(c: char) -> bool {\n" % cat
|
||||
yield " %s_table.lookup(c)\n" % cat
|
||||
yield " }\n\n"
|
||||
yield " }\n"
|
||||
|
||||
yield "}\n\n"
|
||||
|
||||
@ -753,21 +761,21 @@ def generate_conversions_module(unicode_data):
|
||||
yield """
|
||||
pub fn to_lower(c: char) -> [char; 3] {
|
||||
match bsearch_case_table(c, to_lowercase_table) {
|
||||
None => [c, '\\0', '\\0'],
|
||||
None => [c, '\\0', '\\0'],
|
||||
Some(index) => to_lowercase_table[index].1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_upper(c: char) -> [char; 3] {
|
||||
match bsearch_case_table(c, to_uppercase_table) {
|
||||
None => [c, '\\0', '\\0'],
|
||||
None => [c, '\\0', '\\0'],
|
||||
Some(index) => to_uppercase_table[index].1,
|
||||
}
|
||||
}
|
||||
|
||||
fn bsearch_case_table(c: char, table: &[(char, [char; 3])]) -> Option<usize> {
|
||||
table.binary_search_by(|&(key, _)| key.cmp(&c)).ok()
|
||||
}\n\n"""
|
||||
}\n"""
|
||||
|
||||
decl_type = "&[(char, [char; 3])]"
|
||||
format_conversion = lambda x: "({},[{},{},{}])".format(*(
|
||||
@ -827,13 +835,9 @@ def main():
|
||||
/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
|
||||
/// `char` and `str` methods are based on.
|
||||
#[unstable(feature = "unicode_version", issue = "49726")]
|
||||
pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {{
|
||||
major: {version.major},
|
||||
minor: {version.minor},
|
||||
micro: {version.micro},
|
||||
_priv: (),
|
||||
}};
|
||||
""").format(version=unicode_version)
|
||||
pub const UNICODE_VERSION: UnicodeVersion =
|
||||
UnicodeVersion {{ major: {v.major}, minor: {v.minor}, micro: {v.micro}, _priv: () }};
|
||||
""").format(v=unicode_version)
|
||||
buf.write(unicode_version_notice)
|
||||
|
||||
get_path = lambda f: get_unicode_file_path(unicode_version, f)
|
||||
|
Loading…
x
Reference in New Issue
Block a user