Skip to content

[6.0] [Sema] Don't parse skipped bodies when computing discriminators #75423

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
Jul 24, 2024
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
3 changes: 2 additions & 1 deletion lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ unsigned LocalDiscriminatorsRequest::evaluate(
ParameterList *params = nullptr;
ParamDecl *selfParam = nullptr;
if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
node = func->getBody();
if (!func->isBodySkipped())
node = func->getBody();
selfParam = func->getImplicitSelfDecl();
params = func->getParameters();

Expand Down
21 changes: 21 additions & 0 deletions test/Frontend/skip-function-bodies-parsing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %empty-directory(%t/stats)

// RUN: %target-swift-frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types -module-name Mod -emit-module-path %t/Mod.swiftmodule -stats-output-dir %t/stats %s
// RUN: %{python} %utils/process-stats-dir.py --set-csv-baseline %t/stats.csv %t/stats
// RUN: %FileCheck -input-file %t/stats.csv %s

// The printing implementation differs in asserts and no-asserts builds, it will
// either print `"Parse.NumFunctionsParsed" 0` or not print it at all. Make sure
// we don't output any non-zero value.
// CHECK-NOT: {{"Parse.NumFunctionsParsed" [^0]}}

// Make sure we skip parsing these bodies.
public func foo(x: Int, y: Int) {}

public func bar() {
func baz() {}
}

public struct S {
public func qux() {}
}
20 changes: 20 additions & 0 deletions test/Parse/issue-74561.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %empty-directory(%t)

// Make sure we can parse with and without skipping.
// RUN: %target-typecheck-verify-swift
// RUN: not %target-swift-frontend -emit-module -experimental-skip-non-inlinable-function-bodies -module-name Mod -emit-module-path %t/Mod.swiftmodule -diagnostic-style=llvm %s 2>&1 | %FileCheck %s

// https://github.com/swiftlang/swift/issues/74561
// Make sure we can parse this.
#sourceLocation(file: "A", line: 3)
public func foo(_ param: Int) {
#sourceLocation()
}

// FIXME: This should parse correctly.
#sourceLocation(file: "B", line: 3)
@inlinable
public func bar(_ param: Int) {
#sourceLocation()
}
// CHECK: B:6:1: error: parameterless closing #sourceLocation() directive without prior opening #sourceLocation(file:,line:) directive