Repository navigation
Brevi v0.24.4
Every one of the 48 final release-test programs from v0.24.3's runs now builds natively, with no CPython: enum, io.StringIO, json.JSONDecoder().raw_decode and path text from os and pathlib run natively, and exact fractions.Fraction, bin/hex/oct, startswith with a start index re.S/re.M and csv.writer(sys.stdout) are on the typed path. On the 813-program corpus 550 programs build typed, up from 496, and eight silent wrong outputs are fixed (re groups and tuples, rows changed in a loop, typed $ and re.split, dict keys printed as None). Release test over five runs (four on main before #171 and #172, one on the release commit): Sonnet 1.06x of Python's cost (95% range 1.03x to 1.10x), Haiku 1.03x (0.98x to 1.10x), every task passed on both sides, 120 of 120 and 117 of 120 final programs native. The run on the release commit alone gave 1.02x and 1.03x. Five checks along the way (of 2 tasks, trains and poker) failed under Brevi where CPython passed the same files; the models fixed their code and passed, and those typed-build wrong outputs are being fixed for the next release. The 3 programs that ran in CPython were split into several files, where a module Brevi could not build (a with other than open, except IndexError) sends the whole program to CPython.
- Typed path round 3. On the 813-program corpus 550 programs build typed, up from 522, none moved off it, and the CPython shadow check finds no wrong output.
j.get(k),j.get(k, [])andj.get(k, {})on JSON values,json.load(sys.stdin),any(f(x, seen) for ...)wherefchangesseen,deps or [], names set inside a loop (or just before itsbreak) and read after it, andreturn Nonefrom a function returning JSON now build typed. AMISSING = object()sentinel is read as None when every test of it also tests None. A loop over a set builds typed when its passes cannot depend on order (adding to sets, appending to the element's own entry, counting, setting a flag). - Silent wrong output fixed: dicts with different keys. When a list held dicts with different key sets (
{"id": 1, "error": "bad"}next to{"id": 2, "total": "4"}), the typed build printed and dumped every key on every dict, so a missing key showed asNone/null. Keys only some dicts have are now left out while unset, as in Python, andk in randr.get(k)see whether the key is set. csv.writer(sys.stdout)on the typed path.w = csv.writer(sys.stdout, lineterminator='\n')(also throughout = sys.stdoutused only for the writer) withw.writerow(row)andw.writerows(rows)now builds typed, quoting fields as CPython's csv module does (a field holding the delimiter, a quote or a line break is quoted, quotes doubled;delimiter=andlineterminator=literals). Of the 48 final release-suite programs, haiku_csv_join moved to the typed path and prints what python3 prints on the task's tests.re.S/re.DOTALLandre.M/re.MULTILINEon the typed path.re.compile(r'\{\{(.*?)\}\}', re.S)andre.split(p, s, flags=re.S), common in template renderers, sent the program to the dynamic build; the flags (and(?s)/(?m)written in the pattern) now build typed. Silent wrong output fixed: in the typed build$matched only at the very end, while Python's also matches before a final newline (re.search(r'z$', 'z\n'));re.splitskipped empty matches (re.split(r'\b', 'a b'), Python 3.7 on splits there) and gave''instead ofNonefor a group that took no part.io.StringIObuilds natively. An in-memory text file (write,getvalue,read,readline, iteration,seek,tell,truncate,print(..., file=buf),with), and socsv.writer(io.StringIO())andcsv.DictReader(io.StringIO(text)), now take the dynamic build, also under--sandboxwithout# allow native. The rest ofio(BytesIO,open) still runs in CPython. Both saved csv_join fallback programs print what python3 prints. Also: under--sandboxthe{"path":"dynamic"}line for such programs namedallow nativethough none was needed; it now says which modules the typed build lacks.bin,hex,octandstartswith/endswithwith a start index on the typed path.bin(x).count('1')and tokenizers that tests.startswith('<->', i)built over dynamic values; they now build typed (negative numbers and negative starts as in Python). Of the 48 final release-suite programs, haiku_sudoku moved to the typed path and prints what python3 prints on the task's tests.json.JSONDecoder().raw_decodeandjson.decoder.scanstringbuild natively. Tokenizers that read a JSON value or string out of a longer text (v, end = json.JSONDecoder().raw_decode(s, i)) ran in CPython; they now take the dynamic build, with CPython's indexes andJSONDecodeErrormessages. These were the last 2 of the 48 final release-suite programs that still needed CPython (bothjson_query); both now print what python3 prints on the task's tests.enumbuilds natively.class Color(Enum)with plain values orauto(), aliases, methods, properties and an__init__taking tuple values, plusColor(1),Color['RED'], iteration,len,in,__members__,@unique, andstr/intmixins (class Level(str, Enum)), now runs in the dynamic build; it used to run in CPython.repr,str, f-strings, hashing and errors (ValueError: 7 is not a valid Color,TypeErroron<) print what CPython prints.IntEnum,StrEnumandFlagstill run in CPython. Also:vars(SomeClass)works, and a class's attributes keep the order its body defines them in.- Exact fractions on the typed path.
fractions.Fractionin a typed build held only denominators that divide lcm(1..32)*10, so every Python file importing fractions went to the dynamic build. A Fraction is now a reduced numerator over a denominator (64 bits each, worked in 128-bit arithmetic), so unit tables, matrix elimination and exact ratios such as 1/86400 build typed and print what CPython prints, includingx.numerator,x.denominator,Fraction("3/4"),//,%,round,absandsum(xs, Fraction(0)). A value that needs more than 64 bits stops with an error naming the limit rather than rounding. - More plain Python stays typed. On the 813-program corpus (bench/typed_corpus.py: saved solutions and repros), 522 build typed, up from 496 on main (386 of the 580 solutions, up from 371); 37 moved onto the typed path and every one with tests prints what python3 prints, and 11 moved off it on purpose (the silent wrong outputs below).
~x,yield [x for ...],(only,) = xs,d.setdefault(k, {})[j] = v,re.sub(pattern, repl, s)withrepla function of the program, a nested function with default arguments, and calls inside a generator inside another generator (" ".join(fmt(x) for x in r) for r in m) now build typed. A re group that took no part in the match is None, as in CPython, som.group(2) is Nonestays typed. - Silent wrong output fixed: re groups and tuples. In typed builds
print(m.group(2))for a group that did not match printed an empty line instead ofNone, andprint(m.groups())showed['a', '', 'c']instead of('a', None, 'c'). A list filled withtuple(cur)by a helper function (out.append(tuple(cur))on a list passed in, or returned) printed its items as lists. All now match CPython (printingm.groups()and such lists goes to the dynamic build). - Silent wrong output fixed: rows changed in a loop.
for r in t[2]: r[1] = von rows held in a tuple (a table kept as(cols, order, rows)) changed copies of the rows in typed builds, so the update was lost; it now changes the rows themselves, and a loop that changes each row while also reading the rows' owner (if test(t, r): r[i] = v) builds over dynamic values. A program whose mixed lists ([1, 'a']) have the same item types as one of its real tuples printed those lists as tuples and copied them where Python shares them; it now builds over dynamic values too. Regex patterns also read\x00,\u00e9,\f,\vand\aescapes, which the typed build matched as letters. - Path text from
osandpathlibbuilds natively everywhere. A program whose only uses ofosandpathlibare path text (os.path.join,basename,dirname,splitext,normpath,os.sep,pathlib.PurePath) used Brevi's own copies of those functions only under--sandbox; outside it the program ran in CPython. It now builds natively in both. A program that also reaches files, processes or the environment (os.environ,os.listdir,pathlib.Path,os.path.exists) still runs those in CPython, as before. - Docs: the site has a Changelog page built from this file, and every diagram is a sharp SVG that opens full size on click; the architecture diagram shows the current build paths.
Prebuilt brevi compiler for Linux, macOS and Windows. brevi still needs rustc on the PATH to build programs. On Linux and macOS, sh install.sh installs rustc if it is missing and picks the right download; on Windows, install Rust with rustup and unzip the .zip. Details: https://brevi-lang.org/docs/install