Files
carbon-lang/toolchain/check/merge.h
T
Jon Ross-Perkins 5c567b892d Address invalid redeclaration and definitions across imports. (#3842)
Note, there's still a TODO "Allow non-extern declarations in the same
library."
2024-04-02 18:01:25 +00:00

42 lines
1.5 KiB
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_MERGE_H_
#define CARBON_TOOLCHAIN_CHECK_MERGE_H_
#include "toolchain/check/context.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::Check {
struct PrevInstForMerge {
// The resolved instruction.
SemIR::Inst inst;
// Whether an import was encountered during resolution.
bool is_import;
};
// Resolves prev_inst_id for merging (or name conflicts). This handles imports
// to return the instruction relevant for a merge. If an import is found and was
// previously used, it notes it, although an invalid redeclaration may diagnose
// for other reasons too.
auto ResolvePrevInstForMerge(Context& context, Parse::NodeId node_id,
SemIR::InstId prev_inst_id) -> PrevInstForMerge;
// When the prior name lookup result is an import and we are successfully
// merging, replace the name lookup result with the reference in the current
// file.
auto ReplacePrevInstForMerge(Context& context, SemIR::NameScopeId scope_id,
SemIR::NameId name_id, SemIR::InstId new_inst_id)
-> void;
// Merges an import ref at new_inst_id another at prev_inst_id. May print a
// diagnostic if merging is invalid.
auto MergeImportRef(Context& context, SemIR::InstId new_inst_id,
SemIR::InstId prev_inst_id) -> void;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_MERGE_H_