Replace ResolvePrevInstForMerge with decl logic. (#3936)

This addresses the const reliance of ResolvePrevInstForMerge by checking
the imported instruction, testing with `alias` name conflicts. Given the
need to examine structure, the helper function feels like it now gets in
the way, so I'm just removing it.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-Perkins
2024-05-06 21:27:21 +00:00
committed by GitHub
co-authored by Richard Smith
parent d5c0c9cfe3
commit 292a9d3cb4
10 changed files with 400 additions and 97 deletions
@@ -86,7 +86,7 @@ fn A() {}
library "redef_after_def" impl;
// CHECK:STDERR: fail_redef_after_def.impl.carbon:[[@LINE+9]]:1: ERROR: Redefinition of `fn A`.
// CHECK:STDERR: fail_redef_after_def.impl.carbon:[[@LINE+10]]:1: ERROR: Redefinition of `fn A`.
// CHECK:STDERR: fn A() {}
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR: fail_redef_after_def.impl.carbon:[[@LINE-5]]:1: In import.
@@ -95,8 +95,31 @@ library "redef_after_def" impl;
// CHECK:STDERR: redef_after_def.carbon:4:1: Previously defined here.
// CHECK:STDERR: fn A() {}
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR:
fn A() {}
// --- def_alias.carbon
library "def_alias" api;
fn A();
alias B = A;
// --- fail_def_alias.impl.carbon
library "def_alias" impl;
// CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE+9]]:1: ERROR: Duplicate name being declared in the same scope.
// CHECK:STDERR: fn B() {}
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE-5]]:1: In import.
// CHECK:STDERR: library "def_alias" impl;
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR: def_alias.carbon:5:7: Name is previously declared here.
// CHECK:STDERR: alias B = A;
// CHECK:STDERR: ^
fn B() {}
// CHECK:STDOUT: --- basic.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
@@ -290,3 +313,50 @@ fn A() {}
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- def_alias.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %A: type = fn_type @A [template]
// CHECK:STDOUT: %.1: type = tuple_type () [template]
// CHECK:STDOUT: %struct: A = struct_value () [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .A = %A.decl
// CHECK:STDOUT: .B = %B
// CHECK:STDOUT: }
// CHECK:STDOUT: %A.decl: A = fn_decl @A [template = constants.%struct] {}
// CHECK:STDOUT: %A.ref: A = name_ref A, %A.decl [template = constants.%struct]
// CHECK:STDOUT: %B: A = bind_alias B, %A.decl [template = constants.%struct]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @A();
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_def_alias.impl.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %A: type = fn_type @A [template]
// CHECK:STDOUT: %.1: type = tuple_type () [template]
// CHECK:STDOUT: %struct.1: A = struct_value () [template]
// CHECK:STDOUT: %.2: type = fn_type @.1 [template]
// CHECK:STDOUT: %struct.2: <invalid> = struct_value () [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .A = %import_ref.1
// CHECK:STDOUT: .B = %import_ref.2
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.1 = import_ref ir0, inst+1, unloaded
// CHECK:STDOUT: %import_ref.2: A = import_ref ir0, inst+6, loaded [template = constants.%struct.1]
// CHECK:STDOUT: %.decl: <invalid> = fn_decl @.1 [template = constants.%struct.2] {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @A();
// CHECK:STDOUT:
// CHECK:STDOUT: fn @.1() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: