Skip to content

[NFC] Bridging and utilities for SwiftCompilerSources required by lifetime dependence utilities. #70485

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 10 commits into from
Dec 19, 2023

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Dec 15, 2023

Straightforward utilities needed for lifetime dependence:

  • Argument.isReborrow
  • Argument.incomingOperand(predecessor:)
  • FunctionConvention.swift
  • InstructionRange API; exitBlocks, getRepresentativeInstruction
  • BasicBlock.singleSuccessor
  • BeginApplyInst.token
  • Value.lifetimeEndingUses
  • Value.hasLifetime
  • Sequence.walk()
  • CollectionLikeSequence.contains()

Cherry-picked from Draft PR: #70460

Previously reviewed by @nate-chandler

@atrick atrick requested a review from eeckstein as a code owner December 15, 2023 05:14
@atrick
Copy link
Contributor Author

atrick commented Dec 15, 2023

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Dec 15, 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.

lgtm, just a few minor comments and questions


extension InstructionRange {
// TODO: Add direct support for phis or function args. This workaround will be problematic when used in a pass that mutates the block.
static func getRepresentativeInstruction(for value: Value) -> Instruction {
Copy link
Contributor

Choose a reason for hiding this comment

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

For what should this be used?
Is there a better name for this utility? At least you should add a comment

Copy link
Contributor Author

@atrick atrick Dec 15, 2023

Choose a reason for hiding this comment

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

This is a terrible hack because InstructionRange doesn't support ranges that start at block boundaries, and I just don't have time to design that right now. It's incorrect to say the a block argument begins at the first instruction. The first instruction should instead be seen as within the range and we should be able to insert instructions above it.

(Note that we also need some kind of MultiInstructionRange that supports multiple begin values)

The key point here is that I do not want to add an initializer that takes a Value because that would be misleading. If someone needs this hack, they should know what they're doing first.

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 converted getRepresentativeInstruction to an initializer since we don't plan on modeling instruction ranges that start at block boundaries.

import SILBridging

/// SIL function convention based on the AST function type and SIL stage.
public struct FunctionConvention {
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this different or the same as the APIs we have in Function, e.g. Function.numArguments, etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to query the conventions of a function type without knowing what SIL function will be called. The Function interface should call down to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Migrating Function and ApplySite to FunctionConventions is a separate PR: #70535

Bridge information about the AST function type that does not require a
SIL function body.

Support querying the function type's ResultInfo.
@atrick
Copy link
Contributor Author

atrick commented Dec 18, 2023

@swift-ci smoke test

@atrick
Copy link
Contributor Author

atrick commented Dec 19, 2023

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Dec 19, 2023

This test seems to be spuriously failing on linux:
SourceKit/Diagnostics/cancel_diags.swift

@atrick
Copy link
Contributor Author

atrick commented Dec 19, 2023

@swift-ci smoke test linux

@atrick atrick merged commit 7dc3d72 into swiftlang:main Dec 19, 2023
@atrick atrick deleted the bridge-util branch December 19, 2023 21:07
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