Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically derive Debug and Clone in Rust backend #2613

Merged
merged 4 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rerun/archetypes/points2d.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace rerun.archetypes;
/// \rs \include:../../../../../docs/code-examples/point2d_simple_v2.rs
/// \rs ```
table Points2D (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
order: 100
) {
// --- Required ---
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rerun/components/class_id.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ClassId (
"attr.python.aliases": "int",
"attr.python.array_aliases": "int, npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32], npt.NDArray[np.uint64]",
"attr.rerun.legacy_fqname": "rerun.class_id",
"attr.rust.derive": "Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash",
"attr.rust.derive": "Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash",
"attr.rust.tuple_struct",
order: 100
) {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rerun/components/color.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Color (
"attr.python.aliases": "int, Sequence[int], npt.NDArray[Union[np.uint8, np.float32, np.float64]]",
"attr.python.array_aliases": "Sequence[Sequence[int]], npt.NDArray[Union[np.uint8, np.uint32, np.float32, np.float64]]",
"attr.rerun.legacy_fqname": "rerun.colorrgba",
"attr.rust.derive": "Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.derive": "Default, Copy, PartialEq, Eq, PartialOrd, Ord, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent",
"attr.rust.tuple_struct",
order: 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct DrawOrder (
"attr.python.aliases": "float",
"attr.python.array_aliases": "npt.NDArray[np.float32]",
"attr.rerun.legacy_fqname": "rerun.draw_order",
"attr.rust.derive": "Debug, Clone, Copy",
"attr.rust.derive": "Copy",
"attr.rust.repr": "transparent",
"attr.rust.tuple_struct",
order: 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct InstanceKey (
"attr.python.array_aliases": "npt.NDArray[np.uint64]",
"attr.rerun.legacy_fqname": "rerun.instance_key",
"attr.rust.tuple_struct",
"attr.rust.derive": "Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord",
"attr.rust.derive": "Copy, PartialEq, Eq, PartialOrd, Ord",
order: 100
) {
value: uint64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct KeypointId (
"attr.python.aliases": "float",
"attr.python.array_aliases": "npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32]",
"attr.rerun.legacy_fqname": "rerun.keypoint_id",
"attr.rust.derive": "Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash",
"attr.rust.derive": "Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash",
"attr.rust.tuple_struct",
order: 200
) {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rerun/components/label.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ table Label (
"attr.python.aliases": "str",
"attr.python.array_aliases": "Sequence[str]",
"attr.rerun.legacy_fqname": "rerun.label",
"attr.rust.derive": "Debug, Clone, PartialEq, Eq, PartialOrd, Ord",
"attr.rust.derive": "PartialEq, Eq, PartialOrd, Ord",
"attr.rust.repr": "transparent",
"attr.rust.tuple_struct",
order: 100
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rerun/components/point2d.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct Point2D (
"attr.python.aliases": "npt.NDArray[np.float32], Sequence[float], Tuple[float, float]",
"attr.python.array_aliases": "npt.NDArray[np.float32], Sequence[float]",
"attr.rerun.legacy_fqname": "rerun.point2d",
"attr.rust.derive": "Debug, Default, Clone, Copy, PartialEq, PartialOrd",
"attr.rust.derive": "Default, Copy, PartialEq, PartialOrd",
order: 100
) {
xy: rerun.datatypes.Point2D (order: 100);
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rerun/components/radius.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct Radius (
"attr.python.array_aliases": "npt.NDArray[np.float32]",
"attr.rerun.legacy_fqname": "rerun.radius",
"attr.rust.tuple_struct",
"attr.rust.derive": "Debug, Clone, Copy, PartialEq, PartialOrd",
"attr.rust.derive": "Copy, PartialEq, PartialOrd",
order: 100
) {
value: float;
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rerun/datatypes/point2d.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace rerun.datatypes;
struct Point2D (
"attr.python.aliases": "Sequence[float]",
"attr.python.array_aliases": "npt.NDArray[np.float32], Sequence[npt.NDArray[np.float32]], Sequence[Tuple[float, float]], Sequence[float]",
"attr.rust.derive": "Debug, Default, Clone, Copy, PartialEq, PartialOrd",
"attr.rust.derive": "Default, Copy, PartialEq, PartialOrd",
order: 100
) {
x: float (order: 100);
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rerun/datatypes/vec2d.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Vec2D (
"attr.arrow.transparent",
"attr.python.aliases": "Tuple[float, float]",
"attr.python.array_aliases": "npt.NDArray[np.float32], Sequence[Tuple[float, float]], Sequence[float]",
"attr.rust.derive": "Debug, Default, Clone, Copy, PartialEq, PartialOrd",
"attr.rust.derive": "Default, Copy, PartialEq, PartialOrd",
"attr.rust.tuple_struct",
order: 100
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace rerun.testing.archetypes;
// - required affects the nullability of the element values for the underlying array (both native and arrow)

table AffixFuzzer1 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
order: 100
) {
fuzz1001: rerun.testing.components.AffixFuzzer1 ("attr.rerun.component_required", required, order: 1001);
Expand Down
28 changes: 14 additions & 14 deletions crates/re_types/definitions/rerun/testing/components/fuzzy.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,101 +9,101 @@ namespace rerun.testing.components;
// ---

table AffixFuzzer1 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
order: 100
) {
single_required: rerun.testing.datatypes.AffixFuzzer1 (required);
}

table AffixFuzzer2 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
"attr.rust.tuple_struct",
order: 200
) {
single_required: rerun.testing.datatypes.AffixFuzzer1 (required);
}

table AffixFuzzer3 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
order: 300
) {
single_required: rerun.testing.datatypes.AffixFuzzer1 (required);
}

table AffixFuzzer4 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
order: 400
) {
single_optional: rerun.testing.datatypes.AffixFuzzer1;
}

table AffixFuzzer5 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
"attr.rust.tuple_struct",
order: 500
) {
single_optional: rerun.testing.datatypes.AffixFuzzer1;
}

table AffixFuzzer6 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
order: 600
) {
single_optional: rerun.testing.datatypes.AffixFuzzer1;
}

table AffixFuzzer7 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
order: 700
) {
many_optional: [rerun.testing.datatypes.AffixFuzzer1] (order: 100);
}

table AffixFuzzer8 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
order: 800
) {
single_float_optional: float (order: 101);
}

table AffixFuzzer9 (
"attr.rust.derive": "Debug, Clone, PartialEq, Eq",
"attr.rust.derive": "PartialEq, Eq",
order: 900
) {
single_string_required: string (order: 102, required);
}

table AffixFuzzer10 (
"attr.rust.derive": "Debug, Clone, PartialEq, Eq",
"attr.rust.derive": "PartialEq, Eq",
order: 1000
) {
single_string_optional: string (order: 103);
}

table AffixFuzzer11 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
order: 1100
) {
many_floats_optional: [float] (order: 104);
}

table AffixFuzzer12 (
"attr.rust.derive": "Debug, Clone, PartialEq, Eq",
"attr.rust.derive": "PartialEq, Eq",
order: 1200
) {
many_strings_required: [string] (order: 105, required);
}

table AffixFuzzer13 (
"attr.rust.derive": "Debug, Clone, PartialEq, Eq",
"attr.rust.derive": "PartialEq, Eq",
order: 1300
) {
many_strings_optional: [string] (order: 106);
}

// TODO(cmc): the ugly bug we need to take care of at some point
// table AffixFuzzer14 (
// "attr.rust.derive": "Debug, Clone, PartialEq",
// "attr.rust.derive": "PartialEq",
// order: 1400
// ) {
//
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/definitions/rerun/testing/datatypes/fuzzy.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace rerun.testing.datatypes;
// ---

table AffixFuzzer1 (
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
order: 100
) {
single_float_optional: float (order: 101);
Expand All @@ -20,7 +20,7 @@ table AffixFuzzer1 (

table AffixFuzzer2 (
"attr.arrow.transparent",
"attr.rust.derive": "Debug, Clone, PartialEq",
"attr.rust.derive": "PartialEq",
"attr.rust.tuple_struct",
order: 200
) {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/definitions/rust/attributes.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ attribute "attr.rust.tuple_struct";
/// Apply to any object to generate a #derive clause.
///
/// The value of the attribute will be trimmed out but otherwise left as-is.
/// E.g. "attr.rust.derive": "Debug, Clone, Copy"`.
/// E.g. "attr.rust.derive": "Copy"`.
attribute "attr.rust.derive";

/// Apply to any object to generate a #repr clause with the specified value.
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a sha256 hash for all direct and indirect dependencies of this crate's build script.
# It can be safely removed at anytime to force the build script to run again.
# Check out build.rs to see how it's computed.
fe95d42267d6803af40c31b57c2fe5fc59b898b7bb718e2b461400bd83fd16d6
65d6bf828303169287dd4a8df605e50acbde791fa0f2e8167ea751fd23d3a56f
2 changes: 1 addition & 1 deletion crates/re_types/src/components/class_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#[doc = "A 16-bit ID representing a type of semantic class."]
#[doc = ""]
#[doc = "Used to look up a `crate::components::ClassDescription` within the `crate::components::AnnotationContext`."]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ClassId(pub u16);

impl<'a> From<ClassId> for ::std::borrow::Cow<'a, ClassId> {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/src/components/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#[doc = "An RGBA color tuple with unmultiplied/separate alpha, in sRGB gamma space with linear alpha."]
#[derive(
Debug,
Default,
Clone,
Default,
Copy,
PartialEq,
Eq,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/src/components/keypoint_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#[doc = "`KeypointId`s are only meaningful within the context of a `crate::components::ClassDescription`."]
#[doc = ""]
#[doc = "Used to look up an `crate::components::AnnotationInfo` for a Keypoint within the `crate::components::AnnotationContext`."]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct KeypointId(pub u16);

impl<'a> From<KeypointId> for ::std::borrow::Cow<'a, KeypointId> {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/src/components/point2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#![allow(clippy::unnecessary_cast)]

#[doc = "A point in 2D space."]
#[derive(Debug, Default, Clone, Copy, PartialEq, PartialOrd)]
#[derive(Debug, Clone, Default, Copy, PartialEq, PartialOrd)]
pub struct Point2D {
pub xy: crate::datatypes::Point2D,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/src/datatypes/point2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#![allow(clippy::unnecessary_cast)]

#[doc = "A point in 2D space."]
#[derive(Debug, Default, Clone, Copy, PartialEq, PartialOrd)]
#[derive(Debug, Clone, Default, Copy, PartialEq, PartialOrd)]
pub struct Point2D {
pub x: f32,
pub y: f32,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/src/datatypes/vec2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#![allow(clippy::unnecessary_cast)]

#[doc = "A vector in 2D space."]
#[derive(Debug, Default, Clone, Copy, PartialEq, PartialOrd)]
#[derive(Debug, Clone, Default, Copy, PartialEq, PartialOrd)]
pub struct Vec2D(pub [f32; 2usize]);

impl<'a> From<Vec2D> for ::std::borrow::Cow<'a, Vec2D> {
Expand Down
5 changes: 5 additions & 0 deletions crates/re_types_builder/src/codegen/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ fn quote_meta_clause_from_obj(obj: &Object, attr: &str, clause: &str) -> TokenSt
let quoted = obj
.try_get_attr::<String>(attr)
.map(|what| {
let what = if clause == "derive" {
format!("Debug, Clone, {what}")
} else {
what
};
syn::parse_str::<syn::MetaList>(&format!("{clause}({what})"))
.with_context(|| format!("illegal meta clause: {what:?}"))
.unwrap()
Expand Down