Skip to content

[pull] master from ruby:master#1084

Merged
pull[bot] merged 5 commits into
turkdevops:masterfrom
ruby:master
Jun 5, 2026
Merged

[pull] master from ruby:master#1084
pull[bot] merged 5 commits into
turkdevops:masterfrom
ruby:master

Conversation

@pull
Copy link
Copy Markdown

@pull pull Bot commented Jun 5, 2026

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

nobu and others added 5 commits June 5, 2026 22:38
…simplify the transition from a JSON_PHASE_VALUE to the next phase.

ruby/json@887274e642
Extracted from: ruby/json#994

Modern compilers shouldn't have problem computing `strlen` at
compile time and generating the same code.

ruby/json@b07f74bd73
`LoadField` has an associated `return_type` field that's set depending on the type of load. When an object's shape transitions its storage strategy (embedded->heap), the return type may change (e.g., `BasicObject` to `CPtr`). If that shape layout transition is sandwiched between two `LoadField` inside the same block, it's possible we will see two different return types when reading from the same offset of the same object.

Load-store forwarding will rightfully eliminate the second `LoadField`. However, had it not been removed, we'd have two resulting bit-for-bit equal values with two different associated types. That confuses the type checker and so semantically valid code will panic with a `MismatchedOperandType`.

I ran across this while working on GH-16966. I've pulled it out here to make review easier and because the fix doesn't touch any inlining code. We haven't run into this thus far because a same-block shape storage transition emits a `SetIvar`, which has a broad enough effect that load-store forwarding reset its cache. If anything along that chain changes then we could get into this state without inlining. It's a lot to keep track of so I think we should tackle this broadly.

I chatted with @tekknolagi about the general problem. A simple or obvious solution did not present itself. This PR does not fix the broader problem; it temporarily patches over the `MismatchedOperandType` by preserving duplicate loads if the return value would be different. This is not ideal and will need to be reverted when a comprehensive solution is implemented. But, it's enough to satisfy the type checker.
Object tracing listens to the NEWOBJ hook to see all objects allocated
while it is active. Previously it also enabled a FREEOBJ tracepoint to
drop each object's record as the object was freed.

However the FREEOBJ tracepoint only fires while tracing is active. An
object recorded during tracing can be freed after tracing stops, and
that free was missed, leaving a stale record in object_table keyed by a
freed object. These dangling keys are unsafe during compaction, which
was previously mitigated with rb_gc_pointer_to_heap_p (which I'd like to
stop using). These dangling keys could also become incorrectly
associated with a new object allocated in its place.

Instead we can declare object_table's keys as weak references. The GC
then invokes our weak reference callback on every collection, whether or
not tracing is running, letting us reap the records of objects about to
be freed. This callback runs before the FREEOBJ hook, which makes the
FREEOBJ tracepoint unnecessary.
@pull pull Bot locked and limited conversation to collaborators Jun 5, 2026
@pull pull Bot added the ⤵️ pull label Jun 5, 2026
@pull pull Bot merged commit dd9213c into turkdevops:master Jun 5, 2026
1 check was pending
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants