Skip to content

Migrate SwiftCompilerSources to FunctionConvention #70535

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 1 commit into from
Jan 3, 2024

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Dec 19, 2023

Layers:
- FunctionConvention: AST FunctionType: results, parameters
- ArgumentConventions: SIL function arguments
- ApplyOperandConventions: applied operands

The meaning of an integer index is determined by the collection
type. All the mapping between the various indices (results,
parameters, SIL argument, applied arguments) is restricted to the
collection type that owns that mapping. Remove the concept of a
"caller argument index".

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.

Nice! Much better than before!
Just a few comments about naming.

I'm almost tempted to introduce struct ApplyArgumentIndex and struct CalleeArgumentIndex to let the type checker rule out wrong uses of the various index kinds.

return calleeArgumentConventions[argIdx]
}

public func calleeArgumentIndex(of index: Int) -> Int? {
Copy link
Contributor

Choose a reason for hiding this comment

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

better: calleeArgumentIndex(ofOperandIndex: Int) to make it clear that the index is not an argument but the operand index

operandConventions.convention(of: operand)
}

public func calleeArgumentOperand(at calleeArgIdx: Int) -> Operand? {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is wrong. callee -> caller
Also we should specify the kind of index in the argument label: callerArgumentOperand(forCalleeArgumentIndex:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

public func operand(forCalleeArgumentIndex calleeArgIdx: Int) -> Operand?

/// ```
func calleeArgIndex(callerArgIndex: Int) -> Int

/// Converts an argument index of a callee to the corresponding argument index of the apply.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this comment to callerArgumentOperand(forCalleeArgumentIndex:)?

return index + 1
}

public subscript(_ index: Int) -> ArgumentConvention {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you rename index -> operandIndex, so that it's clear that it is not the argument index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. There is still no subscript label, because it can only by used to subscript a collection of operand conventions:
operandConventions[operand.index]

@atrick
Copy link
Contributor Author

atrick commented Dec 23, 2023

Just a few comments about naming.

I'm almost tempted to introduce struct ApplyArgumentIndex and struct CalleeArgumentIndex to let the type checker rule out wrong uses of the various index kinds.

Index wrapper types would also be good. I didn't want to go quite that far yet. But this PR goes a long way toward eliminating ambiguity two ways

  • completely eliminating the concept of a caller argument index
  • for a given conventions type, the index that you pass to its methods always means the same thing, there's no need to rely on the parameter label anymore

@atrick atrick force-pushed the function-conventions branch 2 times, most recently from ce4bf7c to f5a8001 Compare December 25, 2023 08:26
@atrick
Copy link
Contributor Author

atrick commented Dec 25, 2023

@swift-ci test

@atrick atrick marked this pull request as ready for review December 25, 2023 08:27
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!

operandConventions.convention(of: operand)
}

// Converts an argument index of a callee to the corresponding apply operand.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move the comment of the original callerArgIndex(calleeArgIndex: Int) here (with s/caller indices/caller operands/)? Something like

  /// If the apply does not actually apply that argument, it returns nil.
  ///
  /// Example:
  /// ```
  ///                 func callee(v, w, x, y, z) { }
  /// // caller operands in %pa:  -, -, c, d, e     ("-" == nil)
  /// // caller operands in %a:   a, b, -, -, -
  ///
  /// %pa = partial_apply @callee(c, d, e)
  ///  %a = apply         %pa    (a, b)
  /// ```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's great!

@atrick atrick force-pushed the function-conventions branch from f5a8001 to 8905fc9 Compare December 28, 2023 16:45
@atrick
Copy link
Contributor Author

atrick commented Dec 28, 2023

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Jan 3, 2024

@swift-ci smoke test

@atrick atrick enabled auto-merge January 3, 2024 17:46
Layers:
- FunctionConvention: AST FunctionType: results, parameters
- ArgumentConventions: SIL function arguments
- ApplyOperandConventions: applied operands

The meaning of an integer index is determined by the collection
type. All the mapping between the various indices (results,
parameters, SIL argument, applied arguments) is restricted to the
collection type that owns that mapping. Remove the concept of a
"caller argument index".
@atrick atrick force-pushed the function-conventions branch from 8905fc9 to 2128c21 Compare January 3, 2024 20:25
@atrick
Copy link
Contributor Author

atrick commented Jan 3, 2024

@swift-ci smoke test

@atrick atrick merged commit a43a5f7 into swiftlang:main Jan 3, 2024
@atrick atrick deleted the function-conventions branch January 3, 2024 23:28
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