Bug or optimisation
The following code:
indicates that both initialised empty struct has the same address. Are empty structs automatically "singleton"? Or is it a bug in the compiler? I am using Mac M1.
4 Replies
mojo 24.4.0 (2cb57382)
This looks like the compiler is seeing that the constructor is pure and deciding to de-duplicate it because you never modify either instance.
Thanks! I was not aware compilers perform this optimisation.
Compilers like to look for places to de-duplicate work because you can save a lot of processing if you can pull it off. In your case it’s trivial work, but if each constructor needed to calculate the first 200 primes or something like that, you would see noticeable performance increases.