Skip to content

Commit c91e852

Browse files
authored
Revert "[Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros" (#99838)
Reverts #90574
1 parent 7b28cc0 commit c91e852

File tree

19 files changed

+263
-717
lines changed

19 files changed

+263
-717
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ C++2c Feature Support
285285

286286
- Implemented `P2963R3 Ordering of constraints involving fold expressions <https://wg21.link/P2963R3>`_.
287287

288-
- Implemented `P3034R1 Module Declarations Shouldn’t be Macros <https://wg21.link/P3034R1>`_.
289-
290288

291289
Resolutions to C++ Defect Reports
292290
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -952,11 +952,6 @@ def warn_module_conflict : Warning<
952952
InGroup<ModuleConflict>;
953953

954954
// C++20 modules
955-
def err_module_decl_cannot_be_macros : Error<
956-
"the module name in a module%select{| partition}0 declaration cannot contain "
957-
"an object-like macro %1">;
958-
def err_unxepected_paren_in_module_decl : Error<
959-
"unexpected '(' after the module name in a module%select{| partition}0 declaration">;
960955
def err_header_import_semi_in_macro : Error<
961956
"semicolon terminating header import declaration cannot be produced "
962957
"by a macro">;

clang/include/clang/Basic/IdentifierTable.h

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
180180
LLVM_PREFERRED_TYPE(bool)
181181
unsigned IsModulesImport : 1;
182182

183-
// True if this is the 'module' contextual keyword.
184-
LLVM_PREFERRED_TYPE(bool)
185-
unsigned IsModulesDecl : 1;
186-
187183
// True if this is a mangled OpenMP variant name.
188184
LLVM_PREFERRED_TYPE(bool)
189185
unsigned IsMangledOpenMPVariantName : 1;
@@ -200,7 +196,7 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
200196
LLVM_PREFERRED_TYPE(bool)
201197
unsigned IsFinal : 1;
202198

203-
// 21 bits left in a 64-bit word.
199+
// 22 bits left in a 64-bit word.
204200

205201
// Managed by the language front-end.
206202
void *FETokenInfo = nullptr;
@@ -216,8 +212,8 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
216212
IsCPPOperatorKeyword(false), NeedsHandleIdentifier(false),
217213
IsFromAST(false), ChangedAfterLoad(false), FEChangedAfterLoad(false),
218214
RevertedTokenID(false), OutOfDate(false), IsModulesImport(false),
219-
IsModulesDecl(false), IsMangledOpenMPVariantName(false),
220-
IsDeprecatedMacro(false), IsRestrictExpansion(false), IsFinal(false) {}
215+
IsMangledOpenMPVariantName(false), IsDeprecatedMacro(false),
216+
IsRestrictExpansion(false), IsFinal(false) {}
221217

222218
public:
223219
IdentifierInfo(const IdentifierInfo &) = delete;
@@ -524,18 +520,6 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
524520
RecomputeNeedsHandleIdentifier();
525521
}
526522

527-
/// Determine whether this is the contextual keyword \c module.
528-
bool isModulesDeclaration() const { return IsModulesDecl; }
529-
530-
/// Set whether this identifier is the contextual keyword \c module.
531-
void setModulesDeclaration(bool I) {
532-
IsModulesDecl = I;
533-
if (I)
534-
NeedsHandleIdentifier = true;
535-
else
536-
RecomputeNeedsHandleIdentifier();
537-
}
538-
539523
/// Determine whether this is the mangled name of an OpenMP variant.
540524
bool isMangledOpenMPVariantName() const { return IsMangledOpenMPVariantName; }
541525

@@ -756,8 +740,6 @@ class IdentifierTable {
756740
// If this is the 'import' contextual keyword, mark it as such.
757741
if (Name == "import")
758742
II->setModulesImport(true);
759-
else if (Name == "module")
760-
II->setModulesDeclaration(true);
761743

762744
return *II;
763745
}

clang/include/clang/Basic/TokenKinds.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,9 +1003,6 @@ ANNOTATION(module_include)
10031003
ANNOTATION(module_begin)
10041004
ANNOTATION(module_end)
10051005

1006-
// Annotations for C++, Clang and Objective-C named modules.
1007-
ANNOTATION(module_name)
1008-
10091006
// Annotation for a header_name token that has been looked up and transformed
10101007
// into the name of a header unit.
10111008
ANNOTATION(header_unit)

