icerpc / slicec

The Slice compiler library
Apache License 2.0
13 stars 5 forks source link

Simplify `Container` Trait #637

Closed InsertCreativityHere closed 1 year ago

InsertCreativityHere commented 1 year ago

Currently, we have to specify the exact type a Container contains. For example: Struct implements Container<WeakPtr<Field>>. This PR lets us omit the WeakPtr in the middle and just say: Container<Field>. I think it's more readable and less cluttered.

In the past, this was necessary because of Modules, since they didn't store a WeakPtr<T>. (What would T be? Modules can hold structs, classes, etc. No single T works). But now that modules are simpler, everything holds a WeakPtr<T>.

So we no longer need to specify WeakPtr, since we always know it's there. We can simplify the type signature, and improve the contents function to automatically borrow the ptrs.


Question for Reviewers

As of this PR, we have some functions (fields, enumerators, operations) that are just wrappers that call contents. Should we keep these functions for the better names? Or should we just delete them, and just call contents directly?