From eae1737b664586de1843572e6afa9a7155e1019d Mon Sep 17 00:00:00 2001 From: Peterino2 Date: Fri, 20 Nov 2026 18:17:34 -0700 Subject: [PATCH] getting rid of old cruft from imported p2 lib --- .../lib/p2/debugging/lldb_std_formatters.py | 1279 ----------------- .../p2/src/queue-benchmark-cas-baseline.zig | 117 -- engine/lib/p2/src/queue-benchmark.zig | 203 --- engine/lib/p2/src/test.zig | 43 - engine/lib/p2/tools/vscode-env/README.md | 59 - .../p2/tools/vscode-env/extensions/.gitkeep | 1 - engine/lib/p2/tools/vscode-env/install.bat | 137 -- engine/lib/p2/tools/vscode-env/install.sh | 145 -- .../tools/vscode-env/settings/settings.json | 7 - 9 files changed, 1991 deletions(-) delete mode 100644 engine/lib/p2/debugging/lldb_std_formatters.py delete mode 100644 engine/lib/p2/src/queue-benchmark-cas-baseline.zig delete mode 100644 engine/lib/p2/src/queue-benchmark.zig delete mode 100644 engine/lib/p2/src/test.zig delete mode 100644 engine/lib/p2/tools/vscode-env/README.md delete mode 100644 engine/lib/p2/tools/vscode-env/extensions/.gitkeep delete mode 100644 engine/lib/p2/tools/vscode-env/install.bat delete mode 100755 engine/lib/p2/tools/vscode-env/install.sh delete mode 100644 engine/lib/p2/tools/vscode-env/settings/settings.json diff --git a/engine/lib/p2/debugging/lldb_std_formatters.py b/engine/lib/p2/debugging/lldb_std_formatters.py deleted file mode 100644 index a9ef293..0000000 --- a/engine/lib/p2/debugging/lldb_std_formatters.py +++ /dev/null @@ -1,1279 +0,0 @@ -"""LLDB formatters for common Zig standard library data structures. - -Import from LLDB with: - - command script import /path/to/debugging/lldb_std_formatters.py - -The formatters are deliberately field-shape based. Zig's stdlib types are -heavily comptime-generated, so exact type names vary by compiler version, -element type, and package path. These helpers prefer safe summaries and -expandable children over evaluating Zig code inside the debuggee. -""" - -from __future__ import annotations - -import lldb -import re -import struct - - -MAX_STRING_BYTES = 4096 -MAX_CREATE_CHILD_OFFSET = 0xFFFFFFFF -MAX_TRUSTED_SYNTHETIC_CHILDREN = 100000 - - -def __lldb_init_module(debugger: lldb.SBDebugger, _dict) -> None: - debugger.HandleCommand( - "type summary add -x '^\\[\\].*' " - "-F lldb_std_formatters.slice_summary" - ) - debugger.HandleCommand( - "type synthetic add -x '^\\[\\].*' " - "-l lldb_std_formatters.SliceSyntheticProvider" - ) - - debugger.HandleCommand( - "type summary add -x '^\\[\\*\\].*' " - "-F lldb_std_formatters.many_pointer_summary" - ) - - debugger.HandleCommand( - "type summary add -x '(^|.*\\.)ArrayList(Unmanaged)?(Aligned)?(\\(|$|<)' " - "-F lldb_std_formatters.array_list_summary" - ) - debugger.HandleCommand( - "type synthetic add -x '(^|.*\\.)ArrayList(Unmanaged)?(Aligned)?(\\(|$|<)' " - "-l lldb_std_formatters.ArrayListSyntheticProvider" - ) - - debugger.HandleCommand( - "type summary add -x '(^|.*\\.)(StringHashMap|StringArrayHashMap|" - "AutoHashMap|AutoArrayHashMap|HashMap|ArrayHashMap)(Unmanaged)?(\\(|$|<)' " - "-F lldb_std_formatters.hash_map_summary" - ) - debugger.HandleCommand( - "type synthetic add -x '(^|.*\\.)(StringHashMap|StringArrayHashMap|" - "AutoHashMap|AutoArrayHashMap|HashMap|ArrayHashMap)(Unmanaged)?(\\(|$|<)' " - "-l lldb_std_formatters.HashMapSyntheticProvider" - ) - - debugger.HandleCommand( - "type summary add -x '(^|.*\\.)(StringHashMap|StringArrayHashMap)" - "(Unmanaged)?(\\(|$|<)' " - "-F lldb_std_formatters.string_hash_map_summary" - ) - - debugger.HandleCommand( - "type summary add -x '^structures\\.document\\.Record$' " - "-F lldb_std_formatters.record_summary" - ) - debugger.HandleCommand( - "type synthetic add -x '^structures\\.document\\.Record$' " - "-l lldb_std_formatters.RecordSyntheticProvider" - ) - - debugger.HandleCommand( - "type summary add -x '^structures\\.document\\.List$' " - "-F lldb_std_formatters.record_list_summary" - ) - debugger.HandleCommand( - "type synthetic add -x '^structures\\.document\\.List$' " - "-l lldb_std_formatters.RecordListSyntheticProvider" - ) - - debugger.HandleCommand( - "type summary add -x '^structures\\.document\\.Dict$' " - "-F lldb_std_formatters.record_dict_summary" - ) - debugger.HandleCommand( - "type synthetic add -x '^structures\\.document\\.Dict$' " - "-l lldb_std_formatters.RecordDictSyntheticProvider" - ) - - -def slice_summary(valobj: lldb.SBValue, _dict) -> str: - length = _slice_len(valobj) - if length is None: - return "" - - text = _read_u8_string_from_slice(valobj, length) - if text is not None: - return f'len={length} "{text}"' - - if _suspicious_child_count(length): - return f"len={length}, children suppressed" - return f"len={length}" - - -def many_pointer_summary(valobj: lldb.SBValue, _dict) -> str: - address = _address(valobj) - if address is None: - return "" - return f"ptr=0x{address:x}" - - -def array_list_summary(valobj: lldb.SBValue, _dict) -> str: - items = _array_list_items(valobj) - length = _slice_len(items) if items is not None else None - capacity = _uint_child(valobj, "capacity") - - if length is None: - return "" - length_text = f"len={length}" - if _suspicious_child_count(length): - length_text = f"len={length}, children suppressed" - if capacity is None: - return length_text - return f"{length_text}, capacity={capacity}" - - -def hash_map_summary(valobj: lldb.SBValue, _dict) -> str: - count = _hash_map_count(valobj) - capacity = _hash_map_capacity(valobj) - - if count is None and capacity is None: - return "" - if capacity is None: - return f"count={count}" - if count is None: - return f"capacity={capacity}" - return f"count={count}, capacity={capacity}" - - -def string_hash_map_summary(valobj: lldb.SBValue, _dict) -> str: - summary = hash_map_summary(valobj, _dict) - return f"StringHashMap {summary}" - - -def record_summary(valobj: lldb.SBValue, _dict) -> str: - try: - document = _child(valobj, "document") - record_id = _uint_child(valobj, "id") - if document is None or record_id is None: - return "" - - slot = _record_slot(valobj) - if slot is None: - slots_len = _document_slots_len(document) - if slots_len is None: - return f"id={record_id}, slot=" - return f"id={record_id}, slot=, slots.len={slots_len}" - - tag = _zig_union_tag_name(slot) - if tag is None: - return f"id={record_id}, slot={slot.GetTypeName()}" - return f"id={record_id}, tag={tag}" - except Exception as exc: - record_id = _uint_child(valobj, "id") - if record_id is None: - return f"" - return f"id={record_id}, slot=" - - -def record_list_summary(valobj: lldb.SBValue, _dict) -> str: - try: - record = _child(valobj, "record") - if record is None: - return "" - - record_id = _uint_child(record, "id") - active_list = _record_active_list(record) - items = _array_list_items(active_list) if active_list is not None else None - length = _slice_len(items) - if record_id is None: - return "" - if length is None: - return f"id={record_id}, list=" - return f"id={record_id}, len={length}" - except Exception as exc: - return f"" - - -def record_dict_summary(valobj: lldb.SBValue, _dict) -> str: - try: - record = _child(valobj, "record") - if record is None: - return "" - - record_id = _uint_child(record, "id") - active_dict = _record_active_dict(record) - if record_id is None: - return "" - if active_dict is None: - return f"id={record_id}, dict=" - - summary = hash_map_summary(active_dict, _dict) - return f"id={record_id}, {summary}" - except Exception as exc: - return f"" - - -class SliceSyntheticProvider: - def __init__(self, valobj: lldb.SBValue, _dict): - self.valobj = valobj - self.ptr = None - self.length = 0 - self.elem_type = None - self.elem_size = 0 - self.has_string_child = False - self.update() - - def update(self) -> None: - self.ptr = _child(self.valobj, "ptr") - self.length = _slice_len(self.valobj) or 0 - self.elem_type = _pointer_pointee_type(self.ptr) - self.elem_size = _byte_size(self.elem_type) - self.has_string_child = _is_u8_type(self.elem_type) - - def num_children(self) -> int: - string_count = 1 if self.has_string_child else 0 - if _suspicious_child_count(self.length): - return string_count - return string_count + self.length - - def get_child_index(self, name: str) -> int: - if self.has_string_child and name == "string": - return 0 - - match = re.match(r"^\[(\d+)\]$", name) - if match is None: - return -1 - index = int(match.group(1)) - return index + (1 if self.has_string_child else 0) - - def get_child_at_index(self, index: int) -> lldb.SBValue: - if index < 0 or index >= self.num_children(): - return lldb.SBValue() - - if self.has_string_child: - if index == 0: - return _slice_string_child(self.valobj, "string", self.length) - index -= 1 - - if index >= self.length: - return lldb.SBValue() - return _pointer_child_at(self.ptr, self.elem_type, self.elem_size, index) - - def has_children(self) -> bool: - return self.num_children() > 0 - - -class ArrayListSyntheticProvider: - def __init__(self, valobj: lldb.SBValue, _dict): - self.valobj = valobj - self.slice_provider = None - self.update() - - def update(self) -> None: - items = _array_list_items(self.valobj) - self.slice_provider = ( - SliceSyntheticProvider(items, {}) if items is not None else None - ) - - def num_children(self) -> int: - if self.slice_provider is None: - return 0 - return self.slice_provider.num_children() - - def get_child_index(self, name: str) -> int: - if self.slice_provider is None: - return -1 - return self.slice_provider.get_child_index(name) - - def get_child_at_index(self, index: int) -> lldb.SBValue: - if self.slice_provider is None: - return lldb.SBValue() - return self.slice_provider.get_child_at_index(index) - - def has_children(self) -> bool: - return self.num_children() > 0 - - -class HashMapSyntheticProvider: - """Best-effort expansion for std hash maps. - - Zig's HashMap internals differ between releases and between managed and - unmanaged variants. This provider exposes the raw control fields and, for - Zig 0.16 HashMapUnmanaged layout, scans metadata to show only live slots. - """ - - def __init__(self, valobj: lldb.SBValue, _dict): - self.valobj = valobj - self.children = [] - self.entries = None - self.keys = None - self.values = None - self.capacity = 0 - self.header_data = None - self.key_type = None - self.value_type = None - self.live_slots = [] - self.update() - - def update(self) -> None: - self.children = [] - self.entries = _hash_map_entries(self.valobj) - self.keys = _hash_map_keys(self.valobj) - self.values = _hash_map_values(self.valobj) - self.capacity = _hash_map_capacity(self.valobj) or 0 - self.header_data = None - self.key_type = None - self.value_type = None - self.live_slots = [] - - raw_map = _hash_map_unmanaged(self.valobj) - if raw_map is not None: - for name in ("metadata", "size", "available", "pointer_stability"): - child = _child(raw_map, name) - if child is not None: - self.children.append((name, child)) - - header = _hash_map_header(raw_map) - for name, child in header: - self.children.append((name, child)) - - self.header_data = _hash_map_header_data(raw_map) - self.key_type, self.value_type = _hash_map_key_value_types(raw_map) - self.live_slots = _hash_map_live_slots(raw_map, self.header_data) - - def num_children(self) -> int: - fixed_count = len(self.children) - if self._has_live_slot_children(): - count = len(self.live_slots) * 2 - return fixed_count if _suspicious_child_count(count) else fixed_count + count - - if self.entries is None: - if self.keys is not None and self.values is not None: - count = self.capacity * 2 - return fixed_count if _suspicious_child_count(count) else fixed_count + count - if self.keys is not None or self.values is not None: - return fixed_count if _suspicious_child_count(self.capacity) else fixed_count + self.capacity - return fixed_count - count = _slice_len(self.entries) or 0 - return fixed_count if _suspicious_child_count(count) else fixed_count + count - - def get_child_index(self, name: str) -> int: - for i, (child_name, _child_value) in enumerate(self.children): - if child_name == name: - return i - - match = re.match(r"^slot\[(\d+)\]\.(key|value)$", name) - if match is not None: - slot = int(match.group(1)) - try: - live_index = self.live_slots.index(slot) - except ValueError: - return -1 - return len(self.children) + live_index * 2 + (0 if match.group(2) == "key" else 1) - - match = re.match(r"^\[(\d+)\]$", name) - if match is None: - return -1 - return len(self.children) + int(match.group(1)) - - def get_child_at_index(self, index: int) -> lldb.SBValue: - if index < 0 or index >= self.num_children(): - return lldb.SBValue() - - fixed_count = len(self.children) - if index < fixed_count: - _name, child = self.children[index] - return child - - entry_index = index - fixed_count - if self._has_live_slot_children(): - live_index = entry_index // 2 - if live_index < 0 or live_index >= len(self.live_slots): - return lldb.SBValue() - - slot = self.live_slots[live_index] - if entry_index % 2 == 0: - return _hash_map_slot_child( - self.valobj, - self.header_data, - self.key_type, - slot, - f"slot[{slot}].key", - "keys_addr", - ) - return _hash_map_slot_child( - self.valobj, - self.header_data, - self.value_type, - slot, - f"slot[{slot}].value", - "values_addr", - ) - - if self.entries is None: - if self.keys is not None and self.values is not None: - slot = entry_index // 2 - storage = self.keys if entry_index % 2 == 0 else self.values - name = f"[{slot}].key" if entry_index % 2 == 0 else f"[{slot}].value" - child = _pointer_storage_child(storage, name, slot) - return child if child is not None else lldb.SBValue() - if self.keys is not None or self.values is not None: - storage = self.keys if self.keys is not None else self.values - child = _pointer_storage_child(storage, f"[{entry_index}]", entry_index) - return child if child is not None else lldb.SBValue() - return lldb.SBValue() - provider = SliceSyntheticProvider(self.entries, {}) - return provider.get_child_at_index(entry_index) - - def has_children(self) -> bool: - return self.num_children() > 0 - - def _has_live_slot_children(self) -> bool: - return ( - self.header_data is not None - and self.key_type is not None - and self.value_type is not None - and len(self.live_slots) > 0 - ) - - -class RecordSyntheticProvider: - def __init__(self, valobj: lldb.SBValue, _dict): - self.valobj = valobj - self.children = [] - self.update() - - def update(self) -> None: - self.children = [] - try: - record_id = _child(self.valobj, "id") - if record_id is not None: - self.children.append(("id", record_id)) - - document = _child(self.valobj, "document") - if document is not None: - self.children.append(("document", document)) - - slot_ptr = _record_slot_ptr(self.valobj) - if slot_ptr is not None: - self.children.append(("slot_ptr", slot_ptr)) - - slot = _deref(slot_ptr) - if slot is not None: - self.children.append(("slot", slot)) - except Exception: - self.children = [] - - def num_children(self) -> int: - return len(self.children) - - def get_child_index(self, name: str) -> int: - for i, (child_name, _child_value) in enumerate(self.children): - if child_name == name: - return i - return -1 - - def get_child_at_index(self, index: int) -> lldb.SBValue: - if index < 0 or index >= len(self.children): - return lldb.SBValue() - _name, child = self.children[index] - return child - - def has_children(self) -> bool: - return len(self.children) > 0 - - -class RecordListSyntheticProvider: - def __init__(self, valobj: lldb.SBValue, _dict): - self.valobj = valobj - self.children = [] - self.items_provider = None - self.fixed_count = 0 - self.update() - - def update(self) -> None: - self.children = [] - self.items_provider = None - self.fixed_count = 0 - - try: - record = _child(self.valobj, "record") - if record is not None: - self.children.append(("record", record)) - - slot_ptr = _record_slot_ptr(record) if record is not None else None - if slot_ptr is not None: - self.children.append(("slot_ptr", slot_ptr)) - - slot = _deref(slot_ptr) - if slot is not None: - self.children.append(("slot", slot)) - - active_list = _record_active_list(record) if record is not None else None - if active_list is not None: - self.children.append(("active_list", active_list)) - items = _array_list_items(active_list) - if items is not None: - self.children.append(("items", items)) - self.items_provider = SliceSyntheticProvider(items, {}) - - self.fixed_count = len(self.children) - except Exception: - self.children = [] - self.items_provider = None - self.fixed_count = 0 - - def num_children(self) -> int: - item_count = self.items_provider.num_children() if self.items_provider else 0 - return self.fixed_count + item_count - - def get_child_index(self, name: str) -> int: - for i, (child_name, _child_value) in enumerate(self.children): - if child_name == name: - return i - - match = re.match(r"^\[(\d+)\]$", name) - if match is None: - return -1 - return self.fixed_count + int(match.group(1)) - - def get_child_at_index(self, index: int) -> lldb.SBValue: - if index < 0: - return lldb.SBValue() - if index < self.fixed_count: - _name, child = self.children[index] - return child - if self.items_provider is None: - return lldb.SBValue() - - item_index = index - self.fixed_count - return self.items_provider.get_child_at_index(item_index) - - def has_children(self) -> bool: - return self.num_children() > 0 - - -class RecordDictSyntheticProvider: - def __init__(self, valobj: lldb.SBValue, _dict): - self.valobj = valobj - self.children = [] - self.dict_provider = None - self.fixed_count = 0 - self.update() - - def update(self) -> None: - self.children = [] - self.dict_provider = None - self.fixed_count = 0 - - try: - record = _child(self.valobj, "record") - if record is not None: - self.children.append(("record", record)) - - slot_ptr = _record_slot_ptr(record) if record is not None else None - if slot_ptr is not None: - self.children.append(("slot_ptr", slot_ptr)) - - slot = _deref(slot_ptr) - if slot is not None: - self.children.append(("slot", slot)) - - active_dict = _record_active_dict(record) if record is not None else None - if active_dict is not None: - self.children.append(("active_dict", active_dict)) - self.dict_provider = HashMapSyntheticProvider(active_dict, {}) - if record is not None and record.GetType().IsValid(): - self.dict_provider.value_type = record.GetType() - - self.fixed_count = len(self.children) - except Exception: - self.children = [] - self.dict_provider = None - self.fixed_count = 0 - - def num_children(self) -> int: - dict_count = self.dict_provider.num_children() if self.dict_provider else 0 - return self.fixed_count + dict_count - - def get_child_index(self, name: str) -> int: - for i, (child_name, _child_value) in enumerate(self.children): - if child_name == name: - return i - - match = re.match(r"^\[(\d+)\]$", name) - if match is None: - return -1 - return self.fixed_count + int(match.group(1)) - - def get_child_at_index(self, index: int) -> lldb.SBValue: - if index < 0: - return lldb.SBValue() - if index < self.fixed_count: - _name, child = self.children[index] - return child - if self.dict_provider is None: - return lldb.SBValue() - - dict_index = index - self.fixed_count - return self.dict_provider.get_child_at_index(dict_index) - - def has_children(self) -> bool: - return self.num_children() > 0 - - -def _child(valobj: lldb.SBValue | None, name: str) -> lldb.SBValue | None: - if valobj is None or not valobj.IsValid(): - return None - raw = _raw_value(valobj) - child = raw.GetChildMemberWithName(name) - if child.IsValid(): - return child - return None - - -def _raw_value(valobj: lldb.SBValue) -> lldb.SBValue: - raw = valobj.GetNonSyntheticValue() - if raw.IsValid(): - return raw - return valobj - - -def _first_child(valobj: lldb.SBValue | None, names: tuple[str, ...]) -> lldb.SBValue | None: - for name in names: - child = _child(valobj, name) - if child is not None: - return child - return None - - -def _uint(value: lldb.SBValue | None) -> int | None: - if value is None or not value.IsValid(): - return None - result = value.GetValueAsUnsigned(0) - if result != 0 or (value.GetValue() in ("0", "0x0")): - return result - try: - return int(value.GetValue(), 0) - except (TypeError, ValueError): - return None - - -def _uint_child(valobj: lldb.SBValue | None, name: str) -> int | None: - return _uint(_child(valobj, name)) - - -def _address(value: lldb.SBValue | None) -> int | None: - if value is None or not value.IsValid(): - return None - address = value.GetValueAsUnsigned() - if address: - return address - load_address = value.GetLoadAddress() - if load_address != lldb.LLDB_INVALID_ADDRESS: - return load_address - return None - - -def _deref(value: lldb.SBValue | None) -> lldb.SBValue | None: - if value is None or not value.IsValid(): - return None - child = value.Dereference() - if child.IsValid(): - return child - return None - - -def _slice_len(valobj: lldb.SBValue | None) -> int | None: - return _uint_child(valobj, "len") - - -def _pointer_pointee_type(ptr: lldb.SBValue | None) -> lldb.SBType | None: - if ptr is None or not ptr.IsValid(): - return None - pointee = ptr.GetType().GetPointeeType() - if pointee.IsValid(): - return pointee - return None - - -def _byte_size(value_type: lldb.SBType | None) -> int: - if value_type is None or not value_type.IsValid(): - return 0 - return value_type.GetByteSize() - - -def _is_u8_type(value_type: lldb.SBType | None) -> bool: - if value_type is None or not value_type.IsValid(): - return False - return (value_type.GetName() or "") in ("u8", "const u8") - - -def _slice_string_child( - valobj: lldb.SBValue, - name: str, - length: int, -) -> lldb.SBValue: - target = valobj.GetTarget() - if not target.IsValid(): - return lldb.SBValue() - - char_type = target.GetBasicType(lldb.eBasicTypeChar) - if not char_type.IsValid(): - char_type = target.GetBasicType(lldb.eBasicTypeSignedChar) - if not char_type.IsValid(): - char_type = target.GetBasicType(lldb.eBasicTypeUnsignedChar) - if not char_type.IsValid(): - return lldb.SBValue() - - string_len = min(length, MAX_STRING_BYTES) - array_type = char_type.GetArrayType(max(string_len, 1)) - if not array_type.IsValid(): - return lldb.SBValue() - - ptr = _child(valobj, "ptr") - address = _address(ptr) - if address is None: - return lldb.SBValue() - return valobj.CreateValueFromAddress(name, address, array_type) - - -def _string_value(parent: lldb.SBValue, name: str, text: str) -> lldb.SBValue: - escaped = ( - text.replace("\\", "\\\\") - .replace("\n", "\\n") - .replace("\r", "\\r") - .replace("\t", "\\t") - .replace('"', '\\"') - ) - return parent.CreateValueFromExpression(name, f'"{escaped}"') - - -def _pointer_child_at( - ptr: lldb.SBValue | None, - elem_type: lldb.SBType | None, - elem_size: int, - index: int, - name: str | None = None, -) -> lldb.SBValue: - if ptr is None or elem_type is None or elem_size == 0: - return lldb.SBValue() - address = _address(ptr) - if address is None: - return lldb.SBValue() - offset = index * elem_size - if offset > MAX_CREATE_CHILD_OFFSET: - return lldb.SBValue() - try: - child_name = name if name is not None else f"[{index}]" - return ptr.CreateValueFromAddress(child_name, address + offset, elem_type) - except OverflowError: - return lldb.SBValue() - - -def _array_list_items(valobj: lldb.SBValue) -> lldb.SBValue | None: - items = _child(valobj, "items") - if items is not None: - return items - - unmanaged = _first_child(valobj, ("unmanaged", "list", "inner")) - if unmanaged is not None: - return _child(unmanaged, "items") - - return None - - -def _suspicious_child_count(count: int) -> bool: - return count > MAX_TRUSTED_SYNTHETIC_CHILDREN - - -def _record_slot(record: lldb.SBValue) -> lldb.SBValue | None: - return _deref(_record_slot_ptr(record)) - - -def _record_active_list(record: lldb.SBValue) -> lldb.SBValue | None: - slot = _record_slot(record) - if slot is None: - return None - return _union_payload(slot, ("list",)) - - -def _record_active_dict(record: lldb.SBValue) -> lldb.SBValue | None: - slot = _record_slot(record) - if slot is None: - return None - return _union_payload(slot, ("dict",)) - - -def _record_slot_ptr(record: lldb.SBValue) -> lldb.SBValue | None: - document_ptr = _child(record, "document") - record_id = _uint_child(record, "id") - if document_ptr is None or record_id is None: - return None - - document = _deref(document_ptr) - if document is None: - return None - - slots = _child(document, "slots") - if slots is None: - return None - - items = _array_list_items(slots) - slots_len = _slice_len(items) - if items is None or slots_len is None or record_id >= slots_len: - return None - - slot_ptr = _slice_child_at(items, record_id, "slot_ptr") - if slot_ptr.IsValid(): - return slot_ptr - return None - - -def _slice_child_at( - slice_value: lldb.SBValue, - index: int, - name: str | None = None, -) -> lldb.SBValue: - length = _slice_len(slice_value) - if length is None or index < 0 or index >= length: - return lldb.SBValue() - - ptr = _child(slice_value, "ptr") - elem_type = _pointer_pointee_type(ptr) - elem_size = _byte_size(elem_type) - return _pointer_child_at(ptr, elem_type, elem_size, index, name) - - -def _document_slots_len(document_ptr: lldb.SBValue) -> int | None: - document = _deref(document_ptr) - if document is None: - return None - slots = _child(document, "slots") - if slots is None: - return None - items = _array_list_items(slots) - return _slice_len(items) - - -def _zig_union_tag(value: lldb.SBValue) -> str | None: - tag = _zig_union_tag_child(value) - if tag is not None: - return tag.GetValue() or tag.GetSummary() - return None - - -def _zig_union_tag_child(value: lldb.SBValue) -> lldb.SBValue | None: - for name in ("tag", "__tag", "_tag"): - tag = _child(value, name) - if tag is not None: - return tag - - for i in range(value.GetNumChildren()): - child = value.GetChildAtIndex(i) - name = child.GetName() or "" - if "tag" in name.lower(): - return child - - return None - - -def _zig_union_tag_name(value: lldb.SBValue) -> str | None: - raw = _zig_union_tag(value) - if raw is None: - return None - - raw = raw.strip() - if raw.startswith('"') and raw.endswith('"'): - raw = raw[1:-1] - if raw.startswith("."): - raw = raw[1:] - - match = re.search(r"([A-Za-z_][A-Za-z0-9_]*)$", raw) - if match is None: - return raw or None - return match.group(1) - - -def _union_payload(value: lldb.SBValue, names: tuple[str, ...]) -> lldb.SBValue | None: - payload = _first_child(value, names) - if payload is not None: - return payload - - for i in range(value.GetNumChildren()): - child = value.GetChildAtIndex(i) - name = child.GetName() or "" - if name in names: - return child - - lowered = name.lower() - for wanted in names: - wanted_lower = wanted.lower() - if wanted_lower == lowered or wanted_lower in lowered: - return child - - return None - - -def _hash_map_count(valobj: lldb.SBValue) -> int | None: - direct = _first_uint_child( - valobj, - ( - "count", - "size", - "len", - "entries_len", - ), - ) - if direct is not None: - return direct - - unmanaged = _hash_map_unmanaged(valobj) - if unmanaged is not None and unmanaged.GetID() != valobj.GetID(): - return _hash_map_count(unmanaged) - - metadata = _first_child(valobj, ("metadata", "header")) - if metadata is not None: - return _first_uint_child(metadata, ("count", "size", "len")) - - return None - - -def _hash_map_capacity(valobj: lldb.SBValue) -> int | None: - direct = _first_uint_child( - valobj, - ( - "capacity", - "available", - "entries_cap", - ), - ) - if direct is not None: - return direct - - unmanaged = _hash_map_unmanaged(valobj) - if unmanaged is not None and unmanaged.GetID() != valobj.GetID(): - return _hash_map_capacity(unmanaged) - - entries = _hash_map_entries(valobj) - if entries is not None: - return _slice_len(entries) - - header_capacity = _hash_map_header_capacity(valobj) - if header_capacity is not None: - return header_capacity - - return None - - -def _hash_map_header_capacity(valobj: lldb.SBValue) -> int | None: - header = _hash_map_header_data(valobj) - if header is None: - return None - return header["capacity"] - - -def _hash_map_header(valobj: lldb.SBValue) -> list[tuple[str, lldb.SBValue]]: - header = _hash_map_header_data(valobj) - if header is None: - return [] - - children: list[tuple[str, lldb.SBValue]] = [] - children.append(("header_addr", _usize_value(valobj, "header_addr", header["header_addr"]))) - children.append(("header.values", _usize_value(valobj, "header.values", header["values_addr"]))) - children.append(("header.keys", _usize_value(valobj, "header.keys", header["keys_addr"]))) - children.append(("header.capacity", _usize_value(valobj, "header.capacity", header["capacity"]))) - return children - - -def _hash_map_header_data(valobj: lldb.SBValue) -> dict[str, int] | None: - metadata = _child(valobj, "metadata") - metadata_addr = _address(metadata) - if metadata_addr is None: - return None - - process = valobj.GetProcess() - if not process.IsValid(): - return None - - address_size = process.GetAddressByteSize() - header_fields_size = address_size * 2 + 4 - header_size = _align_forward(header_fields_size, address_size) - header_addr = metadata_addr - header_size - - err = lldb.SBError() - raw = process.ReadMemory(header_addr, header_size, err) - if not err.Success() or len(raw) != header_size: - return None - - endian_prefix = _endian_prefix(process) - if address_size == 8: - values_addr = struct.unpack_from(endian_prefix + "Q", raw, 0)[0] - keys_addr = struct.unpack_from(endian_prefix + "Q", raw, 8)[0] - capacity = struct.unpack_from(endian_prefix + "I", raw, 16)[0] - elif address_size == 4: - values_addr = struct.unpack_from(endian_prefix + "I", raw, 0)[0] - keys_addr = struct.unpack_from(endian_prefix + "I", raw, 4)[0] - capacity = struct.unpack_from(endian_prefix + "I", raw, 8)[0] - else: - return None - - return { - "header_addr": header_addr, - "values_addr": values_addr, - "keys_addr": keys_addr, - "capacity": capacity, - } - - -def _hash_map_live_slots( - valobj: lldb.SBValue, - header: dict[str, int] | None, -) -> list[int]: - if header is None: - return [] - - capacity = header["capacity"] - if capacity == 0 or _suspicious_child_count(capacity): - return [] - - metadata = _child(valobj, "metadata") - metadata_addr = _address(metadata) - if metadata_addr is None: - return [] - - process = valobj.GetProcess() - if not process.IsValid(): - return [] - - err = lldb.SBError() - raw = process.ReadMemory(metadata_addr, capacity, err) - if not err.Success() or len(raw) != capacity: - return [] - - byte_order = process.GetByteOrder() - used_mask = 0x01 if byte_order == lldb.eByteOrderBig else 0x80 - return [index for index, metadata_byte in enumerate(raw) if metadata_byte & used_mask] - - -def _hash_map_key_value_types( - valobj: lldb.SBValue, -) -> tuple[lldb.SBType | None, lldb.SBType | None]: - type_name = valobj.GetTypeName() or valobj.GetType().GetName() or "" - args = _type_arguments(type_name, "HashMapUnmanaged") - if len(args) < 2: - args = _type_arguments(type_name, "HashMap") - if len(args) < 2: - return (None, None) - - target = valobj.GetTarget() - if not target.IsValid(): - return (None, None) - - key_type = _find_type(target, args[0]) - value_type = _find_type(target, args[1]) - if key_type is None or value_type is None: - return (None, None) - return (key_type, value_type) - - -def _type_arguments(type_name: str, callee: str) -> list[str]: - start = type_name.find(callee + "(") - if start < 0: - return [] - - start += len(callee) + 1 - depth = 0 - end = start - while end < len(type_name): - char = type_name[end] - if char in "([{": - depth += 1 - elif char in ")]}": - if depth == 0: - break - depth -= 1 - end += 1 - - if end >= len(type_name): - return [] - return _split_top_level_args(type_name[start:end]) - - -def _split_top_level_args(args: str) -> list[str]: - result: list[str] = [] - start = 0 - depth = 0 - for index, char in enumerate(args): - if char in "([{": - depth += 1 - elif char in ")]}": - depth -= 1 - elif char == "," and depth == 0: - result.append(args[start:index].strip()) - start = index + 1 - result.append(args[start:].strip()) - return [arg for arg in result if arg] - - -def _find_type(target: lldb.SBTarget, type_name: str) -> lldb.SBType | None: - candidates = [type_name] - if type_name.startswith("const "): - candidates.append(type_name[len("const ") :]) - - for candidate in candidates: - found = target.FindFirstType(candidate) - if found.IsValid(): - return found - - return None - - -def _hash_map_slot_child( - parent: lldb.SBValue, - header: dict[str, int] | None, - child_type: lldb.SBType | None, - slot: int, - name: str, - address_field: str, -) -> lldb.SBValue: - if header is None or child_type is None or not child_type.IsValid(): - return lldb.SBValue() - - elem_size = child_type.GetByteSize() - if elem_size == 0: - return lldb.SBValue() - - address = header[address_field] + slot * elem_size - return parent.CreateValueFromAddress(name, address, child_type) - - -def _usize_value(parent: lldb.SBValue, name: str, value: int) -> lldb.SBValue: - return parent.CreateValueFromExpression(name, str(value)) - - -def _endian_prefix(process: lldb.SBProcess) -> str: - byte_order = process.GetByteOrder() - if byte_order == lldb.eByteOrderBig: - return ">" - return "<" - - -def _align_forward(value: int, alignment: int) -> int: - return (value + alignment - 1) & ~(alignment - 1) - - -def _first_uint_child(valobj: lldb.SBValue, names: tuple[str, ...]) -> int | None: - for name in names: - result = _uint_child(valobj, name) - if result is not None: - return result - return None - - -def _hash_map_unmanaged(valobj: lldb.SBValue) -> lldb.SBValue | None: - return _first_child( - valobj, - ( - "unmanaged", - "map", - "hm", - "hash_map", - ), - ) or valobj - - -def _hash_map_entries(valobj: lldb.SBValue) -> lldb.SBValue | None: - direct = _first_child( - valobj, - ( - "entries", - "keys", - "values", - ), - ) - if direct is not None and _slice_len(direct) is not None: - return direct - - unmanaged = _hash_map_unmanaged(valobj) - if unmanaged is not None and unmanaged.GetID() != valobj.GetID(): - return _hash_map_entries(unmanaged) - - return None - - -def _hash_map_keys(valobj: lldb.SBValue) -> lldb.SBValue | None: - return _hash_map_pointer_storage(valobj, ("keys", "key_ptr", "keyPtr")) - - -def _hash_map_values(valobj: lldb.SBValue) -> lldb.SBValue | None: - return _hash_map_pointer_storage(valobj, ("values", "value_ptr", "valuePtr")) - - -def _hash_map_pointer_storage( - valobj: lldb.SBValue, - names: tuple[str, ...], -) -> lldb.SBValue | None: - direct = _first_child(valobj, names) - if direct is not None: - return direct - - unmanaged = _hash_map_unmanaged(valobj) - if unmanaged is not None and unmanaged.GetID() != valobj.GetID(): - return _hash_map_pointer_storage(unmanaged, names) - - return None - - -def _pointer_storage_child( - storage: lldb.SBValue | None, - name: str, - index: int, -) -> lldb.SBValue | None: - if storage is None: - return None - - if _slice_len(storage) is not None: - provider = SliceSyntheticProvider(storage, {}) - child = _slice_child_at(storage, index, name) - return child if child.IsValid() else None - - elem_type = _pointer_pointee_type(storage) - elem_size = _byte_size(elem_type) - child = _pointer_child_at(storage, elem_type, elem_size, index, name) - return child if child.IsValid() else None - - -def _read_u8_string_from_slice(valobj: lldb.SBValue, length: int) -> str | None: - if length == 0: - return "" - - ptr = _child(valobj, "ptr") - elem_type = _pointer_pointee_type(ptr) - if elem_type is None: - return None - - elem_name = elem_type.GetName() or "" - if elem_name not in ("u8", "const u8"): - return None - - address = _address(ptr) - if address is None: - return None - - process = valobj.GetProcess() - if not process.IsValid(): - return None - - read_len = min(length, MAX_STRING_BYTES) - err = lldb.SBError() - data = process.ReadMemory(address, read_len, err) - if not err.Success(): - return None - - decoded = data.decode("utf-8", errors="replace") - escaped = ( - decoded.replace("\\", "\\\\") - .replace("\n", "\\n") - .replace("\r", "\\r") - .replace("\t", "\\t") - .replace('"', '\\"') - ) - if read_len < length: - escaped += "..." - return escaped diff --git a/engine/lib/p2/src/queue-benchmark-cas-baseline.zig b/engine/lib/p2/src/queue-benchmark-cas-baseline.zig deleted file mode 100644 index 592d8cf..0000000 --- a/engine/lib/p2/src/queue-benchmark-cas-baseline.zig +++ /dev/null @@ -1,117 +0,0 @@ -//! Frozen pre-fetchSub implementation for queue-benchmark.zig only. -//! Do not use as a production queue or update alongside the live implementation. -const std = @import("std"); - -pub const PackedState = packed struct(u32) { - remaining_items: u24 = 0, // Unclaimed entries. - active_readers: u8 = 0, // Consumers copying descriptors. -}; - -/// Single-producer, multiple-consumer batch mailbox. -/// -/// Keep the mailbox at a stable address once shared. -/// Values are copied -/// -/// usage: -/// -/// producer: -/// queue.push(.{.x = 4}); -/// -/// consumers: -/// while(alive) { -/// if(queue.tryTake())|value| -/// { -/// self.dowork(value); -/// } -/// else -/// { -/// chillout(); -/// } -/// } -/// -pub fn CommitQueue(comptime T: type) type { - return struct { - allocator: std.mem.Allocator, - state: std.atomic.Value(PackedState) = .init(.{}), - - active: std.ArrayList(T) = .empty, - back: std.ArrayList(T) = .empty, - - pub fn init(allocator: std.mem.Allocator) @This() { - return .{ .allocator = allocator }; - } - - pub fn deinit(self: *@This()) void { - while (!self.canSubmit()) std.atomic.spinLoopHint(); - - self.active.deinit(self.allocator); - self.back.deinit(self.allocator); - } - - /// Producer only. Grows the private backbuffer as needed. - pub fn push(self: *@This(), item: T) !void { - if (self.back.items.len == std.math.maxInt(u24)) return error.BatchFull; - try self.back.append(self.allocator, item); - } - - /// Consumers. Null means the batch is empty or all 255 reader pins are in use. - pub fn tryTake(self: *@This()) ?T { - var s = self.state.load(.monotonic); - - while (true) { - if (s.remaining_items == 0 or s.active_readers == std.math.maxInt(u8)) - return null; - - // Claim one entry and pin its batch atomically. - var desired = s; - desired.remaining_items -= 1; - desired.active_readers += 1; - - if (self.state.cmpxchgWeak(s, desired, .acquire, .monotonic)) |observed| { - s = observed; - continue; - } - - // Read metadata only after successfully pinning. - const index = self.active.items.len - @as(usize, s.remaining_items); - const item = self.active.items[index]; - - self.releaseReader(); - return item; - } - } - - /// Historical release loop, intentionally frozen for A/B measurement. - fn releaseReader(self: *@This()) void { - var s = self.state.load(.monotonic); - var bailOut: u32 = 100000000; - while (bailOut > 0) : (bailOut -= 1) { - var desired = s; - desired.active_readers -= 1; - if (self.state.cmpxchgWeak(s, desired, .release, .monotonic)) |observed| { - s = observed; - continue; - } - return; - } - } - - pub fn canSubmit(self: *const @This()) bool { - const state = self.state.load(.acquire); - return state.remaining_items == 0 and state.active_readers == 0; - } - - /// Must only be called Producer only. - /// publishes the backbuffer to all consumers, - pub fn submit(self: *@This()) void { - while (!self.canSubmit()) { - std.atomic.spinLoopHint(); - } - - std.mem.swap(@TypeOf(self.active), &self.active, &self.back); - - self.back.clearRetainingCapacity(); - self.state.store(.{ .remaining_items = @intCast(self.active.items.len) }, .release); - } - }; -} diff --git a/engine/lib/p2/src/queue-benchmark.zig b/engine/lib/p2/src/queue-benchmark.zig deleted file mode 100644 index 967b5e2..0000000 --- a/engine/lib/p2/src/queue-benchmark.zig +++ /dev/null @@ -1,203 +0,0 @@ -//! One producer, N consumers. Run through `zig build bench-queues` in lib/p2. -const std = @import("std"); -const CommitQueue = @import("structures/spmc-submission-queue.zig").CommitQueue; -const ConcurrentQueue = @import("structures/concurrent-queue.zig").ConcurrentQueueU; -const CasCommitQueue = @import("queue-benchmark-cas-baseline.zig").CommitQueue; -const Kind = enum { commit, concurrent, commit_cas }; - -fn Bench(comptime kind: Kind, comptime wordCount: usize, comptime work: usize) type { - return struct { - const Item = struct { words: [wordCount]u64 }; - const Queue = switch (kind) { - .commit => CommitQueue(Item, .{ .ChunkSize = 256 }), - .commit_cas => CasCommitQueue(Item), - .concurrent => ConcurrentQueue(Item), - }; - const Worker = struct { - queue: *Queue, - gate: *std.Io.Event, - ready: *std.atomic.Value(usize), - producerDone: *std.atomic.Value(bool), - io: std.Io, - count: u64 align(64) = 0, - sum: u64 = 0, - xor: u64 = 0, - digest: u64 = 0, - bad: bool = false, - - fn run(self: *@This()) void { - _ = self.ready.fetchAdd(1, .release); - self.gate.waitUncancelable(self.io); - var output: [256]Item = undefined; - var draining = false; - while (true) { - const items: []const Item = if (kind == .commit) - self.queue.maybeTake(&output) - else blk: { - const item = if (kind == .commit_cas) self.queue.tryTake() else self.queue.pop(); - if (item) |value| { - output[0] = value; - break :blk output[0..1]; - } - break :blk &.{}; - }; - for (items) |item| { - const id = item.words[0]; - self.count += 1; - self.sum +%= id; - self.xor ^= id; - for (item.words[1..], 1..) |value, lane| { - if (value != id ^ @as(u64, @intCast(lane))) self.bad = true; - } - var result = id; - for (0..work) |_| result = (result ^ (result >> 13)) *% 0x9e3779b97f4a7c15; - self.digest +%= result; - } - if (items.len == 0) { - if (draining) return; - // After acquiring completion, recheck the queue before - // exiting: the first empty observation may predate publication. - draining = self.producerDone.load(.acquire); - std.atomic.spinLoopHint(); - } - } - } - }; - - fn makeItem(id: u64) Item { - var item: Item = undefined; - for (&item.words, 0..) |*value, lane| value.* = id ^ @as(u64, @intCast(lane)); - return item; - } - - fn flush(queue: *Queue) void { - if (kind != .concurrent) queue.submit(); - } - - fn measure(gpa: std.mem.Allocator, io: std.Io, consumers: usize, batch: usize, milliseconds: i64) !f64 { - const capacity = @max(batch, consumers); - var queue = if (kind != .concurrent) Queue.init(gpa) else try Queue.initCapacity(gpa, capacity * 2); - defer if (kind != .concurrent) queue.deinit() else queue.deinit(gpa); - if (kind != .concurrent) { - try queue.active.ensureTotalCapacity(gpa, capacity); - try queue.back.ensureTotalCapacity(gpa, capacity); - } - var gate: std.Io.Event = .unset; - var ready: std.atomic.Value(usize) = .init(0); - var producerDone: std.atomic.Value(bool) = .init(false); - var workers: [8]Worker = undefined; - var threads: [8]std.Thread = undefined; - var spawned: usize = 0; - // Even a partial spawn must release and shut down existing workers. - errdefer { - gate.set(io); - flush(&queue); - producerDone.store(true, .release); - for (threads[0..spawned]) |thread| thread.join(); - } - for (0..consumers) |i| { - workers[i] = .{ .queue = &queue, .gate = &gate, .ready = &ready, .producerDone = &producerDone, .io = io }; - threads[i] = try std.Thread.spawn(.{}, Worker.run, .{&workers[i]}); - spawned += 1; - } - while (ready.load(.acquire) != consumers) std.atomic.spinLoopHint(); - const begin = std.Io.Timestamp.now(io, .awake); - gate.set(io); - var produced: u64 = 0; - var expectedSum: u64 = 0; - var expectedXor: u64 = 0; - var batches: usize = 0; - while (true) { - for (0..batch) |_| { - try queue.push(makeItem(produced)); - expectedSum +%= produced; - expectedXor ^= produced; - produced += 1; - } - flush(&queue); - batches += 1; - // Amortize clock overhead for small batches; check every large batch - // so a 65K batch does not force millions of extra items per sample. - const clockInterval: usize = if (batch >= 10000) 1 else 64; - if (batches % clockInterval == 0 and begin.durationTo(std.Io.Timestamp.now(io, .awake)).toMilliseconds() >= milliseconds) break; - } - producerDone.store(true, .release); - for (threads[0..consumers]) |thread| thread.join(); - spawned = 0; - const elapsed = begin.durationTo(std.Io.Timestamp.now(io, .awake)).toNanoseconds(); - var count: u64 = 0; - var sum: u64 = 0; - var xor: u64 = 0; - for (workers[0..consumers]) |*worker| { - if (worker.bad) return error.CorruptPayload; - count += worker.count; - sum +%= worker.sum; - xor ^= worker.xor; - std.mem.doNotOptimizeAway(worker.digest); - } - if (count != produced or sum != expectedSum or xor != expectedXor) return error.IncorrectDelivery; - return @as(f64, @floatFromInt(count)) * 1000.0 / @as(f64, @floatFromInt(elapsed)); - } - }; -} - -fn scenario(comptime words: usize, comptime work: usize, init: std.process.Init, consumers: usize, batch: usize, sampleMs: i64, compareCas: bool) !void { - if (compareCas) return scenarioAgainst(words, work, .commit_cas, init, consumers, batch, sampleMs); - return scenarioAgainst(words, work, .concurrent, init, consumers, batch, sampleMs); -} - -fn scenarioAgainst(comptime words: usize, comptime work: usize, comptime other: Kind, init: std.process.Init, consumers: usize, batch: usize, sampleMs: i64) !void { - const S = Bench(.commit, words, work); - const C = Bench(other, words, work); - _ = try S.measure(init.gpa, init.io, consumers, batch, 100); - _ = try C.measure(init.gpa, init.io, consumers, batch, 100); - for (0..3) |sample| { - var s: f64 = undefined; - var c: f64 = undefined; - if (sample % 2 == 0) { - s = try S.measure(init.gpa, init.io, consumers, batch, sampleMs); - c = try C.measure(init.gpa, init.io, consumers, batch, sampleMs); - } else { - c = try C.measure(init.gpa, init.io, consumers, batch, sampleMs); - s = try S.measure(init.gpa, init.io, consumers, batch, sampleMs); - } - std.debug.print("{d},{d},{d},{d},{d},commit,{d:.6}\n", .{ consumers, batch, words * 8, work, sample, s }); - std.debug.print("{d},{d},{d},{d},{d},{s},{d:.6}\n", .{ consumers, batch, words * 8, work, sample, @tagName(other), c }); - } -} - -pub fn main(init: std.process.Init) !void { - var sampleMs: i64 = 400; - var minConsumers: usize = 1; - var largeBatches = false; - var compareCas = false; - const args = try init.minimal.args.toSlice(init.arena.allocator()); - for (args[1..]) |arg| { - if (std.mem.startsWith(u8, arg, "--sample-ms=")) { - sampleMs = try std.fmt.parseInt(i64, arg["--sample-ms=".len..], 10); - if (sampleMs < 1) return error.InvalidSampleDuration; - } else if (std.mem.startsWith(u8, arg, "--min-consumers=")) { - minConsumers = try std.fmt.parseInt(usize, arg["--min-consumers=".len..], 10); - if (minConsumers < 1 or minConsumers > 8) return error.InvalidConsumerCount; - } else if (std.mem.eql(u8, arg, "--large-batches")) { - largeBatches = true; - } else if (std.mem.eql(u8, arg, "--compare-cas")) { - compareCas = true; - } else return error.UnknownArgument; - } - std.debug.print("consumers,batch,payload_bytes,work_iterations,sample,queue,million_items_per_second\n", .{}); - for ([_]usize{ 1, 2, 4, 8 }) |consumers| { - if (consumers < minConsumers) continue; - if (largeBatches) { - for ([_]usize{ 10000, 65536 }) |batch| { - try scenario(2, 0, init, consumers, batch, sampleMs, compareCas); - try scenario(32, 0, init, consumers, batch, sampleMs, compareCas); - try scenario(2, 256, init, consumers, batch, sampleMs, compareCas); - } - } else { - for ([_]usize{ 1, 64, 1024 }) |batch| try scenario(2, 0, init, consumers, batch, sampleMs, compareCas); - try scenario(32, 0, init, consumers, 256, sampleMs, compareCas); - try scenario(2, 256, init, consumers, 256, sampleMs, compareCas); - } - } -} diff --git a/engine/lib/p2/src/test.zig b/engine/lib/p2/src/test.zig deleted file mode 100644 index 0d7de64..0000000 --- a/engine/lib/p2/src/test.zig +++ /dev/null @@ -1,43 +0,0 @@ -const Engine = struct {}; - -pub fn println(comptime fmt: []const u8, args: anytype) void { - std.debug.print(fmt ++ "\n", .{args}); -} - -pub fn printlns(comptime fmt: []const u8) void { - std.debug.print(fmt ++ "\n", .{}); -} - -const MyEngineSystem = struct { - pub fn init(self: *@This(), engineContext: *Engine) !void { - _ = self; - _ = engineContext; - println("initialized", .{}); - } - - pub fn tick(self: *@This(), dt: f32) void { - _ = self; - printlns("tick!"); - _ = dt; - } - - pub fn deinit(self: *@This()) void { - _ = self; - - printlns("deinitialized"); - } -}; - -const Vec2 = struct { - x: f32 = 0, - y: f32 = 0, -}; - -const Vec2d = struct { - x: f32 = 0, - y: f32 = 0, -}; - -test "testing" {} - -const std = @import("std"); diff --git a/engine/lib/p2/tools/vscode-env/README.md b/engine/lib/p2/tools/vscode-env/README.md deleted file mode 100644 index 17ace13..0000000 --- a/engine/lib/p2/tools/vscode-env/README.md +++ /dev/null @@ -1,59 +0,0 @@ -# P2 VS Code Environment - -This directory holds the repo-local definition for a pinned/custom VS Code setup. -It is meant to live under `lib/p2`, while installing generated launcher files at -the workspace root. - -## Layout - -- `extensions/`: put vendored `.vsix` files here. -- `settings/settings.json`: settings copied into the isolated VS Code user data. -- `install.sh`: installs the environment into the workspace root. - -## Install - -From `lib/p2`: - -```sh -./tools/vscode-env/install.sh -``` - -By default this creates: - -- `/.vscode-p2/` -- `/.bin/p2-code` -- `/.bin/p2-code.bat` -- `/p2.code-workspace` - -Run the environment with: - -```sh -/.bin/p2-code -``` - -The wrapper uses an isolated `--user-data-dir` and `--extensions-dir`, so custom -extensions do not affect your normal VS Code profile. - -On Windows, run: - -```bat -\.bin\p2-code.bat -``` - -## Vendored Extensions - -Drop custom or forked extensions into `extensions/` as `.vsix` files, then rerun -`install.sh`. The installer will install every `.vsix` it finds into the isolated -extension directory. - -For example: - -```sh -cp ~/dev/vscode-zig/ziglang.vscode-zig-0.6.18-custom.vsix tools/vscode-env/extensions/ -./tools/vscode-env/install.sh -``` - -Custom language extensions can live next to the tool they support, such as -`tools/riblang/vscode/`, and publish a packaged `.vsix` into this directory. -That keeps the source near the language implementation while keeping the editor -environment installer simple and pinned. diff --git a/engine/lib/p2/tools/vscode-env/extensions/.gitkeep b/engine/lib/p2/tools/vscode-env/extensions/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/engine/lib/p2/tools/vscode-env/extensions/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/engine/lib/p2/tools/vscode-env/install.bat b/engine/lib/p2/tools/vscode-env/install.bat deleted file mode 100644 index d94ac19..0000000 --- a/engine/lib/p2/tools/vscode-env/install.bat +++ /dev/null @@ -1,137 +0,0 @@ -@echo off -setlocal EnableExtensions EnableDelayedExpansion - -set "SCRIPT_DIR=%~dp0" -if "%SCRIPT_DIR:~-1%"=="\" set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%" -for %%I in ("%SCRIPT_DIR%\..\..") do set "P2_DIR=%%~fI" - -set "WORKSPACE_ROOT=" -set "CODE_BIN=code" - -:parse_args -if "%~1"=="" goto after_args -if /I "%~1"=="--workspace-root" ( - if "%~2"=="" ( - echo missing value for --workspace-root 1>&2 - exit /b 2 - ) - set "WORKSPACE_ROOT=%~2" - shift - shift - goto parse_args -) -if /I "%~1"=="--code-bin" ( - if "%~2"=="" ( - echo missing value for --code-bin 1>&2 - exit /b 2 - ) - set "CODE_BIN=%~2" - shift - shift - goto parse_args -) -if /I "%~1"=="-h" goto usage -if /I "%~1"=="--help" goto usage - -echo unknown argument: %~1 1>&2 -goto usage_error - -:after_args -if "%WORKSPACE_ROOT%"=="" ( - for /f "usebackq delims=" %%I in (`git -C "%P2_DIR%" rev-parse --show-toplevel 2^>nul`) do set "WORKSPACE_ROOT=%%I" -) -if "%WORKSPACE_ROOT%"=="" set "WORKSPACE_ROOT=%P2_DIR%" -for %%I in ("%WORKSPACE_ROOT%") do set "WORKSPACE_ROOT=%%~fI" - -set "ENV_DIR=%WORKSPACE_ROOT%\.vscode-p2" -set "BIN_DIR=%WORKSPACE_ROOT%\.bin" -set "USER_DATA_DIR=%ENV_DIR%\user-data" -set "EXTENSIONS_DIR=%ENV_DIR%\extensions" -set "WORKSPACE_FILE=%WORKSPACE_ROOT%\p2.code-workspace" - -mkdir "%BIN_DIR%" 2>nul -mkdir "%USER_DATA_DIR%\User" 2>nul -mkdir "%EXTENSIONS_DIR%" 2>nul -copy /Y "%SCRIPT_DIR%\settings\settings.json" "%USER_DATA_DIR%\User\settings.json" >nul - -( - echo @echo off - echo setlocal - echo. - echo if "%%CODE_BIN%%"=="" ^( - echo set "CODE_BIN=%CODE_BIN%" - echo ^) - echo. - echo set "WORKSPACE_ROOT=%WORKSPACE_ROOT%" - echo set "ENV_DIR=%%WORKSPACE_ROOT%%\.vscode-p2" - echo. - echo "%%CODE_BIN%%" ^^ - echo --user-data-dir "%%ENV_DIR%%\user-data" ^^ - echo --extensions-dir "%%ENV_DIR%%\extensions" ^^ - echo "%%WORKSPACE_ROOT%%\p2.code-workspace" ^^ - echo %%* -) > "%BIN_DIR%\p2-code.bat" - -set "P2_REL=%P2_DIR%" -set "P2_REL=!P2_REL:%WORKSPACE_ROOT%=!" -if "!P2_REL:~0,1!"=="\" set "P2_REL=!P2_REL:~1!" -set "P2_REL=!P2_REL:\=/!" - -( - echo { - echo "folders": [ - echo { - echo "name": "snow", - echo "path": "." - echo }, - echo { - echo "name": "p2", - echo "path": "!P2_REL!" - echo } - echo ], - echo "settings": { - echo "editor.foldingStrategy": "auto" - echo } - echo } -) > "%WORKSPACE_FILE%" - -where "%CODE_BIN%" >nul 2>nul -if errorlevel 1 ( - echo VS Code binary not found: %CODE_BIN% 1>&2 - echo Skipping .vsix installation. Re-run with --code-bin PATH when available. 1>&2 -) else ( - set "FOUND_VSIX=0" - for %%F in ("%SCRIPT_DIR%\extensions\*.vsix") do ( - if exist "%%~fF" ( - set "FOUND_VSIX=1" - "%CODE_BIN%" --extensions-dir "%EXTENSIONS_DIR%" --install-extension "%%~fF" - ) - ) - if "!FOUND_VSIX!"=="0" echo No vendored .vsix files found in %SCRIPT_DIR%\extensions -) - -echo Installed P2 VS Code environment: -echo windows: %BIN_DIR%\p2-code.bat -echo workspace: %WORKSPACE_FILE% -echo user data: %USER_DATA_DIR% -echo extensions:%EXTENSIONS_DIR% -echo. -echo Run: -echo %BIN_DIR%\p2-code.bat -exit /b 0 - -:usage -echo Usage: install.bat [--workspace-root PATH] [--code-bin CODE] -echo. -echo Installs the P2 VS Code environment at the workspace root. -echo. -echo Options: -echo --workspace-root PATH Override the detected Git root. -echo --code-bin CODE VS Code binary to use for installing .vsix files. -echo -h, --help Show this help. -exit /b 0 - -:usage_error -call :usage -exit /b 2 - diff --git a/engine/lib/p2/tools/vscode-env/install.sh b/engine/lib/p2/tools/vscode-env/install.sh deleted file mode 100755 index a69c8aa..0000000 --- a/engine/lib/p2/tools/vscode-env/install.sh +++ /dev/null @@ -1,145 +0,0 @@ -#!/usr/bin/env sh -set -eu - -usage() { - cat <<'EOF' -Usage: install.sh [--workspace-root PATH] [--code-bin CODE] - -Installs the P2 VS Code environment at the workspace root. - -Options: - --workspace-root PATH Override the detected Git root. - --code-bin CODE VS Code binary to use for installing .vsix files. - -h, --help Show this help. -EOF -} - -script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) -p2_dir=$(CDPATH= cd -- "$script_dir/../.." && pwd) -workspace_root= -code_bin=${CODE_BIN:-code} - -while [ "$#" -gt 0 ]; do - case "$1" in - --workspace-root) - [ "$#" -ge 2 ] || { - echo "missing value for --workspace-root" >&2 - exit 2 - } - workspace_root=$2 - shift 2 - ;; - --code-bin) - [ "$#" -ge 2 ] || { - echo "missing value for --code-bin" >&2 - exit 2 - } - code_bin=$2 - shift 2 - ;; - -h|--help) - usage - exit 0 - ;; - *) - echo "unknown argument: $1" >&2 - usage >&2 - exit 2 - ;; - esac -done - -if [ -z "$workspace_root" ]; then - workspace_root=$(git -C "$p2_dir" rev-parse --show-toplevel 2>/dev/null || printf '%s\n' "$p2_dir") -fi - -workspace_root=$(CDPATH= cd -- "$workspace_root" && pwd) -env_dir="$workspace_root/.vscode-p2" -bin_dir="$workspace_root/.bin" -user_data_dir="$env_dir/user-data" -extensions_dir="$env_dir/extensions" -workspace_file="$workspace_root/p2.code-workspace" - -mkdir -p "$bin_dir" "$user_data_dir/User" "$extensions_dir" -cp "$script_dir/settings/settings.json" "$user_data_dir/User/settings.json" - -cat > "$bin_dir/p2-code" < "$bin_dir/p2-code.bat" < "$workspace_file" </dev/null 2>&1; then - found_vsix=false - for vsix in "$script_dir"/extensions/*.vsix; do - [ -e "$vsix" ] || continue - found_vsix=true - "$code_bin" --extensions-dir "$extensions_dir" --install-extension "$vsix" - done - if [ "$found_vsix" = false ]; then - echo "No vendored .vsix files found in $script_dir/extensions" - fi -else - echo "VS Code binary not found: $code_bin" >&2 - echo "Skipping .vsix installation. Re-run with --code-bin PATH when available." >&2 -fi - -cat <