Skip to content

[Clang][driver][cc1] Fix handling of of C++20 modules in ObjectiveC++ #6015

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

Merged
merged 1 commit into from
Jan 27, 2023

Conversation

Bigcheese
Copy link

Currently there is no way to have Objective-C++20 without LSV. This is a problem because some existing ObjectiveC code is not compatible with LSV. This patch provides a way to disable LSV even in C++20 mode and makes it the default for ObjC++20.

I intend to cherry-pick this into stable/20220421 and stable/20221013.

Comment on lines 5924 to 5925
Default<!strconcat("(", fmodules_ts.KeyPath, "||", fcxx_modules.KeyPath,
") && !LangOpts->ObjC")>,

Choose a reason for hiding this comment

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

Let's either enhance the TableGen infrastructure so that this doesn't have to be string concatenation, or parse/generate these flags manually in CompilerInvocation.cpp.

@Bigcheese
Copy link
Author

Bigcheese commented Jan 25, 2023

I just updated this patch to better handle the overall situation. Defaults to no LSV and no C++20 modules. Adds -cc1 overrides to change this, but rejects invalid combinations.

I didn't switch off of strconcat yet because I'd like to enhance tablegen to support this. Trying to do this in CompilerInvocation.cpp ends up being a lot uglier and harder to follow.

@Bigcheese Bigcheese changed the title [Clang][cc1] Make -fno-modules-local-submodule-visibility the default for ObjC++20 [Clang][driver][cc1] Fix handling of of C++20 modules in ObjectiveC++ Jan 25, 2023
Copy link

@jansvoboda11 jansvoboda11 left a comment

Choose a reason for hiding this comment

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

LGTM with my suggestions resolved.

@@ -1516,8 +1517,8 @@ defm async_exceptions: BoolFOption<"async-exceptions",
LangOpts<"EHAsynch">, DefaultFalse,
PosFlag<SetTrue, [CC1Option], "Enable EH Asynchronous exceptions">, NegFlag<SetFalse>>;
defm cxx_modules : BoolFOption<"cxx-modules",
LangOpts<"CPlusPlusModules">, Default<cpp20.KeyPath>,
NegFlag<SetFalse, [CC1Option], "Disable">, PosFlag<SetTrue, [], "Enable">,
LangOpts<"CPlusPlusModules">, Default<!strconcat(cpp20.KeyPath, " && !", objc.KeyPath)>,

Choose a reason for hiding this comment

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

Please leave a FIXME behind to teach TableGen to handle this in a more structured way.

Comment on lines 6008 to 6009
Default<!strconcat("(", fmodules_ts.KeyPath, "||", fcxx_modules.KeyPath,
") && !", objc.KeyPath)>,

Choose a reason for hiding this comment

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

As discussed offline, it's no longer necessary to have !ObjC here since it's covered by the defm cxx_modules logic.

Comment on lines +4108 to +4109
if ((Opts.ModulesTS || Opts.CPlusPlusModules) && !Opts.ModulesLocalVisibility)
Diags.Report(diag::err_modules_no_lsv) << (Opts.CPlusPlusModules ? 0 : 1);

Choose a reason for hiding this comment

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

Please add tests that cover all the cases.

Unfortunately, ObjectiveC++ does not currently support C++20 modules.
This is because ObjectiveC requires Local Submodule Visibility in
practice, which is not compatible with C++20 modules. Given our
options are to either drop ObjectiveC compatibility, or C++20 modules
compatibility, we currently choose to disable C++20 modules to allow
using other C++20 features in ObjectiveC++20 mode.

This patch also allows enabling LSV and C++20 modules in
ObjectiveC++20 mode for the few cases it does work. It adds errors for
incompatible configurations.
@Bigcheese
Copy link
Author

@swift-ci test

@Bigcheese
Copy link
Author

Previous failures looked unrelated.

@swift-ci test

@Bigcheese Bigcheese merged commit 8a3c5f8 into swiftlang:next Jan 27, 2023
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.

2 participants