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

First proposal of improvements on C++ generator #1065

Merged
merged 11 commits into from
Sep 21, 2023

Conversation

tristan0x
Copy link
Member

@tristan0x tristan0x commented Sep 6, 2023

  • Reduce number of copies
  • CodePrinter::add_text:
    • now supports multiple arguments
    • use it instead of trivial but expensive calls to fmt::format.
  • CodePrinter::add_multi_line:
    • Rework the implementation to support C++ raw string literals
    • Use it instead of 3 or more consecutive calls to add_line
  • CodePrinter::start_block: rename to push_block
  • CodePrinter::end_block: rename to pop_block
  • CodePrinter::chain_block: rename to chain_block

@tristan0x
Copy link
Member Author

Initial discussion : @pramodk @ohm314

Stack approach to manipulate code blocks

CodePrinter::start_block: rename to push_block
CodePrinter::end_block: rename to pop_block

Rework CodePrinter::add_line

The change allows the method to essentially work like the Python standard library function textwrap.dedent

Remove trivial fmt::format

It costs ~8x more to do CodePrinter::fmt_line("{} bar", var_name) than CodePrinter::add_line(var_name, " bar") (I did a micro-benchmark). I would like to replace these calls and emphase in the documentation that fmt should be used only when the formatting is complex or add_line(...) would make the code hard to read.

@pramodk
Copy link
Contributor

pramodk commented Sep 6, 2023

@tristan0x: suggestions look fine to me! (as mentioned elsewhere, we would like to make it easy to understand/develop/contribute by external users/devs)

@ohm314
Copy link
Contributor

ohm314 commented Sep 6, 2023

(Bear with me until I look in detail at the changes but) overall I agree with the suggestions.

Copy link
Contributor

@ohm314 ohm314 left a comment

Choose a reason for hiding this comment

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

Alright, I did a pass. I really like the changes. Had just some minor comments.

src/printer/code_printer.hpp Outdated Show resolved Hide resolved
src/printer/code_printer.hpp Outdated Show resolved Hide resolved
src/codegen/codegen_acc_visitor.cpp Outdated Show resolved Hide resolved
src/codegen/codegen_cpp_visitor.cpp Outdated Show resolved Hide resolved
src/codegen/codegen_cpp_visitor.cpp Show resolved Hide resolved
src/codegen/codegen_cpp_visitor.cpp Show resolved Hide resolved
@tristan0x tristan0x force-pushed the tristan0x/enh/code-printer branch 3 times, most recently from 87e724f to 453cc1a Compare September 8, 2023 16:20
@bbpbuildbot

This comment has been minimized.

@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

Patch coverage: 90.59% and project coverage change: +0.24% 🎉

Comparison is base (441a3b1) 69.94% compared to head (c767d70) 70.19%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1065      +/-   ##
==========================================
+ Coverage   69.94%   70.19%   +0.24%     
==========================================
  Files         188      188              
  Lines       25647    25632      -15     
==========================================
+ Hits        17939    17992      +53     
+ Misses       7708     7640      -68     
Files Changed Coverage Δ
src/codegen/codegen_acc_visitor.hpp 50.00% <ø> (ø)
src/symtab/symbol_properties.cpp 58.69% <0.00%> (+11.88%) ⬆️
src/utils/string_utils.hpp 100.00% <ø> (+5.71%) ⬆️
src/codegen/codegen_info.cpp 70.73% <75.00%> (ø)
src/symtab/symbol_table.hpp 76.66% <77.77%> (+1.66%) ⬆️
src/codegen/codegen_acc_visitor.cpp 64.10% <85.00%> (-0.26%) ⬇️
src/codegen/codegen_cpp_visitor.cpp 85.56% <89.65%> (-0.16%) ⬇️
src/printer/code_printer.cpp 94.20% <96.96%> (+7.76%) ⬆️
src/codegen/codegen_compatibility_visitor.cpp 100.00% <100.00%> (ø)
src/codegen/codegen_compatibility_visitor.hpp 100.00% <100.00%> (ø)
... and 7 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bbpbuildbot

This comment has been minimized.

@bbpbuildbot

This comment has been minimized.

@bbpbuildbot

This comment has been minimized.

* reduce number of copies
* `CodePrinter::add_text`:
  * now supports multiple arguments
  * use it instead of trivial but expensive call to `fmt::format`.
* `CodePrinter::add_multi_line`:
  * rework to work with C++ raw string literals
  * used it instead of 3 or more consecutive `add_line`
* `CodePrinter::start_block`: rename to `push_block`
* `CodePrinter::end_block`: rename to pop_block
@bbpbuildbot

This comment has been minimized.

@tristan0x tristan0x marked this pull request as ready for review September 19, 2023 10:09
src/codegen/codegen_acc_visitor.cpp Outdated Show resolved Hide resolved
src/codegen/codegen_acc_visitor.cpp Outdated Show resolved Hide resolved
src/printer/code_printer.cpp Outdated Show resolved Hide resolved
@bbpbuildbot

This comment has been minimized.

Copy link
Contributor

@iomaganaris iomaganaris left a comment

Choose a reason for hiding this comment

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

LGTM overall. Some small suggestions

src/printer/code_printer.cpp Show resolved Hide resolved
src/printer/code_printer.cpp Outdated Show resolved Hide resolved
src/codegen/codegen_cpp_visitor.cpp Outdated Show resolved Hide resolved
Co-authored-by: Ioannis Magkanaris <[email protected]>
@bbpbuildbot

This comment has been minimized.

@bbpbuildbot

This comment has been minimized.

@tristan0x
Copy link
Member Author

The CI has failed since yesterday with a weird setuptools_scm issue. Any idea where I can loop @pramodk @ohm314 @heerener ?

@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #154642 (:white_check_mark:) have been uploaded here!

Status and direct links:

@tristan0x tristan0x merged commit 4a6d511 into master Sep 21, 2023
16 checks passed
@tristan0x tristan0x deleted the tristan0x/enh/code-printer branch September 21, 2023 13:51
@pramodk
Copy link
Contributor

pramodk commented Sep 21, 2023

Sorry, I was too late to notice comment. But I guess this has resolved somehow 👍

ohm314 pushed a commit that referenced this pull request Oct 5, 2023
* First proposal of improvements on C++ generator

* reduce number of copies
* `CodePrinter::add_text`:
  * now supports multiple arguments
  * use it instead of trivial but expensive call to `fmt::format`.
* `CodePrinter::add_multi_line`:
  * rework to work with C++ raw string literals
  * used it instead of 3 or more consecutive `add_line`
* `CodePrinter::start_block`: rename to `push_block`
* `CodePrinter::end_block`: rename to pop_block
* CodegenCppVisitor::visit_program more visible
* Try removing python3-importlib-metadata

Co-authored-by: Nicolas Cornu <[email protected]>
Co-authored-by: Ioannis Magkanaris <[email protected]>
Co-authored-by: Erik Heeren <[email protected]>
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.

7 participants