Skip to content

Instantly share code, notes, and snippets.

@matklad

matklad/ires.rs Secret

Created July 27, 2020 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matklad/145c88131282e8392e64d088ee8a50e4 to your computer and use it in GitHub Desktop.
Save matklad/145c88131282e8392e64d088ee8a50e4 to your computer and use it in GitHub Desktop.
//! Abstract import resolution
use std::hash::Hash;
use ra_arena::{Arena, Idx};
use rustc_hash::FxHashMap;
type Name = hir_expand::name::Name;
type Def = u32;
struct Scopes {
scopes: Arena<ScopeData>,
links: Vec<Link>,
}
type Scope = Idx<ScopeData>;
struct ScopeData {
defs: PerNs<FxHashMap<Name, Def>>,
}
struct Import {
anchor: ImportAnchor,
path: Vec<Name>,
what: ImportSpec,
}
enum ImportAnchor {
None,
Ancestor(u32),
Crate,
Abs,
}
enum ImportSpec {
All,
Name { name: Name, alias: Option<Option<Name>> },
}
struct PerNs<T> {
types: T,
values: T,
macros: T,
}
struct Resolver {
scopes: Scopes,
}
struct Link {
from: Scope,
to: Scope,
what: ImportSpec,
}
impl Resolver {
fn add_scope() -> Scope {
todo!()
}
fn add_def(&mut self, scope: Scope, name: Name, def: PerNs<Def>) {
todo!()
}
fn add_import(&mut self, scope: Scope, import: Import) {
todo!()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment