Skip to content

Commit

Permalink
chore: Unfudge release build
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Aug 5, 2024
1 parent e48f687 commit 9f5c327
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,14 @@ jobs:
fail-fast: false
matrix:
feature: [capture-io, "cli,doc", "cli,fmt", cli, workspace, languageserver, byte-code]
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo build -p rune --no-default-features --features ${{matrix.feature}}
- run: cargo check --release -p rune --no-default-features --features ${{matrix.feature}}

wasm:
runs-on: ubuntu-latest
Expand Down
23 changes: 1 addition & 22 deletions crates/rune/src/compile/v1/needs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ use core::mem::replace;
use crate::ast::Spanned;
use crate::compile;
use crate::runtime::{Inst, InstAddress, Output};
use crate::shared::rune_diagnose;
use crate::shared::{rune_diagnose, Backtrace};

use super::{Ctxt, DisplayNamed, ScopeId, Scopes};

#[cfg(debug_assertions)]
use crate::shared::Backtrace;

/// Trait used to abstract interactions over different needs.
pub(super) trait Needs<'a, 'hir> {
/// Access the span for the needs.
Expand Down Expand Up @@ -171,7 +168,6 @@ pub(super) struct Address<'a, 'hir> {
kind: AddressKind,
/// A diagnostical name for the address.
name: Option<&'static str>,
#[cfg(debug_assertions)]
backtrace: Backtrace,
}

Expand All @@ -190,7 +186,6 @@ impl<'a, 'hir> Address<'a, 'hir> {
address: addr,
kind: AddressKind::Local,
name: None,
#[cfg(debug_assertions)]
backtrace: Backtrace::capture(),
}
}
Expand All @@ -209,7 +204,6 @@ impl<'a, 'hir> Address<'a, 'hir> {
address: addr,
kind: AddressKind::Assigned,
name: None,
#[cfg(debug_assertions)]
backtrace: Backtrace::capture(),
}
}
Expand All @@ -228,7 +222,6 @@ impl<'a, 'hir> Address<'a, 'hir> {
address: addr,
kind: AddressKind::Dangling,
name: None,
#[cfg(debug_assertions)]
backtrace: Backtrace::capture(),
}
}
Expand Down Expand Up @@ -349,11 +342,7 @@ impl Drop for Address<'_, '_> {
return;
}

#[cfg(debug_assertions)]
rune_diagnose!("{self} was not freed:\nallocated at:\n{}", self.backtrace);

#[cfg(not(debug_assertions))]
rune_diagnose!("{self} was not freed");
}
}

Expand Down Expand Up @@ -401,7 +390,6 @@ impl fmt::Debug for AnyKind<'_, '_> {
pub(super) struct Any<'a, 'hir> {
span: &'hir dyn Spanned,
kind: AnyKind<'a, 'hir>,
#[cfg(debug_assertions)]
backtrace: Backtrace,
}

Expand All @@ -412,7 +400,6 @@ impl<'a, 'hir> Any<'a, 'hir> {
Self {
span,
kind: AnyKind::Ignore { name: None },
#[cfg(debug_assertions)]
backtrace: Backtrace::capture(),
}
}
Expand All @@ -427,7 +414,6 @@ impl<'a, 'hir> Any<'a, 'hir> {
scope,
name: None,
},
#[cfg(debug_assertions)]
backtrace: Backtrace::capture(),
}
}
Expand All @@ -444,7 +430,6 @@ impl<'a, 'hir> Any<'a, 'hir> {
kind: AnyKind::Address {
address: Address::assigned(span, scopes, addr),
},
#[cfg(debug_assertions)]
backtrace: Backtrace::capture(),
}
}
Expand Down Expand Up @@ -481,7 +466,6 @@ impl<'a, 'hir> Any<'a, 'hir> {
address: from,
kind: AddressKind::Assigned,
name: *name,
#[cfg(debug_assertions)]
backtrace: Backtrace::capture(),
},
};
Expand Down Expand Up @@ -510,7 +494,6 @@ impl<'a, 'hir> Any<'a, 'hir> {
address: scopes.alloc_in(self.span, scope)?,
kind: AddressKind::Scope(scope),
name,
#[cfg(debug_assertions)]
backtrace: Backtrace::capture(),
};

Expand Down Expand Up @@ -628,10 +611,6 @@ impl Drop for Any<'_, '_> {
return;
}

#[cfg(debug_assertions)]
rune_diagnose!("{self} was not freed:\nallocated at:\n{}", self.backtrace);

#[cfg(not(debug_assertions))]
rune_diagnose!("{self} was not freed");
}
}
98 changes: 51 additions & 47 deletions crates/rune/src/shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,6 @@ pub(crate) use self::consts::Consts;
pub(crate) use self::fixed_vec::{CapacityError, FixedVec};
pub(crate) use self::gen::Gen;

#[cfg(all(debug_assertions, not(feature = "std")))]
mod r#impl {
use core::fmt;

macro_rules! _rune_diagnose {
($($tt:tt)*) => {
tracing::trace!($($tt)*);
};
}

macro_rules! _rune_trace {
($at:expr, $tok:expr) => {{
_ = $at;
_ = $tok;
}};
}

pub(crate) struct Backtrace;

impl Backtrace {
#[inline]
pub(crate) fn capture() -> Self {
Self
}
}

impl fmt::Display for Backtrace {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "backtrace not available (missing feature `std`)")
}
}

/// A macro for logging or panicking based on the current assertions model.
///
/// The assertion model can be changed from logging to panicking by setting
/// the `RUNE_ASSERT=panic` environment.
#[doc(inline)]
pub(crate) use _rune_diagnose as rune_diagnose;

/// A macro for tracing a specific call site.
///
/// Tracing is enabled if `RUNE_ASSERT=trace` is set.
#[doc(inline)]
pub(crate) use _rune_trace as rune_trace;
}

/// Test whether current assertions model should panic.
#[cfg(all(debug_assertions, feature = "std"))]
mod r#impl {
Expand Down Expand Up @@ -213,5 +167,55 @@ mod r#impl {
pub(crate) use _rune_trace as rune_trace;
}

#[cfg(debug_assertions)]
#[cfg(not(all(debug_assertions, feature = "std")))]
mod r#impl {
use core::fmt;

macro_rules! _rune_diagnose {
($($tt:tt)*) => {
tracing::trace!($($tt)*);
};
}

macro_rules! _rune_trace {
($at:expr, $tok:expr) => {{
_ = $at;
_ = $tok;
}};
}

pub(crate) struct Backtrace;

impl Backtrace {
#[inline(always)]
pub(crate) fn capture() -> Self {
Self
}
}

impl fmt::Display for Backtrace {
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"backtrace not available, missing cfg(all(debug_assertions, feature = \"std\"))"
)
}
}

/// A macro for logging or panicking based on the current assertions model.
///
/// The assertion model can be changed from logging to panicking by setting
/// the `RUNE_ASSERT=panic` environment.
#[doc(inline)]
pub(crate) use _rune_diagnose as rune_diagnose;

/// A macro for tracing a specific call site.
///
/// Tracing is enabled if `RUNE_ASSERT=trace` is set.
#[doc(inline)]
#[cfg(feature = "fmt")]
pub(crate) use _rune_trace as rune_trace;
}

pub(crate) use self::r#impl::*;

0 comments on commit 9f5c327

Please sign in to comment.