Skip to content

Commit

Permalink
Add lint for builder pattern functions and deref impls to be marked `…
Browse files Browse the repository at this point in the history
…#[inline]` (#4435)

### What
The Rust compiler is not able to inline across traits unless things are
marked inline or link time optimization is enabled. This new lint makes
sure we don't forget it on builder pattern functions an deref
implementations which are usually very small methods that warrant
`#[inline]`.

### 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):
  * Full build: [app.rerun.io](https://app.rerun.io/pr/4435/index.html)
* Partial build:
[app.rerun.io](https://app.rerun.io/pr/4435/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
- Useful for quick testing when changes do not affect examples in any
way
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/4435)
- [Docs
preview](https://rerun.io/preview/0f56b84930f1c7da0aaa66036e7d8c7a54963108/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/0f56b84930f1c7da0aaa66036e7d8c7a54963108/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
Wumpf authored Dec 5, 2023
1 parent eab8244 commit 90429c6
Show file tree
Hide file tree
Showing 36 changed files with 222 additions and 13 deletions.
1 change: 1 addition & 0 deletions crates/re_arrow_store/src/store_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct StoreEvent {
impl std::ops::Deref for StoreEvent {
type Target = StoreDiff;

#[inline]
fn deref(&self) -> &Self::Target {
&self.diff
}
Expand Down
2 changes: 2 additions & 0 deletions crates/re_renderer/src/line_strip_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl<'a> LineBatchBuilder<'a> {
}

/// Sets the picking object id for every element in the batch.
#[inline]
pub fn picking_object_id(mut self, picking_object_id: PickingLayerObjectId) -> Self {
self.batch_mut().picking_object_id = picking_object_id;
self
Expand Down Expand Up @@ -496,6 +497,7 @@ impl<'a> LineStripBuilder<'a> {
self
}

#[inline]
pub fn picking_instance_id(mut self, instance_id: PickingLayerInstanceId) -> Self {
self.picking_instance_id = instance_id;
self
Expand Down
2 changes: 2 additions & 0 deletions crates/re_renderer/src/point_cloud_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,14 @@ impl<'a> PointCloudBatchBuilder<'a> {
}

/// Adds (!) flags for this batch.
#[inline]
pub fn flags(mut self, flags: PointCloudBatchFlags) -> Self {
self.batch_mut().flags |= flags;
self
}

/// Sets the picking object id for the current batch.
#[inline]
pub fn picking_object_id(mut self, picking_object_id: PickingLayerObjectId) -> Self {
self.batch_mut().picking_object_id = picking_object_id;
self
Expand Down
1 change: 1 addition & 0 deletions crates/re_renderer/src/wgpu_resources/bind_group_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct GpuBindGroup {
impl std::ops::Deref for GpuBindGroup {
type Target = wgpu::BindGroup;

#[inline]
fn deref(&self) -> &Self::Target {
&self.resource.inner
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct StoredResource<Res> {
impl<Res> Deref for StoredResource<Res> {
type Target = Res;

#[inline]
fn deref(&self) -> &Self::Target {
&self.resource
}
Expand Down
8 changes: 8 additions & 0 deletions crates/re_sdk/src/recording_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl RecordingStreamBuilder {
/// If the `RERUN` environment variable is set, it will override this.
///
/// Set also: [`Self::enabled`].
#[inline]
pub fn default_enabled(mut self, default_enabled: bool) -> Self {
self.default_enabled = default_enabled;
self
Expand All @@ -152,6 +153,7 @@ impl RecordingStreamBuilder {
/// Setting this will ignore the `RERUN` environment variable.
///
/// Set also: [`Self::default_enabled`].
#[inline]
pub fn enabled(mut self, enabled: bool) -> Self {
self.enabled = Some(enabled);
self
Expand All @@ -166,6 +168,7 @@ impl RecordingStreamBuilder {
/// unique `RecordingId`s.
///
/// The default is to use a random `RecordingId`.
#[inline]
pub fn recording_id(mut self, recording_id: impl Into<String>) -> Self {
self.store_id = Some(StoreId::from_string(
StoreKind::Recording,
Expand All @@ -183,6 +186,7 @@ impl RecordingStreamBuilder {
/// unique [`StoreId`]s.
///
/// The default is to use a random [`StoreId`].
#[inline]
pub fn store_id(mut self, store_id: StoreId) -> Self {
self.store_id = Some(store_id);
self
Expand All @@ -191,25 +195,29 @@ impl RecordingStreamBuilder {
/// Specifies the configuration of the internal data batching mechanism.
///
/// See [`DataTableBatcher`] & [`DataTableBatcherConfig`] for more information.
#[inline]
pub fn batcher_config(mut self, config: DataTableBatcherConfig) -> Self {
self.batcher_config = Some(config);
self
}

#[doc(hidden)]
#[inline]
pub fn store_source(mut self, store_source: StoreSource) -> Self {
self.store_source = Some(store_source);
self
}

#[allow(clippy::wrong_self_convention)]
#[doc(hidden)]
#[inline]
pub fn is_official_example(mut self, is_official_example: bool) -> Self {
self.is_official_example = is_official_example;
self
}

#[doc(hidden)]
#[inline]
pub fn blueprint(mut self) -> Self {
self.store_kind = StoreKind::Blueprint;
self
Expand Down
6 changes: 6 additions & 0 deletions crates/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/re_types/src/archetypes/asset3d.rs

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

1 change: 1 addition & 0 deletions crates/re_types/src/archetypes/bar_chart.rs

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

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

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

7 changes: 7 additions & 0 deletions crates/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/re_types/src/archetypes/depth_image.rs

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

1 change: 1 addition & 0 deletions crates/re_types/src/archetypes/image.rs

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

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

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

Loading

0 comments on commit 90429c6

Please sign in to comment.