5 ms·
I have actually requested an even more intelligent/aggressive size optimization for nested enums, where values are automatically reassigned to not coincide/conf
by ComputerGuru 1y ago
I have actually requested an even more intelligent/aggressive size optimization for nested enums, where values are automatically reassigned to not coincide/conflict to enable tag-less differentiation. Consensus was that it’s a big ask though doable, but maybe possible to implement in a more restrictive version.
https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Suboptimal.20size.20of.20nested.20discriminated.20unions.2Fnested.20e.2E.2E.2E/near/440676847 https://rust-lang.zulipchat.com/#narrow/channel/131828-t-com...
- infogulch 1y agoGood idea! I like the solution of an explicit annotation setting the first variant's discriminant (the rest autoicrement?), which enables you to manually coordinate your enums to not overlap. Then an optimization for nested enums where if all cases are other enums with no overlapping discriminants they can all share one field. This seems achievable. The "but do it automatically" part seems rather problematic. Requiring global analysis is a big ask indeed. Say, if you change a variant's discriminant value, does that count as a semver breaking change? Probably. Would it be an ABI breaking change? Probably.