Bring constraints into scope when a generic calls a template. (#2878)

When a template has an argument that involves a generic parameter, we're supposed to delay instantiation until we know the concrete value, but explorer is not set up to do that yet, so for now we instead instantiate the template with the symbolic argument. When that happens, bring the constraints on the generic parameter into scope so they can be used inside the template instantiation.

This requires adding a new search over a value for the generic parameters that appear within it; a `VisitNestedValues` visitor is added to visit all the `Value`s nested with a value, and also convert an existing place where we were doing the same thing in a way that was incorrect (but harmlessly incorrect for now) to use it.

This is needed by #2881, which needs implementations of `ImplicitAs` for nested types when instantiating a builtin impl of `ImplicitAs` for an aggregate type.

Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
Richard Smith
2023-06-09 10:09:52 -07:00
committed by GitHub
co-authored by Geoff Romer
parent c43839e1b1
commit 4e1adcf4c7
5 changed files with 169 additions and 29 deletions
+2 -2
View File
@@ -106,8 +106,8 @@ class Pattern : public AstNode {
};
// Call the given `visitor` on all patterns nested within the given pattern,
// including `pattern` itself. Aborts and returns `false` if `visitor` returns
// `false`, otherwise returns `true`.
// including `pattern` itself, in a preorder traversal. Aborts and returns
// `false` if `visitor` returns `false`, otherwise returns `true`.
auto VisitNestedPatterns(const Pattern& pattern,
llvm::function_ref<bool(const Pattern&)> visitor)
-> bool;