Hi!
Stumbled into kind of rust compiler believes citybound code is undefined behaviour for some reason. Hope there is something wrong with my setup, otherwise it would be a hard but interesting thing to track down )
so the bug:
creating some roads, then spawning cars on mac soon results in:
transfer lane not connected for obstacles yet
[1] 42607 illegal hardware instruction target/release/citybound
running under release lldb:
~/citybound master > lldb -- target/release/citybound
(lldb) run
All mapped
2017-12-16 12:42:17.346005+0100 citybound[42500:3746908] Month 13 is out of bounds
2017-12-16 12:42:17.405368+0100 citybound[42500:3746908] MessageTracer: load_domain_whitelist_search_tree:73: Search tree file's format version number (0) is not supported
2017-12-16 12:42:17.405397+0100 citybound[42500:3746908] MessageTracer: Falling back to default whitelist
2017-12-16 12:42:17.774650+0100 citybound[42500:3746908] Month 13 is out of bounds
Process 42500 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
frame #0: 0x00000001001482a5 citybound`kay::actor_system::ActorSystem::add_spawner::_$u7b$$u7b$closure$u7d$$u7d$::h0ad618cd037e08ef + 37
citybound`kay::actor_system::ActorSystem::add_spawner::_$u7b$$u7b$closure$u7d$$u7d$::h0ad618cd037e08ef:
-> 0x1001482a5 <+37>: ud2
0x1001482a7 <+39>: ud2
0x1001482a9 <+41>: nopl (%rax)
the previous instruction being
0x1001474c0 <+32>: callq 0x10019a980 ; citybound::core::simulation::kay_auto::SimulationID::wake_up_in::h30045977a0c501c4
I think rust compiler believes that everything after the call to wake_up_in would result in undefined bahaviour.
compiling with asm and mir output to get the source of the closure:
RUSTFLAGS=" --emit asm --emit=llvm-ir" cargo build --release
then grepping for the closure:
cd target/release
rg 'h0ad618cd037e08ef'
>
deps/citybound-47bb228c87096c93.citybound3-504d2d731c62cd7d7aeab2b09e40774b.rs.rcgu.s
88340:__ZN3kay12actor_system11ActorSystem11add_spawner28_$u7b$$u7b$closure$u7d$$u7d$17h0ad618cd037e08efE:
// reveals the asm location
less +88340 deps/citybound-47bb228c87096c93.citybound3-504d2d731c62cd7d7aeab2b09e40774b.rs.rcgu.s
which then has the reference to the file:
.file 76 "/Users/.../citybound/game/economy/households/family/mod.rs"
move_into method
in the move_into method there is a offers vec
vec![
Offer::new(
MemberIdx(0),
TimeOfDayRange::new(16, 0, 11, 0),
Deal::new(Some((Awakeness, 3.0)), Duration::from_hours(1)),
1,
true
),
].into(),
which gets converted to CVec.
altering the source to have this vec![] empty makes rust and llvm remove the undefined behaviour (ud2 instruction immedately after the call to wake_up_in) and generating the code after wake_up_in.
Unfortunately, this is all that I had time to dig, hope that helps!
I'll try to continue in the meantime.