Skip to content

[swift2objc] Add support for Swift Borrowing Features #2086

@nikeokoronkwo

Description

@nikeokoronkwo

This issue is used to track the development of Swift Borrowing Features such as moveonly, consuming, and borrowing.

From https://github.com/swiftlang/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md

We give developers direct control over the ownership convention of parameters by introducing two new parameter modifiers, borrowing and consuming.

borrowing and consuming become contextual keywords inside parameter type declarations. They can appear in the same places as the inout modifier, and are mutually exclusive with each other and with inout. In a func, subscript, or init declaration, they appear as follows:

func foo(_: borrowing Foo)
func foo(_: consuming Foo)
func foo(_: inout Foo)

Methods can also use the consuming or borrowing modifier to indicate respectively that they consume ownership of their self parameter or that they borrow it. These modifiers are mutually exclusive with each other and with the existing mutating modifier:

struct Foo {
  consuming func foo() // `consuming` self
  borrowing func foo() // `borrowing` self
  mutating func foo() // modify self with `inout` semantics
}

Parameters may need to be transformed to consider such borrowing or consuming

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions