Skip to content

Commit 94264e4

Browse files
committed
fixes for merge conflicts
1 parent e1f2ec1 commit 94264e4

File tree

7 files changed

+29
-43
lines changed

7 files changed

+29
-43
lines changed

compiler/qsc_eval/src/intrinsic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ pub(crate) fn invoke_intrinsic(
3737
invoke_quantum_intrinsic(name, name_span, args, args_span)
3838
} else {
3939
match name {
40-
"Length" => match args.try_into_array().with_span(args_span)?.len().try_into() {
41-
Ok(len) => ControlFlow::Continue(Value::Int(len)),
42-
Err(_) => ControlFlow::Break(Reason::Error(Error::ArrayTooLarge(args_span))),
40+
"Length" => match args.into_array().len().try_into() {
41+
Ok(len) => Ok(Value::Int(len)),
42+
Err(_) => Err(Error::ArrayTooLarge(args_span)),
4343
},
4444

4545
#[allow(clippy::cast_precision_loss)]

compiler/qsc_eval/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,6 @@ impl<'a, G: GlobalLookup<'a>> State<'a, G> {
852852
fn cont_field(&mut self, field: PrimField, span: Span) -> Result<(), Error> {
853853
let record = self.pop_val();
854854
let res = match (record, field) {
855-
(Value::Array(arr), PrimField::Length) => arr
856-
.len()
857-
.try_into()
858-
.map_err(|_| Error::ArrayTooLarge(span))?,
859855
(Value::Range(Some(start), _, _), PrimField::Start) => start,
860856
(Value::Range(_, step, _), PrimField::Step) => step,
861857
(Value::Range(_, _, Some(end)), PrimField::End) => end,

compiler/qsc_eval/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ fn block_qubit_use_array_invalid_count_expr() {
318318
UserFail(
319319
"Cannot allocate qubit array with a negative length",
320320
Span {
321-
lo: 371,
322-
hi: 428,
321+
lo: 758,
322+
hi: 815,
323323
},
324324
),
325325
CallStack {
@@ -336,7 +336,7 @@ fn block_qubit_use_array_invalid_count_expr() {
336336
0,
337337
),
338338
item: LocalItemId(
339-
3,
339+
5,
340340
),
341341
},
342342
caller: PackageId(

compiler/qsc_passes/src/lib.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ pub mod spec_gen;
1414

1515
use loop_unification::LoopUni;
1616
use miette::Diagnostic;
17-
use qsc_frontend::{
18-
compile::{CompileUnit, PackageStore},
19-
incremental::Fragment,
20-
};
17+
use qsc_frontend::{compile::CompileUnit, incremental::Fragment};
2118
use qsc_hir::{
2219
assigner::Assigner,
23-
global::Table,
24-
hir::{Item, ItemKind},
20+
global::{self, Table},
21+
hir::{Item, ItemKind, PackageId},
2522
mut_visit::MutVisitor,
2623
};
2724
use replace_qubit_allocation::ReplaceQubitAllocation;
@@ -42,10 +39,11 @@ pub fn run_default_passes(core: &Table, unit: &mut CompileUnit) -> Vec<Error> {
4239
let conjugate_errors = conjugate_invert::invert_conjugate_exprs(core, unit);
4340

4441
LoopUni {
42+
core,
4543
assigner: &mut unit.assigner,
4644
}
4745
.visit_package(&mut unit.package);
48-
ReplaceQubitAllocation::new(&mut unit.assigner, store.core()).visit_package(&mut unit.package);
46+
ReplaceQubitAllocation::new(core, &mut unit.assigner).visit_package(&mut unit.package);
4947

5048
spec_errors
5149
.into_iter()
@@ -54,17 +52,18 @@ pub fn run_default_passes(core: &Table, unit: &mut CompileUnit) -> Vec<Error> {
5452
.collect()
5553
}
5654

57-
pub fn run_core_passes(unit: &mut CompileUnit) {
55+
pub fn run_core_passes(core: &mut CompileUnit) {
56+
let table = global::iter_package(Some(PackageId::CORE), &core.package).collect();
5857
LoopUni {
59-
assigner: &mut unit.assigner,
58+
core: &table,
59+
assigner: &mut core.assigner,
6060
}
61-
.visit_package(&mut unit.package);
61+
.visit_package(&mut core.package);
6262
}
6363

6464
pub fn run_default_passes_for_fragment(
6565
core: &Table,
6666
assigner: &mut Assigner,
67-
core_table: &Table,
6867
fragment: &mut Fragment,
6968
) -> Vec<Error> {
7069
let mut errors = Vec::new();
@@ -76,8 +75,8 @@ pub fn run_default_passes_for_fragment(
7675
.into_iter()
7776
.map(Error::ConjInvert),
7877
);
79-
LoopUni { assigner }.visit_stmt(stmt);
80-
ReplaceQubitAllocation::new(assigner, core_table).visit_stmt(stmt);
78+
LoopUni { core, assigner }.visit_stmt(stmt);
79+
ReplaceQubitAllocation::new(core, assigner).visit_stmt(stmt);
8180
}
8281
Fragment::Item(Item {
8382
kind: ItemKind::Callable(decl),
@@ -93,8 +92,8 @@ pub fn run_default_passes_for_fragment(
9392
.into_iter()
9493
.map(Error::ConjInvert),
9594
);
96-
LoopUni { assigner }.visit_callable_decl(decl);
97-
ReplaceQubitAllocation::new(assigner, core_table).visit_callable_decl(decl);
95+
LoopUni { core, assigner }.visit_callable_decl(decl);
96+
ReplaceQubitAllocation::new(core, assigner).visit_callable_decl(decl);
9897
}
9998
Fragment::Item(_) | Fragment::Error(_) => {}
10099
}

compiler/qsc_passes/src/loop_unification/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn check(file: &str, expect: &Expect) {
1616
let mut unit = compile(&store, &[], sources);
1717
assert!(unit.errors.is_empty(), "{:?}", unit.errors);
1818
LoopUni {
19+
core: store.core(),
1920
assigner: &mut unit.assigner,
2021
}
2122
.visit_package(&mut unit.package);

compiler/qsc_passes/src/replace_qubit_allocation.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ struct QubitIdent {
2525

2626
pub(crate) struct ReplaceQubitAllocation<'a> {
2727
assigner: &'a mut Assigner,
28-
core_table: &'a Table,
28+
core: &'a Table,
2929
qubits_curr_callable: Vec<Vec<QubitIdent>>,
3030
qubits_curr_block: Vec<QubitIdent>,
3131
prefix_qubits: Vec<QubitIdent>,
3232
}
3333

3434
impl<'a> ReplaceQubitAllocation<'a> {
35-
pub(crate) fn new(assigner: &'a mut Assigner, core_table: &'a Table) -> Self {
35+
pub(crate) fn new(core: &'a Table, assigner: &'a mut Assigner) -> Self {
3636
Self {
3737
assigner,
38-
core_table,
38+
core,
3939
qubits_curr_callable: Vec::new(),
4040
qubits_curr_block: Vec::new(),
4141
prefix_qubits: Vec::new(),
@@ -212,7 +212,7 @@ impl<'a> ReplaceQubitAllocation<'a> {
212212
create_general_alloc_stmt(
213213
ident,
214214
create_gen_core_ref(
215-
self.core_table,
215+
self.core,
216216
"QIR.Runtime",
217217
"__quantum__rt__qubit_allocate",
218218
ident.span,
@@ -224,20 +224,15 @@ impl<'a> ReplaceQubitAllocation<'a> {
224224
fn create_array_alloc_stmt(&self, ident: &IdentTemplate, array_size: Expr) -> Stmt {
225225
create_general_alloc_stmt(
226226
ident,
227-
create_gen_core_ref(
228-
self.core_table,
229-
"QIR.Runtime",
230-
"AllocateQubitArray",
231-
ident.span,
232-
),
227+
create_gen_core_ref(self.core, "QIR.Runtime", "AllocateQubitArray", ident.span),
233228
Some(array_size),
234229
)
235230
}
236231

237232
fn create_dealloc_stmt(&self, ident: &IdentTemplate) -> Stmt {
238233
create_general_dealloc_stmt(
239234
create_gen_core_ref(
240-
self.core_table,
235+
self.core,
241236
"QIR.Runtime",
242237
"__quantum__rt__qubit_release",
243238
ident.span,
@@ -248,12 +243,7 @@ impl<'a> ReplaceQubitAllocation<'a> {
248243

249244
fn create_array_dealloc_stmt(&self, ident: &IdentTemplate) -> Stmt {
250245
create_general_dealloc_stmt(
251-
create_gen_core_ref(
252-
self.core_table,
253-
"QIR.Runtime",
254-
"ReleaseQubitArray",
255-
ident.span,
256-
),
246+
create_gen_core_ref(self.core, "QIR.Runtime", "ReleaseQubitArray", ident.span),
257247
ident,
258248
)
259249
}

compiler/qsc_passes/src/replace_qubit_allocation/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn check(file: &str, expect: &Expect) {
1212
let sources = SourceMap::new([("test".into(), file.into())], None);
1313
let mut unit = compile(&store, &[], sources);
1414
assert!(unit.errors.is_empty(), "{:?}", unit.errors);
15-
ReplaceQubitAllocation::new(&mut unit.assigner, store.core()).visit_package(&mut unit.package);
15+
ReplaceQubitAllocation::new(store.core(), &mut unit.assigner).visit_package(&mut unit.package);
1616
expect.assert_eq(&unit.package.to_string());
1717
}
1818

0 commit comments

Comments
 (0)