mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 22:02:33 +01:00
Fix a collection of issues that were preventing lowering for overloaded operators from working. Instead of creating `import_ref` instructions during name lookup in the current block, whatever that might be, we now create them in the `file` block always. This avoids inserting them into blocks that might not be intended to contain them, such as functions, and avoids the IR generated for a function depending on which names we happen to have looked up first. When importing a class, function, or interface, import its enclosing scope ID. This is necessary to allow us to distinguish between functions at interface scope, which shouldn't be lowered, and other functions, and will also be used in future to provide qualified names for declarations when printing types. In order to support this: - Track the constant values of namespaces created during importing so that we can find them when resolving an import ref. Use those constant values to convert an enclosing scope ID from the imported IR into a corresponding ID in the current IR. - Change how we do two-pass import of classes and namespaces so that we can do two-pass import even for non-defining declarations, so that we can import the enclosing scope. While working on the final point above, I reworked `TryResolveInst` to return a flag indicating whether another pass is necessary instead of implicitly encoding this in the `ConstantId`. This permits the handling of classes to be simplified; now `import_ir_constant_values` is only accessed in a single place. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>