-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Existentials: "x as some_iface" promotion makes polymorphic fns monomorphise wrong #2734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
note: I believe this to be an issue in the monomorphisation implementation, rather than an inherent flaw of the type system. |
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) |
I believe this is a bug in type_use. I'll keep investigating further. |
Awesome detective work here. |
Good work on @bblum 's part as well for coming up with the test case! |
This segfaults:
When the destructor for _ runs at the end of main, it tries to destroy @42 as though it were an @str, causing a call to free((void*)42).
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.
The text was updated successfully, but these errors were encountered: