Skip to content

[6.0] SILGen: Skip function bodies with errors in lazy typechecking mode #75102

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
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
23 changes: 22 additions & 1 deletion lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,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) {
Expand Down
5 changes: 5 additions & 0 deletions test/SILGen/lazy_typecheck_errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ public class DerivedFromNonExistent: NonExistent {

public func method() {}
}

@inlinable public func hasErrorInBody() {
nonExistent()
// expected-error@-1 {{cannot find 'nonExistent' in scope}}
}