From f1c5c112ba5a41116f1876a8f846c8068af8a06d Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Wed, 6 Aug 2025 10:44:44 -0700 Subject: [PATCH 1/4] playground default for qir gen is adaptive_rif and looks for entrypoint target profile --- source/npm/qsharp/src/browser.ts | 15 ++++++++++++++- source/npm/qsharp/src/compiler/compiler.ts | 2 +- source/npm/qsharp/src/project.ts | 12 ------------ source/playground/src/editor.tsx | 3 +++ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/source/npm/qsharp/src/browser.ts b/source/npm/qsharp/src/browser.ts index 9b8821d0c1..cf9def6ca4 100644 --- a/source/npm/qsharp/src/browser.ts +++ b/source/npm/qsharp/src/browser.ts @@ -22,6 +22,7 @@ import { QSharpDebugService, debugServiceProtocol, } from "./debug-service/debug-service.js"; +import { callAndTransformExceptions } from "./diagnostics.js"; import { ILanguageService, ILanguageServiceWorker, @@ -156,6 +157,19 @@ export function getLanguageServiceWorker( return createProxy(worker, wasmModule, languageServiceProtocol); } +export async function getTargetProfileFromEntryPoint( + fileName: string, + source: string, +): Promise { + await instantiateWasm(); + return callAndTransformExceptions( + async () => + wasm.get_target_profile_from_entry_point(fileName, source) as + | wasm.TargetProfile + | undefined, + ); +} + export { StepResultId } from "../lib/web/qsc_wasm.js"; export type { IBreakpointSpan, @@ -186,7 +200,6 @@ export type { } from "./language-service/language-service.js"; export { default as openqasm_samples } from "./openqasm-samples.generated.js"; export type { ProjectLoader } from "./project.js"; -export { getTargetProfileFromEntryPoint } from "./project.js"; export { default as samples } from "./samples.generated.js"; export type { CircuitGroup as CircuitData } from "./data-structures/circuit.js"; export * as utils from "./utils.js"; diff --git a/source/npm/qsharp/src/compiler/compiler.ts b/source/npm/qsharp/src/compiler/compiler.ts index b2a3d08b1e..6ed5d19fce 100644 --- a/source/npm/qsharp/src/compiler/compiler.ts +++ b/source/npm/qsharp/src/compiler/compiler.ts @@ -204,7 +204,7 @@ export class Compiler implements ICompiler { async getQir(program: ProgramConfig): Promise { return callAndTransformExceptions(async () => - this.wasm.get_qir(toWasmProgramConfig(program, "base")), + this.wasm.get_qir(toWasmProgramConfig(program, "adaptive_rif")), ); } diff --git a/source/npm/qsharp/src/project.ts b/source/npm/qsharp/src/project.ts index 3bff8825c4..86e149898a 100644 --- a/source/npm/qsharp/src/project.ts +++ b/source/npm/qsharp/src/project.ts @@ -29,15 +29,3 @@ export class ProjectLoader { ); } } - -export async function getTargetProfileFromEntryPoint( - fileName: string, - source: string, -): Promise { - return callAndTransformExceptions( - async () => - wasm.get_target_profile_from_entry_point(fileName, source) as - | wasm.TargetProfile - | undefined, - ); -} diff --git a/source/playground/src/editor.tsx b/source/playground/src/editor.tsx index 7794926d28..2ce070bca2 100644 --- a/source/playground/src/editor.tsx +++ b/source/playground/src/editor.tsx @@ -13,6 +13,7 @@ import { log, ProgramConfig, LanguageServiceDiagnosticEvent, + getTargetProfileFromEntryPoint, } from "qsharp-lang"; import { Exercise, getExerciseSources } from "qsharp-lang/katas-md"; import { codeToCompressedBase64, lsRangeToMonacoRange } from "./utils.js"; @@ -128,6 +129,7 @@ export function Editor(props: { const config = { sources: [["code", code]] as [string, string][], languageFeatures: [], + profile: await getTargetProfileFromEntryPoint("main.qs", code), }; if (props.activeTab === "ast-tab") { @@ -182,6 +184,7 @@ export function Editor(props: { const config = { sources: [["code", code]], languageFeatures: [], + profile: await getTargetProfileFromEntryPoint("main.qs", code), } as ProgramConfig; try { From 792db3526b6e53db37bac535c52f711d07eb5319 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Wed, 6 Aug 2025 10:49:42 -0700 Subject: [PATCH 2/4] added function description --- source/npm/qsharp/src/browser.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/npm/qsharp/src/browser.ts b/source/npm/qsharp/src/browser.ts index cf9def6ca4..15dc0a0af9 100644 --- a/source/npm/qsharp/src/browser.ts +++ b/source/npm/qsharp/src/browser.ts @@ -157,6 +157,10 @@ export function getLanguageServiceWorker( return createProxy(worker, wasmModule, languageServiceProtocol); } +/// Extracts the target profile from a Q# source file's entry point. +/// Scans the provided source code for an EntryPoint argument specifying +/// a profile and returns the corresponding TargetProfile value, if found. +/// Returns undefined if no profile is specified or if the profile is not recognized. export async function getTargetProfileFromEntryPoint( fileName: string, source: string, From b452d7d89443fa3f9b77739dda5b366caa71aee7 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Wed, 6 Aug 2025 12:57:41 -0700 Subject: [PATCH 3/4] default for rir is adaptive_rif --- source/npm/qsharp/src/compiler/compiler.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/source/npm/qsharp/src/compiler/compiler.ts b/source/npm/qsharp/src/compiler/compiler.ts index 6ed5d19fce..a9cd4f08ea 100644 --- a/source/npm/qsharp/src/compiler/compiler.ts +++ b/source/npm/qsharp/src/compiler/compiler.ts @@ -156,10 +156,7 @@ export class Compiler implements ICompiler { } async getRir(program: ProgramConfig): Promise { - const config = toWasmProgramConfig( - program, - program.profile || "adaptive_ri", - ); + const config = toWasmProgramConfig(program, "adaptive_rif"); return callAndTransformExceptions(async () => this.wasm.get_rir(config)); } From de6e04927312ba256ccab00b237f4dc203e8e521 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Wed, 6 Aug 2025 16:00:12 -0700 Subject: [PATCH 4/4] keep npm defaults unchanged --- source/npm/qsharp/src/compiler/compiler.ts | 4 ++-- source/playground/src/editor.tsx | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/npm/qsharp/src/compiler/compiler.ts b/source/npm/qsharp/src/compiler/compiler.ts index a9cd4f08ea..9ff7e23540 100644 --- a/source/npm/qsharp/src/compiler/compiler.ts +++ b/source/npm/qsharp/src/compiler/compiler.ts @@ -156,7 +156,7 @@ export class Compiler implements ICompiler { } async getRir(program: ProgramConfig): Promise { - const config = toWasmProgramConfig(program, "adaptive_rif"); + const config = toWasmProgramConfig(program, "adaptive_ri"); return callAndTransformExceptions(async () => this.wasm.get_rir(config)); } @@ -201,7 +201,7 @@ export class Compiler implements ICompiler { async getQir(program: ProgramConfig): Promise { return callAndTransformExceptions(async () => - this.wasm.get_qir(toWasmProgramConfig(program, "adaptive_rif")), + this.wasm.get_qir(toWasmProgramConfig(program, "base")), ); } diff --git a/source/playground/src/editor.tsx b/source/playground/src/editor.tsx index 2ce070bca2..28ef7323b1 100644 --- a/source/playground/src/editor.tsx +++ b/source/playground/src/editor.tsx @@ -129,7 +129,9 @@ export function Editor(props: { const config = { sources: [["code", code]] as [string, string][], languageFeatures: [], - profile: await getTargetProfileFromEntryPoint("main.qs", code), + profile: + (await getTargetProfileFromEntryPoint("main.qs", code)) || + "adaptive_rif", // Default to adaptive_rif for qir and rir generation }; if (props.activeTab === "ast-tab") {