Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow implicit top-level namespaces when parsing files #1416

Merged
merged 157 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 155 commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
016153c
wip
sezna Mar 14, 2024
b8a801e
wip
sezna Mar 18, 2024
a83a1e9
wip
sezna Mar 18, 2024
5d6a33a
wip
sezna Mar 18, 2024
e5ec193
wip
sezna Mar 18, 2024
a18ef5d
it builds??
sezna Mar 19, 2024
a041e58
wip
sezna Mar 19, 2024
4a644ef
wip: add nested namespace structure
sezna Mar 19, 2024
ac8745d
Switch to using new namespace API
sezna Mar 19, 2024
bf6561b
doc comment
sezna Mar 20, 2024
c571f2e
start working on converting HIR to new structure
sezna Mar 20, 2024
21fac31
wip: refactor core namespaces into namespace ids
sezna Mar 20, 2024
f52ed17
wip
sezna Mar 21, 2024
e6c15ba
wip
sezna Mar 21, 2024
2b1e51d
wip
sezna Mar 21, 2024
422542b
Refactor new namespace work into qsc_data_structures
sezna Mar 21, 2024
0b4069a
add more namespace ids
sezna Mar 25, 2024
b2c0f2f
Merge branch 'main' of github.com:microsoft/qsharp into alex/hns
sezna Mar 25, 2024
38327a9
wip: continue refactor of namespaceids
sezna Mar 25, 2024
261aa8a
update methods for namespace tree node
sezna Mar 25, 2024
3e6d39d
finish lining up types for completion lists
sezna Mar 26, 2024
71e3ddd
fmT
sezna Mar 26, 2024
dd1e312
introduce vecident to qsc_fir
sezna Mar 26, 2024
51eefa1
lower VecIdent for fir and hir
sezna Mar 26, 2024
2187506
remove todos from name locator and hover in lang service
sezna Mar 26, 2024
50ddf45
include prelude namespace IDs in default opens
sezna Mar 26, 2024
ee532c0
refactor opens to use string identifiers for namespaces instead of ids
sezna Mar 26, 2024
8713435
remove todos in completions
sezna Mar 26, 2024
0bcd526
implement get in name resolution
sezna Mar 26, 2024
a78fe73
continue work on resolve.rs
sezna Mar 26, 2024
5da2fb9
bind opens with namespace ids
sezna Mar 27, 2024
7c5b9d6
finish removing TODOs; work on unit testing
sezna Mar 27, 2024
01bcddc
namespace root traversals are working
sezna Mar 27, 2024
105e625
fmt
sezna Mar 27, 2024
f62b977
refactor namespaces into their own files
sezna Mar 27, 2024
8a11e1d
add forgotten test file
sezna Mar 27, 2024
a41952e
parsing tests pass
sezna Mar 27, 2024
81d1c6c
Working on making katas tests pass. WIP. Need to sort out how to hand…
sezna Mar 27, 2024
3719610
namespaces seem to be...working?
sezna Mar 28, 2024
86e99b9
mid-opens-refactor, might need to revert this
sezna Apr 1, 2024
d5e7011
Revert "mid-opens-refactor, might need to revert this"
sezna Apr 1, 2024
966ab4b
hierarchical opens work
sezna Apr 1, 2024
9fe7bde
fix display in duplicate definition error
sezna Apr 1, 2024
467beeb
implicit hierarchy works
sezna Apr 1, 2024
71b5a55
improve test clarity
sezna Apr 1, 2024
1a25d48
it works -- but tons of debug stuff everywhere
sezna Apr 2, 2024
2e7293b
Merge branch 'main' of github.com:microsoft/qsharp into alex/hns
sezna Apr 2, 2024
1a3c838
remove lots of debug cruft
sezna Apr 2, 2024
5f0d8ba
fmt and add hierarchical namespace resolution back in
sezna Apr 2, 2024
149070e
fix interpolation tests
sezna Apr 2, 2024
f725bc0
simplify beefy part of resolve function
sezna Apr 2, 2024
69a5137
fix renamer for namespaces
sezna Apr 2, 2024
1206b0b
just need to sort out shadowing
sezna Apr 2, 2024
8c08c61
fix shadowing rules
sezna Apr 3, 2024
7eae708
fix removal of unimplemented items from resolution
sezna Apr 3, 2024
552f346
fix ambiguous prelude
sezna Apr 3, 2024
a1be75b
refactor symbol finder to be generic; fix ambiguous opens test
sezna Apr 3, 2024
e80f154
fmt
sezna Apr 3, 2024
2674be3
replicate merged namespace alias behavior
sezna Apr 4, 2024
70faf28
all frontend tests pass
sezna Apr 4, 2024
4c04a17
Merge branch 'main' of github.com:microsoft/qsharp into alex/hns
sezna Apr 4, 2024
d9c6c7e
clear up warnings
sezna Apr 4, 2024
3c13840
remove dead code
sezna Apr 4, 2024
42a9051
clippy on frontend
sezna Apr 4, 2024
eb33cd4
wip on clippy
sezna Apr 4, 2024
24a8a22
fix all clippy warnings in compiler subdir
sezna Apr 4, 2024
ef1d739
fix language service open namespace text edit issue
sezna Apr 4, 2024
f235671
deduplicate prelude definition
sezna Apr 4, 2024
9a69246
simpify resolve fn
sezna Apr 4, 2024
ad12a62
simplify resolution
sezna Apr 4, 2024
36d7a31
further simplify resolution algorithms
sezna Apr 4, 2024
804f4e7
Fix interpreter test case for printing stack traces
sezna Apr 4, 2024
8016603
fix katas test
sezna Apr 4, 2024
5d60bfa
fix katas shadowing rules and doc gen tests
sezna Apr 4, 2024
992791d
Merge branch 'main' of github.com:microsoft/qsharp into alex/hns
sezna Apr 4, 2024
b2cf9c6
Fix resolve and RCA tests
sezna Apr 5, 2024
42e6ec9
update not available test
sezna Apr 5, 2024
fe267f8
cargo fmt
sezna Apr 5, 2024
03027ce
format string sample
sezna Apr 6, 2024
499283a
revert sample changes
sezna Apr 6, 2024
654d269
Merge branch 'main' of github.com:microsoft/qsharp into alex/hns
sezna Apr 6, 2024
a29308b
merge from main
sezna Apr 12, 2024
5355c85
merge from main
sezna Apr 22, 2024
158108e
temporary profiling changes
sezna Apr 22, 2024
71d93ee
Wip performance improvements
sezna Apr 22, 2024
8531b29
memoize find_id
sezna Apr 23, 2024
23f84c5
fix algorithm for finding ids
sezna Apr 23, 2024
847aa33
Remove debug strings
sezna Apr 23, 2024
883d5b2
fmt and docstrings
sezna Apr 23, 2024
4e08289
docstrings and refactoring
sezna Apr 23, 2024
00bb27c
reintroduce symbol stripping in root cargo toml
sezna Apr 23, 2024
adfaddf
update Cargo.toml to use equivalent, but more readable, release options
sezna Apr 23, 2024
f032ddb
update test cases for latest data structure
sezna Apr 23, 2024
50878b4
Merge branch 'main' of github.com:microsoft/qsharp into alex/hns
sezna Apr 23, 2024
1b58c4f
pull from main
sezna Apr 23, 2024
a31f208
improve memoization and add docstrings
sezna Apr 23, 2024
9ed559c
optimize API for querying namespace tree
sezna Apr 24, 2024
44b75f4
fix tests
sezna Apr 24, 2024
9e63b93
fmt
sezna Apr 24, 2024
21df355
merge from main
sezna Apr 24, 2024
216a896
Add docstring
sezna Apr 24, 2024
18b9cc1
fix runtime typo
sezna Apr 24, 2024
66b7b65
Allow implicit top-level namespaces
sezna Apr 24, 2024
da4408e
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/nake…
sezna Apr 24, 2024
dcdf766
Fix partial evaluation for implicit namespaces
sezna Apr 24, 2024
937f529
Remove unnecessary clones
sezna Apr 24, 2024
7db2238
Remove unnecessary clone
sezna Apr 24, 2024
ea512e9
address pr feedback
sezna Apr 25, 2024
6c5a864
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/nake…
sezna Apr 25, 2024
7395cc4
save at least one alloc maybe
sezna Apr 25, 2024
dee215e
provide more helpful err if user tries to use a dotted import alias
sezna Apr 25, 2024
e7523a6
add are
sezna Apr 26, 2024
e6c0b04
pull from alex/hns
sezna Apr 26, 2024
7d78f40
basic functionality of implicit namespaces is working
sezna Apr 26, 2024
c64f350
fmt and clippy
sezna Apr 26, 2024
7357645
small clippy change
sezna Apr 27, 2024
89140c3
fix tests
sezna Apr 30, 2024
cc71e1d
Merge branch 'main' of github.com:microsoft/qsharp into alex/hns
sezna Apr 30, 2024
a290d2f
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/nake…
sezna Apr 30, 2024
bdc3b6b
PR feedback from Mine
sezna Apr 30, 2024
3bf5797
rename vecident to idents
sezna May 1, 2024
4762de9
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/nake…
sezna May 1, 2024
60b5ebe
rename vec ident to idents
sezna May 1, 2024
59d2e5f
replace Vec<Ident> with Box<[Ident]>
sezna May 1, 2024
219295c
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/nake…
sezna May 1, 2024
41340a8
Merge branch 'main' of github.com:microsoft/qsharp into alex/hns
sezna May 3, 2024
bfe45ec
remove idents from fir
minestarks May 1, 2024
9a6daea
one wave of PR feedback
sezna May 7, 2024
c5733d3
merge
sezna May 7, 2024
df10589
clippy
sezna May 7, 2024
b4d0f42
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/nake…
sezna May 7, 2024
0e94b9e
Update compiler/qsc_fir/src/fir.rs
sezna May 7, 2024
1a37cd0
Update compiler/qsc_frontend/src/resolve.rs
sezna May 7, 2024
ccb0a82
Update compiler/qsc_parse/src/lib.rs
sezna May 7, 2024
9fa1e63
all the smaller PR feedback
sezna May 7, 2024
39d089e
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/hns
sezna May 7, 2024
d462174
switch to indexmap
sezna May 7, 2024
3b2582f
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/nake…
sezna May 7, 2024
0685625
wip
sezna May 8, 2024
b22c282
PR feedback
sezna May 9, 2024
abe1a2d
Merge branch 'main' of github.com:microsoft/qsharp into alex/hns
sezna May 9, 2024
54d09ea
fix opening parent namespaces
sezna May 9, 2024
dd56ae0
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/nake…
sezna May 9, 2024
da46d55
add test for opening implicitly opened parent namespace
sezna May 10, 2024
612c10c
fix state unit tests
sezna May 10, 2024
b16b6f5
rename file_name variable
sezna May 10, 2024
7111974
pr feedback
sezna May 13, 2024
c8a4e52
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/nake…
sezna May 13, 2024
3d11f0c
Merge branch 'main' of github.com:microsoft/qsharp into alex/hns
sezna May 13, 2024
5848083
Merge branch 'alex/hns' of github.com:microsoft/qsharp into alex/nake…
sezna May 13, 2024
4904ebb
@minestarks vibes the mutation
sezna May 13, 2024
04acaf8
Revert fir changes
sezna May 13, 2024
f1b9d1d
fix pip interpreter
sezna May 15, 2024
c4c2ea2
wip: most of the PR feedback
sezna May 15, 2024
3d9141c
clippy
sezna May 15, 2024
a4c8f2f
add newline after test fn
sezna May 15, 2024
cf402fa
merge from main
sezna May 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ __pycache__/
/fuzz/Cargo.lock
.mypy_cache/
.pytest_cache/
.idea/
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ missing_panics_doc = "allow"
module_name_repetitions = "allow"

[profile.release]
debug = 1
strip = true
debug = "limited"
strip = "symbols"
lto = "fat"
codegen-units = 1

Expand Down
2 changes: 2 additions & 0 deletions compiler/qsc/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum ErrorKind {
Lint(#[from] qsc_linter::Lint),
}

/// Compiles a package from its AST representation.
#[must_use]
#[allow(clippy::module_name_repetitions)]
pub fn compile_ast(
Expand All @@ -54,6 +55,7 @@ pub fn compile_ast(
process_compile_unit(store, package_type, capabilities, unit)
}

/// Compiles a package from its source representation.
#[must_use]
pub fn compile(
store: &PackageStore,
Expand Down
12 changes: 6 additions & 6 deletions compiler/qsc/src/interpret/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use qsc_frontend::compile::PackageStore;
use qsc_hir::hir;
use qsc_hir::hir::{Item, ItemKind};
use qsc_lowerer::map_fir_package_to_hir;
use std::rc::Rc;

#[must_use]
pub(crate) fn format_call_stack(
Expand Down Expand Up @@ -82,10 +83,9 @@ fn get_item_file_name(store: &PackageStore, id: StoreItemId) -> Option<String> {
}

#[must_use]
fn get_ns_name(item: &Item) -> Option<String> {
if let ItemKind::Namespace(ns, _) = &item.kind {
Some(ns.name.to_string())
} else {
None
}
fn get_ns_name(item: &Item) -> Option<Rc<str>> {
let ItemKind::Namespace(ns, _) = &item.kind else {
return None;
};
Some(ns.name())
}
13 changes: 8 additions & 5 deletions compiler/qsc/src/interpret/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1785,11 +1785,14 @@ mod given_interpreter {
let path = Path {
id: NodeId::default(),
span: Span::default(),
namespace: Some(Box::new(qsc_ast::ast::Ident {
id: NodeId::default(),
span: Span::default(),
name: ns.into(),
})),
namespace: Some(
std::iter::once(qsc_ast::ast::Ident {
id: NodeId::default(),
span: Span::default(),
name: ns.into(),
})
.collect(),
),
name: Box::new(qsc_ast::ast::Ident {
id: NodeId::default(),
span: Span::default(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/qsc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub mod project {
}

pub use qsc_data_structures::{
language_features::LanguageFeatures, span::Span, target::TargetCapabilityFlags,
language_features::LanguageFeatures, namespaces::*, span::Span, target::TargetCapabilityFlags,
};

pub use qsc_passes::{lower_hir_to_fir, PackageType, PassContext};
Expand Down
133 changes: 130 additions & 3 deletions compiler/qsc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub struct Namespace {
/// The documentation.
pub doc: Rc<str>,
/// The namespace name.
pub name: Box<Ident>,
pub name: Idents,
/// The items in the namespace.
pub items: Box<[Box<Item>]>,
}
Expand Down Expand Up @@ -259,7 +259,7 @@ pub enum ItemKind {
#[default]
Err,
/// An `open` item for a namespace with an optional alias.
Open(Box<Ident>, Option<Box<Ident>>),
Open(Idents, Option<Box<Ident>>),
/// A `newtype` declaration.
Ty(Box<Ident>, Box<TyDef>),
}
Expand Down Expand Up @@ -1273,7 +1273,7 @@ pub struct Path {
/// The span.
pub span: Span,
/// The namespace.
pub namespace: Option<Box<Ident>>,
pub namespace: Option<Idents>,
/// The declaration name.
pub name: Box<Ident>,
}
Expand Down Expand Up @@ -1306,6 +1306,133 @@ pub struct Ident {
pub name: Rc<str>,
}

/// A [`Idents`] represents a sequence of idents. It provides a helpful abstraction
/// that is more powerful than a simple `Vec<Ident>`, and is primarily used to represent
/// dot-separated paths.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Default)]
pub struct Idents(pub Box<[Ident]>);

impl From<Idents> for Vec<Rc<str>> {
fn from(v: Idents) -> Self {
v.0.iter().map(|i| i.name.clone()).collect()
}
}

impl From<&Idents> for Vec<Rc<str>> {
fn from(v: &Idents) -> Self {
v.0.iter().map(|i| i.name.clone()).collect()
}
}

impl From<Vec<Ident>> for Idents {
fn from(v: Vec<Ident>) -> Self {
Idents(v.into_boxed_slice())
}
}

impl From<Idents> for Vec<Ident> {
fn from(v: Idents) -> Self {
v.0.to_vec()
}
}

impl Display for Idents {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut buf = Vec::with_capacity(self.0.len());

for ident in self.0.iter() {
buf.push(format!("{ident}"));
}
if buf.len() > 1 {
// use square brackets only if there are more than one ident
write!(f, "[{}]", buf.join(", "))
} else {
write!(f, "{}", buf[0])
}
}
}

impl<'a> IntoIterator for &'a Idents {
type IntoIter = std::slice::Iter<'a, Ident>;
type Item = &'a Ident;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

impl<'a> From<&'a Idents> for IdentsStrIter<'a> {
fn from(v: &'a Idents) -> Self {
IdentsStrIter(v)
}
}

/// An iterator which yields string slices of the names of the idents in a [`Idents`].
/// Note that [`Idents`] itself only implements [`IntoIterator`] where the item is an [`Ident`].
pub struct IdentsStrIter<'a>(pub &'a Idents);

impl<'a> IntoIterator for IdentsStrIter<'a> {
type IntoIter = std::iter::Map<std::slice::Iter<'a, Ident>, fn(&'a Ident) -> &'a str>;
type Item = &'a str;
fn into_iter(self) -> Self::IntoIter {
self.0.iter().map(|i| i.name.as_ref())
}
}

impl FromIterator<Ident> for Idents {
fn from_iter<T: IntoIterator<Item = Ident>>(iter: T) -> Self {
Idents(iter.into_iter().collect())
}
}

impl From<Path> for Idents {
fn from(p: Path) -> Self {
let mut buf = p.namespace.unwrap_or_default().0.to_vec();
buf.push(*p.name);
Self(buf.into_boxed_slice())
}
}

impl Idents {
/// constructs an iterator over the [Ident]s that this contains.
/// see [`Self::str_iter`] for an iterator over the string slices of the [Ident]s.
pub fn iter(&self) -> std::slice::Iter<'_, Ident> {
self.0.iter()
}

/// constructs an iterator over the elements of `self` as string slices.
/// see [`Self::iter`] for an iterator over the [Ident]s.
#[must_use]
pub fn str_iter(&self) -> IdentsStrIter {
self.into()
}

/// the conjoined span of all idents in the `Idents`
#[must_use]
pub fn span(&self) -> Span {
Span {
lo: self.0.first().map(|i| i.span.lo).unwrap_or_default(),
hi: self.0.last().map(|i| i.span.hi).unwrap_or_default(),
}
}

/// The stringified dot-separated path of the idents in this [`Idents`]
/// E.g. `a.b.c`
#[must_use]
pub fn name(&self) -> Rc<str> {
if self.0.len() == 1 {
return self.0[0].name.clone();
}
let mut buf = String::new();
for ident in self.0.iter() {
if !buf.is_empty() {
buf.push('.');
}
buf.push_str(&ident.name);
}
Rc::from(buf)
}
}

impl Default for Ident {
fn default() -> Self {
Ident {
Expand Down
19 changes: 16 additions & 3 deletions compiler/qsc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ pub trait MutVisitor: Sized {
walk_ident(self, ident);
}

fn visit_idents(&mut self, ident: &mut crate::ast::Idents) {
walk_idents(self, ident);
}

fn visit_span(&mut self, _: &mut Span) {}
}

Expand All @@ -89,7 +93,8 @@ pub fn walk_package(vis: &mut impl MutVisitor, package: &mut Package) {

pub fn walk_namespace(vis: &mut impl MutVisitor, namespace: &mut Namespace) {
vis.visit_span(&mut namespace.span);
vis.visit_ident(&mut namespace.name);
vis.visit_idents(&mut namespace.name);

namespace.items.iter_mut().for_each(|i| vis.visit_item(i));
}

Expand All @@ -104,7 +109,7 @@ pub fn walk_item(vis: &mut impl MutVisitor, item: &mut Item) {
ItemKind::Callable(decl) => vis.visit_callable_decl(decl),
ItemKind::Err => {}
ItemKind::Open(ns, alias) => {
vis.visit_ident(ns);
vis.visit_idents(ns);
alias.iter_mut().for_each(|a| vis.visit_ident(a));
}
ItemKind::Ty(ident, def) => {
Expand Down Expand Up @@ -333,10 +338,18 @@ pub fn walk_qubit_init(vis: &mut impl MutVisitor, init: &mut QubitInit) {

pub fn walk_path(vis: &mut impl MutVisitor, path: &mut Path) {
vis.visit_span(&mut path.span);
path.namespace.iter_mut().for_each(|n| vis.visit_ident(n));
if let Some(ref mut ns) = path.namespace {
vis.visit_idents(ns);
}
vis.visit_ident(&mut path.name);
}

pub fn walk_ident(vis: &mut impl MutVisitor, ident: &mut Ident) {
vis.visit_span(&mut ident.span);
}

pub fn walk_idents(vis: &mut impl MutVisitor, ident: &mut crate::ast::Idents) {
for ref mut ident in ident.0.iter_mut() {
vis.visit_ident(ident);
}
}
22 changes: 16 additions & 6 deletions compiler/qsc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

use crate::ast::{
Attr, Block, CallableBody, CallableDecl, Expr, ExprKind, FunctorExpr, FunctorExprKind, Ident,
Item, ItemKind, Namespace, Package, Pat, PatKind, Path, QubitInit, QubitInitKind, SpecBody,
SpecDecl, Stmt, StmtKind, StringComponent, TopLevelNode, Ty, TyDef, TyDefKind, TyKind,
Visibility,
Idents, Item, ItemKind, Namespace, Package, Pat, PatKind, Path, QubitInit, QubitInitKind,
SpecBody, SpecDecl, Stmt, StmtKind, StringComponent, TopLevelNode, Ty, TyDef, TyDefKind,
TyKind, Visibility,
};

pub trait Visitor<'a>: Sized {
Expand Down Expand Up @@ -72,6 +72,10 @@ pub trait Visitor<'a>: Sized {
}

fn visit_ident(&mut self, _: &'a Ident) {}

fn visit_idents(&mut self, idents: &'a Idents) {
walk_idents(self, idents);
}
}

pub fn walk_package<'a>(vis: &mut impl Visitor<'a>, package: &'a Package) {
Expand All @@ -83,7 +87,7 @@ pub fn walk_package<'a>(vis: &mut impl Visitor<'a>, package: &'a Package) {
}

pub fn walk_namespace<'a>(vis: &mut impl Visitor<'a>, namespace: &'a Namespace) {
vis.visit_ident(&namespace.name);
vis.visit_idents(&namespace.name);
namespace.items.iter().for_each(|i| vis.visit_item(i));
}

Expand All @@ -94,7 +98,7 @@ pub fn walk_item<'a>(vis: &mut impl Visitor<'a>, item: &'a Item) {
ItemKind::Err => {}
ItemKind::Callable(decl) => vis.visit_callable_decl(decl),
ItemKind::Open(ns, alias) => {
vis.visit_ident(ns);
vis.visit_idents(ns);
alias.iter().for_each(|a| vis.visit_ident(a));
}
ItemKind::Ty(ident, def) => {
Expand Down Expand Up @@ -300,6 +304,12 @@ pub fn walk_qubit_init<'a>(vis: &mut impl Visitor<'a>, init: &'a QubitInit) {
}

pub fn walk_path<'a>(vis: &mut impl Visitor<'a>, path: &'a Path) {
path.namespace.iter().for_each(|n| vis.visit_ident(n));
if let Some(ref ns) = path.namespace {
vis.visit_idents(ns);
}
vis.visit_ident(&path.name);
}

pub fn walk_idents<'a>(vis: &mut impl Visitor<'a>, idents: &'a Idents) {
idents.iter().for_each(|i| vis.visit_ident(i));
}
4 changes: 2 additions & 2 deletions compiler/qsc_circuit/src/operations/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn compile_one_operation(code: &str) -> (Item, String) {
});
let mut namespaces = unit.package.items.values().filter_map(|i| {
if let ItemKind::Namespace(ident, _) = &i.kind {
Some(ident.name.clone())
Some(ident.clone())
} else {
None
}
Expand All @@ -46,7 +46,7 @@ fn compile_one_operation(code: &str) -> (Item, String) {
);
(
only_callable.clone(),
format!("{only_namespace}.{callable_name}"),
format!("{}.{callable_name}", only_namespace.name()),
)
}

Expand Down