@geastack/compiler 1.0.31 → 1.0.32

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.
@@ -6478,6 +6478,16 @@ struct NativeCallReceiver {
6478
6478
  receiver.boxObject = &boxTypedObject<T>;
6479
6479
  return receiver;
6480
6480
  }
6481
+ /** An object receiver whose boxer the holder recorded earlier, so naming it here instantiates nothing. */
6482
+ static NativeCallReceiver erasedObject(Ref<void> held, Value (*box)(const Ref<void>&)) {
6483
+ if (held.isUndefined()) return undefined();
6484
+ if (!held) return null();
6485
+ NativeCallReceiver receiver;
6486
+ receiver.kind = Kind::Object;
6487
+ receiver.held = std::move(held);
6488
+ receiver.boxObject = box;
6489
+ return receiver;
6490
+ }
6481
6491
  template <typename T>
6482
6492
  static Value boxTypedObject(const Ref<void>&);
6483
6493
  template <typename T>
@@ -8941,6 +8951,15 @@ struct ArrayObject {
8941
8951
  bool lengthWritable = true;
8942
8952
  Ref<NativeArrayViewSource<Element>> liveSource;
8943
8953
  Ref<DynamicObject> indexedDescriptors;
8954
+ /**
8955
+ * How an index accessor's `this` boxes this array, recorded by the only
8956
+ * paths that create `indexedDescriptors` -- every one of them already
8957
+ * dynamic. Named statically from the element read instead, it made a plain
8958
+ * `arr[i]` on any typed array instantiate that array's whole boxed protocol
8959
+ * (`boxTypedObject` -> `Value::box` -> `valueMetadataFor`) for a branch
8960
+ * that only runs once something defined an index descriptor.
8961
+ */
8962
+ Value (*indexedReceiverBox)(const Ref<void>&) = nullptr;
8944
8963
  const void* elementPolicy = nullptr;
8945
8964
  const NativeArrayElementPolicyOps<Element>* elementProtocol = nullptr;
8946
8965
  Value (*elementObserver)(const Element&) = nullptr;
@@ -8957,6 +8976,15 @@ struct ArrayObject {
8957
8976
  if (liveSource) return liveSource->receiver();
8958
8977
  return NativeCallReceiver::object(Ref<ArrayObject<Element>>::adopt(const_cast<ArrayObject<Element>*>(this), true));
8959
8978
  }
8979
+ NativeCallReceiver indexedReceiver() const {
8980
+ return NativeCallReceiver::erasedObject(
8981
+ Ref<void>(Ref<ArrayObject<Element>>::adopt(const_cast<ArrayObject<Element>*>(this), true)), indexedReceiverBox);
8982
+ }
8983
+ void createIndexedDescriptors() {
8984
+ if (indexedDescriptors) return;
8985
+ indexedDescriptors = makeRef<DynamicObject>();
8986
+ indexedReceiverBox = &NativeCallReceiver::template boxTypedObject<ArrayObject<Element>>;
8987
+ }
8960
8988
  void requireOrdinaryStorage() const {
8961
8989
  if (liveSource || indexedDescriptors) bigint_detail::fail("TypeError", "direct array cells require ordinary storage");
8962
8990
  }
@@ -18407,6 +18435,20 @@ struct ValueMetadata {
18407
18435
  };
18408
18436
  inline constexpr ValueMetadata emptyValueMetadata{nullptr, nullptr, nullptr, nullptr, nullptr, -1, false, false, false, false, nullptr, nullptr, nullptr, nullptr};
18409
18437
 
18438
+ /**
18439
+ * Whether a boxed `Ref<T>` carries no dynamic protocol: no document table and
18440
+ * no array table. The compiler decides it per program type from the
18441
+ * whole-program reflection census (`translation-unit.ts`) and states it as an
18442
+ * explicit specialization ahead of every struct body; the default keeps both
18443
+ * tables, which is the answer for every runtime type and for an incomplete
18444
+ * census. A type the census proves no dynamic code reads into still reaches a
18445
+ * box -- a typed listener adapted to a `gea::Value` signature boxes its
18446
+ * arguments only to unbox them -- and building both tables for every such
18447
+ * type, read or not, was most of gea-raw's binary growth since 1.0.16.
18448
+ */
18449
+ template <typename T>
18450
+ inline constexpr bool dynamicProtocolOmitted = false;
18451
+
18410
18452
  template <typename T, int RestFrom = -1, bool ActualArguments = false>
18411
18453
  const ValueMetadata* valueMetadataFor() {
18412
18454
  static const ValueMetadata metadata = [] {
@@ -18416,7 +18458,15 @@ const ValueMetadata* valueMetadataFor() {
18416
18458
  Ref<void> (*anchor)(const void*) = nullptr;
18417
18459
  bool (*viewValue)(const void*, Value&) = nullptr;
18418
18460
  const NativeDocumentOps* document = nullptr;
18419
- if constexpr (IsRefPayload<T>::value) document = nativeDocumentOpsFor<typename T::element_type>();
18461
+ const NativeArrayOps* elements = nullptr;
18462
+ if constexpr (IsRefPayload<T>::value) {
18463
+ if constexpr (!dynamicProtocolOmitted<typename T::element_type>) {
18464
+ document = nativeDocumentOpsFor<typename T::element_type>();
18465
+ elements = nativeArrayOpsFor<T>();
18466
+ }
18467
+ } else {
18468
+ elements = nativeArrayOpsFor<T>();
18469
+ }
18420
18470
  if constexpr (IsRefPayload<T>::value && requires(const T& value) { value->viewAnchor(); }) {
18421
18471
  anchor = +[](const void* payload) -> Ref<void> {
18422
18472
  const T& value = *static_cast<const T*>(payload);
@@ -18429,7 +18479,7 @@ const ValueMetadata* valueMetadataFor() {
18429
18479
  };
18430
18480
  }
18431
18481
  return ValueMetadata{nativeFieldOpsFor<T>(), nativePrototypeOpsFor<T>(), calls,
18432
- nativeArrayOpsFor<T>(), payloadTypeTagFor<T>(), RestFrom, ActualArguments,
18482
+ elements, payloadTypeTagFor<T>(), RestFrom, ActualArguments,
18433
18483
  IsArrayPayload<T>::value, IsMapPayload<T>::value, IsNativeErrorRefPayload<T>::value,
18434
18484
  nativeConstructFor<T>(), anchor, viewValue, document};
18435
18485
  }();
@@ -24817,8 +24867,12 @@ struct DynamicCallSignature<CallableObject<Result(Arguments...)>> {
24817
24867
  }
24818
24868
 
24819
24869
  static Value callWithReceiver(const void* payload, const Value& receiver, const Value* arguments, std::size_t count) {
24820
- return invokeWithReceiver(*static_cast<const CallableObject<Result(Arguments...)>*>(payload), receiver, arguments, count,
24821
- std::index_sequence_for<Arguments...>{});
24870
+ // The native-receiver frame decodes the same arguments the same way; a
24871
+ // second decoder per signature was only code.
24872
+ if constexpr (supported) return callWithNativeReceiver(payload, NativeCallReceiver::fromValue(receiver), arguments, count, false);
24873
+ else
24874
+ return invokeWithReceiver(*static_cast<const CallableObject<Result(Arguments...)>*>(payload), receiver, arguments, count,
24875
+ std::index_sequence_for<Arguments...>{});
24822
24876
  }
24823
24877
 
24824
24878
  private:
@@ -24879,7 +24933,11 @@ struct DynamicCallSignature<CallableConstructorObject<Result(Arguments...), Cons
24879
24933
  }
24880
24934
 
24881
24935
  static Value callWithReceiver(const void* payload, const Value& receiver, const Value* arguments, std::size_t count) {
24882
- return invokeWithReceiver(*static_cast<const CallableConstructorObject<Result(Arguments...), Constructed(ConstructArguments...)>*>(payload), receiver, arguments, count,
24936
+ // The native-receiver frame decodes the same arguments the same way; a
24937
+ // second decoder per signature was only code.
24938
+ if constexpr (supported) return callWithNativeReceiver(payload, NativeCallReceiver::fromValue(receiver), arguments, count, false);
24939
+ else
24940
+ return invokeWithReceiver(*static_cast<const CallableConstructorObject<Result(Arguments...), Constructed(ConstructArguments...)>*>(payload), receiver, arguments, count,
24883
24941
  std::index_sequence_for<Arguments...>{});
24884
24942
  }
24885
24943
 
@@ -25098,7 +25156,11 @@ struct DynamicRestCallSignature<CallableObject<Result(Arguments...)>, RestFrom,
25098
25156
  }
25099
25157
 
25100
25158
  static Value callWithReceiver(const void* payload, const Value& receiver, const Value* arguments, std::size_t count) {
25101
- return invokeWithReceiver(*static_cast<const CallableObject<Result(Arguments...)>*>(payload), receiver, arguments, count,
25159
+ // The native-receiver frame decodes the same arguments the same way; a
25160
+ // second decoder per signature was only code.
25161
+ if constexpr (supported) return callWithNativeReceiver(payload, NativeCallReceiver::fromValue(receiver), arguments, count, false);
25162
+ else
25163
+ return invokeWithReceiver(*static_cast<const CallableObject<Result(Arguments...)>*>(payload), receiver, arguments, count,
25102
25164
  std::make_index_sequence<RestFrom>{});
25103
25165
  }
25104
25166
 
@@ -25170,7 +25232,11 @@ struct DynamicRestCallSignature<CallableConstructorObject<Result(Arguments...),
25170
25232
  }
25171
25233
 
25172
25234
  static Value callWithReceiver(const void* payload, const Value& receiver, const Value* arguments, std::size_t count) {
25173
- return invokeWithReceiver(*static_cast<const Callable*>(payload), receiver, arguments, count,
25235
+ // The native-receiver frame decodes the same arguments the same way; a
25236
+ // second decoder per signature was only code.
25237
+ if constexpr (supported) return callWithNativeReceiver(payload, NativeCallReceiver::fromValue(receiver), arguments, count, false);
25238
+ else
25239
+ return invokeWithReceiver(*static_cast<const Callable*>(payload), receiver, arguments, count,
25174
25240
  std::make_index_sequence<RestFrom>{});
25175
25241
  }
25176
25242
 
@@ -25356,16 +25422,17 @@ struct NativeLayoutInfo {
25356
25422
  // Each field's presence flag and attributes as offsets into the object, so
25357
25423
  // a scan is a loop over two byte arrays rather than a call per field down
25358
25424
  // the visitor chain (which `-Os` leaves out of line: a 250-field options
25359
- // record paid 250 calls per scan). `scannable` is false when a PRESENCE flag
25360
- // lives outside the object, and every scan then walks the visitor. An
25361
- // attribute triple outside the object is a `static` member (records.ts
25362
- // makes them program-constant for a struct nothing can freeze or redefine):
25363
- // its offset is `outsideObject` and its address is kept in `attributeAddresses`.
25425
+ // record paid 250 calls per scan). A presence flag or attribute triple
25426
+ // outside the object is a `static` member (records.ts makes them
25427
+ // program-constant for a field that is always present, or a struct nothing
25428
+ // can freeze or redefine): its offset is `outsideObject` and its address is
25429
+ // kept beside it. Every layout is therefore scannable, and no scan has to be
25430
+ // instantiated a second time down each type's own visitor chain.
25364
25431
  static constexpr std::uint32_t outsideObject = ~std::uint32_t{0};
25365
25432
  std::vector<std::uint32_t> presence;
25433
+ std::vector<const bool*> presenceAddresses;
25366
25434
  std::vector<std::uint32_t> attributes;
25367
25435
  std::vector<const NativeIndexAttributes*> attributeAddresses;
25368
- bool scannable = false;
25369
25436
  // The flags sit side by side in layout order (records.ts declares them in
25370
25437
  // one run), so a scan reads them eight at a time and visits only the set
25371
25438
  // ones: a wide options record holds a handful of its ~140 fields, and a
@@ -25377,6 +25444,15 @@ struct NativeLayoutInfo {
25377
25444
  // were most of a spread's presence walk).
25378
25445
  bool plainEnumerable = false;
25379
25446
 
25447
+ const bool& presentAt(const char* base, std::size_t position) const {
25448
+ const std::uint32_t at = presence[position];
25449
+ return at == outsideObject ? *presenceAddresses[position] : *reinterpret_cast<const bool*>(base + at);
25450
+ }
25451
+ const NativeIndexAttributes& attributesAt(const char* base, std::size_t position) const {
25452
+ const std::uint32_t at = attributes[position];
25453
+ return at == outsideObject ? *attributeAddresses[position] : *reinterpret_cast<const NativeIndexAttributes*>(base + at);
25454
+ }
25455
+
25380
25456
  void index() {
25381
25457
  std::size_t size = 16;
25382
25458
  while (size < names.size() * 2) size *= 2;
@@ -25398,6 +25474,37 @@ struct NativeLayoutInfo {
25398
25474
  }
25399
25475
  };
25400
25476
 
25477
+ // Out of line and shared by every layout: each type's own walk then costs one
25478
+ // call per declared field instead of six inlined vector appends per field.
25479
+ [[gnu::noinline]] inline void recordLayoutField(NativeLayoutInfo& built, const char* base, std::size_t size, std::string_view name,
25480
+ const bool* present, const NativeIndexAttributes* attributes) {
25481
+ const auto offsetWithin = [&](const void* member) {
25482
+ const char* at = static_cast<const char*>(member);
25483
+ return at >= base && at < base + size ? static_cast<std::uint32_t>(at - base) : NativeLayoutInfo::outsideObject;
25484
+ };
25485
+ built.names.push_back(name);
25486
+ const std::uint32_t presence = offsetWithin(present);
25487
+ built.presence.push_back(presence);
25488
+ built.presenceAddresses.push_back(presence == NativeLayoutInfo::outsideObject ? present : nullptr);
25489
+ const std::uint32_t attribute = offsetWithin(attributes);
25490
+ built.attributes.push_back(attribute);
25491
+ built.attributeAddresses.push_back(attribute == NativeLayoutInfo::outsideObject ? attributes : nullptr);
25492
+ }
25493
+
25494
+ [[gnu::noinline]] inline void finishLayout(NativeLayoutInfo& built) {
25495
+ built.presenceContiguous = !built.presence.empty() && built.presence[0] != NativeLayoutInfo::outsideObject;
25496
+ for (std::size_t position = 1; built.presenceContiguous && position < built.presence.size(); ++position)
25497
+ if (built.presence[position] != built.presence[0] + position) built.presenceContiguous = false;
25498
+ built.plainEnumerable = true;
25499
+ for (std::size_t position = 0; built.plainEnumerable && position < built.names.size(); ++position) {
25500
+ const std::string_view name = built.names[position];
25501
+ if (built.attributes[position] != NativeLayoutInfo::outsideObject || !built.attributeAddresses[position]->enumerable ||
25502
+ (!name.empty() && name[0] >= '0' && name[0] <= '9'))
25503
+ built.plainEnumerable = false;
25504
+ }
25505
+ built.index();
25506
+ }
25507
+
25401
25508
  template <typename T>
25402
25509
  const NativeLayoutInfo& nativeLayoutInfoOf(const T& self) {
25403
25510
  // The visitor sees every declared field whatever its presence, so any
@@ -25405,38 +25512,11 @@ const NativeLayoutInfo& nativeLayoutInfoOf(const T& self) {
25405
25512
  static const NativeLayoutInfo info = [&] {
25406
25513
  NativeLayoutInfo built;
25407
25514
  const char* base = reinterpret_cast<const char*>(std::addressof(self));
25408
- const auto within = [&](const void* member) {
25409
- const char* at = static_cast<const char*>(member);
25410
- return at >= base && at < base + sizeof(T);
25411
- };
25412
- built.scannable = true;
25413
25515
  T::gea_eachOwnField(self, [&](std::string_view name, const bool& present, const NativeIndexAttributes& attributes) {
25414
- built.names.push_back(name);
25415
- if (within(std::addressof(present))) {
25416
- built.presence.push_back(static_cast<std::uint32_t>(reinterpret_cast<const char*>(std::addressof(present)) - base));
25417
- if (within(std::addressof(attributes))) {
25418
- built.attributes.push_back(static_cast<std::uint32_t>(reinterpret_cast<const char*>(std::addressof(attributes)) - base));
25419
- built.attributeAddresses.push_back(nullptr);
25420
- } else {
25421
- built.attributes.push_back(NativeLayoutInfo::outsideObject);
25422
- built.attributeAddresses.push_back(std::addressof(attributes));
25423
- }
25424
- } else {
25425
- built.scannable = false;
25426
- }
25516
+ recordLayoutField(built, base, sizeof(T), name, std::addressof(present), std::addressof(attributes));
25427
25517
  return false;
25428
25518
  });
25429
- built.presenceContiguous = built.scannable && !built.presence.empty();
25430
- for (std::size_t position = 1; built.presenceContiguous && position < built.presence.size(); ++position)
25431
- if (built.presence[position] != built.presence[0] + position) built.presenceContiguous = false;
25432
- built.plainEnumerable = built.scannable;
25433
- for (std::size_t position = 0; built.plainEnumerable && position < built.names.size(); ++position) {
25434
- const std::string_view name = built.names[position];
25435
- if (built.attributes[position] != NativeLayoutInfo::outsideObject || !built.attributeAddresses[position]->enumerable ||
25436
- (!name.empty() && name[0] >= '0' && name[0] <= '9'))
25437
- built.plainEnumerable = false;
25438
- }
25439
- built.index();
25519
+ finishLayout(built);
25440
25520
  return built;
25441
25521
  }();
25442
25522
  return info;
@@ -25444,89 +25524,77 @@ const NativeLayoutInfo& nativeLayoutInfoOf(const T& self) {
25444
25524
 
25445
25525
  /**
25446
25526
  * `visit(position, name, present, attributes)` for each PRESENT declared
25447
- * field of `self` in layout order, until it answers true (which this
25448
- * returns): eight flags at a time when they are contiguous, else over the
25449
- * layout's offset tables, else down the visitor. `present` is always true; it
25450
- * stays in the signature so a visitor reads like one over every field.
25527
+ * field of the object at `base` in layout order, until it answers true (which
25528
+ * this returns): eight flags at a time when they are contiguous, else over the
25529
+ * layout's offset tables. `present` is always true; it stays in the signature
25530
+ * so a visitor reads like one over every field.
25451
25531
  */
25452
- template <typename T, typename Visit>
25453
- bool eachNativeDeclaredField(const T& self, Visit&& visit) {
25454
- const NativeLayoutInfo& layout = nativeLayoutInfoOf(self);
25455
- if (layout.scannable) {
25456
- const char* base = reinterpret_cast<const char*>(std::addressof(self));
25457
- const std::size_t count = layout.names.size();
25458
- const auto visitAt = [&](std::size_t position) {
25459
- const bool& present = *reinterpret_cast<const bool*>(base + layout.presence[position]);
25460
- const std::uint32_t attributesAt = layout.attributes[position];
25461
- const NativeIndexAttributes& attributes = attributesAt == NativeLayoutInfo::outsideObject
25462
- ? *layout.attributeAddresses[position]
25463
- : *reinterpret_cast<const NativeIndexAttributes*>(base + attributesAt);
25464
- return visit(position, layout.names[position], present, attributes);
25465
- };
25466
- if (layout.presenceContiguous) {
25467
- const char* flags = base + layout.presence[0];
25468
- for (std::size_t word = 0; word < count; word += 8) {
25469
- // A variable-length memcpy is a call into libc (memcpy@plt) per eight
25470
- // flags, ~17 per walk of a 134-field options record; the fixed-size
25471
- // loads below compile to one mov each. The short tail re-reads the last
25472
- // eight flags and shifts the already-visited ones out.
25473
- std::uint64_t bits = 0;
25474
- if (word + 8 <= count) {
25475
- std::memcpy(&bits, flags + word, 8);
25476
- } else if (count >= 8) {
25477
- std::memcpy(&bits, flags + count - 8, 8);
25478
- bits >>= (8 - (count - word)) * 8;
25479
- } else {
25480
- for (std::size_t at = 0; at < count; ++at) bits |= std::uint64_t{static_cast<unsigned char>(flags[at])} << (at * 8);
25481
- }
25482
- while (bits != 0) {
25483
- const unsigned byte = static_cast<unsigned>(__builtin_ctzll(bits)) >> 3;
25484
- bits &= ~(std::uint64_t{0xff} << (byte * 8));
25485
- if (visitAt(word + byte)) return true;
25486
- }
25532
+ template <typename Visit>
25533
+ bool eachDeclaredFieldIn(const NativeLayoutInfo& layout, const char* base, Visit&& visit) {
25534
+ const std::size_t count = layout.names.size();
25535
+ const auto visitAt = [&](std::size_t position) {
25536
+ return visit(position, layout.names[position], layout.presentAt(base, position), layout.attributesAt(base, position));
25537
+ };
25538
+ if (layout.presenceContiguous) {
25539
+ const char* flags = base + layout.presence[0];
25540
+ for (std::size_t word = 0; word < count; word += 8) {
25541
+ // A variable-length memcpy is a call into libc (memcpy@plt) per eight
25542
+ // flags, ~17 per walk of a 134-field options record; the fixed-size
25543
+ // loads below compile to one mov each. The short tail re-reads the last
25544
+ // eight flags and shifts the already-visited ones out.
25545
+ std::uint64_t bits = 0;
25546
+ if (word + 8 <= count) {
25547
+ std::memcpy(&bits, flags + word, 8);
25548
+ } else if (count >= 8) {
25549
+ std::memcpy(&bits, flags + count - 8, 8);
25550
+ bits >>= (8 - (count - word)) * 8;
25551
+ } else {
25552
+ for (std::size_t at = 0; at < count; ++at) bits |= std::uint64_t{static_cast<unsigned char>(flags[at])} << (at * 8);
25553
+ }
25554
+ while (bits != 0) {
25555
+ const unsigned byte = static_cast<unsigned>(__builtin_ctzll(bits)) >> 3;
25556
+ bits &= ~(std::uint64_t{0xff} << (byte * 8));
25557
+ if (visitAt(word + byte)) return true;
25487
25558
  }
25488
- return false;
25489
25559
  }
25490
- for (std::size_t position = 0; position < count; ++position)
25491
- if (*reinterpret_cast<const bool*>(base + layout.presence[position]) && visitAt(position)) return true;
25492
25560
  return false;
25493
25561
  }
25494
- std::size_t position = 0;
25495
- return T::gea_eachOwnField(self, [&](std::string_view name, const bool& present, const NativeIndexAttributes& attributes) {
25496
- const std::size_t at = position++;
25497
- return present && visit(at, name, present, attributes);
25498
- });
25562
+ for (std::size_t position = 0; position < count; ++position)
25563
+ if (layout.presentAt(base, position) && visitAt(position)) return true;
25564
+ return false;
25499
25565
  }
25500
25566
 
25501
- /** Whether any declared field of `self` after layout position `at` is present. */
25502
- template <typename T>
25503
- bool nativeDeclaredFieldPresentAfter(const T& self, std::size_t at) {
25504
- const NativeLayoutInfo& layout = nativeLayoutInfoOf(self);
25505
- if (layout.scannable) {
25506
- const char* base = reinterpret_cast<const char*>(std::addressof(self));
25507
- const std::size_t count = layout.names.size();
25508
- if (layout.presenceContiguous) {
25509
- // The flags after `at` are one run of bytes: eight at a time, and a
25510
- // wide options record's early field (a late store of `session` on a
25511
- // 134-field layout) tests ~16 words rather than ~130 bytes.
25512
- const char* flags = base + layout.presence[0];
25513
- std::size_t position = at + 1;
25514
- for (; position + 8 <= count; position += 8) {
25515
- std::uint64_t bits = 0;
25516
- std::memcpy(&bits, flags + position, 8);
25517
- if (bits != 0) return true;
25518
- }
25519
- for (; position < count; ++position)
25520
- if (flags[position] != 0) return true;
25521
- return false;
25522
- }
25523
- for (std::size_t position = at + 1; position < count; ++position)
25524
- if (*reinterpret_cast<const bool*>(base + layout.presence[position])) return true;
25567
+ template <typename T, typename Visit>
25568
+ bool eachNativeDeclaredField(const T& self, Visit&& visit) {
25569
+ return eachDeclaredFieldIn(nativeLayoutInfoOf(self), reinterpret_cast<const char*>(std::addressof(self)), std::forward<Visit>(visit));
25570
+ }
25571
+
25572
+ /** Whether any declared field of the object at `base` after layout position `at` is present. */
25573
+ inline bool declaredFieldPresentAfter(const NativeLayoutInfo& layout, const char* base, std::size_t at) {
25574
+ const std::size_t count = layout.names.size();
25575
+ if (layout.presenceContiguous) {
25576
+ // The flags after `at` are one run of bytes: eight at a time, and a
25577
+ // wide options record's early field (a late store of `session` on a
25578
+ // 134-field layout) tests ~16 words rather than ~130 bytes.
25579
+ const char* flags = base + layout.presence[0];
25580
+ std::size_t position = at + 1;
25581
+ for (; position + 8 <= count; position += 8) {
25582
+ std::uint64_t bits = 0;
25583
+ std::memcpy(&bits, flags + position, 8);
25584
+ if (bits != 0) return true;
25585
+ }
25586
+ for (; position < count; ++position)
25587
+ if (flags[position] != 0) return true;
25525
25588
  return false;
25526
25589
  }
25527
- return eachNativeDeclaredField(self, [&](std::size_t position, std::string_view, const bool& present, const NativeIndexAttributes&) {
25528
- return position > at && present;
25529
- });
25590
+ for (std::size_t position = at + 1; position < count; ++position)
25591
+ if (layout.presentAt(base, position)) return true;
25592
+ return false;
25593
+ }
25594
+
25595
+ template <typename T>
25596
+ bool nativeDeclaredFieldPresentAfter(const T& self, std::size_t at) {
25597
+ return declaredFieldPresentAfter(nativeLayoutInfoOf(self), reinterpret_cast<const char*>(std::addressof(self)), at);
25530
25598
  }
25531
25599
 
25532
25600
  /**
@@ -26498,15 +26566,20 @@ void pendNativeKeyOrder(const gea::Ref<T>& self, const std::string_view* keys, s
26498
26566
  * last note, each by position: no name is hashed or copied. `skip` (the key
26499
26567
  * about to be created) is left for its creation to place.
26500
26568
  */
26501
- template <typename T>
26502
- void learnDeclaredFieldsSinceLastNoteExcept(NativeOwnKeyOrder& order, const T& self, std::size_t skip) {
26503
- order.useDeclaredLayout(&nativeLayoutInfoOf(self));
26504
- eachNativeDeclaredField(self, [&](std::size_t index, std::string_view, const bool& isPresent, const NativeIndexAttributes&) {
26569
+ inline void learnDeclaredFieldsSinceLastNoteExcept(NativeOwnKeyOrder& order, const NativeLayoutInfo& layout, const char* base,
26570
+ std::size_t skip) {
26571
+ order.useDeclaredLayout(&layout);
26572
+ eachDeclaredFieldIn(layout, base, [&](std::size_t index, std::string_view, const bool& isPresent, const NativeIndexAttributes&) {
26505
26573
  if (isPresent && index != skip && !order.isDeclaredLearned(index)) order.learnDeclared(index);
26506
26574
  return false;
26507
26575
  });
26508
26576
  }
26509
26577
 
26578
+ template <typename T>
26579
+ void learnDeclaredFieldsSinceLastNoteExcept(NativeOwnKeyOrder& order, const T& self, std::size_t skip) {
26580
+ learnDeclaredFieldsSinceLastNoteExcept(order, nativeLayoutInfoOf(self), reinterpret_cast<const char*>(std::addressof(self)), skip);
26581
+ }
26582
+
26510
26583
  template <typename T>
26511
26584
  void learnDeclaredFieldsSinceLastNote(NativeOwnKeyOrder& order, const T& self, const PropertyKey* skip) {
26512
26585
  const std::size_t position =
@@ -26852,42 +26925,53 @@ bool nativeDeclaredKeyViewsInOrder(const T& self, NativeOwnKeyOrder& order, std:
26852
26925
  return true;
26853
26926
  }
26854
26927
 
26928
+ // Shared by every layout type: the per-type caller only supplies the layout,
26929
+ // the object's own field-key lister and whether anything decorates it.
26930
+ [[gnu::noinline]] inline void noteLayoutIndexKeyCreated(const gea::Ref<void>& payload, const PropertyKey& key, const NativeLayoutInfo& layout,
26931
+ bool undecorated, KeyLister fieldKeys) {
26932
+ const char* base = static_cast<const char*>(payload.get());
26933
+ const std::size_t skip = key.isSymbol() ? NativeLayoutInfo::npos : layout.position(std::string_view(key.text()));
26934
+ // An existing log holds every earlier noted key; only the declared fields
26935
+ // stored silently since the last note are missing from it.
26936
+ if (payload && (refCountsOf(payload.get())->weak & expandoTagged) != 0) {
26937
+ if (NativeOwnKeyOrder* existing = findNativeOwnKeyOrder(payload.get())) {
26938
+ learnDeclaredFieldsSinceLastNoteExcept(*existing, layout, base, skip);
26939
+ existing->create(key);
26940
+ return;
26941
+ }
26942
+ }
26943
+ // No log, pend or expando yet, and no index entry: the present keys are
26944
+ // exactly the declared fields, learned by view in layout order. Listing
26945
+ // them as `PropertyKey`s first copied every present name of a wide
26946
+ // options record per late store (`options.willRetryWrite = ...`).
26947
+ if (undecorated) {
26948
+ NativeOwnKeyOrder& order = nativeOwnKeyOrderFor(payload);
26949
+ learnDeclaredFieldsSinceLastNoteExcept(order, layout, base, skip);
26950
+ order.create(key);
26951
+ return;
26952
+ }
26953
+ auto declaredKeys = [&](std::vector<PropertyKey>& keys) {
26954
+ eachDeclaredFieldIn(layout, base, [&](std::size_t, std::string_view name, const bool&, const NativeIndexAttributes&) {
26955
+ keys.push_back(PropertyKey::string(std::string(name)));
26956
+ return false;
26957
+ });
26958
+ };
26959
+ noteNativeOwnKeyCreatedErased(payload, key, fieldKeys, KeyLister::of(declaredKeys));
26960
+ }
26961
+
26855
26962
  template <typename T>
26856
26963
  void noteNativeIndexKeyCreated(const T* self, const PropertyKey& key) {
26964
+ const gea::Ref<void> payload = gea::refCastToVoid(gea::Ref<T>::adopt(const_cast<T*>(self), true));
26965
+ auto fieldKeys = [&](std::vector<PropertyKey>& keys) { self->gea_ownFieldKeys(keys); };
26857
26966
  if constexpr (requires { T::gea_eachOwnField(*self, [](std::string_view, const bool&, const NativeIndexAttributes&) { return false; }); }) {
26858
- // An existing log holds every earlier noted key; only the declared fields
26859
- // stored silently since the last note are missing from it.
26860
- if (self != nullptr && (refCountsOf(const_cast<T*>(self))->weak & expandoTagged) != 0) {
26861
- if (NativeOwnKeyOrder* existing = findNativeOwnKeyOrder(self)) {
26862
- learnDeclaredFieldsSinceLastNote(*existing, *self, &key);
26863
- existing->create(key);
26864
- return;
26865
- }
26866
- }
26867
- // No log, pend or expando yet, and no index entry: the present keys are
26868
- // exactly the declared fields, learned by view in layout order. Listing
26869
- // them as `PropertyKey`s first copied every present name of a wide
26870
- // options record per late store (`options.willRetryWrite = ...`).
26871
- bool undecorated = self != nullptr && (refCountsOf(const_cast<T*>(self))->weak & expandoTagged) == 0;
26967
+ if (self == nullptr) return;
26968
+ bool undecorated = (refCountsOf(const_cast<T*>(self))->weak & expandoTagged) == 0;
26872
26969
  if constexpr (requires { self->gea_dynamic.size(); })
26873
26970
  undecorated = undecorated && self->gea_dynamic.size() == 0;
26874
- if (undecorated) {
26875
- NativeOwnKeyOrder& order = nativeOwnKeyOrderFor(gea::refCastToVoid(gea::Ref<T>::adopt(const_cast<T*>(self), true)));
26876
- learnDeclaredFieldsSinceLastNote(order, *self, &key);
26877
- order.create(key);
26878
- return;
26879
- }
26971
+ noteLayoutIndexKeyCreated(payload, key, nativeLayoutInfoOf(*self), undecorated, KeyLister::of(fieldKeys));
26972
+ } else {
26973
+ noteNativeOwnKeyCreatedErased(payload, key, KeyLister::of(fieldKeys));
26880
26974
  }
26881
- noteNativeOwnKeyCreated(
26882
- gea::refCastToVoid(gea::Ref<T>::adopt(const_cast<T*>(self), true)), key,
26883
- [&](std::vector<PropertyKey>& keys) { self->gea_ownFieldKeys(keys); },
26884
- [&](std::vector<PropertyKey>& keys) {
26885
- // The visitor chain stops at the first `true` (a find), so every field is seen by answering `false`.
26886
- T::gea_eachOwnField(*self, [&](std::string_view name, const bool& present, const NativeIndexAttributes&) {
26887
- if (present) keys.push_back(PropertyKey::string(std::string(name)));
26888
- return false;
26889
- });
26890
- });
26891
26975
  }
26892
26976
 
26893
26977
  /**
@@ -26923,16 +27007,15 @@ struct SuppressNativeKeyNotes {
26923
27007
  * Answers false, leaving the pend untouched, when the list cannot hold them.
26924
27008
  * The block is a full `orderPositionCapacity` long whatever `count` says.
26925
27009
  */
26926
- template <typename T>
26927
- bool notePositionalPendKeyCreated(const T& self, InlineKeyOrder& held, std::size_t at) {
27010
+ inline bool notePositionalPendKeyCreated(const NativeLayoutInfo& layout, const char* base, InlineKeyOrder& held, std::size_t at) {
26928
27011
  constexpr std::size_t capacity = orderPositionCapacity;
26929
27012
  for (std::uint32_t index = 0; index < held.count; ++index)
26930
27013
  if (held.positions[index] == at) return true;
26931
- if (!nativeDeclaredFieldPresentAfter(self, at)) return true;
27014
+ if (!declaredFieldPresentAfter(layout, base, at)) return true;
26932
27015
  std::uint32_t silent[capacity];
26933
27016
  std::size_t silentCount = 0;
26934
27017
  bool overflow = false;
26935
- eachNativeDeclaredField(self, [&](std::size_t index, std::string_view, const bool&, const NativeIndexAttributes&) {
27018
+ eachDeclaredFieldIn(layout, base, [&](std::size_t index, std::string_view, const bool&, const NativeIndexAttributes&) {
26936
27019
  if (index == at) return false;
26937
27020
  for (std::uint32_t listed = 0; listed < held.count; ++listed)
26938
27021
  if (held.positions[listed] == index) return false;
@@ -26967,6 +27050,69 @@ inline NativeDeclaredKeyPositionHint (&nativeDeclaredKeyPositionHints())[256] {
26967
27050
  return hints->entries;
26968
27051
  }
26969
27052
 
27053
+ /** What `noteDeclaredKeyCreatedAt` needs of the type it was written for: reached only once a log must be made or reached. */
27054
+ struct DeclaredKeyNoteHooks {
27055
+ NativeOwnKeyOrder& (*orderFor)(const void* self);
27056
+ void (*indexKeyCreated)(const void* self, std::string_view key);
27057
+ };
27058
+
27059
+ /**
27060
+ * `noteNativeDeclaredKeyCreated` for any record type, given its layout, its
27061
+ * counts, its inline order (null when the type has none) and whether it holds
27062
+ * dynamic properties: every record type shares this one body.
27063
+ */
27064
+ [[gnu::noinline]] inline void noteDeclaredKeyCreatedAt(const void* self, std::string_view key, const NativeLayoutInfo& layout,
27065
+ RefCounts* counts, InlineKeyOrder* held, bool undecorated,
27066
+ const DeclaredKeyNoteHooks& hooks) {
27067
+ // The key is a string literal at nearly every call: its address names its position,
27068
+ // verified against the layout (so a reused or torn entry only costs the hash).
27069
+ auto& hints = nativeDeclaredKeyPositionHints();
27070
+ NativeDeclaredKeyPositionHint& hint = hints[(reinterpret_cast<std::uintptr_t>(key.data()) * 0x9E3779B97F4A7C15ull) >> 56];
27071
+ std::size_t at;
27072
+ if (hint.data == key.data() && hint.position < layout.names.size() && layout.names[hint.position] == key) {
27073
+ at = hint.position;
27074
+ } else {
27075
+ at = layout.position(key);
27076
+ if (at == NativeLayoutInfo::npos) return;
27077
+ hint.data = key.data();
27078
+ hint.position = static_cast<std::uint32_t>(at);
27079
+ }
27080
+ const char* base = static_cast<const char*>(self);
27081
+ if (held != nullptr) {
27082
+ // A spread's list of positions takes the key without becoming a log.
27083
+ constexpr std::uint32_t kinds = expandoTagged | keyOrderPending | expandoEntry;
27084
+ if ((counts->weak & kinds) == (expandoTagged | keyOrderPending))
27085
+ if (held->pending && held->positional && notePositionalPendKeyCreated(layout, base, *held, at)) return;
27086
+ }
27087
+ const bool tagged = (counts->weak & expandoTagged) != 0;
27088
+ NativeOwnKeyOrder* order = tagged ? findNativeOwnKeyOrder(self) : nullptr;
27089
+ // An absent field the log already places was placed by the literal that
27090
+ // creates it, after its spread (`later`): a delete erases the place. The
27091
+ // store keeps that place.
27092
+ if (order != nullptr && order->ordinals.layout == &layout && order->isDeclaredLearned(at)) return;
27093
+ if (!declaredFieldPresentAfter(layout, base, at)) return;
27094
+ // `noteNativeIndexKeyCreated`'s two log arms, by position: the created
27095
+ // field takes the next ordinal after every present field the log lacks.
27096
+ // Spelling the key as a `PropertyKey` and hashing it back to its position
27097
+ // cost a wide options record's every late store.
27098
+ if (!tagged && undecorated) order = &hooks.orderFor(self);
27099
+ if (order == nullptr) {
27100
+ hooks.indexKeyCreated(self, key);
27101
+ return;
27102
+ }
27103
+ learnDeclaredFieldsSinceLastNoteExcept(*order, layout, base, at);
27104
+ order->learnDeclared(at);
27105
+ }
27106
+
27107
+ template <typename T>
27108
+ inline constexpr DeclaredKeyNoteHooks declaredKeyNoteHooks{
27109
+ [](const void* self) -> NativeOwnKeyOrder& {
27110
+ return nativeOwnKeyOrderFor(gea::refCastToVoid(gea::Ref<T>::adopt(static_cast<T*>(const_cast<void*>(self)), true)));
27111
+ },
27112
+ [](const void* self, std::string_view key) {
27113
+ noteNativeIndexKeyCreated(static_cast<const T*>(self), PropertyKey::string(std::string(key)));
27114
+ }};
27115
+
26970
27116
  template <typename T>
26971
27117
  void noteNativeDeclaredKeyCreated(const T* self, std::string_view key) {
26972
27118
  GEA_PARALLEL_SIDE_TABLE
@@ -26978,50 +27124,12 @@ void noteNativeDeclaredKeyCreated(const T* self, std::string_view key) {
26978
27124
  #if defined(GEA_MEASURE_SKIP_WIDE_KEY_ORDER)
26979
27125
  if (nativeLayoutInfoOf(*self).names.size() > 100) return;
26980
27126
  #endif
26981
- const NativeLayoutInfo& layout = nativeLayoutInfoOf(*self);
26982
- // The key is a string literal at nearly every call: its address names its position,
26983
- // verified against the layout (so a reused or torn entry only costs the hash).
26984
- auto& hints = nativeDeclaredKeyPositionHints();
26985
- NativeDeclaredKeyPositionHint& hint = hints[(reinterpret_cast<std::uintptr_t>(key.data()) * 0x9E3779B97F4A7C15ull) >> 56];
26986
- std::size_t at;
26987
- if (hint.data == key.data() && hint.position < layout.names.size() && layout.names[hint.position] == key) {
26988
- at = hint.position;
26989
- } else {
26990
- at = layout.position(key);
26991
- if (at == NativeLayoutInfo::npos) return;
26992
- hint.data = key.data();
26993
- hint.position = static_cast<std::uint32_t>(at);
26994
- }
26995
- if constexpr (requires { self->gea_keyOrder; }) {
26996
- // A spread's list of positions takes the key without becoming a log.
26997
- constexpr std::uint32_t kinds = expandoTagged | keyOrderPending | expandoEntry;
26998
- if ((refCountsOf(const_cast<T*>(self))->weak & kinds) == (expandoTagged | keyOrderPending)) {
26999
- InlineKeyOrder& held = const_cast<T*>(self)->gea_keyOrder;
27000
- if (held.pending && held.positional && notePositionalPendKeyCreated(*self, held, at)) return;
27001
- }
27002
- }
27003
- const bool tagged = (refCountsOf(const_cast<T*>(self))->weak & expandoTagged) != 0;
27004
- NativeOwnKeyOrder* order = tagged ? findNativeOwnKeyOrder(self) : nullptr;
27005
- // An absent field the log already places was placed by the literal that
27006
- // creates it, after its spread (`later`): a delete erases the place. The
27007
- // store keeps that place.
27008
- if (order != nullptr && order->ordinals.layout == &layout && order->isDeclaredLearned(at)) return;
27009
- if (!nativeDeclaredFieldPresentAfter(*self, at)) return;
27010
- // `noteNativeIndexKeyCreated`'s two log arms, by position: the created
27011
- // field takes the next ordinal after every present field the log lacks.
27012
- // Spelling the key as a `PropertyKey` and hashing it back to its position
27013
- // cost a wide options record's every late store.
27014
- if (!tagged) {
27015
- bool undecorated = true;
27016
- if constexpr (requires { self->gea_dynamic.size(); }) undecorated = self->gea_dynamic.size() == 0;
27017
- if (undecorated) order = &nativeOwnKeyOrderFor(gea::refCastToVoid(gea::Ref<T>::adopt(const_cast<T*>(self), true)));
27018
- }
27019
- if (order == nullptr) {
27020
- noteNativeIndexKeyCreated(self, PropertyKey::string(std::string(key)));
27021
- return;
27022
- }
27023
- learnDeclaredFieldsSinceLastNoteExcept(*order, *self, at);
27024
- order->learnDeclared(at);
27127
+ InlineKeyOrder* held = nullptr;
27128
+ if constexpr (requires { self->gea_keyOrder; }) held = &const_cast<T*>(self)->gea_keyOrder;
27129
+ bool undecorated = true;
27130
+ if constexpr (requires { self->gea_dynamic.size(); }) undecorated = self->gea_dynamic.size() == 0;
27131
+ noteDeclaredKeyCreatedAt(self, key, nativeLayoutInfoOf(*self), refCountsOf(const_cast<T*>(self)), held, undecorated,
27132
+ declaredKeyNoteHooks<T>);
27025
27133
  }
27026
27134
  }
27027
27135
 
@@ -27568,9 +27676,8 @@ template <typename Element>
27568
27676
  Element readArrayIndexedDescriptor(const ArrayObject<Element>& array, std::size_t index) {
27569
27677
  const auto* descriptor = array.indexedDescriptors->ownProperty(arrayIndexedKey(index));
27570
27678
  if (!descriptor) host::throwRuntimeError("TypeError", "an array descriptor disappeared during its native read");
27571
- const auto receiver = Ref<ArrayObject<Element>>::adopt(const_cast<ArrayObject<Element>*>(&array), true);
27572
27679
  if constexpr (std::is_same_v<Element, Value>) {
27573
- return array.indexedDescriptors->getWithNativeReceiver(arrayIndexedKey(index), NativeCallReceiver::object(receiver));
27680
+ return array.indexedDescriptors->getWithNativeReceiver(arrayIndexedKey(index), array.indexedReceiver());
27574
27681
  } else {
27575
27682
  if (!descriptor->isAccessor()) {
27576
27683
  std::optional<Element> value;
@@ -27598,7 +27705,7 @@ Element readArrayIndexedDescriptor(const ArrayObject<Element>& array, std::size_
27598
27705
  NativeFieldRead read(result);
27599
27706
  if (array.elementPolicy) read.requestedPolicy = array.elementPolicy;
27600
27707
  const auto answered = array.indexedDescriptors->readNativeAccessor(
27601
- arrayIndexedKey(index), NativeCallReceiver::object(receiver), read);
27708
+ arrayIndexedKey(index), array.indexedReceiver(), read);
27602
27709
  if (!answered || !*answered || !result)
27603
27710
  host::throwRuntimeError("TypeError", "an array getter changed its native element carrier");
27604
27711
  return std::move(*result);
@@ -27607,12 +27714,11 @@ Element readArrayIndexedDescriptor(const ArrayObject<Element>& array, std::size_
27607
27714
 
27608
27715
  template <typename Element, typename Policy>
27609
27716
  bool arrayWriteIndexedDescriptor(ArrayObject<Element>& array, std::size_t index, const Element& value) {
27610
- const auto receiver = Ref<ArrayObject<Element>>::adopt(&array, true);
27611
27717
  if constexpr (std::is_same_v<Element, Value>) {
27612
- return array.indexedDescriptors->setWithNativeReceiver(arrayIndexedKey(index), value, NativeCallReceiver::object(receiver));
27718
+ return array.indexedDescriptors->setWithNativeReceiver(arrayIndexedKey(index), value, array.indexedReceiver());
27613
27719
  } else {
27614
27720
  return array.indexedDescriptors->template setNativeDataWithNativeReceiver<Element, Policy>(
27615
- arrayIndexedKey(index), value, nullptr, NativeCallReceiver::object(receiver));
27721
+ arrayIndexedKey(index), value, nullptr, array.indexedReceiver());
27616
27722
  }
27617
27723
  }
27618
27724
  template <typename Element>
@@ -27622,8 +27728,7 @@ bool writeArrayIndexedDescriptor(ArrayObject<Element>& array, std::size_t index,
27622
27728
  }
27623
27729
  template <typename Element>
27624
27730
  bool writeArrayUndefinedDescriptor(ArrayObject<Element>& array, std::size_t index) {
27625
- const auto receiver = Ref<ArrayObject<Element>>::adopt(&array, true);
27626
- return array.indexedDescriptors->setWithNativeReceiver(arrayIndexedKey(index), Value{}, NativeCallReceiver::object(receiver));
27731
+ return array.indexedDescriptors->setWithNativeReceiver(arrayIndexedKey(index), Value{}, array.indexedReceiver());
27627
27732
  }
27628
27733
 
27629
27734
  template <typename Element>
@@ -27665,7 +27770,7 @@ bool ArrayObject<Element>::defineIndex(std::size_t index, const PropertyDescript
27665
27770
  PropertyDescriptor current;
27666
27771
  const bool exists = ownIndexDescriptor(index, current);
27667
27772
  if (!exists && !extensible()) return false;
27668
- if (!indexedDescriptors) indexedDescriptors = makeRef<DynamicObject>();
27773
+ createIndexedDescriptors();
27669
27774
  const PropertyKey key = arrayIndexedKey(index);
27670
27775
  if (indexedDescriptors->ownProperty(key) == nullptr && exists && !indexedDescriptors->defineOwnProperty(key, current)) return false;
27671
27776
  if (!indexedDescriptors->defineOwnProperty(key, descriptor)) return false;
@@ -27722,8 +27827,7 @@ bool arrayReadNativeElement(const ArrayObject<Element>& array, std::size_t index
27722
27827
  return answer.template acceptsExact<Element, Policy>() && answer.template assign<Policy>(array.cells[index].value);
27723
27828
  }
27724
27829
  if (!descriptor->isAccessor()) return descriptor->nativeValue && descriptor->nativeValue.read(answer);
27725
- const auto receiver = Ref<ArrayObject<Element>>::adopt(const_cast<ArrayObject<Element>*>(&array), true);
27726
- const auto handled = array.indexedDescriptors->readNativeAccessor(arrayIndexedKey(index), NativeCallReceiver::object(receiver), answer);
27830
+ const auto handled = array.indexedDescriptors->readNativeAccessor(arrayIndexedKey(index), array.indexedReceiver(), answer);
27727
27831
  return handled && *handled;
27728
27832
  }
27729
27833
  template <typename Element, typename Policy>
@@ -27755,12 +27859,11 @@ bool ArrayObject<Element>::setNativeElement(std::size_t index, const Native& val
27755
27859
  } else {
27756
27860
  PropertyDescriptor current;
27757
27861
  const bool exists = ownIndexDescriptor(index, current);
27758
- if (!indexedDescriptors) indexedDescriptors = makeRef<DynamicObject>();
27862
+ createIndexedDescriptors();
27759
27863
  const PropertyKey key = arrayIndexedKey(index);
27760
27864
  if (exists && indexedDescriptors->ownProperty(key) == nullptr && !indexedDescriptors->defineOwnProperty(key, current)) return false;
27761
- const auto receiver = Ref<ArrayObject<Element>>::adopt(this, true);
27762
27865
  if (!indexedDescriptors->template setNativeDataWithNativeReceiver<Native, Policy>(
27763
- key, value, observe, NativeCallReceiver::object(receiver))) return false;
27866
+ key, value, observe, indexedReceiver())) return false;
27764
27867
  if (index >= cells.size()) {
27765
27868
  openHoles();
27766
27869
  cells.resize(index + 1);
@@ -28801,8 +28904,35 @@ void nativeSpreadObjectDataSet(const gea::Ref<Receiver>& object, std::string_vie
28801
28904
  * attribute set against a fixed-layout member store is a larger feature this
28802
28905
  * call does not need yet, so it is left to a future caller to state.
28803
28906
  */
28907
+ namespace detail {/**
28908
+ * Whether `T`'s document protocol is the shared record one
28909
+ * (`gea_document_view.h`): every native object except the ones with a protocol
28910
+ * of their own -- `DynamicObject`, dictionaries, `ArrayObject`, `Map`.
28911
+ */
28912
+ template <typename T>
28913
+ inline constexpr bool sharedRecordDocument = !std::is_same_v<T, DynamicObject> && !std::is_same_v<T, Dictionary<Value>> &&
28914
+ !IsArrayObjectStruct<T>::value && !IsMapPayload<Ref<T>>::value && !TypedStringDictionaryTable<T>;
28915
+ // The generic own-property templates hand a type to the shared record path only
28916
+ // when its own-field protocol is whole: building the bridge asserts that, and a
28917
+ // partial protocol keeps the templates' own per-hook dispatch.
28918
+ template <typename T>
28919
+ inline constexpr bool sharedRecordDelegation = sharedRecordDocument<T> && nativeOwnFieldProtocolIsWhole<T>;
28920
+ struct NativeRecordDocumentBridge;
28921
+ template <typename T>
28922
+ const NativeRecordDocumentBridge& recordDocumentBridgeOf();
28923
+ inline bool recordOwnDescriptor(const Ref<void>& source, const NativeRecordDocumentBridge& bridge, const PropertyKey& key,
28924
+ PropertyDescriptor& out);
28925
+ inline std::vector<PropertyKey> recordDocumentOwnKeys(const Ref<void>& source, const NativeRecordDocumentBridge& bridge);
28926
+ inline bool recordDynamicDefine(const Ref<void>& source, const NativeRecordDocumentBridge& bridge, const PropertyKey& key,
28927
+ const PropertyDescriptor& descriptor);
28928
+ inline bool recordDocumentDelete(const Ref<void>& source, const NativeRecordDocumentBridge& bridge, const PropertyKey& key);
28929
+ inline bool recordDynamicHas(const Ref<void>& source, const NativeRecordDocumentBridge& bridge, const PropertyKey& key);
28930
+ inline std::vector<PropertyKey> recordEnumerableStringKeys(const Ref<void>& source, const NativeRecordDocumentBridge& bridge);
28931
+ } // namespace detail
28932
+
28804
28933
  template <typename T>
28805
28934
  bool nativeDynamicDefineProperty(const gea::Ref<T>& object, const PropertyKey& key, const PropertyDescriptor& descriptor) {
28935
+ if constexpr (detail::sharedRecordDelegation<T>) return detail::recordDynamicDefine(Ref<void>(object), detail::recordDocumentBridgeOf<T>(), key, descriptor);
28806
28936
  if (!object) return false;
28807
28937
  if (record::immutableDescriptorSnapshotView(Ref<void>(object)))
28808
28938
  host::throwRuntimeError("TypeError", "a native descriptor snapshot definition has no certified source protocol");
@@ -28834,6 +28964,13 @@ bool nativeDynamicDefineProperty(const gea::Ref<T>& object, const PropertyKey& k
28834
28964
 
28835
28965
  template <typename T>
28836
28966
  Optional<PropertyDescriptor> nativeOwnPropertyDescriptor(const gea::Ref<T>& object, const PropertyKey& key) {
28967
+ if constexpr (detail::sharedRecordDelegation<T>) {
28968
+ // The shared record path takes these exact steps once for every type.
28969
+ PropertyDescriptor descriptor;
28970
+ return detail::recordOwnDescriptor(Ref<void>(object), detail::recordDocumentBridgeOf<T>(), key, descriptor)
28971
+ ? Optional<PropertyDescriptor>(descriptor)
28972
+ : Optional<PropertyDescriptor>();
28973
+ }
28837
28974
  if (!object) return Optional<PropertyDescriptor>();
28838
28975
  if constexpr (IsArrayObjectStruct<T>::value) {
28839
28976
  if (!key.isSymbol() && key.text() == "length") {
@@ -28887,6 +29024,7 @@ Optional<PropertyDescriptor> nativeOwnPropertyDescriptor(const gea::Ref<T>& obje
28887
29024
  */
28888
29025
  template <typename T>
28889
29026
  std::vector<PropertyKey> nativeOwnPropertyKeys(const gea::Ref<T>& object) {
29027
+ if constexpr (detail::sharedRecordDelegation<T>) return detail::recordDocumentOwnKeys(Ref<void>(object), detail::recordDocumentBridgeOf<T>());
28890
29028
  std::vector<PropertyKey> keys;
28891
29029
  if (!object) return keys;
28892
29030
  if constexpr (IsArrayObjectStruct<T>::value) {
@@ -29162,6 +29300,7 @@ struct NativeDocumentOwner {
29162
29300
 
29163
29301
  template <typename T>
29164
29302
  const NativeDocumentOps* nativeDocumentOpsFor();
29303
+
29165
29304
  } // namespace detail
29166
29305
 
29167
29306
  namespace json {
@@ -30032,6 +30171,7 @@ inline gea::Ref<void> viewOrigin(const gea::Ref<gea::Dictionary<gea::Value>>& vi
30032
30171
 
30033
30172
  template <typename T>
30034
30173
  bool nativeDynamicHas(const gea::Ref<T>& object, const PropertyKey& key) {
30174
+ if constexpr (detail::sharedRecordDelegation<T>) return detail::recordDynamicHas(Ref<void>(object), detail::recordDocumentBridgeOf<T>(), key);
30035
30175
  if (!object) return false;
30036
30176
  if constexpr (IsArrayObjectStruct<T>::value) {
30037
30177
  if (!key.isSymbol() && key.text() == "length") return true;
@@ -30093,6 +30233,7 @@ bool nativeDynamicHasProperty(const gea::Ref<T>& object, const PropertyKey& key)
30093
30233
 
30094
30234
  template <typename T>
30095
30235
  bool nativeDynamicDelete(const gea::Ref<T>& object, const PropertyKey& key) {
30236
+ if constexpr (detail::sharedRecordDelegation<T>) return detail::recordDocumentDelete(Ref<void>(object), detail::recordDocumentBridgeOf<T>(), key);
30096
30237
  if (!object) return true;
30097
30238
  if (record::immutableDescriptorSnapshotView(Ref<void>(object)))
30098
30239
  host::throwRuntimeError("TypeError", "a native descriptor snapshot deletion has no certified source protocol");
@@ -30152,6 +30293,7 @@ bool nativeDynamicDelete(const gea::Ref<T>& object, const PropertyKey& key) {
30152
30293
  */
30153
30294
  template <typename T>
30154
30295
  std::vector<PropertyKey> nativeEnumerableStringKeys(const gea::Ref<T>& object) {
30296
+ if constexpr (detail::sharedRecordDelegation<T>) return detail::recordEnumerableStringKeys(Ref<void>(object), detail::recordDocumentBridgeOf<T>());
30155
30297
  std::vector<PropertyKey> original;
30156
30298
  if (record::ownNativeViewKeys(Ref<void>(object), original, true)) return original;
30157
30299
  std::vector<PropertyKey> keys = nativeOwnPropertyKeys(object);