Skip to content

Commit

Permalink
fix soundness hole in segment idx
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-quinones committed Oct 11, 2024
1 parent 416fafe commit ea3a4a5
Show file tree
Hide file tree
Showing 14 changed files with 524 additions and 143 deletions.
9 changes: 4 additions & 5 deletions faer-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl Tree {
fn init(&self) -> TokenStream {
let name = &self.name;
let glue_name = Ident::new(&(name.to_string() + "__"), name.span());
let mut stmt = quote! { let mut #glue_name = __faer_traits::hacks::NonCopy; let #name = __faer_traits::hacks::__with_lifetime_of(&mut #glue_name); };
let mut stmt = quote! { let mut #glue_name = faer_traits::hacks::NonCopy; let #name = faer_traits::hacks::__with_lifetime_of(&mut #glue_name); };

for child in &self.children {
let child = child.init();
Expand Down Expand Up @@ -413,7 +413,7 @@ impl Tree {
let mut stmt = quote! {
#[allow(non_camel_case_types)]
struct #name<'scope, #(#lt2,)* #(#ty,)*> {
#(#children: __faer_traits::hacks::GhostNode<'scope, #lt, #children>,)*
#(#children: faer_traits::hacks::GhostNode<'scope, #lt, #children>,)*
__marker: ::core::marker::PhantomData<fn(&'scope()) -> &'scope ()>,
}
};
Expand All @@ -431,7 +431,7 @@ impl Tree {
let children = self.children.iter().map(|x| &x.name);
let children_init = self.children.iter().map(|x| x.struct_init());
quote! {
__faer_traits::hacks::GhostNode::new(
faer_traits::hacks::GhostNode::new(
#name {
#(#children: #children_init,)*
__marker: ::core::marker::PhantomData,
Expand Down Expand Up @@ -463,9 +463,8 @@ pub fn ghost_tree(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let name = &tree.name;

let block = quote! {{
extern crate faer_traits as __faer_traits;

__faer_traits::hacks::make_guard!(__scope);
faer_traits::hacks::make_guard!(__scope);
#struct_def
{ #init if const { true } { let mut #name = #struct_init; _ = &mut #name; {#block} } else { #deinit panic!() } }
}};
Expand Down
8 changes: 6 additions & 2 deletions faer-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,8 +1397,8 @@ pub unsafe trait Container: 'static {
const N_COMPONENTS: usize = size_of::<Self::Of<u8>>();

const IS_CANONICAL: bool;
type Conj: Container<Conj = Self, Canonical = Self::Canonical>;
type Canonical: Container<Canonical = Self::Canonical>;
type Conj: Container<Conj = Self, Canonical = Self::Canonical, Real = Self::Real>;
type Canonical: Container<Canonical = Self::Canonical, Real = Self::Real>;
type Real: RealContainer;

fn map_impl<T, U, Ctx>(
Expand All @@ -1416,6 +1416,10 @@ pub trait RealContainer: ComplexContainer<Conj = Self, Canonical = Self, Real =
impl<C: Container<Canonical = C>> ComplexContainer for C {}
impl<C: Container<Canonical = C, Conj = C, Real = Self>> RealContainer for C {}

pub type RealValue<C, T> = <<C as Container>::Real as Container>::Of<
<<T as ConjUnit>::Canonical as ComplexField<<C as Container>::Canonical>>::RealUnit,
>;

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
pub struct Unit;

Expand Down
3 changes: 2 additions & 1 deletion faer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"

[dependencies]
bytemuck = "1.18.0"
equator = "0.4.1"
generativity = "1.1.0"
num-complex = { version = "0.4.6", features = ["rand"] }
reborrow = "0.5.5"
Expand All @@ -15,6 +14,8 @@ log = { version = "0.4.22", optional = true }

dyn-stack = { path = "../../dynstack" }
pulp = { path = "../../pulp/pulp" }
equator = { path = "../../equator/equator" }

gemm = { version = "0.18.0", default-features = false }
rand = "0.8.5"

Expand Down
2 changes: 1 addition & 1 deletion faer/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn bench_new(bencher: Bencher, n: usize) {
with_dim!(N, n);
let mut full_l = l.rb_mut().as_shape_mut(N, N);
let mut d = d.rb_mut().as_col_shape_mut(N);
_ = faer::linalg::cholesky::ldlt::factor::cholesky_in_place(
_ = faer::linalg::cholesky::ldlt::factor::simd_cholesky(
&default(),
full_l.as_mut(),
d.as_mut(),
Expand Down
6 changes: 5 additions & 1 deletion faer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ pub use row::{Row, RowGeneric, RowMut, RowMutGeneric, RowRef, RowRefGeneric};

#[allow(unused_imports, dead_code)]
mod internal_prelude {
pub use crate::prelude::default;
pub use crate::prelude::{ctx, default};

pub use crate::{
col::{
Expand Down Expand Up @@ -519,6 +519,8 @@ mod internal_prelude {
pub mod prelude {
use super::*;

pub use faer_traits::Unit;

pub use col::{Col, ColMut, ColRef};
pub use mat::{Mat, MatMut, MatRef};
pub use row::{Row, RowMut, RowRef};
Expand All @@ -527,6 +529,8 @@ pub mod prelude {
pub fn default<Ctx: Default>() -> Ctx {
Default::default()
}

pub use default as ctx;
}

pub struct ScaleGeneric<C: Container, T>(pub C::Of<T>);
Expand Down
Loading

0 comments on commit ea3a4a5

Please sign in to comment.