granite-rust/compiler
Jack Huey b6c87c555f Implementation for 65853
This attempts to bring better error messages to invalid method calls, by applying some heuristics to identify common mistakes.

The algorithm is inspired by Levenshtein distance and longest common sub-sequence.   In essence, we treat the types of the function, and the types of the arguments you provided as two "words" and compute the edits to get from one to the other.

We then modify that algorithm to detect 4 cases:

 - A function input is missing
 - An extra argument was provided
 - The type of an argument is straight up invalid
 - Two arguments have been swapped
 - A subset of the arguments have been shuffled

(We detect the last two as separate cases so that we can detect two swaps, instead of 4 parameters permuted.)

It helps to understand this argument by paying special attention to terminology: "inputs" refers to the inputs being *expected* by the function, and "arguments" refers to what has been provided at the call site.

The basic sketch of the algorithm is as follows:

 - Construct a boolean grid, with a row for each argument, and a column for each input.  The cell [i, j] is true if the i'th argument could satisfy the j'th input.
 - If we find an argument that could satisfy no inputs, provided for an input that can't be satisfied by any other argument, we consider this an "invalid type".
 - Extra arguments are those that can't satisfy any input, provided for an input that *could* be satisfied by another argument.
 - Missing inputs are inputs that can't be satisfied by any argument, where the provided argument could satisfy another input
 - Swapped / Permuted arguments are identified with a cycle detection algorithm.

As each issue is found, we remove the relevant inputs / arguments and check for more issues.  If we find no issues, we match up any "valid" arguments, and start again.

Note that there's a lot of extra complexity:
 - We try to stay efficient on the happy path, only computing the diagonal until we find a problem, and then filling in the rest of the matrix.
 - Closure arguments are wrapped in a tuple and need to be unwrapped
 - We need to resolve closure types after the rest, to allow the most specific type constraints
 - We need to handle imported C functions that might be variadic in their inputs.

I tried to document a lot of this in comments in the code and keep the naming clear.
2022-04-16 02:26:56 -04:00
..
rustc Propagate parallel_compiler feature through rustc crates. Turned off feature gives change of builded crates: 238 -> 224. 2022-03-28 08:41:12 +03:00
rustc_apfloat Addressed comments by @compiler-errors and @bjorn3 2022-03-30 17:04:46 -04:00
rustc_arena mark FIXMES for all the places found that are probably offset_from 2022-03-29 20:18:28 -04:00
rustc_ast Use const Box::default in P::<[T]>::new 2022-04-11 12:14:18 -07:00
rustc_ast_lowering diagnostics: use correct span for const generics 2022-04-04 12:16:20 -07:00
rustc_ast_passes [let_chains] Forbid let inside parentheses 2022-03-31 18:33:05 -03:00
rustc_ast_pretty Remove Nonterminal::NtTT. 2022-03-28 10:03:02 +11:00
rustc_attr Rollup merge of #94948 - jhpratt:rustc_deprecated, r=Dylan-DPC 2022-03-20 09:14:59 +01:00
rustc_borrowck Add new MutatatingUseContexts for deinit and SetDiscriminant 2022-04-11 09:26:26 -04:00
rustc_builtin_macros Auto merge of #95697 - klensy:no-strings, r=petrochenkov 2022-04-09 13:15:26 +00:00
rustc_codegen_cranelift Add new Deinit statement kind 2022-04-11 08:55:03 -04:00
rustc_codegen_gcc Use WrappingRange::full instead of hand-rolling it 2022-04-05 13:18:22 +00:00
rustc_codegen_llvm Auto merge of #95656 - cjgillot:no-id-hashing-mode, r=Aaron1011 2022-04-13 11:27:17 +00:00
rustc_codegen_ssa Auto merge of #95968 - davidtwco:translation-lazy-fallback, r=oli-obk 2022-04-13 21:04:19 +00:00
rustc_const_eval Remove rule that place loads may not happen with variant index set 2022-04-11 15:56:04 -04:00
rustc_data_structures Remove NodeIdHashingMode. 2022-04-12 19:59:32 +02:00
rustc_driver errors: lazily load fallback fluent bundle 2022-04-13 02:44:59 +01:00
rustc_error_codes rework error messages for incorrect inherent impls 2022-03-30 11:23:58 +02:00
rustc_error_messages errors: lazily load fallback fluent bundle 2022-04-13 02:44:59 +01:00
rustc_errors errors: lazily load fallback fluent bundle 2022-04-13 02:44:59 +01:00
rustc_expand Auto merge of #95928 - nnethercote:rm-TokenTree-Clone, r=petrochenkov 2022-04-14 06:36:04 +00:00
rustc_feature Fix crate_type attribute to not warn on duplicates 2022-04-10 16:35:37 -07:00
rustc_fs_util Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_graphviz eplace usages of vec![].into_iter with [].into_iter 2022-01-09 14:09:25 +11:00
rustc_hir Auto merge of #95656 - cjgillot:no-id-hashing-mode, r=Aaron1011 2022-04-13 11:27:17 +00:00
rustc_hir_pretty resolve: Fix incorrect results of opt_def_kind query for some built-in macros 2022-02-24 22:54:36 +03:00
rustc_incremental check_doc_keyword: don't alloc string for emptiness check 2022-04-08 11:45:57 +03:00
rustc_index Spellchecking compiler comments 2022-03-30 15:14:15 -04:00
rustc_infer Implementation for 65853 2022-04-16 02:26:56 -04:00
rustc_interface sess: try sysroot candidates for fluent bundle 2022-04-12 10:15:37 +01:00
rustc_lexer Reduce max hash in raw strings from u16 to u8 2022-03-23 22:13:55 +01:00
rustc_lint Auto merge of #94527 - oli-obk:undef_scalars, r=nagisa,erikdesjardin 2022-04-05 16:46:13 +00:00
rustc_lint_defs Split fuzzy_provenance_casts into lossy and fuzzy, feature gate and test it 2022-04-08 17:41:28 +02:00
rustc_llvm Respect -Z verify-llvm-ir and other flags that add extra passes when combined with -C no-prepopulate-passes in the new LLVM Pass Manager. 2022-04-10 15:40:16 -04:00
rustc_log Make rustc_log doc test runnable 2022-01-03 22:31:56 -08:00
rustc_macros macros: support translatable suggestions 2022-04-05 07:01:03 +01:00
rustc_metadata Simplify FixedSizeEncoding using const generics. 2022-04-10 16:59:51 +02:00
rustc_middle Auto merge of #95656 - cjgillot:no-id-hashing-mode, r=Aaron1011 2022-04-13 11:27:17 +00:00
rustc_mir_build Auto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk 2022-04-13 07:50:56 +00:00
rustc_mir_dataflow Add new MutatatingUseContexts for deinit and SetDiscriminant 2022-04-11 09:26:26 -04:00
rustc_mir_transform Remove inlining cost of Deinit statements 2022-04-11 10:23:33 -04:00
rustc_monomorphize Use def_key in tcx.item_name when possible. 2022-04-09 10:54:43 +02:00
rustc_parse use to_string instead of format! 2022-04-12 07:51:23 +09:00
rustc_parse_format Spellchecking compiler comments 2022-03-30 15:14:15 -04:00
rustc_passes check_doc_keyword: don't alloc string for emptiness check 2022-04-08 11:45:57 +03:00
rustc_plugin_impl replace dynamic library module with libloading 2021-12-06 12:03:47 -05:00
rustc_privacy do use ty::Const in patterns and abstract consts 2022-04-02 12:20:59 +02:00
rustc_query_impl rework implementation for inherent impls for builtin types 2022-03-30 11:23:58 +02:00
rustc_query_system Remove NodeIdHashingMode. 2022-04-12 19:59:32 +02:00
rustc_resolve Rollup merge of #95918 - compiler-errors:issue-95878, r=cjgillot 2022-04-12 23:16:59 +02:00
rustc_save_analysis Rollup merge of #95497 - nyurik:compiler-spell-comments, r=compiler-errors 2022-03-31 04:57:28 +02:00
rustc_serialize errors: implement fallback diagnostic translation 2022-04-05 07:01:02 +01:00
rustc_session errors: lazily load fallback fluent bundle 2022-04-13 02:44:59 +01:00
rustc_span Auto merge of #95981 - martingms:invert-line-offset-parsing, r=nnethercote 2022-04-13 23:18:33 +00:00
rustc_symbol_mangling Auto merge of #95656 - cjgillot:no-id-hashing-mode, r=Aaron1011 2022-04-13 11:27:17 +00:00
rustc_target trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
rustc_trait_selection Implementation for 65853 2022-04-16 02:26:56 -04:00
rustc_traits Remove opaque type obligation and just register opaque types as they are encountered. 2022-03-28 16:57:45 +00:00
rustc_ty_utils Avoid accessing HIR from MIR queries. 2022-04-10 13:08:36 +02:00
rustc_type_ir Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk" 2022-03-28 16:27:14 +00:00
rustc_typeck Implementation for 65853 2022-04-16 02:26:56 -04:00