Skip to content
2 changes: 1 addition & 1 deletion compiler/qsc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use qsc_frontend::compile::{
};

pub mod resolve {
pub use qsc_frontend::resolve::Res;
pub use qsc_frontend::resolve::{Local, LocalKind, Locals, Res};
}

pub mod fir {
Expand Down
12 changes: 7 additions & 5 deletions compiler/qsc_frontend/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod preprocess;
use crate::{
error::WithSource,
lower::{self, Lowerer},
resolve::{self, Names, Resolver},
resolve::{self, Locals, Names, Resolver},
typeck::{self, Checker, Table},
};
use bitflags::bitflags;
Expand Down Expand Up @@ -105,6 +105,7 @@ pub struct AstPackage {
pub package: ast::Package,
pub tys: Table,
pub names: Names,
pub locals: Locals,
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -335,7 +336,7 @@ pub fn compile(
ast_assigner.visit_package(&mut ast_package);
AstValidator::default().visit_package(&ast_package);
let mut hir_assigner = HirAssigner::new();
let (names, name_errors) = resolve_all(
let (names, locals, name_errors) = resolve_all(
store,
dependencies,
&mut hir_assigner,
Expand Down Expand Up @@ -365,6 +366,7 @@ pub fn compile(
package: ast_package,
tys,
names,
locals,
},
assigner: hir_assigner,
sources,
Expand Down Expand Up @@ -526,7 +528,7 @@ fn resolve_all(
assigner: &mut HirAssigner,
package: &ast::Package,
mut dropped_names: Vec<TrackedName>,
) -> (Names, Vec<resolve::Error>) {
) -> (Names, Locals, Vec<resolve::Error>) {
let mut globals = resolve::GlobalTable::new();
if let Some(unit) = store.get(PackageId::CORE) {
globals.add_external_package(PackageId::CORE, &unit.package);
Expand All @@ -544,9 +546,9 @@ fn resolve_all(
let mut errors = globals.add_local_package(assigner, package);
let mut resolver = Resolver::new(globals, dropped_names);
resolver.with(assigner).visit_package(package);
let (names, mut resolver_errors) = resolver.into_names();
let (names, locals, mut resolver_errors) = resolver.into_result();
errors.append(&mut resolver_errors);
(names, errors)
(names, locals, errors)
}

fn typeck_all(
Expand Down
3 changes: 3 additions & 0 deletions compiler/qsc_frontend/src/incremental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl Compiler {
ast: AstPackage {
package: ast,
names: self.resolver.names().clone(),
locals: self.resolver.locals().clone(),
tys: self.checker.table().clone(),
},
hir,
Expand Down Expand Up @@ -163,6 +164,7 @@ impl Compiler {
ast: AstPackage {
package: ast,
names: self.resolver.names().clone(),
locals: self.resolver.locals().clone(),
tys: self.checker.table().clone(),
},
hir,
Expand All @@ -178,6 +180,7 @@ impl Compiler {
// replace the current tables instead of extending.
unit.ast.names = new.ast.names;
unit.ast.tys = new.ast.tys;
unit.ast.locals = new.ast.locals;

// Update the HIR
extend_hir(&mut unit.package, new.hir);
Expand Down
86 changes: 85 additions & 1 deletion compiler/qsc_frontend/src/incremental/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,61 @@ fn one_callable() {
node_id:2,node_id:5,node_id:8,
terms:
node_id:6,node_id:10,
locals:
Locals {
scopes: [
Scope {
span: Span {
lo: 0,
hi: 4294967295,
Comment thread
ScottCarda-MS marked this conversation as resolved.
},
kind: Block,
opens: {},
tys: {},
terms: {},
vars: {},
ty_vars: {},
},
Scope {
span: Span {
lo: 0,
hi: 44,
},
kind: Namespace(
"Foo",
),
opens: {},
tys: {},
terms: {},
vars: {},
ty_vars: {},
},
Scope {
span: Span {
lo: 16,
hi: 42,
},
kind: Callable,
opens: {},
tys: {},
terms: {},
vars: {},
ty_vars: {},
},
Scope {
span: Span {
lo: 40,
hi: 42,
},
kind: Block,
opens: {},
tys: {},
terms: {},
vars: {},
ty_vars: {},
},
],
}
hir:
Package:
Item 0 [0-44] (Public):
Expand Down Expand Up @@ -84,6 +139,30 @@ fn one_statement() {
node_id:3,
terms:
node_id:1,node_id:2,node_id:3,node_id:4,
locals:
Locals {
scopes: [
Scope {
span: Span {
lo: 0,
hi: 4294967295,
},
kind: Block,
opens: {},
tys: {},
terms: {},
vars: {
"q": (
16,
NodeId(
3,
),
),
},
ty_vars: {},
},
],
}
hir:
Package:
Stmt 0 [0-16]: Qubit (Fresh)
Expand Down Expand Up @@ -366,10 +445,15 @@ fn check_unit(expect: &Expect, actual: &Increment) {
output
})
);
let locals = format!("\nlocals:\n{:#?}", actual.ast.locals);
Comment thread
minestarks marked this conversation as resolved.

let hir = format!("\nhir:\n{}", actual.hir);

expect.assert_eq(&[ast, names, terms, hir].into_iter().collect::<String>());
expect.assert_eq(
&[ast, names, terms, locals, hir]
.into_iter()
.collect::<String>(),
);
}

fn fail_on_error(errors: Vec<Error>) -> Result<(), Vec<Error>> {
Expand Down
Loading