Remove ImportRefUsed (#3934)

This was to track use of a declaration after import, prior to a
redeclaration. Per [discussion on
Discord](https://discord.com/channels/655572317891461132/1217182321933815820/1236016521059237962),
we likely don't need this check due to the change in behavior of
`extern`.

Rather than potentially getting one of many `extern` decls and depending
on it by accident, it is now planned to be _required_ to be imported,
and the library doing a non-`extern` decl must _know_ it's importing the
`extern` decl. The stricter requirement on the library means it now
seems more reasonable to use the `extern` decl.

So kind of rolling back #3831, though keeping `ImportIRInstId` (at least
for now) and keeping `Loaded`/`Unloaded` terminology (seems a nicer
fit).
This commit is contained in:
Jon Ross-Perkins
2024-05-03 23:33:42 +00:00
committed by GitHub
parent 76ed3c73cb
commit 92fa0ac1ac
76 changed files with 361 additions and 475 deletions
+27 -48
View File
@@ -240,7 +240,7 @@ var c: {.c: i32} = C((1,));
var d: () = D();
var e: () = NS.E();
// --- fail_decl_after_use.carbon
// --- decl_after_use.carbon
library "decl_after_use" api;
@@ -248,34 +248,20 @@ import library "extern_api";
var a: () = A();
// CHECK:STDERR: fail_decl_after_use.carbon:[[@LINE+7]]:1: ERROR: Redeclaration of imported entity that was previously used.
// CHECK:STDERR: fn A();
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR: fail_decl_after_use.carbon:[[@LINE-5]]:13: Import used here.
// CHECK:STDERR: var a: () = A();
// CHECK:STDERR: ^
// CHECK:STDERR:
fn A();
// --- fail_decl_after_use_two_errors.carbon
// --- fail_redecl_mismatch_after_use.carbon
library "decl_after_use_two_errors" api;
library "redecl_mismatch_after_use" api;
import library "extern_api";
var a: () = A();
// CHECK:STDERR: fail_decl_after_use_two_errors.carbon:[[@LINE+17]]:1: ERROR: Redeclaration of imported entity that was previously used.
// CHECK:STDERR: fail_redecl_mismatch_after_use.carbon:[[@LINE+10]]:1: ERROR: Function redeclaration differs because return type is `i32`.
// CHECK:STDERR: fn A() -> i32;
// CHECK:STDERR: ^~~~~~~~~~~~~~
// CHECK:STDERR: fail_decl_after_use_two_errors.carbon:[[@LINE-5]]:13: Import used here.
// CHECK:STDERR: var a: () = A();
// CHECK:STDERR: ^
// CHECK:STDERR:
// CHECK:STDERR: fail_decl_after_use_two_errors.carbon:[[@LINE+10]]:1: ERROR: Function redeclaration differs because return type is `i32`.
// CHECK:STDERR: fn A() -> i32;
// CHECK:STDERR: ^~~~~~~~~~~~~~
// CHECK:STDERR: fail_decl_after_use_two_errors.carbon:[[@LINE-14]]:1: In import.
// CHECK:STDERR: fail_redecl_mismatch_after_use.carbon:[[@LINE-7]]:1: In import.
// CHECK:STDERR: import library "extern_api";
// CHECK:STDERR: ^~~~~~
// CHECK:STDERR: extern_api.carbon:4:1: Previously declared with no return type.
@@ -284,7 +270,7 @@ var a: () = A();
// CHECK:STDERR:
fn A() -> i32;
// --- fail_extern_after_use.carbon
// --- todo_fail_extern_after_use.carbon
library "extern_after_use" api;
@@ -292,13 +278,6 @@ import library "api";
var a: () = A();
// CHECK:STDERR: fail_extern_after_use.carbon:[[@LINE+7]]:1: ERROR: Redeclaration of imported entity that was previously used.
// CHECK:STDERR: extern fn A();
// CHECK:STDERR: ^~~~~~~~~~~~~~
// CHECK:STDERR: fail_extern_after_use.carbon:[[@LINE-5]]:13: Import used here.
// CHECK:STDERR: var a: () = A();
// CHECK:STDERR: ^
// CHECK:STDERR:
extern fn A();
// --- unloaded.carbon
@@ -538,15 +517,15 @@ import library "extern_api";
// CHECK:STDOUT: .d = %d
// CHECK:STDOUT: .e = %e
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loc_15 [template = constants.%struct.1]
// CHECK:STDOUT: %import_ref.2: B = import_ref ir1, inst+9, loc_24 [template = constants.%struct.2]
// CHECK:STDOUT: %import_ref.3: C = import_ref ir1, inst+23, loc_39 [template = constants.%struct.3]
// CHECK:STDOUT: %import_ref.4: D = import_ref ir1, inst+26, loc_53 [template = constants.%struct.4]
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loaded [template = constants.%struct.1]
// CHECK:STDOUT: %import_ref.2: B = import_ref ir1, inst+9, loaded [template = constants.%struct.2]
// CHECK:STDOUT: %import_ref.3: C = import_ref ir1, inst+23, loaded [template = constants.%struct.3]
// CHECK:STDOUT: %import_ref.4: D = import_ref ir1, inst+26, loaded [template = constants.%struct.4]
// CHECK:STDOUT: %import_ref.5: <namespace> = import_ref ir1, inst+29, loaded
// CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.5, [template] {
// CHECK:STDOUT: .E = %import_ref.6
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.6: E = import_ref ir1, inst+30, loc_65 [template = constants.%struct.5]
// CHECK:STDOUT: %import_ref.6: E = import_ref ir1, inst+30, loaded [template = constants.%struct.5]
// CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
// CHECK:STDOUT: %.loc6_9.1: () = tuple_literal ()
// CHECK:STDOUT: %.loc6_9.2: type = converted %.loc6_9.1, constants.%.1 [template = constants.%.1]
@@ -869,15 +848,15 @@ import library "extern_api";
// CHECK:STDOUT: .d = %d
// CHECK:STDOUT: .e = %e
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loc_19 [template = constants.%struct.1]
// CHECK:STDOUT: %import_ref.2: B = import_ref ir1, inst+9, loc_28 [template = constants.%struct.2]
// CHECK:STDOUT: %import_ref.3: C = import_ref ir1, inst+23, loc_43 [template = constants.%struct.3]
// CHECK:STDOUT: %import_ref.4: D = import_ref ir1, inst+26, loc_57 [template = constants.%struct.4]
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loaded [template = constants.%struct.1]
// CHECK:STDOUT: %import_ref.2: B = import_ref ir1, inst+9, loaded [template = constants.%struct.2]
// CHECK:STDOUT: %import_ref.3: C = import_ref ir1, inst+23, loaded [template = constants.%struct.3]
// CHECK:STDOUT: %import_ref.4: D = import_ref ir1, inst+26, loaded [template = constants.%struct.4]
// CHECK:STDOUT: %import_ref.5: <namespace> = import_ref ir1, inst+29, loaded
// CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.5, [template] {
// CHECK:STDOUT: .E = %import_ref.6
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.6: E = import_ref ir1, inst+30, loc_69 [template = constants.%struct.5]
// CHECK:STDOUT: %import_ref.6: E = import_ref ir1, inst+30, loaded [template = constants.%struct.5]
// CHECK:STDOUT: %import_ref.7 = import_ref ir2, inst+2, unloaded
// CHECK:STDOUT: %import_ref.8 = import_ref ir2, inst+9, unloaded
// CHECK:STDOUT: %import_ref.9 = import_ref ir2, inst+23, unloaded
@@ -973,15 +952,15 @@ import library "extern_api";
// CHECK:STDOUT: .d = %d
// CHECK:STDOUT: .e = %e
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loc_19 [template = constants.%struct.1]
// CHECK:STDOUT: %import_ref.2: B = import_ref ir1, inst+9, loc_28 [template = constants.%struct.2]
// CHECK:STDOUT: %import_ref.3: C = import_ref ir1, inst+23, loc_43 [template = constants.%struct.3]
// CHECK:STDOUT: %import_ref.4: D = import_ref ir1, inst+26, loc_57 [template = constants.%struct.4]
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loaded [template = constants.%struct.1]
// CHECK:STDOUT: %import_ref.2: B = import_ref ir1, inst+9, loaded [template = constants.%struct.2]
// CHECK:STDOUT: %import_ref.3: C = import_ref ir1, inst+23, loaded [template = constants.%struct.3]
// CHECK:STDOUT: %import_ref.4: D = import_ref ir1, inst+26, loaded [template = constants.%struct.4]
// CHECK:STDOUT: %import_ref.5: <namespace> = import_ref ir1, inst+29, loaded
// CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.5, [template] {
// CHECK:STDOUT: .E = %import_ref.6
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.6: E = import_ref ir1, inst+30, loc_69 [template = constants.%struct.5]
// CHECK:STDOUT: %import_ref.6: E = import_ref ir1, inst+30, loaded [template = constants.%struct.5]
// CHECK:STDOUT: %import_ref.7 = import_ref ir2, inst+2, unloaded
// CHECK:STDOUT: %import_ref.8 = import_ref ir2, inst+9, unloaded
// CHECK:STDOUT: %import_ref.9 = import_ref ir2, inst+23, unloaded
@@ -1043,7 +1022,7 @@ import library "extern_api";
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_decl_after_use.carbon
// CHECK:STDOUT: --- decl_after_use.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: type = tuple_type () [template]
@@ -1061,7 +1040,7 @@ import library "extern_api";
// CHECK:STDOUT: .a = %a
// CHECK:STDOUT: .A = %A.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loc_15 [template = constants.%struct]
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loaded [template = constants.%struct]
// CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+9, unloaded
// CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+23, unloaded
// CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+26, unloaded
@@ -1088,7 +1067,7 @@ import library "extern_api";
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_decl_after_use_two_errors.carbon
// CHECK:STDOUT: --- fail_redecl_mismatch_after_use.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: type = tuple_type () [template]
@@ -1108,7 +1087,7 @@ import library "extern_api";
// CHECK:STDOUT: .Core = %Core
// CHECK:STDOUT: .a = %a
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loc_15 [template = constants.%struct.1]
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loaded [template = constants.%struct.1]
// CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+9, unloaded
// CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+23, unloaded
// CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+26, unloaded
@@ -1139,7 +1118,7 @@ import library "extern_api";
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_extern_after_use.carbon
// CHECK:STDOUT: --- todo_fail_extern_after_use.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: type = tuple_type () [template]
@@ -1157,7 +1136,7 @@ import library "extern_api";
// CHECK:STDOUT: .a = %a
// CHECK:STDOUT: .A = %A.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loc_15 [template = constants.%struct]
// CHECK:STDOUT: %import_ref.1: A = import_ref ir1, inst+2, loaded [template = constants.%struct]
// CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+9, unloaded
// CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+23, unloaded
// CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+26, unloaded
@@ -179,10 +179,10 @@ fn CallFAndGIncomplete() {
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+1, unloaded
// CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+3, unloaded
// CHECK:STDOUT: %import_ref.3: ReturnCUnused = import_ref ir1, inst+7, loc_14 [template = constants.%struct.2]
// CHECK:STDOUT: %import_ref.4: ReturnCUsed = import_ref ir1, inst+13, loc_18 [template = constants.%struct.3]
// CHECK:STDOUT: %import_ref.5: ReturnDUnused = import_ref ir1, inst+18, loc_22 [template = constants.%struct.4]
// CHECK:STDOUT: %import_ref.6: ReturnDUsed = import_ref ir1, inst+23, loc_26 [template = constants.%struct.5]
// CHECK:STDOUT: %import_ref.3: ReturnCUnused = import_ref ir1, inst+7, loaded [template = constants.%struct.2]
// CHECK:STDOUT: %import_ref.4: ReturnCUsed = import_ref ir1, inst+13, loaded [template = constants.%struct.3]
// CHECK:STDOUT: %import_ref.5: ReturnDUnused = import_ref ir1, inst+18, loaded [template = constants.%struct.4]
// CHECK:STDOUT: %import_ref.6: ReturnDUsed = import_ref ir1, inst+23, loaded [template = constants.%struct.5]
// CHECK:STDOUT: %import_ref.7 = import_ref ir1, inst+26, unloaded
// CHECK:STDOUT: %CallFAndGIncomplete.decl: CallFAndGIncomplete = fn_decl @CallFAndGIncomplete [template = constants.%struct.1] {}
// CHECK:STDOUT: %import_ref.8 = import_ref ir1, inst+4, unloaded