Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Existentials: "x as some_iface" promotion makes polymorphic fns monomorphise wrong #2734
It runs without segfaulting if the call in deadcode() is commented out. That call causes perform_hax(x) to get monomorphised to promote x as hax as though x were @str. With the call gone, the first monomorphisation happens at main's call, for @int.
It runs without segfaulting if deadcode() and main() are reordered lexicographically, for the same reason as above.
It runs without segfaulting if perform_hax is manually inlined (so that there are two '... as hax').
It runs without segfaulting if "let _ =" is removed in main. Filing a separate issue for that.
referenced this issue
Jun 28, 2012
Problem seems to be more general than existentials (still to do with monomorphising). I've also run into it (i.e., presence or absence of deadcode toggles segfaults) with two other open-coded approaches to implementing similar functionality, all with @-boxes.
(edit: although note that both of those involved unsafe::transmute, and i'm not sure i could reproduce without either iface or transmute.)
Backing up that this is because of monomorphizing, the following hand-monomorphized version of the code doesn't leak:
I have a hypothesis about what the bug is, but I'll keep digging.
Perhaps more illuminating than your code (i.e., narrowing it down) -- if you change it to this, it still doesn't crash:
(and then of course if you change deadcode to call perform_hax_int, it starts crashing again)