Skip to content

[sil] Add SILBuilder helpers for updating passes to handle both ossa … #21824

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

Conversation

gottesmm
Copy link
Contributor

…and non-ossa code.

Specifically we add two groups of APIs: ones for borrows and ones for
destructure.

The borrow helper (emitBeginBorrowOperation) makes it easier to update passes
by:

  • If ownership is disabled, the passed in intruction is just returned.
  • Otherwise if the value is already guaranteed, return an empty SILValue(). This
    is useful since when writing a recursive function it enables one to tell if
    one needs to insert an end_borrow or not.
  • Otherwise, we return (begin_borrow x).

The destructure helpers are a family of functions built around
emitDestructureValueOperation. These in ossa produce destructures and pass the
results off to the caller in some manner that hides the internal destructure
instruction. In non-ossa, the appropriate projections are created and passed off
to the caller.

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

if (!hasOwnership())
return v;
if (v.getOwnershipKind().isCompatibleWith(ValueOwnershipKind::Guaranteed))
return SILValue();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this not returning v?

Choose a reason for hiding this comment

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

It is in the PR description I think but should be commented in the code - much easier than doing git blame: "if the value is already guaranteed, return an empty SILValue(). This
is useful since when writing a recursive function it enables one to tell if
one needs to insert an end_borrow or not."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm... I was looking at this and I discovered that this was actually a thinko in my code that I fixed in a subsequent commit locally. Let me fix this up.

/// This allows for recursive code that deals with borrows to only borrow the
/// first time the function is called. It also by returning v when ownership
/// is disabled makes it easy to write code that works on ossa and on non-ossa
/// SIL.

Choose a reason for hiding this comment

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

The PR / commit message has great documentation that I think should be in the code, easier to grok than just reading this comment, I would incorporate some of that here.

@gottesmm
Copy link
Contributor Author

I am going to rip out the begin borrow part of this. I don't need it. I need the rest though.

…and non-ossa code.

Specifically we add a groups of APIs for destructure operations. The destructure
helpers are a family of functions built around
emitDestructureValueOperation. These in ossa produce destructures and pass the
results off to the caller in some manner that hides the internal destructure
instruction. In non-ossa, the appropriate projections are created and passed off
to the caller.
@gottesmm gottesmm force-pushed the pr-c96623709e3223fd2907cde1e57fbf711938fcc3 branch from c100d29 to 3551c43 Compare January 15, 2019 17:02
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test and merge

3 similar comments
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test and merge

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test and merge

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test and merge

@swift-ci swift-ci merged commit 03e0c4f into swiftlang:master Jan 15, 2019
@gottesmm gottesmm deleted the pr-c96623709e3223fd2907cde1e57fbf711938fcc3 branch January 15, 2019 18:05
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