From d0346c43b6916c9aa0f2c1acce2ccf7b4c84ad0e Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Tue, 28 May 2024 13:25:17 -0700 Subject: [PATCH] Respect target setting for "Estimate" command (#1576) Fixes #1199. --- npm/qsharp/src/compiler/compiler.ts | 16 +++++++++++++--- vscode/src/webviewPanel.ts | 9 ++++++--- wasm/src/lib.rs | 4 +++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/npm/qsharp/src/compiler/compiler.ts b/npm/qsharp/src/compiler/compiler.ts index 806d77c988..ac53410a51 100644 --- a/npm/qsharp/src/compiler/compiler.ts +++ b/npm/qsharp/src/compiler/compiler.ts @@ -195,10 +195,15 @@ export class Compiler implements ICompiler { } async newGetEstimates( - { sources, languageFeatures }: ProgramConfig, + { sources, languageFeatures, profile = "unrestricted" }: ProgramConfig, params: string, ): Promise { - return this.wasm.get_estimates(sources, params, languageFeatures || []); + return this.wasm.get_estimates( + sources, + params, + languageFeatures || [], + profile, + ); } async deprecatedGetEstimates( @@ -206,7 +211,12 @@ export class Compiler implements ICompiler { params: string, languageFeatures: string[], ): Promise { - return this.wasm.get_estimates(sources, params, languageFeatures); + return this.wasm.get_estimates( + sources, + params, + languageFeatures, + "unrestricted", + ); } async getAst( diff --git a/vscode/src/webviewPanel.ts b/vscode/src/webviewPanel.ts index e68fa370a9..4eccb87a9a 100644 --- a/vscode/src/webviewPanel.ts +++ b/vscode/src/webviewPanel.ts @@ -220,9 +220,12 @@ export function registerWebViewCommands(context: ExtensionContext) { {}, ); const estimatesStr = await worker.getEstimates( - sources, + { + sources, + languageFeatures, + profile: getTarget(), + }, JSON.stringify(params), - languageFeatures, ); sendTelemetryEvent( EventType.ResourceEstimationEnd, @@ -371,7 +374,7 @@ export function registerWebViewCommands(context: ExtensionContext) { clearTimeout(compilerTimeout); } catch (e: any) { log.error("Histogram error. ", e.toString()); - throw new Error("Run failed"); + throw new Error("Run failed. " + e.toString()); } finally { worker.terminate(); } diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 5902262353..dfe67440e5 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -103,8 +103,10 @@ pub fn get_estimates( sources: Vec, params: &str, language_features: Vec, + targetProfile: &str, ) -> Result { let sources = get_source_map(sources, &None); + let target_profile = Profile::from_str(targetProfile).expect("invalid target profile"); let language_features = LanguageFeatures::from_iter(language_features); @@ -112,7 +114,7 @@ pub fn get_estimates( true, sources, PackageType::Exe, - Profile::Unrestricted.into(), + target_profile.into(), language_features, ) .map_err(|e| e[0].to_string())?;