@geastack/compiler 1.0.30 → 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.
@@ -4255,6 +4255,13 @@ namespace host {
4255
4255
  }
4256
4256
 
4257
4257
  namespace detail {
4258
+ // Out of line and cold so a `Ref` dereference stays one compare clang inlines:
4259
+ // with the message built at every `->`, clang at -Os stopped inlining
4260
+ // `operator->` and gea-raw lost ~8% throughput (bench box, 2026-10-11).
4261
+ [[noreturn, gnu::cold, gnu::noinline]] inline void throwNullDereference(bool undefined) {
4262
+ host::throwRuntimeError("TypeError", undefined ? "Cannot read properties of undefined" : "Cannot read properties of null");
4263
+ }
4264
+
4258
4265
  /**
4259
4266
  * The one word every `Ref<T>` is: the object, erased.
4260
4267
  *
@@ -4401,14 +4408,14 @@ struct Ref : detail::RefStorage {
4401
4408
  }
4402
4409
 
4403
4410
  T* get() const { return pointer(); }
4404
- T* operator->() const {
4405
- if (!ownsObject()) host::throwRuntimeError("TypeError", isUndefined() ? "Cannot read properties of undefined" : "Cannot read properties of null");
4406
- return pointer();
4411
+ [[gnu::always_inline]] T* operator->() const {
4412
+ if (!ownsObject()) [[unlikely]] detail::throwNullDereference(isUndefined());
4413
+ return static_cast<T*>(erased_);
4407
4414
  }
4408
4415
  /** `add_lvalue_reference_t` rather than `T&`, for the same reason `std::shared_ptr` spells it that way: `Ref<void>` is the box's own storage, and `void&` is not a type. */
4409
- typename std::add_lvalue_reference<T>::type operator*() const {
4410
- if (!ownsObject()) host::throwRuntimeError("TypeError", isUndefined() ? "Cannot read properties of undefined" : "Cannot read properties of null");
4411
- return *pointer();
4416
+ [[gnu::always_inline]] typename std::add_lvalue_reference<T>::type operator*() const {
4417
+ if (!ownsObject()) [[unlikely]] detail::throwNullDereference(isUndefined());
4418
+ return *static_cast<T*>(erased_);
4412
4419
  }
4413
4420
  explicit operator bool() const { return ownsObject(); }
4414
4421
 
@@ -6471,6 +6478,16 @@ struct NativeCallReceiver {
6471
6478
  receiver.boxObject = &boxTypedObject<T>;
6472
6479
  return receiver;
6473
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
+ }
6474
6491
  template <typename T>
6475
6492
  static Value boxTypedObject(const Ref<void>&);
6476
6493
  template <typename T>
@@ -8934,6 +8951,15 @@ struct ArrayObject {
8934
8951
  bool lengthWritable = true;
8935
8952
  Ref<NativeArrayViewSource<Element>> liveSource;
8936
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;
8937
8963
  const void* elementPolicy = nullptr;
8938
8964
  const NativeArrayElementPolicyOps<Element>* elementProtocol = nullptr;
8939
8965
  Value (*elementObserver)(const Element&) = nullptr;
@@ -8950,6 +8976,15 @@ struct ArrayObject {
8950
8976
  if (liveSource) return liveSource->receiver();
8951
8977
  return NativeCallReceiver::object(Ref<ArrayObject<Element>>::adopt(const_cast<ArrayObject<Element>*>(this), true));
8952
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
+ }
8953
8988
  void requireOrdinaryStorage() const {
8954
8989
  if (liveSource || indexedDescriptors) bigint_detail::fail("TypeError", "direct array cells require ordinary storage");
8955
8990
  }
@@ -18400,6 +18435,20 @@ struct ValueMetadata {
18400
18435
  };
18401
18436
  inline constexpr ValueMetadata emptyValueMetadata{nullptr, nullptr, nullptr, nullptr, nullptr, -1, false, false, false, false, nullptr, nullptr, nullptr, nullptr};
18402
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
+
18403
18452
  template <typename T, int RestFrom = -1, bool ActualArguments = false>
18404
18453
  const ValueMetadata* valueMetadataFor() {
18405
18454
  static const ValueMetadata metadata = [] {
@@ -18409,7 +18458,15 @@ const ValueMetadata* valueMetadataFor() {
18409
18458
  Ref<void> (*anchor)(const void*) = nullptr;
18410
18459
  bool (*viewValue)(const void*, Value&) = nullptr;
18411
18460
  const NativeDocumentOps* document = nullptr;
18412
- 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
+ }
18413
18470
  if constexpr (IsRefPayload<T>::value && requires(const T& value) { value->viewAnchor(); }) {
18414
18471
  anchor = +[](const void* payload) -> Ref<void> {
18415
18472
  const T& value = *static_cast<const T*>(payload);
@@ -18422,7 +18479,7 @@ const ValueMetadata* valueMetadataFor() {
18422
18479
  };
18423
18480
  }
18424
18481
  return ValueMetadata{nativeFieldOpsFor<T>(), nativePrototypeOpsFor<T>(), calls,
18425
- nativeArrayOpsFor<T>(), payloadTypeTagFor<T>(), RestFrom, ActualArguments,
18482
+ elements, payloadTypeTagFor<T>(), RestFrom, ActualArguments,
18426
18483
  IsArrayPayload<T>::value, IsMapPayload<T>::value, IsNativeErrorRefPayload<T>::value,
18427
18484
  nativeConstructFor<T>(), anchor, viewValue, document};
18428
18485
  }();
@@ -24810,8 +24867,12 @@ struct DynamicCallSignature<CallableObject<Result(Arguments...)>> {
24810
24867
  }
24811
24868
 
24812
24869
  static Value callWithReceiver(const void* payload, const Value& receiver, const Value* arguments, std::size_t count) {
24813
- return invokeWithReceiver(*static_cast<const CallableObject<Result(Arguments...)>*>(payload), receiver, arguments, count,
24814
- 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...>{});
24815
24876
  }
24816
24877
 
24817
24878
  private:
@@ -24872,7 +24933,11 @@ struct DynamicCallSignature<CallableConstructorObject<Result(Arguments...), Cons
24872
24933
  }
24873
24934
 
24874
24935
  static Value callWithReceiver(const void* payload, const Value& receiver, const Value* arguments, std::size_t count) {
24875
- 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,
24876
24941
  std::index_sequence_for<Arguments...>{});
24877
24942
  }
24878
24943
 
@@ -25091,7 +25156,11 @@ struct DynamicRestCallSignature<CallableObject<Result(Arguments...)>, RestFrom,
25091
25156
  }
25092
25157
 
25093
25158
  static Value callWithReceiver(const void* payload, const Value& receiver, const Value* arguments, std::size_t count) {
25094
- 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,
25095
25164
  std::make_index_sequence<RestFrom>{});
25096
25165
  }
25097
25166
 
@@ -25163,7 +25232,11 @@ struct DynamicRestCallSignature<CallableConstructorObject<Result(Arguments...),
25163
25232
  }
25164
25233
 
25165
25234
  static Value callWithReceiver(const void* payload, const Value& receiver, const Value* arguments, std::size_t count) {
25166
- 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,
25167
25240
  std::make_index_sequence<RestFrom>{});
25168
25241
  }
25169
25242
 
@@ -25349,16 +25422,17 @@ struct NativeLayoutInfo {
25349
25422
  // Each field's presence flag and attributes as offsets into the object, so
25350
25423
  // a scan is a loop over two byte arrays rather than a call per field down
25351
25424
  // the visitor chain (which `-Os` leaves out of line: a 250-field options
25352
- // record paid 250 calls per scan). `scannable` is false when a PRESENCE flag
25353
- // lives outside the object, and every scan then walks the visitor. An
25354
- // attribute triple outside the object is a `static` member (records.ts
25355
- // makes them program-constant for a struct nothing can freeze or redefine):
25356
- // 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.
25357
25431
  static constexpr std::uint32_t outsideObject = ~std::uint32_t{0};
25358
25432
  std::vector<std::uint32_t> presence;
25433
+ std::vector<const bool*> presenceAddresses;
25359
25434
  std::vector<std::uint32_t> attributes;
25360
25435
  std::vector<const NativeIndexAttributes*> attributeAddresses;
25361
- bool scannable = false;
25362
25436
  // The flags sit side by side in layout order (records.ts declares them in
25363
25437
  // one run), so a scan reads them eight at a time and visits only the set
25364
25438
  // ones: a wide options record holds a handful of its ~140 fields, and a
@@ -25370,6 +25444,15 @@ struct NativeLayoutInfo {
25370
25444
  // were most of a spread's presence walk).
25371
25445
  bool plainEnumerable = false;
25372
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
+
25373
25456
  void index() {
25374
25457
  std::size_t size = 16;
25375
25458
  while (size < names.size() * 2) size *= 2;
@@ -25391,6 +25474,37 @@ struct NativeLayoutInfo {
25391
25474
  }
25392
25475
  };
25393
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
+
25394
25508
  template <typename T>
25395
25509
  const NativeLayoutInfo& nativeLayoutInfoOf(const T& self) {
25396
25510
  // The visitor sees every declared field whatever its presence, so any
@@ -25398,38 +25512,11 @@ const NativeLayoutInfo& nativeLayoutInfoOf(const T& self) {
25398
25512
  static const NativeLayoutInfo info = [&] {
25399
25513
  NativeLayoutInfo built;
25400
25514
  const char* base = reinterpret_cast<const char*>(std::addressof(self));
25401
- const auto within = [&](const void* member) {
25402
- const char* at = static_cast<const char*>(member);
25403
- return at >= base && at < base + sizeof(T);
25404
- };
25405
- built.scannable = true;
25406
25515
  T::gea_eachOwnField(self, [&](std::string_view name, const bool& present, const NativeIndexAttributes& attributes) {
25407
- built.names.push_back(name);
25408
- if (within(std::addressof(present))) {
25409
- built.presence.push_back(static_cast<std::uint32_t>(reinterpret_cast<const char*>(std::addressof(present)) - base));
25410
- if (within(std::addressof(attributes))) {
25411
- built.attributes.push_back(static_cast<std::uint32_t>(reinterpret_cast<const char*>(std::addressof(attributes)) - base));
25412
- built.attributeAddresses.push_back(nullptr);
25413
- } else {
25414
- built.attributes.push_back(NativeLayoutInfo::outsideObject);
25415
- built.attributeAddresses.push_back(std::addressof(attributes));
25416
- }
25417
- } else {
25418
- built.scannable = false;
25419
- }
25516
+ recordLayoutField(built, base, sizeof(T), name, std::addressof(present), std::addressof(attributes));
25420
25517
  return false;
25421
25518
  });
25422
- built.presenceContiguous = built.scannable && !built.presence.empty();
25423
- for (std::size_t position = 1; built.presenceContiguous && position < built.presence.size(); ++position)
25424
- if (built.presence[position] != built.presence[0] + position) built.presenceContiguous = false;
25425
- built.plainEnumerable = built.scannable;
25426
- for (std::size_t position = 0; built.plainEnumerable && position < built.names.size(); ++position) {
25427
- const std::string_view name = built.names[position];
25428
- if (built.attributes[position] != NativeLayoutInfo::outsideObject || !built.attributeAddresses[position]->enumerable ||
25429
- (!name.empty() && name[0] >= '0' && name[0] <= '9'))
25430
- built.plainEnumerable = false;
25431
- }
25432
- built.index();
25519
+ finishLayout(built);
25433
25520
  return built;
25434
25521
  }();
25435
25522
  return info;
@@ -25437,89 +25524,77 @@ const NativeLayoutInfo& nativeLayoutInfoOf(const T& self) {
25437
25524
 
25438
25525
  /**
25439
25526
  * `visit(position, name, present, attributes)` for each PRESENT declared
25440
- * field of `self` in layout order, until it answers true (which this
25441
- * returns): eight flags at a time when they are contiguous, else over the
25442
- * layout's offset tables, else down the visitor. `present` is always true; it
25443
- * 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.
25444
25531
  */
25445
- template <typename T, typename Visit>
25446
- bool eachNativeDeclaredField(const T& self, Visit&& visit) {
25447
- const NativeLayoutInfo& layout = nativeLayoutInfoOf(self);
25448
- if (layout.scannable) {
25449
- const char* base = reinterpret_cast<const char*>(std::addressof(self));
25450
- const std::size_t count = layout.names.size();
25451
- const auto visitAt = [&](std::size_t position) {
25452
- const bool& present = *reinterpret_cast<const bool*>(base + layout.presence[position]);
25453
- const std::uint32_t attributesAt = layout.attributes[position];
25454
- const NativeIndexAttributes& attributes = attributesAt == NativeLayoutInfo::outsideObject
25455
- ? *layout.attributeAddresses[position]
25456
- : *reinterpret_cast<const NativeIndexAttributes*>(base + attributesAt);
25457
- return visit(position, layout.names[position], present, attributes);
25458
- };
25459
- if (layout.presenceContiguous) {
25460
- const char* flags = base + layout.presence[0];
25461
- for (std::size_t word = 0; word < count; word += 8) {
25462
- // A variable-length memcpy is a call into libc (memcpy@plt) per eight
25463
- // flags, ~17 per walk of a 134-field options record; the fixed-size
25464
- // loads below compile to one mov each. The short tail re-reads the last
25465
- // eight flags and shifts the already-visited ones out.
25466
- std::uint64_t bits = 0;
25467
- if (word + 8 <= count) {
25468
- std::memcpy(&bits, flags + word, 8);
25469
- } else if (count >= 8) {
25470
- std::memcpy(&bits, flags + count - 8, 8);
25471
- bits >>= (8 - (count - word)) * 8;
25472
- } else {
25473
- for (std::size_t at = 0; at < count; ++at) bits |= std::uint64_t{static_cast<unsigned char>(flags[at])} << (at * 8);
25474
- }
25475
- while (bits != 0) {
25476
- const unsigned byte = static_cast<unsigned>(__builtin_ctzll(bits)) >> 3;
25477
- bits &= ~(std::uint64_t{0xff} << (byte * 8));
25478
- if (visitAt(word + byte)) return true;
25479
- }
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;
25480
25558
  }
25481
- return false;
25482
25559
  }
25483
- for (std::size_t position = 0; position < count; ++position)
25484
- if (*reinterpret_cast<const bool*>(base + layout.presence[position]) && visitAt(position)) return true;
25485
25560
  return false;
25486
25561
  }
25487
- std::size_t position = 0;
25488
- return T::gea_eachOwnField(self, [&](std::string_view name, const bool& present, const NativeIndexAttributes& attributes) {
25489
- const std::size_t at = position++;
25490
- return present && visit(at, name, present, attributes);
25491
- });
25562
+ for (std::size_t position = 0; position < count; ++position)
25563
+ if (layout.presentAt(base, position) && visitAt(position)) return true;
25564
+ return false;
25492
25565
  }
25493
25566
 
25494
- /** Whether any declared field of `self` after layout position `at` is present. */
25495
- template <typename T>
25496
- bool nativeDeclaredFieldPresentAfter(const T& self, std::size_t at) {
25497
- const NativeLayoutInfo& layout = nativeLayoutInfoOf(self);
25498
- if (layout.scannable) {
25499
- const char* base = reinterpret_cast<const char*>(std::addressof(self));
25500
- const std::size_t count = layout.names.size();
25501
- if (layout.presenceContiguous) {
25502
- // The flags after `at` are one run of bytes: eight at a time, and a
25503
- // wide options record's early field (a late store of `session` on a
25504
- // 134-field layout) tests ~16 words rather than ~130 bytes.
25505
- const char* flags = base + layout.presence[0];
25506
- std::size_t position = at + 1;
25507
- for (; position + 8 <= count; position += 8) {
25508
- std::uint64_t bits = 0;
25509
- std::memcpy(&bits, flags + position, 8);
25510
- if (bits != 0) return true;
25511
- }
25512
- for (; position < count; ++position)
25513
- if (flags[position] != 0) return true;
25514
- return false;
25515
- }
25516
- for (std::size_t position = at + 1; position < count; ++position)
25517
- 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;
25518
25588
  return false;
25519
25589
  }
25520
- return eachNativeDeclaredField(self, [&](std::size_t position, std::string_view, const bool& present, const NativeIndexAttributes&) {
25521
- return position > at && present;
25522
- });
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);
25523
25598
  }
25524
25599
 
25525
25600
  /**
@@ -26491,15 +26566,20 @@ void pendNativeKeyOrder(const gea::Ref<T>& self, const std::string_view* keys, s
26491
26566
  * last note, each by position: no name is hashed or copied. `skip` (the key
26492
26567
  * about to be created) is left for its creation to place.
26493
26568
  */
26494
- template <typename T>
26495
- void learnDeclaredFieldsSinceLastNoteExcept(NativeOwnKeyOrder& order, const T& self, std::size_t skip) {
26496
- order.useDeclaredLayout(&nativeLayoutInfoOf(self));
26497
- 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&) {
26498
26573
  if (isPresent && index != skip && !order.isDeclaredLearned(index)) order.learnDeclared(index);
26499
26574
  return false;
26500
26575
  });
26501
26576
  }
26502
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
+
26503
26583
  template <typename T>
26504
26584
  void learnDeclaredFieldsSinceLastNote(NativeOwnKeyOrder& order, const T& self, const PropertyKey* skip) {
26505
26585
  const std::size_t position =
@@ -26845,42 +26925,53 @@ bool nativeDeclaredKeyViewsInOrder(const T& self, NativeOwnKeyOrder& order, std:
26845
26925
  return true;
26846
26926
  }
26847
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
+
26848
26962
  template <typename T>
26849
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); };
26850
26966
  if constexpr (requires { T::gea_eachOwnField(*self, [](std::string_view, const bool&, const NativeIndexAttributes&) { return false; }); }) {
26851
- // An existing log holds every earlier noted key; only the declared fields
26852
- // stored silently since the last note are missing from it.
26853
- if (self != nullptr && (refCountsOf(const_cast<T*>(self))->weak & expandoTagged) != 0) {
26854
- if (NativeOwnKeyOrder* existing = findNativeOwnKeyOrder(self)) {
26855
- learnDeclaredFieldsSinceLastNote(*existing, *self, &key);
26856
- existing->create(key);
26857
- return;
26858
- }
26859
- }
26860
- // No log, pend or expando yet, and no index entry: the present keys are
26861
- // exactly the declared fields, learned by view in layout order. Listing
26862
- // them as `PropertyKey`s first copied every present name of a wide
26863
- // options record per late store (`options.willRetryWrite = ...`).
26864
- 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;
26865
26969
  if constexpr (requires { self->gea_dynamic.size(); })
26866
26970
  undecorated = undecorated && self->gea_dynamic.size() == 0;
26867
- if (undecorated) {
26868
- NativeOwnKeyOrder& order = nativeOwnKeyOrderFor(gea::refCastToVoid(gea::Ref<T>::adopt(const_cast<T*>(self), true)));
26869
- learnDeclaredFieldsSinceLastNote(order, *self, &key);
26870
- order.create(key);
26871
- return;
26872
- }
26971
+ noteLayoutIndexKeyCreated(payload, key, nativeLayoutInfoOf(*self), undecorated, KeyLister::of(fieldKeys));
26972
+ } else {
26973
+ noteNativeOwnKeyCreatedErased(payload, key, KeyLister::of(fieldKeys));
26873
26974
  }
26874
- noteNativeOwnKeyCreated(
26875
- gea::refCastToVoid(gea::Ref<T>::adopt(const_cast<T*>(self), true)), key,
26876
- [&](std::vector<PropertyKey>& keys) { self->gea_ownFieldKeys(keys); },
26877
- [&](std::vector<PropertyKey>& keys) {
26878
- // The visitor chain stops at the first `true` (a find), so every field is seen by answering `false`.
26879
- T::gea_eachOwnField(*self, [&](std::string_view name, const bool& present, const NativeIndexAttributes&) {
26880
- if (present) keys.push_back(PropertyKey::string(std::string(name)));
26881
- return false;
26882
- });
26883
- });
26884
26975
  }
