@@ -468,8 +468,7 @@ impl<'a> Analyzer<'a> {
468468 self . get_current_application_instance ( )
469469 . locals_map
470470 . find_local_compute_kind ( local_var_id)
471- . expect ( "local should have been processed before this" )
472- . compute_kind
471+ . map_or ( ComputeKind :: Classical , |v| v. compute_kind )
473472 . value_kind_or_default ( ValueKind :: Element ( RuntimeKind :: Static ) )
474473 } )
475474 . chain ( self . derive_arg_value_kinds ( & arg_exprs) )
@@ -1091,10 +1090,10 @@ impl<'a> Analyzer<'a> {
10911090 // Gather the current compute kind of the local.
10921091 Res :: Local ( local_var_id) => {
10931092 let application_instance = self . get_current_application_instance ( ) ;
1094- let local_compute_kind = application_instance
1093+ application_instance
10951094 . locals_map
1096- . get_local_compute_kind ( * local_var_id) ;
1097- local_compute_kind . compute_kind
1095+ . find_local_compute_kind ( * local_var_id)
1096+ . map_or ( ComputeKind :: Classical , |v| v . compute_kind )
10981097 }
10991098 Res :: Err => panic ! ( "unexpected error resolution" ) ,
11001099 }
@@ -1332,15 +1331,13 @@ impl<'a> Analyzer<'a> {
13321331
13331332 fn bind_compute_kind_to_ident (
13341333 & mut self ,
1335- pat : & Pat ,
13361334 ident : & Ident ,
13371335 local_kind : LocalKind ,
13381336 compute_kind : ComputeKind ,
13391337 ) {
13401338 let application_instance = self . get_current_application_instance_mut ( ) ;
13411339 let local = Local {
13421340 var : ident. id ,
1343- ty : pat. ty . clone ( ) ,
13441341 kind : local_kind,
13451342 } ;
13461343 let local_compute_kind = LocalComputeKind {
@@ -1369,7 +1366,7 @@ impl<'a> Analyzer<'a> {
13691366 let application_instance = self . get_current_application_instance ( ) ;
13701367 let expr_compute_kind = * application_instance. get_expr_compute_kind ( expr_id) ;
13711368 let bound_compute_kind = ComputeKind :: map_to_type ( expr_compute_kind, & pat. ty ) ;
1372- self . bind_compute_kind_to_ident ( pat , ident, local_kind, bound_compute_kind) ;
1369+ self . bind_compute_kind_to_ident ( ident, local_kind, bound_compute_kind) ;
13731370 }
13741371 PatKind :: Tuple ( pats) => match & expr. kind {
13751372 ExprKind :: Tuple ( exprs) => {
@@ -1403,7 +1400,7 @@ impl<'a> Analyzer<'a> {
14031400 let application_instance = self . get_current_application_instance ( ) ;
14041401 let expr_compute_kind = * application_instance. get_expr_compute_kind ( expr_id) ;
14051402 let bound_compute_kind = ComputeKind :: map_to_type ( expr_compute_kind, & pat. ty ) ;
1406- self . bind_compute_kind_to_ident ( pat , ident, local_kind, bound_compute_kind) ;
1403+ self . bind_compute_kind_to_ident ( ident, local_kind, bound_compute_kind) ;
14071404 }
14081405 PatKind :: Tuple ( pats) => {
14091406 for pat_id in pats {
@@ -1569,10 +1566,14 @@ impl<'a> Analyzer<'a> {
15691566 // The updated compute kind is the aggregation of the compute kind of the local variable and the
15701567 // assigned value.
15711568 // Start by initializing the updated compute kind with the compute kind of the local variable.
1572- let application_instance = self . get_current_application_instance ( ) ;
1569+ let application_instance = self . get_current_application_instance_mut ( ) ;
15731570 let local_var_compute_kind = application_instance
15741571 . locals_map
1575- . get_local_compute_kind ( * local_var_id) ;
1572+ . get_or_init_local_compute_kind (
1573+ * local_var_id,
1574+ LocalKind :: Mutable ,
1575+ ComputeKind :: Classical ,
1576+ ) ;
15761577 let mut updated_compute_kind = local_var_compute_kind. compute_kind ;
15771578
15781579 // Since the local variable compute kind is what will be updated, the value kind must match the local
@@ -1582,16 +1583,14 @@ impl<'a> Analyzer<'a> {
15821583 // a UDT variable field since we do not track individual UDT fields).
15831584 let value_expr_compute_kind =
15841585 * application_instance. get_expr_compute_kind ( value_expr_id) ;
1585- let assigned_compute_kind = ComputeKind :: map_to_type (
1586- value_expr_compute_kind,
1587- & local_var_compute_kind. local . ty ,
1588- ) ;
1586+ let assigned_compute_kind =
1587+ ComputeKind :: map_to_type ( value_expr_compute_kind, & assignee_expr. ty ) ;
15891588 updated_compute_kind = updated_compute_kind. aggregate ( assigned_compute_kind) ;
15901589
15911590 // If a local is updated within a dynamic scope, the updated value of the local variable should be
15921591 // dynamic and additional runtime features may apply.
15931592 if !application_instance. active_dynamic_scopes . is_empty ( ) {
1594- let local_type = & local_var_compute_kind . local . ty ;
1593+ let local_type = & assignee_expr . ty ;
15951594 let mut dynamic_value_kind = ValueKind :: new_dynamic_from_type ( local_type) ;
15961595 let mut dynamic_runtime_features =
15971596 derive_runtime_features_for_value_kind_associated_to_type (
@@ -1621,7 +1620,7 @@ impl<'a> Analyzer<'a> {
16211620 updated_quantum_properties. runtime_features |=
16221621 derive_runtime_features_for_value_kind_associated_to_type (
16231622 value_kind,
1624- & local_var_compute_kind . local . ty ,
1623+ & assignee_expr . ty ,
16251624 ) ;
16261625 }
16271626
@@ -2551,7 +2550,6 @@ fn derive_specialization_controls(
25512550 match & pat. kind {
25522551 PatKind :: Bind ( ident) => Some ( Local {
25532552 var : ident. id ,
2554- ty : pat. ty . clone ( ) ,
25552553 kind : LocalKind :: SpecInput ,
25562554 } ) ,
25572555 PatKind :: Discard => None , // Nothing to bind to.
0 commit comments