Skip to content

Rust hidden sealed subs - #617

Merged
tjpalmer merged 3 commits into
mainfrom
rust-hidden-sealed-subs
Oct 12, 2026
Merged

tjpalmer merged 3 commits into
mainfrom
rust-hidden-sealed-subs

Conversation

@tjpalmer

Copy link
Copy Markdown
Contributor

Signed-off-by: Tom <tom@temper.systems>
Signed-off-by: Tom <tom@temper.systems>
Signed-off-by: Tom <tom@temper.systems>
append("time = { version = \"=0.3.41\", optional = true }\n")
append("ureq = { version = \"=3.1.2\", optional = true }\n")
// Here down are transitive dependencies that need versions locked.
append("powerfmt = { version = \"=0.2.0\", optional = true }\n")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Another magic breakage that happened in the past day or three.

val crateScope = Rust.VisibilityScope(pos, Rust.VisibilityScopeOption.Crate)
val pubCrate = Rust.VisibilityPub(pos, scope = crateScope)
add(Rust.Use(pos, supportId.deepCopy().extendWith("*")).toItem(pub = pubCrate))
add(Rust.Use(pos, supportId.deepCopy().extendWith("*")).toItem(pub = pubCrate(pos)))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Extracted a helper.

* - https://releases.rs/docs/1.70.0/ - Jun 2023, OnceLock
* - https://releases.rs/docs/1.71.1/ - Aug 2023, Required for ureq
* - https://releases.rs/docs/1.85.0/ - Feb 2025, Rust 2024, cargo also defaults to looking at rust-version
* - https://releases.rs/docs/1.85.1/ - Mar 2025, Fixes some regressions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We might want to update to 1.85 soon, but that was out of scope here.

hasAnyInternalSealedSubs.add(topLevel.name.name)
}
continue@decls
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't know if set lookup is faster or not, but n^2 checking on every sealed subtype translation also felt wrong.

if (supDecl?.parts?.metadataSymbolMap?.contains(sealedTypeSymbol) == true) {
if (
supDecl?.parts?.metadataSymbolMap?.contains(sealedTypeSymbol) == true &&
supShape.name !in hasAnyInternalSealedSubs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Like here we'd be iterating every super's sealed subtypes for every sealed subtype. Common case is few, but what if there were 50 sometime or something.

val name = translateTypeOutName(decl.name.name)
val id = name.toId(decl.name.pos)
val enumId = when {
// TODO Only if all sealed subtypes are public?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TODONE.

val pub = when {
decl.typeShape.name in hasAnyInternalSealedSubs -> pubCrate(pos)
else -> chooseVisibility(decl)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And here's where I've chosen to keep the enum defined but just not pub it outside the crate.

|}
|pub (crate) enum ExportedSealedEnum {
| InternalSub(InternalSub), ExportedSub(ExportedSub)
|}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Enum now pub(crate) instead of pub. The enum isn't currently used at all when hidden, but I like seeing it for reference, and it doesn't cost much.

| return selfish;
| }
|}
|impl ExportedSealedTrait for ExportedSub {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And no as_enum on any of these.


But don't export the subtype. This was breaking be-rust.

class SSub<T extends I>(public thing: T) extends SI<T> {}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The export above broke this in be-rust before this pr.

@tjpalmer
tjpalmer marked this pull request as ready for review October 10, 2026 13:03
@tjpalmer
tjpalmer merged commit 2b061dd into main Oct 12, 2026
2 checks passed
@tjpalmer
tjpalmer deleted the rust-hidden-sealed-subs branch October 12, 2026 18:41
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.

Rust internal subclass of sealed interface breaks

2 participants