Skip to content

Commit 751cd38

Browse files
authored
Merge pull request #36105 from bnbarham/allow-missing-files
[Frontend] Allow missing files when allowing compiler errors
2 parents 0b15060 + bb9dd3a commit 751cd38

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ bool ArgsToFrontendOptionsConverter::convert(
139139
Opts.VerifyGenericSignaturesInModule = A->getValue();
140140
}
141141

142+
Opts.AllowModuleWithCompilerErrors |= Args.hasArg(OPT_experimental_allow_module_with_compiler_errors);
143+
142144
computeDumpScopeMapLocations();
143145

144146
Optional<FrontendInputsAndOutputs> inputsAndOutputs =
@@ -159,6 +161,8 @@ bool ArgsToFrontendOptionsConverter::convert(
159161
} else {
160162
HaveNewInputsAndOutputs = true;
161163
Opts.InputsAndOutputs = std::move(inputsAndOutputs).getValue();
164+
if (Opts.AllowModuleWithCompilerErrors)
165+
Opts.InputsAndOutputs.setShouldRecoverMissingInputs();
162166
}
163167

164168
if (Args.hasArg(OPT_parse_sil) || Opts.InputsAndOutputs.shouldTreatAsSIL()) {
@@ -230,7 +234,6 @@ bool ArgsToFrontendOptionsConverter::convert(
230234
Opts.EnableIncrementalDependencyVerifier |= Args.hasArg(OPT_verify_incremental_dependencies);
231235
Opts.UseSharedResourceFolder = !Args.hasArg(OPT_use_static_resource_dir);
232236
Opts.DisableBuildingInterface = Args.hasArg(OPT_disable_building_interface);
233-
Opts.AllowModuleWithCompilerErrors = Args.hasArg(OPT_experimental_allow_module_with_compiler_errors);
234237

235238
computeImportObjCHeaderOptions();
236239
computeImplicitImportModuleNames(OPT_import_module, /*isTestable=*/false);

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ CompilerInstance::getRecordedBufferID(const InputFile &input,
655655

656656
// Recover by dummy buffer if requested.
657657
if (!buffers.hasValue() && shouldRecover &&
658-
input.getType() == file_types::TY_Swift && !input.isPrimary()) {
658+
input.getType() == file_types::TY_Swift) {
659659
buffers = ModuleBuffers(llvm::MemoryBuffer::getMemBuffer(
660660
"// missing file\n", input.getFileName()));
661661
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -emit-module -o %t/singlemissing.swiftmodule -experimental-allow-module-with-compiler-errors missing.swift 2>&1 | %FileCheck -check-prefix=CHECK-SINGLEMISSING %s
4+
// CHECK-SINGLEMISSING: error opening input file 'missing.swift'
5+
// RUN: llvm-bcanalyzer %t/singlemissing.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
6+
7+
// RUN: %target-swift-frontend -emit-module -o %t/multimissingwmo.swiftmodule -experimental-allow-module-with-compiler-errors -whole-module-optimization missing.swift missing2.swift 2>&1 | %FileCheck -check-prefix=CHECK-MULTIMISSINGWMO %s
8+
// CHECK-MULTIMISSINGWMO-DAG: error opening input file 'missing.swift'
9+
// CHECK-MULTIMISSINGWMO-DAG: error opening input file 'missing2.swift'
10+
// RUN: llvm-bcanalyzer %t/multimissingwmo.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
11+
12+
// RUN: %target-swift-frontend -emit-module -o %t/singlemissingwmo.swiftmodule -experimental-allow-module-with-compiler-errors -whole-module-optimization %s missing.swift 2>&1 | %FileCheck -check-prefix=CHECK-SINGLEMISSINGWMO %s
13+
// CHECK-SINGLEMISSINGWMO: error opening input file 'missing.swift'
14+
// RUN: llvm-bcanalyzer %t/singlemissingwmo.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
15+
16+
// RUN: %target-swift-frontend -emit-module -o %t/nonprimarymissing.swiftmodule -experimental-allow-module-with-compiler-errors -primary-file %s missing.swift 2>&1 | %FileCheck -check-prefix=CHECK-NONPRIMARYMISSING %s
17+
// CHECK-NONPRIMARYMISSING: error opening input file 'missing.swift'
18+
// RUN: llvm-bcanalyzer %t/nonprimarymissing.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
19+
20+
// RUN: %target-swift-frontend -emit-module -o %t/primarymissing.swiftmodule -experimental-allow-module-with-compiler-errors -primary-file missing.swift %s 2>&1 | %FileCheck -check-prefix=CHECK-PRIMARYMISSING %s
21+
// CHECK-PRIMARYMISSING: error opening input file 'missing.swift'
22+
// RUN: llvm-bcanalyzer %t/primarymissing.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
23+
24+
func foo() -> Int { return 0 }
25+
26+
// CHECK-BC-NOT: UnknownCode

0 commit comments

Comments
 (0)