Skip to content

Commit

Permalink
Respect target setting for "Estimate" command (#1576)
Browse files Browse the repository at this point in the history
Fixes #1199.
  • Loading branch information
swernli authored May 28, 2024
1 parent a66b323 commit d0346c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
16 changes: 13 additions & 3 deletions npm/qsharp/src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,28 @@ export class Compiler implements ICompiler {
}

async newGetEstimates(
{ sources, languageFeatures }: ProgramConfig,
{ sources, languageFeatures, profile = "unrestricted" }: ProgramConfig,
params: string,
): Promise<string> {
return this.wasm.get_estimates(sources, params, languageFeatures || []);
return this.wasm.get_estimates(
sources,
params,
languageFeatures || [],
profile,
);
}

async deprecatedGetEstimates(
sources: [string, string][],
params: string,
languageFeatures: string[],
): Promise<string> {
return this.wasm.get_estimates(sources, params, languageFeatures);
return this.wasm.get_estimates(
sources,
params,
languageFeatures,
"unrestricted",
);
}

async getAst(
Expand Down
9 changes: 6 additions & 3 deletions vscode/src/webviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,18 @@ pub fn get_estimates(
sources: Vec<js_sys::Array>,
params: &str,
language_features: Vec<String>,
targetProfile: &str,
) -> Result<String, String> {
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);

let mut interpreter = interpret::Interpreter::new(
true,
sources,
PackageType::Exe,
Profile::Unrestricted.into(),
target_profile.into(),
language_features,
)
.map_err(|e| e[0].to_string())?;
Expand Down

0 comments on commit d0346c4

Please sign in to comment.