Repository navigation
Rust hidden sealed subs - #617
Conversation
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") |
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
We might want to update to 1.85 soon, but that was out of scope here.
| hasAnyInternalSealedSubs.add(topLevel.name.name) | ||
| } | ||
| continue@decls | ||
| } |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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? |
| val pub = when { | ||
| decl.typeShape.name in hasAnyInternalSealedSubs -> pubCrate(pos) | ||
| else -> chooseVisibility(decl) | ||
| } |
There was a problem hiding this comment.
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) | ||
| |} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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> {} |
There was a problem hiding this comment.
The export above broke this in be-rust before this pr.
@auto("==")on types #581 would perhaps enable all our RegexNode hierarchy to besealedand@auto("==")powerfmtcrate, used by thetimecrate