Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@jiahaog
Copy link
Member

@jiahaog jiahaog commented Oct 2, 2023

Internal bug: b/303067268

#46376 is causing a breakage to the internal engine build because of

#ifndef IMPELLER_TRACE_CANVAS
// Canvas recorder should only be used when IMPELLER_TRACE_CANVAS is defined
// (never in production code).
static_assert(false);
#endif
. Internally, we do not set IMPELLER_TRACE_CANVAS.

It looks like the cause is that the internal toolchain causes the static_assert to be compiled even though the template is not instantiated.

@chingjun helped me to figure out the following:

https://stackoverflow.com/questions/5246049/c11-static-assert-and-template-instantiation points us to the spec. In the later version (ISO/IEC 14882:2017(E)):

The program is ill-formed, no diagnostic required, if ... no valid specialization can be generated for a template or a substatement of a constexpr if statement (9.4.1) within a template and the template is not instantiated,

The relevant section

The relevant section of the spec

Interpretation: the compiler can either choose to emit the error caused by the static_assert or not. Currently the compiler used by the build here on LUCI does not; internally it does.

For example, the following links shows that simply changing the Clang version affects whether the error appears or not for a minimal template.

Hence, #ifdef out the class instead of using a static_assert for more consistent behavior across these two toolchains.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Oh wild, I didn't expect to see such a difference in compilers. Nice find. I was trying to keep the ifdef compact but this will work, lgtm.

@chinmaygarde chinmaygarde changed the title Don't define CanvasRecorder if IMPELLER_TRACE_CANVAS is not set [Impeller] Don't define CanvasRecorder if IMPELLER_TRACE_CANVAS is not set. Oct 3, 2023
@jiahaog jiahaog added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 4, 2023
@auto-submit auto-submit bot merged commit 857f800 into flutter:main Oct 4, 2023
@jiahaog jiahaog deleted the static-assert branch October 4, 2023 03:06
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 4, 2023
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
…s not set. (#46476)

Internal bug: b/303067268

#46376 is causing a breakage to the internal engine build because of https://github.com/flutter/engine/blob/150d1b6ab51f34c07e21fc32ef76e4842edd4d04/impeller/aiks/canvas_recorder.h#L58-L62. Internally, we do not set `IMPELLER_TRACE_CANVAS`.

It looks like the cause is that the internal toolchain causes the `static_assert` to be compiled even though the template is not instantiated.

@chingjun helped me to figure out the following:

https://stackoverflow.com/questions/5246049/c11-static-assert-and-template-instantiation points us to the spec. In the later version (ISO/IEC 14882:2017(E)):

> The program is ill-formed, no diagnostic required, if ... no valid specialization can be generated for a template or a substatement of a constexpr if statement (9.4.1) within a template and the template is not instantiated,

<details>

<summary>The relevant section</summary>

![The relevant section of the spec](https://github.com/flutter/engine/assets/7111741/4503efcd-9479-4c7a-b4a1-7302dea1653b)

</details>

Interpretation: the compiler can either choose to emit the error caused by the `static_assert` or not. Currently the compiler used by the build here on LUCI does not; internally it does.

For example, the following links shows that simply changing the Clang version affects whether the error appears or not for a minimal template.

- ok: https://godbolt.org/z/n9nYrcvcP
- not ok: https://godbolt.org/z/fWcvdcn35

Hence, `#ifdef` out the class instead of using a `static_assert` for more consistent behavior across these two toolchains.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App e: impeller

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants