From 117b9cf144aee402ef2eb682151076a2a11bfeb5 Mon Sep 17 00:00:00 2001 From: Ryan Goodfellow Date: Tue, 23 Dec 2025 23:21:10 -0800 Subject: [PATCH 1/4] bump to rust 1.92 --- p4/src/ast.rs | 5 ++++- rust-toolchain.toml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/p4/src/ast.rs b/p4/src/ast.rs index 19db75f5..5f52520f 100644 --- a/p4/src/ast.rs +++ b/p4/src/ast.rs @@ -47,7 +47,10 @@ impl AST { self.parsers.iter().find(|&p| p.name == name) } - pub fn get_user_defined_type(&self, name: &str) -> Option { + pub fn get_user_defined_type( + &self, + name: &str, + ) -> Option> { if let Some(user_struct) = self.get_struct(name) { return Some(UserDefinedType::Struct(user_struct)); } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4bd1ff45..9cf77fc1 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.86.0" +channel = "1.92.0" profile = "default" From e74c4dd7c5deaddc266f7ef7fa79bee7a7f2ed78 Mon Sep 17 00:00:00 2001 From: Ryan Goodfellow Date: Tue, 23 Dec 2025 23:22:16 -0800 Subject: [PATCH 2/4] clippy auto fixes --- codegen/rust/src/lib.rs | 5 ++--- lang/p4rs/src/checksum.rs | 2 +- lang/p4rs/src/lib.rs | 2 +- lang/p4rs/src/table.rs | 7 ++----- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/codegen/rust/src/lib.rs b/codegen/rust/src/lib.rs index a41ba0e7..df39522f 100644 --- a/codegen/rust/src/lib.rs +++ b/codegen/rust/src/lib.rs @@ -101,8 +101,7 @@ pub fn emit( // On failure write generated code to a tempfile println!("Code generation produced unparsable code"); write_to_tempfile(&tokens)?; - return Err(io::Error::new( - io::ErrorKind::Other, + return Err(io::Error::other( format!("Failed to parse generated code: {:?}", e), )); } @@ -299,7 +298,7 @@ fn type_size(ty: &Type, ast: &AST) -> usize { fn type_size_bytes(ty: &Type, ast: &AST) -> usize { let s = type_size(ty, ast); let mut b = s >> 3; - if s % 8 != 0 { + if !s.is_multiple_of(8) { b += 1 } b diff --git a/lang/p4rs/src/checksum.rs b/lang/p4rs/src/checksum.rs index 936289dd..7b8e9ad2 100644 --- a/lang/p4rs/src/checksum.rs +++ b/lang/p4rs/src/checksum.rs @@ -62,7 +62,7 @@ pub fn udp6_checksum(data: &[u8]) -> u16 { csum.add(payload_len[0], payload_len[1]); let len = payload.len(); - let (odd, len) = if len % 2 == 0 { + let (odd, len) = if len.is_multiple_of(2) { (false, len) } else { (true, len - 1) diff --git a/lang/p4rs/src/lib.rs b/lang/p4rs/src/lib.rs index d63c3c14..4d9d49c8 100644 --- a/lang/p4rs/src/lib.rs +++ b/lang/p4rs/src/lib.rs @@ -370,7 +370,7 @@ pub fn extract_bit_action_parameter( size: usize, ) -> BitVec { let mut byte_size = size >> 3; - if size % 8 != 0 { + if !size.is_multiple_of(8) { byte_size += 1; } let mut b: BitVec = diff --git a/lang/p4rs/src/table.rs b/lang/p4rs/src/table.rs index 54d33f79..832b3730 100644 --- a/lang/p4rs/src/table.rs +++ b/lang/p4rs/src/table.rs @@ -84,17 +84,14 @@ impl Key { } #[derive(Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize)] +#[derive(Default)] pub enum Ternary { + #[default] DontCare, Value(BigUintKey), Masked(BigUint, BigUint, usize), } -impl Default for Ternary { - fn default() -> Self { - Self::DontCare - } -} #[derive(Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize)] pub struct Prefix { From 30f3d058cc286c2b727de58c61dd2e73a424dd19 Mon Sep 17 00:00:00 2001 From: Ryan Goodfellow Date: Tue, 23 Dec 2025 23:26:02 -0800 Subject: [PATCH 3/4] fmt --- codegen/rust/src/lib.rs | 7 ++++--- lang/p4rs/src/table.rs | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/codegen/rust/src/lib.rs b/codegen/rust/src/lib.rs index df39522f..4d9ec523 100644 --- a/codegen/rust/src/lib.rs +++ b/codegen/rust/src/lib.rs @@ -101,9 +101,10 @@ pub fn emit( // On failure write generated code to a tempfile println!("Code generation produced unparsable code"); write_to_tempfile(&tokens)?; - return Err(io::Error::other( - format!("Failed to parse generated code: {:?}", e), - )); + return Err(io::Error::other(format!( + "Failed to parse generated code: {:?}", + e + ))); } }; fs::write(filename, prettyplease::unparse(&f))?; diff --git a/lang/p4rs/src/table.rs b/lang/p4rs/src/table.rs index 832b3730..535062e9 100644 --- a/lang/p4rs/src/table.rs +++ b/lang/p4rs/src/table.rs @@ -83,8 +83,9 @@ impl Key { } } -#[derive(Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize)] -#[derive(Default)] +#[derive( + Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize, Default, +)] pub enum Ternary { #[default] DontCare, @@ -92,7 +93,6 @@ pub enum Ternary { Masked(BigUint, BigUint, usize), } - #[derive(Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize)] pub struct Prefix { pub addr: IpAddr, From 93ae66d1172399f4fff49d00163dd9ef454fadc2 Mon Sep 17 00:00:00 2001 From: Ryan Goodfellow Date: Tue, 23 Dec 2025 23:33:49 -0800 Subject: [PATCH 4/4] deal with breaking mdbook changes --- book/text/book.toml | 1 - book/text/theme/index.hbs | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/book/text/book.toml b/book/text/book.toml index a75b2341..4ef9c82f 100644 --- a/book/text/book.toml +++ b/book/text/book.toml @@ -1,7 +1,6 @@ [book] authors = ["Ryan Goodfellow"] language = "en" -multilingual = false src = "src" title = "The x4c Book" diff --git a/book/text/theme/index.hbs b/book/text/theme/index.hbs index e131c461..d5e538d3 100644 --- a/book/text/theme/index.hbs +++ b/book/text/theme/index.hbs @@ -196,17 +196,17 @@ @@ -214,17 +214,17 @@