Skip to content

Commit

Permalink
Enable reflection for all archetypes and add is_required flag to `A…
Browse files Browse the repository at this point in the history
…rchetypeFieldReflection` (#7319)

### What

This PR:
- enables reflection for all archetypes (was opt-in)
- removes the now-unused opt-in fbs attribute
- add the `is_required` flag to the archetype's field reflection struct

Note: I opted to kept the `ArchetypeReflectionMarker` marker trait for
now, since it's used by some code where it clarifies the intent to
actually use reflection stuff, but we could certainly remove it as well.

Review first commit only (second is codegen).

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/7319?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/7319?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!
* [x] If have noted any breaking changes to the log API in
`CHANGELOG.md` and the migration guide

- [PR Build Summary](https://build.rerun.io/pr/7319)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
abey79 authored Sep 2, 2024
1 parent 5df2aed commit 73bbbab
Show file tree
Hide file tree
Showing 66 changed files with 1,031 additions and 99 deletions.
14 changes: 3 additions & 11 deletions crates/build/re_types_builder/src/codegen/rust/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use crate::{
ArrowRegistry, CodeGenerator, ElementType, Object, ObjectField, ObjectKind, Objects, Reporter,
Type, ATTR_DEFAULT, ATTR_RERUN_COMPONENT_OPTIONAL, ATTR_RERUN_COMPONENT_RECOMMENDED,
ATTR_RERUN_COMPONENT_REQUIRED, ATTR_RERUN_LOG_MISSING_AS_EMPTY, ATTR_RERUN_VIEW_IDENTIFIER,
ATTR_RUST_CUSTOM_CLAUSE, ATTR_RUST_DERIVE, ATTR_RUST_DERIVE_ONLY,
ATTR_RUST_GENERATE_FIELD_INFO, ATTR_RUST_NEW_PUB_CRATE, ATTR_RUST_REPR,
ATTR_RUST_CUSTOM_CLAUSE, ATTR_RUST_DERIVE, ATTR_RUST_DERIVE_ONLY, ATTR_RUST_NEW_PUB_CRATE,
ATTR_RUST_REPR,
};

use super::{
Expand Down Expand Up @@ -1189,14 +1189,6 @@ fn quote_trait_impls_for_archetype(obj: &Object) -> TokenStream {
})
};

let impl_archetype_reflection_marker = if obj.is_attr_set(ATTR_RUST_GENERATE_FIELD_INFO) {
quote! {
impl ::re_types_core::ArchetypeReflectionMarker for #name { }
}
} else {
quote!()
};

quote! {
static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentName; #num_required]> =
once_cell::sync::Lazy::new(|| {[#required]});
Expand Down Expand Up @@ -1294,7 +1286,7 @@ fn quote_trait_impls_for_archetype(obj: &Object) -> TokenStream {
}
}

#impl_archetype_reflection_marker
impl ::re_types_core::ArchetypeReflectionMarker for #name { }
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/build/re_types_builder/src/codegen/rust/reflection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use quote::{format_ident, quote};

use crate::{
codegen::{autogen_warning, Target},
ObjectKind, Objects, Reporter, ATTR_RUST_GENERATE_FIELD_INFO,
ObjectKind, Objects, Reporter, ATTR_RERUN_COMPONENT_REQUIRED,
};

use super::util::{append_tokens, doc_as_lines};
Expand Down Expand Up @@ -142,7 +142,6 @@ fn generate_archetype_reflection(reporter: &Reporter, objects: &Objects) -> Toke
for obj in objects
.objects_of_kind(ObjectKind::Archetype)
.filter(|obj| !obj.is_testing())
.filter(|obj| obj.is_attr_set(ATTR_RUST_GENERATE_FIELD_INFO))
{
let quoted_field_reflections = obj.fields.iter().map(|field| {
let Some(component_name) = field.typ.fqname() else {
Expand All @@ -159,12 +158,14 @@ fn generate_archetype_reflection(reporter: &Reporter, objects: &Objects) -> Toke
obj.is_experimental(),
)
.join("\n");
let required = field.attrs.has(ATTR_RERUN_COMPONENT_REQUIRED);

quote! {
ArchetypeFieldReflection {
component_name: #component_name.into(),
display_name: #display_name,
docstring_md: #docstring_md,
is_required: #required,
}
}
});
Expand Down
2 changes: 0 additions & 2 deletions crates/build/re_types_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ pub const ATTR_RUST_NEW_PUB_CRATE: &str = "attr.rust.new_pub_crate";
pub const ATTR_RUST_OVERRIDE_CRATE: &str = "attr.rust.override_crate";
pub const ATTR_RUST_REPR: &str = "attr.rust.repr";
pub const ATTR_RUST_TUPLE_STRUCT: &str = "attr.rust.tuple_struct";
pub const ATTR_RUST_GENERATE_FIELD_INFO: &str = "attr.rust.generate_field_info";

pub const ATTR_CPP_NO_FIELD_CTORS: &str = "attr.cpp.no_field_ctors";
pub const ATTR_CPP_RENAME_FIELD: &str = "attr.cpp.rename_field";

Expand Down
3 changes: 0 additions & 3 deletions crates/store/re_types/definitions/attributes/rust.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,3 @@ attribute "attr.rust.new_pub_crate";
/// an object of kind `Blueprint` with `attr.rust.override_crate=re_viewport`, the final
/// object will be generated in `re_viewport/src/blueprint`.
attribute "attr.rust.override_crate";

/// Specify on an archetype to opt-in into generating `ArchetypeFieldInfo` for all fields.
attribute "attr.rust.generate_field_info";
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ namespace rerun.archetypes;
table InstancePoses3D (
"attr.docs.category": "Spatial 3D",
"attr.docs.view_types": "Spatial3DView, Spatial2DView: if logged above active projection",
"attr.rust.derive": " PartialEq",
"attr.rust.generate_field_info"
"attr.rust.derive": " PartialEq"
) {
/// Translation vectors.
translations: [rerun.components.PoseTranslation3D] ("attr.rerun.component_optional", nullable, order: 1100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ table Transform3D (
"attr.docs.category": "Spatial 3D",
"attr.docs.view_types": "Spatial3DView, Spatial2DView: if logged above active projection",
"attr.rerun.log_missing_as_empty", // See https://github.com/rerun-io/rerun/issues/6909
"attr.rust.derive": "Copy, PartialEq",
"attr.rust.generate_field_info"
"attr.rust.derive": "Copy, PartialEq"
) {
/// Translation vector.
translation: rerun.components.Translation3D ("attr.rerun.component_optional", nullable, order: 1100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ namespace rerun.blueprint.archetypes;
table Background (
"attr.python.aliases": "datatypes.Rgba32Like, blueprint_components.BackgroundKindLike",
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Copy",
"attr.rust.generate_field_info"
"attr.rust.derive": "Copy"
) {
// --- Required ---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace rerun.blueprint.archetypes;

// ---

/// The top-level description of the Viewport.
/// The description of a container.
table ContainerBlueprint (
"attr.rerun.scope": "blueprint",
"attr.rust.override_crate": "re_types_blueprint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ namespace rerun.blueprint.archetypes;

/// The query for the dataframe view.
table DataframeQuery (
"attr.rerun.scope": "blueprint",
"attr.rust.generate_field_info"
"attr.rerun.scope": "blueprint"
) {
// --- Optional ---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace rerun.blueprint.archetypes;
table PlotLegend (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default",
"attr.rust.generate_field_info",
"attr.python.aliases": "blueprint_components.Corner2D"
) {
// --- Optional ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ namespace rerun.blueprint.archetypes;
/// Configuration for the scalar axis of a plot.
table ScalarAxis (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default",
"attr.rust.generate_field_info"
"attr.rust.derive": "Default"
) {
// --- Optional ---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace rerun.blueprint.archetypes;

// ---

/// The top-level description of the Viewport.
/// The description of a single view.
table SpaceViewBlueprint (
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ namespace rerun.blueprint.archetypes;
/// Configures how tensor scalars are mapped to color.
table TensorScalarMapping (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default",
"attr.rust.generate_field_info"
"attr.rust.derive": "Default"
) {
/// Filter used when zooming in on the tensor.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ namespace rerun.blueprint.archetypes;
/// Specifies a 2D slice of a tensor.
table TensorSliceSelection (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default, Hash, PartialEq, Eq",
"attr.rust.generate_field_info"
"attr.rust.derive": "Default, Hash, PartialEq, Eq"
) {
/// Which dimension to map to width.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace rerun.blueprint.archetypes;
table TensorViewFit (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default",
"attr.rust.generate_field_info",
"attr.python.aliases": "blueprint_components.ViewFitLike"
) {
/// How the image is scaled to fit the view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ namespace rerun.blueprint.archetypes;
/// Ordering of the time range table of the dataframe view
table TimeRangeTableOrder (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Copy",
"attr.rust.generate_field_info"
"attr.rust.derive": "Copy"
) {
// --- Optional ---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace rerun.blueprint.archetypes;

// ---

/// The top-level description of the Viewport.
/// The top-level description of the viewport.
table ViewportBlueprint (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ namespace rerun.blueprint.archetypes;
/// based on the bounding-box of the data or other camera information present in the view.
table VisualBounds2D (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Copy",
"attr.rust.generate_field_info"
"attr.rust.derive": "Copy"
) {
/// Controls the visible range of a 2D view.
///
Expand Down
2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/annotation_context.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/arrows2d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/arrows3d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/asset3d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/asset_video.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/bar_chart.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/boxes2d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/boxes3d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/depth_image.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/disconnected_space.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/ellipsoids3d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/encoded_image.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/image.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/line_strips2d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/line_strips3d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/mesh3d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/pinhole.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/points2d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/points3d.rs

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

2 changes: 2 additions & 0 deletions crates/store/re_types/src/archetypes/scalar.rs

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

Loading

0 comments on commit 73bbbab

Please sign in to comment.