The Prove view gives each routine 3 seconds on the clock. On a slow or busy device that runs out before the proof does, and claims stay open with nothing to say why. - The view says when the time, not the proof, stopped the checker, that what was not finished is open and not disproved, and offers to prove again with the next longer time. The setting is at the foot of the view: 3, 10 or 30 seconds or 2 minutes for each routine, kept in the browser (pplus.proveclock). - A proof rendered with Quarto takes prove-seconds on the shortcode or pplus-prove-seconds for the site, and the render warns when the time ran out. - The home page's own example is proved with no time on the clock, and the tests that hold a proof's outcome give it time to spare, so neither depends on the machine. - core moves to 38e6e2c, whose report says which routines the clock stopped.
This commit is contained in:
19 files changed
+240
-6
No files matched your search
@@ -26,6 +26,7 @@ No version has been tagged yet. What programs mean is pplus-core's, and its chan
|
||||
|
||||
### Added
|
||||
|
||||
- The Prove view's time limit is the reader's to set: 3 seconds for each routine as before, or 10, 30 or 120, kept in the browser. When the time, not the proof, stopped the checker (a slow or busy device), the view says so, says that what was not finished is open and not disproved, and offers to prove again with more. A proof rendered with Quarto takes `prove-seconds` on the shortcode or `pplus-prove-seconds` for the site, and the render warns when the time ran out.
|
||||
- `THIRD_PARTY.md`, with the copyright notice of every package bundled into the editor, and a test that holds it to the bundle, the copied stylesheets, the fonts and the locks.
|
||||
- The Apache License 2.0, a NOTICE, contributing rules, a security policy, a code of conduct, and a citation file.
|
||||
- A footer with the license, the notices, the disclaimer about Modular, the build's commit, and "What this site stores and sends", each statement held to the code by a test.
|
||||
|
||||
+1
-1
Submodule core updated: b10a5c87a3...38e6e2cdd2.
@@ -131,6 +131,7 @@ The **Share** button in the app produces the app link, a ready-to-paste `<iframe
|
||||
- **Mojo for every exercise with pseudo**: each has its Mojo in `core/library/mojo/local/`, so the Developer and Hardware areas always have something to show for it; `core/tests/mojo.test.mjs` runs each Mojo program in the interpreter and checks it prints what the exercise expects.
|
||||
- **Panes**: the area's own (see the table above), dimmed when empty (a dimmed tab opens an empty pane to write in), as tabs over one editor (CodeMirror: search and replace with Ctrl+F, go to line with Ctrl+G, bracket matching, undo and redo; Tab indents, Ctrl+/ comments). The editor is never split: in the Bridge a short note in the pane head says the other tabs update as you type (lingo and matho update the pseudo, and the pseudo the Mojo made from it), and clicking a line marks the lines it became in the next tab down; Hardware does the same between Mojo and x86-64. Drag the dividers to resize (double-click resets); the widths, the dock tab, and what is folded are remembered in the share link.
|
||||
- **The side column** is the inspect panel. Its tabs are offered only when they mean something for the pane (Prove for the pseudo family) and dimmed, with the reason, when the run has nothing for them yet.
|
||||
- **Prove has a time limit the reader sets.** The prover's work is counted, the same on every machine; behind that it stops at a time on the clock, 3 seconds for each routine, so a page never waits long. On a slow or busy device 3 seconds can run out before the proof does. Core's report says when (`ProofReport.clock`), and the view then says "Time ran out" on those routines, that what was not finished is open and not disproved, and offers to prove again with the next longer time. The setting itself is at the foot of the view: 3, 10 or 30 seconds or 2 minutes for each routine (`src/core/proveclock.ts`, kept in this browser as `pplus.proveclock`; `Session.setProofClock` proves again). More time never proves anything that is not true. The home page's own example is proved with no time on the clock, so it reads the same on every device; a page rendered with Quarto takes `prove-seconds` (`quarto/README.md`).
|
||||
- **The Run view** (the first tab, in the Bridge and the Developer area; `src/core/runview.ts`, drawn by `src/ui/views/run.ts`) is the whole run read top to bottom, one row per step: its number, its line, what ran (indented by call depth, with what it printed), and a column for each variable you **follow**, holding its value after that step: in color where the step wrote it (with the position, `[5, 6]`, when it wrote one element), faded where it carries over, underlined where the step reads it, hatched where it is not in scope. The lifecycle of the value a variable names (Mojo: made ●, copied ⧉, moved in ⇢, moved out ⇥, destroyed ✕) is marked in the same cell; events of values no column names are noted beside the step. Above the rows, the followed variables as they stand at the stepper's position, with a ruler for a string or list and a grid for a table, the element just written and the one about to be read marked. **+ variables** opens a picker of every variable in the run, by routine; until you choose, it follows the variables of the routine that does the most work. The choice is kept per area (`layout.follow`). "Only steps that change something" hides the rest. Click a row to step there; the stepper keeps its row in view. It replaces the Variables panel, the trace table, the table of values and the Lifetimes tab, which each showed part of this.
|
||||
- **The Tests tab** is a fuzzer that shows its work (`core/src/common/fuzz.ts`, drawn by `src/ui/views/tests.ts`). For each routine (the pseudo's, with the speco woven in; or each Mojo function other than `main`) it lists **what each input must do** (finish within the step limit; raise no runtime error, or for Mojo no abort and no uncaught raise; keep every REQUIRE, ENSURE, INVARIANT, DECREASES and ASSERT, with inputs that break a REQUIRE skipped rather than failed; give the same answer when run again), **how the inputs were made** (each parameter's generator, with the values it tries first, and each strategy with how many inputs it made: edge cases in combination, every DNA string up to three letters for a routine that reads one, seeded random values, and mutations of the inputs that reached a line nothing earlier had reached, as a coverage-guided fuzzer does), each **failure** with the case that found it and every step of shrinking it to a smaller input that still fails the same way (the shrinking is greedy, so the input it ends on is the smallest it found, not always the smallest there is) (**Step through this input** puts that call in the call box and shows the run), the **lines reached** by how many inputs (a line no input reached is flagged), the **answers** given and how often, and **every case** run with its strategy, input, outcome, answer or error, and steps, filterable by outcome and strategy. The seed and the number of inputs (100 to 3,000) are chosen at the top; the same seed always makes the same inputs. `core/tests/fuzz.test.mjs` runs it on every exercise.
|
||||
- **Views that follow the run**: the **Flowchart** shades by the run so far and marks the box that runs next; the **Data flow** lights up the names the next line reads and the name the last line wrote.
|
||||
|
||||
@@ -47,6 +47,7 @@ syntax-definitions:
|
||||
pplus-engine: ../programming-plus # a built Programming+ (its folder, or its dist/)
|
||||
pplus-url: "https://pplus.scient.ing" # where the live views point (this is the default)
|
||||
pplus-strict: true # optional: a view that cannot be rendered, or a run that does not print its EXPECT lines, stops the render
|
||||
pplus-prove-seconds: 30 # optional: the seconds the prover has for each routine of a rendered proof (default 3)
|
||||
```
|
||||
|
||||
`mojo.xml` is generated from the same words as the Mojo pane's highlighter (the compiler's own token table, at the pinned Mojo version). A printed listing therefore colors `mut`, `deinit`, the transfer `^`, and removed words such as `fn` exactly as the pane does. If the project already has its own `pseudo.xml`, keep that and add only `lingo.xml`.
|
||||
@@ -122,10 +123,13 @@ And these work with the rendered ones:
|
||||
| `height` | the live frame's height when it is put in place (default 520; 720 for translate and the machine's views, which open the whole playground) |
|
||||
| `follow` | steps: the variables to show, comma-separated |
|
||||
| `max` | steps: the most steps kept (default 400; from 10 to 5000) |
|
||||
| `prove-seconds` | proof: the seconds the prover has for each routine (default 3, or the site's `pplus-prove-seconds`) |
|
||||
| `to`, `layout` | translate: the notations to show, comma-separated; `tabs` (default), `columns` or `grid` |
|
||||
| `compiler` | run, for a Mojo file: `auto`, `on` or `off` |
|
||||
| `column` | Quarto's column for the view (`page`, `screen`, `margin`, ...) |
|
||||
|
||||
**A proof has a time limit.** The prover's work is counted and is the same on every machine, but it also stops at a time on the clock, 3 seconds for each routine as in the app, and a page is rendered once on whatever machine builds the site. If that machine is slow or busy, 3 seconds can run out before the proof does: the page then shows claims open that are provable, with a "Time ran out" note, and the render warns (`proof: time ran out on ...`). Give the prover more with `prove-seconds="30"` on the shortcode or `pplus-prove-seconds: 30` for the site; more time never proves anything that is not true. A result is kept in `.quarto/pplus/` by its request, so a new time renders again.
|
||||
|
||||
In a format other than HTML (a PDF, a Word file), a rendered view becomes Markdown. The run is printed as a code block; the steps, the table of values and the machine's counters as tables; the proof, tests and checker's findings as lists; and translate as one listing per notation. The flowchart, the data flow and the lifetimes say they are drawn in the HTML version. A view of the machine gives the registers the run has written by step `t` and names the cards drawn in the HTML version. Each view except translate is followed by a link to the app.
|
||||
|
||||
### The live views, arranged
|
||||
|
||||
@@ -314,6 +314,19 @@ body.quarto-dark .pplus-static,
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.pplus-static .proof-timeout {
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid var(--line);
|
||||
border-left: 3px solid var(--warn, #b45309);
|
||||
border-radius: var(--r);
|
||||
padding: 6px 10px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.pplus-static .proof-timeout p {
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
|
||||
.pplus-static .proof-unit {
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid var(--line);
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
-- listing pplus-hw: 0 leaves out the x86-64 listing beside the cards
|
||||
-- column body | page | screen | ...: Quarto's column for the figure (pplus-hw's board is page-wide by default)
|
||||
-- stepper pplus-hw: 0 draws only step t (no stepper); max: the most steps drawn (a longer run is sampled)
|
||||
-- prove-seconds proof: the seconds the prover has for each routine (default 3, or pplus-prove-seconds)
|
||||
-- live click: a button that puts the live view in place of the rendered one
|
||||
-- height the live frame's height in px when live="click" is pressed (default 520)
|
||||
--
|
||||
@@ -76,6 +77,8 @@
|
||||
-- looked for. none: render nothing with the page (each rendered view shows its listing and the live view)
|
||||
-- pplus-node the node to run it with (default: node on the PATH)
|
||||
-- pplus-strict true: a view that cannot be rendered, or a run that does not print its EXPECT lines (a program with EXPECT lines that does not run at all among them), stops the render
|
||||
-- pplus-prove-seconds the seconds the prover has for each routine in a rendered proof (default 3, the app's own); a
|
||||
-- slow build machine can run out of 3 and show a claim open that is provable, and the render warns
|
||||
-- pplus-cache false: render every view again each time (by default results are kept in .quarto/pplus/)
|
||||
|
||||
local str = pandoc.utils.stringify
|
||||
@@ -614,6 +617,7 @@ local function static_view(view, kwargs, meta, extra)
|
||||
req.t = tonumber(kwarg(kwargs, "t") or "")
|
||||
req.title = kwarg(kwargs, "title")
|
||||
req.max = tonumber(kwarg(kwargs, "max") or "")
|
||||
if view == "proof" then req.proveSeconds = tonumber(kwarg(kwargs, "prove-seconds") or meta_str(meta, "pplus-prove-seconds") or "") end
|
||||
if kwarg(kwargs, "follow") then req.follow = split_list(kwarg(kwargs, "follow")) end
|
||||
if kwarg(kwargs, "to") then req.to = split_list(kwarg(kwargs, "to")) end
|
||||
req.compiler = kwarg(kwargs, "compiler") or "auto"
|
||||
|
||||
@@ -50,6 +50,9 @@ for (const s of samples) for (const view of STATIC_VIEWS.filter((v) => v !== 'hw
|
||||
// the editor's token colors and the step colors, whichever a sample happened to show
|
||||
for (const c of ['tok-keyword', 'tok-builtin', 'tok-string', 'tok-number', 'tok-comment', 'tok-label', 'tok-op', 'tok-error', 'tok-punct', 'tok-convention', 'tok-transfer', 'tok-name']) used.add(c);
|
||||
|
||||
// the notice a rendered proof carries when the build machine ran out of the prover's time: no sample does (it is the machine's)
|
||||
used.add('proof-timeout');
|
||||
|
||||
/* ---------- styles.css as rules ---------- */
|
||||
|
||||
/** Top-level rules and @media blocks: { selector, body } or { media, rules }. Comments are dropped. */
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/**
|
||||
* The time on the clock the Prove view gives each routine: 3 seconds unless the reader gives it more. The prover's
|
||||
* work is counted and ends at the same point on every machine; the clock is the one part that depends on the
|
||||
* machine, there so a page never waits long on one routine. On a slow or busy device 3 seconds can run out before
|
||||
* the proof does, and a claim stays open that a faster machine proves. The report says when that happened
|
||||
* (`ProofReport.clock`), the view says so, and this is the setting it offers. More time never makes anything
|
||||
* proved that is not: it only lets the same checker finish.
|
||||
*
|
||||
* Kept in this browser's localStorage. DOM-free; the storage is a parameter, so the tests give one.
|
||||
*/
|
||||
type Store = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
||||
const KEY = 'pplus.proveclock';
|
||||
|
||||
/** The choices, in milliseconds for each routine. The first is the default, and what a browser with no setting has. */
|
||||
export const PROVE_CLOCKS: ReadonlyArray<{ ms: number; label: string }> = [
|
||||
{ ms: 3000, label: '3 seconds' },
|
||||
{ ms: 10000, label: '10 seconds' },
|
||||
{ ms: 30000, label: '30 seconds' },
|
||||
{ ms: 120000, label: '2 minutes' },
|
||||
];
|
||||
export const DEFAULT_PROVE_CLOCK = PROVE_CLOCKS[0].ms;
|
||||
|
||||
const defaultStore = (): Store | null => { try { return typeof localStorage === 'undefined' ? null : localStorage; } catch { return null; } };
|
||||
|
||||
/** How a budget reads in a sentence: "3 seconds", "2 minutes", and any other number of milliseconds in seconds. */
|
||||
export function clockWords(ms: number): string {
|
||||
const known = PROVE_CLOCKS.find((c) => c.ms === ms);
|
||||
if (known) return known.label;
|
||||
const s = Math.round(ms / 100) / 10;
|
||||
return `${s} second${s === 1 ? '' : 's'}`;
|
||||
}
|
||||
|
||||
/** The reader's setting: one of PROVE_CLOCKS, or the default when nothing (or anything else) is stored. */
|
||||
export function loadProveClock(store: Store | null = defaultStore()): number {
|
||||
try {
|
||||
const ms = Number(store?.getItem(KEY));
|
||||
return PROVE_CLOCKS.some((c) => c.ms === ms) ? ms : DEFAULT_PROVE_CLOCK;
|
||||
} catch { return DEFAULT_PROVE_CLOCK; }
|
||||
}
|
||||
|
||||
/** Keep the setting (the default is kept by removing it), and return what was kept. */
|
||||
export function saveProveClock(ms: number, store: Store | null = defaultStore()): number {
|
||||
const kept = PROVE_CLOCKS.some((c) => c.ms === ms) ? ms : DEFAULT_PROVE_CLOCK;
|
||||
try { if (kept === DEFAULT_PROVE_CLOCK) store?.removeItem(KEY); else store?.setItem(KEY, String(kept)); } catch { /* private mode or quota */ }
|
||||
return kept;
|
||||
}
|
||||
|
||||
/** The next longer choice after `ms`, or null at the longest. */
|
||||
export function longerProveClock(ms: number): number | null {
|
||||
return PROVE_CLOCKS.find((c) => c.ms > ms)?.ms ?? null;
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import { findPractices, findingsToDiagnostics, applyPractices, type PracticeFind
|
||||
import { checkMojo } from '#core/mojo/check.js';
|
||||
import { GENERATED_HEADER } from '#core/sync/header.js';
|
||||
import { SyncHub, isLinked, type Linked } from '#core/sync/hub.js';
|
||||
import { DEFAULT_PROVE_CLOCK, loadProveClock, saveProveClock } from './proveclock.js';
|
||||
|
||||
/** One answer from godbolt, kept with exactly what it answered. */
|
||||
export interface CompileRecord {
|
||||
@@ -73,6 +74,17 @@ export class Session extends Workspace {
|
||||
super(state);
|
||||
this.finder = opts.practices ?? findPractices;
|
||||
this.area = opts.area ?? null; this.storageId = opts.storageId; this.keep = opts.keep; this.original = opts.original ? structuredClone(opts.original) : null; this.stale = !!opts.stale;
|
||||
// the reader's time for a proof, from this browser (3 seconds where nothing is kept, as in a page rendered by Node)
|
||||
this.proofBudgetMs = loadProveClock();
|
||||
}
|
||||
/** The time on the clock a proof has for each routine here, in milliseconds (src/core/proveclock.ts). */
|
||||
proofClock(): number { return this.proofBudgetMs ?? DEFAULT_PROVE_CLOCK; }
|
||||
/** Give proofs another time on the clock, keep it for this browser, and prove again. */
|
||||
setProofClock(ms: number): void {
|
||||
const kept = saveProveClock(ms);
|
||||
if (kept === this.proofClock()) return;
|
||||
this.proofBudgetMs = kept;
|
||||
this.emit('run');
|
||||
}
|
||||
/**
|
||||
* The area the work is open in (from the route); the layout is kept per area. Null for a session that is not
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ export function siteVersion(meta: string | null | undefined): string | null {
|
||||
*/
|
||||
export const SITE_DATA: readonly string[] = [
|
||||
'No accounts, no cookies, no analytics.',
|
||||
'Your work, its saved versions, the answers Compile & run brought back, and your settings (the theme, the best-practices switches, whether messages show in the editor, whether you agreed to send to godbolt.org) are kept in this browser\'s localStorage, under names that start with "pplus". While saved work runs, this tab also keeps a mark in its sessionStorage, so a page that stops can put that work aside. Nothing is kept on a server: clearing this site\'s data in the browser removes it all, and Share → Download keeps a copy as a file.',
|
||||
'Your work, its saved versions, the answers Compile & run brought back, and your settings (the theme, the best-practices switches, whether messages show in the editor, the time a proof may take, whether you agreed to send to godbolt.org) are kept in this browser\'s localStorage, under names that start with "pplus". While saved work runs, this tab also keeps a mark in its sessionStorage, so a page that stops can put that work aside. Nothing is kept on a server: clearing this site\'s data in the browser removes it all, and Share → Download keeps a copy as a file.',
|
||||
'A shared link carries its work in the address after the #, which the browser does not send to any server. Opening one never saves over your own work on the same problem.',
|
||||
'Compile & run sends the Mojo pane\'s text, the input box\'s lines and the build flags to godbolt.org (Compiler Explorer, a public service run by others, with its own privacy policy), and nothing else: no title, no other pane, nothing stored. The first time, it says so and asks; nothing is sent until you agree.',
|
||||
'Nothing else leaves the browser. The page, its scripts and its fonts come from this site, and no other site is asked for anything. Links to other sites (the Mojo manual, where a method comes from) are followed only when you click them.',
|
||||
|
||||
+11
-2
@@ -72,6 +72,8 @@ export interface RenderRequest {
|
||||
/** hw: false leaves out the x86-64 listing; stepper false draws only the step `t`. */
|
||||
listing?: boolean;
|
||||
stepper?: boolean;
|
||||
/** proof: the seconds on the clock the prover has for each routine (default 3, the app's own). */
|
||||
proveSeconds?: number;
|
||||
/** A run of the Mojo file by a real compiler (render.mjs does it when `mojo` is on the PATH). */
|
||||
compiled?: { stdout: string; stderr: string; status: number | null; version: string } | null;
|
||||
}
|
||||
@@ -130,7 +132,10 @@ function prepare(req: RenderRequest): Prepared {
|
||||
if (req.machine) state.machine = req.machine;
|
||||
if (typeof req.t === 'number' && req.t >= 0) state.t = Math.floor(req.t);
|
||||
if (req.title) state.title = req.title;
|
||||
return { session: new Session(state), header, given, sources };
|
||||
const session = new Session(state);
|
||||
// a page is rendered once, on whatever machine builds the site: its author may give a proof more than the app's 3 seconds
|
||||
if (typeof req.proveSeconds === 'number' && req.proveSeconds > 0) session.proofBudgetMs = Math.round(req.proveSeconds * 1000);
|
||||
return { session, header, given, sources };
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
@@ -423,7 +428,11 @@ function proofOf(p: Prepared): RenderResult {
|
||||
const node = appView((h) => proofView(session, h, noHooks), 'view-proof');
|
||||
const pr = session.proof();
|
||||
const md = pr ? [`**${pr.report.counts.proved} proved, ${pr.report.counts.broken} broken, ${pr.report.counts.open} open.**`, '', ...pr.report.units.flatMap((u) => u.obligations.map((o) => `- ${o.status}: ${o.label} (line ${(o as any).specoLine ?? (o as any).pseudoLine ?? o.line})`))].join('\n') : '*The proof needs pseudocode that parses.*';
|
||||
return result('proof', 'pseudo', node, md, pr && pr.report.counts.broken ? [`proof: ${pr.report.counts.broken} claim(s) broken`] : []);
|
||||
const warnings = pr && pr.report.counts.broken ? [`proof: ${pr.report.counts.broken} claim(s) broken`] : [];
|
||||
// the machine that renders the page was too slow for the clock: the page would show claims open that are provable
|
||||
const stopped = pr?.report.clock?.stopped ?? [];
|
||||
if (stopped.length) warnings.push(`proof: time ran out on ${stopped.join(', ')} (${session.proofClock() / 1000} s for each routine): give it more with prove-seconds on the shortcode, or pplus-prove-seconds for the site`);
|
||||
return result('proof', 'pseudo', node, md, warnings);
|
||||
}
|
||||
|
||||
function testsOf(p: Prepared): RenderResult {
|
||||
|
||||
@@ -67,6 +67,7 @@ export function mountEmbed(session: Session, view: ViewId | LangId, params: URLS
|
||||
return ed;
|
||||
};
|
||||
const hooks: PanelHooks = {
|
||||
live: true,
|
||||
reveal: (lang, line) => { const ed = editors.get(lang); if (ed) { ed.scrollToLine(line); ed.setDecorations({ linked: new Set([line]) }); setTimeout(() => ed.setDecorations({ linked: undefined }), 1200); } },
|
||||
fix: (lang, f) => editors.get(lang)?.applyFix(f),
|
||||
};
|
||||
|
||||
+5
-1
@@ -255,7 +255,11 @@ function notations(): HTMLElement {
|
||||
|
||||
function specs(): HTMLElement {
|
||||
const proved = problemById('count-base-proved')!;
|
||||
const pr = new Session(stateForProblem(proved)).proof();
|
||||
// the site's own example, proved with no time on the clock: its work is small and counted, and what the home
|
||||
// page says of it must not depend on how fast or busy the reader's device is
|
||||
const session = new Session(stateForProblem(proved));
|
||||
session.proofBudgetMs = Infinity;
|
||||
const pr = session.proof();
|
||||
const c = pr?.report.counts ?? { proved: 0, broken: 0, open: 0, total: 0 };
|
||||
return el('section', { class: 'spec-section' },
|
||||
el('div', { class: 'spec-text' },
|
||||
|
||||
@@ -1061,6 +1061,7 @@ export class Shell {
|
||||
|
||||
private hooks(): PanelHooks {
|
||||
return {
|
||||
live: true,
|
||||
reveal: (lang, line) => {
|
||||
this.setNarrow('code');
|
||||
if (lang !== this.session.state.lang) { this.session.setLang(lang); this.showPane(lang); }
|
||||
|
||||
@@ -11,6 +11,7 @@ import type { Diagnostic, LangId, QuickFix } from '#core/common/types.js';
|
||||
import { LANG_NAMES } from '#core/common/types.js';
|
||||
import type { Session } from '../../core/session.js';
|
||||
import { toMath } from '#core/services/speco.js';
|
||||
import { PROVE_CLOCKS, clockWords, longerProveClock } from '../../core/proveclock.js';
|
||||
|
||||
export const GUIDE_URL = 'https://biosc1540.scient.ing/programmingplus/reference/pseudocode/';
|
||||
|
||||
@@ -19,6 +20,8 @@ export interface PanelHooks {
|
||||
reveal(lang: LangId, line: number): void;
|
||||
/** Apply a rewrite to a language's source. */
|
||||
fix(lang: LangId, f: QuickFix): void;
|
||||
/** The view is on a live page (the app, an embed), where a control does something; a page rendered with Quarto is not. */
|
||||
live?: boolean;
|
||||
}
|
||||
|
||||
const SEV_ICON: Record<string, string> = { error: '●', warning: '▲', note: '○' };
|
||||
@@ -70,6 +73,16 @@ export function proofView(session: Session, root: HTMLElement, hooks: PanelHooks
|
||||
el('span', { class: 'badge badge-open' }, `${report.counts.open} open`),
|
||||
));
|
||||
if (!report.counts.total) add(root, el('p', { class: 'muted' }, 'No claims to check. Add an ENSURE under a FUNCTION line, or a SPEC in the speco pane.'));
|
||||
// the clock, not the proof, stopped the checker: say so, and offer the same proof with more time
|
||||
const stopped = report.clock?.stopped ?? [];
|
||||
if (stopped.length) {
|
||||
const had = clockWords(report.clock!.budgetMs);
|
||||
const more = hooks.live ? longerProveClock(session.proofClock()) : null;
|
||||
add(root, el('div', { class: 'proof-timeout', role: 'status' },
|
||||
el('p', {}, el('b', {}, 'Time ran out'), ` on ${stopped.length === 1 ? stopped[0] : `${stopped.length} routines (${stopped.join(', ')})`}: the checker had ${had} for each routine, and this device needed more. What it did not finish is shown open, not disproved.`),
|
||||
more ? button(`Prove again with ${clockWords(more)}`, () => session.setProofClock(more), { class: 'btn btn-small' }) : null,
|
||||
));
|
||||
}
|
||||
for (const u of report.units) {
|
||||
const sec = el('details', { class: 'proof-unit', open: true }, el('summary', {}, el('b', {}, u.name), ` · ${u.obligations.length} claim${u.obligations.length === 1 ? '' : 's'}`, u.partial ? el('span', { class: 'badge badge-open' }, 'partial: not every path was examined') : null));
|
||||
if (u.inferred.length) add(sec, el('p', { class: 'muted small' }, 'Invariants the checker found on its own: ', ...u.inferred.map((x) => el('code', { class: 'math' }, toMath(String(x)), ' '))));
|
||||
@@ -92,6 +105,13 @@ export function proofView(session: Session, root: HTMLElement, hooks: PanelHooks
|
||||
add(sec, list);
|
||||
add(root, sec);
|
||||
}
|
||||
if (hooks.live) {
|
||||
const clock = el('select', { class: 'select', id: 'proof-clock', onChange: () => session.setProofClock(Number(clock.value)) },
|
||||
...PROVE_CLOCKS.map((c) => el('option', { value: String(c.ms), selected: c.ms === session.proofClock() }, c.label)));
|
||||
add(root, el('p', { class: 'proof-clock small muted' },
|
||||
el('label', { for: 'proof-clock' }, 'Time for each routine: '), clock,
|
||||
' The checker stops at this time whether or not it is done, and the page waits while it works. More time never proves anything that is not true: it lets a slow device finish.'));
|
||||
}
|
||||
add(root, el('p', { class: 'small muted' }, 'Proved means: on every path the checker examined, the claim follows from what is known. Open means the checker could not finish the argument; usually a loop needs an invariant. Broken means a generated input violated it.'));
|
||||
}
|
||||
const off = session.onChange(render);
|
||||
|
||||
+17
@@ -2329,6 +2329,23 @@ body.resizing textarea {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.proof-timeout {
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid var(--line);
|
||||
border-left: 3px solid var(--warn, #b45309);
|
||||
border-radius: var(--r);
|
||||
padding: 6px 10px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.proof-timeout p {
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
|
||||
.proof-clock .select {
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
.proof-unit {
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid var(--line);
|
||||
|
||||
@@ -84,6 +84,7 @@ test('prove and tests work on the hub\'s pseudo, with the speco woven', () => {
|
||||
s.setSource('lingo', lingo + '\n'); // an edit in English
|
||||
assert.equal(s.state.sync.authority, 'lingo');
|
||||
assert.match(s.source('pseudo'), /ENSURE/, 'the contracts are in the pseudo the English lowered to');
|
||||
s.proofBudgetMs = Infinity; // no time on the clock: the same answer on a slow machine
|
||||
const proof = s.proof();
|
||||
assert.ok(proof && proof.report.counts.total > 0, 'there is something to prove');
|
||||
assert.equal(proof.report.counts.broken, 0);
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// The time a proof may take is the reader's to set (src/core/proveclock.ts): the Prove view says when the clock, not
|
||||
// the proof, stopped the checker, offers more time, and proves again; a page rendered with Quarto takes its time
|
||||
// from the shortcode or the site, and warns its author when it ran out.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { installDocument } from '../dist/quarto/dom.js';
|
||||
|
||||
installDocument();
|
||||
const { PROVE_CLOCKS, DEFAULT_PROVE_CLOCK, loadProveClock, saveProveClock, longerProveClock, clockWords } = await import('../dist/core/proveclock.js');
|
||||
const { Session } = await import('../dist/core/session.js');
|
||||
const { problemById, stateForProblem } = await import('../dist/core/catalog.js');
|
||||
const { proofView } = await import('../dist/ui/views/panels.js');
|
||||
const { renderStatic } = await import('../dist/quarto/render.js');
|
||||
|
||||
const memory = () => { const m = new Map(); return { getItem: (k) => (m.has(k) ? m.get(k) : null), setItem: (k, v) => { m.set(k, String(v)); }, removeItem: (k) => { m.delete(k); }, m }; };
|
||||
const hooks = (live) => ({ reveal() {}, fix() {}, live });
|
||||
const draw = (session, live) => { const root = document.createElement('div'); proofView(session, root, hooks(live)); return root; };
|
||||
const proved = () => new Session(stateForProblem(problemById('count-base-proved')), { storageId: null });
|
||||
|
||||
test('the setting is one of the listed times, 3 seconds unless the reader chose another, and kept under a pplus name', () => {
|
||||
assert.equal(DEFAULT_PROVE_CLOCK, 3000);
|
||||
assert.deepEqual(PROVE_CLOCKS.map((c) => c.ms), [3000, 10000, 30000, 120000]);
|
||||
const store = memory();
|
||||
assert.equal(loadProveClock(store), 3000);
|
||||
assert.equal(saveProveClock(30000, store), 30000);
|
||||
assert.deepEqual([...store.m.keys()], ['pplus.proveclock']);
|
||||
assert.equal(loadProveClock(store), 30000);
|
||||
// anything that is not a listed time is the default, stored or asked for
|
||||
store.setItem('pplus.proveclock', '99999999');
|
||||
assert.equal(loadProveClock(store), 3000);
|
||||
assert.equal(saveProveClock(7, store), 3000);
|
||||
assert.equal(store.m.size, 0, 'the default is kept by keeping nothing');
|
||||
assert.equal(loadProveClock(null), 3000);
|
||||
assert.equal(longerProveClock(3000), 10000);
|
||||
assert.equal(longerProveClock(120000), null);
|
||||
assert.equal(clockWords(120000), '2 minutes');
|
||||
assert.equal(clockWords(1500), '1.5 seconds');
|
||||
});
|
||||
|
||||
test('a proof the clock stopped says so, offers the next longer time, and is proved again with it', () => {
|
||||
const s = proved();
|
||||
assert.equal(s.proofClock(), 3000);
|
||||
// a clock that has already run out, which is what 3 seconds are on a slow or busy device
|
||||
s.proofBudgetMs = -1;
|
||||
const cut = s.proof().report;
|
||||
assert.ok(cut.clock.stopped.length >= 1, JSON.stringify(cut.clock));
|
||||
assert.equal(cut.counts.broken, 0);
|
||||
const view = draw(s, true);
|
||||
const notice = view.querySelector('.proof-timeout');
|
||||
assert.match(notice.textContent, /Time ran out on .*shown open, not disproved/);
|
||||
assert.match(notice.querySelector('button').textContent, /^Prove again with 3 seconds$/);
|
||||
assert.ok(view.querySelector('select#proof-clock'), 'and the setting itself is in the view');
|
||||
// the setter proves again and tells the views
|
||||
let told = 0;
|
||||
s.onChange((what) => { if (what === 'run') told++; });
|
||||
s.setProofClock(10000);
|
||||
assert.equal(s.proofClock(), 10000);
|
||||
assert.equal(told, 1);
|
||||
const whole = s.proof().report;
|
||||
assert.deepEqual(whole.clock, { budgetMs: 10000, stopped: [] });
|
||||
assert.ok(whole.counts.proved > cut.counts.proved);
|
||||
assert.equal(draw(s, true).querySelector('.proof-timeout'), null);
|
||||
assert.equal(draw(s, true).querySelector('select#proof-clock').value, '10000');
|
||||
s.setProofClock(10000);
|
||||
assert.equal(told, 1, 'the same time again is no change');
|
||||
s.setProofClock(3000);
|
||||
});
|
||||
|
||||
test('a view that is not live (a page rendered with Quarto) says the time ran out and offers no control', () => {
|
||||
const s = proved();
|
||||
s.proofBudgetMs = -1;
|
||||
const view = draw(s, false);
|
||||
assert.match(view.querySelector('.proof-timeout').textContent, /Time ran out/);
|
||||
assert.equal(view.querySelector('button.btn'), null);
|
||||
assert.equal(view.querySelector('select'), null);
|
||||
});
|
||||
|
||||
test('a rendered proof takes its time from the request, and has no warning when the time was enough', () => {
|
||||
const p = problemById('count-base-proved');
|
||||
const files = { pseudo: p.sources.pseudo, speco: p.sources.speco };
|
||||
const r = renderStatic({ view: 'proof', files, proveSeconds: 600 });
|
||||
assert.match(r.html, /[1-9]\d* proved/);
|
||||
assert.doesNotMatch(r.html, /Time ran out/);
|
||||
assert.deepEqual(r.warnings, []);
|
||||
});
|
||||
@@ -116,7 +116,10 @@ test('every rendered view draws for a program that has what it needs, with the a
|
||||
assert.ok(r.markdown.length > 10, `${view} has a Markdown form`);
|
||||
}
|
||||
assert.match(renderStatic({ view: 'flow', files }).html, /<svg[^>]*class="flow-svg"/);
|
||||
assert.match(renderStatic({ view: 'proof', files }).html, /4 proved/);
|
||||
// with time to spare: the 3 seconds a rendered proof has by default can run out on a slow machine (prove-seconds)
|
||||
const proof = renderStatic({ view: 'proof', files, proveSeconds: 600 });
|
||||
assert.match(proof.html, /4 proved/);
|
||||
assert.deepEqual(proof.warnings, []);
|
||||
const check = renderStatic({ view: 'check', files: { pseudo: problemById('five-bugs').sources.pseudo } });
|
||||
assert.match(check.html, /problem-error/);
|
||||
assert.match(check.markdown, /\*\*error\*\*, pseudo line \d+: /);
|
||||
|
||||
Reference in new issue
Block a user