Opened 4 years ago
#181 new enhancement
Add Support for Opaque Polymorphic Types
Reported by: | ajbeach | Owned by: | |
---|---|---|---|
Priority: | minor | Component: | cfa-cc |
Version: | 1.0 | Keywords: | |
Cc: |
Description
I have been trying to make some smart pointers and I hit a problem with the polymorphic data structures. All are polymorphic on a type T which is the type they point at (their dereference returns a T&).
One of the pointers points directly at a T object and it works as a pointer and T can be opaque. The other one wraps the T type in a new structure. This means it must have a sized
assertion and in turn the pointer type must also include it, which means it cannot be used with an opaque.
To explain it here are the current definitions:
forall(dtype T | sized(T)) struct counter_data { unsigned int counter; T object; }; forall(dtype T | sized(T) /* ! */) struct counter_ptr { counter_data(T) * data; };
The ! assertion is the one that means you can't use an opaque type. This conflicts with the traditional C use of a pointer to an opaque type if you wanted to pass around a memory managed pointer.
The problem is that all uses of a polymorphic type must carry its assertions, even if they aren't used here. There should be a way to drop sized from the assertion list when you just have a pointer to the type. The system doesn't have to know the size or layout as long as you don't dereference the pointer except for the assertion list.