Skip to content

Commit 5f1373f

Browse files
authored
Merge 22184d0 into 298ae6a
2 parents 298ae6a + 22184d0 commit 5f1373f

File tree

42 files changed

+3457
-2024
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3457
-2024
lines changed

library/fixed_point/src/Main.qs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
export Init.PrepareFxP as PrepareFxP, Types.FixedPoint as FixedPoint;
4+
export Init.PrepareFxP, Types.FixedPoint;
55

66
@Config(Unrestricted)
7-
export Reciprocal.ComputeReciprocalFxP as ComputeReciprocalFxP;
7+
export Reciprocal.ComputeReciprocalFxP;
88

99
@Config(FloatingPointComputations)
10-
export Measurement.MeasureFxP as MeasureFxP;
10+
export Measurement.MeasureFxP;

library/rotations/src/Main.qs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
export HammingWeightPhasing.HammingWeightPhasing as HammingWeightPhasing;
4+
export HammingWeightPhasing.HammingWeightPhasing;

library/std/src/legacy_api.qs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.Quantum {
1010

1111
namespace Microsoft.Quantum.Core {
1212
import Std.Range.*;
13-
export RangeStart, RangeEnd, IsRangeEmpty, Length, Repeated, Int, Qubit, Bool, Unit;
13+
export RangeStart, RangeEnd, IsRangeEmpty, Length, Repeated;
1414
}
1515

1616
namespace Microsoft.Quantum.Unstable {

source/compiler/qsc/src/interpret.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl Interpreter {
334334
.expect("package should exist in the package store")
335335
.package;
336336
for global in global::iter_package(Some(map_fir_package_to_hir(package_id)), package) {
337-
if let global::Kind::Term(term) = global.kind {
337+
if let global::Kind::Callable(term) = global.kind {
338338
let store_item_id = fir::StoreItemId {
339339
package: package_id,
340340
item: fir::LocalItemId::from(usize::from(term.id.item)),

source/compiler/qsc/src/interpret/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ mod given_interpreter {
508508
&result,
509509
&output,
510510
&expect![[r#"
511-
name error: `DumpMachine` could refer to the item in `Other` or `Microsoft.Quantum.Diagnostics`
511+
name error: `DumpMachine` could refer to the item in `Other` or `Std.Diagnostics`
512512
ambiguous name [line_3] [DumpMachine]
513513
found in this namespace [line_1] [Other]
514514
and also in this namespace [line_2] [Std.Diagnostics]

source/compiler/qsc/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ pub use qsc_formatter::formatter;
1414
pub use qsc_frontend::compile::{CompileUnit, PackageStore, SourceContents, SourceMap, SourceName};
1515

1616
pub mod resolve {
17-
pub use qsc_frontend::resolve::{Local, LocalKind, Locals, Res, path_as_field_accessor};
17+
pub use qsc_frontend::resolve::{
18+
Local, LocalKind, Locals, Res, iter_valid_items, path_as_field_accessor,
19+
};
1820
}
1921

2022
pub mod fir {

source/compiler/qsc_ast/src/ast.rs

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ impl Display for ItemKind {
293293
},
294294
ItemKind::Ty(name, t) => write!(f, "New Type ({name}): {t}")?,
295295
ItemKind::Struct(s) => write!(f, "{s}")?,
296-
ItemKind::ImportOrExport(item) if item.is_export => write!(f, "Export ({item})")?,
297-
ItemKind::ImportOrExport(item) => write!(f, "Import ({item})")?,
296+
ItemKind::ImportOrExport(item) => write!(f, "{item}")?,
298297
}
299298
Ok(())
300299
}
@@ -1889,13 +1888,18 @@ pub struct ImportOrExportDecl {
18891888

18901889
impl Display for ImportOrExportDecl {
18911890
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1892-
let items_str = self
1893-
.items
1894-
.iter()
1895-
.map(std::string::ToString::to_string)
1896-
.collect::<Vec<_>>()
1897-
.join(", ");
1898-
write!(f, "ImportOrExportDecl {}: [{items_str}]", self.span)
1891+
let mut indent = set_indentation(indented(f), 0);
1892+
if self.is_export {
1893+
write!(indent, "Export")?;
1894+
} else {
1895+
write!(indent, "Import")?;
1896+
}
1897+
write!(indent, " {}:", self.span)?;
1898+
indent = set_indentation(indent, 1);
1899+
for item in &self.items {
1900+
write!(indent, "\n{item}")?;
1901+
}
1902+
Ok(())
18991903
}
19001904
}
19011905

@@ -1921,39 +1925,32 @@ impl ImportOrExportDecl {
19211925
pub fn is_import(&self) -> bool {
19221926
!self.is_export
19231927
}
1924-
1925-
/// Returns an iterator over the items being exported from this namespace.
1926-
pub fn items(&self) -> impl Iterator<Item = &ImportOrExportItem> {
1927-
self.items.iter()
1928-
}
19291928
}
19301929

19311930
/// An individual item within an [`ImportOrExportDecl`]. This can be a path or a path with an alias.
19321931
#[derive(Clone, Debug, Eq, PartialEq, Default)]
19331932
pub struct ImportOrExportItem {
1934-
/// The span of the import path including the glob and alias, if any.
1933+
/// The span of the import path including the wildcard and alias, if any.
19351934
pub span: Span,
19361935
/// The path to the item being exported.
19371936
pub path: PathKind,
1938-
/// An optional alias for the item being exported.
1939-
pub alias: Option<Ident>,
1940-
/// Whether this is a glob import/export.
1941-
pub is_glob: bool,
1937+
/// The kind of import being performed, direct or wildcard.
1938+
pub kind: ImportKind,
19421939
}
19431940

19441941
impl Display for ImportOrExportItem {
19451942
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1946-
let ImportOrExportItem {
1947-
span: _,
1948-
path,
1949-
alias,
1950-
is_glob,
1951-
} = self;
1952-
let is_glob = if *is_glob { ".*" } else { "" };
1953-
match alias {
1954-
Some(alias) => write!(f, "{path}{is_glob} as {alias}",),
1955-
None => write!(f, "{path}{is_glob}"),
1943+
write!(f, "{} ", self.span)?;
1944+
match &self.kind {
1945+
ImportKind::Wildcard => write!(f, "Wildcard")?,
1946+
ImportKind::Direct { alias } => {
1947+
write!(f, "Direct")?;
1948+
if let Some(alias) = alias {
1949+
write!(f, " (alias: {alias})")?;
1950+
}
1951+
}
19561952
}
1953+
write!(f, ": {}", self.path)
19571954
}
19581955
}
19591956

@@ -1968,19 +1965,34 @@ impl ImportOrExportItem {
19681965
/// Returns `None` if the path has an error.
19691966
#[must_use]
19701967
pub fn name(&self) -> Option<&Ident> {
1971-
match &self.alias {
1972-
Some(_) => self.alias.as_ref(),
1973-
None => {
1974-
if let PathKind::Ok(path) = &self.path {
1975-
Some(&path.name)
1976-
} else {
1977-
None
1978-
}
1979-
}
1968+
match &self.kind {
1969+
ImportKind::Wildcard => None,
1970+
ImportKind::Direct { alias } => alias.as_ref().or_else(|| match &self.path {
1971+
PathKind::Ok(path) => Some(path.name.as_ref()),
1972+
PathKind::Err(_) => None,
1973+
}),
19801974
}
19811975
}
19821976
}
19831977

1978+
/// The kind of import being performed in an `ImportOrExportItem`.
1979+
#[derive(Clone, Debug, Eq, PartialEq)]
1980+
pub enum ImportKind {
1981+
/// A wildcard import: `import A.*`
1982+
Wildcard,
1983+
/// A direct import or export: `import A.B`, `export A`, etc.
1984+
Direct {
1985+
/// An optional alias for the item being imported.
1986+
alias: Option<Ident>,
1987+
},
1988+
}
1989+
1990+
impl Default for ImportKind {
1991+
fn default() -> Self {
1992+
ImportKind::Direct { alias: None }
1993+
}
1994+
}
1995+
19841996
/// A [`TypeParameter`] is a generic type variable with optional bounds (constraints).
19851997
#[derive(Default, Debug, PartialEq, Eq, Clone, Hash)]
19861998
pub struct TypeParameter {

source/compiler/qsc_ast/src/mut_visit.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
use crate::ast::{
55
Attr, Block, CallableBody, CallableDecl, Expr, ExprKind, FieldAccess, FieldAssign, FieldDef,
6-
FunctorExpr, FunctorExprKind, Ident, Item, ItemKind, Namespace, Package, Pat, PatKind, Path,
7-
PathKind, QubitInit, QubitInitKind, SpecBody, SpecDecl, Stmt, StmtKind, StringComponent,
8-
StructDecl, TopLevelNode, Ty, TyDef, TyDefKind, TyKind, TypeParameter,
6+
FunctorExpr, FunctorExprKind, Ident, ImportKind, ImportOrExportItem, Item, ItemKind, Namespace,
7+
Package, Pat, PatKind, Path, PathKind, QubitInit, QubitInitKind, SpecBody, SpecDecl, Stmt,
8+
StmtKind, StringComponent, StructDecl, TopLevelNode, Ty, TyDef, TyDefKind, TyKind,
9+
TypeParameter,
910
};
1011
use qsc_data_structures::span::Span;
1112

@@ -38,6 +39,10 @@ pub trait MutVisitor: Sized {
3839
walk_struct_decl(self, decl);
3940
}
4041

42+
fn visit_import_or_export(&mut self, item: &mut ImportOrExportItem) {
43+
walk_import_or_export(self, item);
44+
}
45+
4146
fn visit_field_def(&mut self, def: &mut FieldDef) {
4247
walk_field_def(self, def);
4348
}
@@ -128,15 +133,11 @@ pub fn walk_item(vis: &mut impl MutVisitor, item: &mut Item) {
128133
vis.visit_ty_def(def);
129134
}
130135
ItemKind::Struct(decl) => vis.visit_struct_decl(decl),
131-
ItemKind::ImportOrExport(export) => {
132-
vis.visit_span(&mut export.span);
133-
for item in &mut *export.items {
134-
vis.visit_span(&mut item.span);
135-
vis.visit_path_kind(&mut item.path);
136-
if let Some(ref mut alias) = item.alias {
137-
vis.visit_ident(alias);
138-
}
139-
}
136+
ItemKind::ImportOrExport(decl) => {
137+
vis.visit_span(&mut decl.span);
138+
decl.items
139+
.iter_mut()
140+
.for_each(|item| vis.visit_import_or_export(item));
140141
}
141142
}
142143
}
@@ -193,6 +194,14 @@ pub fn walk_struct_decl(vis: &mut impl MutVisitor, decl: &mut StructDecl) {
193194
decl.fields.iter_mut().for_each(|f| vis.visit_field_def(f));
194195
}
195196

197+
pub fn walk_import_or_export(vis: &mut impl MutVisitor, item: &mut ImportOrExportItem) {
198+
vis.visit_span(&mut item.span);
199+
vis.visit_path_kind(&mut item.path);
200+
if let ImportKind::Direct { alias: Some(alias) } = &mut item.kind {
201+
vis.visit_ident(alias);
202+
}
203+
}
204+
196205
pub fn walk_field_def(vis: &mut impl MutVisitor, def: &mut FieldDef) {
197206
vis.visit_span(&mut def.span);
198207
vis.visit_ident(&mut def.name);

source/compiler/qsc_ast/src/visit.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
use crate::ast::{
55
Attr, Block, CallableBody, CallableDecl, Expr, ExprKind, FieldAccess, FieldAssign, FieldDef,
6-
FunctorExpr, FunctorExprKind, Ident, Item, ItemKind, Namespace, Package, Pat, PatKind, Path,
7-
PathKind, QubitInit, QubitInitKind, SpecBody, SpecDecl, Stmt, StmtKind, StringComponent,
8-
StructDecl, TopLevelNode, Ty, TyDef, TyDefKind, TyKind, TypeParameter,
6+
FunctorExpr, FunctorExprKind, Ident, ImportKind, ImportOrExportItem, Item, ItemKind, Namespace,
7+
Package, Pat, PatKind, Path, PathKind, QubitInit, QubitInitKind, SpecBody, SpecDecl, Stmt,
8+
StmtKind, StringComponent, StructDecl, TopLevelNode, Ty, TyDef, TyDefKind, TyKind,
9+
TypeParameter,
910
};
1011

1112
pub trait Visitor<'a>: Sized {
@@ -37,6 +38,10 @@ pub trait Visitor<'a>: Sized {
3738
walk_struct_decl(self, decl);
3839
}
3940

41+
fn visit_import_or_export(&mut self, item: &'a ImportOrExportItem) {
42+
walk_import_or_export(self, item);
43+
}
44+
4045
fn visit_field_def(&mut self, def: &'a FieldDef) {
4146
walk_field_def(self, def);
4247
}
@@ -120,16 +125,12 @@ pub fn walk_item<'a>(vis: &mut impl Visitor<'a>, item: &'a Item) {
120125
}
121126
ItemKind::Struct(decl) => vis.visit_struct_decl(decl),
122127
ItemKind::ImportOrExport(decl) => {
123-
for item in &decl.items {
124-
vis.visit_path_kind(&item.path);
125-
if let Some(ref alias) = item.alias {
126-
vis.visit_ident(alias);
127-
}
128-
}
128+
decl.items
129+
.iter()
130+
.for_each(|item| vis.visit_import_or_export(item));
129131
}
130132
}
131133
}
132-
133134
pub fn walk_attr<'a>(vis: &mut impl Visitor<'a>, attr: &'a Attr) {
134135
vis.visit_ident(&attr.name);
135136
vis.visit_expr(&attr.arg);
@@ -174,6 +175,16 @@ pub fn walk_struct_decl<'a>(vis: &mut impl Visitor<'a>, decl: &'a StructDecl) {
174175
decl.fields.iter().for_each(|f| vis.visit_field_def(f));
175176
}
176177

178+
pub fn walk_import_or_export<'a>(vis: &mut impl Visitor<'a>, item: &'a ImportOrExportItem) {
179+
vis.visit_path_kind(&item.path);
180+
if let ImportKind::Direct {
181+
alias: Some(ref alias),
182+
} = item.kind
183+
{
184+
vis.visit_ident(alias);
185+
}
186+
}
187+
177188
pub fn walk_field_def<'a>(vis: &mut impl Visitor<'a>, def: &'a FieldDef) {
178189
vis.visit_ident(&def.name);
179190
vis.visit_ty(&def.ty);

source/compiler/qsc_codegen/src/qsharp.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use std::vec;
1515

1616
use qsc_ast::ast::{
1717
self, Attr, BinOp, Block, CallableBody, CallableDecl, CallableKind, Expr, ExprKind,
18-
FieldAccess, Functor, FunctorExpr, FunctorExprKind, Ident, Idents, ImportOrExportItem, Item,
19-
ItemKind, Lit, Mutability, Pat, PatKind, Path, PathKind, Pauli, QubitInit, QubitInitKind,
20-
QubitSource, SetOp, SpecBody, SpecDecl, SpecGen, Stmt, StmtKind, StringComponent, TernOp,
21-
TopLevelNode, Ty, TyDef, TyDefKind, TyKind, UnOp,
18+
FieldAccess, Functor, FunctorExpr, FunctorExprKind, Ident, Idents, ImportKind,
19+
ImportOrExportItem, Item, ItemKind, Lit, Mutability, Pat, PatKind, Path, PathKind, Pauli,
20+
QubitInit, QubitInitKind, QubitSource, SetOp, SpecBody, SpecDecl, SpecGen, Stmt, StmtKind,
21+
StringComponent, TernOp, TopLevelNode, Ty, TyDef, TyDefKind, TyKind, UnOp,
2222
};
2323
use qsc_ast::ast::{Namespace, Package};
2424
use qsc_ast::visit::Visitor;
@@ -162,19 +162,18 @@ impl<W: Write> Visitor<'_> for QSharpGen<W> {
162162
ImportOrExportItem {
163163
span: _,
164164
path,
165-
is_glob,
166-
alias,
165+
kind,
167166
},
168167
) in decl.items.iter().enumerate()
169168
{
170169
let is_last = ix == decl.items.len() - 1;
171170
self.visit_path_kind(path);
172171

173-
if *is_glob {
172+
if let ImportKind::Wildcard = kind {
174173
self.write(".*");
175174
}
176175

177-
if let Some(alias) = alias {
176+
if let ImportKind::Direct { alias: Some(alias) } = kind {
178177
self.write(&format!(" as {}", alias.name));
179178
}
180179

0 commit comments

Comments
 (0)