From d092abb316582a286f712ed05eeb8c61854ec524 Mon Sep 17 00:00:00 2001 From: John Howard Date: Tue, 21 May 2024 15:34:24 -0700 Subject: [PATCH] Update to support nightly after 3/22/24 From https://github.com/rust-lang/rust/commit/44d185b0d00c8ba228aafa789a39b77d7fd11daf --- src/formatter.rs | 3 + src/parser.rs | 7 + src/reader.rs | 1 + src/schema.rs | 1 + tests/runner.rs | 1 + tests/samples/compiler_messages.txt | 14 ++ tests/snapshots/runner__async_fn_types.snap | 13 ++ tests/snapshots/runner__command_types.snap | 16 +++ .../runner__compiler_messages_types.snap | 125 ++++++++++++++++++ .../snapshots/runner__control_flow_types.snap | 2 + .../runner__several_types_types.snap | 21 +++ tests/snapshots/runner__timex_types.snap | 31 +++++ tests/snapshots/runner__tokio_udp_types.snap | 11 ++ 13 files changed, 246 insertions(+) create mode 100644 tests/samples/compiler_messages.txt create mode 100644 tests/snapshots/runner__compiler_messages_types.snap diff --git a/src/formatter.rs b/src/formatter.rs index b9e1d2f..113ba6a 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -24,6 +24,9 @@ impl Formatter { if let Some(offset) = field.offset { let _ = write!(self.o, " offset={offset}"); } + if let Some(t) = &field.local_type { + let _ = write!(self.o, " type={t}"); + } let _ = writeln!(self.o); } diff --git a/src/parser.rs b/src/parser.rs index 0dcfb11..b95e1b8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -43,6 +43,11 @@ fn alignment(input: &str) -> IResult<&str, usize> { preceded(tag("alignment: "), bytes)(input) } +// Example: "type: {async fn body of fn}" +fn local_type(input: &str) -> IResult<&str, &str> { + preceded(tag("type: "), is_not("\n"))(input) +} + // Example: "offset: 0 bytes" fn offset(input: &str) -> IResult<&str, usize> { preceded(tag("offset: "), bytes)(input) @@ -62,6 +67,7 @@ fn field(input: &str) -> IResult<&str, Field> { let (input, (name, _, size)) = tuple((name, tag(": "), bytes))(input)?; let (input, offset) = opt(preceded(tag(", "), offset))(input)?; let (input, align) = opt(preceded(tag(", "), alignment))(input)?; + let (input, local_type) = opt(preceded(tag(", "), local_type))(input)?; let field = Field { kind, @@ -70,6 +76,7 @@ fn field(input: &str) -> IResult<&str, Field> { size, align, offset, + local_type: local_type.map(|s| s.to_string()), }; Ok((input, field)) diff --git a/src/reader.rs b/src/reader.rs index 88bcf9e..df327f1 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -7,6 +7,7 @@ pub fn read(mut rd: impl BufRead) -> eyre::Result { while rd.read_line(&mut line)? > 0 { let Some(refined_line) = line.strip_prefix("print-type-size ") else { + line.clear(); continue }; diff --git a/src/schema.rs b/src/schema.rs index 09f733e..dc81e32 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -54,6 +54,7 @@ pub struct Field { pub align: Option, // TODO: what is it? pub offset: Option, + pub local_type: Option } #[derive(Debug, PartialEq, Eq)] diff --git a/tests/runner.rs b/tests/runner.rs index 5f9a77a..aceba9b 100644 --- a/tests/runner.rs +++ b/tests/runner.rs @@ -27,5 +27,6 @@ test_sample!(tokio_udp); test_sample!(several_types); test_sample!(timex); test_sample!(async_fn); +test_sample!(compiler_messages); // TODO: add samples from rustc tests. diff --git a/tests/samples/compiler_messages.txt b/tests/samples/compiler_messages.txt new file mode 100644 index 0000000..d2ea17b --- /dev/null +++ b/tests/samples/compiler_messages.txt @@ -0,0 +1,14 @@ + Compiling project v0.0.0 (/home/project) +print-type-size type: `{async fn body of run()}`: 7880 bytes, alignment: 8 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Unresumed`: 592 bytes +print-type-size upvar `.self`: 568 bytes, offset: 0 bytes, alignment: 8 bytes +print-type-size upvar `.drain`: 24 bytes +print-type-size variant `Suspend0`: 7879 bytes +print-type-size upvar `.self`: 568 bytes, offset: 0 bytes, alignment: 8 bytes +print-type-size upvar `.drain`: 24 bytes +print-type-size local `.self`: 568 bytes +print-type-size padding: 1 bytes +print-type-size local `..coroutine_field3`: 1 bytes, alignment: 1 bytes, type: bool +print-type-size padding: 6 bytes +print-type-size local `.__awaitee`: 6712 bytes, alignment: 8 bytes, type: {async fn body of run()} diff --git a/tests/snapshots/runner__async_fn_types.snap b/tests/snapshots/runner__async_fn_types.snap index bc3989e..9cb460a 100644 --- a/tests/snapshots/runner__async_fn_types.snap +++ b/tests/snapshots/runner__async_fn_types.snap @@ -28,6 +28,7 @@ expression: types offset: Some( 0, ), + local_type: None, }, ), ], @@ -47,6 +48,7 @@ expression: types offset: Some( 0, ), + local_type: None, }, ), Field( @@ -56,6 +58,7 @@ expression: types size: 8192, align: None, offset: None, + local_type: None, }, ), Field( @@ -65,6 +68,7 @@ expression: types size: 1, align: None, offset: None, + local_type: None, }, ), ], @@ -84,6 +88,7 @@ expression: types offset: Some( 0, ), + local_type: None, }, ), ], @@ -103,6 +108,7 @@ expression: types offset: Some( 0, ), + local_type: None, }, ), ], @@ -126,6 +132,7 @@ expression: types size: 8192, align: None, offset: None, + local_type: None, }, ), ], @@ -152,6 +159,7 @@ expression: types size: 0, align: None, offset: None, + local_type: None, }, ), Field( @@ -161,6 +169,7 @@ expression: types size: 8192, align: None, offset: None, + local_type: None, }, ), ], @@ -214,6 +223,7 @@ expression: types size: 1, align: None, offset: None, + local_type: None, }, ), ], @@ -240,6 +250,7 @@ expression: types size: 0, align: None, offset: None, + local_type: None, }, ), Field( @@ -249,6 +260,7 @@ expression: types size: 1, align: None, offset: None, + local_type: None, }, ), ], @@ -279,6 +291,7 @@ expression: types size: 0, align: None, offset: None, + local_type: None, }, ), ], diff --git a/tests/snapshots/runner__command_types.snap b/tests/snapshots/runner__command_types.snap index 0c0f2af..50b7097 100644 --- a/tests/snapshots/runner__command_types.snap +++ b/tests/snapshots/runner__command_types.snap @@ -17,6 +17,7 @@ expression: types size: 32, align: None, offset: None, + local_type: None, }, ), Field( @@ -26,6 +27,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -35,6 +37,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -44,6 +47,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -53,6 +57,7 @@ expression: types size: 24, align: None, offset: None, + local_type: None, }, ), Field( @@ -62,6 +67,7 @@ expression: types size: 24, align: None, offset: None, + local_type: None, }, ), Field( @@ -71,6 +77,7 @@ expression: types size: 24, align: None, offset: None, + local_type: None, }, ), Field( @@ -80,6 +87,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -89,6 +97,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -98,6 +107,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -107,6 +117,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -116,6 +127,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -125,6 +137,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -134,6 +147,7 @@ expression: types size: 1, align: None, offset: None, + local_type: None, }, ), Field( @@ -143,6 +157,7 @@ expression: types size: 1, align: None, offset: None, + local_type: None, }, ), Field( @@ -152,6 +167,7 @@ expression: types size: 1, align: None, offset: None, + local_type: None, }, ), ], diff --git a/tests/snapshots/runner__compiler_messages_types.snap b/tests/snapshots/runner__compiler_messages_types.snap new file mode 100644 index 0000000..c312961 --- /dev/null +++ b/tests/snapshots/runner__compiler_messages_types.snap @@ -0,0 +1,125 @@ +--- +source: tests/runner.rs +expression: types +--- +[ + Type { + name: "{async fn body of run()}", + size: 7880, + align: 8, + kind: Enum( + EnumType { + discriminant_size: Some( + 1, + ), + variants: [ + EnumVariant { + name: "Unresumed", + size: 592, + items: [ + Field( + Field { + kind: Upvar, + name: "self", + size: 568, + align: Some( + 8, + ), + offset: Some( + 0, + ), + local_type: None, + }, + ), + Field( + Field { + kind: Upvar, + name: "drain", + size: 24, + align: None, + offset: None, + local_type: None, + }, + ), + ], + }, + EnumVariant { + name: "Suspend0", + size: 7879, + items: [ + Field( + Field { + kind: Upvar, + name: "self", + size: 568, + align: Some( + 8, + ), + offset: Some( + 0, + ), + local_type: None, + }, + ), + Field( + Field { + kind: Upvar, + name: "drain", + size: 24, + align: None, + offset: None, + local_type: None, + }, + ), + Field( + Field { + kind: GeneratorLocal, + name: "self", + size: 568, + align: None, + offset: None, + local_type: None, + }, + ), + Padding( + 1, + ), + Field( + Field { + kind: GeneratorLocal, + name: "coroutine_field3", + size: 1, + align: Some( + 1, + ), + offset: None, + local_type: Some( + "bool", + ), + }, + ), + Padding( + 6, + ), + Field( + Field { + kind: GeneratorLocal, + name: "__awaitee", + size: 6712, + align: Some( + 8, + ), + offset: None, + local_type: Some( + "{async fn body of run()}", + ), + }, + ), + ], + }, + ], + }, + ), + end_padding: None, + }, +] diff --git a/tests/snapshots/runner__control_flow_types.snap b/tests/snapshots/runner__control_flow_types.snap index 9ee4015..afffd16 100644 --- a/tests/snapshots/runner__control_flow_types.snap +++ b/tests/snapshots/runner__control_flow_types.snap @@ -22,6 +22,7 @@ expression: types size: 32, align: None, offset: None, + local_type: None, }, ), ], @@ -37,6 +38,7 @@ expression: types size: 0, align: None, offset: None, + local_type: None, }, ), ], diff --git a/tests/snapshots/runner__several_types_types.snap b/tests/snapshots/runner__several_types_types.snap index 3eab617..2bf927d 100644 --- a/tests/snapshots/runner__several_types_types.snap +++ b/tests/snapshots/runner__several_types_types.snap @@ -17,6 +17,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -26,6 +27,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -35,6 +37,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -44,6 +47,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -53,6 +57,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -62,6 +67,7 @@ expression: types size: 1, align: None, offset: None, + local_type: None, }, ), ], @@ -85,6 +91,7 @@ expression: types size: 48, align: None, offset: None, + local_type: None, }, ), Field( @@ -94,6 +101,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), ], @@ -115,6 +123,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -124,6 +133,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -133,6 +143,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), ], @@ -154,6 +165,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -163,6 +175,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -172,6 +185,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -181,6 +195,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -190,6 +205,7 @@ expression: types size: 1, align: None, offset: None, + local_type: None, }, ), ], @@ -220,6 +236,7 @@ expression: types size: 24, align: None, offset: None, + local_type: None, }, ), ], @@ -235,6 +252,7 @@ expression: types size: 24, align: None, offset: None, + local_type: None, }, ), ], @@ -258,6 +276,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -267,6 +286,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -276,6 +296,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), ], diff --git a/tests/snapshots/runner__timex_types.snap b/tests/snapshots/runner__timex_types.snap index f71bf5d..b49fa18 100644 --- a/tests/snapshots/runner__timex_types.snap +++ b/tests/snapshots/runner__timex_types.snap @@ -17,6 +17,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Padding( @@ -31,6 +32,7 @@ expression: types 8, ), offset: None, + local_type: None, }, ), Field( @@ -40,6 +42,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -49,6 +52,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -58,6 +62,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -67,6 +72,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Padding( @@ -81,6 +87,7 @@ expression: types 8, ), offset: None, + local_type: None, }, ), Field( @@ -90,6 +97,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -99,6 +107,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -108,6 +117,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -117,6 +127,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -126,6 +137,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -135,6 +147,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -144,6 +157,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Padding( @@ -158,6 +172,7 @@ expression: types 8, ), offset: None, + local_type: None, }, ), Field( @@ -167,6 +182,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -176,6 +192,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -185,6 +202,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -194,6 +212,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -203,6 +222,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -212,6 +232,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -221,6 +242,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -230,6 +252,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -239,6 +262,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -248,6 +272,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -257,6 +282,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -266,6 +292,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -275,6 +302,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -284,6 +312,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -293,6 +322,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), Field( @@ -302,6 +332,7 @@ expression: types size: 4, align: None, offset: None, + local_type: None, }, ), ], diff --git a/tests/snapshots/runner__tokio_udp_types.snap b/tests/snapshots/runner__tokio_udp_types.snap index ee1e48e..974701d 100644 --- a/tests/snapshots/runner__tokio_udp_types.snap +++ b/tests/snapshots/runner__tokio_udp_types.snap @@ -29,6 +29,7 @@ expression: types 8, ), offset: None, + local_type: None, }, ), Padding( @@ -43,6 +44,7 @@ expression: types 8, ), offset: None, + local_type: None, }, ), ], @@ -63,6 +65,7 @@ expression: types 8, ), offset: None, + local_type: None, }, ), Padding( @@ -77,6 +80,7 @@ expression: types 8, ), offset: None, + local_type: None, }, ), ], @@ -97,6 +101,7 @@ expression: types 8, ), offset: None, + local_type: None, }, ), Padding( @@ -111,6 +116,7 @@ expression: types 8, ), offset: None, + local_type: None, }, ), ], @@ -130,6 +136,7 @@ expression: types offset: Some( 0, ), + local_type: None, }, ), Field( @@ -139,6 +146,7 @@ expression: types size: 144, align: None, offset: None, + local_type: None, }, ), Field( @@ -148,6 +156,7 @@ expression: types size: 16, align: None, offset: None, + local_type: None, }, ), Field( @@ -157,6 +166,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), Field( @@ -166,6 +176,7 @@ expression: types size: 8, align: None, offset: None, + local_type: None, }, ), ],