clang/include/clang/Lex/Preprocessor.h

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ class Preprocessor {
615615

616616
ModuleDeclSeq ModuleDeclState;
617617

618+
/// Whether the module import expects an identifier next. Otherwise,
619+
/// it expects a '.' or ';'.
620+
bool ModuleImportExpectsIdentifier = false;
621+
618622
/// The identifier and source location of the currently-active
619623
/// \#pragma clang arc_cf_code_audited begin.
620624
std::pair<IdentifierInfo *, SourceLocation> PragmaARCCFCodeAuditedInfo;
@@ -1740,14 +1744,11 @@ class Preprocessor {
17401744
/// Lex a token, forming a header-name token if possible.
17411745
bool LexHeaderName(Token &Result, bool AllowMacroExpansion = true);
17421746

1743-
/// Lex a module name or a partition name.
1744-
bool LexModuleName(Token &Result, bool IsImport);
1745-
17461747
/// Lex the parameters for an #embed directive, returns nullopt on error.
17471748
std::optional<LexEmbedParametersResult> LexEmbedParameters(Token &Current,
17481749
bool ForHasEmbed);
1750+
17491751
bool LexAfterModuleImport(Token &Result);
1750-
bool LexAfterModuleDecl(Token &Result);
17511752
void CollectPpImportSuffix(SmallVectorImpl<Token> &Toks);
17521753

17531754
void makeModuleVisible(Module *M, SourceLocation Loc);
@@ -3038,9 +3039,6 @@ class Preprocessor {
30383039
static bool CLK_LexAfterModuleImport(Preprocessor &P, Token &Result) {
30393040
return P.LexAfterModuleImport(Result);
30403041
}
3041-
static bool CLK_LexAfterModuleDecl(Preprocessor &P, Token &Result) {
3042-
return P.LexAfterModuleDecl(Result);
3043-
}
30443042
};
30453043

30463044
/// Abstract base class that describes a handler that will receive
@@ -3073,77 +3071,6 @@ struct EmbedAnnotationData {
30733071
/// Registry of pragma handlers added by plugins
30743072
using PragmaHandlerRegistry = llvm::Registry<PragmaHandler>;
30753073

3076-
/// Represents module or partition name token sequance.
3077-
///
3078-
/// module-name:
3079-
/// module-name-qualifier[opt] identifier
3080-
///
3081-
/// partition-name: [C++20]
3082-
/// : module-name-qualifier[opt] identifier
3083-
///
3084-
/// module-name-qualifier
3085-
/// module-name-qualifier[opt] identifier .
3086-
///
3087-
/// This class can only be created by the preprocessor and guarantees that the
3088-
/// two source array being contiguous in memory and only contains 3 kind of
3089-
/// tokens (identifier, '.' and ':'). And only available when the preprocessor
3090-
/// returns annot_module_name token.
3091-
///
3092-
/// For exmaple:
3093-
///
3094-
/// export module m.n:c.d
3095-
///
3096-
/// The module name array has 3 tokens ['m', '.', 'n'].
3097-
/// The partition name array has 4 tokens [':', 'c', '.', 'd'].
3098-
///
3099-
/// When import a partition in a named module fragment (Eg. import :part1;),
3100-
/// the module name array will be empty, and the partition name array has 2
3101-
/// tokens.
3102-
///
3103-
/// When we meet a private-module-fragment (Eg. module :private;), preprocessor
3104-
/// will not return a annot_module_name token, but will return 2 separate tokens
3105-
/// [':', 'kw_private'].
3106-
3107-
class ModuleNameInfo {
3108-
friend class Preprocessor;
3109-
ArrayRef<Token> ModuleName;
3110-
ArrayRef<Token> PartitionName;
3111-
3112-
ModuleNameInfo(ArrayRef<Token> AnnotToks, std::optional<unsigned> ColonIndex);
3113-
3114-
public:
3115-
/// Return the contiguous token array.
3116-
ArrayRef<Token> getTokens() const {
3117-
if (ModuleName.empty())
3118-
return PartitionName;
3119-
if (PartitionName.empty())
3120-
return ModuleName;
3121-
return ArrayRef(ModuleName.begin(), PartitionName.end());
3122-
}
3123-
bool hasModuleName() const { return !ModuleName.empty(); }
3124-
bool hasPartitionName() const { return !PartitionName.empty(); }
3125-
ArrayRef<Token> getModuleName() const { return ModuleName; }
3126-
ArrayRef<Token> getPartitionName() const { return PartitionName; }
3127-
Token getColonToken() const {
3128-
assert(hasPartitionName() && "Do not have a partition name");
3129-
return getPartitionName().front();
3130-
}
3131-
3132-
/// Under the standard C++ Modules, the dot is just part of the module name,
3133-
/// and not a real hierarchy separator. Flatten such module names now.
3134-
std::string getFlatName() const;
3135-
3136-
/// Build a module id path from the contiguous token array, both include
3137-
/// module name and partition name.
3138-
void getModuleIdPath(
3139-
SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path) const;
3140-
3141-
/// Build a module id path from \param ModuleName.
3142-
static void getModuleIdPath(
3143-
ArrayRef<Token> ModuleName,
3144-
SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path);
3145-
};
3146-
31473074
} // namespace clang
31483075

31493076
#endif // LLVM_CLANG_LEX_PREPROCESSOR_H

clang/include/clang/Lex/Token.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ class Token {
235235
assert(isAnnotation() && "Used AnnotVal on non-annotation token");
236236
return PtrData;
237237
}
238-
template <class T> T getAnnotationValueAs() const {
239-
return static_cast<T>(getAnnotationValue());
240-
}
241238
void setAnnotationValue(void *val) {
242239
assert(isAnnotation() && "Used AnnotVal on non-annotation token");
243240
PtrData = val;

clang/include/clang/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3876,7 +3876,7 @@ class Parser : public CodeCompletionHandler {
38763876
}
38773877

38783878
bool ParseModuleName(
3879-
SourceLocation UseLoc, ArrayRef<Token> ModuleName,
3879+
SourceLocation UseLoc,
38803880
SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path,
38813881
bool IsImport);
38823882

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,8 @@ void IdentifierTable::AddKeywords(const LangOptions &LangOpts) {
322322
if (LangOpts.IEEE128)
323323
AddKeyword("__ieee128", tok::kw___float128, KEYALL, LangOpts, *this);
324324

325-
// Add the 'import' and 'module' contextual keyword.
325+
// Add the 'import' contextual keyword.
326326
get("import").setModulesImport(true);
327-
get("module").setModulesDeclaration(true);
328327
}
329328

330329
/// Checks if the specified token kind represents a keyword in the

clang/lib/Frontend/PrintPreprocessedOutput.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,9 @@ void PrintPPOutputPPCallbacks::HandleWhitespaceBeforeTok(const Token &Tok,
758758
// These tokens are not expanded to anything and don't need whitespace before
759759
// them.
760760
if (Tok.is(tok::eof) ||
761-
(Tok.isAnnotation() && Tok.isNot(tok::annot_header_unit) &&
762-
Tok.isNot(tok::annot_module_begin) && Tok.isNot(tok::annot_module_end) &&
763-
Tok.isNot(tok::annot_module_name) &&
764-
Tok.isNot(tok::annot_repl_input_end) && Tok.isNot(tok::annot_embed)))
761+
(Tok.isAnnotation() && !Tok.is(tok::annot_header_unit) &&
762+
!Tok.is(tok::annot_module_begin) && !Tok.is(tok::annot_module_end) &&
763+
!Tok.is(tok::annot_repl_input_end) && !Tok.is(tok::annot_embed)))
765764
return;
766765

767766
// EmittedDirectiveOnThisLine takes priority over RequireSameLine.
@@ -952,11 +951,6 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
952951
PP.Lex(Tok);
953952
IsStartOfLine = true;
954953
continue;
955-
} else if (Tok.is(tok::annot_module_name)) {
956-
auto *Info = static_cast<ModuleNameInfo *>(Tok.getAnnotationValue());
957-
*Callbacks->OS << Info->getFlatName();
958-
PP.Lex(Tok);
959-
continue;
960954
} else if (Tok.is(tok::annot_header_unit)) {
961955
// This is a header-name that has been (effectively) converted into a
962956
// module-name.

clang/lib/Lex/PPLexerChange.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer,
122122
CurPPLexer = TheLexer;
123123
CurDirLookup = CurDir;
124124
CurLexerSubmodule = nullptr;
125-
if (CurLexerCallback != CLK_LexAfterModuleImport &&
126-
CurLexerCallback != CLK_LexAfterModuleDecl)
125+
if (CurLexerCallback != CLK_LexAfterModuleImport)
127126
CurLexerCallback = TheLexer->isDependencyDirectivesLexer()
128127
? CLK_DependencyDirectivesLexer
129128
: CLK_Lexer;
@@ -162,7 +161,8 @@ void Preprocessor::EnterMacro(Token &Tok, SourceLocation ILEnd,
162161
PushIncludeMacroStack();
163162
CurDirLookup = nullptr;
164163
CurTokenLexer = std::move(TokLexer);
165-
CurLexerCallback = CLK_TokenLexer;
164+
if (CurLexerCallback != CLK_LexAfterModuleImport)
165+
CurLexerCallback = CLK_TokenLexer;
166166
}
167167

168168
/// EnterTokenStream - Add a "macro" context to the top of the include stack,
@@ -216,8 +216,7 @@ void Preprocessor::EnterTokenStream(const Token *Toks, unsigned NumToks,
216216
PushIncludeMacroStack();
217217
CurDirLookup = nullptr;
218218
CurTokenLexer = std::move(TokLexer);
219-
if (CurLexerCallback != CLK_LexAfterModuleImport &&
220-
CurLexerCallback != CLK_LexAfterModuleDecl)
219+
if (CurLexerCallback != CLK_LexAfterModuleImport)
221220
CurLexerCallback = CLK_TokenLexer;
222221
}
223222

0 commit comments

Comments
 (0)