mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 06:11:11 +00:00
This doesn't significantly change logic, although I'm trying to add the location to used state. The issue I'm trying to address is how to identify a declaration as "allowed to be redeclared". Consider: ``` library "a" api; extern fn F(); ``` ``` library "b" api; extern fn F(); ``` ``` library "c" api; import library "a"; import library "b"; var x: auto = F(); fn F(); ``` What currently happens is: 1. On import of "a", `F` becomes ImportRefUnused 2. On import of "b", `F` becomes ImportRefUsed in order to merge. 3. In "c", the call `F()` doesn't change the state. 4. In "c", the declaration `fn F();` needs some breadcrumb to understand whether "F" has been referenced, as in step (3) here. What I want to happen is: 1. On import of "a", `F` becomes ImportRefUnloaded 2. On import of "b", `F` becomes ImportRefLoaded in order to merge. 3. In "c", the call `F()` causes `F` to become ImportRefUsed 4. In "c", the declaration `fn F();` detects that `F` is already ImportRefUsed, and can use the associated `used_id` for a diagnostic about why redeclaring is invalid. Note this PR isn't implementing (4). I'm focused on the refactoring to add a new ImportRef state here.
21 lines
669 B
C++
21 lines
669 B
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_TOOLCHAIN_CHECK_IMPORT_REF_H_
|
|
#define CARBON_TOOLCHAIN_CHECK_IMPORT_REF_H_
|
|
|
|
#include "toolchain/check/context.h"
|
|
#include "toolchain/sem_ir/file.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
// If the passed in instruction ID is an ImportRefUnloaded, loads it for use.
|
|
// The result will be an ImportRefUsed.
|
|
auto LoadImportRef(Context& context, SemIR::InstId inst_id, SemIRLoc loc)
|
|
-> void;
|
|
|
|
} // namespace Carbon::Check
|
|
|
|
#endif // CARBON_TOOLCHAIN_CHECK_IMPORT_REF_H_
|