Skip to content

[Frontend] Allow missing files when allowing compiler errors #36105

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

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ bool ArgsToFrontendOptionsConverter::convert(
Opts.VerifyGenericSignaturesInModule = A->getValue();
}

Opts.AllowModuleWithCompilerErrors |= Args.hasArg(OPT_experimental_allow_module_with_compiler_errors);

computeDumpScopeMapLocations();

Optional<FrontendInputsAndOutputs> inputsAndOutputs =
Expand All @@ -159,6 +161,8 @@ bool ArgsToFrontendOptionsConverter::convert(
} else {
HaveNewInputsAndOutputs = true;
Opts.InputsAndOutputs = std::move(inputsAndOutputs).getValue();
if (Opts.AllowModuleWithCompilerErrors)
Opts.InputsAndOutputs.setShouldRecoverMissingInputs();
}

if (Args.hasArg(OPT_parse_sil) || Opts.InputsAndOutputs.shouldTreatAsSIL()) {
Expand Down Expand Up @@ -230,7 +234,6 @@ bool ArgsToFrontendOptionsConverter::convert(
Opts.EnableIncrementalDependencyVerifier |= Args.hasArg(OPT_verify_incremental_dependencies);
Opts.UseSharedResourceFolder = !Args.hasArg(OPT_use_static_resource_dir);
Opts.DisableBuildingInterface = Args.hasArg(OPT_disable_building_interface);
Opts.AllowModuleWithCompilerErrors = Args.hasArg(OPT_experimental_allow_module_with_compiler_errors);

computeImportObjCHeaderOptions();
computeImplicitImportModuleNames(OPT_import_module, /*isTestable=*/false);
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ CompilerInstance::getRecordedBufferID(const InputFile &input,

// Recover by dummy buffer if requested.
if (!buffers.hasValue() && shouldRecover &&
input.getType() == file_types::TY_Swift && !input.isPrimary()) {
input.getType() == file_types::TY_Swift) {
buffers = ModuleBuffers(llvm::MemoryBuffer::getMemBuffer(
"// missing file\n", input.getFileName()));
}
Expand Down
26 changes: 26 additions & 0 deletions test/Frontend/allow-errors-missing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %empty-directory(%t)

// 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
// CHECK-SINGLEMISSING: error opening input file 'missing.swift'
// RUN: llvm-bcanalyzer %t/singlemissing.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s

// 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
// CHECK-MULTIMISSINGWMO-DAG: error opening input file 'missing.swift'
// CHECK-MULTIMISSINGWMO-DAG: error opening input file 'missing2.swift'
// RUN: llvm-bcanalyzer %t/multimissingwmo.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s

// 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
// CHECK-SINGLEMISSINGWMO: error opening input file 'missing.swift'
// RUN: llvm-bcanalyzer %t/singlemissingwmo.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s

// 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
// CHECK-NONPRIMARYMISSING: error opening input file 'missing.swift'
// RUN: llvm-bcanalyzer %t/nonprimarymissing.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s

// 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
// CHECK-PRIMARYMISSING: error opening input file 'missing.swift'
// RUN: llvm-bcanalyzer %t/primarymissing.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s

func foo() -> Int { return 0 }

// CHECK-BC-NOT: UnknownCode