Skip to content

Swift 5.9 parameter ownership modifiers #54

Description

@oscbyspro

Introduction

Swift 5.9 (SE-0377) introduces borrowing and consuming parameter ownership modifiers.

An immediate use case

I'm working on some utility methods with the following inout convention:

@inlinable public static func incrementSufficientUnsignedInteger<T>(
_ pointee: inout T, by digit: T.Element, plus bit: inout Bool, at index: inout T.Index)
where T: MutableCollection, T.Element: NBKFixedWidthInteger & NBKUnsignedInteger { ... }

These are used instead of the much more ergonomic return convention:

@inlinable public static func incrementSufficientUnsignedInteger<T>(
_ pointee: inout T, by digit: T.Element, plus bit: Bool, at index: T.Index) -> (index: T.Index, overflow: Bool)
where T: MutableCollection, T.Element: NBKFixedWidthInteger & NBKUnsignedInteger { ... }

I've tried every reasonable combination of attributes, but can't make it perform as well as the inout version. I assume this is related to parameter ownership, and that I want to consume the arguments. I'm not sure this is the solution, but I hope so:

@inlinable public static func incrementSufficientUnsignedInteger<T>(
_ pointee: inout T, by digit: consuming T.Element, plus bit: consuming Bool, at index: consuming T.Index) -> (index: T.Index, overflow: Bool)
where T: MutableCollection, T.Element: NBKFixedWidthInteger & NBKUnsignedInteger { ... }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaitcan't be done yetbrrrsuch code, much wow

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions