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

[RemoveDIs] Load into new debug info format by default in LLVM #89799

Merged
merged 5 commits into from
May 1, 2024

Conversation

SLTozer
Copy link
Contributor

@SLTozer SLTozer commented Apr 23, 2024

This patch enables parsing and creating modules directly into the new debug info format. Prior to this patch, all modules were constructed with the old debug info format by default, and would be converted into the new format just before running LLVM passes. This is an important milestone, in that this means that every tool will now be exposed to debug records, rather than those that run LLVM passes. As far as I've tested, all LLVM tools/projects now either handle debug records, or convert them to the old intrinsic format.

There are a few unit tests that need updating for this patch; these are either cases of tests that previously needed to set the debug info format to function, or tests that depend on the old debug info format in some way. There should be no visible change in the output of any LLVM tool as a result of this patch, although the likelihood of this patch breaking downstream code means an NFC tag might be a little misleading, if not technically incorrect:

This will probably break some downstream tools that don't already handle debug records. If your downstream code breaks as a result of this change, the simplest fix is to convert the module in question to the old debug format before you process it, using Module::convertFromNewDbgValues(). For more information about how to handle debug records or about what has changed, see the migration document:
https://llvm.org/docs/RemoveDIsDebugInfo.html

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 23, 2024

@llvm/pr-subscribers-llvm-analysis
@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-debuginfo

Author: Stephen Tozer (SLTozer)

Changes

This patch enables parsing and creating modules directly into the new debug info format. Prior to this patch, all modules were constructed with the old debug info format by default, and would be converted into the new format just before running LLVM passes. This is an important milestone, in that this means that every tool will now be exposed to debug records, rather than those that run LLVM passes. As far as I've tested, all LLVM tools/projects now either handle debug records, or convert them to the old intrinsic format.

There are a few unit tests that need updating for this patch; these are either cases of tests that previously needed to set the debug info format to function, or tests that depend on the old debug info format in some way. There should be no visible change in the output of any LLVM tool as a result of this patch, although the likelihood of this patch breaking downstream code means an NFC tag might be a little misleading, if not technically incorrect:

This will probably break some downstream tools that don't already handle debug records. If your downstream code breaks as a result of this change, the simplest fix is to convert the module in question to the old debug format before you process it, using Module::convertFromNewDbgValues(). For more information about how to handle debug records or about what has changed, see the migration document:
https://llvm.org/docs/RemoveDIsDebugInfo.html


Patch is 25.57 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/89799.diff

15 Files Affected:

  • (modified) llvm/include/llvm/AsmParser/LLParser.h (-1)
  • (modified) llvm/lib/AsmParser/LLParser.cpp (+16-18)
  • (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+1-1)
  • (modified) llvm/lib/IR/BasicBlock.cpp (+1-1)
  • (modified) llvm/lib/IR/Function.cpp (+3-1)
  • (modified) llvm/lib/IR/Module.cpp (+3-1)
  • (modified) llvm/tools/llvm-as/llvm-as.cpp (+3-4)
  • (modified) llvm/tools/llvm-dis/llvm-dis.cpp (+1-1)
  • (modified) llvm/tools/llvm-link/llvm-link.cpp (+1-7)
  • (modified) llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp (+32)
  • (modified) llvm/unittests/IR/BasicBlockDbgInfoTest.cpp (-17)
  • (modified) llvm/unittests/IR/DebugInfoTest.cpp (+8-7)
  • (modified) llvm/unittests/IR/InstructionsTest.cpp (+5)
  • (modified) llvm/unittests/Transforms/Utils/CloningTest.cpp (+3-2)
  • (modified) llvm/unittests/Transforms/Utils/LocalTest.cpp (+55)
diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h
index b2dcdfad0a04b4..e687254f6c4c70 100644
--- a/llvm/include/llvm/AsmParser/LLParser.h
+++ b/llvm/include/llvm/AsmParser/LLParser.h
@@ -337,7 +337,6 @@ namespace llvm {
 
     // Top-Level Entities
     bool parseTopLevelEntities();
-    bool finalizeDebugInfoFormat(Module *M);
     void dropUnknownMetadataReferences();
     bool validateEndOfModule(bool UpgradeDebugInfo);
     bool validateEndOfIndex();
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 2902bd9fe17c48..34053a5ca9c8e8 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -74,23 +74,6 @@ static std::string getTypeString(Type *T) {
   return Tmp.str();
 }
 
-// Whatever debug info format we parsed, we should convert to the expected debug
-// info format immediately afterwards.
-bool LLParser::finalizeDebugInfoFormat(Module *M) {
-  // We should have already returned an error if we observed both intrinsics and
-  // records in this IR.
-  assert(!(SeenNewDbgInfoFormat && SeenOldDbgInfoFormat) &&
-         "Mixed debug intrinsics/records seen without a parsing error?");
-  if (PreserveInputDbgFormat == cl::boolOrDefault::BOU_TRUE) {
-    UseNewDbgInfoFormat = SeenNewDbgInfoFormat;
-    WriteNewDbgInfoFormatToBitcode = SeenNewDbgInfoFormat;
-    WriteNewDbgInfoFormat = SeenNewDbgInfoFormat;
-  } else if (M) {
-    M->setIsNewDbgInfoFormat(false);
-  }
-  return false;
-}
-
 /// Run: module ::= toplevelentity*
 bool LLParser::Run(bool UpgradeDebugInfo,
                    DataLayoutCallbackTy DataLayoutCallback) {
@@ -108,7 +91,7 @@ bool LLParser::Run(bool UpgradeDebugInfo,
   }
 
   return parseTopLevelEntities() || validateEndOfModule(UpgradeDebugInfo) ||
-         validateEndOfIndex() || finalizeDebugInfoFormat(M);
+         validateEndOfIndex();
 }
 
 bool LLParser::parseStandaloneConstantValue(Constant *&C,
@@ -207,6 +190,18 @@ void LLParser::dropUnknownMetadataReferences() {
 bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
   if (!M)
     return false;
+
+  // We should have already returned an error if we observed both intrinsics and
+  // records in this IR.
+  assert(!(SeenNewDbgInfoFormat && SeenOldDbgInfoFormat) &&
+         "Mixed debug intrinsics/records seen without a parsing error?");
+  if (PreserveInputDbgFormat == cl::boolOrDefault::BOU_TRUE) {
+    UseNewDbgInfoFormat = SeenNewDbgInfoFormat;
+    WriteNewDbgInfoFormatToBitcode = SeenNewDbgInfoFormat;
+    WriteNewDbgInfoFormat = SeenNewDbgInfoFormat;
+    M->setNewDbgInfoFormatFlag(SeenNewDbgInfoFormat);
+  }
+
   // Handle any function attribute group forward references.
   for (const auto &RAG : ForwardRefAttrGroups) {
     Value *V = RAG.first;
@@ -439,6 +434,9 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
   UpgradeModuleFlags(*M);
   UpgradeSectionAttributes(*M);
 
+  if (PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE)
+    M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat);
+
   if (!Slots)
     return false;
   // Initialize the slot mapping.
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 0b7fcd88418894..73fe63b5b8f6f7 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -4319,7 +4319,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
   if (PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE) {
     TheModule->IsNewDbgInfoFormat =
         UseNewDbgInfoFormat &&
-        LoadBitcodeIntoNewDbgInfoFormat == cl::boolOrDefault::BOU_TRUE;
+        LoadBitcodeIntoNewDbgInfoFormat != cl::boolOrDefault::BOU_FALSE;
   }
 
   this->ValueTypeCallback = std::move(Callbacks.ValueType);
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 6e62767c99e2a2..73595dbe280be8 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -181,7 +181,7 @@ template class llvm::SymbolTableListTraits<Instruction,
 BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
                        BasicBlock *InsertBefore)
     : Value(Type::getLabelTy(C), Value::BasicBlockVal),
-      IsNewDbgInfoFormat(false), Parent(nullptr) {
+      IsNewDbgInfoFormat(UseNewDbgInfoFormat), Parent(nullptr) {
 
   if (NewParent)
     insertInto(NewParent, InsertBefore);
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index e66fe73425e863..823e4a70dd9b7e 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -83,6 +83,8 @@ static cl::opt<unsigned> NonGlobalValueMaxNameSize(
     "non-global-value-max-name-size", cl::Hidden, cl::init(1024),
     cl::desc("Maximum size for the name of non-global values."));
 
+extern cl::opt<bool> UseNewDbgInfoFormat;
+
 void Function::convertToNewDbgValues() {
   IsNewDbgInfoFormat = true;
   for (auto &BB : *this) {
@@ -438,7 +440,7 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
     : GlobalObject(Ty, Value::FunctionVal,
                    OperandTraits<Function>::op_begin(this), 0, Linkage, name,
                    computeAddrSpace(AddrSpace, ParentModule)),
-      NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(false) {
+      NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
   assert(FunctionType::isValidReturnType(getReturnType()) &&
          "invalid return type");
   setGlobalObjectSubClassData(0);
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index a8696ed9e3ce5d..915fa5097383cc 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -54,6 +54,8 @@
 
 using namespace llvm;
 
+extern cl::opt<bool> UseNewDbgInfoFormat;
+
 //===----------------------------------------------------------------------===//
 // Methods to implement the globals and functions lists.
 //
@@ -72,7 +74,7 @@ template class llvm::SymbolTableListTraits<GlobalIFunc>;
 Module::Module(StringRef MID, LLVMContext &C)
     : Context(C), ValSymTab(std::make_unique<ValueSymbolTable>(-1)),
       ModuleID(std::string(MID)), SourceFileName(std::string(MID)), DL(""),
-      IsNewDbgInfoFormat(false) {
+      IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
   Context.addModule(this);
 }
 
diff --git a/llvm/tools/llvm-as/llvm-as.cpp b/llvm/tools/llvm-as/llvm-as.cpp
index e48e3f4d22c123..0958e16c2197ac 100644
--- a/llvm/tools/llvm-as/llvm-as.cpp
+++ b/llvm/tools/llvm-as/llvm-as.cpp
@@ -142,11 +142,10 @@ int main(int argc, char **argv) {
   }
 
   // Convert to new debug format if requested.
-  assert(!M->IsNewDbgInfoFormat && "Unexpectedly in new debug mode");
-  if (UseNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode) {
-    M->convertToNewDbgValues();
+  M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat &&
+                           WriteNewDbgInfoFormatToBitcode);
+  if (M->IsNewDbgInfoFormat)
     M->removeDebugIntrinsicDeclarations();
-  }
 
   std::unique_ptr<ModuleSummaryIndex> Index = std::move(ModuleAndIndex.Index);
 
diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp
index fbbb5506e43e05..d28af85bc739eb 100644
--- a/llvm/tools/llvm-dis/llvm-dis.cpp
+++ b/llvm/tools/llvm-dis/llvm-dis.cpp
@@ -258,7 +258,7 @@ int main(int argc, char **argv) {
       // All that llvm-dis does is write the assembly to a file.
       if (!DontPrint) {
         if (M) {
-          ScopedDbgInfoFormatSetter FormatSetter(*M, WriteNewDbgInfoFormat);
+          M->setIsNewDbgInfoFormat(WriteNewDbgInfoFormat);
           if (WriteNewDbgInfoFormat)
             M->removeDebugIntrinsicDeclarations();
           M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder);
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index 7794f2d81ed064..b84469d1c757f8 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -489,12 +489,6 @@ int main(int argc, char **argv) {
   if (LoadBitcodeIntoNewDbgInfoFormat == cl::boolOrDefault::BOU_UNSET)
     LoadBitcodeIntoNewDbgInfoFormat = cl::boolOrDefault::BOU_TRUE;
 
-  // RemoveDIs debug-info transition: tests may request that we /try/ to use the
-  // new debug-info format.
-  if (TryUseNewDbgInfoFormat) {
-    // Turn the new debug-info format on.
-    UseNewDbgInfoFormat = true;
-  }
   // Since llvm-link collects multiple IR modules together, for simplicity's
   // sake we disable the "PreserveInputDbgFormat" flag to enforce a single
   // debug info format.
@@ -556,7 +550,7 @@ int main(int argc, char **argv) {
     SetFormat(WriteNewDbgInfoFormat);
     Composite->print(Out.os(), nullptr, PreserveAssemblyUseListOrder);
   } else if (Force || !CheckBitcodeOutputToConsole(Out.os())) {
-    SetFormat(WriteNewDbgInfoFormatToBitcode);
+    SetFormat(UseNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode);
     WriteBitcodeToFile(*Composite, Out.os(), PreserveBitcodeUseListOrder);
   }
 
diff --git a/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp b/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp
index f6a053792f8529..69ea590945668e 100644
--- a/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp
+++ b/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/IRSimilarityIdentifier.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/AsmParser/Parser.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
@@ -22,6 +23,27 @@
 using namespace llvm;
 using namespace IRSimilarity;
 
+extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
+extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;
+extern bool WriteNewDbgInfoFormatToBitcode;
+extern cl::opt<bool> WriteNewDbgInfoFormat;
+
+// Backup all of the existing settings that may be modified when
+// PreserveInputDbgFormat=true, so that when the test is finished we return them
+// (and the "preserve" setting) to their original values.
+auto TempSettingChange() {
+  return make_scope_exit(
+      [OldPreserveInputDbgFormat = PreserveInputDbgFormat.getValue(),
+       OldUseNewDbgInfoFormat = UseNewDbgInfoFormat.getValue(),
+       OldWriteNewDbgInfoFormatToBitcode = WriteNewDbgInfoFormatToBitcode,
+       OldWriteNewDbgInfoFormat = WriteNewDbgInfoFormat.getValue()] {
+        PreserveInputDbgFormat = OldPreserveInputDbgFormat;
+        UseNewDbgInfoFormat = OldUseNewDbgInfoFormat;
+        WriteNewDbgInfoFormatToBitcode = OldWriteNewDbgInfoFormatToBitcode;
+        WriteNewDbgInfoFormat = OldWriteNewDbgInfoFormat;
+      });
+}
+
 static std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context,
                                               StringRef ModuleStr) {
   SMDiagnostic Err;
@@ -1308,6 +1330,9 @@ TEST(IRInstructionMapper, CallBrInstIllegal) {
 
 // Checks that an debuginfo intrinsics are mapped to be invisible.  Since they
 // do not semantically change the program, they can be recognized as similar.
+// FIXME: PreserveInputDbgFormat is set to true because this test contains
+// malformed debug info that cannot be converted to the new debug info format;
+// this test should be updated later to use valid debug info.
 TEST(IRInstructionMapper, DebugInfoInvisible) {
   StringRef ModuleString = R"(
                           define i32 @f(i32 %a, i32 %b) {
@@ -1320,6 +1345,8 @@ TEST(IRInstructionMapper, DebugInfoInvisible) {
 
                           declare void @llvm.dbg.value(metadata)
                           !0 = distinct !{!"test\00", i32 10})";
+  auto SettingGuard = TempSettingChange();
+  PreserveInputDbgFormat = cl::boolOrDefault::BOU_TRUE;
   LLVMContext Context;
   std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
 
@@ -1916,6 +1943,9 @@ TEST(IRSimilarityCandidate, CheckRegionsDifferentTypes) {
 
 // Check that debug instructions do not impact similarity. They are marked as
 // invisible.
+// FIXME: PreserveInputDbgFormat is set to true because this test contains
+// malformed debug info that cannot be converted to the new debug info format;
+// this test should be updated later to use valid debug info.
 TEST(IRSimilarityCandidate, IdenticalWithDebug) {
   StringRef ModuleString = R"(
                           define i32 @f(i32 %a, i32 %b) {
@@ -1938,6 +1968,8 @@ TEST(IRSimilarityCandidate, IdenticalWithDebug) {
                           declare void @llvm.dbg.value(metadata)
                           !0 = distinct !{!"test\00", i32 10}
                           !1 = distinct !{!"test\00", i32 11})";
+  auto SettingGuard = TempSettingChange();
+  PreserveInputDbgFormat = cl::boolOrDefault::BOU_TRUE;
   LLVMContext Context;
   std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
 
diff --git a/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp b/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
index 905928819dda80..cea0e6fd852a39 100644
--- a/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
+++ b/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
@@ -72,8 +72,6 @@ TEST(BasicBlockDbgInfoTest, InsertAfterSelf) {
     !11 = !DILocation(line: 1, column: 1, scope: !6)
 )");
 
-  // Convert the module to "new" form debug-info.
-  M->convertToNewDbgValues();
   // Fetch the entry block.
   BasicBlock &BB = M->getFunction("f")->getEntryBlock();
 
@@ -104,8 +102,6 @@ TEST(BasicBlockDbgInfoTest, InsertAfterSelf) {
   auto Range2 = RetInst->getDbgRecordRange();
   EXPECT_EQ(std::distance(Range2.begin(), Range2.end()), 1u);
 
-  M->convertFromNewDbgValues();
-
   UseNewDbgInfoFormat = false;
 }
 
@@ -140,8 +136,6 @@ TEST(BasicBlockDbgInfoTest, MarkerOperations) {
 
   // Fetch the entry block,
   BasicBlock &BB = M->getFunction("f")->getEntryBlock();
-  // Convert the module to "new" form debug-info.
-  M->convertToNewDbgValues();
   EXPECT_EQ(BB.size(), 2u);
 
   // Fetch out our two markers,
@@ -276,8 +270,6 @@ TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
   // Test that the movement of debug-data when using moveBefore etc and
   // insertBefore etc are governed by the "head" bit of iterators.
   BasicBlock &BB = M->getFunction("f")->getEntryBlock();
-  // Convert the module to "new" form debug-info.
-  M->convertToNewDbgValues();
 
   // Test that the head bit behaves as expected: it should be set when the
   // code wants the _start_ of the block, but not otherwise.
@@ -385,8 +377,6 @@ TEST(BasicBlockDbgInfoTest, InstrDbgAccess) {
   // Check that DbgVariableRecords can be accessed from Instructions without
   // digging into the depths of DbgMarkers.
   BasicBlock &BB = M->getFunction("f")->getEntryBlock();
-  // Convert the module to "new" form debug-info.
-  M->convertToNewDbgValues();
 
   Instruction *BInst = &*BB.begin();
   Instruction *CInst = BInst->getNextNode();
@@ -523,7 +513,6 @@ class DbgSpliceTest : public ::testing::Test {
   void SetUp() override {
     UseNewDbgInfoFormat = true;
     M = parseIR(C, SpliceTestIR.c_str());
-    M->convertToNewDbgValues();
 
     BBEntry = &M->getFunction("f")->getEntryBlock();
     BBExit = BBEntry->getNextNode();
@@ -1163,7 +1152,6 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceTrailing) {
 
   BasicBlock &Entry = M->getFunction("f")->getEntryBlock();
   BasicBlock &Exit = *Entry.getNextNode();
-  M->convertToNewDbgValues();
 
   // Begin by forcing entry block to have dangling DbgVariableRecord.
   Entry.getTerminator()->eraseFromParent();
@@ -1217,7 +1205,6 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsert) {
 )");
 
   BasicBlock &Entry = M->getFunction("f")->getEntryBlock();
-  M->convertToNewDbgValues();
 
   // Fetch the relevant instructions from the converted function.
   Instruction *SubInst = &*Entry.begin();
@@ -1296,7 +1283,6 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsertForOneDbgVariableRecord) {
 )");
 
   BasicBlock &Entry = M->getFunction("f")->getEntryBlock();
-  M->convertToNewDbgValues();
 
   // Fetch the relevant instructions from the converted function.
   Instruction *SubInst = &*Entry.begin();
@@ -1380,7 +1366,6 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty1) {
   Function &F = *M->getFunction("f");
   BasicBlock &Entry = F.getEntryBlock();
   BasicBlock &Exit = *Entry.getNextNode();
-  M->convertToNewDbgValues();
 
   // Begin by forcing entry block to have dangling DbgVariableRecord.
   Entry.getTerminator()->eraseFromParent();
@@ -1450,7 +1435,6 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty2) {
   Function &F = *M->getFunction("f");
   BasicBlock &Entry = F.getEntryBlock();
   BasicBlock &Exit = *Entry.getNextNode();
-  M->convertToNewDbgValues();
 
   // Begin by forcing entry block to have dangling DbgVariableRecord.
   Entry.getTerminator()->eraseFromParent();
@@ -1520,7 +1504,6 @@ TEST(BasicBlockDbgInfoTest, DbgMoveToEnd) {
   Function &F = *M->getFunction("f");
   BasicBlock &Entry = F.getEntryBlock();
   BasicBlock &Exit = *Entry.getNextNode();
-  M->convertToNewDbgValues();
 
   // Move the return to the end of the entry block.
   Instruction *Br = Entry.getTerminator();
diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp
index d06b979bf4a1c4..2e75384c67b063 100644
--- a/llvm/unittests/IR/DebugInfoTest.cpp
+++ b/llvm/unittests/IR/DebugInfoTest.cpp
@@ -237,6 +237,9 @@ TEST(DbgVariableIntrinsic, EmptyMDIsKillLocation) {
 // Duplicate of above test, but in DbgVariableRecord representation.
 TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) {
   LLVMContext C;
+  bool OldDbgValueMode = UseNewDbgInfoFormat;
+  UseNewDbgInfoFormat = true;
+
   std::unique_ptr<Module> M = parseIR(C, R"(
     define i16 @f(i16 %a) !dbg !6 {
       %b = add i16 %a, 1, !dbg !11
@@ -262,10 +265,7 @@ TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) {
     !11 = !DILocation(line: 1, column: 1, scope: !6)
 )");
 
-  bool OldDbgValueMode = UseNewDbgInfoFormat;
-  UseNewDbgInfoFormat = true;
   Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI();
-  M->convertToNewDbgValues();
 
   // Find the DbgVariableRecords using %b.
   SmallVector<DbgValueInst *, 2> DVIs;
@@ -1044,10 +1044,6 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
 TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
   LLVMContext C;
 
-  // For the purpose of this test, set and un-set the command line option
-  // corresponding to UseNewDbgInfoFormat.
-  UseNewDbgInfoFormat = true;
-
   std::unique_ptr<Module> M = parseIR(C, R"(
     define i16 @f(i16 %a) !dbg !6 {
       call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11
@@ -1077,6 +1073,11 @@ TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
     !11 = !DILocation(line: 1, column: 1, scope: !6)
 )");
 
+  // For the purpose of this test, set and un-set the command line option
+  // corresponding to UseNewDbgInfoFormat, but only after parsing, to ensure
+  // that the IR starts off in the old format.
+  UseNewDbgInfoFormat = true;
+
   // Check that the conversion routines and utilities between dbg.value
   // debug-info format and DbgVariableRecords works.
   Function *F = M->getFunction("f");
diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp
index b47c73f0b329ae..6c4debf4dbec8c 100644
--- a/llvm/unittests/IR/InstructionsTest.cpp
+++ b/llvm/unittests/IR/InstructionsTest.cpp
@@ -31,6 +31,8 @@
 #include "gtest/gtest.h"
 #include <memory>
 
+extern llvm::cl::opt<llvm::cl::boolOrDefault> PreserveInputDbgFormat;
+
 namespace llvm {
 namespace {
 
@@ -1460,6 +1462,8 @@ TEST(InstructionsTest, GetSplat) {
 
 TEST(InstructionsTest, SkipDebug) {
   LLVMContext C;
+  cl::boolOrDefault OldDbgFormat = PreserveInputDbgFormat;
+  PreserveInputDbgFormat = cl::boolOrDefault::BOU_TRUE;
   std::unique_ptr<Module> M = parseIR(C,
                                       R"(
       declare void @llvm.dbg.value(metadata, metadata, metadata)
@@ -1495,6 +1499,7 @@ TEST(InstructionsTest, SkipDebug) {
 
   // After the terminator, there are no non-debug instructions.
   EXPECT_EQ(nullptr, Term->getNextNonDebugInstruction());
+  PreserveInputDbgFormat = OldDbgFormat;
 }
 
 TEST(InstructionsTest, PhiMightNotBeFPMathOperator) {
diff --git a/llvm/unittests/Transforms/Utils/CloningTest.cpp b/llvm/unittests/Transforms/Utils/CloningTest.cpp
index 025771f07ce5d4..6f4e860d604680 100644
--- a/llvm/unittests/Transforms/Utils/CloningTest.cpp
+++ b/llvm/unittests/Transforms/Utils/CloningTest.cpp
@@ -844,8 +844,9 @@ TEST(CloneFunction, CloneFunctionWithInlinedSubprograms) {
   EXPECT_FA...
[truncated]

Copy link
Contributor

@OCHyams OCHyams left a comment

Choose a reason for hiding this comment

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

LGTM-ish. Overall looks good, and is an important and exciting milestone indeed!

There's not many of them, but I'm worried about the loss of test coverage between this landing and the tests with FIXMEs getting fixed up. Fixing them up will cause some coverage loss for debug intrinsics, but IMO the primary / default mode should have the better coverage.

I don't think changing these few test alone is enough to suggest that debug intrinsic support is at all unsupported yet, but I think it brings us closer to the point where we need to consider telling people that debug intrinsic support is winding down. We should probably look at the opaque pointer transition - I may be misremembering but IIRC there was a release where typed pointers existed but they had limited testing / support. Ah yep,

LLVM 16: Opaque pointers are enabled by default. Typed pointers are supported on a best-effort basis only and not tested.

https://llvm.org/docs/OpaquePointers.html

Do you have a plan for those FIXME tests? I'm happy to take a look at fixing those up as a patch to land immediately after this one.

// Backup all of the existing settings that may be modified when
// PreserveInputDbgFormat=true, so that when the test is finished we return them
// (and the "preserve" setting) to their original values.
auto TempSettingChange() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: static?
double bit: Can we give this a more specific name, e.g. "SaveDbgInfoFormat" or something similar?

llvm/unittests/IR/DebugInfoTest.cpp Show resolved Hide resolved
// Backup all of the existing settings that may be modified when
// PreserveInputDbgFormat=true, so that when the test is finished we return them
// (and the "preserve" setting) to their original values.
auto TempSettingChange() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should be shared somewhere? Maybe not necessary for this - depends if there's any common unit test header you can use? Then you could use it in the other tests too rather then manually saving and restoring
PreserveInputDbgFormat etc. YMMV. Please apply static and the rename mentioned at the other instance of this function either way.

EDIT: This doesn't matter much if we're going to fix up the tests immediately.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore the above, the usage in this file gets removed in #90476 anyway.

Comment on lines 629 to 631
// FIXME: PreserveInputDbgFormat is set to true because this test has
// been written to expect debug intrinsics rather than debug records; use the
// intrinsic format until we update the test checks.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd argue this test doesn't make sense for DbgRecords at all, and the comment should say something along the lines of "TODO: Remove when debug intrinsics are fully removed".

@@ -1284,6 +1334,11 @@ TEST(Local, ExpressionForConstant) {

TEST(Local, ReplaceDbgVariableRecord) {
LLVMContext C;
// FIXME: PreserveInputDbgFormat is set to true because this test has
// been written to expect debug intrinsics rather than debug records; use the
// intrinsic format until we update the test checks.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's probably value in leaving this test as-is until debug intrinscs are completely removed, as not only does it test that DbgVariableRecord RAUW works, but it gives us the additional coverage that it works after converting from debug intrinsics, which is worth something IMO. Could you adjust this comment to reflect that if you agree?

Copy link
Contributor Author

@SLTozer SLTozer Apr 29, 2024

Choose a reason for hiding this comment

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

I think that with the approach described above, where we only support intrinsics on a best-effort basis, maintaining the convert-from-intrinsic component seems unnecessary to me - but I don't mind leaving this test as-is until intrinsics are fully removed. I don't see the specific argument for maintaining the conversion coverage here (rather than testing conversion on its own), but if you think it'd be good then I'm happy to leave it in without further justification, since it's essentially 0 cost to maintain.

@jryans
Copy link
Member

jryans commented Apr 25, 2024

Should this change (or another one happening soon) mention the new debug info format in the release notes?

Copy link
Contributor

@OCHyams OCHyams left a comment

Choose a reason for hiding this comment

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

Once my inline comments are addressed I'm happy to approve this - I've converted the FIXME-tests that can/should be upgraded in #90476, which can land after this does.

// Backup all of the existing settings that may be modified when
// PreserveInputDbgFormat=true, so that when the test is finished we return them
// (and the "preserve" setting) to their original values.
auto TempSettingChange() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore the above, the usage in this file gets removed in #90476 anyway.

@dwblaikie
Copy link
Collaborator

Should this change (or another one happening soon) mention the new debug info format in the release notes?

+1 to this

@SLTozer
Copy link
Contributor Author

SLTozer commented Apr 30, 2024

Updated some of the tests according to the review comments, except for the comments that are resolved in #90476. Also added some release notes - I added them to the "debug info" section, but it wasn't clear to me whether that refers to debug info in LLVM's IR (superseding the "LLVM IR" category for debug-info-specific topics), or just debug info produced in objects built by LLVM.

Copy link
Contributor

@OCHyams OCHyams left a comment

Choose a reason for hiding this comment

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

Code / test changes LGTM

I'll leave it to @dwblaikie or @jryans to Accept if you're happy with the release notes situation.

records. This should happen transparently when using the DIBuilder to
construct debug variable information, but will require changes for any code
that interacts with debug intrinsics directly; for more information, see the
`migration docs <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to mention that testing for debug intrinsics will be best-effort going forward (/soon)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That should probably be in the migration docs as well, but it makes sense to put it here.

Copy link
Member

@jryans jryans left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for working on this! 😄

@SLTozer SLTozer merged commit 2f01fd9 into llvm:main May 1, 2024
4 of 5 checks passed
SLTozer added a commit that referenced this pull request May 1, 2024
@SLTozer
Copy link
Contributor Author

SLTozer commented May 2, 2024

Following the failed merge, there's a small functional change and a number of trivial unit test updates needed to fix the patch - since I can't reopen the review, the commit containing the changes is here: SLTozer@a8fed21

Anyone able to eyeball it and give reapproval?

@jryans
Copy link
Member

jryans commented May 2, 2024

Additional commit looks good to me. 🙂

@OCHyams
Copy link
Contributor

OCHyams commented May 2, 2024

Additional commit looks good to me. 🙂

+1

I'd consider splitting up the return condition in DbgVariableRecord::isKillLocation into multiple returns, but ymmv, fine either way.

SLTozer added a commit that referenced this pull request May 2, 2024
…VM (#89799)"

Fixes the broken tests in the original commit:
  2f01fd9

This will probably break some downstream tools that don't already handle
debug records. If your downstream code breaks as a result of this
change, the simplest fix is to convert the module in question to the old
debug format before you process it, using
`Module::convertFromNewDbgValues()`. For more information about how to
handle debug records or about what has changed, see the migration
document:
  https://llvm.org/docs/RemoveDIsDebugInfo.html

This reverts commit 00821fe.
SLTozer added a commit that referenced this pull request May 2, 2024
…LVM (#89799)"

Reverted following probably-causing failures on some clang buildbots:
  https://lab.llvm.org/buildbot/#/builders/245/builds/24037

This reverts commit a126225.
SLTozer added a commit that referenced this pull request May 3, 2024
…LVM (#89799)"

Reapplies the original commit:
  2f01fd9

The previous application of this patch failed due to some missing
DbgVariableRecord support in clang, which has been added now by commit
8805465.

This will probably break some downstream tools that don't already handle
debug records. If your downstream code breaks as a result of this
change, the simplest fix is to convert the module in question to the old
debug format before you process it, using
`Module::convertFromNewDbgValues()`. For more information about how to
handle debug records or about what has changed, see the migration
document:
    https://llvm.org/docs/RemoveDIsDebugInfo.html

This reverts commit 4fd319a.
bors pushed a commit to rust-lang-ci/rust that referenced this pull request May 7, 2024
llvm/llvm-project#89799 changes llvm.dbg.value/declare intrinsics to be in a different, out-of-instruction-line representation. For example
  call void @llvm.dbg.declare(...)
becomes
  #dbg_declare(...)

Update tests accordingly to work with both the old and new way.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 7, 2024
Adjust dbg.value/dbg.declare checks for LLVM update

llvm/llvm-project#89799 changes llvm.dbg.value/declare intrinsics to be in a different, out-of-instruction-line representation. For example
  call void `@llvm.dbg.declare(...)`
becomes
  #dbg_declare(...)

Update tests accordingly to work with both the old and new way.
OCHyams added a commit that referenced this pull request May 7, 2024
This patch updates the unittests that can be changed to the new format
after #89799 (which changes the default format everywhere) to avoid a
loss in coverage for the (new) default debug info format.
@aeubanks
Copy link
Contributor

aeubanks commented May 9, 2024

Global is external, but doesn't have external or weak linkage!
ptr @_ZN5clang12ast_matchers8internal18makeAllOfCompositeINS_8QualTypeEEENS1_15BindableMatcherIT_EEN4llvm8ArrayRefIPKNS1_7MatcherIS5_EEEE
function declaration may only have a unique !dbg attachment
ptr @_ZN5clang12ast_matchers8internal18makeAllOfCompositeINS_8QualTypeEEENS1_15BindableMatcherIT_EEN4llvm8ArrayRefIPKNS1_7MatcherIS5_EEEE
fatal error: error in backend: Broken module found, compilation aborted!

we're seeing a stage 2 ThinLTO (+PGO) build of clang failing with the above verifier error, any ideas what this could be?

@SLTozer
Copy link
Contributor Author

SLTozer commented May 9, 2024

we're seeing a stage 2 ThinLTO (+PGO) build of clang failing with the above verifier error, any ideas what this could be?

Not immediately clear: the second error is a verifier error resulting from a bad !DISubprogram attachment to a function, which in theory shouldn't be directly impacted by this change, since this is only concerned with debug intrinsics/records, not with debug metadata attachments to non-debug objects. The first error looks entirely unrelated, I've no clear idea how this change could result in changing the linkage of a symbol - at the very least it sounds like it would be a "debug affecting codegen" error if true?

I've only got vague suspicions from those error messages - are you able to share anything else? Reduced reproducers are obviously best, but if those aren't immediately available then it would help to know what flags were used, and at what point in compilation the error is occurring at: is this during pre-link optimization pipeline, immediately after loading bitcode for linking, immediately after linking (I suspect it's probably this), or during/after the post-link optimization pipeline?

@OCHyams
Copy link
Contributor

OCHyams commented May 9, 2024

The verification errors look very unrelated to DbgRecords, which makes me think that maybe there's some bitcode incompatibility happening here (i.e., new bitcode records being misinterpreted or something).

@aeubanks, this is possibly a long shot, are you able to confirm the version of lld that is used to link the stage 2 build is the stage 1 lld?

There was an issue on one of the bots when we first added the new bitcode representation where the system lld was used to link both stage 1 and stage 2, which doesn't work because the stage 1 compiler produced new bitcode that the system lld didn't understand: llvm/llvm-zorg#139.

@aeubanks
Copy link
Contributor

aeubanks commented May 9, 2024

lld is actually not involved here, this is with distributed ThinLTO that invokes clang, and this occurs in the post-link optimization pipeline. I sprinkled some verifyModules around and it seems like function importing is causing the issue. still investigating...

Billy-Sheppard added a commit to Billy-Sheppard/rust that referenced this pull request May 13, 2024
reorganised attrs

removed OsStr impls

added backticks

Add note about possible allocation-sharing to Arc/Rc<str/[T]/CStr>::default.

Use shared statics for the ArcInner for Arc<str, CStr>::default, and for Arc<[T]>::default where alignof(T) <= 16.

fixed unsafe block

Revert "fixed unsafe block"

This reverts commit 6eb6aee.

Return coherent description for boolean instead of panicking

Improve check-cfg CLI errors with more structured diagnostics

Move various stdlib tests to library/std/tests

Run tidy on tests

Rename test for issue 21058

Implement `edition` method on `Rustdoc` type as well

Migrate `run-make/doctests-runtool` to rmake

Rename `run-make-support` library `output` method to `command_output`

Add new `output` method to `Rustc` and `Rustdoc` types

Migrate `run-make/rustdoc-error-lines` to `rmake.rs`

add f16 associated constants

NaN and infinity are not included as they require arithmetic.

add f128 associated constants

NaN and infinity are not included as they require arithmetic.

add constants in std::f16::consts

add constants in std::f128::consts

update error messages in ui tests

Document that `create_dir_all` calls `mkdir`/`CreateDirW` multiple times

Also mention that there might be leftover directories in the error case.

Prefer lower vtable candidates in select in new solver

Don't consider candidates with no failing where clauses

Use super_fold in RegionsToStatic visitor

Make check-cfg docs more user-friendly

Record impl args in the InsepctCandiate rather than rematching during select

Use correct ImplSource for alias bounds

BorrowckInferCtxt: infcx by value

borrowck: more eagerly prepopulate opaques

switch new solver to directly inject opaque types

Update books

Adjust dbg.value/dbg.declare checks for LLVM update

llvm/llvm-project#89799 changes llvm.dbg.value/declare intrinsics to be in a different, out-of-instruction-line representation. For example
  call void @llvm.dbg.declare(...)
becomes
  #dbg_declare(...)

Update tests accordingly to work with both the old and new way.

Adjust 64-bit ARM data layouts for LLVM update

LLVM has updated data layouts to specify `Fn32` on 64-bit ARM to avoid
C++ accidentally underaligning functions when trying to comply with
member function ABIs.

This should only affect Rust in cases where we had a similar bug (I
don't believe we have one), but our data layout must match to generate
code.

As a compatibility adaptatation, if LLVM is not version 19 yet, `Fn32`
gets voided from the data layout.

See llvm/llvm-project#90415

Update version of cc crate to v1.0.97

Reason:

In order to build the Windows version of the Rust toolchain for the Android platform, the following patch to the cc is crate is required to avoid incorrectly determining that we are building with the Android NDK: rust-lang/cc-rs@57853c4

This patch is present in version 1.0.80 and newer versions of the cc crate. The rustc source distribution currently has 3 different versions of cc in the vendor directory, only one of which has the necessary fix.

We (the Android Rust toolchain) are currently maintaining local patches to upgrade the cc crate dependency versions, which we would like to upstream.

Furthermore, beyond the specific reason, the cc crate in bootstrap is currently pinned at an old version due to problems in the past when trying to update it. It is worthwhile to figure out and resolve these problems so we can keep the dependency up-to-date.

Other fixes:

As of cc v1.0.78, object files are prefixed with a 16-character hash.
Update src/bootstrap/src/core/build_steps/llvm.rs to account for this to
avoid failures when building libunwind and libcrt. Note that while the hash
prefix was introduced in v1.0.78, in order to determine the names of the
object files without scanning the directory, we rely on the compile_intermediates
method, which was introduced in cc v1.0.86

As of cc v1.0.86, compilation on MacOS uses the -mmacosx-version-min flag.
A long-standing bug in the CMake rules for compiler-rt causes compilation
to fail when this flag is specified. So we add a workaround to suppress this
flag.

Updating to cc v1.0.91 and newer requires fixes to bootstrap unit tests.
The unit tests use targets named "A", "B", etc., which fail a validation
check introduced in 1.0.91 of the cc crate.

Implement lldb formattter for "clang encoded" enums (LLDB 18.1+)
Summary:
I landed a fix last year to enable `DW_TAG_variant_part` encoding in LLDBs (https://reviews.llvm.org/D149213). This PR is a corresponding fix in synthetic formatters to decode that information.
This is in no way perfect implementation but at least it improves the status quo. But most types of enums will be visible and debuggable in some way.
I've also updated most of the existing tests that touch enums and re-enabled test cases based on LLDB for enums.

Test Plan:
ran tests `./x test tests/debuginfo/`. Also tested manually in LLDB CLI and LLDB VSCode

Other Thoughs
A better approach would probably be adopting [formatters from codelldb](https://github.com/vadimcn/codelldb/blob/master/formatters/rust.py). There is some neat hack that hooks up summary provider via synthetic provider which can ultimately fix more display issues for Rust types and enums too. But getting it to work well might take more time that I have right now.

f16::is_sign_{positive,negative} were feature-gated on f128

Correct the const stabilization of `last_chunk` for slices

`<[T]>::last_chunk` should have become const stable as part of
<rust-lang#117561>. Update the const
stability gate to reflect this.

Add tests

Lower never patterns to Unreachable in mir

rustdoc: dedup search form HTML

This change constructs the search form HTML using JavaScript, instead of plain HTML. It uses a custom element because

- the [parser]'s insert algorithm runs the connected callback synchronously, so we won't get layout jank
- it requires very little HTML, so it's a real win in size

[parser]: https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token

This shrinks the standard library by about 60MiB, by my test.

rustdoc: allow custom element rustdoc-search

generalize hr alias: avoid unconstrainable infer vars

narrow down visibilities in `rustc_parse::lexer`

replace another Option<Span> by DUMMY_SP

Don't ICE when we cannot eval a const to a valtree in the new solver

Do not ICE on `AnonConst`s in `diagnostic_hir_wf_check`

coverage: Add branch coverage support for let-else

coverage: Add branch coverage support for if-let and let-chains

Do not ICE on foreign malformed `diagnostic::on_unimplemented`

Fix rust-lang#124651.

Add test for rust-lang#124651

Update cargo

compiler: Privatize `Parser::current_closure`

This was added as pub in 2021 and remains only privately used in 2024!

compiler: derive Debug in parser

It's annoying to debug the parser if you have to stop every five seconds
to add a Debug impl.

compiler: add `Parser::debug_lookahead`

I tried debugging a parser-related issue but found it annoying to not be
able to easily peek into the Parser's token stream.

Add a convenience fn that offers an opinionated view into the parser,
but one that is useful for answering basic questions about parser state.

Fuchsia test runner: fixup script

This commit fixes several issues in the fuchsia-test-runner.py script:

1. Migrate from `pm` to `ffx` for package management, as `pm` is now
deprecated. Furthermore, the `pm` calls used in this script no longer
work at Fuchsia's HEAD. This is the largest change in this commit, and
impacts all steps around repository management (creation and
registration of the repo, as well as package publishing).

2. Allow for `libtest` to be either statically or dynamically linked.
The script assumed it was dynamically linked, but the current Rust
behavior at HEAD is to statically link it.

3. Minor cleanup to use `ffx --machine json` rather than string parsing.

4. Minor cleanup to the docs around the script.

std::net: Socket::new_raw set to SO_NOSIGPIPE on freebsd/netbsd/dragonfly.

add note about `AlreadyExists` to `create_new`

Apply suggestions from code review

Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>

iOS/tvOS/watchOS/visionOS: Default to kernel-defined backlog in listen

This behavior is defined in general for the XNU kernel, not just macOS:
https://github.com/apple-oss-distributions/xnu/blob/rel/xnu-10002/bsd/kern/uipc_socket.c

iOS/tvOS/watchOS/visionOS: Set the main thread name

Tested in the iOS simulator that the thread name is not set by default,
and that setting it improves the debugging experience in lldb / Xcode.

iOS/tvOS/watchOS: Fix alloc w. large alignment on older versions

Tested on an old MacBook and the iOS simulator.

iOS/tvOS/watchOS/visionOS: Fix reading large files

Tested in the iOS simulator with something like:
```
let mut buf = vec![0; c_int::MAX as usize - 1 + 2];
let read_bytes = f.read(&mut buf).unwrap();
```

iOS/tvOS/watchOS/visionOS: Improve File Debug impl

This uses `libc::fcntl`, which, while not explicitly marked as available
in the headers, is already used by `File::sync_all` and `File::sync_data`
on these platforms, so should be fine to use here as well.

next_power_of_two: add a doctest to show what happens on 0

rustc: Change LLVM target for the wasm32-wasip2 Rust target

This commit changes the LLVM target of for the Rust `wasm32-wasip2`
target to `wasm32-wasip2` as well. LLVM does a bit of detection on the
target string to know when to call `wasm-component-ld` vs `wasm-ld` so
otherwise clang is invoking the wrong linker.

rustc: Don't pass `-fuse-ld=lld` on wasm targets

This argument isn't necessary for WebAssembly targets since `wasm-ld` is
the only linker for the targets. Passing it otherwise interferes with
Clang's linker selection on `wasm32-wasip2` so avoid it altogether.

rustc: Change wasm32-wasip2 to PIC-by-default

This commit changes the new `wasm32-wasip2` target to being PIC by
default rather than the previous non-PIC by default. This change is
intended to make it easier for the standard library to be used in a
shared object in its precompiled form. This comes with a hypothetical
modest slowdown but it's expected that this is quite minor in most use
cases or otherwise wasm compilers and/or optimizing runtimes can elide
the cost.

Handle normalization failure in `struct_tail_erasing_lifetimes`

Fixes an ICE that occurred when the struct in question has an error

Fix insufficient logic when searching for the underlying allocation

in the `invalid_reference_casting` lint, when trying to lint on
bigger memory layout casts.

rustdoc: use stability, instead of features, to decide what to show

To decide if internal items should be inlined in a doc page,
check if the crate is itself internal, rather than if it has
the rustc_private feature flag. The standard library uses
internal items, but is not itself internal and should not show
internal items on its docs pages.

Avoid a cast in `ptr::slice_from_raw_parts(_mut)`

Casting to `*const ()` or `*mut ()` just bloats the MIR, so let's not.

If ACP#362 goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.

add enum variant field names to make the code clearer

remove redundant flat vs nested distinction to simplify enum

turn all_nested_unused into used_childs

store the span of the nested part of the use tree in the ast

 remove braces when fixing a nested use tree into a single use

Use generic `NonZero` in examples.

Simplify `clippy` lint.

Simplify suggestion.

Use generic `NonZero`.

crashes: add lastest batch of crash tests

Make sure we don't deny macro vars w keyword names

Simplify `use crate::rustc_foo::bar` occurrences.

They can just be written as `use rustc_foo::bar`, which is far more
standard. (I didn't even know that a `crate::` prefix was valid.)

Update cc crate to v1.0.97

Ignore empty RUSTC_WRAPPER in bootstrap

This change ignores the RUSTC_WRAPPER_REAL environment variable if it's
set to the empty string. This matches cargo behaviour and allows users
to easily shadow a globally set RUSTC_WRAPPER (which they might have set
for non-rustc projects).

Handle normalization failure in `struct_tail_erasing_lifetimes`

Fixes an ICE that occurred when the struct in question has an error

Implement `as_chunks` with `split_at_unchecked`

Remove `macro_use` from `stable_hasher`.

Normal `use` items are nicer.

Reorder top-level crate items.

- `use` before `mod`
- `pub` before `non-pub`
- Alphabetical order within sections

Remove `extern crate tracing`.

`use` is a nicer way of doing things.

Document `Pu128`.

And move the `repr` line after the `derive` line, where it's harder to
overlook. (I overlooked it initially, and didn't understand how this
type worked.)

Remove `TinyList`.

It is optimized for lists with a single element, avoiding the need for
an allocation in that case. But `SmallVec<[T; 1]>` also avoids the
allocation, and is better in general: more standard, log2 number of
allocations if the list exceeds one item, and a much more capable API.

This commit removes `TinyList` and converts the two uses to
`SmallVec<[T; 1]>`. It also reorders the `use` items in the relevant
file so they are in just two sections (`pub` and non-`pub`), ordered
alphabetically, instead of many sections. (This is a relevant part of
the change because I had to decide where to add a `use` item for
`SmallVec`.)

Remove `vec_linked_list`.

It provides a way to effectively embed a linked list within an
`IndexVec` and also iterate over that list. It's written in a very
generic way, involving two traits `Links` and `LinkElem`. But the
`Links` trait is only impl'd for `IndexVec` and `&IndexVec`, and the
whole thing is only used in one module within `rustc_borrowck`. So I
think it's over-engineered and hard to read. Plus it has no comments.

This commit removes it, and adds a (non-generic) local iterator for the
use within `rustc_borrowck`. Much simpler.

Remove `enum_from_u32`.

It's a macro that just creates an enum with a `from_u32` method. It has
two arms. One is unused and the other has a single use.

This commit inlines that single use and removes the whole macro. This
increases readability because we don't have two different macros
interacting (`enum_from_u32` and `language_item_table`).

Update Tests

Fix Error Messages for `break` Inside Coroutines

Previously, `break` inside `gen` blocks and functions
were incorrectly identified to be enclosed by a closure.

This PR fixes it by displaying an appropriate error message
for async blocks, async closures, async functions, gen blocks,
gen closures, gen functions, async gen blocks, async gen closures
and async gen functions.

Note: gen closure and async gen closure are not supported by the
compiler yet but I have added an error message here assuming that
they might be implemented in the future.

Also, fixes grammar in a few places by replacing
`inside of a $coroutine` with `inside a $coroutine`.

Migrate `run-make/rustdoc-map-file` to rmake

Add more ICEs due to malformed diagnostic::on_unimplemented

Fix ICEs in diagnostic::on_unimplemented

Handle field projections like slice indexing in invalid_reference_casting

Fix typos

Do not add leading asterisk in the `PartialEq`

Adding leading asterisk can cause compilation failure for
the _types_ that don't implement the `Copy`.

Use sum type for `WorkflowRunType`

Parse try build CI job name from commit message

Make the regex more robust

Address review comments

CI: fix auto builds and make sure that we always have at least a single CI job

Include the line number in tidy's `iter_header`

Tidy check for test revisions that are mentioned but not declared

If a `[revision]` name appears in a test header directive or error annotation,
but isn't declared in the `//@ revisions:` header, that is almost always a
mistake.

In cases where a revision needs to be temporarily disabled, adding it to an
`//@ unused-revision-names:` header will suppress these checks for that name.

Adding the wildcard name `*` to the unused list will suppress these checks for
the entire file.

Fix test problems discovered by the revision check

Most of these changes either add revision names that were apparently missing,
or explicitly mark a revision name as currently unused.

fix rust-lang#124714 str.to_lowercase sigma handling

Make a minimal amount of region APIs public

Add `ErrorGuaranteed` to `Recovered::Yes` and use it more.

The starting point for this was identical comments on two different
fields, in `ast::VariantData::Struct` and `hir::VariantData::Struct`:
```
    // FIXME: investigate making this a `Option<ErrorGuaranteed>`
    recovered: bool
```
I tried that, and then found that I needed to add an `ErrorGuaranteed`
to `Recovered::Yes`. Then I ended up using `Recovered` instead of
`Option<ErrorGuaranteed>` for these two places and elsewhere, which
required moving `ErrorGuaranteed` from `rustc_parse` to `rustc_ast`.

This makes things more consistent, because `Recovered` is used in more
places, and there are fewer uses of `bool` and
`Option<ErrorGuaranteed>`. And safer, because it's difficult/impossible
to set `recovered` to `Recovered::Yes` without having emitted an error.

interpret/miri: better errors on failing offset_from

chore: remove repetitive words

Make `#![feature]` suggestion MaybeIncorrect

Update Makefiles with explanatory comments

correct comments

add FIXME

Upgrade the version of Clang used in the build, move MSVC builds to Server 2022

Rename Generics::params to Generics::own_params

Add benchmarks for `impl Debug for str`

In order to inform future perf improvements and prevent regressions,
lets add some benchmarks that stress `impl Debug for str`.

Remove unused `step_trait` feature.

Also sort the features.

Remove unused `LinkSelfContainedDefault::is_linker_enabled` method.

Correct a comment.

I tried simplifying `RegionCtxt`, which led me to finding that the
fields are printed in `sccs_info`.

Fix up `DescriptionCtx::new`.

The comment mentions that `ReBound` and `ReVar` aren't expected here.
Experimentation with the full test suite indicates this is true, and
that `ReErased` also doesn't occur. So the commit introduces `bug!` for
those cases. (If any of them show up later on, at least we'll have a
test case.)

The commit also remove the first sentence in the comment.
`RePlaceholder` is now handled in the match arm above this comment and
nothing is printed for it, so that sentence is just wrong. Furthermore,
issue rust-lang#13998 was closed some time ago.

Fix out-of-date comment.

The type name has changed.

Remove `TyCtxt::try_normalize_erasing_late_bound_regions`.

It's unused.

Remove out-of-date comment.

The use of `Binder` was removed in the recent rust-lang#123900, but the comment
wasn't removed at the same time.

De-tuple two `vtable_trait_first_method_offset` args.

Thus eliminating a `FIXME` comment.

opt-dist: use xz2 instead of xz crate

xz crate consist of simple reexport of xz2 crate. Why? Idk.

analyse visitor: build proof tree in probe

update crashes

always use `GenericArgsRef`

Inline and remove unused methods.

`InferCtxt::next_{ty,const,int,float}_var_id` each have a single call
site, in `InferCtt::next_{ty,const,int,float}_var` respectively.

The only remaining method that creates a var_id is
`InferCtxt::next_ty_var_id_in_universe`, which has one use outside the
crate.

Use fewer origins when creating type variables.

`InferCtxt::next_{ty,const}_var*` all take an origin, but the
`param_def_id` is almost always `None`. This commit changes them to just
take a `Span` and build the origin within the method, and adds new
methods for the rare cases where `param_def_id` might not be `None`.
This avoids a lot of tedious origin building.

Specifically:
- next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of
  `TypeVariableOrigin`
- next_ty_var_with_origin: added

- next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin
- next_const_var_with_origin: added

- next_region_var, next_region_var_in_universe: these are unchanged,
  still take RegionVariableOrigin

The API inconsistency (ty/const vs region) seems worth it for the
large conciseness improvements.

print walltime benchmarks with subnanosecond precision

example results when benchmarking 1-4 serialized ADD instructions

```
running 4 tests
test add  ... bench:           0.24 ns/iter (+/- 0.00)
test add2 ... bench:           0.48 ns/iter (+/- 0.01)
test add3 ... bench:           0.72 ns/iter (+/- 0.01)
test add4 ... bench:           0.96 ns/iter (+/- 0.01)
```

emit fractional benchmark nanoseconds in libtest's JSON output format

bootstrap should also render fractional nanoseconds for benchmarks

from_str_radix: outline only the panic function

codegen: memmove/memset cannot be non-temporal

coverage: Separately compute the set of BCBs with counter mappings

coverage: Make the special case for async functions exit early

coverage: Don't recompute the number of test vector bitmap bytes

The code in `extract_mcdc_mappings` that allocates these bytes already knows
how many are needed in total, so there's no need to immediately recompute that
value in the calling function.

coverage: Destructure the mappings struct to make sure we don't miss any

coverage: Rename `CoverageSpans` to `ExtractedMappings`

coverage: Tidy imports in `rustc_mir_transform::coverage`

Fix parse error message for meta items

Refactor float `Primitive`s to a separate `Float` type

Migrate `run-make/rustdoc-output-path` to rmake

Make builtin_deref just return a Ty

rename some variants in FulfillmentErrorCode

Remove glob imports for ObligationCauseCode

Rename some ObligationCauseCode variants

More rename fallout

Name tweaks

Add a codegen test for transparent aggregates

Aggregating arrays can always take the place path

Make SSA aggregates without needing an alloca

Lift `Lift`

Lift `TraitRef` into `rustc_type_ir`

Also debug

Apply nits, make some bounds into supertraits on inherent traits

Add `-lmingwex` second time in `mingw_libs`

Upcoming mingw-w64 releases will contain small math functions refactor which moved implementation around.
As a result functions like `lgamma`
now depend on libraries in this order:
`libmingwex.a` -> `libmsvcrt.a` -> `libmingwex.a`.

Fixes rust-lang#124221

ignore generics args in attribute paths

bootstrap: add comments for the automatic dry run

fix typo

Co-authored-by: jyn <github@jyn.dev>

reachable computation: extend explanation of what this does, and why

Make sure we consume a generic arg when checking mistyped turbofish

Update cargo

std::rand: adding solaris/illumos for getrandom support.

To help solarish support for miri https://rust-lang/miri/issues/3567

Update ena to 0.14.3

Fix typo in ManuallyDrop's documentation

Add @saethlin to some triagebot groups

Refactor Apple `target_abi`

This was bundled together with `Arch`, which complicated a few code
paths and meant we had to do more string matching than necessary.

Match ergonomics 2024: let `&` patterns eat `&mut`

Various fixes:

- Only show error when move-check would not be triggered
- Add structured suggestion

Fix spans when macros are involved

Comments and fixes

Rename `explicit_ba`

No more `Option<Option<>>`

Remove redundant comment

Move all ref pat logic into `check_pat_ref`

Add comment on `cap_to_weakly_not`

Co-authored-by: Guillaume Boisseau <Nadrieril@users.noreply.github.com>

Stabilize `byte_slice_trim_ascii` for `&[u8]`/`&str`

Remove feature from documentation examples
Add rustc_const_stable attribute to stabilized functions
Update intra-doc link for `u8::is_ascii_whitespace` on `&[u8]` functions

Document proper usage of `fmt::Error` and `fmt()`'s `Result`.

Documentation of these properties previously existed in a lone paragraph
in the `fmt` module's documentation:
<https://doc.rust-lang.org/1.78.0/std/fmt/index.html#formatting-traits>
However, users looking to implement a formatting trait won't necessarily
look there. Therefore, let's add the critical information (that
formatting per se is infallible) to all the involved items.

check if `x test tests` missing any test directory

Signed-off-by: onur-ozkan <work@onurozkan.dev>

remap missing path `tests/crashes` to `tests`

Signed-off-by: onur-ozkan <work@onurozkan.dev>

add "tidy-alphabetical" check on "tests" remap list

Signed-off-by: onur-ozkan <work@onurozkan.dev>

Handle Deref expressions in invalid_reference_casting

unix/fs: a bit of cleanup around host-specific code

solaris support start.

reduce tokio features

remove rand test

the actual target-specific things we want to test are all in getrandom,
and rand already tests miri itself

getrandom: test with and without isolation

also add some comments for why we keep certain old obscure APIs supported

avoid code duplication between realloc and malloc

Implement wcslen

organize libc tests into a proper folder, and run some of them on Windows

README: update introduction

remove problems that I do not think we have seen in a while

io::Error handling: keep around the full io::Error for longer so we can give better errors

Implement non-null pointer for malloc(0)

Allow test targets to be set via CLI args

Update CI script for the miri-script test changes

Update documentation for miri-script test changes

minor tweaks

make MIRI_TEST_TARGET entirely an internal thing

make RUSTC_BLESS entirely an internal thing

do not run symlink tests on Windows hosts

rename 'extern-so' to 'native-lib'

Preparing for merge from rustc

alloc: update comments around malloc() alignment

separate windows heap functions from C heap shims

Add windows_i686_gnullvm to the list

Pin libc back to 0.2.153

Update Cargo.lock

fix few typo in filecheck annotations

Consolidate obligation cause codes for where clauses

Clean up users of rust_dbg_call

Enable profiler for armv7-unknown-linux-gnueabihf.

Always hide private fields in aliased type

Migrate `run-make/rustdoc-shared-flags` to rmake

Relax allocator requirements on some Rc APIs.

* Remove A: Clone bound from Rc::assume_init, Rc::downcast, and Rc::downcast_unchecked.
* Make From<Rc<[T; N]>> for Rc<[T]> allocator-aware.

Internal changes:

* Made Arc::internal_into_inner_with_allocator method into Arc::into_inner_with_allocator associated fn.
* Add private Rc::into_inner_with_allocator (to match Arc), so other fns don't have to juggle ManuallyDrop.

Relax A: Clone requirement on Rc/Arc::unwrap_or_clone.

Add test for rust-lang#122775

Refactoring after the `PlaceValue` addition

I added `PlaceValue` in 123775, but kept that one line-by-line simple because it touched so many places.

This goes through to add more helpers & docs, and change some `PlaceRef` to `PlaceValue` where the type didn't need to be included.

No behaviour changes.

Make it possible to derive Lift/TypeVisitable/TypeFoldable in rustc_type_ir

Uplift `TraitPredicate`

Uplift `ExistentialTraitRef`, `ExistentialProjection`, `ProjectionPredicate`

Uplift `NormalizesTo`, `CoercePredicate`, and `SubtypePredicate`

Apply nits, uplift ExistentialPredicate too

And `ImplPolarity` too

Expand on expr_requires_semi_to_be_stmt documentation

Mark expr_requires_semi_to_be_stmt call sites

For each of these, we need to decide whether they need to be using
`expr_requires_semi_to_be_stmt`, or `expr_requires_comma_to_be_match_arm`,
which are supposed to be 2 different behaviors. Previously they were
conflated into one, causing either too much or too little
parenthesization.

Macro call with braces does not require semicolon to be statement

This commit by itself is supposed to have no effect on behavior. All of
the call sites are updated to preserve their previous behavior.

The behavior changes are in the commits that follow.

Add ExprKind::MacCall statement boundary tests

Fix pretty printer statement boundaries after braced macro call

Delete MacCall case from pretty-printing semicolon after StmtKind::Expr

I didn't figure out how to reach this condition with `expr` containing
`ExprKind::MacCall`. All the approaches I tried ended up with the macro
call ending up in the `StmtKind::MacCall` case below instead.

In any case, from visual inspection this is a bugfix. If we do end up
with a `StmtKind::Expr` containing `ExprKind::MacCall` with brace
delimiter, it would not need ";" printed after it.

Add test of unused_parens lint involving macro calls

Document the situation with unused_parens lint and braced macro calls

Add parser tests for statement boundary insertion

Mark Parser::expr_is_complete call sites

Document MacCall special case in Parser::expr_is_complete

Document MacCall special case in Parser::parse_arm

Add macro calls to else-no-if parser test

Remove MacCall special case from recovery after missing 'if' after 'else'

The change to the test is a little goofy because the compiler was
guessing "correctly" before that `falsy! {}` is the condition as opposed
to the else body. But I believe this change is fundamentally correct.
Braced macro invocations in statement position are most often item-like
(`thread_local! {...}`) as opposed to parenthesized macro invocations
which are condition-like (`cfg!(...)`).

Remove MacCall special cases from Parser::parse_full_stmt

It is impossible for expr here to be a braced macro call. Expr comes
from `parse_stmt_without_recovery`, in which macro calls are parsed by
`parse_stmt_mac`. See this part:

    let kind = if (style == MacStmtStyle::Braces
        && self.token != token::Dot
        && self.token != token::Question)
        || self.token == token::Semi
        || self.token == token::Eof
    {
        StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None }))
    } else {
        // Since none of the above applied, this is an expression statement macro.
        let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac));
        let e = self.maybe_recover_from_bad_qpath(e)?;
        let e = self.parse_expr_dot_or_call_with(e, lo, attrs)?;
        let e = self.parse_expr_assoc_with(
            0,
            LhsExpr::AlreadyParsed { expr: e, starts_statement: false },
        )?;
        StmtKind::Expr(e)
    };

A braced macro call at the head of a statement is always either extended
into ExprKind::Field / MethodCall / Await / Try / Binary, or else
returned as StmtKind::MacCall. We can never get a StmtKind::Expr
containing ExprKind::MacCall containing brace delimiter.

Add classify::expr_is_complete

Fix redundant parens around braced macro call in match arms

use key-value format in stage0 file

Currently, we are working on the python removal task on bootstrap. Which means
we have to extract some data from the stage0 file using shell scripts. However,
parsing values from the stage0.json file is painful because shell scripts don't
have a built-in way to parse json files.

This change simplifies the stage0 file format to key-value pairs, which makes
it easily readable from any environment.

Signed-off-by: onur-ozkan <work@onurozkan.dev>

awk stage0 file on CI

Signed-off-by: onur-ozkan <work@onurozkan.dev>

use stage0 file in `bootstrap.py`

Signed-off-by: onur-ozkan <work@onurozkan.dev>

use shared stage0 parser from `build_helper`

Signed-off-by: onur-ozkan <work@onurozkan.dev>

remove outdated stage0.json parts

Signed-off-by: onur-ozkan <work@onurozkan.dev>

move comments position in `src/stage0`

Signed-off-by: onur-ozkan <work@onurozkan.dev>

io::Write::write_fmt: panic if the formatter fails when the stream does not fail

std::alloc: using posix_memalign instead of memalign on solarish.

simpler code path since small alignments are already taking care of.
close rust-langGH-124787

Relax slice safety requirements

Per rust-lang#116677 (comment), the language as written promises too much. This PR relaxes the language to be consistent with current semantics. If and when rust-lang#117945 is implemented, we can revert to the old language.

References must also be non-null

Add `crate_type` method to `Rustdoc`

Add `crate_name` method to `Rustdoc` and `Rustc`

Add `python_command` and `source_path` functions

Add `extern_` method to `Rustdoc`

Migrate `rustdoc-scrape-examples-ordering` to `rmake`

Fix some minor issues from the ui-test auto-porting

solve: replace all `debug` with `trace`

structurally important functions to `debug`

fix hidden title in command-line-arguments docs

Assert that MemCategorizationVisitor actually errors when it bails ungracefully

Inline MemCategorization into ExprUseVisitor

Remove unncessary mut ref

Introduce TypeInformationCtxt to abstract over LateCtxt/FnCtxt

Make LateCtxt be a type info delegate for EUV for clippy

Try structurally resolve

Apply nits

Propagate errors rather than using return_if_err

Match ergonomics 2024: migration lint

Unfortunately, we can't always offer a machine-applicable suggestion when there are subpatterns from macro expansion.

Co-Authored-By: Guillaume Boisseau <Nadrieril@users.noreply.github.com>

Add AST pretty-printer tests for let-else

Pretty-print let-else with added parenthesization when needed

rename
Billy-Sheppard added a commit to Billy-Sheppard/rust that referenced this pull request May 13, 2024
reorganised attrs

removed OsStr impls

added backticks

Add note about possible allocation-sharing to Arc/Rc<str/[T]/CStr>::default.

Use shared statics for the ArcInner for Arc<str, CStr>::default, and for Arc<[T]>::default where alignof(T) <= 16.

fixed unsafe block

Revert "fixed unsafe block"

This reverts commit 6eb6aee.

Return coherent description for boolean instead of panicking

Improve check-cfg CLI errors with more structured diagnostics

Move various stdlib tests to library/std/tests

Run tidy on tests

Rename test for issue 21058

Implement `edition` method on `Rustdoc` type as well

Migrate `run-make/doctests-runtool` to rmake

Rename `run-make-support` library `output` method to `command_output`

Add new `output` method to `Rustc` and `Rustdoc` types

Migrate `run-make/rustdoc-error-lines` to `rmake.rs`

add f16 associated constants

NaN and infinity are not included as they require arithmetic.

add f128 associated constants

NaN and infinity are not included as they require arithmetic.

add constants in std::f16::consts

add constants in std::f128::consts

update error messages in ui tests

Document that `create_dir_all` calls `mkdir`/`CreateDirW` multiple times

Also mention that there might be leftover directories in the error case.

Prefer lower vtable candidates in select in new solver

Don't consider candidates with no failing where clauses

Use super_fold in RegionsToStatic visitor

Make check-cfg docs more user-friendly

Record impl args in the InsepctCandiate rather than rematching during select

Use correct ImplSource for alias bounds

BorrowckInferCtxt: infcx by value

borrowck: more eagerly prepopulate opaques

switch new solver to directly inject opaque types

Update books

Adjust dbg.value/dbg.declare checks for LLVM update

llvm/llvm-project#89799 changes llvm.dbg.value/declare intrinsics to be in a different, out-of-instruction-line representation. For example
  call void @llvm.dbg.declare(...)
becomes
  #dbg_declare(...)

Update tests accordingly to work with both the old and new way.

Adjust 64-bit ARM data layouts for LLVM update

LLVM has updated data layouts to specify `Fn32` on 64-bit ARM to avoid
C++ accidentally underaligning functions when trying to comply with
member function ABIs.

This should only affect Rust in cases where we had a similar bug (I
don't believe we have one), but our data layout must match to generate
code.

As a compatibility adaptatation, if LLVM is not version 19 yet, `Fn32`
gets voided from the data layout.

See llvm/llvm-project#90415

Update version of cc crate to v1.0.97

Reason:

In order to build the Windows version of the Rust toolchain for the Android platform, the following patch to the cc is crate is required to avoid incorrectly determining that we are building with the Android NDK: rust-lang/cc-rs@57853c4

This patch is present in version 1.0.80 and newer versions of the cc crate. The rustc source distribution currently has 3 different versions of cc in the vendor directory, only one of which has the necessary fix.

We (the Android Rust toolchain) are currently maintaining local patches to upgrade the cc crate dependency versions, which we would like to upstream.

Furthermore, beyond the specific reason, the cc crate in bootstrap is currently pinned at an old version due to problems in the past when trying to update it. It is worthwhile to figure out and resolve these problems so we can keep the dependency up-to-date.

Other fixes:

As of cc v1.0.78, object files are prefixed with a 16-character hash.
Update src/bootstrap/src/core/build_steps/llvm.rs to account for this to
avoid failures when building libunwind and libcrt. Note that while the hash
prefix was introduced in v1.0.78, in order to determine the names of the
object files without scanning the directory, we rely on the compile_intermediates
method, which was introduced in cc v1.0.86

As of cc v1.0.86, compilation on MacOS uses the -mmacosx-version-min flag.
A long-standing bug in the CMake rules for compiler-rt causes compilation
to fail when this flag is specified. So we add a workaround to suppress this
flag.

Updating to cc v1.0.91 and newer requires fixes to bootstrap unit tests.
The unit tests use targets named "A", "B", etc., which fail a validation
check introduced in 1.0.91 of the cc crate.

Implement lldb formattter for "clang encoded" enums (LLDB 18.1+)
Summary:
I landed a fix last year to enable `DW_TAG_variant_part` encoding in LLDBs (https://reviews.llvm.org/D149213). This PR is a corresponding fix in synthetic formatters to decode that information.
This is in no way perfect implementation but at least it improves the status quo. But most types of enums will be visible and debuggable in some way.
I've also updated most of the existing tests that touch enums and re-enabled test cases based on LLDB for enums.

Test Plan:
ran tests `./x test tests/debuginfo/`. Also tested manually in LLDB CLI and LLDB VSCode

Other Thoughs
A better approach would probably be adopting [formatters from codelldb](https://github.com/vadimcn/codelldb/blob/master/formatters/rust.py). There is some neat hack that hooks up summary provider via synthetic provider which can ultimately fix more display issues for Rust types and enums too. But getting it to work well might take more time that I have right now.

f16::is_sign_{positive,negative} were feature-gated on f128

Correct the const stabilization of `last_chunk` for slices

`<[T]>::last_chunk` should have become const stable as part of
<rust-lang#117561>. Update the const
stability gate to reflect this.

Add tests

Lower never patterns to Unreachable in mir

rustdoc: dedup search form HTML

This change constructs the search form HTML using JavaScript, instead of plain HTML. It uses a custom element because

- the [parser]'s insert algorithm runs the connected callback synchronously, so we won't get layout jank
- it requires very little HTML, so it's a real win in size

[parser]: https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token

This shrinks the standard library by about 60MiB, by my test.

rustdoc: allow custom element rustdoc-search

generalize hr alias: avoid unconstrainable infer vars

narrow down visibilities in `rustc_parse::lexer`

replace another Option<Span> by DUMMY_SP

Don't ICE when we cannot eval a const to a valtree in the new solver

Do not ICE on `AnonConst`s in `diagnostic_hir_wf_check`

coverage: Add branch coverage support for let-else

coverage: Add branch coverage support for if-let and let-chains

Do not ICE on foreign malformed `diagnostic::on_unimplemented`

Fix rust-lang#124651.

Add test for rust-lang#124651

Update cargo

compiler: Privatize `Parser::current_closure`

This was added as pub in 2021 and remains only privately used in 2024!

compiler: derive Debug in parser

It's annoying to debug the parser if you have to stop every five seconds
to add a Debug impl.

compiler: add `Parser::debug_lookahead`

I tried debugging a parser-related issue but found it annoying to not be
able to easily peek into the Parser's token stream.

Add a convenience fn that offers an opinionated view into the parser,
but one that is useful for answering basic questions about parser state.

Fuchsia test runner: fixup script

This commit fixes several issues in the fuchsia-test-runner.py script:

1. Migrate from `pm` to `ffx` for package management, as `pm` is now
deprecated. Furthermore, the `pm` calls used in this script no longer
work at Fuchsia's HEAD. This is the largest change in this commit, and
impacts all steps around repository management (creation and
registration of the repo, as well as package publishing).

2. Allow for `libtest` to be either statically or dynamically linked.
The script assumed it was dynamically linked, but the current Rust
behavior at HEAD is to statically link it.

3. Minor cleanup to use `ffx --machine json` rather than string parsing.

4. Minor cleanup to the docs around the script.

std::net: Socket::new_raw set to SO_NOSIGPIPE on freebsd/netbsd/dragonfly.

add note about `AlreadyExists` to `create_new`

Apply suggestions from code review

Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>

iOS/tvOS/watchOS/visionOS: Default to kernel-defined backlog in listen

This behavior is defined in general for the XNU kernel, not just macOS:
https://github.com/apple-oss-distributions/xnu/blob/rel/xnu-10002/bsd/kern/uipc_socket.c

iOS/tvOS/watchOS/visionOS: Set the main thread name

Tested in the iOS simulator that the thread name is not set by default,
and that setting it improves the debugging experience in lldb / Xcode.

iOS/tvOS/watchOS: Fix alloc w. large alignment on older versions

Tested on an old MacBook and the iOS simulator.

iOS/tvOS/watchOS/visionOS: Fix reading large files

Tested in the iOS simulator with something like:
```
let mut buf = vec![0; c_int::MAX as usize - 1 + 2];
let read_bytes = f.read(&mut buf).unwrap();
```

iOS/tvOS/watchOS/visionOS: Improve File Debug impl

This uses `libc::fcntl`, which, while not explicitly marked as available
in the headers, is already used by `File::sync_all` and `File::sync_data`
on these platforms, so should be fine to use here as well.

next_power_of_two: add a doctest to show what happens on 0

rustc: Change LLVM target for the wasm32-wasip2 Rust target

This commit changes the LLVM target of for the Rust `wasm32-wasip2`
target to `wasm32-wasip2` as well. LLVM does a bit of detection on the
target string to know when to call `wasm-component-ld` vs `wasm-ld` so
otherwise clang is invoking the wrong linker.

rustc: Don't pass `-fuse-ld=lld` on wasm targets

This argument isn't necessary for WebAssembly targets since `wasm-ld` is
the only linker for the targets. Passing it otherwise interferes with
Clang's linker selection on `wasm32-wasip2` so avoid it altogether.

rustc: Change wasm32-wasip2 to PIC-by-default

This commit changes the new `wasm32-wasip2` target to being PIC by
default rather than the previous non-PIC by default. This change is
intended to make it easier for the standard library to be used in a
shared object in its precompiled form. This comes with a hypothetical
modest slowdown but it's expected that this is quite minor in most use
cases or otherwise wasm compilers and/or optimizing runtimes can elide
the cost.

Handle normalization failure in `struct_tail_erasing_lifetimes`

Fixes an ICE that occurred when the struct in question has an error

Fix insufficient logic when searching for the underlying allocation

in the `invalid_reference_casting` lint, when trying to lint on
bigger memory layout casts.

rustdoc: use stability, instead of features, to decide what to show

To decide if internal items should be inlined in a doc page,
check if the crate is itself internal, rather than if it has
the rustc_private feature flag. The standard library uses
internal items, but is not itself internal and should not show
internal items on its docs pages.

Avoid a cast in `ptr::slice_from_raw_parts(_mut)`

Casting to `*const ()` or `*mut ()` just bloats the MIR, so let's not.

If ACP#362 goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.

add enum variant field names to make the code clearer

remove redundant flat vs nested distinction to simplify enum

turn all_nested_unused into used_childs

store the span of the nested part of the use tree in the ast

 remove braces when fixing a nested use tree into a single use

Use generic `NonZero` in examples.

Simplify `clippy` lint.

Simplify suggestion.

Use generic `NonZero`.

crashes: add lastest batch of crash tests

Make sure we don't deny macro vars w keyword names

Simplify `use crate::rustc_foo::bar` occurrences.

They can just be written as `use rustc_foo::bar`, which is far more
standard. (I didn't even know that a `crate::` prefix was valid.)

Update cc crate to v1.0.97

Ignore empty RUSTC_WRAPPER in bootstrap

This change ignores the RUSTC_WRAPPER_REAL environment variable if it's
set to the empty string. This matches cargo behaviour and allows users
to easily shadow a globally set RUSTC_WRAPPER (which they might have set
for non-rustc projects).

Handle normalization failure in `struct_tail_erasing_lifetimes`

Fixes an ICE that occurred when the struct in question has an error

Implement `as_chunks` with `split_at_unchecked`

Remove `macro_use` from `stable_hasher`.

Normal `use` items are nicer.

Reorder top-level crate items.

- `use` before `mod`
- `pub` before `non-pub`
- Alphabetical order within sections

Remove `extern crate tracing`.

`use` is a nicer way of doing things.

Document `Pu128`.

And move the `repr` line after the `derive` line, where it's harder to
overlook. (I overlooked it initially, and didn't understand how this
type worked.)

Remove `TinyList`.

It is optimized for lists with a single element, avoiding the need for
an allocation in that case. But `SmallVec<[T; 1]>` also avoids the
allocation, and is better in general: more standard, log2 number of
allocations if the list exceeds one item, and a much more capable API.

This commit removes `TinyList` and converts the two uses to
`SmallVec<[T; 1]>`. It also reorders the `use` items in the relevant
file so they are in just two sections (`pub` and non-`pub`), ordered
alphabetically, instead of many sections. (This is a relevant part of
the change because I had to decide where to add a `use` item for
`SmallVec`.)

Remove `vec_linked_list`.

It provides a way to effectively embed a linked list within an
`IndexVec` and also iterate over that list. It's written in a very
generic way, involving two traits `Links` and `LinkElem`. But the
`Links` trait is only impl'd for `IndexVec` and `&IndexVec`, and the
whole thing is only used in one module within `rustc_borrowck`. So I
think it's over-engineered and hard to read. Plus it has no comments.

This commit removes it, and adds a (non-generic) local iterator for the
use within `rustc_borrowck`. Much simpler.

Remove `enum_from_u32`.

It's a macro that just creates an enum with a `from_u32` method. It has
two arms. One is unused and the other has a single use.

This commit inlines that single use and removes the whole macro. This
increases readability because we don't have two different macros
interacting (`enum_from_u32` and `language_item_table`).

Update Tests

Fix Error Messages for `break` Inside Coroutines

Previously, `break` inside `gen` blocks and functions
were incorrectly identified to be enclosed by a closure.

This PR fixes it by displaying an appropriate error message
for async blocks, async closures, async functions, gen blocks,
gen closures, gen functions, async gen blocks, async gen closures
and async gen functions.

Note: gen closure and async gen closure are not supported by the
compiler yet but I have added an error message here assuming that
they might be implemented in the future.

Also, fixes grammar in a few places by replacing
`inside of a $coroutine` with `inside a $coroutine`.

Migrate `run-make/rustdoc-map-file` to rmake

Add more ICEs due to malformed diagnostic::on_unimplemented

Fix ICEs in diagnostic::on_unimplemented

Handle field projections like slice indexing in invalid_reference_casting

Fix typos

Do not add leading asterisk in the `PartialEq`

Adding leading asterisk can cause compilation failure for
the _types_ that don't implement the `Copy`.

Use sum type for `WorkflowRunType`

Parse try build CI job name from commit message

Make the regex more robust

Address review comments

CI: fix auto builds and make sure that we always have at least a single CI job

Include the line number in tidy's `iter_header`

Tidy check for test revisions that are mentioned but not declared

If a `[revision]` name appears in a test header directive or error annotation,
but isn't declared in the `//@ revisions:` header, that is almost always a
mistake.

In cases where a revision needs to be temporarily disabled, adding it to an
`//@ unused-revision-names:` header will suppress these checks for that name.

Adding the wildcard name `*` to the unused list will suppress these checks for
the entire file.

Fix test problems discovered by the revision check

Most of these changes either add revision names that were apparently missing,
or explicitly mark a revision name as currently unused.

fix rust-lang#124714 str.to_lowercase sigma handling

Make a minimal amount of region APIs public

Add `ErrorGuaranteed` to `Recovered::Yes` and use it more.

The starting point for this was identical comments on two different
fields, in `ast::VariantData::Struct` and `hir::VariantData::Struct`:
```
    // FIXME: investigate making this a `Option<ErrorGuaranteed>`
    recovered: bool
```
I tried that, and then found that I needed to add an `ErrorGuaranteed`
to `Recovered::Yes`. Then I ended up using `Recovered` instead of
`Option<ErrorGuaranteed>` for these two places and elsewhere, which
required moving `ErrorGuaranteed` from `rustc_parse` to `rustc_ast`.

This makes things more consistent, because `Recovered` is used in more
places, and there are fewer uses of `bool` and
`Option<ErrorGuaranteed>`. And safer, because it's difficult/impossible
to set `recovered` to `Recovered::Yes` without having emitted an error.

interpret/miri: better errors on failing offset_from

chore: remove repetitive words

Make `#![feature]` suggestion MaybeIncorrect

Update Makefiles with explanatory comments

correct comments

add FIXME

Upgrade the version of Clang used in the build, move MSVC builds to Server 2022

Rename Generics::params to Generics::own_params

Add benchmarks for `impl Debug for str`

In order to inform future perf improvements and prevent regressions,
lets add some benchmarks that stress `impl Debug for str`.

Remove unused `step_trait` feature.

Also sort the features.

Remove unused `LinkSelfContainedDefault::is_linker_enabled` method.

Correct a comment.

I tried simplifying `RegionCtxt`, which led me to finding that the
fields are printed in `sccs_info`.

Fix up `DescriptionCtx::new`.

The comment mentions that `ReBound` and `ReVar` aren't expected here.
Experimentation with the full test suite indicates this is true, and
that `ReErased` also doesn't occur. So the commit introduces `bug!` for
those cases. (If any of them show up later on, at least we'll have a
test case.)

The commit also remove the first sentence in the comment.
`RePlaceholder` is now handled in the match arm above this comment and
nothing is printed for it, so that sentence is just wrong. Furthermore,
issue rust-lang#13998 was closed some time ago.

Fix out-of-date comment.

The type name has changed.

Remove `TyCtxt::try_normalize_erasing_late_bound_regions`.

It's unused.

Remove out-of-date comment.

The use of `Binder` was removed in the recent rust-lang#123900, but the comment
wasn't removed at the same time.

De-tuple two `vtable_trait_first_method_offset` args.

Thus eliminating a `FIXME` comment.

opt-dist: use xz2 instead of xz crate

xz crate consist of simple reexport of xz2 crate. Why? Idk.

analyse visitor: build proof tree in probe

update crashes

always use `GenericArgsRef`

Inline and remove unused methods.

`InferCtxt::next_{ty,const,int,float}_var_id` each have a single call
site, in `InferCtt::next_{ty,const,int,float}_var` respectively.

The only remaining method that creates a var_id is
`InferCtxt::next_ty_var_id_in_universe`, which has one use outside the
crate.

Use fewer origins when creating type variables.

`InferCtxt::next_{ty,const}_var*` all take an origin, but the
`param_def_id` is almost always `None`. This commit changes them to just
take a `Span` and build the origin within the method, and adds new
methods for the rare cases where `param_def_id` might not be `None`.
This avoids a lot of tedious origin building.

Specifically:
- next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of
  `TypeVariableOrigin`
- next_ty_var_with_origin: added

- next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin
- next_const_var_with_origin: added

- next_region_var, next_region_var_in_universe: these are unchanged,
  still take RegionVariableOrigin

The API inconsistency (ty/const vs region) seems worth it for the
large conciseness improvements.

print walltime benchmarks with subnanosecond precision

example results when benchmarking 1-4 serialized ADD instructions

```
running 4 tests
test add  ... bench:           0.24 ns/iter (+/- 0.00)
test add2 ... bench:           0.48 ns/iter (+/- 0.01)
test add3 ... bench:           0.72 ns/iter (+/- 0.01)
test add4 ... bench:           0.96 ns/iter (+/- 0.01)
```

emit fractional benchmark nanoseconds in libtest's JSON output format

bootstrap should also render fractional nanoseconds for benchmarks

from_str_radix: outline only the panic function

codegen: memmove/memset cannot be non-temporal

coverage: Separately compute the set of BCBs with counter mappings

coverage: Make the special case for async functions exit early

coverage: Don't recompute the number of test vector bitmap bytes

The code in `extract_mcdc_mappings` that allocates these bytes already knows
how many are needed in total, so there's no need to immediately recompute that
value in the calling function.

coverage: Destructure the mappings struct to make sure we don't miss any

coverage: Rename `CoverageSpans` to `ExtractedMappings`

coverage: Tidy imports in `rustc_mir_transform::coverage`

Fix parse error message for meta items

Refactor float `Primitive`s to a separate `Float` type

Migrate `run-make/rustdoc-output-path` to rmake

Make builtin_deref just return a Ty

rename some variants in FulfillmentErrorCode

Remove glob imports for ObligationCauseCode

Rename some ObligationCauseCode variants

More rename fallout

Name tweaks

Add a codegen test for transparent aggregates

Aggregating arrays can always take the place path

Make SSA aggregates without needing an alloca

Lift `Lift`

Lift `TraitRef` into `rustc_type_ir`

Also debug

Apply nits, make some bounds into supertraits on inherent traits

Add `-lmingwex` second time in `mingw_libs`

Upcoming mingw-w64 releases will contain small math functions refactor which moved implementation around.
As a result functions like `lgamma`
now depend on libraries in this order:
`libmingwex.a` -> `libmsvcrt.a` -> `libmingwex.a`.

Fixes rust-lang#124221

ignore generics args in attribute paths

bootstrap: add comments for the automatic dry run

fix typo

Co-authored-by: jyn <github@jyn.dev>

reachable computation: extend explanation of what this does, and why

Make sure we consume a generic arg when checking mistyped turbofish

Update cargo

std::rand: adding solaris/illumos for getrandom support.

To help solarish support for miri https://rust-lang/miri/issues/3567

Update ena to 0.14.3

Fix typo in ManuallyDrop's documentation

Add @saethlin to some triagebot groups

Refactor Apple `target_abi`

This was bundled together with `Arch`, which complicated a few code
paths and meant we had to do more string matching than necessary.

Match ergonomics 2024: let `&` patterns eat `&mut`

Various fixes:

- Only show error when move-check would not be triggered
- Add structured suggestion

Fix spans when macros are involved

Comments and fixes

Rename `explicit_ba`

No more `Option<Option<>>`

Remove redundant comment

Move all ref pat logic into `check_pat_ref`

Add comment on `cap_to_weakly_not`

Co-authored-by: Guillaume Boisseau <Nadrieril@users.noreply.github.com>

Stabilize `byte_slice_trim_ascii` for `&[u8]`/`&str`

Remove feature from documentation examples
Add rustc_const_stable attribute to stabilized functions
Update intra-doc link for `u8::is_ascii_whitespace` on `&[u8]` functions

Document proper usage of `fmt::Error` and `fmt()`'s `Result`.

Documentation of these properties previously existed in a lone paragraph
in the `fmt` module's documentation:
<https://doc.rust-lang.org/1.78.0/std/fmt/index.html#formatting-traits>
However, users looking to implement a formatting trait won't necessarily
look there. Therefore, let's add the critical information (that
formatting per se is infallible) to all the involved items.

check if `x test tests` missing any test directory

Signed-off-by: onur-ozkan <work@onurozkan.dev>

remap missing path `tests/crashes` to `tests`

Signed-off-by: onur-ozkan <work@onurozkan.dev>

add "tidy-alphabetical" check on "tests" remap list

Signed-off-by: onur-ozkan <work@onurozkan.dev>

Handle Deref expressions in invalid_reference_casting

unix/fs: a bit of cleanup around host-specific code

solaris support start.

reduce tokio features

remove rand test

the actual target-specific things we want to test are all in getrandom,
and rand already tests miri itself

getrandom: test with and without isolation

also add some comments for why we keep certain old obscure APIs supported

avoid code duplication between realloc and malloc

Implement wcslen

organize libc tests into a proper folder, and run some of them on Windows

README: update introduction

remove problems that I do not think we have seen in a while

io::Error handling: keep around the full io::Error for longer so we can give better errors

Implement non-null pointer for malloc(0)

Allow test targets to be set via CLI args

Update CI script for the miri-script test changes

Update documentation for miri-script test changes

minor tweaks

make MIRI_TEST_TARGET entirely an internal thing

make RUSTC_BLESS entirely an internal thing

do not run symlink tests on Windows hosts

rename 'extern-so' to 'native-lib'

Preparing for merge from rustc

alloc: update comments around malloc() alignment

separate windows heap functions from C heap shims

Add windows_i686_gnullvm to the list

Pin libc back to 0.2.153

Update Cargo.lock

fix few typo in filecheck annotations

Consolidate obligation cause codes for where clauses

Clean up users of rust_dbg_call

Enable profiler for armv7-unknown-linux-gnueabihf.

Always hide private fields in aliased type

Migrate `run-make/rustdoc-shared-flags` to rmake

Relax allocator requirements on some Rc APIs.

* Remove A: Clone bound from Rc::assume_init, Rc::downcast, and Rc::downcast_unchecked.
* Make From<Rc<[T; N]>> for Rc<[T]> allocator-aware.

Internal changes:

* Made Arc::internal_into_inner_with_allocator method into Arc::into_inner_with_allocator associated fn.
* Add private Rc::into_inner_with_allocator (to match Arc), so other fns don't have to juggle ManuallyDrop.

Relax A: Clone requirement on Rc/Arc::unwrap_or_clone.

Add test for rust-lang#122775

Refactoring after the `PlaceValue` addition

I added `PlaceValue` in 123775, but kept that one line-by-line simple because it touched so many places.

This goes through to add more helpers & docs, and change some `PlaceRef` to `PlaceValue` where the type didn't need to be included.

No behaviour changes.

Make it possible to derive Lift/TypeVisitable/TypeFoldable in rustc_type_ir

Uplift `TraitPredicate`

Uplift `ExistentialTraitRef`, `ExistentialProjection`, `ProjectionPredicate`

Uplift `NormalizesTo`, `CoercePredicate`, and `SubtypePredicate`

Apply nits, uplift ExistentialPredicate too

And `ImplPolarity` too

Expand on expr_requires_semi_to_be_stmt documentation

Mark expr_requires_semi_to_be_stmt call sites

For each of these, we need to decide whether they need to be using
`expr_requires_semi_to_be_stmt`, or `expr_requires_comma_to_be_match_arm`,
which are supposed to be 2 different behaviors. Previously they were
conflated into one, causing either too much or too little
parenthesization.

Macro call with braces does not require semicolon to be statement

This commit by itself is supposed to have no effect on behavior. All of
the call sites are updated to preserve their previous behavior.

The behavior changes are in the commits that follow.

Add ExprKind::MacCall statement boundary tests

Fix pretty printer statement boundaries after braced macro call

Delete MacCall case from pretty-printing semicolon after StmtKind::Expr

I didn't figure out how to reach this condition with `expr` containing
`ExprKind::MacCall`. All the approaches I tried ended up with the macro
call ending up in the `StmtKind::MacCall` case below instead.

In any case, from visual inspection this is a bugfix. If we do end up
with a `StmtKind::Expr` containing `ExprKind::MacCall` with brace
delimiter, it would not need ";" printed after it.

Add test of unused_parens lint involving macro calls

Document the situation with unused_parens lint and braced macro calls

Add parser tests for statement boundary insertion

Mark Parser::expr_is_complete call sites

Document MacCall special case in Parser::expr_is_complete

Document MacCall special case in Parser::parse_arm

Add macro calls to else-no-if parser test

Remove MacCall special case from recovery after missing 'if' after 'else'

The change to the test is a little goofy because the compiler was
guessing "correctly" before that `falsy! {}` is the condition as opposed
to the else body. But I believe this change is fundamentally correct.
Braced macro invocations in statement position are most often item-like
(`thread_local! {...}`) as opposed to parenthesized macro invocations
which are condition-like (`cfg!(...)`).

Remove MacCall special cases from Parser::parse_full_stmt

It is impossible for expr here to be a braced macro call. Expr comes
from `parse_stmt_without_recovery`, in which macro calls are parsed by
`parse_stmt_mac`. See this part:

    let kind = if (style == MacStmtStyle::Braces
        && self.token != token::Dot
        && self.token != token::Question)
        || self.token == token::Semi
        || self.token == token::Eof
    {
        StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None }))
    } else {
        // Since none of the above applied, this is an expression statement macro.
        let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac));
        let e = self.maybe_recover_from_bad_qpath(e)?;
        let e = self.parse_expr_dot_or_call_with(e, lo, attrs)?;
        let e = self.parse_expr_assoc_with(
            0,
            LhsExpr::AlreadyParsed { expr: e, starts_statement: false },
        )?;
        StmtKind::Expr(e)
    };

A braced macro call at the head of a statement is always either extended
into ExprKind::Field / MethodCall / Await / Try / Binary, or else
returned as StmtKind::MacCall. We can never get a StmtKind::Expr
containing ExprKind::MacCall containing brace delimiter.

Add classify::expr_is_complete

Fix redundant parens around braced macro call in match arms

use key-value format in stage0 file

Currently, we are working on the python removal task on bootstrap. Which means
we have to extract some data from the stage0 file using shell scripts. However,
parsing values from the stage0.json file is painful because shell scripts don't
have a built-in way to parse json files.

This change simplifies the stage0 file format to key-value pairs, which makes
it easily readable from any environment.

Signed-off-by: onur-ozkan <work@onurozkan.dev>

awk stage0 file on CI

Signed-off-by: onur-ozkan <work@onurozkan.dev>

use stage0 file in `bootstrap.py`

Signed-off-by: onur-ozkan <work@onurozkan.dev>

use shared stage0 parser from `build_helper`

Signed-off-by: onur-ozkan <work@onurozkan.dev>

remove outdated stage0.json parts

Signed-off-by: onur-ozkan <work@onurozkan.dev>

move comments position in `src/stage0`

Signed-off-by: onur-ozkan <work@onurozkan.dev>

io::Write::write_fmt: panic if the formatter fails when the stream does not fail

std::alloc: using posix_memalign instead of memalign on solarish.

simpler code path since small alignments are already taking care of.
close rust-langGH-124787

Relax slice safety requirements

Per rust-lang#116677 (comment), the language as written promises too much. This PR relaxes the language to be consistent with current semantics. If and when rust-lang#117945 is implemented, we can revert to the old language.

References must also be non-null

Add `crate_type` method to `Rustdoc`

Add `crate_name` method to `Rustdoc` and `Rustc`

Add `python_command` and `source_path` functions

Add `extern_` method to `Rustdoc`

Migrate `rustdoc-scrape-examples-ordering` to `rmake`

Fix some minor issues from the ui-test auto-porting

solve: replace all `debug` with `trace`

structurally important functions to `debug`

fix hidden title in command-line-arguments docs

Assert that MemCategorizationVisitor actually errors when it bails ungracefully

Inline MemCategorization into ExprUseVisitor

Remove unncessary mut ref

Introduce TypeInformationCtxt to abstract over LateCtxt/FnCtxt

Make LateCtxt be a type info delegate for EUV for clippy

Try structurally resolve

Apply nits

Propagate errors rather than using return_if_err

Match ergonomics 2024: migration lint

Unfortunately, we can't always offer a machine-applicable suggestion when there are subpatterns from macro expansion.

Co-Authored-By: Guillaume Boisseau <Nadrieril@users.noreply.github.com>

Add AST pretty-printer tests for let-else

Pretty-print let-else with added parenthesization when needed

rename
@MaskRay
Copy link
Member

MaskRay commented May 13, 2024

I am sorry but I am going to revert this patch. The stage-2 IR verifier error is from a ThinLTO+SamplePGO build.

In a non-assertion -flto=thin -gsplit-dwarf -g -fdebug-info-for-profiling -fprofile-sample-use= build of clang, a ThinLTO backend compile has
assertion failures:

    Global is external, but doesn't have external or weak linkage!
    ptr @_ZN5clang12ast_matchers8internal18makeAllOfCompositeINS_8QualTypeEEENS1_15BindableMatcherIT_EEN4llvm8ArrayRefIPKNS1_7MatcherIS5_EEEE
    function declaration may only have a unique !dbg attachment
    ptr @_ZN5clang12ast_matchers8internal18makeAllOfCompositeINS_8QualTypeEEENS1_15BindableMatcherIT_EEN4llvm8ArrayRefIPKNS1_7MatcherIS5_EEEE

The failures somehow go away if -fprofile-sample-use= is removed.


In an assertion build, I get an assertion failure during ThinLTO backend compiles when llvm/lib/Transforms/IPO/FunctionImport.cpp is importing PointerIterationChecker.pic.o (SrcModule) into NumberObjectConversionChecker.pic.o (DestModule).

computeTypeMapping calls TypeMapTy::areTypesIsomorphic and adds a mapping to MappedTypes.

Then, when IRLinker::run=>ValueMapper::mapValue=>Mapper::flush=>remapFunction=>remapInstruction=>Mapper::mapMetadata=> MDNodeMapper::remapOperands=>mapTopLevelUniquedNode=>MDNodeMapper::visitOperands=>Mapper::mapSimpleMetadata=>GlobalValueMaterializer::materialize=>linkGlobalValueProto=>...copyFunctionProto=>mapAttributeTypes maps a type attribute at IRMover.cpp:679, Attrs.replaceAttributeTypeAtIndex causes an assertion failure:

261│       assert(!(Pair.first != Ty && Pair.second == Ty) &&
262│              "mapping to a source type");

Pair.first and Pair.second are initialized by TypeMapTy::areTypesIsomorphic, called by computeTypeMapping.

Pair.first == 0x55e510d2f0b0 %"class.clang::ast_matchers::internal::BindableMatcher.1199" (then unnamed)
Pair.second == 0x55e50d3dfb80 %"class.clang::ast_matchers::internal::BindableMatcher" 

MaskRay added a commit that referenced this pull request May 13, 2024
…ult in LLVM (#89799)""

This reverts commit 91446e2 and
a unittest followup 1530f31 (#90476).

In a stage-2 -flto=thin -gsplit-dwarf -g -fdebug-info-for-profiling
-fprofile-sample-use= build of clang, a ThinLTO backend compile has
assertion failures:

    Global is external, but doesn't have external or weak linkage!
    ptr @_ZN5clang12ast_matchers8internal18makeAllOfCompositeINS_8QualTypeEEENS1_15BindableMatcherIT_EEN4llvm8ArrayRefIPKNS1_7MatcherIS5_EEEE
    function declaration may only have a unique !dbg attachment
    ptr @_ZN5clang12ast_matchers8internal18makeAllOfCompositeINS_8QualTypeEEENS1_15BindableMatcherIT_EEN4llvm8ArrayRefIPKNS1_7MatcherIS5_EEEE

The failures somehow go away if -fprofile-sample-use= is removed.
@jmorse
Copy link
Member

jmorse commented May 14, 2024

Drive by comment as I'm very out-of-office -- #37394 has a similar error message, during which debug variable locations are implicated in an LTO / IRMover context. The story there is something to do with debug-info materializing something that doesn't have any "real" references, which feels like the kind of thing we might do by mistake with RemoveDIs.

nhasabni pushed a commit to nhasabni/llvm-project that referenced this pull request May 14, 2024
…ult in LLVM (llvm#89799)""

This reverts commit 91446e2 and
a unittest followup 1530f31 (llvm#90476).

In a stage-2 -flto=thin -gsplit-dwarf -g -fdebug-info-for-profiling
-fprofile-sample-use= build of clang, a ThinLTO backend compile has
assertion failures:

    Global is external, but doesn't have external or weak linkage!
    ptr @_ZN5clang12ast_matchers8internal18makeAllOfCompositeINS_8QualTypeEEENS1_15BindableMatcherIT_EEN4llvm8ArrayRefIPKNS1_7MatcherIS5_EEEE
    function declaration may only have a unique !dbg attachment
    ptr @_ZN5clang12ast_matchers8internal18makeAllOfCompositeINS_8QualTypeEEENS1_15BindableMatcherIT_EEN4llvm8ArrayRefIPKNS1_7MatcherIS5_EEEE

The failures somehow go away if -fprofile-sample-use= is removed.
mub-at-arm pushed a commit to mub-at-arm/llvm-project that referenced this pull request May 16, 2024
…ult in LLVM (llvm#89799)""

This reverts commit 91446e2 and
a unittest followup 1530f31 (llvm#90476).

In a stage-2 -flto=thin -gsplit-dwarf -g -fdebug-info-for-profiling
-fprofile-sample-use= build of clang, a ThinLTO backend compile has
assertion failures:

    Global is external, but doesn't have external or weak linkage!
    ptr @_ZN5clang12ast_matchers8internal18makeAllOfCompositeINS_8QualTypeEEENS1_15BindableMatcherIT_EEN4llvm8ArrayRefIPKNS1_7MatcherIS5_EEEE
    function declaration may only have a unique !dbg attachment
    ptr @_ZN5clang12ast_matchers8internal18makeAllOfCompositeINS_8QualTypeEEENS1_15BindableMatcherIT_EEN4llvm8ArrayRefIPKNS1_7MatcherIS5_EEEE

The failures somehow go away if -fprofile-sample-use= is removed.
@danilaml
Copy link
Collaborator

Another drive-by: in my local build I was able to reliably reproduce unittests failures with this commit for debug build with Assertion !NodePtr->isKnownSentinel()' failed. assertion.

@SLTozer
Copy link
Contributor Author

SLTozer commented May 21, 2024

Another drive-by: in my local build I was able to reliably reproduce unittests failures with this commit for debug build with Assertion !NodePtr->isKnownSentinel()' failed. assertion.

Which unit test(s), and what platform+build configuration were you using?

@SLTozer
Copy link
Contributor Author

SLTozer commented May 21, 2024

I am sorry but I am going to revert this patch. The stage-2 IR verifier error is from a ThinLTO+SamplePGO build.

I've got stage-2 ThinLTO+SPGO build of clang using the flags you included but can't reproduce the error - do you have any more information that might be relevant to reproducing the error? Otherwise I'll continue to dig at the rest of the info you've provided to see if I can see an obvious cause of failure, and see if we can find some way to verify a fix without having to repeatedly land and revert until the fix is confirmed.

@danilaml
Copy link
Collaborator

@SLTozer my issue went away after some time and I wasn't able to reproduce it since. I'm guessing it's some sort of merge fluke.

@MaskRay
Copy link
Member

MaskRay commented May 23, 2024

I am sorry but I am going to revert this patch. The stage-2 IR verifier error is from a ThinLTO+SamplePGO build.

I've got stage-2 ThinLTO+SPGO build of clang using the flags you included but can't reproduce the error - do you have any more information that might be relevant to reproducing the error? Otherwise I'll continue to dig at the rest of the info you've provided to see if I can see an obvious cause of failure, and see if we can find some way to verify a fix without having to repeatedly land and revert until the fix is confirmed.

I am able to reproduce the assertion failure using an internal sample profile in a ThinLTO+SamplePGO+ -g build at current HEAD.
Disabling any of these three features (ThinLTO, SamplePGO, or -g) resolves the assertion failure.
(Both -g and -g -gsplit-dwarf can reproduce the assertion failure.)

// during ThinLTO backend compilation for clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
llvm-project/llvm/lib/Linker/IRMover.cpp:260 in Type *(anonymous namespace)::TypeMapTy::get(Type *, SmallPtrSet<StructType *, 8>
&): !(Pair.first != Ty && Pair.second == Ty) && "mapping to a source type"

The sample profile file matters. I've tried a simpler profile using llvm-test-suite sqlite3.i (below), but that doesn't reproduce the crash.

  • reland [RemoveDIs] Load into new debug info format by default in LLVM #89799
  • create a stage 1 build
  • Create a stage 2 ThinLTO+SamplePGO+split DWARF build: configure-llvm s2-custom-fdo -DLLVM_TARGETS_TO_BUILD=host -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_{C,CXX}_FLAGS='-g -fdebug-info-for-profiling -funique-internal-linkage-names' -DCMAKE_EXE_LINKER_FLAGS=-Wl,--build-id -DLLVM_USE_SPLIT_DWARF=on -DLLVM_ENABLE_LTO=Thin
  • Preprocess llvm-test-suite sqlite.c to sqlite.i: clang -DNDEBUG -w -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -I. -E llvm-test-suite/MultiSource/Applications/sqlite3/sqlite3.c -o sqlite3.i
  • Collect perf.data using sqlite3.i on an machine with an Intel CPU: perf record -b -e BR_INST_RETIRED.NEAR_TAKEN:uppp -- /tmp/out/s2-custom-fdo/bin/clang -c -O1 sqlite3.i
  • create_llvm_prof --binary=/tmp/out/s2-custom-fdo/bin/clang --profile=perf.data --out=clang.prof
  • configure-llvm s2-custom-use -DLLVM_TARGETS_TO_BUILD=host -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_{C,CXX}_FLAGS='-g -fdebug-info-for-profiling -funique-internal-linkage-names -fprofile-sample-use=/t/clang.prof' -DLLVM_USE_SPLIT_DWARF=on -DLLVM_ENABLE_LTO=Thin

I've also tried an instrumentation PGO with a simple profile and the -fprofile-use= build does not reproduce the assertion failure.

I know that the task is still on our side to figure out the issue, as this seems really difficult on your side.

@SLTozer
Copy link
Contributor Author

SLTozer commented May 23, 2024

I know that the task is still on our side to figure out the issue, as this seems really difficult on your side.

Thanks for this, and also for the additional info. I was beginning to suspect that a specific sample would be needed; part of the preconditions for the problem that you gave in your previous post are that the problem function is reachable from an instruction metadata attachment, and I've found exactly one instruction (in my non-reproducing build) prior to function importing that has the requisite attachment; that instruction exists in NumberObjectConversionChecker, and I can't see any way (in my build) for it to be imported into PointerIterationChecker, so it's not clear how/why the ValueMapper would touch it, though it could happen in the reverse case (importing NumberObjectConversionChecker into PointerIterationChecker).

Based on where this error first appears, I suspect that the sample profile is only needed to produce the bitcode modules for the thin link; the error happens during importing, which I think (I'm not very familiar with ThinLTO or PGO) happens before llvm-lto2 performs any post-link optimizations that would use the sample profile; if that's correct, then it should be possible to reproduce the error with just the pre-LTO bitcode modules (which could then be reduced further if needed by reducing the objects passed to the link) and the linker flags. If that is the case, and you can get a reproducer that contains no internal data, I should be able to handle the investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants