feat: opaque_repr attribute to suppress "trivial structure" opt - #2292
feat: opaque_repr attribute to suppress "trivial structure" opt#2292digama0 wants to merge 3 commits into
opaque_repr attribute to suppress "trivial structure" opt#2292Conversation
|
@digama0 sent me the following explanation of the underlying issue here, which I'll quote here in the hope it is useful:
|
|
This hasn't been touched in over a year, and has a merge conflict. I'm closing now; please re-open if you think appropriate. |
This adds an attribute
@[opaque_repr]which is used by both the old and new compilers to suppress the "trivial structure" optimization (which deletesmkandprojapplications for newtype structures), replacing the existingis_runtime_builtin_type()function. (There is aTODO(Leo): use an attribute?comment in the code, so I am hopeful that this is a desirable direction.)I have renamed the function to
has_opaque_repr_attrthough because it's not actually about builtin types, and the provided test case shows where it is useful in user code: when you are making an opaque type (i.e. a type where the mk / val / casesOn will be overridden usingimplemented_by), the compiler's trivial structure optimization can cause calls to the overridden functions to be removed.The attribute name is slightly more generic than "suppress trivial structure optimization", and is intended as a general purpose attribute to put on types to direct the compiler that it should not make any assumptions about the type layout, with the default (non-overridden) behavior being that of a boxed inductive type.