Repository navigation
Brevi v0.25.0
The launch release, out ahead of the weekly Monday release. Most of it is correctness: Brevi now measures itself against CPython's own test suite (tools/conformance.py), and the fixes it led to cut built programs that give a wrong answer there from 79 to 45 while the share of tests that match rose from 49.2% to 57.9%; every other silent wrong output found in the release runs is fixed too, including d.copy() and list(d) on a dict in typed builds. 567 of 813 saved agent programs now take the fast typed build, with none differing from CPython. Python files exit 1 on an uncaught exception, Brevi-only syntax in a .py file is refused as CPython refuses it, install.sh checks its download against SHA256SUMS, and the dynamic build's re beats CPython on search loops. Release test, two runs on the release tree: Sonnet 1.09x and Haiku 1.01x the cost of CPython, every task passed, no check failed because of Brevi, 95 of 96 final programs native (two earlier runs on the tree just before #207: 1.04x and 1.05x, 96 of 96).
- Composio example.
integrations/composio_agent.pygives a LangChain agent Composio's hosted MCP server for app tools (GitHub issues here) next tobrevi mcp. Composio holds the credentials and makes the calls; the data reaches Brevi'srunasstdin, so the agent's program runs sandboxed with nothing granted. - Silent wrong output fixed: list items that start with
\x01. On the typed pathprint(["\x01a", "b"])printed['b'], because regex matches kept their group positions as a hidden last string and printing a list dropped any such string. A match is now its own type holding the positions apart, so a list shows every item, printing a match shows<re.Match object; ...>, andm.group(9),m[-1],len(m)andfor x in mfail as in CPython instead of exposing the hidden text. (#200, thanks @timoconnellaus) - CPython conformance measure.
tools/conformance.pycuts each test of CPython 3.13.13'stest_grammar,test_scope,test_int,test_listandtest_dictinto a standalone script and comparesbrevi buildoutput with CPython's: at first 49.2% of 311 scored tests matched (153), 59 were refused and 79 built programs gave a wrong answer; after the fixes below from that run, 57.9% match (180), 67 are refused and 45 give a wrong answer (57.6% and 45 withBREVI_DYN=1). Report;--checkfails only on a wrong result not incompat/conformance_known_wrong.txt. Not in CI. (#199, thanks @timoconnellaus) install.shverifies its download. The script now checks the release archive against the release'sSHA256SUMSbefore unpacking it, and stops with nothing installed on a mismatch or when the check cannot be made (BREVI_FROM_SOURCE=1still builds from source). (#198, thanks @timoconnellaus)time.gmtime,time.strftimeanddatetime.timezonebuild natively (#194). The dynamic build refused them, so a shared module formatting a UTC timestamp sent 23 of the 27 files of the pipeline in #175 to CPython. Nowtime.gmtime()gives atime.struct_time(fields, indexing,tm_zone),time.strftime(fmt, t)formats it, andtime.time_ns()is there. Datetimes can be aware:datetime.timezone.utc,datetime.UTC,timezone(timedelta(...)),tzinfo=indatetime(...),combine(d, t, tz),replace(tzinfo=...),now(tz),fromtimestamp(ts, tz),utcfromtimestamp,astimezone(tz),timestamp(),utcoffset(),tzname(),%z/%Z, offsets inisoformat(),str()andrepr(), comparison and subtraction as instants, and CPython's error for mixing naive and aware datetimes.fromisoformat("...Z")and"...+02:00"now give aware datetimes; before, theZwas dropped and the result was naive (silent wrong output). Local time (time.localtime,strftimewithout a tuple, a naivetimestamp(),fromtimestampwithout tz) still runs in CPython. Aware datetimes passed to a Python library keep their offset.- A dynamic-build blocker in an imported module names that module's file (#194).
brevi check main.pysaidmain.py line 4: time.gmtime is not supportedwhen line 4 was in_m.py; it now says_m.py line 4, in check, in run's path line and in--explain. (x or "").lower()on a JSON value builds typed (#195).x or ""wherexcame fromjson.loadswas typed as a bool, so the typed build's Rust did not compile and the file took the slower dynamic build. A JSON valueora string or int is now a JSON value. Also:re.search,re.sub,re.findalland friends on a JSON string build typed (they stopped the typed build withno method named re_find found for enum Json).json.load(open(path))builds typed (#195). It stopped check withunknown function __open_r(), which read like an internal error; it now reads the file aswith open(path) as f: json.load(f)does. Other uses of anopen()file the typed build cannot take (passing it to a function, for example) get a plain message instead.- The dynamic build's
reis faster than CPython on search loops (#195). A search now skips straight to the characters a match can start with (also after\b,^or\A, and withre.I), a one-character pattern such as[^a-z ]scans without backtracking, and searching one text with many patterns converts the text once. On a stand-in for the issue's bench (re.search(rf"\b{w}", scene, re.I)over 147 topics and 79 scenes, plusre.sub) the dynamic build went from 0.86x to about 1.8x CPython's speed. - Silent wrong output fixed:
\N{NAME}in.pyfiles.print("\N{BULLET} item")printed the escape as text on the typed path and sent the program to CPython from the dynamic build. Both builds now resolve names (any case, aliases) from a table in the compiler, 400 KB of binary size; a bad name, or a computedCJK UNIFIED IDEOGRAPH-/HANGUL SYLLABLEone, is refused and left to CPython. (#185, thanks @timoconnellaus) - Silent wrong output fixed: float
sum(). Typed builds added floats one by one, sosum([0.1] * 10)printed0.9999999999999999andsum([1e100, 1.0, -1e100])printed0.0. Every typed float sum (lists, generators, JSON numbers, Python library values,sum(xs, start)) is now compensated as in CPython 3.12+ and the dynamic build, andsum([-0.0])prints0.0. (#190, thanks @timoconnellaus) - Uncaught exceptions in Python files exit 1, as in CPython. Native typed builds exited 101, Rust's panic status, and
bench/compare/compare.pyhid it by only comparing zero with non-zero; it now compares exact exit codes..bvprograms still exit 101 after a runtime error. (#187, thanks @timoconnellaus) - A
.pyfile with Brevi-only syntax or methods is refused, as CPython refuses it.if a && b:,x => x + 1,fn f(x):,0..n,true,fail("x")andxs.push(1)on a list used to build and print an answer; nowcheckandbuildreport one error with the Python spelling andbrevi runfalls back to CPython, which gives the real error. A class's ownpushstill works, and.bvfiles keep every Python spelling. (#189, thanks @timoconnellaus) - Silent wrong output fixed: print arguments and tuple items changed by a later one.
print(xs, grow(xs)), wheregrowchanges the list (or a global, orself), printed the list from before the change in typed builds, andr = (q, q.pop())kept a copy ofq; both now go to the dynamic build and print what python3 prints. None of the 580 saved solutions moved off the typed path. (#188, thanks @timoconnellaus) - Silent wrong output fixed: a Python file the guard could not read. When the dynamic parser could not read a file (or a module it imports) that the typed build accepted, such as one using
except*, every guard check was skipped, soprint({3, -1, 5})printed the set sorted. Such a file is no longer built typed:brevi runruns it with python3, andbuildandcheckreport an error. Files with a bareallowline now get the guard's checks too. (#191, thanks @timoconnellaus) - Silent wrong output fixed:
d.copy()andlist(d)on a dict in typed builds.d.copy()gave the dict's keys, soprint(d.copy())showed{'a'}for{'a': 1}, andlist(d)printed as a set ({'a'}for['a']).d.copy()is now a copy of the dict (also with tuple keys) andlist(d)a list of its keys. Found from the conformance run. - Silent wrong output fixed: comparing dict views in typed builds.
d.items() <= e.items()andd.keys() == {1, 2}follow set rules in CPython; the typed build compared them as lists. Programs that comparekeys(),items()orvalues()with<,<=,>,>=,==or!=now take the dynamic build, which now compares key and item views with sets and with each other as CPython does (values()views compare by identity, sod.values() == d.values()is False). Found from the conformance run. - Dict subclasses in dynamic builds:
__missing__anddict(mapping).d[k]on a dict subclass with__missing__now calls it for a missing key (aCounter-stylec[k] += 1works), anddict(sub),dict(obj)andd.update(obj)copy a dict subclass, or any object withkeys()and__getitem__, as CPython does instead of giving an empty dict. - A class with
__del__runs in CPython. Both builds free objects at other times than CPython, so a__del__that counts or logs ran at the wrong moment or not at all.brevi runnow runs such a file with python3 and says why;buildandcheckrefuse it. - Silent wrong output fixed:
returninsidetry/finallyin typed builds. A function whosetrybody returned, with afinallyafter it, returned None in typed builds and thefinallynever ran;breakandcontinueout of such atryskipped thefinallytoo. These programs now take the dynamic build, which runs thefinallyas CPython does.try/exceptwithout afinallystays typed. Found by the CPython conformance run (#199). - Silent wrong output fixed: string escapes in typed builds.
'say \"hi\"'and"don\'t"kept the backslash (don\'t, and a length of 2 for"\'"), and a backslash at the end of a line inside a string was kept instead of joining the lines. - Silent wrong output fixed:
for k in objover a JSON object in typed builds walked nothing; it now walks the keys (and a JSON string's characters), as in Python. Seen oncemeta = d.get("meta") or {}built typed. issue["labels"] or []andd.get(k) or {}on JSON build typed. They stopped the typed build withthe trait bound `bool: AxEach` is not satisfiedand took the slower dynamic build.- Dynamic builds raise CPython's errors in more places (from the conformance run): a list, dict or set method that takes no arguments raises TypeError when given one (
xs.clear(None),d.items(1)); deleting a dict key and adding another while looping over the dict raisesRuntimeError: dictionary keys changed during iteration; a slice step,xs.index()bound orint()base past 64 bits is clamped or refused as in CPython instead of stopping withIndexError: cannot fit 'int' into an index-sized integer. - Silent wrong output fixed:
"%d items" % (n,)in typed builds. A string%a one-item tuple printed the item as a list ([3] items,['a']), because the typed build keeps(x,)as a one-item list. It now fills in the item, as CPython does. - Silent wrong output fixed: one-item tuples shown whole.
print((5,)), a list or dict holding(x,), an f-string of one, or one returned from a function or passed to one printed[5]in typed builds. These programs now take the dynamic build and print(5,). The check follows only the one-item tuple itself, so a real tuple that holds one ((n, path + (u,)), read back by index) stays typed. - A module file with a triple-quoted string over several lines is no longer refused.
TOKEN_RE = re.compile(r'''...''', re.X)in an imported.pyfile stopped the build witha used file holds only fn, type, enum and test itemsat the pattern's second line. Seen in a release-runjson_queryprogram, which now builds and passes its tests. import json.decoderworks in dynamic builds.json.decoder.scanstring(...)afterimport json.decoderwas refused (json.decoder is not supported in dynamic builds), and in a file the typed build also could not take, the build failed outright. Seen in a release-runjson_queryprogram, which now builds natively and passes its tests.e2e.py --verdictno longer passes on nothing. A log glob that matched no files printedrelease test PASSED; it now stops with an error.--verdictexits 1 when the bar is missed, and a run without theanthropicpackage orBENCH_ANTHROPIC_KEYsays what to install or set.- The result cache no longer replays a refusal caused by the machine. When the dynamic build's runtime library could not be built (many builds starting on a cold cache at once, a full disk) or rustc was killed, a Python file was refused with the typed build's reason, such as
cannot work out the type of s, and that refusal was kept and shown again on later runs until the cache was cleared. Such failures are now never kept, and a crate rustc could not load is no longer cached as an error in the program. Seen in the v0.24.6 release run.
Contributors: thanks to @timoconnellaus for their work in this release.
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