A call of an imported C-runtime procedure from a procedure or main() recovers with its prototype #805
Loading…
Reference in a new issue
No description provided.
Delete branch "lcimp"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
A call of an imported C-runtime procedure from a procedure or
main()recovers with its prototypefclose(f),rc = fclose(f),p = fopen(%addr(a): %addr(b)),p = fgets(%addr(buf): 150: f),p = geterr()of__errnoandcee_discardHeap(heap: *omit)failed atimportFrame: the frame ofa call that a procedure makes is not the frame of the cycle. This change reads the frame of a
procedure, reads each argument from the call site and the return from the symbol of the import, and
writes the prototype from them:
dcl-pr P int(10) extproc('_C_IFS_fclose'); *n pointer value; end-pr;.What the object does not tell stays a failure line:
p = fgets(%addr(buf): %size(buf): f)is one of them(fact 8). 21 of the 22 clean twins of the battery round-trip to the same object on the host (
match,only
compilationdiffers); the 22nd,lcimp-r03, keeps its failure line.The battery is
requests/lcimp/cimport(16 cases, captureslcimp-cimport),cimport2(13 cases:return and argument types), and the clean programs for the round trip,
cimport3b,3c,3d(21 cases, no unused field, compiled with
DFTACTGRP(*NO) BNDDIR(QC2LE)),cimport3e(r22, a droppedint(3)),cimport3i(d14) andcimport3f(d15). SC-ILE/EXPERIMENTS holdslcimp-r01tolcimp-r22and the seven refusalslcimp-d05,-d06,-d08,-d10,-d11,-d14,-d15.The facts, and the probe pairs that decide them
cimport/c01-cycleagainstc02-procdiffer inthe caller only (the loop captures; the committed twins are
lcimp-r06-cycleand-r01-drop).The cycle has
27 I; 37 S 92 C10and the blank of S+102. A procedure has27 I; 1; 37 C 26 C10; 37 S 92 C10, the blank of S+102 and the blank of C+16 (C the 48-byte call information of theprocedure,
callInformation).c03-mainagainstc02-proc(main() only) has the sameoperations: a
main()procedure is a procedure (lcimp-r10-main). The header (99 P N 0 1) isindependent of the caller:
lcimp-r09-clib(extproc('fclose')) has the header and the copy,_C_IFS_*,__errnoandCEE*have neither (the header follows the name, as forusleep,printfandstrcat).importFramerequired a null pointer before unit 1in the no-header form (
*OMIT, h-ceeran).r06has a pointer variable there, andlcimp-r15-noargshas no argument (
99 P 0 0 0). The frame is units 1 and 2, the optional header, the name and theblanks; the arguments are read apart.
113 q 2after an argument is a reference, no tag is a value.lcimp-r08-byref(
s pointer) against-r01-drop(s pointer value) differ in the prototype only:34 f 0; 113 9 2against29 f 0 3. An untagged34 X 0(%addr(x),-r05,-r03) or29 P 0 T(apointer variable) is a
pointer value. Every by-reference argument that recovers today is tagged(h-extproc, h-ceeran, dict-calls3, -4, -5).
27 K; 78 8; 75 4; 75 4and29 n 0 T; 75 8; 75 4; 75 4are anint(10) value(-r04the literal 150,-r17a variable;-r03%size(buf)has the same operations and is refused, fact 8). Anint(5)has75 2; 75 2(
-d05), an unsigned76(-d06), anint(20)has none (-d08): refused.28 (1 signed binary, 2 unsigned binary, 9 pointer, 0x11 none) and the size in bytes is its word
20.
int(3),int(5)andint(10)compile to the same operations (99; 75 8), and a droppedint(20)and a dropped pointer to the same too (99; 3); only the symbol tells them apart(
cimport2d01, d03 andcimportc02, c06, c09: 2, 1, 4, 8 and 16 bytes).lcimp-r11-ret-int5(dropped) and
-r12-ret-int5-setround-trip withint(5), andlcimp-r22-drop-int3(a 1-byte symbol)with
int(3); withint(10)for the symbol of anint(5)the first attempt differed in the symbols, which is how the word was found. Theoperations then have to be the measured ones of the type: a binary of 1, 2 or 4 bytes is widened
by
75 8right after the call (76 8foruns(10)), the others are not; a dropped result ispopped by
3; a result that a store consumes is the store of a pointer, or75 S; 75 S; 37 X 0 Tof an
int(5)or anint(10)of the size S. Other kinds and widths (uns(5), a float, a packedresult, a stored
int(20)) have no probe and no verdict.end a block follow it: the jump to the end of the procedure (
-r07), an IF without ELSE(
-r13,-r14in the cycle), the jump over an ELSE (-r18). A pop, a compare or any otheroperation after a call that the symbol says returns nothing refuses; so does a call with a result
and no pop or consumer.
*OMITonly for a CEE service.-d11-null-last(fgets(b: 150: *null))compiles to the operations of an
*OMIT; the emit writes*OMITand the feedback codechar(12) options(*omit)for a name that starts withCEE(h-ceeran,-r07) and refuses for anyother name, and only for the last argument.
%SIZE(buf)is not the literal 150.lcimp-r03(%size(buf)) and-r04(150) have the sameoperations; the round trip of the emit
150for r03 differs in the creation instructions, the symbols,the literals, the constant area and the initialization. The compiler folds
%SIZEto the number andleaves a packed constant of that value that no operation loads (
rpg_elem_count.zig); the literal hasnone. An integer constant is read as a literal only when the module holds no such constant of its value
(
rpg_elem_count.leftByBuiltin), else the call refuses. A literal that shares its value with a%SIZEelsewhere in the module refuses too: which one is which is not proved.
lcimp-d15-two-formscallsCEEDSHP(n: fc)andCEEDSHP(n: *omit): the second statement reads as another form of the second parameter than theprototype of the first, and keeps its failure line.
lcimp-d14-copy-const(CEEDSHP(5: *omit)to aCONST
int(10)) passes the untagged address of a compiler temporary (37 T; 33 T; 113 q 1): the sitereads a
copyand the emit keeps the failure line.What changed
rpg_import_site.zig(new, PURE): the call site.readwalks the operations of the statementbefore the frame with the stack walk of
rpg_value_pointer(nowstep, one operation, andItem.from, where a value began) and gives the form of each argument (reference,pointer_value,int10_value,omitted,copyfor the untagged address of a compiler temporary,which keeps the old text of the failure) and the return (from the symbol, and whether a store
consumes it).
int10takes an integer constant only whenrpg_elem_count.leftByBuiltinsays that no folded builtinleft a constant of its value (fact 8), and no other kind of constant.
rpg_frames.importFramereads the four frames (header, call information copy; no argument).rewriterefuses a call with no site, and gives the call operation the forms and the return.rpg_eval.callrenders each argument by its form: a reference as the data,%ADDR(x)or a pointervariable for a value, a number for an
int(10).Emitter.importCallreads the same site from the original operations of the statement and writesPrototype.Parameter.pointer_valueand.int10_valueandPrototype.returns; the prototypewriter puts the return type after the name. A second call of one import has to agree with the first
in every form and in the return, or it fails.
Emitter.expressiontakes the call of an importinside an expression (
p = fgets(...); the name may start with_).Measured
The 32 public scout programs (
captures/l10-scout2,l10-scout2b: 33 directories, one program is inboth trees and counted once), base v0.1.521 against this build,
capture-emit-diff.sh: statements512, emitted 295 to 306, failures 224 to 213 (
runs/lcimp/scout-fix, the build with the%SIZErefusal offact 8). Six programs change; every changed statement is an import call, and each reads as its source line:
fptr = fopen(%addr(fpath): %addr(fmode)),fclose(%addr(fpath))fclose(stream),p_errno = sys_errno()cee_discardHeap(heapId: *omit)7 of the 15 statements of the triage recover (2 + 1 + 1 + 1 + 1 + 1); the other 8 are the
success = fgets(%ADDR(buffer): %SIZE(buffer): stream)lines of the four adventofcode programs, which keeptheir failure line (fact 8: the emit
150is another object). The four__errnostatements of the nexttoken recover. The first version of this change emitted those eight as
fgets(%ADDR(buffer): 150: stream)(emitted 314, failures 205) and was refused in review for it.
agree.shover the 32 programs: same 148 to151, suspect 12 to 12, wrong parameters 0 to 0. The 1347 public captures under
captures/(the lext importtwins, dev5, l10-pgm-a1 and -a2 among them) were measured with the first version: only those six programs
changed, and the refusal only takes emitted statements away; the
usleeptwins stay as they were (theiruns(10) valueargument refuses).The committed twins (emit-all over
src/testdata, base against head): none gets worse; 3 existingtwins change: TSELR (
fclose(f)recovers, the prototype reads as its source), dict-calls3 (thestrcmpprototype has itsint(10)return, andI = cpyr(C: C2)recovers) and dict-calls4 (a failureline says
CALLP strcat(...)in place ofunresolved). h-ceeran, which matches on the host, keepsits text byte for byte, and so does a void CEE call in the cycle (
lcimp-r14, base and head equal).The round trip (host, pub400,
pub-roundtrip.shwith the build of this change)fclose(f)dropped, from a procedurerc = fclose(f)p = fgets(%addr(buf): %size(buf): f)150of the first version wasdifferent: creation instructions, symbols, literals, constant area, initialization, importsfopen, a reference, the C library name with a header,main(), the cycleCEEDSHP(n: *omit), alone, in an IF, in the cycle, before an ELSEint(5)dropped and stored__errnowithout argument, two calls of one import, anint(10)variableint(20), pointer anduns(10)int(3)pub-lcimp-r22-drop-int3-011901)r03is the folded builtin:%SIZE(buf)leaves a packed constant that no operation loads(
rpg_elem_count.zig), and the literal 150 ofr04has none. The operations are equal, and the objectdiffers; the first version of this change wrote
150for both and r03 did not round trip. A constant withsuch a head is no literal, and the call refuses (fact 8). Eight of the fifteen statements of the triage are
this shape; a rule that writes
%SIZE(buf)for it (the buffer is the field that%ADDRnames in the firstargument) is the next change, not this one.
Not done, and why
operation consumes (
lcimp-d10), anint(5), an unsigned or anint(20)value argument(
-d05,-d06,-d08), a null that is not the last argument or not of a CEE name (-d11), apointer plus a byte (
29 P 0 T; ...; 62, untagged), the address of a compiler temporary (-d14), asecond call of one import whose forms or return differ from the first (
-d15) and an integer constantthat a
%SIZEor%LENmay have left (-r03): the site has no verdict, the statement stays a failureline. A null that is not the last argument and a pointer plus a byte are pinned by mutation tests of
lcimp-r07and-r01; every other refusal has a twin.options(*string)family (fopen(filename: options)with characters): the arguments aretemporaries of a copy that ends in a zero byte, another family.
bnddir('QC2LE')is not in thectl-optof the emit; the object does not say it. The round trip ofa program that calls
_C_IFS_*needs the binding directory in the compile command (the commandsof the committed r twins carry it,
probe.json).For the matrix
lcimp-r01to-r22except-r03match on the host.-r03keeps a failure line (above), as do theseven refusals (
-d05,-d06,-d08,-d10,-d11,-d14,-d15) by design: they have a failureline, and some have unused fields and
bnddirin theirctl-opt. None of them can match, and they need aclass row (
known_gap, the reason in this fragment).Gate (host round trips, base = ~/bin/sourcerer, the code of v0.1.521)
The frame of a call that a procedure or main() makes copies the name into its call information; the cycle does not. The call site gives the form of each argument (a reference, a pointer value, an int(10) value, *OMIT), and the symbol of the import gives the type that it returns. The emit writes the prototype from them: dcl-pr P int(10) extproc('_C_IFS_fclose'). What the object does not tell stays a failure line.1fec51b77afdb37831a9