Skip to content

Commit f98f70c

Browse files
youknowdotcodex
andauthored
Share code construction and comparison controls (#9713)
* Preserve code comparison and hashing callbacks Assisted-by: OpenAI Codex:model version not exposed * Share code construction and replacement controls Preserve argument owners, signed validation, audit and name-conversion order through shared construction. Match optional closure tuples and replacement controls without invoking tuple subclass iteration. Assisted-by: OpenAI Codex:model version not exposed * Use canonical code constructor argument names Remove redundant pyarg name overrides by naming the FromArgs fields codestring and constants. Preserve constructor storage mapping and Python signatures. Assisted-by: OpenAI: undisclosed * Rely on scope cleanup for redundant explicit drops Preserve callback ownership, release ordering, and retained argument owners. Assisted-by: Codex:model-version-unavailable * Use shared binding validation for retained code arguments Forward the derived binding metadata and let bind_for validate once before converting. Preserve original argument owners through conversion and audit callbacks. Assisted-by: OpenAI Codex:GPT-6 --------- Co-authored-by: Codex <codex@openai.com>
1 parent 08861e0 commit f98f70c

2 files changed

Lines changed: 511 additions & 376 deletions

File tree

‎crates/compiler-core/src/bytecode.rs‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -969,26 +969,37 @@ impl CodeUnits {
969969
&self,
970970
resolve: impl Fn(usize, Instruction) -> Instruction,
971971
) -> Vec<u8> {
972-
let len = self.len();
973-
let mut out = Vec::with_capacity(len * 2);
974-
let mut i = 0;
975-
while i < len {
976-
let op = resolve(i, self.read_op(i)).deoptimize();
977-
let arg = self.read_arg(i);
978-
let caches = op.cache_entries();
979-
out.push(u8::from(op));
980-
out.push(u8::from(arg));
972+
let mut out = Vec::with_capacity(self.len() * 2);
973+
for unit in self.original_instructions_with(resolve) {
974+
out.push(u8::from(unit.op));
975+
out.push(u8::from(unit.arg));
981976
// Zero-fill all CACHE entries (counter + cached data)
982-
for _ in 0..caches {
983-
i += 1;
977+
for _ in 0..unit.op.cache_entries() {
984978
out.push(0); // op = Cache = 0
985979
out.push(0); // arg = 0
986980
}
987-
i += 1;
988981
}
989982
out
990983
}
991984

985+
/// Iterate over deoptimized instructions, skipping inline cache data.
986+
/// `resolve` restores instrumentation placeholders before resolving base opcodes.
987+
pub fn original_instructions_with(
988+
&self,
989+
resolve: impl Fn(usize, Instruction) -> Instruction,
990+
) -> impl Iterator<Item = CodeUnit> {
991+
let mut i = 0;
992+
core::iter::from_fn(move || {
993+
if i >= self.len() {
994+
return None;
995+
}
996+
let op = resolve(i, self.read_op(i)).deoptimize();
997+
let unit = CodeUnit::new(op, self.read_arg(i));
998+
i += 1 + op.cache_entries();
999+
Some(unit)
1000+
})
1001+
}
1002+
9921003
/// Initialize adaptive warmup counters for all cacheable instructions.
9931004
/// Called lazily at RESUME (first execution of a code object).
9941005
/// Counters are stored out-of-line to preserve `op = Instruction::Cache`.

0 commit comments

Comments
 (0)