Skip to content

[lldb] Fallback to implicit modules when explicit modules are missing #8356

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

Conversation

kastiglione
Copy link

@kastiglione kastiglione commented Mar 7, 2024

Handle the case where an explicit module path does not exist, by falling back to implicit modules.

The initial logic is: If any one explicit module is nonexistent, then remove all references to explicit modules. Additionally, remove all explicit module maps.

@kastiglione
Copy link
Author

@artemcm do you know if it's possible to have a hybrid mode? By that I mean:

Could we strip -fno-implicit-module-maps, to allow implicit module maps, but keep all the explicit -fmodule-map-file= options. Would clang prefer the explicit, and if missing, fallback to implicit?

@artemcm
Copy link

artemcm commented Mar 7, 2024

@artemcm do you know if it's possible to have a hybrid mode? By that I mean:

Could we strip -fno-implicit-module-maps, to allow implicit module maps, but keep all the explicit -fmodule-map-file= options. Would clang prefer the explicit, and if missing, fallback to implicit?

This is a good question for @jansvoboda11 or @Bigcheese .

@jansvoboda11
Copy link

Clang would first parse the explicit module maps and then parse any additional module maps found during header search I think. The questions is: can you rely on the explicit module maps still being around if the PCM files aren't? And even if you check for that, is there any chance for time-of-check time-of-use bugs?

Comment on lines 1606 to 1607
// The value's format is 'ModuleName=ModulePath'. Drop the prefix up to the
// first '=' character to obtain the path.

Choose a reason for hiding this comment

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

Not necessarily. There's another format that's just -fmodule-file=ModulePath we might switch to in the future.

Copy link
Author

Choose a reason for hiding this comment

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

@jansvoboda11 thanks. Do you know, are explicit modules guaranteed to be absolute paths? I would presume yes.

Choose a reason for hiding this comment

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

That ultimately depends on the build system. I'd expect them to be absolute in practice, but it's not a guarantee. Theoretically these might be relative to -working-directory or the process CWD.

@kastiglione
Copy link
Author

Clang would first parse the explicit module maps and then parse any additional module maps found during header search I think.

In my local testing this was happening, causing duplicate/shadow issues. And so I removed the references to explicit module maps, and went full implicit. This resulted in compilation working. Thanks for explaining.

@jansvoboda11
Copy link

Clang would first parse the explicit module maps and then parse any additional module maps found during header search I think.

In my local testing this was happening, causing duplicate/shadow issues. And so I removed the references to explicit module maps, and went full implicit. This resulted in compilation working. Thanks for explaining.

Was the shadowing caused by two different module maps? I don't think Clang will parse the same module map twice.

@kastiglione
Copy link
Author

Was the shadowing caused by two different module maps?

I don't think so, but I don't know. I could investigate further. What I can say for certain is that by removing -fno-implicit-module-maps and -fmodule-map-path= flags, the errors went away. When I was initially seeing errors, the code was only removing -fno-implicit-module-maps, but not -fmodule-map-path=.

@kastiglione
Copy link
Author

@swift-ci test

Copy link

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

Can you add a test for this that FileChecks the types log?

// Check both path and value. This is to handle paths containing '='.
if (!llvm::sys::fs::exists(path) && !llvm::sys::fs::exists(value)) {
std::string m_description;
HEALTH_LOG_PRINTF("Nonexistent explicit module file %s", path.data());

Choose a reason for hiding this comment

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

Unfortunately you'll need to either use path.str() or add a HEALTH_LOG macro that takes LLVM formats. There is no guarantee that .data() is nullterminated.

Copy link
Author

Choose a reason for hiding this comment

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

The StringRef references a std::string, which I understand would it a guarantee that data is null terminated.

Choose a reason for hiding this comment

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

  1. Technically correct :-)
  2. But then it would be safer to replace const auto & with const std::string & then to guard against future modification
  3. It would be even better to add a HEALTH_LOG that uses llvm::format so we can avoid the problem altogether

Copy link
Author

Choose a reason for hiding this comment

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

I'll do HEALTH_LOG in an isolated change.

Copy link
Author

Choose a reason for hiding this comment

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

I replaced auto with std::string in 610d19f

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione marked this pull request as ready for review March 11, 2024 23:24
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test windows

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test windows

@kastiglione
Copy link
Author

@swift-ci test linux

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione merged commit 2abff47 into stable/20230725 Mar 15, 2024
@kastiglione kastiglione deleted the dl/lldb-Fallback-to-implicit-modules-when-explicit-modules-are-missing branch March 15, 2024 23:24
kastiglione added a commit that referenced this pull request Mar 18, 2024
…#8356)

Handle the case where an explicit module path does not exist, by falling back to 
implicit modules.

The initial logic is: If any one explicit module is nonexistent, then remove all 
references to explicit modules. Additionally, remove all explicit module maps.

(cherry-picked from commit 2abff47)
kastiglione added a commit that referenced this pull request Mar 18, 2024
…#8356) (#8427)

Handle the case where an explicit module path does not exist, by falling back to 
implicit modules.

The initial logic is: If any one explicit module is nonexistent, then remove all 
references to explicit modules. Additionally, remove all explicit module maps.

(cherry-picked from commit 2abff47)
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.

4 participants