Refactor impellerc_main to better organize some of its logic#182783
Refactor impellerc_main to better organize some of its logic#182783auto-submit[bot] merged 4 commits intoflutter:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors impellerc_main.cc to improve the organization of its logic. Compilers are now created once and reused across different output steps. Logic for outputting SPIR-V has been extracted into a helper function, and comments in the Main function have been updated to reflect the new structure. My review identifies a missing error check in the refactored OutputIPLR function that was present in the original code.
54adf15 to
698e08d
Compare
|
|
||
| auto stage_data = reflector->GetRuntimeStageShaderData(); | ||
| for (const auto& compiler : compilers) { | ||
| auto stage_data = compiler->GetReflector()->GetRuntimeStageShaderData(); |
There was a problem hiding this comment.
please remove type deduction, it's important here since you may be accidentally introducing a copy.
https://google.github.io/styleguide/cppguide.html#Type_deduction
There was a problem hiding this comment.
I changed it to be std::shared_ptr<RuntimeStageData::Shader>. But can you clarify what you mean when you say auto can accidentally introduce a copy?
My understanding is that auto would be std::shared_ptr<RuntimeStageData::Shader> here, right? So I think it creates a copy of the shared_ptr. But that is fine because the ptr is lightweight to copy, and the underlying RuntimeStageData::Shader is not copied. Is that correct? Replacing the auto with std::shared_ptr<RuntimeStageData::Shader> doesn't change anything, does it? Or am I misunderstanding, and I should I be doing something else?
There was a problem hiding this comment.
std::shared_ptr in aggregate it can cause performance problems in systems programming. It introduces atomics for synchronizing ref counts. This is why languages like Rust opted to have 2 types of ref counting (see Arc vs Rc).
In this case the getter is returning a std::shared_ptr by value, so the deduced type is not hiding an extra copy. We've had instances where auto has hid them before so it's best to stick to the C++ style guide, especially when capturing intermediate values.
For fun check this out: https://www.volatileint.dev/posts/auto-type-deduction-gauntlet/
| static bool OutputIPLR( | ||
| const Switches& switches, | ||
| const std::shared_ptr<fml::Mapping>& source_file_mapping) { | ||
| static std::shared_ptr<Compiler> CreateCompiler( |
There was a problem hiding this comment.
nit: i know it's done elsewhere in this file but static functions is kind of a c way or doing things, not a c++. it should be anonymous namespaces.
There was a problem hiding this comment.
Done. Moved all the static functions into an anonymous namespace.
|
|
||
| if (switches.iplr && !OutputIPLR(switches, source_file_mapping)) { | ||
| return false; | ||
| std::vector<std::shared_ptr<Compiler>> compilers; |
There was a problem hiding this comment.
nit: put a .reserve() call in here since we know the size.
| return false; | ||
| std::vector<std::shared_ptr<Compiler>> compilers; | ||
| for (const auto& platform : switches.PlatformsToCompile()) { | ||
| auto compiler = CreateCompiler(platform, source_file_mapping, switches); |
|
autosubmit label was removed for flutter/flutter/182783, because - The status or check suite Linux_android_emu android_engine_opengles_tests has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/flutter/182783, because - The status or check suite Linux_android_emu android_engine_opengles_tests has failed. Please fix the issues identified (or deflake) before re-applying this label. |
Roll Flutter from dad6f9d4107a to b31548feb941 (39 revisions) flutter/flutter@dad6f9d...b31548f 2026-02-25 [email protected] [web] Fix failure on Firefox 148 (flutter/flutter#182855) 2026-02-25 [email protected] Roll Fuchsia Linux SDK from KfPgw04T0OEADLJA5... to XI0Ax7fbtYE4XKYAQ... (flutter/flutter#182887) 2026-02-25 [email protected] Use AnimationStyle curve and reverseCurve in ModalBottomSheet animation (flutter/flutter#181403) 2026-02-25 [email protected] Roll Dart SDK from fd3dce5b6a4e to 5c57e75f1102 (9 revisions) (flutter/flutter#182801) 2026-02-25 98614782+auto-submit[bot]@users.noreply.github.com Reverts "refactor: remove material in context_menu_controller_test, icon_test, list_wheel_scroll_view_test, media_query_test, platform_menu_bar_test (#182697)" (flutter/flutter#182879) 2026-02-25 [email protected] Make sure that an AnimatedSlide doesn't crash in 0x0 environment (flutter/flutter#181535) 2026-02-24 [email protected] Reland Standardize on Test* widgets in *_tester.dart files (flutter/flutter#182632) 2026-02-24 [email protected] docs(Path): clarify that zero-length contours are excluded from computeMetrics (flutter/flutter#180165) 2026-02-24 [email protected] Fix typo in assert message (flutter/flutter#182843) 2026-02-24 [email protected] [win32] Fix overflow in TaskRunnerWindow. (flutter/flutter#182822) 2026-02-24 [email protected] feat: Add --no-uninstall flag to flutter test for integration tests (flutter/flutter#182714) 2026-02-24 [email protected] Rename noFrequencyBasedMinification to useFrequencyBasedMinification (flutter/flutter#182684) 2026-02-24 [email protected] [Impeller] Fix fail to render pixel buffer texture on Linux (flutter/flutter#181656) 2026-02-24 [email protected] Remove FlutterFramework app migration (flutter/flutter#182100) 2026-02-24 [email protected] Roll Packages from 12b43a1 to 062c8d4 (5 revisions) (flutter/flutter#182839) 2026-02-24 [email protected] [web] Run webparagraph tests in CI (flutter/flutter#182092) 2026-02-24 [email protected] Fix a race in EmbedderTest.CanSpecifyCustomUITaskRunner (flutter/flutter#182649) 2026-02-24 [email protected] flutter_tools: Use a super-parameter in several missed cases (flutter/flutter#182581) 2026-02-24 [email protected] Replace more references to `flutter/engine` with `flutter/flutter` (flutter/flutter#182654) 2026-02-24 [email protected] Carousel: Migration from Scrollable+Viewport to CustomScrollView (flutter/flutter#182475) 2026-02-24 [email protected] Refactor impellerc_main to better organize some of its logic (flutter/flutter#182783) 2026-02-24 [email protected] Remove unused `getPluginList ` (flutter/flutter#182660) 2026-02-24 [email protected] Refactor: Remove material from ticker provider test (flutter/flutter#181697) 2026-02-24 [email protected] Roll Skia from 26eebffe12bd to f44d7db68805 (3 revisions) (flutter/flutter#182821) 2026-02-24 [email protected] refactor: remove material in context_menu_controller_test, icon_test, list_wheel_scroll_view_test, media_query_test, platform_menu_bar_test (flutter/flutter#182697) 2026-02-24 [email protected] Roll Skia from 7dad66aae75a to 26eebffe12bd (5 revisions) (flutter/flutter#182810) 2026-02-24 [email protected] Update roadmap for 2026 (flutter/flutter#182798) 2026-02-24 [email protected] Marks Windows tool_tests_commands_1_2 to be unflaky (flutter/flutter#179670) 2026-02-23 [email protected] [web] scroll iOS iframe text input into view (flutter/flutter#179759) 2026-02-23 [email protected] Fix textscaler clamp assertion error (flutter/flutter#181716) 2026-02-23 [email protected] Roll Skia from 9a5a3c92c336 to 7dad66aae75a (4 revisions) (flutter/flutter#182779) 2026-02-23 [email protected] Move more getters from userMessages class to the appropriate places (flutter/flutter#182656) 2026-02-23 [email protected] Manual roll Dart SDK from f8fac50475b8 to fd3dce5b6a4e (6 revisions) (flutter/flutter#182768) 2026-02-23 [email protected] Copy Flutter framework to Add to App FlutterPluginRgistrant (flutter/flutter#182523) 2026-02-23 [email protected] Add progress indicator to artifact downloads (flutter/flutter#181808) 2026-02-23 [email protected] Clarify batch release mode requirements (flutter/flutter#182228) 2026-02-23 [email protected] [web] Remove --disable-gpu from flutter chrome tests (flutter/flutter#182618) 2026-02-23 [email protected] running-apps: update running-apps to use Duration.ago() (flutter/flutter#182172) 2026-02-23 [email protected] Refactor bin/ shell scripts for better performance and safety (flutter/flutter#182674) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. ...
…#182783) No-op change to better organize some of the logic in impellerc_main. This makes some of the followup work for flutter#182400 easier to do. - Instead of creating each compiler inside the `OutputIPLR` function, create them outside of `OutputIPLR` and pass the list of compilers into `OutputIPLR`. This way, the created compilers can be re-used for the alternate `OutputSLFile` step and for the subsequent `OutputSPIRV`, `OutputReflectionData`, and `OutputDepfile` steps. - Moves the logic to output the SPIRV file into a `OutputSPIRV` helper function instead of having it inlined in `Main`. - Move/fix some of the existing comments about the 4 steps performed in `Main`. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
No-op change to better organize some of the logic in impellerc_main. This makes some of the followup work for #182400 easier to do.
OutputIPLRfunction, create them outside ofOutputIPLRand pass the list of compilers intoOutputIPLR. This way, the created compilers can be re-used for the alternateOutputSLFilestep and for the subsequentOutputSPIRV,OutputReflectionData, andOutputDepfilesteps.OutputSPIRVhelper function instead of having it inlined inMain.Main.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.