You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Added
A portable d6 for any Linux. Each release now attaches d6-VERSION-linux-x86_64.tar.gz
and d6-VERSION-linux-aarch64.tar.gz. They hold d6, facet, d6-lsp and d6-dap as
fully static musl executables, with SQLite, PostgreSQL, MySQL/MariaDB (MySQL 8 and MariaDB
authentication plugins included), TLS, zlib and BCrypt linked in. Before each release they
are checked in clean Ubuntu 26.04 and 22.04, Debian 12, Fedora 44, Arch, Alpine and
openSUSE Leap containers. They target baseline x86-64 rather than x86-64-v3, have no JIT
and cannot run d6 build. tools/build_portable.sh builds them in an Alpine container
(deployment).
Changed
Self-hosted compiler closer to native.selfhost/parser.d6 now compiles -> Self return
types, attr_reader item: T in generic classes, generic type arguments on classes inside a
module (Relation[T]), every File and Dir method, Fiber.yield, TCPServer.listen's host:/backlog: options with the non-blocking TCP forms, and do-block
contracts on generic functions (generic_collect(21) do [] end binds T to Int). It also
compiles every runtime builtin call: Time, Thread.new, Channel, Supervisor.new, Process, IO, SQLite3/MySQL/PostgreSQL, TLS and UDP sockets, DNS, Signal, Tensor, SemVer, and the crypto and encoding calls, so Active Record runs through it. Run
through it, every one of the 1,587 tests/cases programs now compiles and runs (up from
1,342 of 1,586), including the Callable contracts native infers: do blocks on constructors and
on a union of callables, generic function references (identity) fixed to the type a parameter
expects, and Box.new(41) known as a Box[Int].
ProgramBuilder type sets can say Callable[[], T]. A declare_type_set descriptor takes
an optional seventh Bool marking a written parameter list, so a typed zero-parameter Callable
differs from Callable[0, T] as it does in the native compiler.
Time and Tensor values cross threads. They can be Thread.new arguments and results,
go through a Channel, and be the result of ProgramBuilder#run, copied as plain data.
The JIT compiles functions that call methods on values of unknown type. A method call
whose receiver the JIT could not prove the type of (an untyped parameter, an Array element, a
polymorphic call site) used to keep the whole function interpreted; it now compiles to a call
into the interpreter's own dispatch. Functions that pass a block capturing their locals, and
the Math functions, compile too. With DIAMOND_JIT=1, the counts benchmark runs about 37%
fewer instructions, nbody and poly about 14% fewer, and sort 13% fewer.
Faster recursion under the JIT. A compiled function calling itself now calls its own
machine code directly, with the callee's registers on the native stack, instead of going
back through the VM. With DIAMOND_JIT=1, fib runs 53% fewer instructions (160 to 121 ms)
and trees 14% fewer. The call-depth limit and its stack-overflow error are unchanged.
Blocks run as machine code under the JIT. The body of a do ... end block or closure now
compiles, including the captured variables it reads and writes. Functions that read a
top-level constant compile too. With DIAMOND_JIT=1, the blocks and iterate benchmarks run
36% fewer instructions (91 to 76 ms and 152 to 116 ms), and regex 5% fewer. Captured
variables are now read and written by inline machine code instead of a call per access, and
a compiled block is entered directly from each/map/times, which takes blocks a
further 20% (70 to 60 ms) and iterate 15% (112 to 95 ms).
Closure calls and string interpolation compile under the JIT. A function that calls a
block or closure it holds, or builds a string with #{...}, no longer stays interpreted. With DIAMOND_JIT=1, the closures benchmark runs 5.6% fewer cycles and regex 6% fewer.
Functions with begin/rescue/ensure compile under the JIT. Exception handlers, retry, raise, and break/next/return through ensure no longer keep a function
interpreted, with the same errors and backtraces. With DIAMOND_JIT=1, the exceptions
benchmark runs 14% fewer cycles.
A memory budget keeps a VM on the interpreter under DIAMOND_JIT=1.DIAMOND_MAX_MEMORY_BYTES
was not enforced in compiled code: a compiled loop that only grew one array ran past the
budget until the system ran out of memory. Instruction and wall-clock budgets already did
this.
Many more functions compile under the JIT.!, puts/print, class-method calls
(Name.method(), self.method()), class variables, destructuring assignment, unary minus,
symbols, .class(), and calls that pass keywords, a *spread or explicit type arguments no
longer keep a function interpreted. These run the interpreter's own code for the
instruction, so results and errors are unchanged. Across the test cases, benchmarks and
examples, functions the JIT turned away fell from 3,041 to 1,333.
Generic functions and methods of generic classes compile under the JIT. Each compiled
call binds its type variables on entry, from the arguments, explicit type arguments
(f[Int](https://github.com/diamond-language/d6/blob/v0.29.0/x), obj.method[Int](https://github.com/diamond-language/d6/blob/v0.29.0/x)), the receiver or a block's creator, exactly as the
interpreter does, so type checks and errors are unchanged. -> Self methods compile too.
Functions the JIT turned away fell from 1,333 to 553. With DIAMOND_JIT=1, the
typed_dispatch benchmark runs 7% fewer instructions and the new generic_calls 4.6% fewer.
The JIT compiles functions with more than 256 registers. A function that big (a long
hash literal, two large methods the ORM packages share) used to run interpreted; it now
compiles, with its registers on the heap as the interpreter keeps them. Functions the JIT
turns away fell from 553 to 457, and native calls to smaller functions cost the same as before.
The JIT compiles variadic functions and methods.def f(head, *rest) and def f(*rest, &block) now compile; the rest Array is built in the compiled code, and their
tail calls to themselves still run in constant stack. A call with more arguments than the
function has registers runs in the interpreter, as does a function whose parameter setup
writes where its rest arguments wait (a default before the rest parameter). Functions the
JIT turns away fell from 457 to 416.
The JIT compiles blocks that break or return, and the functions they land in. A
function whose block breaks out of the call it was passed to, or returns from the function,
used to run interpreted, and so did the block. Both compile now, ensure clauses still run on
the way out, and a break from a block whose call has finished is still a rescuable error.
About 70 fewer functions are turned away.
The JIT compiles functions that use the builtins. Bitwise and shift operators, <=>, to_i/to_f/to_sym, case patterns, JSON, Regexp.new, encodings, digests, ciphers, Time, Fiber, sockets, processes, database opens, Thread.new, define_method and the
rest of the builtin calls no longer send a function back to the interpreter. Across the test
cases, benchmarks and examples the functions the JIT turns away fell from 363 to 17, and
those 17 only stop under the debugger.
Compiled code calls other compiled functions and methods directly. With the JIT on, a
call from compiled code to another compiled function, or to a method of an object whose class
the call site has seen before (up to four classes per site), no longer goes through the
interpreter's call machinery, and getters and setters called that way compile too. Instruction
counts fell 49% on a polymorphic shapes[i].area() loop, 38% on small objects, 28% on an
n-body simulation and 20% on structs; method dispatch benchmarks run 44 to 73% fewer.
Redefining a method with redefine_method or define_method still takes effect at once.
A block boxes only the locals it reads. Creating a do ... end block used to move every
local visible at that point into a heap cell, and every later read of those locals went
through the cell. Now only the ones the block's body names are, so the rest stay plain
registers: an n-body step that runs one bodies.each() do ... end per call does 11% fewer
instructions in the interpreter.
Compiled code handles objects inline. With the JIT on, Class.new allocates and calls a
compiled initialize directly, a type check against a single class, x == nil on an object
whose class has no ==, instance variable reads and writes, and calls to plain getters and
setters (attr_accessor, def x() = @x) no longer go through C. Together with the native
calls above, instruction counts fell 63% on an n-body simulation, 61% on small objects, 54%
on polymorphic calls, 49% on binary trees and 41% on structs.
Compiled code reads Array elements inline. With the JIT on, values[i] for a
non-negative Int index inside the array is a direct load; everything else takes the usual
path. The sieve benchmark runs 15% fewer instructions.
Closures and captured variables are cheaper to create. Swept closures (up to 16 captures)
and capture cells are kept for reuse, like small objects, strings and arrays already were.
A closure-heavy benchmark runs 31% fewer instructions in the interpreter and 47% fewer with
the JIT.
Compiled code runs Array each and map loops itself. With the JIT on, a block passed
to each or map on an Array is called natively from the loop instead of through C for
every element. A map-heavy benchmark runs 8% fewer instructions and an each-heavy one 10%
fewer; other iterators still use the C loop.
The interpreter is faster. 64 builtin opcode bodies moved out of its main loop, which
leaves the compiler more registers for the hot path: 2 to 10% fewer instructions on every
benchmark (fibonacci and tail calls about 10%), and with the JIT on fiber_switch and case_pattern_matching run about 18% fewer.
Fixed
A block inside a string interpolation no longer turns a local into a Cell. In out.push("#{list.map() do |v| out.length() + v end}"), out was read before the block boxed
it, so the call failed with undefined method 'push' for Cell.
A rest parameter no longer holds a placeholder when only a block is passed. f() do ... end for def f(*rest, &block) gave rest one invalid element, and reading it
(printing rest, say) crashed. It is now empty.
JIT: big-integer and operator-method arithmetic no longer loses values under GC pressure. A
compiled function whose only allocations came from +, -, *, /, %, a comparison or == on operands its fast path does not handle (big integers, Strings, a user operator
method) kept its registers hidden from the garbage collector during that call, so a
collection could free an intermediate result. (a / b) * b + a % b == a on big integers
could come out false with DIAMOND_JIT=1.
String#scan with a String pattern no longer crashes under GC pressure. The Regexp
compiled from the pattern was held only by the result register, which the scan overwrote
with its result Array before allocating the matches, so a collection mid-scan could free it.
Bytecode verifier reads is type ids in full. It truncated the type in x is Type to a
byte, so a program built with ProgramBuilder that tested against its 39th or later interface
failed with "constructed bytecode is invalid".