Skip to content

Commit

Permalink
finalize new stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
sezna committed Sep 10, 2024
1 parent 06b372c commit 6cd0124
Show file tree
Hide file tree
Showing 23 changed files with 5,707 additions and 5,601 deletions.
2 changes: 1 addition & 1 deletion compiler/qsc/src/interpret/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ mod given_interpreter {
&output,
&expect![[r#"
runtime error: qubits in invocation are not unique
[qsharp-library-source:intrinsic.qs] [(control, target)]
[qsharp-library-source:Std/Intrinsic.qs] [(control, target)]
"#]],
);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/qsc/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod tests {

expect![[r#"
Location {
source: "qsharp-library-source:arrays.qs",
source: "qsharp-library-source:Std/Arrays.qs",
range: Range {
start: Position {
line: 0,
Expand Down
12 changes: 6 additions & 6 deletions compiler/qsc_data_structures/src/namespaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ mod tests;
use rustc_hash::{FxHashMap, FxHashSet};
use std::{cell::RefCell, collections::BTreeMap, fmt::Display, iter::Peekable, ops::Deref, rc::Rc};

pub const PRELUDE: [[&str; 3]; 4] = [
["Microsoft", "Quantum", "Canon"],
["Microsoft", "Quantum", "Core"],
["Microsoft", "Quantum", "Intrinsic"],
["Microsoft", "Quantum", "Measurement"],
pub const PRELUDE: &[&[&str]; 4] = &[
&["Std", "Canon"],
&["Microsoft", "Quantum", "Core"],
&["Std", "Intrinsic"],
&["Std", "Measurement"],
];

/// An ID that corresponds to a namespace in the global scope.
Expand Down Expand Up @@ -279,7 +279,7 @@ impl Default for NamespaceTreeRoot {
memo: RefCell::new(FxHashMap::default()),
};
// insert the prelude namespaces using the `NamespaceTreeRoot` API
for ns in &PRELUDE {
for ns in PRELUDE {
let iter = ns.iter().map(|s| Rc::from(*s)).peekable();
let _ = tree.insert_or_find_namespace(iter);
}
Expand Down
115 changes: 59 additions & 56 deletions compiler/qsc_data_structures/src/namespaces/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,41 @@ fn test_tree_construction() {
NamespaceTreeRoot
children: [
ns1(id 11) {
Std(id 1) {
children: [
nsc(id 14) {empty node},
nsb(id 13) {empty node},
nsa(id 12) {empty node},
Measurement(id 7) {empty node},
Canon(id 2) {empty node},
Intrinsic(id 6) {empty node},
]
},
ns0(id 7) {
ns1(id 12) {
children: [
nsc(id 10) {empty node},
nsb(id 9) {empty node},
nsa(id 8) {empty node},
nsc(id 15) {empty node},
nsb(id 14) {empty node},
nsa(id 13) {empty node},
]
},
Microsoft(id 1) {
ns0(id 8) {
children: [
Quantum(id 2) {
nsc(id 11) {empty node},
nsb(id 10) {empty node},
nsa(id 9) {empty node},
]
},
Microsoft(id 3) {
children: [
Quantum(id 4) {
children: [
Canon(id 3) {empty node},
Measurement(id 6) {empty node},
Core(id 4) {empty node},
Intrinsic(id 5) {empty node},
Core(id 5) {empty node},
]
},
]
},
ns2(id 15) {
ns2(id 16) {
children: [
nsc(id 18) {empty node},
nsb(id 17) {empty node},
nsa(id 16) {empty node},
nsc(id 19) {empty node},
nsb(id 18) {empty node},
nsa(id 17) {empty node},
]
},
]
Expand Down Expand Up @@ -117,9 +121,9 @@ fn test_find_id() {
RefCell {
value:
children: [
nsc(id 10) {empty node},
nsb(id 9) {empty node},
nsa(id 8) {empty node},
nsc(id 11) {empty node},
nsb(id 10) {empty node},
nsa(id 9) {empty node},
]
},
},
Expand Down Expand Up @@ -158,9 +162,9 @@ fn test_find_id() {
RefCell {
value:
children: [
nsc(id 14) {empty node},
nsb(id 13) {empty node},
nsa(id 12) {empty node},
nsc(id 15) {empty node},
nsb(id 14) {empty node},
nsa(id 13) {empty node},
]
},
},
Expand Down Expand Up @@ -199,9 +203,9 @@ fn test_find_id() {
RefCell {
value:
children: [
nsc(id 18) {empty node},
nsb(id 17) {empty node},
nsa(id 16) {empty node},
nsc(id 19) {empty node},
nsb(id 18) {empty node},
nsa(id 17) {empty node},
]
},
},
Expand All @@ -228,19 +232,19 @@ fn test_insert_or_find_namespace() {
ids_sorted.dedup();
// there should be no duplicate or out-of-order ids
assert_eq!(ids_sorted, ids);
expect![[r"
expect![[r#"
[
8,
9,
10,
12,
11,
13,
14,
16,
15,
17,
18,
19,
]
"]]
"#]]
.assert_debug_eq(&ids);
}

Expand All @@ -265,11 +269,6 @@ fn test_get_namespace_id() {
}
expect![[r#"
[
Some(
NamespaceId(
8,
),
),
Some(
NamespaceId(
9,
Expand All @@ -282,12 +281,12 @@ fn test_get_namespace_id() {
),
Some(
NamespaceId(
7,
11,
),
),
Some(
NamespaceId(
12,
8,
),
),
Some(
Expand All @@ -302,12 +301,12 @@ fn test_get_namespace_id() {
),
Some(
NamespaceId(
11,
15,
),
),
Some(
NamespaceId(
16,
12,
),
),
Some(
Expand All @@ -322,7 +321,12 @@ fn test_get_namespace_id() {
),
Some(
NamespaceId(
15,
19,
),
),
Some(
NamespaceId(
16,
),
),
]
Expand Down Expand Up @@ -350,25 +354,28 @@ fn test_tree_iter() {
],
[
[
"Microsoft",
"Std",
],
],
[
[
"Microsoft",
"Quantum",
"Std",
"Canon",
],
[
"Std",
"Canon",
],
],
[
[
"Microsoft",
"Quantum",
"Canon",
],
],
[
[
"Microsoft",
"Quantum",
"Canon",
],
],
[
Expand All @@ -385,25 +392,21 @@ fn test_tree_iter() {
],
[
[
"Microsoft",
"Quantum",
"Std",
"Intrinsic",
],
[
"Microsoft",
"Quantum",
"Std",
"Intrinsic",
],
],
[
[
"Microsoft",
"Quantum",
"Std",
"Measurement",
],
[
"Microsoft",
"Quantum",
"Std",
"Measurement",
],
],
Expand Down
4 changes: 2 additions & 2 deletions compiler/qsc_frontend/src/incremental/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ fn one_callable() {
},
kind: Namespace(
NamespaceId(
9,
10,
),
),
opens: {
[]: [
Open {
namespace: NamespaceId(
9,
10,
),
span: Span {
lo: 10,
Expand Down
2 changes: 1 addition & 1 deletion compiler/qsc_frontend/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ pub fn prelude_namespaces(globals: &GlobalScope) -> Vec<(NamespaceId, String)> {
prelude.push((
globals
.namespaces
.get_namespace_id(prelude_namespace)
.get_namespace_id(prelude_namespace.to_vec())
.expect("prelude should always exist in the namespace map"),
prelude_namespace.join("."),
));
Expand Down
Loading

0 comments on commit 6cd0124

Please sign in to comment.