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

Migrate the standard library to the project system #1912

Merged
merged 33 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9af6f07
convert arrays.qs to the new stdlib
sezna Sep 9, 2024
dd55538
move Convert to modern stdlib
sezna Sep 9, 2024
d3905ae
move diagnostics to new stdlib
sezna Sep 9, 2024
a86106c
convert some more to the modern style
sezna Sep 9, 2024
baf489a
forgotten adds
sezna Sep 9, 2024
9bd4487
wip: refactor stdlib
sezna Sep 9, 2024
50e49a6
port intrinsic and internals to new project format
sezna Sep 10, 2024
84258ab
migrate half of unstable lib
sezna Sep 10, 2024
06b372c
everything migrated except canon and core
sezna Sep 10, 2024
6cd0124
finalize new stdlib
sezna Sep 10, 2024
920dd71
migrate canon and undo unstable migration
sezna Sep 10, 2024
f878951
remove opens
sezna Sep 10, 2024
59bff76
update tests
sezna Sep 10, 2024
22b6ffc
clippy
sezna Sep 10, 2024
e6de5af
fix basics.js test
sezna Sep 10, 2024
0e7f0f7
update integration test
sezna Sep 11, 2024
2a8f221
update integration tests
sezna Sep 11, 2024
400ef4d
Merge branch 'main' of github.com:microsoft/qsharp into alex/all-stdl…
sezna Sep 13, 2024
343a376
pr feedback
sezna Sep 13, 2024
64906c4
update all non-katas code to use import instead of open
sezna Sep 13, 2024
9878915
update codegen tests
sezna Sep 13, 2024
c115436
fix codegen bug
sezna Sep 13, 2024
d661795
update tests
sezna Sep 13, 2024
83c25bc
update tests
sezna Sep 13, 2024
f2787df
update spans
sezna Sep 13, 2024
26642b6
Merge branch 'alex/all-stdlib-except-core' of github.com:microsoft/qs…
sezna Sep 13, 2024
f16998a
update basics test
sezna Sep 14, 2024
0bca193
sanity check
sezna Sep 16, 2024
4769f37
merge from main
sezna Sep 16, 2024
6ecc2be
Sanity check???
sezna Sep 16, 2024
8973d25
fix tests
sezna Sep 17, 2024
411205a
merge from main
sezna Sep 17, 2024
9647ce9
Fmt
sezna Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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},
sezna marked this conversation as resolved.
Show resolved Hide resolved
]
},
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
Loading