Просмотр исходного кода

Allow repeated includes, particularly for min_prelude (#5741)

Make min_prelude parts include what they use, and remove the inclusions
which were for indirect uses from the main min_prelude files.
Jon Ross-Perkins 10 месяцев назад
Родитель
Сommit
49212feac6

+ 1 - 0
testing/file_test/BUILD

@@ -50,6 +50,7 @@ cc_library(
         "//common:ostream",
         "//common:pretty_stack_trace_function",
         "//common:raw_string_ostream",
+        "//common:set",
         "//testing/base:file_helpers",
         "@abseil-cpp//absl/flags:flag",
         "@abseil-cpp//absl/flags:parse",

+ 7 - 0
testing/file_test/test_file.cpp

@@ -13,6 +13,7 @@
 #include "common/error.h"
 #include "common/find.h"
 #include "common/raw_string_ostream.h"
+#include "common/set.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/JSON.h"
 #include "testing/base/file_helpers.h"
@@ -835,8 +836,14 @@ auto ProcessTestFile(llvm::StringRef test_name, bool running_autoupdate)
   }
 
   // Process includes. This can add entries to `include_files`.
+  Set<std::string> processed_includes;
   for (size_t i = 0; i < include_files.size(); ++i) {
     const auto& filename = include_files[i];
+    if (!processed_includes.Insert(filename).is_inserted()) {
+      // Ignore repeated includes, mainly so that included files can include the
+      // same file (i.e., repeated indirectly).
+      continue;
+    }
     CARBON_ASSIGN_OR_RETURN(std::string content, ReadFile(filename));
     // Note autoupdate never touches included files.
     CARBON_RETURN_IF_ERROR(ProcessFileContent(

+ 16 - 0
testing/file_test/testdata/include_repeated.carbon

@@ -0,0 +1,16 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// INCLUDE-FILE: testing/file_test/testdata/include_files/no_split.carbon
+// INCLUDE-FILE: testing/file_test/testdata/include_files/no_split.carbon
+// INCLUDE-FILE: testing/file_test/testdata/include_files/no_split.carbon
+//
+// AUTOUPDATE
+// TIP: To test this file alone, run:
+// TIP:   bazel test //testing/file_test:file_test_base_test --test_arg=--file_tests=testing/file_test/testdata/include_repeated.carbon
+// TIP: To dump output, run:
+// TIP:   bazel run //testing/file_test:file_test_base_test -- --dump_output --file_tests=testing/file_test/testdata/include_repeated.carbon
+
+// CHECK:STDOUT: 3 args: `default_args`, `include_repeated.carbon`, `include_files/no_split.carbon`
+// CHECK:STDOUT: include_files/no_split.carbon:5: no split

+ 0 - 6
toolchain/testing/testdata/min_prelude/int.carbon

@@ -2,12 +2,6 @@
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
-// TODO: This should move to the place where it's imported, but it ends up
-// included more than once and that fails to build.
-// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/as.carbon
-// TODO: This should move to the place where it's imported, but it ends up
-// included more than once and that fails to build.
-// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/int_literal.carbon
 // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/int.carbon
 // EXTRA-ARGS: --custom-core --exclude-dump-file-prefix=min_prelude/
 

+ 2 - 0
toolchain/testing/testdata/min_prelude/parts/float.carbon

@@ -1,6 +1,8 @@
 // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/int_literal.carbon
 
 // --- min_prelude/parts/float.carbon
 

+ 3 - 0
toolchain/testing/testdata/min_prelude/parts/int.carbon

@@ -1,6 +1,9 @@
 // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/as.carbon
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/int_literal.carbon
 
 // --- min_prelude/parts/int.carbon
 

+ 2 - 0
toolchain/testing/testdata/min_prelude/parts/iterate.carbon

@@ -1,6 +1,8 @@
 // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/optional.carbon
 
 // --- min_prelude/parts/iterate.carbon
 

+ 2 - 0
toolchain/testing/testdata/min_prelude/parts/optional.carbon

@@ -1,6 +1,8 @@
 // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/bool.carbon
 
 // --- min_prelude/parts/optional.carbon
 

+ 3 - 0
toolchain/testing/testdata/min_prelude/parts/uint.carbon

@@ -1,6 +1,9 @@
 // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/as.carbon
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/int_literal.carbon
 
 // --- min_prelude/parts/uint.carbon
 

+ 0 - 6
toolchain/testing/testdata/min_prelude/primitives.carbon

@@ -2,14 +2,8 @@
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
-// TODO: This should move to the place where it's imported, but it ends up
-// included more than once and that fails to build.
-// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/as.carbon
 // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/bool.carbon
-// TODO: This should move to the place where it's imported, but it ends up
-// included more than once and that fails to build.
 // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/float.carbon
-// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/int_literal.carbon
 // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/int.carbon
 // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/uint.carbon
 // EXTRA-ARGS: --custom-core --exclude-dump-file-prefix=min_prelude/

+ 0 - 6
toolchain/testing/testdata/min_prelude/uint.carbon

@@ -2,12 +2,6 @@
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
-// TODO: This should move to the place where it's imported, but it ends up
-// included more than once and that fails to build.
-// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/as.carbon
-// TODO: This should move to the place where it's imported, but it ends up
-// included more than once and that fails to build.
-// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/int_literal.carbon
 // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/int.carbon
 // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/uint.carbon
 // EXTRA-ARGS: --custom-core --exclude-dump-file-prefix=min_prelude/