Skip to content

Should Destroy use a blanket impl for class types, or should it be instantiated per-class? #6124

@jonmeow

Description

@jonmeow

Summary of issue:

How should Destroy work for classes?

The two main options are:

  1. Have a blanket impl next to Destroy which covers all classes that should support Destroy.
  2. Generate an impl as Destroy as part of each class definition.
    • This would likely behave similarly as if users wrote that inside the class definition, particularly to support class C { class Nested {} var n: Nested; }

Details:

At present, we already expect to have blanket impls for other types implementing Destroy. For example: tuples, structs, arrays, T*, const T, and MaybeUnformed(T).

class is slightly different because classes are expected to have custom destroy functions, and have a definition owned by a specific library (in contrast with tuples).

There was significant discussion about what users should see, and what limits were desired, in the toolchain meeting on Sep 23.

Prior to the meeting, zygoloid and I had also discussed possible performance differences:

  • In a blanket impl approach, one impl is imported for all types. Each type gets its own specific. Impl lookup would need to test against the blanket impl on the first lookup, but could in theory cache results (not yet implemented).
  • In a per-class approach, there many impls, and each is imported separately. However, in theory impl lookup can look at only the impl that applies (though it may still need to examine and rule out blanket impls).

The discussion about performance was set aside since it didn't seem as compelling about the discussion about desired behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    leads questionA question for the leads team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions