Thanks to visit codestin.com
Credit goes to github.com

Skip to content

LifetimeDependenceDiagnostics: bug fixes and output clarity #81191

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 6 commits into from
Apr 30, 2025

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Apr 30, 2025

  • LifetimeDependence type checking: avoid an assertion on error.
    When the type checker encounters incomplete type error, bail out early to avoid
    an assertion.

  • LifetimeDependenceDiagnostics: avoid infinite recursion on error
    Fix a simple typo that results in infinite recursion on invalid code.

    Fixes rdar://147470493 ([nonescapable] LifetimeDependenceInsertion: infinite
    recursion in VariableUseDefWalker.walkup with immortal setter)

  • Refactor debugVarDecl so arguments also support debug_value users.

  • [NFC] SwiftCompilerSource: bridge Function.accessorKindName

  • LifetimeDependence: clarify diagnostics for many unusual cases.
    Ensure that we always issue a diagnostic on error, but avoid emitting any notes that don't have source locations.

    With implicit accessors and thunks, report the correct line number and indicate which accessor generates the error.

    Always check for debug_value users.

    Consistently handle access scopes across diagnostic analysis and diagnostic messages.

  • LifetimeDependenceDiagnostics: note for unsupported closure capture
    Add a note explaining that dependence on closure captures is not
    supported. Otherwise, the diagnostics are very confusing:
    "it depends on a closure capture; this is not yet supported"

atrick added 6 commits April 29, 2025 15:36
When the type checker encounters incomplete type error, bail out early to avoid
an assertion.
Fix a simple typo that results in infinite recursion on invalid code.

Fixes rdar://147470493 ([nonescapable] LifetimeDependenceInsertion: infinite
recursion in VariableUseDefWalker.walkup with immortal setter)
Ensure that we always issue a diagnostic on error, but avoid emitting any notes that don't have source locations.

With implicit accessors and thunks, report the correct line number and indicate which accessor generates the error.

Always check for debug_value users.

Consistently handle access scopes across diagnostic analysis and diagnostic messages.
Add a note explaining that dependence on closure captures is not
supported. Otherwise, the diagnostics are very confusing:
"it depends on a closure capture; this is not yet supported"
@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2025

@swift-ci merge

@atrick atrick requested a review from meg-gupta April 30, 2025 07:04
@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2025

@swift-ci smoke test

@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2025

Unrelated failure: lldb-shell :: Swift/caching.test

@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2025

@swift-ci smoke test

@atrick atrick enabled auto-merge April 30, 2025 16:09
@@ -34,7 +34,12 @@ public class Argument : Value, Hashable {

public var isLexical: Bool { false }

public var varDecl: VarDecl? { bridged.getVarDecl().getAs(VarDecl.self) }
public var varDecl: VarDecl? {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's good to combine getDecl and the lookup of debug_value users into a single API.
I think it's better to directly bridge getDecl (returning a Decl) and add varDecl on top of this. And varDecl belongs more to OptUtils than defining it in the "raw" SIL, because it looks at a bigger SIL structure (including the users) than the Argument in isolation.

}

extension Value {
var debugValDecl: VarDecl? {
Copy link
Contributor

Choose a reason for hiding this comment

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

The same here: this belongs more to OptUtils.
Also the name is not very descriptive. How about func getValDeclFromDebugUsers?

return debugUserDecl
}

var debugUserDecl: VarDecl? {
Copy link
Contributor

Choose a reason for hiding this comment

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

The same here

}

var debugUserDecl: VarDecl? {
for use in uses {
Copy link
Contributor

Choose a reason for hiding this comment

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

uses.users(ofType: DebugValueInst.self).first?.varDecl

@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2025

@eeckstein This week is especially disruptive to land cleanup PRs on main that interfere with 6.2 cherry-picking. Let's please avoid that.

On Monday I can rethink the varDecl interface (which I don't like either) and land a cleanup PR.
Note that this PR does not add any of the new functionality that you are complaining about, it only refactored it a bit so that it works for Arguments too!

I agree with all your review comments except for moving logic into OptUtils. SIL structure is fundamental to SIL. As a rule, if any passes have expectations about that structure, those conventions need to be defined in SIL, not OptUtils. One of my biggest frustrations with SwiftCompilerSources today is the way fundamental SIL operations are scattered around the optimizer code.

I particularly agree that property declarations should not usually search the use list, and we should try to mirror C++ API semantics.

@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2025

@eeckstein also please be aware that the only reason the varDecl APIs are such a mess is that the SIL structure itself is broken. But fixing that requires fixing SILGen. It is extremely important that such complexities (I would call them bugs) with the SIL structures are handled in the fundamental SIL APIs.

Basically, anything you need to correctly use SIL, including verifying that its structure is valid, needs to be defined as part of SIL.

@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2025

blocked by a timeout building lib benchmark.a

@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2025

@swift-ci smoke test macOS

@atrick atrick merged commit b670a6d into swiftlang:main Apr 30, 2025
3 checks passed
@atrick atrick deleted the var-walker-recursion branch April 30, 2025 23:06
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.

2 participants