From bef46a47efe363bc6a42577904f72ca8ac4b1051 Mon Sep 17 00:00:00 2001 From: Jonas Wanke Date: Thu, 14 Mar 2024 17:48:48 +0100 Subject: [PATCH 1/4] Rename id_path.is_empty() to .is_root() --- compiler/frontend/src/hir.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/hir.rs b/compiler/frontend/src/hir.rs index 67ab9c201..89e7b1c51 100644 --- a/compiler/frontend/src/hir.rs +++ b/compiler/frontend/src/hir.rs @@ -144,13 +144,14 @@ pub enum IdKey { Positional(usize), } impl IdPath { - fn is_empty(&self) -> bool { + #[must_use] + fn is_root(&self) -> bool { self.0.is_empty() } #[must_use] fn child(&self, key: IdKey) -> Self { - if self.is_empty() { + if self.is_root() { Self::from(key) } else { Self(format!("{}:{key}", self.0)) @@ -255,7 +256,7 @@ impl Id { #[must_use] pub fn is_root(&self) -> bool { - self.keys.is_empty() + self.keys.is_root() } #[must_use] From 5607c832fcf81917ea59e0a7f32a2aaa4cc2abc3 Mon Sep 17 00:00:00 2001 From: Jonas Wanke Date: Thu, 14 Mar 2024 17:49:06 +0100 Subject: [PATCH 2/4] Fix id_path.parent() of top-level HIR ID --- compiler/frontend/src/hir.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/frontend/src/hir.rs b/compiler/frontend/src/hir.rs index 89e7b1c51..d76f0a726 100644 --- a/compiler/frontend/src/hir.rs +++ b/compiler/frontend/src/hir.rs @@ -165,7 +165,16 @@ impl IdPath { #[must_use] fn parent(&self) -> Option { - self.0.rfind(':').map(|i| Self(self.0[..i].to_string())) + self.0 + .rfind(':') + .map(|i| Self(self.0[..i].to_string())) + .or_else(|| { + if self.is_root() { + None + } else { + Some(Self::default()) + } + }) } } impl From for IdPath { From 6402e49a111742d4e209c6b48b7378ea25be0ec8 Mon Sep 17 00:00:00 2001 From: Jonas Wanke Date: Thu, 14 Mar 2024 17:54:51 +0100 Subject: [PATCH 3/4] Re-add limited debug information in release builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This re-adds file and line number information to backtraces while only increasing the executable's file size from 15 MB to 76 MB (compared to around 170 MB with full debug information). --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 78eb4f7d7..f1a82a8ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,6 @@ members = [ [workspace.package] edition = "2021" rust-version = "1.78.0" + +[profile.release] +debug = "limited" From 1cc3fb6a11b0fc1118488e507a2edff0851f5fad Mon Sep 17 00:00:00 2001 From: Jonas Wanke Date: Thu, 14 Mar 2024 17:58:27 +0100 Subject: [PATCH 4/4] Add debug information comment --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index f1a82a8ee..1d8eebcb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,7 @@ edition = "2021" rust-version = "1.78.0" [profile.release] +# This adds file and line number information to backtraces while only increasing +# the executable's file size from 15 MB to 76 MB (compared to around 170 MB with +# full debug information). debug = "limited"