Skip to content

SwiftCompilerSources: added OwnershipUtils for ForwardingInstruction. #68885

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 4 commits into from
Oct 5, 2023

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Sep 30, 2023

Add SwiftCompilerSources bridging for operand ownership and forwarding instructions.

This needs to be in place to bootstrap lifetime diagnostics. We'll start adding unit tests as we explore different diagnostic test cases.

@atrick
Copy link
Contributor Author

atrick commented Sep 30, 2023

@swift-ci test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

Basically LGTM, nice work!
I have a few comments about the implementation details

//
// This walker is used to query basic lifetime attributes on values, such as "escaping" or "lexical". It must be precise for correctness and is performance critical.
//
// TODO: Ideally, this would be defined alongside ForwardingInstruction, but basic data structures and utilities are not available in the SIL module.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the walkers really part of SIL? You can also view them as utility, based on ForwardingInstruction.

Anyway, if we want we can easily move the WalkUtils into SIL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any walker that is required for well-formed SIL is part of SIL. In this case, the behavior of the walker will change SIL semantics, so it's definitely part of SIL. If the walker, "stops early" and we fail to see that some value has a pointer-escape, then we lose information needed for correctness. We also cache some information about lifetimes as instruction flags, and that cache needs to be consistent with the walker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that I'm not too concerned about the final resting place for new lifetime utilities because I expect them to change a lot in the next few months.

}

extension Value {
public var forwardingInstruction: ForwardingInstruction? {
Copy link
Contributor

Choose a reason for hiding this comment

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

Though it's a bit lengthy, I think that definingForwardingInstruction would make it a bit clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't care much about the name here, but I'm worried that people will think they can use definingForwardingInstruction the same way they use definingInstruction. But it doesn't work that way. For terminator results, you cannot use the forwarding instruction as an insertion point.

@atrick atrick force-pushed the bridge-forwarding branch 3 times, most recently from 43e4785 to 60d4561 Compare October 3, 2023 07:32
Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

This looks already great!
A have a few more comments

return tpei.tupleOperand
case let sei as SelectEnumInst:
return sei.enumOperand
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be the default implementation

@atrick atrick force-pushed the bridge-forwarding branch 2 times, most recently from 841f6c4 to 4a8b091 Compare October 3, 2023 17:29
atrick added 2 commits October 3, 2023 23:54
This could be combined with ValueUseDefWalker if the latter is
refactored to classsify instructions by projections and aggegation
(which always forward) vs. other arbitrary hard-coded instruction
types. It would also need to limit the walk to real operands (which
are always forwarded). Then this walker can call into the default walk
for projections and track the projection path. The current
implementation is however simpler and more efficient.
@atrick atrick force-pushed the bridge-forwarding branch from 4a8b091 to e27b308 Compare October 4, 2023 06:55
Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

perfect! lgtm!

@atrick
Copy link
Contributor Author

atrick commented Oct 5, 2023

Adding unit tests is taking longer than expected. I'll put them in a follow-up PR.

@atrick
Copy link
Contributor Author

atrick commented Oct 5, 2023

@swift-ci test

@atrick atrick merged commit eccf94d into swiftlang:main Oct 5, 2023
@atrick atrick deleted the bridge-forwarding branch October 5, 2023 17:22
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