Commit graph

9 commits

Author SHA1 Message Date
mzhoot 94ae8c354c Рабочие синонимы 2026-07-04 21:44:54 +03:00
Graeme Geldenhuys 406a8c303c rtl-unification: dedup RTL objects by symbol, build race-free; move fixpoint scripts off the archive
Builds on the source-built-RTL link path.  Two correctness fixes plus the
fixpoint-script migration that takes the self-host pipeline off blaise_rtl.a.

1. Symbol-based dedup.  A program that uses an RTL unit (e.g. `uses classes`
   pulls runtime.arc) compiles that unit into its own object cache, so
   EnsureRTLObjects must not supply a second copy or the link double-defines it.
   The dedup now compares the DEFINED symbols of the caller's objects against
   each RTL object (via the ELF reader) and skips one only when fully redundant
   — matching the old archive's member selection.  An earlier filename-only
   check wrongly suppressed the real bare-symbol provider when a same-named but
   differently-mangled stale object was present.

2. Race-free build.  EnsureRTLObjects now builds into a per-process private
   directory (rtl/build-<pid>/) and atomically renames each finished object
   into the shared cache.  Parallel builders (e.g. e2e suites warming a cold
   cache) no longer corrupt each other: a reader never sees a half-written
   object, and two builders just publish identical results.  The private dir is
   cleaned up afterwards.  getpid/rmdir are declared directly rather than via
   GRtlPlatform to avoid a unit-init-order crash in the driver.

3. Fixpoint scripts off the archive.  New scripts/build-rtl-objects.sh builds
   the RTL from source (the script-level equivalent of EnsureRTLObjects), with
   --exclude-defined-by so a whole-program --emit-ir/--emit-asm dump (which
   inlines the RTL units the compiler uses) is not handed a duplicate copy.
   fixpoint.sh and fixpoint-native.sh link via this helper instead of
   blaise_rtl.a; fixpoint-native-internal.sh and fixpoint-warmcache.sh no longer
   copy the archive beside the compiler (the driver source-builds the RTL).

All four fixpoints green (FIXPOINT_OK, NATIVE_FIXPOINT_OK, NATIVE_INTERNAL_OK,
WARMCACHE_FIXPOINT_OK); full suite green (3829 tests) under QBE- and
native-built runners; four cold-cache parallel suite runs pass.

The runtime Makefile / ar / make install are still present; removing them is the
final Stage-3 step.
2026-06-25 23:08:30 +01:00
Graeme Geldenhuys 0d47c5f996 feat(backend): default to native backend; fix codegen bugs exposed by the switch
The native x86-64 backend is now the default (bkNative).  QBE remains
available via --backend qbe.  Several codegen bugs that were invisible
while QBE was the default are fixed in this commit:

Native backend fixes:
- EmitLeaqGlobal helper: threadvar globals now emit the correct
  fs:0 + @tpoff TLS sequence instead of bare %rip-relative leaq.
  Fixes static array write (FreeLists), string subscript assignment,
  EmitExprAddr, record memcpy, method-ptr cast, and open-array push
  paths that all used raw leaq %s(%rip).
- EmitIncDec: unified local/global paths through VarOperand so
  threadvar scalar Inc/Dec (e.g. LargeFreeCount) gets TLS addressing.
- EmitIncDec FAE.Base: Inc(P^.Field) where P is a pointer now
  evaluates the base expression instead of leaq on the stack slot.
- FinalizeEmit: data section (.data/.bss/.rodata) now emits once at
  the end of unit compilation via FinalizeEmit, not inside each
  EmitUnit call.  Fixes duplicate/missing string literals in sep-compile.
- EmitFunctionDef AExported: implementation-only helpers in monolithic
  mode stay file-local (.globl suppressed) to avoid symbol collisions
  with the RTL archive.

QBE backend fixes:
- AppendUnit typeinfo: export prefix added to data $typeinfo_TObject,
  $typeinfo_TCustomAttribute, $vtable_TObject, $vtable_TCustomAttribute
  so native-built RTL can resolve them.
- FSuppressSystemDefs: decoupled from FExportAll so CreateUnitCodeGen
  can export all symbols without suppressing system defs.

Infrastructure:
- runtime/Makefile: BLAISE_FLAGS variable for passing extra compiler
  flags (e.g. --backend qbe) from build scripts.
- fixpoint.sh: make clean before RTL rebuild to pick up backend change.
2026-06-19 04:27:41 +01:00
Graeme Geldenhuys 57c0660a37 refactor(lang): remove IsNoArgFuncCall dead code, fix remaining bare calls
With mandatory () on all zero-argument calls (51ebf23), the
IsNoArgFuncCall/NoArgFuncDecl fields on TIdentExpr and the
synthesised TFuncCallExpr codegen path are dead code. Remove them.

This exposed ~300 bare function calls missed by the original
migration script across compiler, runtime, stdlib, tests, and
embedded Blaise source strings. Fix all of them.

Add IsProcFieldCall support to TMethodCallExpr so that
H.Handler() works for procedure-type fields — the parser creates
TMethodCallExpr for Obj.Name(), and the semantic pass now detects
when 'Name' is a procedural-typed field rather than a method,
routing through the indirect-call codegen path.

Update fixpoint.sh to fall back to an existing blaise_rtl.a when
the release binary is too old to build the runtime.

