Skip to content

proposals: propose protocol metatype extensions#3244

Open
compnerd wants to merge 2 commits into
swiftlang:mainfrom
compnerd:protocol-metatype-extensionss
Open

proposals: propose protocol metatype extensions#3244
compnerd wants to merge 2 commits into
swiftlang:mainfrom
compnerd:protocol-metatype-extensionss

Conversation

@compnerd
Copy link
Copy Markdown
Member

Propose protocol metatype extensions

@compnerd compnerd force-pushed the protocol-metatype-extensionss branch from 61a8319 to af9f0a3 Compare April 15, 2026 03:48
@rjmccall rjmccall added LSG Contains topics under the domain of the Language Steering Group new proposal Adds a new proposal document labels Apr 20, 2026

We consider this a natural future direction but out of scope for this proposal.

### Protocol metatype conformances
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We discussed this proposal in the Language Steering Group this week. One of the questions we had was whether this proposal was a complete enough story to do what folks might want to do with things like COM interop (or even non-COM use cases). This would be adding a capability to the language where we can use the protocol as a namespace, but as currently written, it ends there—it doesn't permit the kind of generic programming that a user might otherwise expect.

This section points out that a natural thing to want to do with these extensions would be to pass the metatype to a generic function that would operate on that IID. And without the ability to conform metatypes to protocols, there's no way to express that today:

func someFunc<T: /* ??? */>(_ comInterface: T) {
  let iid = T.IID
  /* do something with iid */
}
someFunc(IDispatch.self)

Is this something you foresee users of COM interop wanting to do, and if so, does it follow naturally from what is being proposed here? Did you have plans to work on this space as well, or is this more of an open question?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, this is something that I could see as being valuable (and eventually needed). I think that that this would be something to revisit in the future once more of the COM infrastructure is built out. But, yes, I do feel like it would flow from this work. As to the work itself, that would be more of an open question and something that would come back up when the WinRT layer starts getting looked at.

@allevato
Copy link
Copy Markdown
Member

The Language Steering Group discussed this last week and we think there are some unanswered design questions that need to be figured out before this can be run.

The main concern surrounded the inability to operate on metatypes generically. Even though you acknowledge this as a future direction, we want to avoid backing ourselves into a language design corner if we allow folks to inject members with the current "namespace" approach, especially around the choice that Q.Protocol doesn't inherit members from P.Protocol when Q: P.

For the COM interop use cases you had in mind like generating IIDs for interface protocols, we were generally more comfortable with just having those be synthesized via compiler magic for the time being, rather than add a metatype feature that isn't fully realized.

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

Labels

LSG Contains topics under the domain of the Language Steering Group new proposal Adds a new proposal document

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants