Skip to content

Disable RTTI in the toolchain#7552

Open
danakj wants to merge 5 commits into
carbon-language:trunkfrom
danakj:no-rtti
Open

Disable RTTI in the toolchain#7552
danakj wants to merge 5 commits into
carbon-language:trunkfrom
danakj:no-rtti

Conversation

@danakj

@danakj danakj commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This reduces object sizes which is desirable for linking speed.

zygoloid did some analysis to determine if any of our code requires RTTI for dynamic_cast here: #7532 (comment):

The only thing I found is that libc++ requires dynamic_cast in order for std::print to correctly write Unicode to terminals on Windows

We use llvm::print functionality, not std::print, so this doesn't affect our toolchain.

@danakj
danakj requested a review from a team as a code owner July 22, 2026 17:13
@danakj
danakj requested review from dwblaikie and removed request for a team July 22, 2026 17:13
@github-actions github-actions Bot added infrastructure dependent Depends on another issue/PR labels Jul 22, 2026
@github-actions

Copy link
Copy Markdown

Depends on #7532, start review with these changes

(Last updated: 2026-07-22 17:14:15 UTC)

@danakj
danakj requested review from chandlerc and removed request for dwblaikie July 22, 2026 17:14
@danakj

danakj commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Looks like we use typeid in diagnostics:

In file included from ./toolchain/lex/helpers.h:8:
./toolchain/diagnostics/emitter.h:533:16: error: use of typeid requires -frtti
  533 |                typeid(Arg).name(), typeid(Storage).name());
      |                ^
./toolchain/diagnostics/emitter.h:533:36: error: use of typeid requires -frtti
  533 |                typeid(Arg).name(), typeid(Storage).name());
      |                                    ^
2 errors generated.

@danakj danakj closed this Jul 22, 2026
@zygoloid

Copy link
Copy Markdown
Contributor

#7554 removes the typeid usage throughout the repository. We were only using it to get a static type name, and LLVM provides a better utility for that.

@danakj danakj reopened this Jul 22, 2026
Comment on lines -75 to -76
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should probably keep these. We'd need it for modules to work, and header parsing should give the same error messages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These moved up to line 70 (this is in the dependent PR)

# omit a meaningful cache key as when using the Carbon toolchain we
# don't need it as it is a hermetic part of Bazel.
project_features = carbon_project_features(cache_key = ""),
project_features = carbon_project_features(cache_key = "", toolchain_internals = False),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than this workaround, I think we should just fix the runtimes to correctly force these features on. I think this is just about adding -fexceptions and -frtti to the libc++ (and libc++abi) copts:

https://github.com/carbon-language/carbon-lang/blob/trunk/bazel/llvm_project/0005_Introduce_basic_sources_exporting_for_libcxx_and_libcxxabi.patch#L181-L183

Those flags should be ordered after the project feature flags, and allow us to re-enable things.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see, okay I will look at regenerating patches, or adding another patch (but not today).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could also add them explicitly to the two libcxx rules instead of the variable. No patch generation and we already have -w in both for similar reasons so minimally hacky workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependent Depends on another issue/PR infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants