Skip to content

ast: the in-place alias check reads by type, one visitor - #4750

Open
aleksisch wants to merge 12 commits into
masterfrom
aleksisch/alias-handle-init
Open

aleksisch wants to merge 12 commits into
masterfrom
aleksisch/alias-handle-init

Conversation

@aleksisch

Copy link
Copy Markdown
Collaborator

A make assigned to anything but a plain local was an alias whenever its value read a reference, a global, a container element or a call. Under no_aliasing that made common ECS code an error although nothing there could overlap.

What changes

  • A read counts only when its type can hold the destination type, or the destination type can hold it - the type model the function result check already uses (collectAliasing).
  • A das function with known side effects that reads no global, no pointer, no argument by reference and invokes nothing is a pure call, as a builtin with no side effects was.
  • A struct's field defaults go through the same check; a handled type's initializer is C++ that only builds the destination and reads no das memory.
  • The check is one visitor, DestinationReads, behind mayReadDestination(value, dest) in src/ast/ast_derive_alias.h: one typed preVisit per expression kind, each ending in one read(type, through) decision.

Examples that were errors under no_aliasing and now compile

  • req.usage = ResourceUsage(access = Access.READ_WRITE) - a handled type built from constants.
  • reqs.depth = SubRef(nameId = id, mip = attachment.mip) with attachment of an unrelated struct type.
  • s = Scaled(a = half(x), b = x) with half a das function without side effects.

Reads that can still overlap stay errors, e.g. a float2& read while building a struct that has a float2 field.

Tests

  • tests/language/uncategorized_no_aliasing.das: test_store_handle, test_store_other_type, test_store_pure_call - each fails to compile without this change.
  • failed_aliasing.das, failed_aliasing_construction.das, in_place_build_aliasing.das (including the inlined make that reads its own destination) still pass.
  • tests/language 2250/2250, tests/jit_tests 444 passed 7 skipped. Lint and line-length clean.

@aleksisch
aleksisch force-pushed the aleksisch/alias-handle-init branch from 06b2dc6 to 09daa2b Compare November 22, 2026 19:05
A make assigned to anything but a plain local was an alias whenever its
value read a reference, a global, a container element or a call. Under
no_aliasing that made common ECS code an error although nothing there
could overlap: a handled type built from constants, a struct built from
a reference of an unrelated type, a value computed by a das function
with no side effects.

A read now counts only when its type can hold the destination type, or
the destination type can hold it; this is the type model the function
result check already uses. A das function with known side effects that
reads no global, no pointer, no argument by reference and invokes
nothing is a pure call, as a builtin with no side effects was. A
struct's field defaults go through the same check, and a handled type's
initializer reads no das memory. The default value of any other type, an
empty array or table included, reads nothing, and an operator with no
function behind it, as ?:, reads only its operands.

The check is one visitor, DestinationReads, behind
mayReadDestination(value, dest) in ast_derive_alias.h.
jit_lib_run_in_frame pushed the library's frame without a prologue,
so the stack walk in heap_collect read garbage sizes and never ended.
With the header in place, each call runs collectHeapIfMostlyFree
first: a persistent-heap library with gc frees what earlier calls
left behind once the heap grows past its budget, and the host has
nothing to call. dasllama_lib turns on persistent_heap and gc.
Auto-inline was off to match a runtime that turned it off under
no_aliasing. Since 7ad93e5 the runtime inlines with no_aliasing
too, so the driver inlined less, its hashes differed from the
runtime's and those functions ran interpreted.
@aleksisch
aleksisch force-pushed the aleksisch/alias-handle-init branch 2 times, most recently from c7b3c83 to 8710a7e Compare November 23, 2026 15:35
An AOT object called every builtin through a slot the host filled at
load, so neither the optimizer nor the host's LTO link saw the callee.
It now calls the builtin's link name, as a static -exe does.

The AOT compiler binds host functions to stubs, so the name it saw was
the stub's, which the host does not define. Host functions, methods
and properties are now bound through one wrapper per function
(das_host_call, CallPropertyStubbed) with the same symbol in both
builds: its body is a stub in the AOT compiler and the real call in
the host, so the compiler links without host code and records the
host's symbol. addExternHost binds a host function that way, and the
DAS_ADD_FUN_BIND / DAS_ADD_METHOD_BIND macros are now thin calls to
it. It also marks the function noFolding: a constant call folded in
the AOT compiler would run the stub, and folding in only one of the
two builds would give them different AOT hashes.
A jitted function takes its context last, after its arguments, and a
block after its arguments and its block pointer. ExprFakeContext read
parameter 0, which is the first argument whenever there is one, so a
builtin that takes the context got that argument instead.
@aleksisch
aleksisch force-pushed the aleksisch/alias-handle-init branch 2 times, most recently from 79f239d to 8225f27 Compare November 23, 2026 18:51
An AOT object held machine code, so a host that links with LTO could
not inline across the das and C++ code, even with direct builtin
calls. With DAS_JIT_AOT_LTO the object holds the module's IR, with the
triple, data layout and cpu attributes the target machine would have
used, and the host's linker optimizes it with the rest of the program.
The split exe's LTO partitions and the AOT object now write their
bitcode through one helper, write_lto_bitcode.
is_linkable_symbol read every L<digit> in a mangled name as the marker
of an internal-linkage name. An enum value used as a template argument
mangles the same way (L8PhysType1E), so builtins and properties of
types templated on an enum lost their link names and stayed slot calls
in AOT objects. A literal is now told apart by the value and E that
follow its type name.
An AOT object reached the new, delete, at, each and clone hooks of a
handled type, and every interop builtin, constructor and using,
through a slot the host filled at load, so no call there could inline.
Each hook now returns a JitTarget, the function's address and its
link name, from the one virtual it already had; the hook functions are
named, and these builtins record their link names. With direct
builtins the object calls them by symbol. float3x4[i] alone was the
largest share of indirect calls.
@aleksisch
aleksisch force-pushed the aleksisch/alias-handle-init branch from 8225f27 to a6ec2fd Compare November 23, 2026 19:45
The table at, find and erase helpers, and the string-key at with a
precomputed hash, were reached through slots in AOT objects. They
report their link names now, so with direct builtins the object calls
them by symbol.
A float3x4() constructor had an address but no link name, and the
clock casts had internal linkage, so an AOT object reached them
through slots. They report a link name now.
The parallel emit looked LLVM up as the plain file LLVM.dll, while
the bindings load it as llvm=LLVM.dll. With DAS_EXTERN_LIB_LLVM set,
the two names could resolve to different libraries, or the lookup
could fail although the bindings loaded fine. __dasbind_get_library
now takes a bare alias and returns the library the [extern] bindings
of that alias already loaded, and the split emit asks for "llvm".
A lowering that emits a loop wrote the blocks, the phi and the back
edge by hand, and ir_dsl could only fill a function of its own in
g_mod, not the one the JIT is emitting or the module it belongs to.

ir_loop runs a body for i = 0..count-1, if_value joins two branches
in a phi, return_if can return a value, call calls a function of the
module, and Ir gets * and !. offset and ptr_slot can be inbounds, as
the JIT's own address arithmetic is, so the optimizer drops null
checks on them. ir_at builds at the insertion point of an existing
builder, ir_function takes the module to define into, and it keeps
the state it found, so it can be called inside ir_at.

The emitted code of this branch changed, so LLVM_JIT_CODEGEN_VERSION
moves and the emitter pin follows.
@aleksisch
aleksisch force-pushed the aleksisch/alias-handle-init branch from a6ec2fd to b0c2e94 Compare November 23, 2026 20:21
@aleksisch
aleksisch requested a review from borisbat November 23, 2026 20:26

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant