Skip to content

feat: Allow @elideTypeInfo as an attribute - #2403

Open
spotandjake wants to merge 2 commits into
mainfrom
spotandjake/elideTypeInfo-attr
Open

feat: Allow @elideTypeInfo as an attribute#2403
spotandjake wants to merge 2 commits into
mainfrom
spotandjake/elideTypeInfo-attr

Conversation

@spotandjake

@spotandjake spotandjake commented Sep 4, 2026

Copy link
Copy Markdown
Member

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.

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

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

@Kara-Zor-El Kara-Zor-El left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
),
]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
),
]
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread stdlib/path.gr
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow eliding type info of an individual type or module

2 participants