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

Fix bf500c3: reduce the amount of vars to track by using std::string_view #9389

Closed
wants to merge 1 commit into from

Conversation

@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Jun 20, 2021

Fixes #9386.
Alternative to #9390. Closes #9390.

Motivation / Problem

MacOS said: BOOOO
GCC said: fuck this shit

See #9386 for details and triage. But basically, since we changed a const char * into std::string, more than one compiler went apeshit on us. I present a (possibly temporary) solution: replace it with const std::string_view.

Description

I do not really know why compilers start to track the std::string like this, or let alone why it blows up optimizations (GCC, from what I understand, tracks 50M vars before giving up .. that sounds like an insane alot for the few settings we have). Either way, on a hunch I replaced std::string with const std::string .. no change. So what about const std::string_view? Fixes the issue. Riggghhtttttt....

So to be clear, I have no clue why. I do know it is (most likely) a save operation, as the string itself will be stored in the data-segment, and the string_view will be a thin wrapper around that.

Sadly, this means in a few places where we were replacing const char * with std::string, I revert that situation a bit, as I cheeky use .data() to get this compiling again. By default a std::string_view cannot be casted to a std::string. But I mostly think this indicates places where we should change the std::string to std::string_view instead of the other way around. Either way, I pushed this outside the scope of this PR, to keep this "fix" to its core element.

The commit message:

GCC complaints with:
  note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without

clang on MacOS just crashes (with bus error 10, read: out of memory).

This started to happen after introducing std::string to each setting.
As these are static strings that never change, there is no need to
use std::string. Instead, we can use std::string_view for this. This
seems to make both compilers really happy (as they basically still
only store a "const char *" as it was before this commit).

Limitations

  • I have 0 clues why this fixes the issue, or why the original code was an issue in the first place. This by no means tells us the root-problem. It just seems to fix the issue so everything is happy again. Any insights to what is going on here exactly would be greatly appreciated.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
…view

GCC complaints with:
  note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without

clang on MacOS just crashes (with bus error 10, read: out of memory).

This started to happen after introducing std::string to each setting.
As these are static strings that never change, there is no need to
use std::string. Instead, we can use std::string_view for this. This
seems to make both compilers really happy (as they basically still
only store a "const char *" as it was before this commit).
@TrueBrain
Copy link
Member Author

@TrueBrain TrueBrain commented Jun 20, 2021

On request tested to keep name a std::string but change the parameter type to std::string_view. That doesn't do enough to resolve the issue. The name has to become std::string_view before the problem is resolved.

Loading

@TrueBrain
Copy link
Member Author

@TrueBrain TrueBrain commented Jun 21, 2021

This is not the core issue, just a way to make it hide again. Let's not go for this solution, but try to find a proper solution.

Loading

@TrueBrain TrueBrain closed this Jun 21, 2021
@TrueBrain TrueBrain deleted the fix-clang-macos branch Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

1 participant