mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SILGen: Skip function bodies with errors in lazy typechecking mode.
The SILGen pipeline expects function bodies to have been succesfully type checked and will usually crash if it attempts to emit SIL for a function that has errors. To avoid crashing, cause function body typechecking to happen earlier in lazy typechecking mode and then skip functions whenever any errors have been encountered. Resolves rdar://130777647.
This commit is contained in:
@@ -647,7 +647,28 @@ static SILFunction *getFunctionToInsertAfter(SILGenModule &SGM,
|
||||
}
|
||||
|
||||
static bool shouldEmitFunctionBody(const AbstractFunctionDecl *AFD) {
|
||||
return AFD->hasBody() && !AFD->isBodySkipped();
|
||||
if (!AFD->hasBody())
|
||||
return false;
|
||||
|
||||
if (AFD->isBodySkipped())
|
||||
return false;
|
||||
|
||||
auto &ctx = AFD->getASTContext();
|
||||
if (ctx.TypeCheckerOpts.EnableLazyTypecheck) {
|
||||
// Force the function body to be type-checked and then skip it if there
|
||||
// have been any errors.
|
||||
(void)AFD->getTypecheckedBody();
|
||||
|
||||
// FIXME: Only skip bodies that contain type checking errors.
|
||||
// It would be ideal to only skip the function body if it is specifically
|
||||
// the source of an error. However, that information isn't available today
|
||||
// so instead we avoid emitting all function bodies as soon as any error is
|
||||
// encountered.
|
||||
if (ctx.hadError())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool isEmittedOnDemand(SILModule &M, SILDeclRef constant) {
|
||||
|
||||
@@ -61,3 +61,8 @@ public class DerivedFromNonExistent: NonExistent {
|
||||
|
||||
public func method() {}
|
||||
}
|
||||
|
||||
@inlinable public func hasErrorInBody() {
|
||||
nonExistent()
|
||||
// expected-error@-1 {{cannot find 'nonExistent' in scope}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user