You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
The following code produces a stack overflow at runtime, only when optimizations are turned off.
The behavior that occurs once optimizations are turned on is odd, too: "called Option::unwrap() on a None value" even though I don't see any way a None could possibly be produced, but presumably LLVM eliminates the recursive call to testcase::&'a T.Tag::to_tag somehow and the stack overflow doesn't occur anymore.
use std::sync::Arc;pubtraitTag{fnto_tag(&self) -> Option<Arc<String>>;}implTagforArc<String>{fnto_tag(&self) -> Option<Arc<String>>{Some(self.clone())}}implTagforString{fnto_tag(&self) -> Option<Arc<String>>{Some(Arc::new(self.clone()))}}impl<'a>Tagfor&'astr{fnto_tag(&self) -> Option<Arc<String>>{Some(Arc::new(self.to_string()))}}impl<'a,T:Tag>Tagfor&'aT{fnto_tag(&self) -> Option<Arc<String>>{self.to_tag()}}impl<T:Tag>TagforOption<T>{fnto_tag(&self) -> Option<Arc<String>>{self.as_ref().and_then(|t| t.to_tag())}}fnmain(){let tag = "hello".to_tag();println!("{}",*tag.as_ref().to_tag().unwrap())}
Snippet of gdb backtrace:
#0 0x000000000045561a in rust_stack_exhausted ()
#1 0x00000000004050e1 in __morestack ()
#2 0x0000000000404f61 in testcase::&'a T.Tag::to_tag (self=0x7fffffffc810) at testcase.rs:27
#3 0x0000000000404f61 in testcase::&'a T.Tag::to_tag (self=0x7fffffffc810) at testcase.rs:27
#4 0x0000000000404f61 in testcase::&'a T.Tag::to_tag (self=0x7fffffffc810) at testcase.rs:27
...
Obviously this can just be fixed by correcting that particular implementation to:
I've been tripped up by this too, I've thought about writing a lint that detects when a function/method is being called directly inside itself on the same arguments but never got around to it; I don't think it would be too hard, but I'm not sure. (Happy to mentor if someone feels like doing this; find me here, on IRC as huon or via email (in my github profile).)
but presumably LLVM eliminates the recursive call to testcase::&'a T.Tag::to_tag somehow
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
The following code produces a stack overflow at runtime, only when optimizations are turned off.
The behavior that occurs once optimizations are turned on is odd, too: "called
Option::unwrap()
on aNone
value" even though I don't see any way a None could possibly be produced, but presumably LLVM eliminates the recursive call totestcase::&'a T.Tag::to_tag
somehow and the stack overflow doesn't occur anymore.Snippet of gdb backtrace:
Obviously this can just be fixed by correcting that particular implementation to:
but I feel like the compiler should be able to detect this and either resolve the cycle or throw an error.
The text was updated successfully, but these errors were encountered: