mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
internal: explain why we avoid serializing everything
This commit is contained in:
parent
4b6651a1d1
commit
6a0f7f0852
3 changed files with 19 additions and 2 deletions
|
@ -67,7 +67,10 @@ impl SourceRoot {
|
|||
/// Note that `CrateGraph` is build-system agnostic: it's a concept of the Rust
|
||||
/// language proper, not a concept of the build system. In practice, we get
|
||||
/// `CrateGraph` by lowering `cargo metadata` output.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
///
|
||||
/// `CrateGraph` is `!Serialize` by design, see
|
||||
/// <https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/architecture.md#serialization>
|
||||
#[derive(Debug, Clone, Default /* Serialize, Deserialize */)]
|
||||
pub struct CrateGraph {
|
||||
arena: FxHashMap<CrateId, CrateData>,
|
||||
}
|
||||
|
|
|
@ -457,3 +457,17 @@ It is not cheap enough to enable in prod, and this is a bug which should be fixe
|
|||
rust-analyzer strives to be as configurable as possible while offering reasonable defaults where no configuration exists yet.
|
||||
There will always be features that some people find more annoying than helpful, so giving the users the ability to tweak or disable these is a big part of offering a good user experience.
|
||||
Mind the code--architecture gap: at the moment, we are using fewer feature flags than we really should.
|
||||
|
||||
### Serialization
|
||||
|
||||
In Rust, it is easy (often too easy) to add serialization to any type by adding `#[derive(Serialize)]`.
|
||||
This easiness is misleading -- serializable types impose significant backwards compatability constraints.
|
||||
If a type is serializable, then it is a part of some IPC boundary.
|
||||
You often don't have control over the over side of this boundary, so changing serializable types are hard.
|
||||
|
||||
For this reason, the types in `ide`, `base_db` and bellow are not serializable by design.
|
||||
If such types need to cross an IPC boundary, then the client of rust-analyzer needs to provide custom, client-specific serialization format.
|
||||
This isolates backwards compatibility and migration concerns to a specific client.
|
||||
|
||||
For example, `rust-project.json` is it's own format -- it doesn't include `CrateGraph` as is.
|
||||
Instead, it creates a `CrateGraph` by calling appropriate constructing functions.
|
||||
|
|
|
@ -292,7 +292,7 @@ impl Person {
|
|||
|
||||
**Rationale:** we don't provide public API, it's cheaper to refactor than to pay getters rent.
|
||||
Non-local code properties degrade under change, privacy makes invariant local.
|
||||
Borrowed own data discloses irrelevant details about origin of data.
|
||||
Borrowed owned types (`&String`) disclose irrelevant details about internal representation.
|
||||
Irrelevant (neither right nor wrong) things obscure correctness.
|
||||
|
||||
## Useless Types
|
||||
|
|
Loading…
Reference in a new issue