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

[CHORE] Add derive_more to get rid of manual Display impls #2794

Merged
merged 11 commits into from
Sep 9, 2024

Conversation

raunakab
Copy link
Contributor

@raunakab raunakab commented Sep 5, 2024

Overview

  • Implemented derive_more::Display for a couple structs to remove some boilerplate.
  • Still potentially more things to derive-macro away

Note

This has the potential of increasing build times due to increasing the amount of codegen rustc will have to do internally. I can try and put up some build time metrics in order to compare the differences in build times.

@github-actions github-actions bot added the chore label Sep 5, 2024
Copy link

codspeed-hq bot commented Sep 5, 2024

CodSpeed Performance Report

Merging #2794 will not alter performance

Comparing ronnie/cleanup-display-impls (8ee4db5) with main (d30e62a)

Summary

✅ 16 untouched benchmarks

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 93.33333% with 4 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@d30e62a). Learn more about missing BASE report.
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/daft-dsl/src/functions/mod.rs 93.33% 2 Missing ⚠️
src/daft-core/src/join.rs 50.00% 1 Missing ⚠️
src/daft-schema/src/field.rs 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2794   +/-   ##
=======================================
  Coverage        ?   63.31%           
=======================================
  Files           ?     1008           
  Lines           ?   114154           
  Branches        ?        0           
=======================================
  Hits            ?    72282           
  Misses          ?    41872           
  Partials        ?        0           
Files with missing lines Coverage Δ
daft/expressions/expressions.py 93.50% <ø> (ø)
src/common/display/src/table_display.rs 81.71% <100.00%> (ø)
src/daft-core/src/count_mode.rs 8.69% <100.00%> (ø)
src/daft-core/src/series/mod.rs 98.50% <ø> (ø)
src/daft-dsl/src/expr.rs 75.84% <100.00%> (ø)
src/daft-schema/src/dtype.rs 80.60% <100.00%> (ø)
src/daft-schema/src/image_format.rs 56.00% <100.00%> (ø)
src/daft-schema/src/image_mode.rs 50.00% <100.00%> (ø)
src/daft-schema/src/schema.rs 87.44% <100.00%> (ø)
src/daft-schema/src/time_unit.rs 95.45% <100.00%> (ø)
... and 3 more

@raunakab raunakab marked this pull request as ready for review September 9, 2024 17:28
@raunakab raunakab merged commit 08ca9a4 into main Sep 9, 2024
39 checks passed
@raunakab raunakab deleted the ronnie/cleanup-display-impls branch September 9, 2024 21:47
@samster25
Copy link
Member

@raunakab you should wait on a review before merging some of these bigger PRs. I was in the middle of one for this PR.

@raunakab
Copy link
Contributor Author

raunakab commented Sep 9, 2024

Sorry about that! Guess I jumped the gun here.

daft/expressions/expressions.py Show resolved Hide resolved
func: &FunctionExpr,
inputs: &[ExprRef],
) -> std::result::Result<String, std::fmt::Error> {
let mut f = String::default();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we write it out directly to std::fmt::Writer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so? I don't think std::fmt::Writer exists. Did you mean std::fmt::Write? That's a trait, however.

Copy link
Member

@samster25 samster25 Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops I meant Formatter

I was wondering if instead of writing to a string (heap allocation) which then gets written to the Formatter, if we can write directly to the formatter

For example, when we impl the Trait, we can do that.

impl Display for X {
  fn fmt(&self, f: &mut Formatter) -> Result {}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Not sure how to get access to the Formatter instance that the fmt function gets as its second argument. The docs say not to construct one yourself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya so it looks like we can't directly construct a Formatter instance, nor are we able to access the Formatter through the #[display("{}", ...)] macro. I was trying to do something like #[display(f, "{}", ...)], but that wasn't working. Looks like derive_more doesn't want its users to access the underlying formatter directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want access to the formatter, we'd need to revert back to the manual implementation of Display for Expr.

left: &ExprRef,
right: &ExprRef,
) -> std::result::Result<String, std::fmt::Error> {
let mut f = String::default();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here?

src/daft-schema/src/field.rs Show resolved Hide resolved
#[serde(transparent)]
#[display("{}\n", make_schema_vertical_table(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the former is actually more readable than this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you want the manual impl Display for ... to be used here? Or create a new wrapper helper function which would do something similar?

tests/series/test_tensor.py Show resolved Hide resolved
@samster25
Copy link
Member

@raunakab Just published my review, let's fix in a follow on?

@raunakab
Copy link
Contributor Author

raunakab commented Sep 9, 2024

@raunakab Just published my review, let's fix in a follow on?

Yup! Will open up a follow-up PR soon.

raunakab added a commit that referenced this pull request Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants