Stream: announcements

Topic: breaking changes: operator desugaring and shadowing


view this post on Zulip Richard Feldman (Nov 12 2026 at 15:06):

I found a problem with the way we were doing default-number resolution.

view this post on Zulip Richard Feldman (Nov 12 2026 at 15:06):

as an example, in #12228, argv.fold(0, |size, arg| size + arg.to_utf8().len() did not have enough type information for the compiler to figure out what type size should have, because size + arg.to_utf8().len() desugars to size.plus(arg.to_utf8().len()) and the only type information it has about size at that point is that it starts at 0 (from the first argument to fold) - so it's a number, but it could be any number, even a custom user-defined number!

we used to require that when desugaring operators, the plus method call we desugared + into would be required to have the type a, a -> a - so, its arguments and return type are all the same type. That fixes this case (because arg.to_utf8().len() returns U64, which in turn means size must be U64, and size.plus(...) resolves to U64.plus(...) - but that relies on plus having the constraint of "both arguments and the return type have the same type.")

view this post on Zulip Richard Feldman (Nov 12 2026 at 15:07):

we changed this so that operator desugaring could be more flexible, e.g. so a Duration could support * on a U64, e.g. my_duration * 12 instead of requiring the 12 to also have the type Duration

view this post on Zulip Richard Feldman (Nov 12 2026 at 15:08):

and there was another thread on Zulip somewhere (I forget where offhand) where there was interest in relaxing this all the way to just a + b desugars to a.plus(b)

view this post on Zulip Richard Feldman (Nov 12 2026 at 15:09):

I discovered there are some pretty substantial performance downsides to the sort of "in-between" approach we were doing for this, where we partially constrained the desugared methods and then also had some builtin-specific special-cases (for number types other than Dec)

view this post on Zulip Richard Feldman (Nov 12 2026 at 15:10):

I think this is going to be a bit of a design rabbit hole, weighing the tradeoffs and compiler perf, so for 0.1.0 I've decided to go back to the option that has the best compiler perf (and also works the best for the builtin number types and "normal" custom numbers) even though it's the least flexible in terms of user-defined types: require a, a -> a for plus and similar

view this post on Zulip Richard Feldman (Nov 12 2026 at 15:11):

this will give everyone the best build times (and number literals and arithmetic come up a lot, so degrading perf for them is not a small downside) and also the fewest incidents of type errors due to the compiler not knowing which type you meant (such as the example from the issue above)

view this post on Zulip Richard Feldman (Nov 12 2026 at 15:12):

then from that baseline, we can discuss motivating examples (like Duration) that could justify changing the desugaring rules, what it would cost in terms of compiler perf and examples like the issue here becoming compiler errors vs. the benefits, etc. - sometime after 0.1.0 ships

view this post on Zulip Richard Feldman (Nov 12 2026 at 15:13):

in the immediate term, that will be a breaking change, because stuff like Duration will need to change its types

view this post on Zulip Richard Feldman (Nov 12 2026 at 15:13):

this hasn't landed yet, but I wanted to announce it in advance since it's coming

view this post on Zulip Richard Feldman (Nov 12 2026 at 15:15):

separately, there's another breaking change which hopefully will be pretty minor: I discovered that shadowing rules weren't being applied correctly in nested type declarations. so if you have nested type declarations, once that lands, you might start seeing shadowing warnings for things that were always shadowing but which previously didn't cause a warning.

view this post on Zulip Notification Bot (Nov 12 2026 at 17:53):

11 messages were moved from this topic to #ideas > requiring more type annotations? by Anton.

view this post on Zulip notramo (Nov 12 2026 at 19:32):

and there was another thread on Zulip somewhere (I forget where offhand) where there was interest in relaxing this all the way to just a + b desugars to a.plus(b)

#beginners > Binary search / Interpolation search

view this post on Zulip Aurélien Geron (Nov 18 2026 at 04:34):

The shadowing change seems to have introduced a regression: when the same function is defined in a type and its nested type, then we get a duplicate definition warning, even though these are two different types. In some cases, it's easy to work around this issue by just renaming one function, but when it's a special function (e.g., is_eq), then there's no workaround. This broke 3 Exercism exercises. I filed issue #13192.

view this post on Zulip Richard Feldman (Nov 18 2026 at 12:29):

oh I changed the builtins to demonstrate this - what you do is move the nested type definition to the top level, and then make an alias to the type be what's nested

view this post on Zulip Richard Feldman (Nov 18 2026 at 12:29):

I'm not sure if that's the design we'll go with long-term, but I want to try it out. so far it feels fine for builtins but I want to see how it feels in broader use.


Last updated: Nov 26 2026 at 20:35 UTC