Skip to content

[TypeChecker] Do not attempt to skip typechecking for didSet #34569

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
Nov 5, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ static bool shouldHaveSkippedFunction(const SILFunction &F) {
if (isa<DestructorDecl>(func) || isa<ConstructorDecl>(func))
return false;

// See DeclChecker::shouldSkipBodyTypechecking. Can't skip didSet for now.
if (auto *AD = dyn_cast<AccessorDecl>(func)) {
if (AD->getAccessorKind() == AccessorKind::DidSet)
return false;
}

// If none of those conditions trip, then this is something that _should_
// be serialized in the module even when we're skipping non-inlinable
// function bodies.
Expand Down
7 changes: 7 additions & 0 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
if (!AFD->getBodySourceRange().isValid())
return false;

// didSet runs typechecking to determine whether to keep its parameter,
// so never try to skip.
if (auto *AD = dyn_cast<AccessorDecl>(AFD)) {
if (AD->getAccessorKind() == AccessorKind::DidSet)
return false;
}

// If we're gonna serialize the body, we can't skip it.
if (AFD->getResilienceExpansion() == ResilienceExpansion::Minimal)
return false;
Expand Down
12 changes: 12 additions & 0 deletions test/Frontend/skip-non-inlinable-function-bodies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ public struct Struct {
}
}

public var willSetVar: Int = 1 {
willSet {
_blackHole("willSet body") // CHECK-NOT: "willSet body"
}
}

public var didSetVar: Int = 1 {
didSet {
_blackHole("didSet body") // CHECK-NOT: "didSet body"
}
}

@_transparent
public func transparentFunc() {
_blackHole("@_transparent method body") // CHECK: "@_transparent method body"
Expand Down
9 changes: 9 additions & 0 deletions validation-test/compiler_crashers_2_fixed/rdar70739449.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-swift-frontend -emit-module %s -experimental-skip-non-inlinable-function-bodies

struct Foo {
var fieldWithDidSet : Int {
didSet {
let local = oldValue
}
}
}