mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ParseableInterface] Fix failing to build a module when the importing file has errors.
We were checking the parent invocation's DiagnosticEnginer rather than the subinstance's to determine if there were any errors building the module, which meant we would fail to load the module if there were errors prior to the import statement in the importing file. This also meant code completion would fail to load the module, because it always emits a bogus error in order to mark the AST as erroneous so that different parts of the compiler (e.g. the verifier) have less strict assumptions. rdar://problem/43906499
This commit is contained in:
@@ -452,7 +452,7 @@ bool ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
|
||||
return;
|
||||
}
|
||||
|
||||
SubError = Diags.hadAnyError();
|
||||
SubError = SubInstance.getDiags().hadAnyError();
|
||||
});
|
||||
return !RunSuccess || SubError;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %empty-directory(%t/modulecache)
|
||||
//
|
||||
// Setup builds a parseable interface for a module SomeModule (built from some-module.swift).
|
||||
// This test checks we still build and load its corresponding .swiftmodule when the file that imports it contains an error prior to the import statement.
|
||||
|
||||
// Setup phase 1: Write the input file.
|
||||
//
|
||||
// RUN: echo 'public func SomeFunc() -> Int { return 42; }' >>%t/some-module.swift
|
||||
|
||||
// Setup phase 2: build the module.
|
||||
//
|
||||
// RUN: %target-swift-frontend -I %t -emit-parseable-module-interface-path %t/SomeModule.swiftinterface -module-name SomeModule %t/some-module.swift -emit-module -o /dev/null
|
||||
|
||||
// Actual test: compile and verify the import succeeds (i.e. we only report the error in this file)
|
||||
//
|
||||
// RUN: %target-swift-frontend -typecheck -verify -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface %s
|
||||
|
||||
unresolved // expected-error {{use of unresolved identifier 'unresolved'}}
|
||||
|
||||
import SomeModule
|
||||
|
||||
print(SomeFunc())
|
||||
@@ -0,0 +1,13 @@
|
||||
public struct MyPoint {
|
||||
public let x: Double
|
||||
public let y: Double
|
||||
|
||||
public init(x: Double, y: Double) {
|
||||
self.x = x
|
||||
self.y = y
|
||||
}
|
||||
|
||||
public var magnitudeSquared: Double {
|
||||
return x*x + y*y
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import MyPoint
|
||||
|
||||
public extension MyPoint {
|
||||
var magnitude: Double {
|
||||
return magnitudeSquared.squareRoot()
|
||||
}
|
||||
}
|
||||
28
test/SourceKit/CodeComplete/complete_swiftinterface.swift
Normal file
28
test/SourceKit/CodeComplete/complete_swiftinterface.swift
Normal file
@@ -0,0 +1,28 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %empty-directory(%t/modulecache)
|
||||
|
||||
// 1) Build .swiftinterface files for MyPoint and MyExtensions
|
||||
// RUN: %target-swift-frontend -emit-parseable-module-interface-path %t/MyPoint.swiftinterface -module-name MyPoint -emit-module -o /dev/null %S/Inputs/parseable-interface/MyPoint.swift
|
||||
// RUN: %target-swift-frontend -emit-parseable-module-interface-path %t/MyPointExtensions.swiftinterface -module-name MyPointExtensions -emit-module -o /dev/null -enable-parseable-module-interface -module-cache-path %t/modulecache -I %t %S/Inputs/parseable-interface/MyPointExtensions.swift
|
||||
|
||||
// 2) Check completion with a warm module cache from above
|
||||
// RUN: %swift-ide-test_plain -code-completion -code-completion-token=MEMBER -source-filename %s -I %t -module-cache-path %t/modulecache | %FileCheck %s
|
||||
|
||||
// 3) Check completion with a cold module cache
|
||||
// RUN: %empty-directory(%t/modulecache)
|
||||
// RUN: %swift-ide-test_plain -code-completion -code-completion-token=MEMBER -source-filename %s -I %t -module-cache-path %t/modulecache | %FileCheck %s
|
||||
|
||||
import MyPoint
|
||||
import MyPointExtensions
|
||||
|
||||
let x = MyPoint(x: 1, y: 10.5)
|
||||
|
||||
print(x.#^MEMBER^#)
|
||||
|
||||
// CHECK: Begin completions, 5 items
|
||||
// CHECK: Keyword[self]/CurrNominal: self[#MyPoint#]; name=self
|
||||
// CHECK: Decl[InstanceVar]/CurrNominal: x[#Double#]; name=x
|
||||
// CHECK: Decl[InstanceVar]/CurrNominal: y[#Double#]; name=y
|
||||
// CHECK: Decl[InstanceVar]/CurrNominal: magnitudeSquared[#Double#]; name=magnitudeSquared
|
||||
// CHECK: Decl[InstanceVar]/CurrNominal: magnitude[#Double#]; name=magnitude
|
||||
// CHECK: End completions
|
||||
@@ -258,6 +258,12 @@ static llvm::cl::opt<std::string>
|
||||
ModuleCachePath("module-cache-path", llvm::cl::desc("Clang module cache path"),
|
||||
llvm::cl::cat(Category));
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
EnableParseableModuleInterface("enable-parseable-module-interface",
|
||||
llvm::cl::desc("Enable loading .swiftinterface files when available"),
|
||||
llvm::cl::cat(Category),
|
||||
llvm::cl::init(true));
|
||||
|
||||
static llvm::cl::opt<std::string>
|
||||
PCHOutputDir("pch-output-dir",
|
||||
llvm::cl::desc("place autogenerated PCH files in this directory"),
|
||||
@@ -3127,6 +3133,8 @@ int main(int argc, char *argv[]) {
|
||||
InitInvok.getLangOptions().EffectiveLanguageVersion = actual.getValue();
|
||||
}
|
||||
}
|
||||
InitInvok.getFrontendOptions().EnableParseableModuleInterface =
|
||||
options::EnableParseableModuleInterface;
|
||||
InitInvok.getClangImporterOptions().ModuleCachePath =
|
||||
options::ModuleCachePath;
|
||||
InitInvok.getClangImporterOptions().PrecompiledHeaderOutputDir =
|
||||
|
||||
Reference in New Issue
Block a user