feat: opaque_repr
attribute to suppress "trivial structure" opt
#2292
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds an attribute 8000
@[opaque_repr]
which is used by both the old and new compilers to suppress the "trivial structure" optimization (which deletesmk
andproj
applications 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_attr
though 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.