<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Thanks, this is helpful!</div><div class=""><br class=""></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On May 16, 2017, at 12:26, Richard Smith <<a href="mailto:richard@metafoo.co.uk" class="">richard@metafoo.co.uk</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On 15 May 2017 at 10:28, Jordan Rose via cfe-commits <span dir="ltr" class=""><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank" class="">cfe-commits@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, Richard. Swift was using this information in order to put imported macros in a particular context. It wouldn't surprise me to hear that we were doing it wrong, and that there's a better way to go from a macro back to a module, but is there a recommended replacement?<br class=""></blockquote><div class=""><br class=""></div><div class="">The recommended way to connect macros to modules is via the ModuleMacro objects, which represent a macro exported from a module. You can query the exported macro for a (module, identifier) pair with Preprocessor::getModuleMacro, or walk the ModuleMacro graph for an identifier by starting from Preprocessor::getLeafModuleMacros.</div><div class=""><br class=""></div><div class="">If you alternatively want to know the set of macros that would be visible with a given set of imports, after setting up that state you can walk the range produced by Preprocessor::macros(true) and query getActiveModuleMacros on each MacroState.</div><div class=""><br class=""></div><div class="">If you want to know "what is the set of macros exported directly by this module?", we don't have a prebuilt mechanism for that, since no in-tree client wants that information, but one way would be to walk macros(true) and query getModuleMacro(module, identifier) on each one.</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks,<br class="">
Jordan<br class="">
<div class="HOEnZb"><div class="h5"><br class="">
<br class="">
> On May 12, 2017, at 16:40, Richard Smith via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a>> wrote:<br class="">
><br class="">
> Author: rsmith<br class="">
> Date: Fri May 12 18:40:52 2017<br class="">
> New Revision: 302966<br class="">
><br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=302966&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project?rev=302966&view=rev</a><br class="">
> Log:<br class="">
> Remove unused tracking of owning module for MacroInfo objects.<br class="">
><br class="">
> Modified:<br class="">
> cfe/trunk/include/clang/Lex/<wbr class="">MacroInfo.h<br class="">
> cfe/trunk/include/clang/Lex/<wbr class="">Preprocessor.h<br class="">
> cfe/trunk/lib/Lex/MacroInfo.<wbr class="">cpp<br class="">
> cfe/trunk/lib/Lex/<wbr class="">PPDirectives.cpp<br class="">
> cfe/trunk/lib/Lex/<wbr class="">Preprocessor.cpp<br class="">
> cfe/trunk/lib/Serialization/<wbr class="">ASTReader.cpp<br class="">
> cfe/trunk/lib/Serialization/<wbr class="">ASTWriter.cpp<br class="">
><br class="">
> Modified: cfe/trunk/include/clang/Lex/<wbr class="">MacroInfo.h<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/cfe/trunk/include/<wbr class="">clang/Lex/MacroInfo.h?rev=<wbr class="">302966&r1=302965&r2=302966&<wbr class="">view=diff</a><br class="">
> ==============================<wbr class="">==============================<wbr class="">==================<br class="">
> --- cfe/trunk/include/clang/Lex/<wbr class="">MacroInfo.h (original)<br class="">
> +++ cfe/trunk/include/clang/Lex/<wbr class="">MacroInfo.h Fri May 12 18:40:52 2017<br class="">
> @@ -105,9 +105,6 @@ class MacroInfo {<br class="">
> /// \brief Must warn if the macro is unused at the end of translation unit.<br class="">
> bool IsWarnIfUnused : 1;<br class="">
><br class="">
> - /// \brief Whether this macro info was loaded from an AST file.<br class="">
> - bool FromASTFile : 1;<br class="">
> -<br class="">
> /// \brief Whether this macro was used as header guard.<br class="">
> bool UsedForHeaderGuard : 1;<br class="">
><br class="">
> @@ -264,34 +261,16 @@ public:<br class="">
> IsDisabled = true;<br class="">
> }<br class="">
><br class="">
> - /// \brief Determine whether this macro info came from an AST file (such as<br class="">
> - /// a precompiled header or module) rather than having been parsed.<br class="">
> - bool isFromASTFile() const { return FromASTFile; }<br class="">
> -<br class="">
> /// \brief Determine whether this macro was used for a header guard.<br class="">
> bool isUsedForHeaderGuard() const { return UsedForHeaderGuard; }<br class="">
><br class="">
> void setUsedForHeaderGuard(bool Val) { UsedForHeaderGuard = Val; }<br class="">
><br class="">
> - /// \brief Retrieve the global ID of the module that owns this particular<br class="">
> - /// macro info.<br class="">
> - unsigned getOwningModuleID() const {<br class="">
> - if (isFromASTFile())<br class="">
> - return *(const unsigned *)(this + 1);<br class="">
> -<br class="">
> - return 0;<br class="">
> - }<br class="">
> -<br class="">
> void dump() const;<br class="">
><br class="">
> private:<br class="">
> unsigned getDefinitionLengthSlow(const SourceManager &SM) const;<br class="">
><br class="">
> - void setOwningModuleID(unsigned ID) {<br class="">
> - assert(isFromASTFile());<br class="">
> - *(unsigned *)(this + 1) = ID;<br class="">
> - }<br class="">
> -<br class="">
> friend class Preprocessor;<br class="">
> };<br class="">
><br class="">
><br class="">
> Modified: cfe/trunk/include/clang/Lex/<wbr class="">Preprocessor.h<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/cfe/trunk/include/<wbr class="">clang/Lex/Preprocessor.h?rev=<wbr class="">302966&r1=302965&r2=302966&<wbr class="">view=diff</a><br class="">
> ==============================<wbr class="">==============================<wbr class="">==================<br class="">
> --- cfe/trunk/include/clang/Lex/<wbr class="">Preprocessor.h (original)<br class="">
> +++ cfe/trunk/include/clang/Lex/<wbr class="">Preprocessor.h Fri May 12 18:40:52 2017<br class="">
> @@ -644,14 +644,6 @@ class Preprocessor {<br class="">
> /// of that list.<br class="">
> MacroInfoChain *MIChainHead;<br class="">
><br class="">
> - struct DeserializedMacroInfoChain {<br class="">
> - MacroInfo MI;<br class="">
> - unsigned OwningModuleID; // MUST be immediately after the MacroInfo object<br class="">
> - // so it can be accessed by MacroInfo::getOwningModuleID()<wbr class="">.<br class="">
> - DeserializedMacroInfoChain *Next;<br class="">
> - };<br class="">
> - DeserializedMacroInfoChain *DeserialMIChainHead;<br class="">
> -<br class="">
> void updateOutOfDateIdentifier(<wbr class="">IdentifierInfo &II) const;<br class="">
><br class="">
> public:<br class="">
> @@ -1669,10 +1661,6 @@ public:<br class="">
> /// \brief Allocate a new MacroInfo object with the provided SourceLocation.<br class="">
> MacroInfo *AllocateMacroInfo(<wbr class="">SourceLocation L);<br class="">
><br class="">
> - /// \brief Allocate a new MacroInfo object loaded from an AST file.<br class="">
> - MacroInfo *<wbr class="">AllocateDeserializedMacroInfo(<wbr class="">SourceLocation L,<br class="">
> - unsigned SubModuleID);<br class="">
> -<br class="">
> /// \brief Turn the specified lexer token into a fully checked and spelled<br class="">
> /// filename, e.g. as an operand of \#include.<br class="">
> ///<br class="">
> @@ -1764,9 +1752,6 @@ private:<br class="">
> /// macro name.<br class="">
> void updateModuleMacroInfo(const IdentifierInfo *II, ModuleMacroInfo &Info);<br class="">
><br class="">
> - /// \brief Allocate a new MacroInfo object.<br class="">
> - MacroInfo *AllocateMacroInfo();<br class="">
> -<br class="">
> DefMacroDirective *AllocateDefMacroDirective(<wbr class="">MacroInfo *MI,<br class="">
> SourceLocation Loc);<br class="">
> UndefMacroDirective *AllocateUndefMacroDirective(<wbr class="">SourceLocation UndefLoc);<br class="">
><br class="">
> Modified: cfe/trunk/lib/Lex/MacroInfo.<wbr class="">cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroInfo.cpp?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/cfe/trunk/lib/Lex/<wbr class="">MacroInfo.cpp?rev=302966&r1=<wbr class="">302965&r2=302966&view=diff</a><br class="">
> ==============================<wbr class="">==============================<wbr class="">==================<br class="">
> --- cfe/trunk/lib/Lex/MacroInfo.<wbr class="">cpp (original)<br class="">
> +++ cfe/trunk/lib/Lex/MacroInfo.<wbr class="">cpp Fri May 12 18:40:52 2017<br class="">
> @@ -29,7 +29,6 @@ MacroInfo::MacroInfo(<wbr class="">SourceLocation DefL<br class="">
> IsUsed(false),<br class="">
> IsAllowRedefinitionsWithoutWar<wbr class="">ning(false),<br class="">
> IsWarnIfUnused(false),<br class="">
> - FromASTFile(false),<br class="">
> UsedForHeaderGuard(false) {<br class="">
> }<br class="">
><br class="">
> @@ -137,7 +136,6 @@ LLVM_DUMP_METHOD void MacroInfo::dump()<br class="">
> if (<wbr class="">IsAllowRedefinitionsWithoutWar<wbr class="">ning)<br class="">
> Out << " allow_redefinitions_without_<wbr class="">warning";<br class="">
> if (IsWarnIfUnused) Out << " warn_if_unused";<br class="">
> - if (FromASTFile) Out << " imported";<br class="">
> if (UsedForHeaderGuard) Out << " header_guard";<br class="">
><br class="">
> Out << "\n #define <macro>";<br class="">
><br class="">
> Modified: cfe/trunk/lib/Lex/<wbr class="">PPDirectives.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/cfe/trunk/lib/Lex/<wbr class="">PPDirectives.cpp?rev=302966&<wbr class="">r1=302965&r2=302966&view=diff</a><br class="">
> ==============================<wbr class="">==============================<wbr class="">==================<br class="">
> --- cfe/trunk/lib/Lex/<wbr class="">PPDirectives.cpp (original)<br class="">
> +++ cfe/trunk/lib/Lex/<wbr class="">PPDirectives.cpp Fri May 12 18:40:52 2017<br class="">
> @@ -54,35 +54,12 @@ using namespace clang;<br class="">
> // Utility Methods for Preprocessor Directive Handling.<br class="">
> //===-------------------------<wbr class="">------------------------------<wbr class="">---------------===//<br class="">
><br class="">
> -MacroInfo *Preprocessor::<wbr class="">AllocateMacroInfo() {<br class="">
> - MacroInfoChain *MIChain = BP.Allocate<MacroInfoChain>();<br class="">
> - MIChain->Next = MIChainHead;<br class="">
> +MacroInfo *Preprocessor::<wbr class="">AllocateMacroInfo(<wbr class="">SourceLocation L) {<br class="">
> + auto *MIChain = new (BP) MacroInfoChain{L, MIChainHead};<br class="">
> MIChainHead = MIChain;<br class="">
> return &MIChain->MI;<br class="">
> }<br class="">
><br class="">
> -MacroInfo *Preprocessor::<wbr class="">AllocateMacroInfo(<wbr class="">SourceLocation L) {<br class="">
> - MacroInfo *MI = AllocateMacroInfo();<br class="">
> - new (MI) MacroInfo(L);<br class="">
> - return MI;<br class="">
> -}<br class="">
> -<br class="">
> -MacroInfo *Preprocessor::<wbr class="">AllocateDeserializedMacroInfo(<wbr class="">SourceLocation L,<br class="">
> - unsigned SubModuleID) {<br class="">
> - static_assert(alignof(<wbr class="">MacroInfo) >= sizeof(SubModuleID),<br class="">
> - "alignment for MacroInfo is less than the ID");<br class="">
> - DeserializedMacroInfoChain *MIChain =<br class="">
> - BP.Allocate<<wbr class="">DeserializedMacroInfoChain>();<br class="">
> - MIChain->Next = DeserialMIChainHead;<br class="">
> - DeserialMIChainHead = MIChain;<br class="">
> -<br class="">
> - MacroInfo *MI = &MIChain->MI;<br class="">
> - new (MI) MacroInfo(L);<br class="">
> - MI->FromASTFile = true;<br class="">
> - MI->setOwningModuleID(<wbr class="">SubModuleID);<br class="">
> - return MI;<br class="">
> -}<br class="">
> -<br class="">
> DefMacroDirective *Preprocessor::<wbr class="">AllocateDefMacroDirective(<wbr class="">MacroInfo *MI,<br class="">
> SourceLocation Loc) {<br class="">
> return new (BP) DefMacroDirective(MI, Loc);<br class="">
><br class="">
> Modified: cfe/trunk/lib/Lex/<wbr class="">Preprocessor.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/cfe/trunk/lib/Lex/<wbr class="">Preprocessor.cpp?rev=302966&<wbr class="">r1=302965&r2=302966&view=diff</a><br class="">
> ==============================<wbr class="">==============================<wbr class="">==================<br class="">
> --- cfe/trunk/lib/Lex/<wbr class="">Preprocessor.cpp (original)<br class="">
> +++ cfe/trunk/lib/Lex/<wbr class="">Preprocessor.cpp Fri May 12 18:40:52 2017<br class="">
> @@ -88,7 +88,7 @@ Preprocessor::Preprocessor(<wbr class="">std::shared_p<br class="">
> CurDirLookup(nullptr), CurLexerKind(CLK_Lexer),<br class="">
> CurLexerSubmodule(nullptr), Callbacks(nullptr),<br class="">
> CurSubmoduleState(&<wbr class="">NullSubmoduleState), MacroArgCache(nullptr),<br class="">
> - Record(nullptr), MIChainHead(nullptr), DeserialMIChainHead(nullptr) {<br class="">
> + Record(nullptr), MIChainHead(nullptr) {<br class="">
> OwnsHeaderSearch = OwnsHeaders;<br class="">
><br class="">
> CounterValue = 0; // __COUNTER__ starts at 0.<br class="">
> @@ -169,11 +169,6 @@ Preprocessor::~Preprocessor() {<br class="">
> std::fill(TokenLexerCache, TokenLexerCache + NumCachedTokenLexers, nullptr);<br class="">
> CurTokenLexer.reset();<br class="">
><br class="">
> - while (DeserializedMacroInfoChain *I = DeserialMIChainHead) {<br class="">
> - DeserialMIChainHead = I->Next;<br class="">
> - I->~<wbr class="">DeserializedMacroInfoChain();<br class="">
> - }<br class="">
> -<br class="">
> // Free any cached MacroArgs.<br class="">
> for (MacroArgs *ArgList = MacroArgCache; ArgList;)<br class="">
> ArgList = ArgList->deallocate();<br class="">
><br class="">
> Modified: cfe/trunk/lib/Serialization/<wbr class="">ASTReader.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/cfe/trunk/lib/<wbr class="">Serialization/ASTReader.cpp?<wbr class="">rev=302966&r1=302965&r2=<wbr class="">302966&view=diff</a><br class="">
> ==============================<wbr class="">==============================<wbr class="">==================<br class="">
> --- cfe/trunk/lib/Serialization/<wbr class="">ASTReader.cpp (original)<br class="">
> +++ cfe/trunk/lib/Serialization/<wbr class="">ASTReader.cpp Fri May 12 18:40:52 2017<br class="">
> @@ -1534,9 +1534,8 @@ MacroInfo *ASTReader::ReadMacroRecord(Mo<br class="">
> return Macro;<br class="">
><br class="">
> unsigned NextIndex = 1; // Skip identifier ID.<br class="">
> - SubmoduleID SubModID = getGlobalSubmoduleID(F, Record[NextIndex++]);<br class="">
> SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex);<br class="">
> - MacroInfo *MI = PP.<wbr class="">AllocateDeserializedMacroInfo(<wbr class="">Loc, SubModID);<br class="">
> + MacroInfo *MI = PP.AllocateMacroInfo(Loc);<br class="">
> MI->setDefinitionEndLoc(<wbr class="">ReadSourceLocation(F, Record, NextIndex));<br class="">
> MI->setIsUsed(Record[<wbr class="">NextIndex++]);<br class="">
> MI->setUsedForHeaderGuard(<wbr class="">Record[NextIndex++]);<br class="">
><br class="">
> Modified: cfe/trunk/lib/Serialization/<wbr class="">ASTWriter.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/cfe/trunk/lib/<wbr class="">Serialization/ASTWriter.cpp?<wbr class="">rev=302966&r1=302965&r2=<wbr class="">302966&view=diff</a><br class="">
> ==============================<wbr class="">==============================<wbr class="">==================<br class="">
> --- cfe/trunk/lib/Serialization/<wbr class="">ASTWriter.cpp (original)<br class="">
> +++ cfe/trunk/lib/Serialization/<wbr class="">ASTWriter.cpp Fri May 12 18:40:52 2017<br class="">
> @@ -2413,7 +2413,6 @@ void ASTWriter::WritePreprocessor(<wbr class="">const<br class="">
> }<br class="">
><br class="">
> AddIdentifierRef(Name, Record);<br class="">
> - Record.push_back(<wbr class="">inferSubmoduleIDFromLocation(<wbr class="">MI->getDefinitionLoc()));<br class="">
> AddSourceLocation(MI-><wbr class="">getDefinitionLoc(), Record);<br class="">
> AddSourceLocation(MI-><wbr class="">getDefinitionEndLoc(), Record);<br class="">
> Record.push_back(MI->isUsed())<wbr class="">;<br class="">
><br class="">
><br class="">
> ______________________________<wbr class="">_________________<br class="">
> cfe-commits mailing list<br class="">
> <a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a><br class="">
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/cfe-commits</a><br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
cfe-commits mailing list<br class="">
<a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/cfe-commits</a><br class="">
</div></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>