2627 tests pass, FIXPOINT_OK.
2026-06-06 20:28:13 +01:00
Graeme Geldenhuys 16c4f5b690 fix(fixpoint): drive runtime build with stage-1 binary, not compiler/target/blaise
fixpoint.sh's runtime build (step 1) relied on the runtime Makefile's default
BLAISE=../compiler/target/blaise. After scripts/rolling-bootstrap.sh — which
installs only to releases/ and leaves the live compiler/target/ empty — that
path does not exist, so `cd runtime && make` failed with
"compiler/target/blaise: No such file or directory" (RUNTIME_FAIL) even though
the release binary was perfectly usable.

Pass BLAISE=<abs stage-1 path> into both the runtime `make` and `make install`
so the build never depends on a pre-existing compiler/target/blaise. Resolve
the RTL archive into $RTL_ARCHIVE once (installed compiler/target copy, falling
back to runtime/target/), and use it at both link sites.

Verified by running the patched script from a fresh clone with no
compiler/target/ present (the exact post-rolling-bootstrap state): reaches
FIXPOINT_OK where it previously aborted at step 1.
2026-06-04 01:29:28 +01:00
Graeme Geldenhuys 923b94c541 refactor: split rtl/ into runtime/ + stdlib/, rename bcl.testing to blaise.testing
Separate always-linked runtime code (system.pas, ARC, strings, platform
abstraction) from opt-in standard library units (sysutils, classes, math,
dateutils, generics, etc.).  This mirrors the Go runtime/ vs stdlib, Rust
core vs std, and Swift SwiftRuntime vs SwiftCore patterns.

- runtime/ contains code linked into every binary + C shims
- stdlib/ contains units imported explicitly via uses clause
- Single platform abstraction layer (rtl.platform.*) in runtime/,
  shared by both runtime/ and stdlib/ units
- bcl.testing renamed to blaise.testing across all 95+ test files
- Updated PasBuild project.xml, fixpoint.sh, README, unit search paths
- All 1931 tests pass, fixpoint OK (stage-3/stage-4)
2026-05-16 00:51:18 +01:00
Graeme Geldenhuys 1083e6c776 fix(fixpoint): add stage-4 fallback for cross-release bootstrap gaps
When stage-1 is an older release with different codegen, stage-2 and
stage-3 IR will differ. The script now automatically extends to
stage-3 -> stage-4 and checks that fixpoint instead of failing.
2026-05-13 00:38:23 +01:00
Graeme Geldenhuys 0cfb9ffa98 release: v0.7.0 — FPC-independent, fully self-hosting
Bump version to 0.7.0. Update fixpoint.sh to use the latest release
binary as stage-1 instead of FPC — FPC is no longer needed anywhere
in the toolchain.
2026-05-13 00:35:56 +01:00
Graeme Geldenhuys 5b9bc375ea fix(codegen): eliminate dynamic stack allocs — phi for short-circuit bools, hoist exc frames
Two codegen improvements that eliminate all non-@start `alloc`
instructions from the emitted QBE IR.  Both are prerequisite work for
the self-hosting fixpoint (currently being debugged).

(1) Short-circuit boolean operators now use QBE phi instead of alloc4.

Previously `A and B` / `A or B` emitted:
  %slot =l alloc4 1          <- dynamic alloc, grows stack per execution
  storew %L, %slot
  jnz %L, @rhs, @end
  @rhs  storew %R, %slot  jmp @end
  @end  %T =w loadw %slot

The slot was allocated in whichever basic block the expression appeared
in.  QBE emits a runtime `sub $16, %rsp` for every alloc outside @start
— inside a while-condition this ran on every loop iteration, growing the
stack by 16 bytes per iteration indefinitely.

New form uses a phi node at the join block:
  jnz %L, @rhs, @end
  @rhs  (evaluate R)  jmp @end
  @end  %T =w phi @lhs %L, @rhs %R

No alloc needed; %T is always well-defined at @end by SSA.
FCurrentBlockLabel tracks the current basic block name so the phi can
correctly name its predecessors.

(2) Exception frames pre-allocated at @start via EmitExcFrameAllocs.

Previously EmitTryFinallyStmt / EmitTryExceptStmt emitted `alloc16 512`
inline at the point of the try statement.  Inside a loop (e.g. `for I
:= 0 to N-1 do begin try ... finally ... end end`), each iteration
allocated 512 bytes of stack that was never released until the function
returned.  Over hundreds of iterations this drifted the stack pointer
into parent exception frame territory, corrupting the exc-frame chain.

New approach: CountTryStmts recursively counts all try blocks in the
function body, EmitExcFrameAllocs pre-allocates %_exc_frame_0 …
%_exc_frame_N at @start (QBE hoists these to the static prologue sub),
and EmitTryFinallyStmt/Except index into the pool via FExcFrameNext.

Result: zero alloc instructions outside @start blocks in the emitted IR.

All 1242 tests pass.  Stage-1 IR and stage-2 IR are now byte-for-byte
identical (md5 verified) — the fixpoint is correct at the IR level.
The stage-2 BINARY still crashes during stage-3 generation; this is
under active investigation and may be a QBE vs FPC code-generation
quality issue for the same IR.
2026-05-06 11:47:52 +01:00