Refactor CheckIsAllowedRedecl and stop function definition merging (#4800)

Rename `CheckIsAllowedRedecl` to `DiagnoseIfInvalidRedecl` to try to
better document behavior, and clean up comments.

This extends the no-merge-if-defined behavior to functions. It was
already the case for class/interface, and just added for impl, so if
anything functions were now inconsistent. I was kind of tempted to make
a helper for it, but I didn't think of a great structure/name to get
there: `DiagnoseRedef` isn't always called when it's a redefinition, for
example due to `extern` diagnostics, it's hard to combine.

Cleans up `is_defined` calls to rely more on `has_definition_started`,
removing some code paths that are unused since definitions aren't
merged.
This commit is contained in:
Jon Ross-Perkins
2025-01-14 21:13:21 +00:00
committed by GitHub
parent 5b70a3ea91
commit d958caaff3
15 changed files with 194 additions and 141 deletions
@@ -67,12 +67,14 @@ fn E() {}
// CHECK:STDOUT: %B: %B.type = struct_value () [template]
// CHECK:STDOUT: %C.type: type = fn_type @C [template]
// CHECK:STDOUT: %C: %C.type = struct_value () [template]
// CHECK:STDOUT: %.type: type = fn_type @.1 [template]
// CHECK:STDOUT: %.d85: %.type = struct_value () [template]
// CHECK:STDOUT: %.type.b6a92a.1: type = fn_type @.1 [template]
// CHECK:STDOUT: %.d852be.1: %.type.b6a92a.1 = struct_value () [template]
// CHECK:STDOUT: %D.type: type = fn_type @D [template]
// CHECK:STDOUT: %D: %D.type = struct_value () [template]
// CHECK:STDOUT: %E.type: type = fn_type @E [template]
// CHECK:STDOUT: %E: %E.type = struct_value () [template]
// CHECK:STDOUT: %.type.b6a92a.2: type = fn_type @.2 [template]
// CHECK:STDOUT: %.d852be.2: %.type.b6a92a.2 = struct_value () [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
@@ -81,7 +83,7 @@ fn E() {}
// CHECK:STDOUT: .B = %B.decl.loc21
// CHECK:STDOUT: .C = %C.decl
// CHECK:STDOUT: .D = %D.decl.loc41
// CHECK:STDOUT: .E = %E.decl.loc51
// CHECK:STDOUT: .E = %E.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %A.decl.loc11: %A.type = fn_decl @A [template = constants.%A] {} {}
// CHECK:STDOUT: %A.decl.loc19: %A.type = fn_decl @A [template = constants.%A] {} {}
@@ -108,7 +110,7 @@ fn E() {}
// CHECK:STDOUT: %x.loc29: %empty_tuple.type = bind_name x, %x.param.loc29
// CHECK:STDOUT: }
// CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {} {}
// CHECK:STDOUT: %.decl: %.type = fn_decl @.1 [template = constants.%.d85] {
// CHECK:STDOUT: %.decl.loc39: %.type.b6a92a.1 = fn_decl @.1 [template = constants.%.d852be.1] {
// CHECK:STDOUT: %x.patt: %empty_tuple.type = binding_pattern x
// CHECK:STDOUT: %x.param_patt: %empty_tuple.type = value_param_pattern %x.patt, runtime_param0
// CHECK:STDOUT: } {
@@ -121,8 +123,8 @@ fn E() {}
// CHECK:STDOUT: }
// CHECK:STDOUT: %D.decl.loc41: %D.type = fn_decl @D [template = constants.%D] {} {}
// CHECK:STDOUT: %D.decl.loc49: %D.type = fn_decl @D [template = constants.%D] {} {}
// CHECK:STDOUT: %E.decl.loc51: %E.type = fn_decl @E [template = constants.%E] {} {}
// CHECK:STDOUT: %E.decl.loc58: %E.type = fn_decl @E [template = constants.%E] {} {}
// CHECK:STDOUT: %E.decl: %E.type = fn_decl @E [template = constants.%E] {} {}
// CHECK:STDOUT: %.decl.loc58: %.type.b6a92a.2 = fn_decl @.2 [template = constants.%.d852be.2] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @A();
@@ -143,3 +145,8 @@ fn E() {}
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @.2() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: