Fix precedencegroup and operator decl lookup

Re-implement operator and precedencegroup decl
lookup to use `namelookup::getAllImports` and
existing decl shadowing logic. This allows us to
find operator decls through `@_exported` imports,
prefer operator decls defined in the same module
over imported decls, and fixes a couple of other
subtle issues.

Because this new implementation is technically
source breaking, as we can find multiple results
where we used to only find one result, it's placed
behind the new Frontend flag
`-enable-new-operator-lookup` (with the aim of
enabling it by default when we get a new language
mode).

However the new logic will always be used if the
result is unambiguous. This means that e.g
`@_exported` operators will be instantly available
as long as there's only one candidate. If multiple
candidates are found, we fall back to the old
logic.

Resolves SR-12132.
Resolves rdar://59198796.
This commit is contained in:
Hamish Knight
2020-05-18 14:33:43 -07:00
parent 912baa8a8b
commit cc062ee2bb
24 changed files with 760 additions and 451 deletions

View File

@@ -2247,9 +2247,6 @@ OperatorDecl *ModuleFile::lookupOperator(Identifier name,
if (getStableFixity(fixity) == item.first)
return cast<OperatorDecl>(getDecl(item.second));
}
// FIXME: operators re-exported from other modules?
return nullptr;
}