mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 07:54:41 +01:00
Refactor checking flow to allow for ordering based on import/package. (#3379)
As I was working on this, I noticed `import` and `library` syntax needs to be fixed for how it imports the current package, and for `Main` libraries. This mostly reflects the current state in its testing. Otherwise, this should handle most of the errors I could think of: dependency cycles, redundant imports, etc. It does not actually deal with the nuances of cross-IR references. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
09b5ab14d8
commit
d024403dc4
@@ -0,0 +1,35 @@
|
||||
// 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
|
||||
//
|
||||
// AUTOUPDATE
|
||||
|
||||
// --- api.carbon
|
||||
|
||||
package Api api;
|
||||
|
||||
// --- api_lib.carbon
|
||||
|
||||
package Api library "lib" api;
|
||||
|
||||
// --- import_api.carbon
|
||||
|
||||
import Api;
|
||||
import Api library "lib";
|
||||
|
||||
// CHECK:STDOUT: file "api.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "api_lib.carbon" {
|
||||
// CHECK:STDOUT: %.loc2: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "import_api.carbon" {
|
||||
// CHECK:STDOUT: %.loc3: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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
|
||||
//
|
||||
// AUTOUPDATE
|
||||
|
||||
// --- no_api.carbon
|
||||
|
||||
// CHECK:STDERR: no_api.carbon:[[@LINE+3]]:1: ERROR: Corresponding API not found.
|
||||
// CHECK:STDERR: package Foo impl;
|
||||
// CHECK:STDERR: ^
|
||||
package Foo impl;
|
||||
|
||||
// --- no_api_lib.carbon
|
||||
|
||||
// CHECK:STDERR: no_api_lib.carbon:[[@LINE+3]]:1: ERROR: Corresponding API not found.
|
||||
// CHECK:STDERR: package Foo library "Bar" impl;
|
||||
// CHECK:STDERR: ^
|
||||
package Foo library "Bar" impl;
|
||||
|
||||
// CHECK:STDOUT: file "no_api.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "no_api_lib.carbon" {
|
||||
// CHECK:STDOUT: %.loc5: String = string_literal "Bar"
|
||||
// CHECK:STDOUT: }
|
||||
@@ -0,0 +1,59 @@
|
||||
// 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
|
||||
//
|
||||
// AUTOUPDATE
|
||||
|
||||
// --- a.carbon
|
||||
|
||||
package A api;
|
||||
|
||||
// CHECK:STDERR: a.carbon:[[@LINE+3]]:1: ERROR: Import cannot be used due to a cycle. Cycle must be fixed to import.
|
||||
// CHECK:STDERR: import B;
|
||||
// CHECK:STDERR: ^
|
||||
import B;
|
||||
|
||||
// --- b.carbon
|
||||
|
||||
package B api;
|
||||
|
||||
// CHECK:STDERR: b.carbon:[[@LINE+3]]:1: ERROR: Import cannot be used due to a cycle. Cycle must be fixed to import.
|
||||
// CHECK:STDERR: import C;
|
||||
// CHECK:STDERR: ^
|
||||
import C;
|
||||
|
||||
// --- c.carbon
|
||||
|
||||
package C api;
|
||||
|
||||
// CHECK:STDERR: c.carbon:[[@LINE+3]]:1: ERROR: Import cannot be used due to a cycle. Cycle must be fixed to import.
|
||||
// CHECK:STDERR: import A;
|
||||
// CHECK:STDERR: ^
|
||||
import A;
|
||||
|
||||
// --- c_impl.carbon
|
||||
|
||||
// CHECK:STDERR: c_impl.carbon:[[@LINE+3]]:1: ERROR: Import cannot be used due to a cycle. Cycle must be fixed to import.
|
||||
// CHECK:STDERR: package C impl;
|
||||
// CHECK:STDERR: ^
|
||||
package C impl;
|
||||
|
||||
// --- cycle_child.carbon
|
||||
|
||||
package CycleChild api;
|
||||
|
||||
// CHECK:STDERR: cycle_child.carbon:[[@LINE+3]]:1: ERROR: Import cannot be used due to a cycle. Cycle must be fixed to import.
|
||||
// CHECK:STDERR: import B;
|
||||
// CHECK:STDERR: ^
|
||||
import B;
|
||||
|
||||
// CHECK:STDOUT: file "a.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "b.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "c.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "c_impl.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "cycle_child.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
@@ -0,0 +1,111 @@
|
||||
// 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
|
||||
//
|
||||
// AUTOUPDATE
|
||||
|
||||
// --- main.carbon
|
||||
|
||||
// CHECK:STDERR: main.carbon:[[@LINE+3]]:1: ERROR: Cannot import `Main` from other packages.
|
||||
// CHECK:STDERR: import Main;
|
||||
// CHECK:STDERR: ^
|
||||
import Main;
|
||||
|
||||
// --- main_lib.carbon
|
||||
|
||||
// CHECK:STDERR: main_lib.carbon:[[@LINE+3]]:1: ERROR: Cannot import `Main` from other packages.
|
||||
// CHECK:STDERR: import Main library "lib";
|
||||
// CHECK:STDERR: ^
|
||||
import Main library "lib";
|
||||
|
||||
// --- this.carbon
|
||||
|
||||
package This api;
|
||||
|
||||
// CHECK:STDERR: this.carbon:[[@LINE+3]]:1: ERROR: File cannot import itself.
|
||||
// CHECK:STDERR: import This;
|
||||
// CHECK:STDERR: ^
|
||||
import This;
|
||||
|
||||
// --- this_lib.carbon
|
||||
|
||||
package This library "lib" api;
|
||||
|
||||
// CHECK:STDERR: this_lib.carbon:[[@LINE+3]]:1: ERROR: File cannot import itself.
|
||||
// CHECK:STDERR: import This library "lib";
|
||||
// CHECK:STDERR: ^
|
||||
import This library "lib";
|
||||
|
||||
// --- implicit_api.carbon
|
||||
|
||||
package Implicit api;
|
||||
|
||||
// --- implicit_impl.carbon
|
||||
|
||||
package Implicit impl;
|
||||
|
||||
// CHECK:STDERR: implicit_impl.carbon:[[@LINE+3]]:1: ERROR: Explicit import of `api` from `impl` file is redundant with implicit import.
|
||||
// CHECK:STDERR: import Implicit;
|
||||
// CHECK:STDERR: ^
|
||||
import Implicit;
|
||||
|
||||
// --- implicit_lib_api.carbon
|
||||
|
||||
package Implicit library "lib" api;
|
||||
|
||||
// --- implicit_lib_impl.carbon
|
||||
|
||||
package Implicit library "lib" impl;
|
||||
|
||||
// CHECK:STDERR: implicit_lib_impl.carbon:[[@LINE+3]]:1: ERROR: Explicit import of `api` from `impl` file is redundant with implicit import.
|
||||
// CHECK:STDERR: import Implicit library "lib";
|
||||
// CHECK:STDERR: ^
|
||||
import Implicit library "lib";
|
||||
|
||||
// --- unknown.carbon
|
||||
|
||||
// CHECK:STDERR: unknown.carbon:[[@LINE+3]]:1: ERROR: Imported API not found.
|
||||
// CHECK:STDERR: import Unknown;
|
||||
// CHECK:STDERR: ^
|
||||
import Unknown;
|
||||
|
||||
// CHECK:STDOUT: file "main.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "main_lib.carbon" {
|
||||
// CHECK:STDOUT: %.loc5: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "this.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "this_lib.carbon" {
|
||||
// CHECK:STDOUT: %.loc2: String = string_literal "lib"
|
||||
// CHECK:STDOUT: %.loc7: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "implicit_api.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "implicit_impl.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "implicit_lib_api.carbon" {
|
||||
// CHECK:STDOUT: %.loc2: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "implicit_lib_impl.carbon" {
|
||||
// CHECK:STDOUT: %.loc2: String = string_literal "lib"
|
||||
// CHECK:STDOUT: %.loc7: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "unknown.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
@@ -0,0 +1,50 @@
|
||||
// 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
|
||||
//
|
||||
// AUTOUPDATE
|
||||
|
||||
// --- api.carbon
|
||||
|
||||
package Api api;
|
||||
|
||||
// --- api_lib.carbon
|
||||
|
||||
package Api library "lib" api;
|
||||
|
||||
// --- import_api.carbon
|
||||
|
||||
import Api;
|
||||
// CHECK:STDERR: import_api.carbon:[[@LINE+6]]:1: ERROR: Library imported more than once.
|
||||
// CHECK:STDERR: import Api;
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR: import_api.carbon:[[@LINE-4]]:1: First import here.
|
||||
// CHECK:STDERR: import Api;
|
||||
// CHECK:STDERR: ^
|
||||
import Api;
|
||||
import Api library "lib";
|
||||
// CHECK:STDERR: import_api.carbon:[[@LINE+6]]:1: ERROR: Library imported more than once.
|
||||
// CHECK:STDERR: import Api library "lib";
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR: import_api.carbon:[[@LINE-4]]:1: First import here.
|
||||
// CHECK:STDERR: import Api library "lib";
|
||||
// CHECK:STDERR: ^
|
||||
import Api library "lib";
|
||||
|
||||
// CHECK:STDOUT: file "api.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "api_lib.carbon" {
|
||||
// CHECK:STDOUT: %.loc2: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "import_api.carbon" {
|
||||
// CHECK:STDOUT: %.loc10: String = string_literal "lib"
|
||||
// CHECK:STDOUT: %.loc17: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
@@ -0,0 +1,48 @@
|
||||
// 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
|
||||
//
|
||||
// AUTOUPDATE
|
||||
|
||||
// --- main.carbon
|
||||
|
||||
// CHECK:STDERR: main.carbon:[[@LINE+3]]:1: ERROR: Default `Main` library must omit `package` directive.
|
||||
// CHECK:STDERR: package Main api;
|
||||
// CHECK:STDERR: ^
|
||||
package Main api;
|
||||
|
||||
// --- main_impl.carbon
|
||||
|
||||
// CHECK:STDERR: main_impl.carbon:[[@LINE+3]]:1: ERROR: Default `Main` library must omit `package` directive.
|
||||
// CHECK:STDERR: package Main impl;
|
||||
// CHECK:STDERR: ^
|
||||
package Main impl;
|
||||
|
||||
// --- raw_main.carbon
|
||||
|
||||
// `Main` isn't a keyword, so this fails the same way.
|
||||
// CHECK:STDERR: raw_main.carbon:[[@LINE+3]]:1: ERROR: Default `Main` library must omit `package` directive.
|
||||
// CHECK:STDERR: package r#Main api;
|
||||
// CHECK:STDERR: ^
|
||||
package r#Main api;
|
||||
|
||||
// --- main_lib.carbon
|
||||
|
||||
// CHECK:STDERR: main_lib.carbon:[[@LINE+3]]:1: ERROR: Use `library` directive in `Main` package libraries.
|
||||
// CHECK:STDERR: package Main library "lib" api;
|
||||
// CHECK:STDERR: ^
|
||||
package Main library "lib" api;
|
||||
|
||||
// CHECK:STDOUT: file "main.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "main_impl.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "raw_main.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "main_lib.carbon" {
|
||||
// CHECK:STDOUT: %.loc5: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
@@ -0,0 +1,64 @@
|
||||
// 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
|
||||
//
|
||||
// AUTOUPDATE
|
||||
|
||||
// --- api_only.carbon
|
||||
|
||||
package ApiOnly api;
|
||||
|
||||
// --- api_only_lib.carbon
|
||||
|
||||
package ApiOnly library "lib" api;
|
||||
|
||||
// --- with_impl_api.carbon
|
||||
|
||||
package WithImpl api;
|
||||
|
||||
// --- with_impl_impl.carbon
|
||||
|
||||
package WithImpl impl;
|
||||
|
||||
// --- with_impl_impl_extra.carbon
|
||||
|
||||
// Multiple impls are allowed.
|
||||
package WithImpl impl;
|
||||
|
||||
// --- with_impl_lib_api.carbon
|
||||
|
||||
package WithImpl library "lib" api;
|
||||
|
||||
// --- with_impl_lib_impl.carbon
|
||||
|
||||
package WithImpl library "lib" impl;
|
||||
|
||||
// CHECK:STDOUT: file "api_only.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "api_only_lib.carbon" {
|
||||
// CHECK:STDOUT: %.loc2: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "with_impl_api.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "with_impl_impl.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: file "with_impl_impl_extra.carbon" {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "with_impl_lib_api.carbon" {
|
||||
// CHECK:STDOUT: %.loc2: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "with_impl_lib_impl.carbon" {
|
||||
// CHECK:STDOUT: %.loc2: String = string_literal "lib"
|
||||
// CHECK:STDOUT: }
|
||||
Reference in New Issue
Block a user