@@ -17,15 +17,12 @@ use intrinsic::invoke_intrinsic;
17
17
use miette:: Diagnostic ;
18
18
use num_bigint:: BigInt ;
19
19
use output:: Receiver ;
20
- use qir_backend:: {
21
- __quantum__rt__initialize, __quantum__rt__qubit_allocate, __quantum__rt__qubit_release,
22
- qubit_is_zero,
23
- } ;
20
+ use qir_backend:: __quantum__rt__initialize;
24
21
use qsc_data_structures:: span:: Span ;
25
22
use qsc_hir:: hir:: {
26
23
self , BinOp , Block , CallableBody , CallableDecl , Expr , ExprKind , Functor , Lit , Mutability ,
27
- NodeId , PackageId , Pat , PatKind , PrimField , QubitInit , QubitInitKind , Res , Spec , SpecBody ,
28
- SpecGen , Stmt , StmtKind , StringComponent , TernOp , UnOp ,
24
+ NodeId , PackageId , Pat , PatKind , PrimField , Res , Spec , SpecBody , SpecGen , Stmt , StmtKind ,
25
+ StringComponent , TernOp , UnOp ,
29
26
} ;
30
27
use std:: {
31
28
collections:: { hash_map:: Entry , HashMap } ,
@@ -35,7 +32,7 @@ use std::{
35
32
rc:: Rc ,
36
33
} ;
37
34
use thiserror:: Error ;
38
- use val:: { GlobalId , Qubit } ;
35
+ use val:: GlobalId ;
39
36
40
37
#[ derive( Clone , Debug , Diagnostic , Error ) ]
41
38
pub enum Error {
@@ -88,7 +85,7 @@ pub enum Error {
88
85
RangeStepZero ( #[ label( "invalid range" ) ] Span ) ,
89
86
90
87
#[ error( "Qubit{0} released while not in |0⟩ state" ) ]
91
- ReleasedQubitNotZero ( usize , # [ label ] Span ) ,
88
+ ReleasedQubitNotZero ( usize ) ,
92
89
93
90
#[ error( "mismatched types" ) ]
94
91
Type (
@@ -247,7 +244,6 @@ impl Env {
247
244
#[ derive( Default ) ]
248
245
struct Scope {
249
246
bindings : HashMap < NodeId , Variable > ,
250
- qubits : Vec < ( Qubit , Span ) > ,
251
247
}
252
248
253
249
impl Env {
@@ -261,7 +257,6 @@ enum Event<'a> {
261
257
Cont ( Cont < ' a > ) ,
262
258
Expr ( & ' a Expr ) ,
263
259
Frame ,
264
- Qubit ( & ' a QubitInit ) ,
265
260
Scope ,
266
261
Stmt ( & ' a Stmt ) ,
267
262
}
@@ -279,7 +274,6 @@ enum Cont<'a> {
279
274
Field ( PrimField , Span ) ,
280
275
If ( & ' a Block , & ' a Option < Box < Expr > > ) ,
281
276
Index ( Span ) ,
282
- QubitArray ( Span , Span ) ,
283
277
Range ( bool , bool , bool ) ,
284
278
Return ,
285
279
StringConcat ( usize ) ,
@@ -357,38 +351,16 @@ impl<'a, G: GlobalLookup<'a>> State<'a, G> {
357
351
self . push_val ( last_val) ;
358
352
}
359
353
360
- fn push_qubit ( & mut self , qubit_init : & ' a QubitInit ) {
361
- self . stack . push ( Event :: Qubit ( qubit_init) ) ;
362
- }
363
-
364
354
fn push_scope ( & mut self ) {
365
355
self . env . 0 . push ( Scope :: default ( ) ) ;
366
356
self . stack . push ( Event :: Scope ) ;
367
357
}
368
358
369
- fn track_qubit ( & mut self , qubit : Qubit , span : Span ) {
359
+ fn leave_scope ( & mut self ) {
370
360
self . env
371
- . 0
372
- . last_mut ( )
373
- . expect ( "scope should have been entered to track qubits" )
374
- . qubits
375
- . push ( ( qubit, span) ) ;
376
- }
377
-
378
- fn leave_scope ( & mut self ) -> Result < ( ) , Error > {
379
- for ( qubit, span) in self
380
- . env
381
361
. 0
382
362
. pop ( )
383
- . expect ( "scope should be entered first before leaving" )
384
- . qubits
385
- {
386
- if !qubit_is_zero ( qubit. 0 ) {
387
- return Err ( Error :: ReleasedQubitNotZero ( qubit. 0 as usize , span) ) ;
388
- }
389
- __quantum__rt__qubit_release ( qubit. 0 ) ;
390
- }
391
- Ok ( ( ) )
363
+ . expect ( "scope should be entered first before leaving" ) ;
392
364
}
393
365
394
366
fn push_stmt ( & mut self , stmt : & ' a Stmt ) {
@@ -436,11 +408,10 @@ impl<'a, G: GlobalLookup<'a>> State<'a, G> {
436
408
self . leave_frame ( ) ;
437
409
Ok ( ( ) )
438
410
}
439
- Event :: Qubit ( qubit_init ) => {
440
- self . handle_qubit_init ( qubit_init ) ;
411
+ Event :: Scope => {
412
+ self . leave_scope ( ) ;
441
413
Ok ( ( ) )
442
414
}
443
- Event :: Scope => self . leave_scope ( ) ,
444
415
Event :: Stmt ( stmt) => {
445
416
self . handle_stmt ( stmt) ;
446
417
Ok ( ( ) )
@@ -698,14 +669,7 @@ impl<'a, G: GlobalLookup<'a>> State<'a, G> {
698
669
self . push_expr ( expr) ;
699
670
self . push_val ( Value :: unit ( ) ) ;
700
671
}
701
- StmtKind :: Qubit ( _, pat, qubit_init, block) => {
702
- if let Some ( block) = block {
703
- self . push_block ( block) ;
704
- }
705
- self . push_cont ( Cont :: Bind ( pat, Mutability :: Immutable ) ) ;
706
- self . push_qubit ( qubit_init) ;
707
- self . push_val ( Value :: unit ( ) ) ;
708
- }
672
+ StmtKind :: Qubit ( ..) => panic ! ( "qubit use-stmt should be eliminated by passes" ) ,
709
673
StmtKind :: Semi ( expr) => {
710
674
self . push_cont ( Cont :: Consume ) ;
711
675
self . push_expr ( expr) ;
@@ -714,26 +678,6 @@ impl<'a, G: GlobalLookup<'a>> State<'a, G> {
714
678
}
715
679
}
716
680
717
- fn handle_qubit_init ( & mut self , qubit_init : & ' a QubitInit ) {
718
- match & qubit_init. kind {
719
- QubitInitKind :: Array ( count) => {
720
- self . push_cont ( Cont :: QubitArray ( qubit_init. span , count. span ) ) ;
721
- self . push_expr ( count) ;
722
- }
723
- QubitInitKind :: Single => {
724
- let qubit = Qubit ( __quantum__rt__qubit_allocate ( ) ) ;
725
- self . track_qubit ( qubit, qubit_init. span ) ;
726
- self . push_val ( Value :: Qubit ( qubit) ) ;
727
- }
728
- QubitInitKind :: Tuple ( tup) => {
729
- self . push_cont ( Cont :: Tuple ( tup. len ( ) ) ) ;
730
- for init in tup. iter ( ) . rev ( ) {
731
- self . push_qubit ( init) ;
732
- }
733
- }
734
- }
735
- }
736
-
737
681
fn cont ( & mut self , cont : Cont < ' a > ) -> Result < ( ) , Error > {
738
682
match cont {
739
683
Cont :: Array ( len) => self . cont_array ( len) ,
@@ -754,13 +698,10 @@ impl<'a, G: GlobalLookup<'a>> State<'a, G> {
754
698
Cont :: Field ( field, span) => self . cont_field ( field, span) ?,
755
699
Cont :: If ( then_block, else_expr) => self . cont_if ( then_block, else_expr) ,
756
700
Cont :: Index ( span) => self . cont_index ( span) ?,
757
- Cont :: QubitArray ( qubit_span, count_span) => {
758
- self . cont_qubit_array ( qubit_span, count_span) ?;
759
- }
760
701
Cont :: Range ( has_start, has_step, has_end) => {
761
702
self . cont_range ( has_start, has_step, has_end) ;
762
703
}
763
- Cont :: Return => self . cont_ret ( ) ? ,
704
+ Cont :: Return => self . cont_ret ( ) ,
764
705
Cont :: StringConcat ( len) => self . cont_string_concat ( len) ,
765
706
Cont :: StringLit ( str) => self . push_val ( Value :: String ( Rc :: clone ( str) ) ) ,
766
707
Cont :: TernOp ( op, mid, rhs) => self . cont_ternop ( op, mid, rhs) ?,
@@ -947,22 +888,6 @@ impl<'a, G: GlobalLookup<'a>> State<'a, G> {
947
888
Ok ( ( ) )
948
889
}
949
890
950
- fn cont_qubit_array ( & mut self , qubit_span : Span , count_span : Span ) -> Result < ( ) , Error > {
951
- let count_val = self . pop_val ( ) . into_int ( ) ;
952
- let count: usize = match count_val. try_into ( ) {
953
- Ok ( i) => Ok ( i) ,
954
- Err ( _) => Err ( Error :: Count ( count_val, count_span) ) ,
955
- } ?;
956
- let mut arr = Vec :: new ( ) ;
957
- for _ in 0 ..count {
958
- let qubit = Qubit ( __quantum__rt__qubit_allocate ( ) ) ;
959
- self . track_qubit ( qubit, qubit_span) ;
960
- arr. push ( Value :: Qubit ( qubit) ) ;
961
- }
962
- self . push_val ( Value :: Array ( arr. into ( ) ) ) ;
963
- Ok ( ( ) )
964
- }
965
-
966
891
fn cont_range ( & mut self , has_start : bool , has_step : bool , has_end : bool ) {
967
892
let end = if has_end {
968
893
Some ( self . pop_val ( ) . into_int ( ) )
@@ -982,7 +907,7 @@ impl<'a, G: GlobalLookup<'a>> State<'a, G> {
982
907
self . push_val ( Value :: Range ( start, step, end) ) ;
983
908
}
984
909
985
- fn cont_ret ( & mut self ) -> Result < ( ) , Error > {
910
+ fn cont_ret ( & mut self ) {
986
911
loop {
987
912
let Some ( event) = self . pop_event ( ) else {
988
913
break ;
@@ -992,13 +917,10 @@ impl<'a, G: GlobalLookup<'a>> State<'a, G> {
992
917
self . leave_frame ( ) ;
993
918
break ;
994
919
}
995
- Event :: Scope => {
996
- self . leave_scope ( ) ?;
997
- }
920
+ Event :: Scope => self . leave_scope ( ) ,
998
921
_ => { }
999
922
}
1000
923
}
1001
- Ok ( ( ) )
1002
924
}
1003
925
1004
926
fn cont_string_concat ( & mut self , len : usize ) {
0 commit comments