Repository navigation
Conversation
Rigidity
force-pushed
the
rigidity/inference-restructure-13d
branch
from
November 19, 2026 07:00
30264e8 to
5ab0f78
Compare
…s bounds are checked A bound of an instance can refer to the instance of a generic function compared inside of the same comparison, such as B ≥ (T, T) from fn<T>() -> (T, T) compared with fn() -> B. That instance was rigid by then, so B ≤ (Int, Int) failed, although T can be Int (#363). Each such instance can now still be instantiated while the outer bounds are checked, once for all of them, and its own bounds are checked again with what that adds to them.
- Check the instances' bounds in place rather than cloning them - Take the inner instances' index right after binding - Update the docs of Instance and instantiable_from
A comparison reused from the memo, or a revisit, applied its summary with the instances of the generic functions compared inside of it as rigid binders, so an enclosing comparison couldn't instantiate them while checking its bounds, and the memo changed the result. A summary now carries the bounds of each such instance that the bounds of its key's instances refer to, and applying it makes those binders instances again. - Test it with the memo on and off, and with a struct whose two fields reuse one comparison - Test that an inner instance is instantiated once, along with its own bounds
…nd through more calls
- Keep three copies of a summary component that bounds a local binder, since checking an inner instance's bounds against each other can need bounds from two other copies - Build the summary in two passes, and the applied local binders up front - Drop a needless clone, and update the docs that still said local binders are rigid
…h itself An inner instance can be instantiated while an enclosing comparison checks bounds that refer to it on both sides, such as (T, T) against itself. Bounding it by itself conflicted with its other bounds once it was rigid, so a program main accepts was rejected.
Replaces the arm for a binder compared with itself with an occurs check on the instance arms, which also covers T ≤ T | nil while an enclosing comparison checks bounds on both sides.
Exporting every inner instance's own bounds in summaries made them grow without bound on nested programs (corpus seeds 834 and 877 went from rejected in under a second to giving up), since those bounds refer to more local binders, which merge copies into ever larger components. An inner instance is now reopened only if its own bounds refer to no binder, which is intrinsic to it, so a memo hit, a revisit and computing it again agree, and its exported bounds are closed. The others stay rigid, as on main. - Reopened instances are marked open rather than lowering instantiable_from, and choices are recorded while any is open, so a union member that holds without bounds still holds the others - Test the occurs check at type level
…ed instances rigid without inference
Rigidity
force-pushed
the
rigidity/inference-restructure-13d
branch
from
November 19, 2026 08:43
dc74328 to
c63ebc2
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#362's step 13d. A generic function compared inside another function comparison can now still be instantiated while that comparison checks its bounds.
Closes #363
Part of #362
The problem (#363)
This failed with "Cannot assign
fn<B>(function: fn() -> B) -> Btofn(a: fn<T>() -> (T, T)) -> (Int, Int)". Comparingcallwith that type gives itsB'the boundsB' ≥ (T', T'), fromfn<T>() -> (T, T)againstfn() -> B', andB' ≤ (Int, Int). ButT', the instance ofpairs's generic, was rigid once its own function comparison had finished, so(T', T') ≤ (Int, Int)failed, althoughT' = Intworks.The change (
compare_structure's function arm,check_bounds)Instance::open). They keep their bounds after their own comparison finishes.is_closed). One that refers to other binders stays rigid, which can only reject more. Without this, summaries grew without bound on two corpus programs (seeds 834 and 877 timed out or gave up).T' ≥ Intfrom a parameter can't also beBytes32. Enclosing comparisons' instances stay rigid.refers_to). OtherwiseT' ≤ T'orT' ≤ T' | nil, from an inner function compared with itself, conflicted with its other bounds once it was rigid again (Twin,Optin the snapshot tests).≤ Any.apply_summarymakes those binders instances again.canonicalizekeeps a third copy of a component that bounds a local.holds_without_inferenceclears the reopened flags while it runs, so a union member that fails there leaves no bound on a reopened instance.Breaking changes
None. The change only accepts more programs. The fuzzer and corpus runs below show no program going from accepted to rejected and no change in output.
Limitations
deeper_instances_stay_rigidpins one that's still rejected.(G, G)against two function types thatGis each assignable to is stillInvalid. The compiler accepts the Rue equivalent. This is documented ontest_bound_added_inside_reused.(T, Int) ≤ TwithT = Anyis rejected, as on main.Results
Head
cf137f1fwas checked against main09000478. The full four-configuration run was ondc74328eagainst main6aea07a5, before the rebase and the last two fixes. After them, one range per generator was run again and matched.dc74328e)dc74328e)fn<T>(pair: (T, fn(a: T) -> Int)) -> Intpassed a union of pairs whose functions are generic.generic_inference_instantiated_through_candidate.rue.nested-corpus, seeds 0..2500): identical to main, 626 compiled and 1,874 rejected, with none too complex, timed out or crashed.Review rounds
Twin): fixed with the occurs check.Opt(T' ≤ T' | nil): fixed with the occurs check. The fuzzer and corpus runs then found the corpus regressions (seeds 834 and 877), fixed by reopening closed instances only. That brokeOptagain, because local choices weren't opened while instances were reopened. Fixed through theopencounter.c63ebc23, pinned bytest_bound_added_inside_reusedandbound_kept_when_reused.holds_without_inference. Fixed inc63ebc23.cf137f1fby clearing the flags, pinned by the nested case ofreopened_instances_stay_rigid_without_inference.Provisional decisions, for you
≤ Anyin a summary, a bound that always holds, rather than a per-local flag onSummary.canonicalize, against two for the others. No test shows a result that needs the third, so it's kept on the argument alone.Note
Medium Risk
This changes when a generic function's instance can be instantiated in
rue-types' comparisons, and what memo summaries carry, so a mistake would accept ill-typed programs. It only accepts more programs. Instances that refer to other binders stay rigid, the second check keeps each reopened instance's bounds, and the memo on/off differentials, the fuzzer (0 unsound) and the corpus all agree.compare.rs: reopening in the function arm,check_bounds,is_closed, the occurs check, summaries exporting and re-creating inner instances, andholds_without_inference.summary.rs: the copy count for components that bound a local incanonicalize.