A Python frontend for LemmaScript: proposing a small external-frontend interface
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- python, typescript
Línea de trabajo
Start with the listed generic engine changes in tools/src and their tests, especially Raw IR input, pre-parsed specs, and floordiv/floormod; review the existing lemmascript-crosscheck approach for differential validation. The proposal asks maintainers to decide whether the interface and type format are acceptable and how to split the work. Done means an agreed interface with tests preserving TypeScript behavior and verifying the new Raw IR and operators.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi! I've been building a Python frontend for LemmaScript as a personal project, in a fork: https://github.com/tsakman23/lemmascript-python (branch feat/python-frontend). Fully type-annotated Python with #@ contracts is extracted to Raw IR and goes through your engine and Dafny backend unchanged:
def clamp(x: int, lo: int, hi: int) -> int:
#@ requires lo <= hi
#@ ensures lo <= result <= hi
if x < lo:
return lo
if x > hi:
return hi
return x
lsc check --backend=dafny clamp.py works like it does for a .ts file: it generates .dfy.gen, enforces the additions-only proof, and verifies.
Where it is. The first milestone covers int/bool functions with requires/ensures, if/elif, locals, // and %, raise/assert (modelled as unreachable, like throw), and Python truthiness. Anything outside that subset is rejected with a located error rather than approximated. Lists, loops and recursion are next.
Python semantics, not JS. The frontend lowers each construct to Raw IR whose engine meaning matches Python's. For example, truthiness is made explicit and comparison chains become conjunctions. Contracts are parsed with Python's ast and lowered by the same code as the body, so % in an ensures means Python's %.
Checking the translation. A differential harness compiles the verified .dfy with dafny translate py and runs it against the original Python on Hypothesis inputs. It checks four things:
- the Python and Dafny readings of
requiresagree; - the real code never raises inside the precondition;
- the two results are equal;
- every
ensuresholds on the real Python result.
It follows the approach of lemmascript-crosscheck. Deliberately wrong models are caught, for example, a model that uses Dafny's Euclidean % fails at a=1, b=-2.
The engine changes. These are generic, about 340 lines in tools/src plus tests, each marked HOOK(external-frontend):
- Raw IR input.
lsc gen|check|regen|extract|infoaccepts a versioned Raw IR envelope:foo.rawir.json, or any extension mapped to a frontend command in a newfrontendskey inlemmascript.json.- The envelope carries what
//@ option///@ backendlines provide for TS sources. - TS behaviour is unchanged: every example regenerates byte-identically and the fixture suite passes.
- Pre-parsed specs. Spec fields (
requires,ensures, invariants, …) may hold an already-parsedRawExpras well as annotation text, so a frontend can use its own expression grammar. floordiv/floormodbinops. These lower to aFloorDiv/FloorModpreamble pair built on Dafny's Euclidean ops.FloorModensuresa == b * FloorDiv(a, b) + FloorMod(a, b), which keeps proofs linear.
Questions:
- Would you be open to an external-frontend interface along these lines? If so, would you prefer the three pieces as separate PRs? I'm happy to reshape the envelope or the config key to fit your plans.
- Raw IR types are TS type strings today, and the Python frontend translates its annotations into them (
list[int]→int[]). Is that a format you're comfortable keeping stable for external producers, or is a structured type representation planned? - Once there's a stable interface, the plan is to move the Python frontend to its own repo that depends on the
lemmascriptnpm package. Does that match how you'd like satellites to work?
Thanks for LemmaScript. The engine was a pleasure to build on. Also many thanks to my colleague @quangng2000 for introducing me to LemmaScript.
- Lenguaje dominante
- TypeScript
- Estrellas
- 113
- Forks
- 13
- Merge medio
- 16 h 22 min
- PR fusionados (30 d)
- 40
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de midspiral/LemmaScript
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
midspiral/LemmaScript#308 ·
Los mantenedores suelen responder en 1 día
-
Dafny: `toUpperCase`/`toLowerCase` are modeled as ASCII-only, so false contracts about non-ASCII text verifyPosiblemente ocupada @quangng2000 la tomó hace 1 día. Abierto
midspiral/LemmaScript#312 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 1-2 días Aptitud para principiantes 56/100
midspiral/LemmaScript#311 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 48/100
midspiral/LemmaScript#310 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 67/100
midspiral/LemmaScript#309 ·
Los mantenedores suelen responder en 1 día
Todos los issues de midspiral/LemmaScript
Issues similares
-
area: batch
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
inabagumi/shinju-date#7294 ·
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
streaming-video-technology-alliance/common-media-library#700 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
vercel-labs/ui#809 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
KrisCris/village-in-the-shade-guide#75 ·
Los mantenedores suelen responder en 1 día
-
bot:ai-assisted component:platform-js status:untriaged
Dificultad 1/5 Menos de una hora Aptitud para principiantes 74/100
midnightntwrk/platform-js#38 ·