Skip to content

[Sema] Add flag to optimize building swiftmodule files preserving type info for LLDB #34612

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 2 commits into from
Nov 13, 2020

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Nov 6, 2020

Add a new frontend flag -experimental-skip-non-inlinable-function-bodies-without-types to skip parsing and type-checking non-inlinable functions bodies that don't define nested types. This flag can be used as an alternative to -experimental-skip-non-inlinable-function-bodies to keep all type info used by LLDB.

rdar://problem/71130519

@xymus xymus requested review from bnbarham and nkcsgexi November 6, 2020 18:32
@xymus
Copy link
Contributor Author

xymus commented Nov 6, 2020

@swift-ci Please smoke test

Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

@xymus xymus force-pushed the dont-skip-nested-types branch from edf4098 to 526adc6 Compare November 6, 2020 21:05
@xymus
Copy link
Contributor Author

xymus commented Nov 6, 2020

@swift-ci Please smoke test

@xymus
Copy link
Contributor Author

xymus commented Nov 6, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Nov 6, 2020

Build failed
Swift Test Linux Platform
Git Sha - 526adc67e63655f11ec09af6a2b5a411d1ea7c3a

@swift-ci
Copy link
Contributor

swift-ci commented Nov 7, 2020

Build failed
Swift Test OS X Platform
Git Sha - 526adc67e63655f11ec09af6a2b5a411d1ea7c3a

@xymus
Copy link
Contributor Author

xymus commented Nov 9, 2020

@swift-ci Please smoke test

1 similar comment
@xymus
Copy link
Contributor Author

xymus commented Nov 9, 2020

@swift-ci Please smoke test

Copy link
Contributor

@bnbarham bnbarham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines -18 to -19
// %FileCheck %s --check-prefixes CHECK,CHECK-NONINLINE-ONLY < %t/Skip.noninlinable.sil
// %FileCheck %s --check-prefixes CHECK,CHECK-ALL-ONLY < %t/Skip.all.sil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch. Not sure how I missed that, thanks! I think I changed to outputting to a file quite late...

@@ -58,16 +62,14 @@ public class InlinableDeinit {
@_fixed_layout
public class InlineAlwaysDeinit {
@inline(__always) deinit {
let ALLNOTYPECHECK_local = 1
let INLINENOTYPECHECK_local = 1
let NEVERTYPECHECK_local = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realise you could specify that arg multiple times, handy. Much nicer 👍

// %FileCheck %s --check-prefixes CHECK,CHECK-ALL-ONLY < %t/Skip.all.sil
// RUN: %target-swift-frontend -emit-sil -emit-sorted-sil -experimental-skip-non-inlinable-function-bodies -debug-forbid-typecheck-prefix NEVERTYPECHECK -debug-forbid-typecheck-prefix INLINENOTYPECHECK %s -o %t/Skip.noninlinable.sil
// RUN: %target-swift-frontend -emit-sil -emit-sorted-sil -experimental-skip-non-inlinable-function-bodies-without-types -debug-forbid-typecheck-prefix NEVERTYPECHECK -debug-forbid-typecheck-prefix TYPESNOTYPECHECK %s -o %t/Skip.withouttypes.sil
// RUN: %target-swift-frontend -emit-sil -emit-sorted-sil -O -experimental-skip-all-function-bodies -debug-forbid-typecheck-prefix NEVERTYPECHECK -debug-forbid-typecheck-prefix ALLNOTYPECHECK %s -o %t/Skip.all.sil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do make any more changes feel free to remove the -O as well, but doesn't matter either way.

Comment on lines 286 to 287
_blackHole("didSet body") // Do not check for "didSet body" as it's in
// SIL but not the swiftinerface.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add a separate check for the swiftinterface?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked this locally - didSet body isn't in the serialized SIL for me (CHECK fails, CHECK-NOT succeeds). Am I missing something here?

Also, just noticed typo - "swiftinerface" -> "swiftinterface"

Copy link
Contributor Author

@xymus xymus Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I see a few issues if I set it to CHECK. First, it fails to find the next string @_transparent method body, which is probably an ordering issue, the test succeeded because it had already skipped over that string when looking ahead for the CHECK-NOT. And then I see the string in Skip.noninlinable.sil but not in Skip.all.sil, is that expected?

Just to be clear on the terminology, I'd call this textual SIL or simply SIL, serialized SIL wouldn't be as readable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh, sorry - I rushed this part of the test. Should have double checked the generated textual SIL. The ordering looks a little weird, the willSet is between publicFunc and privateFunc and the didSet is between the transparent init and inlinable init. Assuming that's stable (?) they should both be moved.

It's definitely expected that it's skipped for -experimental-skip-all-function-bodies - that option just skips outputting SIL entirely. I had thought it would be skipped for non-inlinable as well, but that looks like a misunderstanding on my part.

FWIW, the old "skip-noninline-function-bodies.swift" test had a CHECK prefix for SIL vs interface. I had removed it as it was being used, but this looks like a case for it.

@xymus
Copy link
Contributor Author

xymus commented Nov 11, 2020

@swift-ci Please smoke test Linux platform

This frontend flag can be used as an alternative to
-experimental-skip-non-inlinable-function-bodies that doesn’t skip
functions defining nested types. We want to keep these types as they are
used by LLDB. Other functions ares safe to skip parsing and
type-checking.

rdar://71130519
@xymus xymus force-pushed the dont-skip-nested-types branch from c4d9984 to 02c1343 Compare November 12, 2020 22:28
@xymus
Copy link
Contributor Author

xymus commented Nov 12, 2020

@swift-ci Please smoke test

@bnbarham
Copy link
Contributor

Thanks for fixing that test up!

@xymus
Copy link
Contributor Author

xymus commented Nov 12, 2020

@bnbarham Of course, and thanks for that previous PR, it made this one much cleaner.

@xymus
Copy link
Contributor Author

xymus commented Nov 13, 2020

@swift-ci Please smoke test macOS platform

@xymus xymus merged commit b72b0c3 into swiftlang:main Nov 13, 2020
@xymus xymus deleted the dont-skip-nested-types branch August 25, 2021 17:46
brentleyjones added a commit to bazelbuild/rules_swift that referenced this pull request Oct 14, 2021
Uses the newer `-experimental-skip-non-inlinable-function-bodies-without-types` which was introduced here: swiftlang/swift#34612. This should improve LLDB usage in some cases.

When using WMO, it has two downsides in Swift 5.5, both introduced by swiftlang/swift#38939:
- The swiftmodules will have swiftdeps info embedded in them, which is only needed for incremental compilation
- Interface hashing is enabled, which again is only needed for incremental compilation

This is because the swift compiler only expects `-experimental-skip-non-inlinable-function-bodies-without-types` to be used with the new `emit-module-separately` incremental build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants