feat: Allow @elideTypeInfo as an attribute - #2403
Open
spotandjake wants to merge 2 commits into
Open
Conversation
This PR adds a new `@elideTypeInfo` attribute. It is similar to eliding type information at the CLI level, but is intended more for use within the runtime or library internals where we only want to elide type information from specific parts of a program. The attribute can be applied in the following places: **Above a record definition**: * Elides the type information for that record specifically. **Above an enum definition** * Elides the type information for that enum specifically. **Above a submodule definition**: * Elides the type information for everything within the submodule. **Above a module definition**: * This might initially seem equivalent to eliding type information for the entire program, but it only affects the module itself. * For example, if you have a Main module with type information elided, you can still print records from other modules where type information has not been elided. It should be pretty easy in the future to enable this on exceptions as well, but that requires a parser change to allow attributes above exception definitions. While working on #2385, I noticed that a significant portion of the added program size came from the use of higher-level types such as records and enums. Some of that additional size comes from the type information associated with those types. This attribute gives us a way to selectively strip type information from specific modules, submodules, records, or enums. This should be particularly useful for runtime and internal library code where we know that the type information is not needed and want to reduce the resulting program size. Closes: #2365
spotandjake
requested review from
alex-snezhko,
marcusroberts and
peblair
as code owners
September 4, 2026 23:41
Kara-Zor-El
requested changes
Sep 5, 2026
Kara-Zor-El
left a comment
Member
There was a problem hiding this comment.
took a quick look tonight. Also, side note but in general i think it might make more sense to change elide to omit in this and in general. I do think its more common in everyday language and would increase clarity.
Comment on lines
+352
to
+358
| errs := | ||
| [ | ||
| AttributeDisallowed( | ||
| "`elideTypeInfo` is only allowed on module, record, and variant declarations.", | ||
| loc, | ||
| ), | ||
| ] |
Member
There was a problem hiding this comment.
is there a reason these aren't prepended to the error list and instead replaces it?
Comment on lines
+429
to
+436
| errs := | ||
| [ | ||
| AttributeDisallowed( | ||
| "`elideTypeInfo` is only allowed on module, record, and variant declarations.", | ||
| loc, | ||
| ), | ||
| ] | ||
| } |
Member
There was a problem hiding this comment.
you should probably add tests for elideTypeInfo at a file level and maybe testing calling toString on a type in one file from another
Comment on lines
+69
to
+77
| @elideTypeInfo | ||
| enum FileType { | ||
| File, | ||
| Dir, | ||
| } | ||
|
|
||
| // hack to be able to concretely distinguish TypedPath from PathInfo and | ||
| // enforce TypedPath's type parameters | ||
| @elideTypeInfo |
Member
There was a problem hiding this comment.
these two cause toString/print to change
module Main
from "path" include Path
let p = Path.fromString("/file.txt")
print(p)
goes from
AbsoluteFile(({
base: Abs(Root)
}, {
fileType: File
}, ["file.txt"]))
to
AbsoluteFile(({
base: Abs(Root)
}, <record value>, ["file.txt"]))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR adds a new
@elideTypeInfoattribute. It is similar to eliding type information at the CLI level, but is intended more for use within the runtime or library internals where we only want to elide type information from specific parts of a program.The attribute can be applied in the following places:
Above a record definition:
Above an enum definition
Above a submodule definition:
Above a module definition:
It should be pretty easy in the future to enable this on exceptions as well, but that requires a parser change to allow attributes above exception definitions.
While working on #2385, I noticed that a significant portion of the added program size came from the use of higher-level types such as records and enums. Some of that additional size comes from the type information associated with those types.
The intention of introducing this attribute is to give us a more selective way to strip type information from specific modules, submodules, records or enums. This is particularly useful for runtime and internal library code where we know that the type information will never be needed, and want to reduce the size of the resulting program or in the case of the runtime want to ship slim libraries.
Closes: #2365