Repository navigation
Partial and _ generic arguments at calls - #1990
Merged
Merged
Conversation
When a call left a function's generic parameter uninferred, 8-0031 suggested an annotation of the function item's type, such as "consider giving `: fn width<_>` here", which can't be written. Name the parameter instead, and show the generic arguments that would give it: "cannot infer the const parameter `N` of `width`" and "consider giving it explicitly: `width<N>`".
A call had to give all of its callee's generic arguments or none: `op<1>(c)` for `fn op<const N: u64, F: Rules>(_ c: Cursor<F>)` was 8-0022. Now the given arguments fill the parameters from the left, and each omitted parameter takes its default or is inferred, as when no arguments are given. 8-0022 now reports only too many arguments.
`op<1, _>(c)` didn't parse: the generic argument list failed, so `<` was read as a comparison. `_` is now a generic argument of its own kind in the parser, AST, HIR, formatter and tree-sitter grammar, and the vendored tree-sitter wasm is regenerated. Anywhere it is written, `_` is reported as 3-0094 for now.
A `_` among a call's generic arguments now stays the inference variable its callee was instantiated with, even where the parameter has a default, so `op<1, _>(c)` infers `F` and `len<_, 3>(xs)` gives a later argument while inferring an earlier one. This covers function, method and associated function calls and function item values. Anywhere else, including inside a call's argument as in `f<Vec<_>>(x)`, `_` is still 3-0094.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
A call may now give only some of its callee's generic arguments. They fill the parameters from the left, and each one left out takes its default or is inferred, as when none are given:
op<1>(c)callsfn op<const N: u64, F: Rules>(_ c: Cursor<F>)withFinferred fromc. Generic handlers like fevm's can then writeself.op_push<1>(c, mut tracer)rather than spelling out types the arguments already give._asks for one argument to be inferred, even where the parameter has a default, so a later argument can be given while an earlier one is inferred:len<_, 3>(xs). It is allowed only as a whole generic argument of a call (function, method and associated function calls, and function item values); anywhere else it is 3-0094. The parser, formatter and tree-sitter grammar accept it, and the vendored tree-sitter wasm is regenerated.8-0022 now reports only too many generic arguments. When a call leaves a parameter uninferred, 8-0031 names the parameter and shows the call that would give it, instead of suggesting an unwritable
: fn op<_>annotation.