26885
26976
 
26886
26977
  /**
@@ -26916,16 +27007,15 @@ struct SuppressNativeKeyNotes {
26916
27007
  * Answers false, leaving the pend untouched, when the list cannot hold them.
26917
27008
  * The block is a full `orderPositionCapacity` long whatever `count` says.
26918
27009
  */
26919
- template <typename T>
26920
- 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) {
26921
27011
  constexpr std::size_t capacity = orderPositionCapacity;
26922
27012
  for (std::uint32_t index = 0; index < held.count; ++index)
26923
27013
  if (held.positions[index] == at) return true;
26924
- if (!nativeDeclaredFieldPresentAfter(self, at)) return true;
27014
+ if (!declaredFieldPresentAfter(layout, base, at)) return true;
26925
27015
  std::uint32_t silent[capacity];
26926
27016
  std::size_t silentCount = 0;
26927
27017
  bool overflow = false;
26928
- 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&) {
26929
27019
  if (index == at) return false;
26930
27020
  for (std::uint32_t listed = 0; listed < held.count; ++listed)
26931
27021
  if (held.positions[listed] == index) return false;
@@ -26960,6 +27050,69 @@ inline NativeDeclaredKeyPositionHint (&nativeDeclaredKeyPositionHints())[256] {
26960
27050
  return hints->entries;
26961
27051
  }
26962
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
+
26963
27116
  template <typename T>
26964
27117
  void noteNativeDeclaredKeyCreated(const T* self, std::string_view key) {
26965
27118
  GEA_PARALLEL_SIDE_TABLE
@@ -26971,50 +27124,12 @@ void noteNativeDeclaredKeyCreated(const T* self, std::string_view key) {
26971
27124
  #if defined(GEA_MEASURE_SKIP_WIDE_KEY_ORDER)
26972
27125
  if (nativeLayoutInfoOf(*self).names.size() > 100) return;
26973
27126
  #endif
26974
- const NativeLayoutInfo& layout = nativeLayoutInfoOf(*self);
26975
- // The key is a string literal at nearly every call: its address names its position,
26976
- // verified against the layout (so a reused or torn entry only costs the hash).
26977
- auto& hints = nativeDeclaredKeyPositionHints();
26978
- NativeDeclaredKeyPositionHint& hint = hints[(reinterpret_cast<std::uintptr_t>(key.data()) * 0x9E3779B97F4A7C15ull) >> 56];
26979
- std::size_t at;
26980
- if (hint.data == key.data() && hint.position < layout.names.size() && layout.names[hint.position] == key) {
26981
- at = hint.position;
26982
- } else {
26983
- at = layout.position(key);
26984
- if (at == NativeLayoutInfo::npos) return;
26985
- hint.data = key.data();
26986
- hint.position = static_cast<std::uint32_t>(at);
26987
- }
26988
- if constexpr (requires { self->gea_keyOrder; }) {
26989
- // A spread's list of positions takes the key without becoming a log.
26990
- constexpr std::uint32_t kinds = expandoTagged | keyOrderPending | expandoEntry;
26991
- if ((refCountsOf(const_cast<T*>(self))->weak & kinds) == (expandoTagged | keyOrderPending)) {
26992
- InlineKeyOrder& held = const_cast<T*>(self)->gea_keyOrder;
26993
- if (held.pending && held.positional && notePositionalPendKeyCreated(*self, held, at)) return;
26994
- }
26995
- }
26996
- const bool tagged = (refCountsOf(const_cast<T*>(self))->weak & expandoTagged) != 0;
26997
- NativeOwnKeyOrder* order = tagged ? findNativeOwnKeyOrder(self) : nullptr;
26998
- // An absent field the log already places was placed by the literal that
26999
- // creates it, after its spread (`later`): a delete erases the place. The
27000
- // store keeps that place.
27001
- if (order != nullptr && order->ordinals.layout == &layout && order->isDeclaredLearned(at)) return;
27002
- if (!nativeDeclaredFieldPresentAfter(*self, at)) return;
27003
- // `noteNativeIndexKeyCreated`'s two log arms, by position: the created
27004
- // field takes the next ordinal after every present field the log lacks.
27005
- // Spelling the key as a `PropertyKey` and hashing it back to its position
27006
- // cost a wide options record's every late store.
27007
- if (!tagged) {
27008
- bool undecorated = true;
27009
- if constexpr (requires { self->gea_dynamic.size(); }) undecorated = self->gea_dynamic.size() == 0;
27010
- if (undecorated) order = &nativeOwnKeyOrderFor(gea::refCastToVoid(gea::Ref<T>::adopt(const_cast<T*>(self), true)));
27011
- }
27012
- if (order == nullptr) {
27013
- noteNativeIndexKeyCreated(self, PropertyKey::string(std::string(key)));
27014
- return;
27015
- }
27016
- learnDeclaredFieldsSinceLastNoteExcept(*order, *self, at);
27017
- 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>);
27018
27133
  }
27019
27134
  }
27020
27135
 
@@ -27561,9 +27676,8 @@ template <typename Element>
27561
27676
  Element readArrayIndexedDescriptor(const ArrayObject<Element>& array, std::size_t index) {
27562
27677
  const auto* descriptor = array.indexedDescriptors->ownProperty(arrayIndexedKey(index));
27563
27678
  if (!descriptor) host::throwRuntimeError("TypeError", "an array descriptor disappeared during its native read");
27564
- const auto receiver = Ref<ArrayObject<Element>>::adopt(const_cast<ArrayObject<Element>*>(&array), true);
27565
27679
  if constexpr (std::is_same_v<Element, Value>) {
27566
- return array.indexedDescriptors->getWithNativeReceiver(arrayIndexedKey(index), NativeCallReceiver::object(receiver));
27680
+ return array.indexedDescriptors->getWithNativeReceiver(arrayIndexedKey(index), array.indexedReceiver());
27567
27681
  } else {
27568
27682
  if (!descriptor->isAccessor()) {
27569
27683
  std::optional<Element> value;
@@ -27591,7 +27705,7 @@ Element readArrayIndexedDescriptor(const ArrayObject<Element>& array, std::size_
27591
27705
  NativeFieldRead read(result);
27592
27706
  if (array.elementPolicy) read.requestedPolicy = array.elementPolicy;
27593
27707
  const auto answered = array.indexedDescriptors->readNativeAccessor(
27594
- arrayIndexedKey(index), NativeCallReceiver::object(receiver), read);
27708
+ arrayIndexedKey(index), array.indexedReceiver(), read);
27595
27709
  if (!answered || !*answered || !result)
27596
27710
  host::throwRuntimeError("TypeError", "an array getter changed its native element carrier");
27597
27711
  return std::move(*result);
@@ -27600,12 +27714,11 @@ Element readArrayIndexedDescriptor(const ArrayObject<Element>& array, std::size_
27600
27714
 
27601
27715
  template <typename Element, typename Policy>
27602
27716
  bool arrayWriteIndexedDescriptor(ArrayObject<Element>& array, std::size_t index, const Element& value) {
27603
- const auto receiver = Ref<ArrayObject<Element>>::adopt(&array, true);
27604
27717
  if constexpr (std::is_same_v<Element, Value>) {
27605
- return array.indexedDescriptors->setWithNativeReceiver(arrayIndexedKey(index), value, NativeCallReceiver::object(receiver));
27718
+ return array.indexedDescriptors->setWithNativeReceiver(arrayIndexedKey(index), value, array.indexedReceiver());
27606
27719
  } else {
27607
27720
  return array.indexedDescriptors->template setNativeDataWithNativeReceiver<Element, Policy>(
27608
- arrayIndexedKey(index), value, nullptr, NativeCallReceiver::object(receiver));
27721
+ arrayIndexedKey(index), value, nullptr, array.indexedReceiver());
27609
27722
  }
27610
27723
  }
27611
27724
  template <typename Element>
@@ -27615,8 +27728,7 @@ bool writeArrayIndexedDescriptor(ArrayObject<Element>& array, std::size_t index,
27615
27728
  }
27616
27729
  template <typename Element>
27617
27730
  bool writeArrayUndefinedDescriptor(ArrayObject<Element>& array, std::size_t index) {
27618
- const auto receiver = Ref<ArrayObject<Element>>::adopt(&array, true);
27619
- return array.indexedDescriptors->setWithNativeReceiver(arrayIndexedKey(index), Value{}, NativeCallReceiver::object(receiver));
27731
+ return array.indexedDescriptors->setWithNativeReceiver(arrayIndexedKey(index), Value{}, array.indexedReceiver());
27620
27732
  }
27621
27733
 
27622
27734
  template <typename Element>
@@ -27658,7 +27770,7 @@ bool ArrayObject<Element>::defineIndex(std::size_t index, const PropertyDescript
27658
27770
  PropertyDescriptor current;
27659
27771
  const bool exists = ownIndexDescriptor(index, current);
27660
27772
  if (!exists && !extensible()) return false;
27661
- if (!indexedDescriptors) indexedDescriptors = makeRef<DynamicObject>();
27773
+ createIndexedDescriptors();
27662
27774
  const PropertyKey key = arrayIndexedKey(index);
27663
27775
  if (indexedDescriptors->ownProperty(key) == nullptr && exists && !indexedDescriptors->defineOwnProperty(key, current)) return false;
27664
27776
  if (!indexedDescriptors->defineOwnProperty(key, descriptor)) return false;
@@ -27715,8 +27827,7 @@ bool arrayReadNativeElement(const ArrayObject<Element>& array, std::size_t index
27715
27827
  return answer.template acceptsExact<Element, Policy>() && answer.template assign<Policy>(array.cells[index].value);
27716
27828
  }
27717
27829
  if (!descriptor->isAccessor()) return descriptor->nativeValue && descriptor->nativeValue.read(answer);
27718
- const auto receiver = Ref<ArrayObject<Element>>::adopt(const_cast<ArrayObject<Element>*>(&array), true);
27719
- const auto handled = array.indexedDescriptors->readNativeAccessor(arrayIndexedKey(index), NativeCallReceiver::object(receiver), answer);
27830
+ const auto handled = array.indexedDescriptors->readNativeAccessor(arrayIndexedKey(index), array.indexedReceiver(), answer);
27720
27831
  return handled && *handled;
27721
27832
  }
27722
27833
  template <typename Element, typename Policy>
@@ -27748,12 +27859,11 @@ bool ArrayObject<Element>::setNativeElement(std::size_t index, const Native& val
27748
27859
  } else {
27749
27860
  PropertyDescriptor current;
27750
27861
  const bool exists = ownIndexDescriptor(index, current);
27751
- if (!indexedDescriptors) indexedDescriptors = makeRef<DynamicObject>();
27862
+ createIndexedDescriptors();
27752
27863
  const PropertyKey key = arrayIndexedKey(index);
27753
27864
  if (exists && indexedDescriptors->ownProperty(key) == nullptr && !indexedDescriptors->defineOwnProperty(key, current)) return false;
27754
- const auto receiver = Ref<ArrayObject<Element>>::adopt(this, true);
27755
27865
  if (!indexedDescriptors->template setNativeDataWithNativeReceiver<Native, Policy>(
27756
- key, value, observe, NativeCallReceiver::object(receiver))) return false;
27866
+ key, value, observe, indexedReceiver())) return false;
27757
27867
  if (index >= cells.size()) {
27758
27868
  openHoles();
27759
27869
  cells.resize(index + 1);
@@ -28794,8 +28904,35 @@ void nativeSpreadObjectDataSet(const gea::Ref<Receiver>& object, std::string_vie
28794
28904
  * attribute set against a fixed-layout member store is a larger feature this
28795
28905
  * call does not need yet, so it is left to a future caller to state.
28796
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
+
28797
28933
  template <typename T>
28798
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);
28799
28936
  if (!object) return false;
28800
28937
  if (record::immutableDescriptorSnapshotView(Ref<void>(object)))
28801
28938
  host::throwRuntimeError("TypeError", "a native descriptor snapshot definition has no certified source protocol");
@@ -28827,6 +28964,13 @@ bool nativeDynamicDefineProperty(const gea::Ref<T>& object, const PropertyKey& k
28827
28964
 
28828
28965
  template <typename T>
28829
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
+ }
28830
28974
  if (!object) return Optional<PropertyDescriptor>();
28831
28975
  if constexpr (IsArrayObjectStruct<T>::value) {
28832
28976
  if (!key.isSymbol() && key.text() == "length") {
@@ -28880,6 +29024,7 @@ Optional<PropertyDescriptor> nativeOwnPropertyDescriptor(const gea::Ref<T>& obje
28880
29024
  */
28881
29025
  template <typename T>
28882
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>());
28883
29028
  std::vector<PropertyKey> keys;
28884
29029
  if (!object) return keys;
28885
29030
  if constexpr (IsArrayObjectStruct<T>::value) {
@@ -29155,6 +29300,7 @@ struct NativeDocumentOwner {
29155
29300
 
29156
29301
  template <typename T>
29157
29302
  const NativeDocumentOps* nativeDocumentOpsFor();
29303
+
29158
29304
  } // namespace detail
29159
29305
 
29160
29306
  namespace json {
@@ -30025,6 +30171,7 @@ inline gea::Ref<void> viewOrigin(const gea::Ref<gea::Dictionary<gea::Value>>& vi
30025
30171
 
30026
30172
  template <typename T>
30027
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);
30028
30175
  if (!object) return false;
30029
30176
  if constexpr (IsArrayObjectStruct<T>::value) {
30030
30177
  if (!key.isSymbol() && key.text() == "length") return true;
@@ -30086,6 +30233,7 @@ bool nativeDynamicHasProperty(const gea::Ref<T>& object, const PropertyKey& key)
30086
30233
 
30087
30234
  template <typename T>
30088
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);
30089
30237
  if (!object) return true;
30090
30238
  if (record::immutableDescriptorSnapshotView(Ref<void>(object)))
30091
30239
  host::throwRuntimeError("TypeError", "a native descriptor snapshot deletion has no certified source protocol");
@@ -30145,6 +30293,7 @@ bool nativeDynamicDelete(const gea::Ref<T>& object, const PropertyKey& key) {
30145
30293
  */
30146
30294
  template <typename T>
30147
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>());
30148
30297
  std::vector<PropertyKey> original;
30149
30298
  if (record::ownNativeViewKeys(Ref<void>(object), original, true)) return original;
30150
30299
  std::vector<PropertyKey> keys = nativeOwnPropertyKeys(object);