`@inlinable` in protocols, at individual getters and setters, etc

This question (more or less) has been asked before (here and here), but AFAICS it has never been answered. So I ask it again.

We can put @inlinable at all of these places:

public protocol Foo {
  @inlinable var v: Int {
    @inlinable get
    @inlinable set
  }
}

public struct S: Foo {
  @inlinable public var v: Int {
    @inlinable get { ... }
    @inlinable set { ... }
  }
}

But, for example, in what way is the above different than:

public protocol Foo {
  var v: Int { get set }
}

public struct S: Foo {
  public var v: Int {
    @inlinable get { ... }
    @inlinable set { ... }
  }
}

?

Are the rules for this documented somewhere?

AFAICT, it has absolutely no implication. You still need to reannotate the implementation declaration, or else it’ll not get inlined.

If that is indeed the case, then perhaps the compiler should simply disallow any @inlinable (or other attribute) that has no effect, to avoid confusion, ie in my above example:

public protocol Foo {
  @inlinable var v: Int {        // ERROR: '@inlinable' attribute cannot be applied to this declaration
    @inlinable get               // ERROR: '@inlinable' attribute cannot be applied to this declaration
    @inlinable set               // ERROR: '@inlinable' attribute cannot be applied to this declaration
  }
}

public struct S: Foo {
  @inlinable public var v: Int { // ERROR: '@inlinable' attribute cannot be applied to this declaration
    @inlinable get { ... }
    @inlinable set { ... }
  }
}

?

Terms of Service

Privacy Policy

Cookie Policy