diff --git a/compiler/qsc_rca/src/core.rs b/compiler/qsc_rca/src/core.rs index 7b0b6229d1..ce945a7915 100644 --- a/compiler/qsc_rca/src/core.rs +++ b/compiler/qsc_rca/src/core.rs @@ -1155,12 +1155,9 @@ impl<'a> Analyzer<'a> { CallableKind::Function => { derive_intrinsic_function_application_generator_set(callable_context) } - CallableKind::Operation => { + CallableKind::Operation | CallableKind::Measurement => { derive_instrinsic_operation_application_generator_set(callable_context) } - CallableKind::Measurement => { - derive_instrinsic_measurement_application_generator_set(callable_context) - } }; // Insert the generator set in the entry corresponding to the body specialization of the callable. @@ -2241,61 +2238,10 @@ fn array_param_application_from_runtime_features( fn derive_instrinsic_operation_application_generator_set( callable_context: &CallableContext, ) -> ApplicationGeneratorSet { - assert!(matches!(callable_context.kind, CallableKind::Operation)); - - // The value kind of intrinsic operations is inherently dynamic if their output is not `Unit` or `Qubit`. - let value_kind = if callable_context.output_type == Ty::UNIT - || callable_context.output_type == Ty::Prim(Prim::Qubit) - { - ValueKind::Element(RuntimeKind::Static) - } else { - ValueKind::new_dynamic_from_type(&callable_context.output_type) - }; - - // The compute kind of intrinsic operations is always quantum. - let inherent_compute_kind = ComputeKind::Quantum(QuantumProperties { - runtime_features: RuntimeFeatureFlags::empty(), - value_kind, - }); - - // Determine the compute kind of all dynamic parameter applications. - let mut dynamic_param_applications = - Vec::::with_capacity(callable_context.input_params.len()); - for param in &callable_context.input_params { - // For intrinsic operations, we assume any parameter can contribute to the output, so if any parameter is - // dynamic the output of the operation is dynamic. - // When a parameter is bound to a dynamic value, its type contributes to the runtime features used by the - // operation application. - let runtime_features = derive_runtime_features_for_value_kind_associated_to_type( - ValueKind::new_dynamic_from_type(¶m.ty), - ¶m.ty, - ); - let value_kind = ValueKind::new_dynamic_from_type(&callable_context.output_type); - let param_compute_kind = ComputeKind::Quantum(QuantumProperties { - runtime_features, - value_kind, - }); - - // Create a parameter application depending on the parameter type. - let param_application = match ¶m.ty { - Ty::Array(_) => { - array_param_application_from_runtime_features(runtime_features, value_kind) - } - _ => ParamApplication::Element(param_compute_kind), - }; - dynamic_param_applications.push(param_application); - } - - ApplicationGeneratorSet { - inherent: inherent_compute_kind, - dynamic_param_applications, - } -} - -fn derive_instrinsic_measurement_application_generator_set( - callable_context: &CallableContext, -) -> ApplicationGeneratorSet { - assert!(matches!(callable_context.kind, CallableKind::Measurement)); + assert!(matches!( + callable_context.kind, + CallableKind::Operation | CallableKind::Measurement + )); // The value kind of intrinsic operations is inherently dynamic if their output is not `Unit` or `Qubit`. let value_kind = if callable_context.output_type == Ty::UNIT @@ -2308,7 +2254,11 @@ fn derive_instrinsic_measurement_application_generator_set( // The compute kind of intrinsic operations is always quantum. let inherent_compute_kind = ComputeKind::Quantum(QuantumProperties { - runtime_features: RuntimeFeatureFlags::CustomMeasurement, + runtime_features: if matches!(callable_context.kind, CallableKind::Operation) { + RuntimeFeatureFlags::empty() + } else { + RuntimeFeatureFlags::CustomMeasurement + }, value_kind, });