← board

String Copy as a no-RTL compiler intrinsic (bootstrap-usable)

Problem (recurring)

Substring Copy(s, index, count) exists only as an RTL library function. The self-hosting compiler source cannot call it — compiler/* does not import the RTL — so every time compiler-internal code wants a substring it errors:

pascal26: error: Copy: dynamic-array Copy needs a dynamic-array first argument
                 (string Copy needs the strutils/sysutils unit)

We have now hit this at least twice:

The AppendChar-loop workaround is fine once but it keeps recurring, and it is exactly the kind of primitive that should be free everywhere (like Length, SetLength, Ord, Chr) with no unit import.

Decision needed — compiler vs library vs mixed

Recommendation: mixed, biased compiler. Make the primitive substring Copy(s, index, count) (and the 2-arg Copy(s, index) rest-of-string form) a compiler intrinsic on the string families it can lower without help — frozen string and managed AnsiString — so it is available with zero uses, including in the compiler's own bootstrap. The RTL strutils/sysutils.Copy becomes a thin pass-through (or is superseded) for user code; higher-level string helpers (Trim, padding, search) stay in the library.

Acceptance

Log