Skip to content

Use const parameters in mir.format to reduce template bloat #359

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

Merged
merged 3 commits into from
Sep 20, 2021

Conversation

nordlow
Copy link
Contributor

@nordlow nordlow commented Sep 18, 2021

The important changes are the qualifications of the parameters to the text and print overloads which in essence strips off either const or immutable qualifier from the type(s) A. In calls such as

text(int.init)
text(const(int).init)
text(immutable(int).init)
...

all result in the same template instance of text potentially saving time and space requirements on compilation and binary sizes.

@nordlow
Copy link
Contributor Author

nordlow commented Sep 18, 2021

Ready now.

@nordlow nordlow changed the title Use inout in mir.format.text to reduce template bloat Use inout in mir.format to reduce template bloat Sep 18, 2021
@nordlow nordlow changed the title Use inout in mir.format to reduce template bloat Draft: Use inout in mir.format to reduce template bloat Sep 18, 2021
@codecov-commenter
Copy link

codecov-commenter commented Sep 18, 2021

Codecov Report

Merging #359 (b23a5be) into master (5b90150) will decrease coverage by 0.00%.
The diff coverage is n/a.

❗ Current head b23a5be differs from pull request most recent head 38aa2fa. Consider uploading reports for the commit 38aa2fa to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #359      +/-   ##
==========================================
- Coverage   92.64%   92.64%   -0.01%     
==========================================
  Files          62       62              
  Lines       15380    15376       -4     
==========================================
- Hits        14249    14245       -4     
  Misses       1131     1131              
Impacted Files Coverage Δ
source/mir/format.d 94.44% <ø> (-0.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5b90150...38aa2fa. Read the comment docs.

@nordlow nordlow changed the title Draft: Use inout in mir.format to reduce template bloat Use inout in mir.format to reduce template bloat Sep 18, 2021
@nordlow
Copy link
Contributor Author

nordlow commented Sep 18, 2021

Ready now, @9il.

@9il
Copy link
Member

9il commented Sep 19, 2021

  • format_impl don't need this. It is an internal stuff that can't compile for const and immutable types.
  • Functions that accept numeric types should qualify them as const, not inout. Just for simplicity and they almost already do that.
  • The remaining part is two variadic functions. What is the difference between marking them inout and const?

@9il
Copy link
Member

9il commented Sep 19, 2021

const inout(V)[inout(K)] - how this works?

@nordlow
Copy link
Contributor Author

nordlow commented Sep 19, 2021

* format_impl don't need this. It is an internal stuff that can't compile for const and immutable types.

I reverted the changes in format_impl and printStaticString.

@nordlow nordlow changed the title Use inout in mir.format to reduce template bloat Use const in mir.format to reduce template bloat Sep 19, 2021
@nordlow nordlow changed the title Use const in mir.format to reduce template bloat Use const paramters in mir.format to reduce template bloat Sep 19, 2021
@nordlow
Copy link
Contributor Author

nordlow commented Sep 19, 2021

* The remaining part is two variadic functions. What is the difference between marking them `inout` and `const`?

I used

string text(string separator = "", Args...)(auto ref const(Args) args)

instead. It fulfills the purpose of reducing template bloat aswell. Note that

string text(string separator = "", Args...)(auto ref const Args args)

fails with a scope error so I scratched that. I'm not sure how that is different but that doesn't matter for this PR.

@nordlow nordlow changed the title Use const paramters in mir.format to reduce template bloat Use const parameters in mir.format to reduce template bloat Sep 19, 2021
@nordlow nordlow force-pushed the format-inout branch 2 times, most recently from 0d0c265 to 8e55e34 Compare September 19, 2021 22:15
@nordlow
Copy link
Contributor Author

nordlow commented Sep 19, 2021

Ready now.

@nordlow
Copy link
Contributor Author

nordlow commented Sep 19, 2021

Does text or print make use of toString-members like std.format.format does? If so, using const(Args) inplace of inout(Args) is gonna require those toString-members to be const.

@9il
Copy link
Member

9il commented Sep 20, 2021

Does text or print make use of toString-members like std.format.format does? If so, using const(Args) inplace of inout(Args) is gonna require those toString-members to be const.

Yes. toString members should be const.

@9il 9il merged commit 9a6abda into libmir:master Sep 20, 2021
9il added a commit that referenced this pull request Sep 24, 2021
9il added a commit that referenced this pull request Sep 24, 2021
…364)

* Revert "Use const parameters in mir.format to reduce template bloat (#359)"

This reverts commit 9a6abda.

* add test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants