-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Milestone
Description
Interface types are really very similar conceptually and in practice to closures. I think we should make them resemble closures more closely both in the language and implementation as follows:
- Make interface instance two words:
(vtable, data)
(analogous to a closure's (fptr, data)) - Model a vtable with one entry as a single function pointer
- Use type bounds after the iface name to indicate how the data is stored (& vs @ vs ~)
Therefore, for an iface X
, the type:
X
indicates any interface instance Such a closure cannot be copied, just asfn
cannot be copiedX&
indicates an interface instance whose data is located on the stack.X@
indicates an interface instance whose data is boxedX~
indicates an interface instance whose data is sendable and stored via unique ptr
Advantages:
- More analogous.
X~
instances can be sentX&
instances are particularly cheap to construct- Closures are a special case of an interface instance (one with a single method), in the impl at least.
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.