Asset per file scheme, stage 2#70
Conversation
…added in previous commits), also minimize places using `Symbols`
… statement conflicts with an asset identifiers in the current file
…should_panic test for explicit ref type being wrong when referencing something from another file that is already registered
This pass pre-registers asset/module paths, so we can properly resolve the full path of reference to asset which has yet to be processed in the next pass (where types of assets are resolved). The full path needs to be resolved so that delayed resolution of types can happen without the Symbols structure being available. This would be difficult since the delayed resolution handles assets across multiple files. Part of this change is duplicating structures from `BaubleContext` so we can represent the pending asset/module paths but without requiring that assets have a known type. This is done in the new `early_context` module.
…re specific when referenced asset fails to be registerer, and test that local assets will be suggsted in errors
…distinguishing local objects.
local objects from BaubleContext, and prevent them from being referenced outside the current file. ObjectPath uses enum variants to distinguish top-level, local, and inline objects. Objects of different kinds can now have the same path without colliding.
…t is now required
Imberflur
left a comment
There was a problem hiding this comment.
Here are notes for reviewers, and a few cleanup tasks for myself.
| emitter.emit(Rich::custom( | ||
| ident.span, | ||
| format!( | ||
| "The first item must have '{}' as the identifier", |
There was a problem hiding this comment.
We now required the first object to be a top level object and subsequent objects must not use the special identifier.
| } | ||
| } | ||
|
|
||
| if path.is_empty() { |
There was a problem hiding this comment.
moved all the code down past the inner function definitions so it is easier to follow
| /// `ident`, the refs from these will be combined (potentially overriding each other). | ||
| // | ||
| // TODO: couldn't this overriding lead to unexpected behavior? Should we return an error when | ||
| // there are multiple results in the same namespace? |
There was a problem hiding this comment.
TODO resolved by producing an error on ambiguity
| /// | ||
| /// Contains registery of local objects. These are objects that are only referencable by other | ||
| /// objects in the same file. | ||
| pub(crate) struct LocalContext { |
There was a problem hiding this comment.
Local objects are now registered in this ephemeral context type instead of BaubleContext. It only exists during the loading process.
This ended up being a super simple type!
| /// | ||
| /// Path format documented in [`TypePath`]. | ||
| #[derive(Copy, Clone, Debug)] | ||
| pub enum ObjectPath<S = String> { |
There was a problem hiding this comment.
New ObjectPath enum, I hope the docs are sufficient explanation.
There was a problem hiding this comment.
It might be helpful to have examples of what the contents of each variant might look like.
There was a problem hiding this comment.
Added a set of examples
| /// The inner representation of a type path created by this allocator. | ||
| type TypePathInner: 'static; | ||
| /// The inner representation of an object path created by this allocator. | ||
| type PathInner: 'static; |
There was a problem hiding this comment.
renamed for clarity
| let a = &test_file!( | ||
| "a", | ||
| r#"test = integration::Test { x: -5, y: 5 }"#, | ||
| r#"0 = integration::Test { x: -5, y: 5 }"#, |
There was a problem hiding this comment.
all the tests needed updating for the new syntax
|
Testing whether I can comment without it being on a specific line. |
This follows up from #69
Main changes
0identifier is introduced for top level objects so their name does not need to be repeated from the file name.BaubleContext(similarly to inline objects). E.g.BaubleContext::assetsnow only lists top level objects.ObjectPathenum instead of being plainTypePaths. The enum has 3 variants:Top,Local, andInline. Uses of atop_levelbool were replaced with this.Other changes
path::*::identnow produces an error when multiple items could be referenced by it instead of selecting one of those items