@geastack/compiler 1.0.34 → 1.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/targets/cpp/records.js +67 -15
- package/package.json +1 -1
|
@@ -450,15 +450,30 @@ const isRepresentationNode = (value) => typeof value === 'object' && value !== n
|
|
|
450
450
|
* this walk automatically instead of silently falling out of it, which is the
|
|
451
451
|
* failure mode a `switch` over kinds would have. The walk stops at each struct
|
|
452
452
|
* it names -- that struct's own dependencies are placed when IT is ordered.
|
|
453
|
-
|
|
454
|
-
|
|
453
|
+
*
|
|
454
|
+
* `probed` widens the first stopping rule for the one question that looks
|
|
455
|
+
* through a `Ref`: a struct's `geaTraceRefs` signature asks
|
|
456
|
+
* `TraceEdges<decltype(field)>::supported`, and `gea_runtime.h`'s
|
|
457
|
+
* `RefTargetIsLeaf` answers that for a `Ref<ArrayObject<E>>` by asking the
|
|
458
|
+
* ELEMENT. An `Optional<Record>` element is then instantiated and needs
|
|
459
|
+
* `Record` complete (a hard error), and a bare record element is asked for a
|
|
460
|
+
* `geaTraceRefs` friend an incomplete record does not have yet (a silently
|
|
461
|
+
* wrong "leaf"). A recursive container is a named wrapper the probe stops at,
|
|
462
|
+
* so it is never looked into. Dictionaries answer without their value, so
|
|
463
|
+
* they impose nothing here.
|
|
464
|
+
*/
|
|
465
|
+
const valueHeldStructNames = (representation, into, seen, probed = false) => {
|
|
455
466
|
if (seen.has(representation))
|
|
456
467
|
return;
|
|
457
468
|
seen.add(representation);
|
|
458
469
|
const node = representation;
|
|
459
470
|
const ownership = node['ownership'];
|
|
460
|
-
if (typeof ownership === 'string' && ownership !== 'owned')
|
|
471
|
+
if (typeof ownership === 'string' && ownership !== 'owned') {
|
|
472
|
+
const element = probed && ownership === 'shared-refcount' ? traceProbedElementOf(representation) : null;
|
|
473
|
+
if (element !== null)
|
|
474
|
+
valueHeldStructNames(element, into, seen, probed);
|
|
461
475
|
return;
|
|
476
|
+
}
|
|
462
477
|
if (node['abi'] !== undefined) {
|
|
463
478
|
// A bare record in a function-pointer signature may remain incomplete,
|
|
464
479
|
// but a by-value carrier BUILT AROUND that record may not. In
|
|
@@ -470,7 +485,7 @@ const valueHeldStructNames = (representation, into, seen) => {
|
|
|
470
485
|
const nested = [...abi.parameters.map((parameter) => parameter.value), abi.result, ...(abi.receiver ? [abi.receiver] : [])];
|
|
471
486
|
for (const value of nested) {
|
|
472
487
|
if (cppStructNameOf(value) === null)
|
|
473
|
-
valueHeldStructNames(value, into, seen);
|
|
488
|
+
valueHeldStructNames(value, into, seen, probed);
|
|
474
489
|
}
|
|
475
490
|
return;
|
|
476
491
|
}
|
|
@@ -481,7 +496,7 @@ const valueHeldStructNames = (representation, into, seen) => {
|
|
|
481
496
|
}
|
|
482
497
|
const descend = (value) => {
|
|
483
498
|
if (isRepresentationNode(value)) {
|
|
484
|
-
valueHeldStructNames(value, into, seen);
|
|
499
|
+
valueHeldStructNames(value, into, seen, probed);
|
|
485
500
|
return;
|
|
486
501
|
}
|
|
487
502
|
if (Array.isArray(value)) {
|
|
@@ -501,14 +516,20 @@ const valueHeldStructNames = (representation, into, seen) => {
|
|
|
501
516
|
for (const value of Object.values(node))
|
|
502
517
|
descend(value);
|
|
503
518
|
};
|
|
504
|
-
/**
|
|
505
|
-
const
|
|
519
|
+
/** The element `RefTargetIsLeaf` judges a `Ref` to this container by, or `null` when it judges the container without one. */
|
|
520
|
+
const traceProbedElementOf = (representation) => {
|
|
521
|
+
if (representation.kind === 'array-object')
|
|
522
|
+
return representation.recursive === undefined ? representation.element : null;
|
|
523
|
+
return null;
|
|
524
|
+
};
|
|
525
|
+
/** Every struct one struct's own storage embeds by value -- or, `probed`, every struct its trace signature needs complete. */
|
|
526
|
+
const structValueDependencies = (layout, probed = false) => {
|
|
506
527
|
const into = new Set();
|
|
507
528
|
const seen = new Set();
|
|
508
529
|
for (const field of layout.fields)
|
|
509
|
-
valueHeldStructNames(field.value, into, seen);
|
|
530
|
+
valueHeldStructNames(field.value, into, seen, probed);
|
|
510
531
|
for (const index of layout.indexes)
|
|
511
|
-
valueHeldStructNames(index.value, into, seen);
|
|
532
|
+
valueHeldStructNames(index.value, into, seen, probed);
|
|
512
533
|
return into;
|
|
513
534
|
};
|
|
514
535
|
/**
|
|
@@ -776,11 +797,34 @@ const immortalMethodStateRoots = (classStructNames, baseStructNames, links, eval
|
|
|
776
797
|
* name the incomplete type rather than this walk running forever. That is
|
|
777
798
|
* exactly what the previous name sort did for every struct, so a cycle is no
|
|
778
799
|
* worse than before and everything else is now right.
|
|
779
|
-
|
|
780
|
-
|
|
800
|
+
*
|
|
801
|
+
* `traceDependencies` are the structs only a definition's trace signature
|
|
802
|
+
* needs complete (`valueHeldStructNames`' `probed` walk). They are placed
|
|
803
|
+
* after the hard ones, and only where placing one cannot break a hard one: a
|
|
804
|
+
* trace dependency whose own base/by-value closure reaches back into the chain
|
|
805
|
+
* is skipped, because emitting it first would emit a struct before something
|
|
806
|
+
* it embeds -- trading a certain error for a possible one.
|
|
807
|
+
*/
|
|
808
|
+
const definitionOrder = (structNames, bases, valueDependencies, traceDependencies) => {
|
|
781
809
|
const ordered = [];
|
|
782
810
|
const emitted = new Set();
|
|
783
811
|
const placeable = new Set(structNames);
|
|
812
|
+
const hardClosureMeetsChain = (from, chain) => {
|
|
813
|
+
const walked = new Set();
|
|
814
|
+
const pending = [from];
|
|
815
|
+
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
|
|
816
|
+
if (chain.has(next))
|
|
817
|
+
return true;
|
|
818
|
+
if (walked.has(next) || emitted.has(next) || !placeable.has(next))
|
|
819
|
+
continue;
|
|
820
|
+
walked.add(next);
|
|
821
|
+
const base = bases.get(next);
|
|
822
|
+
if (base)
|
|
823
|
+
pending.push(base.structName);
|
|
824
|
+
pending.push(...(valueDependencies.get(next) ?? []));
|
|
825
|
+
}
|
|
826
|
+
return false;
|
|
827
|
+
};
|
|
784
828
|
const visit = (structName, chain) => {
|
|
785
829
|
if (emitted.has(structName) || chain.has(structName))
|
|
786
830
|
return;
|
|
@@ -794,6 +838,10 @@ const definitionOrder = (structNames, bases, valueDependencies) => {
|
|
|
794
838
|
if (placeable.has(dependency))
|
|
795
839
|
visit(dependency, deeper);
|
|
796
840
|
}
|
|
841
|
+
for (const dependency of traceDependencies.get(structName) ?? []) {
|
|
842
|
+
if (placeable.has(dependency) && !hardClosureMeetsChain(dependency, deeper))
|
|
843
|
+
visit(dependency, deeper);
|
|
844
|
+
}
|
|
797
845
|
if (emitted.has(structName))
|
|
798
846
|
return;
|
|
799
847
|
emitted.add(structName);
|
|
@@ -3558,8 +3606,12 @@ conversionSite) => {
|
|
|
3558
3606
|
// deterministic where nothing constrains it.
|
|
3559
3607
|
const forwardDeclarations = structNames.map((structName) => `struct ${structName};`);
|
|
3560
3608
|
const valueDependencies = new Map();
|
|
3561
|
-
|
|
3562
|
-
|
|
3609
|
+
const traceDependencies = new Map();
|
|
3610
|
+
for (const [structName, layout] of fieldsByStruct) {
|
|
3611
|
+
const held = structValueDependencies(layout);
|
|
3612
|
+
valueDependencies.set(structName, held);
|
|
3613
|
+
traceDependencies.set(structName, new Set([...structValueDependencies(layout, true)].filter((name) => !held.has(name))));
|
|
3614
|
+
}
|
|
3563
3615
|
const fieldDefinitionsByStruct = new Map();
|
|
3564
3616
|
const dynamicProtocolByStruct = new Map();
|
|
3565
3617
|
const fieldOperationsByStruct = new Map();
|
|
@@ -3605,7 +3657,7 @@ conversionSite) => {
|
|
|
3605
3657
|
}
|
|
3606
3658
|
const virtualDeclarations = new Map();
|
|
3607
3659
|
const layouts = recordLayoutPolicyOf(deriver, classes, wellKnownSymbols, accessorAbiOf);
|
|
3608
|
-
const ordered = definitionOrder(structNames, links, valueDependencies);
|
|
3660
|
+
const ordered = definitionOrder(structNames, links, valueDependencies, traceDependencies);
|
|
3609
3661
|
const evaluatedOnce = (structName) => {
|
|
3610
3662
|
const declaration = declarationByStruct.get(structName);
|
|
3611
3663
|
return declaration !== undefined && singleEvaluationClasses.has(declaration);
|
|
@@ -3706,7 +3758,7 @@ conversionSite) => {
|
|
|
3706
3758
|
// nominal target a caught value asserted `as Error` projects to
|
|
3707
3759
|
// (`unboxValue<Ref<gea::runtime::Error>>`), so the link is as authenticated
|
|
3708
3760
|
// as a program base's.
|
|
3709
|
-
const runtimeClassBases =
|
|
3761
|
+
const runtimeClassBases = ordered.flatMap((structName) => {
|
|
3710
3762
|
const link = links.get(structName);
|
|
3711
3763
|
if (!classStructNames.has(structName) || !link)
|
|
3712
3764
|
return [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/compiler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"description": "The geastack TypeScript-to-C++ compiler: one semantic spine, no source-shaped authority, no boxing of statically typed values.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|