refactor declaration.rs to change conventions#425
refactor declaration.rs to change conventions#425jesse-shopify wants to merge 5 commits intomainfrom
Conversation
| // TODO: temporary hack to avoid crashing on `Struct.new`, `Class.new` and `Module.new` | ||
| } | ||
| _ => panic!("Tried to add member to a declaration that isn't a namespace"), | ||
| if let Some(namespace) = declaration.as_namespace_mut() { |
There was a problem hiding this comment.
cleaner, I think
| } | ||
| decl.as_namespace() | ||
| .expect("Tried to get members for a declaration that isn't a namespace") | ||
| .members() |
| #[derive(Debug)] | ||
| pub struct NamespaceDeclaration { | ||
| /// The base simple declaration fields | ||
| simple: SimpleDeclaration, |
There was a problem hiding this comment.
I tried this design earlier in the project and having this extra field for all definitions resulted in a lot more memory usage.
Could you compare main against your branch with --stats on a few corpus sizes?
You can produce test corpuses with https://github.com/Shopify/saturn/blob/main/utils/generate-corpus#L11.
There was a problem hiding this comment.
The data is below. There was no change in memory or runtime performance.
There was a problem hiding this comment.
In terms of API, I'm not a fan of having to go through simple depending on the field I want to access.
On the other hand, I do like the simplification around handling namespace related fields and avoiding the matches/panic. Could we get the same result with nested enums instead?
There was a problem hiding this comment.
The thing about Rust is that there are many ways to get to the same place and the only different is ergonomics. Nested enums could work. Another option to improve ergonomics might be Using Deref / DerefMut traits. Another option would be to have a SimpleDeclaration that has an optional, boxed NamespaceDeclaration, though I suppose that would add an extra 8 bytes to SimpleDeclaration but then Declaration might not need to box which could be a performance and memory win.
There was a problem hiding this comment.
I tried nested enums in #470, it's not horrible.
decd579 to
4942fc6
Compare
|
Memory usage using huge corpus: MainThis BranchNo significant change in memory usage. |
small refactors
| test_utils = ["dep:tempfile"] | ||
|
|
||
| [dependencies] | ||
| parking_lot = "0.12" |
There was a problem hiding this comment.
Added due to better lock API
main statsbranch stats |

as_simpleas_simple_mutas_namespaceas_namespace_mut