Skip to content

Commit 532eb35

Browse files
committed
Prepare groundwork for 0.5 dev post
1 parent 8591a03 commit 532eb35

File tree

1 file changed

+116
-0
lines changed
  • website/content/dev/05-update-wip

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
+++
2+
# Copyright (c) godot-rust; Bromeon and contributors.
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
title = "0.5 dev update WIP"
8+
authors = ["Bromeon", "godot-rust contributors"]
9+
10+
[extra]
11+
summary = "v0.5 WIP"
12+
tags = ["dev-update"]
13+
+++
14+
15+
This is WIP for **0.5** update!
16+
17+
Last time we started writing it a bit too late, making it a little too painful to account for&describe everything.
18+
19+
Existence of this PR doesn't mean that we want to release 0.5 anytime soon, duh – it only means that we won't spend 2 days analyzing&documenting the changes.
20+
21+
22+
# Performance
23+
24+
## The Paranoid, The Balanced and Very Unsafe
25+
26+
Godot-rust now supports three tiers that differ in the amount of runtime checks and validations that are performed:
27+
28+
### 🛡️ **Strict**
29+
30+
Default for dev builds. Performs lots of additional, sometimes expensive checks, but allows to detect many bugs during development.
31+
32+
- Gd::bind/bind_mut() provides extensive diagnostics to locate runtime borrow errors.
33+
- Array safe conversion checks (for types like Array<i8>).
34+
- RTTI checks on object access (protect against type mismatch edge cases).
35+
- Geometric invariants (e.g. normalized quaternions).
36+
- Access to engine APIs outside valid scope.
37+
38+
### ⚖️ Balanced
39+
40+
Default for release builds. Performs basic validity and invariant checks, reasonably fast.
41+
Within this level you should not be able to encounter undefined behavior (UB) in safe Rust code.
42+
Invariant violations may however cause panics and logic errors.
43+
44+
- Object liveness checks.
45+
- Gd::bind/bind_mut() cause panics on borrow errors.
46+
47+
### ☣️ Disengaged
48+
49+
Disables most checks, sacrificing safety for raw speed.
50+
This renders a large part of the godot-rust API `unsafe` without polluting the code; you opt in via `unsafe impl ExtensionLibrary`.
51+
52+
Before using this, measure to ensure you truly need the last bit of performance (balanced should be fast enough for most cases; if not, consider bringing it up).
53+
Also test your code thoroughly using the other levels first. Undefined behavior and crashes arising from using this level are your full responsibility.
54+
When reporting a bug, make sure you can reproduce it under the balanced level.
55+
56+
- Unchecked object access -> instant UB if an object is dead.
57+
- Gd::bind/bind_mut() are unchecked -> UB if mutable aliasing occurs.
58+
59+
### Cargo features
60+
61+
You can downgrade 1 level in each `dev` (Debug) and `release` Cargo profiles, with following features:
62+
63+
- `safeguards-dev-balanced`: for `dev`, use ⚖️ **balanced** instead of the default strict level.
64+
- `safeguards-release-disengaged`: for `release`, use ☣️ **disengaged** instead of the default balanced level.
65+
66+
Thanks to @beicause for making bulk work for this feature! #1278
67+
68+
#1278: https://github.com/godot-rust/gdext/pull/1278
69+
70+
## Faster calls for Callables
71+
72+
Thanks to @lyonbeckers Rust Callables received significant improvement – making calling `Callable::from_fn` twice as fast as it was in `0.4`!
73+
74+
[#1331]: https://github.com/godot-rust/gdext/pull/1331
75+
76+
## Simple API to cache and fetch Autoloads
77+
78+
Godot [autoloads][godot-docs-autoload] can be now fetched and cached using higher-level convenience function – `get_autoload_by_name`.
79+
Thanks to it Godot autoloads can be easily accessed anywhere in the scope, even outside the scene tree – including calls from Callables and Objects.
80+
81+
To create rust autoload firstly create a scene with your rust Node in it and add it as an autoload in project settings.
82+
Afterwards it can be accessed via its name and will be cached on the very first use.
83+
84+
```rust
85+
pub fn stage() -> Gd<Stage> {
86+
get_autoload_by_name("StageAutoload")
87+
}
88+
89+
#[derive(GodotClass)]
90+
#[class(init, base = Node)]
91+
pub struct Stage {
92+
#[var]
93+
level: Option<Gd<Level>>,
94+
}
95+
```
96+
97+
Thanks to @bromeon for implementing this feature and @ValorZard for testing it! ([#1381])
98+
99+
100+
[#1381]: https://github.com/godot-rust/gdext/pull/1381
101+
102+
## Improvements for macro-generated signatures
103+
104+
Multiple improvements for macro-generated signatures has been implemented:
105+
106+
- Docs for signals are now being preserved, allowing to inspect them in IDEs ([#1353]).
107+
- Docs in `#[godot_api(secondary)]` blocks are now properly preserved and registered ([#1355]).
108+
- Compile errors caused by wrong signature in `InterfaceTraits` now properly point to user code ([#1370], [#1373], [#1382]).
109+
110+
[#1353]: https://github.com/godot-rust/gdext/pull/1353
111+
[#1355]: https://github.com/godot-rust/gdext/pull/1355
112+
[#1370]: https://github.com/godot-rust/gdext/pull/1370
113+
[#1373]: https://github.com/godot-rust/gdext/pull/1373
114+
[#1382]: https://github.com/godot-rust/gdext/pull/1382
115+
116+
[godot-docs-autoload]: https://docs.godotengine.org/en/latest/tutorials/scripting/singletons_autoload.html

0 commit comments

Comments
 (0)