In this line, I read it as a Module does not have inner items, can someone explain why that is the case?
Contrasting, ast::Item::Func does have inner items
Good question @kev !
I think the primary reason is historical -- items nested in fn's and module items are treeted differently higher in the stack (CrateDefMap)
But I guess on the ItemTree level it might make sense to unify the representation? @Jonas Schievink , do you think we can maybe use some smart encoding here?
Like, flattening all items in a single array, and using some indexing scheme to infer the tree structure?
Not really sure how that would look, I'm not very good with algorithms :)
I guess you're imagining something like how you can store a binary heap in a linear array, and use indices to navigate it?
The encoding would have to be more complicated, as that's n-ary tree
But something like this would contain all the requred information:
item_tree: Vec<(usize, Item)>
usize is the index of parent
An alternative would be
Vec<(Item, ops::Range<usize>)>, where the range specifies the children
Do we need to update those (e.g. to add children)?
Not really, we build the thing once
Ahh I see, thank you for explaining @matklad :) Peeking into CrateDefMap now
Hmm oh I think I understand fully, items inside of a function cannot be called from outside of that scope, but items in mod can, so I guess you needed a way to represent this distinction. So modules have their own Scope Variant