Skip to content

Commit

Permalink
arrow2-convert migration 3: attr.rust.override_crate & optimizing…
Browse files Browse the repository at this point in the history
… out dependencies (#3897)

This introduces the `rust.attr.override_crate` attribute, which is
necessary for the serde-codegen story.

This attribute also allows us to generate some fundamental types such as
`InstanceKey` directly into `re_types_core` rather than `re_types`,
making it possible to reduce the number of crates that depend on the
giant `re_types`.

- The `AutoSpaceViews` & `PanelView` components are now back into their
respective home (`re_viewport` & `re_viewer`, respectively).
They were temporarily moved it because we had no support for
`custom_crate`.
They will be joined by their more complicated siblings in the next PR,
which implements the necessary serde-codegen support.

- `InstanceKey`, `Clear` and `ClearIsRecursive` are now generated into
`re_types_core`.
This allows `re_query`, `re_arrow_store` and `re_data_store` to drop
their dependency on `re_types`.

- Generated code now picks up arrow from `re_types_core::external`
instead of importing it directly.
This means crates hosting generated code are not forced into import
`arrow2` directly.

---


`arrow2-convert` migration PR series:
- #3853 
- #3855
- #3897
- #3902
  • Loading branch information
teh-cmc authored Oct 18, 2023
1 parent cca5cd9 commit 635ddeb
Show file tree
Hide file tree
Showing 177 changed files with 2,109 additions and 1,184 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/re_arrow_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ re_format.workspace = true
re_log_types.workspace = true
re_log.workspace = true
re_tracing.workspace = true
# NOTE: We're on our way to make this crate re_types-free, which is why we import both.
re_types_core.workspace = true
re_types.workspace = true

# External dependencies:
ahash.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions crates/re_arrow_store/src/store_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use re_log_types::{
DataCell, DataCellColumn, DataCellError, DataRow, DataTable, RowId, TimeInt, TimePoint,
TimeRange,
};
use re_types::components::InstanceKey;
use re_types_core::{ComponentName, ComponentNameSet, Loggable, SizeBytes as _};
use re_types_core::{
components::InstanceKey, ComponentName, ComponentNameSet, Loggable, SizeBytes as _,
};

use crate::{
store::MetadataRegistry, DataStore, DataStoreConfig, IndexedBucket, IndexedBucketInner,
Expand Down
2 changes: 0 additions & 2 deletions crates/re_data_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ re_log_types.workspace = true
re_log.workspace = true
re_smart_channel.workspace = true
re_tracing.workspace = true
# NOTE: We're on our way to make this crate re_types-free, which is why we import both.
re_types_core.workspace = true
re_types.workspace = true

document-features.workspace = true
itertools.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions crates/re_data_store/src/entity_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ impl EntityTree {
time_point: &TimePoint,
path_op: &PathOp,
) -> Vec<ComponentPath> {
use re_types::{archetypes::Clear, components::ClearIsRecursive};
use re_types_core::Archetype as _;
use re_types_core::{archetypes::Clear, components::ClearIsRecursive, Archetype as _};

re_tracing::profile_function!();

Expand Down
2 changes: 1 addition & 1 deletion crates/re_data_store/src/instance_path.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{hash::Hash, str::FromStr};

use re_log_types::{DataPath, EntityPath, EntityPathHash, PathParseError, RowId};
use re_types::components::InstanceKey;
use re_types_core::components::InstanceKey;

use crate::{store_db::EntityDb, VersionedInstancePath, VersionedInstancePathHash};

Expand Down
5 changes: 2 additions & 3 deletions crates/re_data_store/src/store_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use re_log_types::{
ApplicationId, ComponentPath, DataCell, DataRow, DataTable, EntityPath, EntityPathHash, LogMsg,
PathOp, RowId, SetStoreInfo, StoreId, StoreInfo, StoreKind, TimePoint, Timeline,
};
use re_types::components::InstanceKey;
use re_types_core::Loggable;
use re_types_core::{components::InstanceKey, Loggable};

use crate::{Error, TimesPerTimeline};

Expand Down Expand Up @@ -117,7 +116,7 @@ impl EntityDb {

// Look for a `ClearIsRecursive` component, and if it's there, go through the clear path
// instead.
use re_types::components::ClearIsRecursive;
use re_types_core::components::ClearIsRecursive;
if let Some(idx) = row.find_cell(&ClearIsRecursive::name()) {
let cell = &row.cells()[idx];
let settings = cell.try_to_native_mono::<ClearIsRecursive>().unwrap();
Expand Down
1 change: 0 additions & 1 deletion crates/re_log_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ re_log.workspace = true
re_string_interner.workspace = true
re_tracing.workspace = true
re_tuid = { workspace = true, features = ["arrow"] }
# NOTE: We're on our way to make this crate re_types-free, which is why we import both.
re_types_core.workspace = true
re_types = { workspace = true, features = ["image"] }

Expand Down
33 changes: 33 additions & 0 deletions crates/re_log_types/src/example_components.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
//! Example components to be used for tests and docs
use arrow2_convert::{ArrowDeserialize, ArrowField, ArrowSerialize};
use re_types::Loggable as _;

// ----------------------------------------------------------------------------

pub struct MyPoints;

impl re_types::Archetype for MyPoints {
type Indicator = re_types::GenericIndicatorComponent<Self>;

fn name() -> re_types::ArchetypeName {
"test.MyPoints".into()
}

fn required_components() -> ::std::borrow::Cow<'static, [re_types::ComponentName]> {
vec![MyPoint::name()].into()
}

fn recommended_components() -> std::borrow::Cow<'static, [re_types_core::ComponentName]> {
vec![MyColor::name(), MyLabel::name()].into()
}
}

// ----------------------------------------------------------------------------

Expand All @@ -10,6 +31,12 @@ pub struct MyPoint {
pub y: f32,
}

impl MyPoint {
pub fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
}

use crate as re_log_types;

re_log_types::arrow2convert_component_shim!(MyPoint as "test.Point2D");
Expand All @@ -31,6 +58,12 @@ re_log_types::arrow2convert_component_shim!(MyPoint as "test.Point2D");
#[repr(transparent)]
pub struct MyColor(pub u32);

impl From<u32> for MyColor {
fn from(value: u32) -> Self {
Self(value)
}
}

re_log_types::arrow2convert_component_shim!(MyColor as "test.Color");

// ----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions crates/re_query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ re_arrow_store.workspace = true
re_data_store.workspace = true
re_format.workspace = true
re_log_types.workspace = true
# NOTE: We're on our way to make this crate re_types-free, which is why we import both.
re_types_core.workspace = true
re_types = { workspace = true, features = ["datagen"] }
re_log.workspace = true
re_tracing.workspace = true

Expand All @@ -51,6 +49,8 @@ polars-core = { workspace = true, optional = true, features = [


[dev-dependencies]
re_types = { workspace = true, features = ["datagen"] }

criterion = "0.5"
itertools = { workspace = true }
mimalloc.workspace = true
Expand Down
7 changes: 3 additions & 4 deletions crates/re_query/src/archetype_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use std::{collections::BTreeMap, marker::PhantomData};
use arrow2::array::{Array, PrimitiveArray};
use re_format::arrow;
use re_log_types::{DataCell, RowId};
use re_types::components::InstanceKey;
use re_types_core::{
Archetype, Component, ComponentName, DeserializationError, DeserializationResult, Loggable,
SerializationResult,
components::InstanceKey, Archetype, Component, ComponentName, DeserializationError,
DeserializationResult, Loggable, SerializationResult,
};

use crate::QueryError;
Expand Down Expand Up @@ -41,7 +40,7 @@ impl ComponentWithInstances {

/// Returns the array of [`InstanceKey`]s.
#[inline]
pub fn instance_keys(&self) -> Vec<re_types::components::InstanceKey> {
pub fn instance_keys(&self) -> Vec<InstanceKey> {
re_tracing::profile_function!();
self.instance_keys.to_native::<InstanceKey>()
}
Expand Down
9 changes: 4 additions & 5 deletions crates/re_query/src/dataframe_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use arrow2::{
};
use polars_core::prelude::*;
use re_arrow_store::ArrayExt;
use re_types::components::InstanceKey;
use re_types_core::{Archetype, Component, Loggable};
use re_types_core::{components::InstanceKey, Archetype, Component, Loggable};

use crate::{ArchetypeView, ComponentWithInstances, QueryError};

Expand Down Expand Up @@ -125,7 +124,7 @@ impl ComponentWithInstances {
let array1 = self.values.as_arrow_ref();

let series0 = Series::try_from((
re_types::components::InstanceKey::name().as_ref(),
InstanceKey::name().as_ref(),
array0.as_ref().clean_for_polars(),
))?;
let series1 = Series::try_from((C0::name().as_ref(), array1.as_ref().clean_for_polars()))?;
Expand All @@ -145,7 +144,7 @@ impl<A: Archetype> ArchetypeView<A> {
let array1 = C1::to_arrow_opt(self.iter_optional_component::<C1>()?)?;

let series0 = Series::try_from((
re_types::components::InstanceKey::name().as_ref(),
InstanceKey::name().as_ref(),
array0.as_ref().clean_for_polars(),
))?;
let series1 = Series::try_from((C1::name().as_ref(), array1.as_ref().clean_for_polars()))?;
Expand All @@ -165,7 +164,7 @@ impl<A: Archetype> ArchetypeView<A> {
let array2 = C2::to_arrow_opt(self.iter_optional_component::<C2>()?)?;

let series0 = Series::try_from((
re_types::components::InstanceKey::name().as_ref(),
InstanceKey::name().as_ref(),
array0.as_ref().clean_for_polars(),
))?;
let series1 = Series::try_from((C1::name().as_ref(), array1.as_ref().clean_for_polars()))?;
Expand Down
Loading

0 comments on commit 635ddeb

Please sign in to comment.