Skip to content

Interner - #299

Open
stefnotch wants to merge 10 commits into
mainfrom
interner
Open

stefnotch wants to merge 10 commits into
mainfrom
interner

Conversation

@stefnotch

@stefnotch stefnotch commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Adds interning to wesl-rs. It's split into smaller commits that should be easier to review.

It first adds an Arena and UniqueArena. They're based on the ones in naga. The Arena isn't actually used.
This also meant adding the dependencies for #292 .

Then it adds a TyContext, which holds the UniqueArena<StructType> everywhere where it will be needed.

In the next step, it actually starts using the TyContext.

And finally, it updates the printing stuff. Turns out that printing types now depends on the TyContext. Which in turn means that error messages depend on the TyContext.
While doing that final step, I also separated the Error and Diagnostic<E> types a bit better. There's no reason to allow a recursive tree of Error::Error(Diagnostic { another error with a diagnostic with another error with a diagnostic ... })

@stefnotch

Copy link
Copy Markdown
Contributor Author

The wesl crate already builds, but all the crates that use it are broken. To print an error, one now needs a &TyContext

I did look at what Naga does, but Naga doesn't do anything useful in this case https://docs.rs/naga/latest/src/naga/valid/type.rs.html#114-115 .

@stefnotch
stefnotch force-pushed the interner branch 4 times, most recently from 2100d7b to cbd2b80 Compare September 19, 2026 21:00
@stefnotch
stefnotch marked this pull request as ready for review September 21, 2026 09:12

@k2d222 k2d222 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

incomplete review pass. Will finish review later :)

overall it looks promising, didn't see anything wrong with it.

Comment thread crates/wesl-cli/src/main.rs Resolved
Comment thread crates/wesl-cli/src/main.rs Resolved
Comment thread crates/wesl/src/pass/condcomp.rs Resolved
Comment thread crates/wesl/src/pass/lower.rs Resolved
Comment thread crates/wesl/src/error.rs Resolved
Comment thread crates/wesl/src/error.rs Resolved
Comment thread crates/wesl/src/error.rs
Comment on lines +467 to +468
_sourcemap: Option<&impl SourceMap>,
_mangler: Option<&impl Mangler>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

dont' need underscores I think

Comment thread crates/wesl/src/error.rs Resolved
match self {
Type::Struct(ty) => ty,
val => panic!("called `Type::unwrap_struct()` on a `{val}` value"),
val => panic!("called `Type::unwrap_struct()` on a `{val:?}` value"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we implement Display for Type with a fallback string for if it requires the arena? Looks like only struct types need the arena.

@stefnotch
stefnotch force-pushed the interner branch 2 times, most recently from 8fb6849 to babddd2 Compare October 25, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants