-
Notifications
You must be signed in to change notification settings - Fork 18k
go/types, types2: correctly handle some recursive constraint type inference cases - don't bail out #48656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Related: Sometimes we get fairly different error messages for different orders of parameters and arguments - i.e., the error depends on which type is inferred first. It would be good to be independent of that order. |
Change https://golang.org/cl/352832 mentions this issue: |
If the type T inferred for a type parameter P is P itself (or a derived type containing P), a subsequent unification step leads to infinite recursion: at each encounter of P with the already inferred type T (which is or contains P), P stands for that T and the recursive matching process continues with T, which inevitably contains P again and recursion never terminates. This CL introduces a set of masks, one for each type parameter. When a type parameter is encountered for which a type has already been inferred, the type parameter is "masked" for the recursive matching of the inferred type. Masking makes the type parameter "invisible" such that it will be handled like any other type and not unpacked further. Fixes #48619. For #48656. Change-Id: Ic1d938322be51fd44323ea14f925303f58b27c97 Reviewed-on: https://go-review.googlesource.com/c/go/+/352832 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]>
Change https://golang.org/cl/353029 mentions this issue: |
This is an almost clean port of CL 352832 from types2 to go/types: The nest files and unify.go where copied verbatim; unify.go was adjusted with correct package name, a slightly different comment was restored to what it was. The test files got adjustments for error position. infer.go got a missing _Todo error code. For #48619. For #48656. Change-Id: Ia1a2d09e8bb37a85032b4b7e7c7a0b08e8c793a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/353029 Trust: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]>
Change https://golang.org/cl/354690 mentions this issue: |
…"fix" The "fix" (CL 352832) for #48619 was incorrect and broke the unification algorithm in some cases (e.g., #48695). This CL reverts the changes made by CL 352832 to unify.go, and comments out code in corresponding tests. As a result, #48695 will be fixed, and we will re-open #48619. Fixes #48695. For #48619. For #48656. Change-Id: I91bc492062dbcc8dae7626f6b33f6dfabf48bcb8 Reviewed-on: https://go-review.googlesource.com/c/go/+/354690 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
Any update on this? Is there anything still need to be done after the CLs above? (The original example still falls into infinite recursion.) Thanks. |
Change https://golang.org/cl/377954 mentions this issue: |
This is a stop gap solution to avoid panics due to stack overflow during type unification. While this doesn't address the underlying issues (for which we are still investigating the correct approach), it prevents a panic during compilation and reports a (possibly not quite correct) error message. If the programs are correct in the first place, manually providing the desired type arguments is a viable work-around, resulting in code that will continue to work even when the issues here are fixed satisfactorily. For #48619. For #48656. Change-Id: I13bb14552b38b4170b5a1b820e3172d88ff656ec Reviewed-on: https://go-review.googlesource.com/c/go/+/377954 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]>
With the above CL this doesn't crash anymore. Still needs a proper fix but not a release blocker anymore. |
This reports an ok error message and doesn't crash anymore. Leaving for 1.19. |
Change https://go.dev/cl/385494 mentions this issue: |
This is a stop gap solution to avoid panics due to stack overflow during type unification. While this doesn't address the underlying issues (for which we are still investigating the correct approach), it prevents a panic during compilation and reports a (possibly not quite correct) error message. If the programs are correct in the first place, manually providing the desired type arguments is a viable work-around, resulting in code that will continue to work even when the issues here are fixed satisfactorily. For golang#48619. For golang#48656. Change-Id: I13bb14552b38b4170b5a1b820e3172d88ff656ec Reviewed-on: https://go-review.googlesource.com/c/go/+/377954 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]>
Reminder issue: when type checking recursive function instances that use constraint type inference, we need to either succeed or produce a useful message. For example:
Case 1 currently fails with stack overflow (see also #48619), and case 2 fails with a not-very-useful error message ("cannot infer P ([ ])").
CC @griesemer
The text was updated successfully, but these errors were encountered: