Send Compile & run through a CompileBackend instead of straight to godbolt
Every compile went to godbolt.org from the session directly. The roadmap moves compiles, and later Dafny and Lean checks, to a pinned service of the app's own, and godbolt has no service guarantee, so where a compile goes is now one replaceable piece. - src/services/compile-backend.ts: a CompileBackend (id, host, compiler, compile), explorerBackend() for any service that speaks Compiler Explorer's API at a base URL, GODBOLT as the default, and compileBackend() / setCompileBackend(). - godbolt.ts: compileMojo takes a CompileTarget (base, compiler, host) and names that host in its messages; the request body is unchanged, so tests/mojo.test.mjs still holds it to what the corpus pipeline sends. - Session.compile asks the current backend and records which host answered (CompileRecord.host; older records came from godbolt.org). - The Compiler view names the host it is asking and the host that answered. The "Compiled on godbolt" badge keeps its wording until a second backend is deployed. A test sends a compile through a fake backend and a refused local address. Manual check list: open a Mojo exercise in the Developer area, Compile & run, and see "Asking godbolt.org (mojo_1_1_0)…" then "Mojo 1.1.0 on godbolt.org" in the Compiler view. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
This commit is contained in:
5 files changed
+91
-15
No files matched your search
+10
-5
@@ -12,7 +12,8 @@ import { provePseudo, studyOf, defaultCall } from '../services/pseudo.js';
|
||||
import { mojoReadsInput, type MojoProgram } from '../services/mojo.js';
|
||||
import { runMojo } from '../mojo/interp.js';
|
||||
import { fuzzPseudo, fuzzMojo, type FuzzReport, type FuzzOptions } from './fuzz.js';
|
||||
import { compileMojo, compilerDiagnostics, listingFunctions, type BuildLevel, type CompileOutcome, type ListingFunction } from '../services/godbolt.js';
|
||||
import { compilerDiagnostics, listingFunctions, type BuildLevel, type CompileOptions, type CompileOutcome, type ListingFunction } from '../services/godbolt.js';
|
||||
import { compileBackend } from '../services/compile-backend.js';
|
||||
import { keepCompile, keptCompiles, compiledStatus, type CompiledStatus, type KeptCompile } from './compiles.js';
|
||||
import { mojoProvenance, type MojoProvenance } from './provenance.js';
|
||||
import { practicesOn } from './prefs.js';
|
||||
@@ -29,6 +30,8 @@ export interface CompileRecord {
|
||||
level: BuildLevel;
|
||||
at: number;
|
||||
outcome: CompileOutcome;
|
||||
/** The service that answered (compileBackend().host when asked); absent in records kept before it was stored, which all came from godbolt.org. */
|
||||
host?: string;
|
||||
/** The compiler's messages, on the Mojo pane's lines. */
|
||||
diagnostics: Diagnostic[];
|
||||
/** The listing, one entry per function. */
|
||||
@@ -319,16 +322,18 @@ export class Session {
|
||||
buildLevel(): BuildLevel { return this.state.build ?? 'O0'; }
|
||||
setBuildLevel(level: BuildLevel): void { this.state.build = level; this.persist(); this.emit('state'); }
|
||||
|
||||
/** Compile and run the Mojo pane on godbolt; the answer is kept for the views that read it. */
|
||||
compile(fetchImpl?: typeof compileMojo, levelOverride?: BuildLevel): Promise<CompileRecord | null> {
|
||||
/** Compile and run the Mojo pane on the compile backend (godbolt.org unless set otherwise); the answer is kept for the views that read it. */
|
||||
compile(fetchImpl?: (source: string, opts: CompileOptions) => Promise<CompileOutcome>, levelOverride?: BuildLevel): Promise<CompileRecord | null> {
|
||||
if (this.compiling) return this.compiling;
|
||||
const source = this.source('mojo');
|
||||
if (!source.trim()) return Promise.resolve(null);
|
||||
const stdin = this.inputLines().join('\n') + (this.inputLines().length ? '\n' : '');
|
||||
const level = levelOverride ?? this.buildLevel();
|
||||
this.compiling = (fetchImpl ?? compileMojo)(source, { stdin, level }).then((outcome) => {
|
||||
const backend = compileBackend();
|
||||
const ask = fetchImpl ?? ((src: string, opts: CompileOptions) => backend.compile(src, opts));
|
||||
this.compiling = ask(source, { stdin, level }).then((outcome) => {
|
||||
const rec: CompileRecord = {
|
||||
source, stdin, level, at: Date.now(), outcome,
|
||||
source, stdin, level, at: Date.now(), outcome, host: backend.host,
|
||||
diagnostics: outcome.answer ? compilerDiagnostics(outcome.answer.buildStderr) : [],
|
||||
functions: outcome.answer ? listingFunctions(outcome.answer.asm) : [],
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user