amethyst / amethyst/legion

Soundness issue with random access API within a system

未关闭
#129 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
1.7k
派生
140
PR 合并指标
30 天内没有已合并 PR

描述

The following snippet demonstrates the issue (only occurs when building with `--release`):

```rust
use legion::prelude::*;

fn main() {
let mut world = World::new();

world.insert((), Some((14u32,)));

let query = >::query();
let system = SystemBuilder::new("soundness issue")
.write_component::()
.with_query(query)
.build(|_, world, _, query| {
for (entity, mut number) in query.iter_entities(world) {
dbg!(&number); // prints 14
*number += 1;
dbg!(&number); // prints 15

let mut number2 = world.get_component_mut::(entity).unwrap();
dbg!(&number); // prints 15
dbg!(&number2); // prints 15
*number2 += 1;

dbg!(&number); // prints 16
dbg!(&number2); // prints 16
}
});

system.run(&world);
}
```

As far as I can tell this is due to some lifetime issue in `Query::iter_entities` or the fact that runtime borrow checking is disabled in release builds. While I am not against such an optimization, this clearly violates Rust's soundness and aliasing guarantees.

For users who still need/want such an optimization, would it be possible to make this an opt-in feature instead? This has the benefit of making potential issues more visible to the developer.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。