diff --git a/core/prelude.carbon b/core/prelude.carbon index e30166c93693..2f437eb52449 100644 --- a/core/prelude.carbon +++ b/core/prelude.carbon @@ -4,7 +4,7 @@ // // AUTOUPDATE -package Core library "prelude" api; +package Core library "prelude"; import library "prelude/operators"; import library "prelude/types"; diff --git a/core/prelude/operators.carbon b/core/prelude/operators.carbon index e4fe994ec49a..08d60cb5eb8b 100644 --- a/core/prelude/operators.carbon +++ b/core/prelude/operators.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -package Core library "prelude/operators" api; +package Core library "prelude/operators"; // TODO: Add a mechanism to re-export the names declared here. import library "prelude/operators/arithmetic"; diff --git a/core/prelude/operators/arithmetic.carbon b/core/prelude/operators/arithmetic.carbon index 0113229bb68d..693d0571f2b4 100644 --- a/core/prelude/operators/arithmetic.carbon +++ b/core/prelude/operators/arithmetic.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -package Core library "prelude/operators/arithmetic" api; +package Core library "prelude/operators/arithmetic"; // Addition: `a + b`. interface Add { diff --git a/core/prelude/operators/bitwise.carbon b/core/prelude/operators/bitwise.carbon index 7f6c4a7177f2..30e665c29406 100644 --- a/core/prelude/operators/bitwise.carbon +++ b/core/prelude/operators/bitwise.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -package Core library "prelude/operators/bitwise" api; +package Core library "prelude/operators/bitwise"; // Bit complement: `^a`. interface BitComplement { diff --git a/core/prelude/operators/comparison.carbon b/core/prelude/operators/comparison.carbon index 11bdc65426aa..f8c01c70deaa 100644 --- a/core/prelude/operators/comparison.carbon +++ b/core/prelude/operators/comparison.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -package Core library "prelude/operators/comparison" api; +package Core library "prelude/operators/comparison"; // Equality comparison: `a == b` and `a != b`. interface Eq { diff --git a/core/prelude/types.carbon b/core/prelude/types.carbon index 71b002c12090..57895ab555e1 100644 --- a/core/prelude/types.carbon +++ b/core/prelude/types.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -package Core library "prelude/types" api; +package Core library "prelude/types"; // TODO: Add a mechanism to re-export the names declared here. diff --git a/core/prelude/types/i32.carbon b/core/prelude/types/i32.carbon index 8d2de0d93244..869d3b6a4e9b 100644 --- a/core/prelude/types/i32.carbon +++ b/core/prelude/types/i32.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -package Core library "prelude/types/i32" api; +package Core library "prelude/types/i32"; import library "prelude/operators"; diff --git a/toolchain/check/check.cpp b/toolchain/check/check.cpp index 54087f667f8b..2d17ffb58d77 100644 --- a/toolchain/check/check.cpp +++ b/toolchain/check/check.cpp @@ -963,8 +963,7 @@ static auto TrackImport( "Explicit import of `api` from `impl` file is " "redundant with implicit import."); CARBON_DIAGNOSTIC(ImportSelf, Error, "File cannot import itself."); - bool is_impl = - !packaging || packaging->api_or_impl == Parse::Tree::ApiOrImpl::Impl; + bool is_impl = !packaging || packaging->is_impl; unit_info.emitter.Emit(import.node_id, is_impl ? ExplicitImportApi : ImportSelf); return; @@ -1073,8 +1072,7 @@ static auto BuildApiMapAndDiagnosePackaging( continue; } - bool is_impl = - packaging && packaging->api_or_impl == Parse::Tree::ApiOrImpl::Impl; + bool is_impl = packaging && packaging->is_impl; // Add to the `api` map and diagnose duplicates. This occurs before the // file extension check because we might emit both diagnostics in situations @@ -1153,7 +1151,7 @@ auto CheckParseTrees(llvm::MutableArrayRef units, bool prelude_import, ready_to_check.reserve(units.size()); for (auto& unit_info : unit_infos) { const auto& packaging = unit_info.unit->parse_tree->packaging_decl(); - if (packaging && packaging->api_or_impl == Parse::Tree::ApiOrImpl::Impl) { + if (packaging && packaging->is_impl) { // An `impl` has an implicit import of its `api`. auto implicit_names = packaging->names; implicit_names.package_id = IdentifierId::Invalid; diff --git a/toolchain/check/decl_state.h b/toolchain/check/decl_state.h index cff68ec61739..da4c24af3b00 100644 --- a/toolchain/check/decl_state.h +++ b/toolchain/check/decl_state.h @@ -30,10 +30,11 @@ enum class KeywordModifierSet : uint32_t { Abstract = 1 << 3, Base = 1 << 4, Default = 1 << 5, - Extend = 1 << 6, - Final = 1 << 7, - Impl = 1 << 8, - Virtual = 1 << 9, + Export = 1 << 6, + Extend = 1 << 7, + Final = 1 << 8, + Impl = 1 << 9, + Virtual = 1 << 10, // Sets of modifiers: Access = Private | Protected, @@ -41,7 +42,7 @@ enum class KeywordModifierSet : uint32_t { Method = Abstract | Impl | Virtual, ImplDecl = Extend | Final, Interface = Default | Final, - Decl = Class | Method | ImplDecl | Interface, + Decl = Class | Method | ImplDecl | Interface | Export, None = 0, LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Virtual) @@ -59,6 +60,10 @@ static_assert(!(KeywordModifierSet::Access & KeywordModifierSet::Extern) && !((KeywordModifierSet::Access | KeywordModifierSet::Extern) & KeywordModifierSet::Decl), "Order-related sets must not overlap"); +static_assert(~KeywordModifierSet::None == + (KeywordModifierSet::Access | KeywordModifierSet::Extern | + KeywordModifierSet::Decl), + "Modifier missing from all modifier sets"); // State stored for each declaration we are currently in: the kind of // declaration and the keyword modifiers that apply to that declaration. @@ -74,9 +79,11 @@ struct DeclState { Export, Fn, Impl, + Import, Interface, Let, Namespace, + PackageOrLibrary, Var }; diff --git a/toolchain/check/handle_import_and_package.cpp b/toolchain/check/handle_import_and_package.cpp index c7e451a5bbb5..ecbb171a73a6 100644 --- a/toolchain/check/handle_import_and_package.cpp +++ b/toolchain/check/handle_import_and_package.cpp @@ -3,44 +3,53 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include "toolchain/check/context.h" +#include "toolchain/check/decl_state.h" +#include "toolchain/check/modifiers.h" namespace Carbon::Check { // `import` and `package` are structured by parsing. As a consequence, no // checking logic is needed here. -auto HandleImportIntroducer(Context& /*context*/, +auto HandleImportIntroducer(Context& context, Parse::ImportIntroducerId /*node_id*/) -> bool { + context.decl_state_stack().Push(DeclState::Import); return true; } -auto HandleImportExport(Context& /*context*/, Parse::ImportExportId /*node_id*/) +auto HandleImportDecl(Context& context, Parse::ImportDeclId /*node_id*/) -> bool { + LimitModifiersOnDecl(context, KeywordModifierSet::Export, + Lex::TokenKind::Import); + context.decl_state_stack().Pop(DeclState::Import); return true; } -auto HandleImportDecl(Context& /*context*/, Parse::ImportDeclId /*node_id*/) - -> bool { - return true; -} - -auto HandleLibraryIntroducer(Context& /*context*/, +auto HandleLibraryIntroducer(Context& context, Parse::LibraryIntroducerId /*node_id*/) -> bool { + context.decl_state_stack().Push(DeclState::PackageOrLibrary); return true; } -auto HandleLibraryDecl(Context& /*context*/, Parse::LibraryDeclId /*node_id*/) +auto HandleLibraryDecl(Context& context, Parse::LibraryDeclId /*node_id*/) -> bool { + LimitModifiersOnDecl(context, KeywordModifierSet::Impl, + Lex::TokenKind::Library); + context.decl_state_stack().Pop(DeclState::PackageOrLibrary); return true; } -auto HandlePackageIntroducer(Context& /*context*/, +auto HandlePackageIntroducer(Context& context, Parse::PackageIntroducerId /*node_id*/) -> bool { + context.decl_state_stack().Push(DeclState::PackageOrLibrary); return true; } -auto HandlePackageDecl(Context& /*context*/, Parse::PackageDeclId /*node_id*/) +auto HandlePackageDecl(Context& context, Parse::PackageDeclId /*node_id*/) -> bool { + LimitModifiersOnDecl(context, KeywordModifierSet::Impl, + Lex::TokenKind::Package); + context.decl_state_stack().Pop(DeclState::PackageOrLibrary); return true; } @@ -64,14 +73,4 @@ auto HandleDefaultLibrary(Context& /*context*/, return true; } -auto HandlePackageApi(Context& /*context*/, Parse::PackageApiId /*node_id*/) - -> bool { - return true; -} - -auto HandlePackageImpl(Context& /*context*/, Parse::PackageImplId /*node_id*/) - -> bool { - return true; -} - } // namespace Carbon::Check diff --git a/toolchain/check/testdata/alias/no_prelude/export_name.carbon b/toolchain/check/testdata/alias/no_prelude/export_name.carbon index 3acb952c9c31..97773582467e 100644 --- a/toolchain/check/testdata/alias/no_prelude/export_name.carbon +++ b/toolchain/check/testdata/alias/no_prelude/export_name.carbon @@ -10,14 +10,14 @@ // --- base.carbon -library "base" api; +library "base"; class C {} alias D = C; // --- export.carbon -library "export" api; +library "export"; import library "base"; @@ -25,7 +25,7 @@ export D; // --- export_orig.carbon -library "export_orig" api; +library "export_orig"; import library "base"; @@ -37,7 +37,7 @@ export C; // --- use_export.carbon -library "use_export" api; +library "use_export"; import library "export"; @@ -45,7 +45,7 @@ var d: D = {}; // --- fail_orig_name_not_in_export.carbon -library "fail_orig_name_not_in_export" api; +library "fail_orig_name_not_in_export"; import library "export"; @@ -56,7 +56,7 @@ var c: C = {}; // --- indirect_compat.carbon -library "indirect_compat" api; +library "indirect_compat"; import library "export"; import library "export_orig"; diff --git a/toolchain/check/testdata/alias/no_prelude/import.carbon b/toolchain/check/testdata/alias/no_prelude/import.carbon index aa00fc4057d0..a59335e607fc 100644 --- a/toolchain/check/testdata/alias/no_prelude/import.carbon +++ b/toolchain/check/testdata/alias/no_prelude/import.carbon @@ -6,7 +6,7 @@ // --- class1.carbon -library "class1" api; +library "class1"; class C {} @@ -16,7 +16,7 @@ var a: C*; // --- class2.carbon -library "class2" api; +library "class2"; import library "class1"; @@ -26,7 +26,7 @@ var b: c_alias*; // --- class3.carbon -library "class3" api; +library "class3"; import library "class2"; @@ -34,7 +34,7 @@ var c: c_alias_alias*; // --- var1.carbon -library "var1" api; +library "var1"; var a: () = (); @@ -42,7 +42,7 @@ alias a_alias = a; // --- var2.carbon -library "var2" api; +library "var2"; import library "var1"; @@ -52,7 +52,7 @@ var b: () = a_alias; // --- fail_var3.carbon -library "var3" api; +library "var3"; // CHECK:STDERR: fail_var3.carbon:[[@LINE+6]]:1: In import. // CHECK:STDERR: import library "var2"; diff --git a/toolchain/check/testdata/alias/no_prelude/import_order.carbon b/toolchain/check/testdata/alias/no_prelude/import_order.carbon index a687e94e3cae..d183ea1e98bc 100644 --- a/toolchain/check/testdata/alias/no_prelude/import_order.carbon +++ b/toolchain/check/testdata/alias/no_prelude/import_order.carbon @@ -6,7 +6,7 @@ // --- a.carbon -library "a" api; +library "a"; class C { var v: (); } alias a = C; @@ -16,7 +16,7 @@ alias d = c; // --- b.carbon -library "b" api; +library "b"; import library "a"; diff --git a/toolchain/check/testdata/as/adapter_conversion.carbon b/toolchain/check/testdata/as/adapter_conversion.carbon index a3fc2badc71e..5a7bce54f6d5 100644 --- a/toolchain/check/testdata/as/adapter_conversion.carbon +++ b/toolchain/check/testdata/as/adapter_conversion.carbon @@ -6,7 +6,7 @@ // --- adapt_class.carbon -library "adapt_class" api; +library "adapt_class"; class A { var x: i32; @@ -32,7 +32,7 @@ var b_factory: B = A.Make() as B; // --- adapt_i32.carbon -library "adapt_i32" api; +library "adapt_i32"; class A { adapt i32; @@ -43,7 +43,7 @@ let n: i32 = a as i32; // --- multi_level_adapt.carbon -library "multi_level_adapt" api; +library "multi_level_adapt"; class A { adapt {}; } class B { adapt A; } @@ -54,7 +54,7 @@ let d: D = {} as D; // --- fail_init_class.carbon -library "fail_init_class" api; +library "fail_init_class"; class A { var x: i32; @@ -80,7 +80,7 @@ var b_init: B = ({.x = 1, .y = 2} as A) as B; // --- fail_adapt_init_from_struct.carbon -library "fail_adapt_init_from_struct" api; +library "fail_adapt_init_from_struct"; class A { var x: i32; diff --git a/toolchain/check/testdata/basics/multifile.carbon b/toolchain/check/testdata/basics/multifile.carbon index d3aa048c2372..52b370147a7a 100644 --- a/toolchain/check/testdata/basics/multifile.carbon +++ b/toolchain/check/testdata/basics/multifile.carbon @@ -5,12 +5,12 @@ // AUTOUPDATE // --- a.carbon -package A api; +package A; fn A() {} // --- b.carbon -package B api; +package B; fn B() {} diff --git a/toolchain/check/testdata/basics/no_prelude/multifile_raw_and_textual_ir.carbon b/toolchain/check/testdata/basics/no_prelude/multifile_raw_and_textual_ir.carbon index 3fec57ab4609..40d16ba0d1f0 100644 --- a/toolchain/check/testdata/basics/no_prelude/multifile_raw_and_textual_ir.carbon +++ b/toolchain/check/testdata/basics/no_prelude/multifile_raw_and_textual_ir.carbon @@ -9,12 +9,12 @@ // AUTOUPDATE // --- a.carbon -package A api; +package A; fn A() {} // --- b.carbon -package B api; +package B; fn B() {} diff --git a/toolchain/check/testdata/basics/no_prelude/multifile_raw_ir.carbon b/toolchain/check/testdata/basics/no_prelude/multifile_raw_ir.carbon index 9428b95091ea..1537f15e8e2c 100644 --- a/toolchain/check/testdata/basics/no_prelude/multifile_raw_ir.carbon +++ b/toolchain/check/testdata/basics/no_prelude/multifile_raw_ir.carbon @@ -9,12 +9,12 @@ // AUTOUPDATE // --- a.carbon -package A api; +package A; fn A() {} // --- b.carbon -package B api; +package B; fn B() {} diff --git a/toolchain/check/testdata/basics/type_literals.carbon b/toolchain/check/testdata/basics/type_literals.carbon index b0875ced0c9d..9c4b8c5cbc0a 100644 --- a/toolchain/check/testdata/basics/type_literals.carbon +++ b/toolchain/check/testdata/basics/type_literals.carbon @@ -5,14 +5,14 @@ // AUTOUPDATE // --- iN.carbon -library "iN" api; +library "iN"; var test_i8: i8; var test_i16: i16; var test_i64: i64; // --- fail_iN_bad_width.carbon -library "fail_iN_bad_width" api; +library "fail_iN_bad_width"; // CHECK:STDERR: fail_iN_bad_width.carbon:[[@LINE+4]]:14: ERROR: Name `i0` not found. // CHECK:STDERR: var test_i0: i0; @@ -42,14 +42,14 @@ var test_i1000000000: i1000000000; var test_i10000000000000000000: i10000000000000000000; // --- uN.carbon -library "uN" api; +library "uN"; var test_u8: u8; var test_u16: u16; var test_u64: u64; // --- fail_uN_bad_width.carbon -library "fail_uN_bad_width" api; +library "fail_uN_bad_width"; // CHECK:STDERR: fail_uN_bad_width.carbon:[[@LINE+4]]:14: ERROR: Name `u0` not found. // CHECK:STDERR: var test_u0: u0; @@ -79,7 +79,7 @@ var test_u1000000000: u1000000000; var test_u10000000000000000000: u10000000000000000000; // --- fail_fN_bad_width.carbon -library "fail_fN_bad_width" api; +library "fail_fN_bad_width"; // CHECK:STDERR: fail_fN_bad_width.carbon:[[@LINE+4]]:14: ERROR: Name `f0` not found. // CHECK:STDERR: var test_f0: f0; @@ -97,7 +97,7 @@ var test_f1000000000: f1000000000; var test_f1000000000000: f1000000000000; // --- fail_fN_todo_unsupported.carbon -library "fail_fN_todo_unsupported" api; +library "fail_fN_todo_unsupported"; // TODO: Some or all of these should eventually work. // CHECK:STDERR: fail_fN_todo_unsupported.carbon:[[@LINE+3]]:15: ERROR: Semantics TODO: `Currently only f64 is allowed`. diff --git a/toolchain/check/testdata/builtins/bool/make_type.carbon b/toolchain/check/testdata/builtins/bool/make_type.carbon index 0dc7fb8330dd..e869ab210cf1 100644 --- a/toolchain/check/testdata/builtins/bool/make_type.carbon +++ b/toolchain/check/testdata/builtins/bool/make_type.carbon @@ -6,13 +6,13 @@ // --- types.carbon -library "types" api; +library "types"; fn Bool() -> type = "bool.make_type"; // --- use_types.carbon -library "uses_types" api; +library "uses_types"; import library "types"; diff --git a/toolchain/check/testdata/builtins/float/add.carbon b/toolchain/check/testdata/builtins/float/add.carbon index cd813e5bf9a6..521f4fd91057 100644 --- a/toolchain/check/testdata/builtins/float/add.carbon +++ b/toolchain/check/testdata/builtins/float/add.carbon @@ -16,7 +16,7 @@ var x: f64 = Add(2.2, 2.3); // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: ERROR: Invalid signature for builtin function "float.add". // CHECK:STDERR: fn TooFew(a: f64) -> f64 = "float.add"; diff --git a/toolchain/check/testdata/builtins/float/div.carbon b/toolchain/check/testdata/builtins/float/div.carbon index eac8396a7774..d29635bb54e3 100644 --- a/toolchain/check/testdata/builtins/float/div.carbon +++ b/toolchain/check/testdata/builtins/float/div.carbon @@ -18,7 +18,7 @@ let c: f64 = Div(0.0, 0.0); // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: ERROR: Invalid signature for builtin function "float.div". // CHECK:STDERR: fn TooFew(a: f64) -> f64 = "float.div"; diff --git a/toolchain/check/testdata/builtins/float/eq.carbon b/toolchain/check/testdata/builtins/float/eq.carbon index 2ce6e9d20ab5..bd1314f3a1d3 100644 --- a/toolchain/check/testdata/builtins/float/eq.carbon +++ b/toolchain/check/testdata/builtins/float/eq.carbon @@ -22,7 +22,7 @@ fn RuntimeCall(a: f64, b: f64) -> bool { // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+3]]:1: ERROR: Invalid signature for builtin function "float.eq". // CHECK:STDERR: fn WrongResult(a: f64, b: f64) -> f64 = "float.eq"; diff --git a/toolchain/check/testdata/builtins/float/make_type.carbon b/toolchain/check/testdata/builtins/float/make_type.carbon index 5222f580dbde..5090b1519a1e 100644 --- a/toolchain/check/testdata/builtins/float/make_type.carbon +++ b/toolchain/check/testdata/builtins/float/make_type.carbon @@ -6,13 +6,13 @@ // --- types.carbon -library "types" api; +library "types"; fn Float(size: i32) -> type = "float.make_type"; // --- use_types.carbon -library "uses_types" api; +library "uses_types"; import library "types"; @@ -24,7 +24,7 @@ fn GetFloat(dyn_size: i32) -> type { // --- fail_invalid_size.carbon -library "invalid_size" api; +library "invalid_size"; import library "types"; diff --git a/toolchain/check/testdata/builtins/float/mul.carbon b/toolchain/check/testdata/builtins/float/mul.carbon index b8c90abe6cec..8135d0bdec3b 100644 --- a/toolchain/check/testdata/builtins/float/mul.carbon +++ b/toolchain/check/testdata/builtins/float/mul.carbon @@ -16,7 +16,7 @@ var x: f64 = Mul(2.0, 0.5); // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: ERROR: Invalid signature for builtin function "float.mul". // CHECK:STDERR: fn TooFew(a: f64) -> f64 = "float.mul"; diff --git a/toolchain/check/testdata/builtins/float/negate.carbon b/toolchain/check/testdata/builtins/float/negate.carbon index 61bf2cfd6353..37773e72b5b5 100644 --- a/toolchain/check/testdata/builtins/float/negate.carbon +++ b/toolchain/check/testdata/builtins/float/negate.carbon @@ -16,7 +16,7 @@ let a: f64 = Negate(1.5); // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: ERROR: Invalid signature for builtin function "float.negate". // CHECK:STDERR: fn TooFew() -> f64 = "float.negate"; diff --git a/toolchain/check/testdata/builtins/float/neq.carbon b/toolchain/check/testdata/builtins/float/neq.carbon index cf18319d06b1..69852b523089 100644 --- a/toolchain/check/testdata/builtins/float/neq.carbon +++ b/toolchain/check/testdata/builtins/float/neq.carbon @@ -22,7 +22,7 @@ fn RuntimeCall(a: f64, b: f64) -> bool { // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+3]]:1: ERROR: Invalid signature for builtin function "float.neq". // CHECK:STDERR: fn WrongResult(a: f64, b: f64) -> f64 = "float.neq"; diff --git a/toolchain/check/testdata/builtins/float/sub.carbon b/toolchain/check/testdata/builtins/float/sub.carbon index 47594aaf757f..43eb7b63c292 100644 --- a/toolchain/check/testdata/builtins/float/sub.carbon +++ b/toolchain/check/testdata/builtins/float/sub.carbon @@ -16,7 +16,7 @@ var x: f64 = Sub(2.0, 0.5); // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: ERROR: Invalid signature for builtin function "float.sub". // CHECK:STDERR: fn TooFew(a: f64) -> f64 = "float.sub"; diff --git a/toolchain/check/testdata/builtins/int/eq.carbon b/toolchain/check/testdata/builtins/int/eq.carbon index c33414702f72..b9c185b2a8f9 100644 --- a/toolchain/check/testdata/builtins/int/eq.carbon +++ b/toolchain/check/testdata/builtins/int/eq.carbon @@ -22,7 +22,7 @@ fn RuntimeCall(a: i32, b: i32) -> bool { // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+3]]:1: ERROR: Invalid signature for builtin function "int.eq". // CHECK:STDERR: fn WrongResult(a: i32, b: i32) -> i32 = "int.eq"; diff --git a/toolchain/check/testdata/builtins/int/left_shift.carbon b/toolchain/check/testdata/builtins/int/left_shift.carbon index 9ea1f6374d8b..810e012ce57f 100644 --- a/toolchain/check/testdata/builtins/int/left_shift.carbon +++ b/toolchain/check/testdata/builtins/int/left_shift.carbon @@ -19,7 +19,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- fail_bad_shift.carbon -package BadShift api; +package BadShift; fn LeftShift(a: i32, b: i32) -> i32 = "int.left_shift"; fn Negate(a: i32) -> i32 = "int.snegate"; diff --git a/toolchain/check/testdata/builtins/int/make_type_32.carbon b/toolchain/check/testdata/builtins/int/make_type_32.carbon index 6b45bb5e427d..839f9384ed31 100644 --- a/toolchain/check/testdata/builtins/int/make_type_32.carbon +++ b/toolchain/check/testdata/builtins/int/make_type_32.carbon @@ -6,13 +6,13 @@ // --- types.carbon -library "types" api; +library "types"; fn Int() -> type = "int.make_type_32"; // --- use_types.carbon -library "uses_types" api; +library "uses_types"; import library "types"; diff --git a/toolchain/check/testdata/builtins/int/make_type_signed.carbon b/toolchain/check/testdata/builtins/int/make_type_signed.carbon index 8b162496f932..ca9b6ccad856 100644 --- a/toolchain/check/testdata/builtins/int/make_type_signed.carbon +++ b/toolchain/check/testdata/builtins/int/make_type_signed.carbon @@ -6,13 +6,13 @@ // --- types.carbon -library "types" api; +library "types"; fn Int(n: i32) -> type = "int.make_type_signed"; // --- use_types.carbon -library "uses_types" api; +library "uses_types"; import library "types"; @@ -30,7 +30,7 @@ fn Symbolic(N:! i32, x: Int(N)) -> Int(N) { // --- fail_zero_size.carbon -library "fail_zero_size" api; +library "fail_zero_size"; import library "types"; @@ -42,7 +42,7 @@ var n: Int(0); // --- fail_negative_size.carbon -library "fail_negative_size" api; +library "fail_negative_size"; import library "types"; @@ -56,7 +56,7 @@ var n: Int(Negate(1)); // --- fail_oversized.carbon -library "fail_oversized" api; +library "fail_oversized"; import library "types"; diff --git a/toolchain/check/testdata/builtins/int/make_type_unsigned.carbon b/toolchain/check/testdata/builtins/int/make_type_unsigned.carbon index 3aaa48a35bbe..82346226f160 100644 --- a/toolchain/check/testdata/builtins/int/make_type_unsigned.carbon +++ b/toolchain/check/testdata/builtins/int/make_type_unsigned.carbon @@ -6,13 +6,13 @@ // --- types.carbon -library "types" api; +library "types"; fn UInt(n: i32) -> type = "int.make_type_unsigned"; // --- use_types.carbon -library "uses_types" api; +library "uses_types"; import library "types"; @@ -30,7 +30,7 @@ fn Symbolic(N:! i32, x: UInt(N)) -> UInt(N) { // --- fail_zero_size.carbon -library "fail_zero_size" api; +library "fail_zero_size"; import library "types"; @@ -42,7 +42,7 @@ var n: UInt(0); // --- fail_negative_size.carbon -library "fail_negative_size" api; +library "fail_negative_size"; import library "types"; @@ -56,7 +56,7 @@ var n: UInt(Negate(1)); // --- fail_oversized.carbon -library "fail_oversized" api; +library "fail_oversized"; import library "types"; diff --git a/toolchain/check/testdata/builtins/int/right_shift.carbon b/toolchain/check/testdata/builtins/int/right_shift.carbon index d223fd1d9dec..743465fb75ac 100644 --- a/toolchain/check/testdata/builtins/int/right_shift.carbon +++ b/toolchain/check/testdata/builtins/int/right_shift.carbon @@ -21,7 +21,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // TODO: Also test unsigned / logical right shift. -package ArithShift api; +package ArithShift; fn RightShift(a: i32, b: i32) -> i32 = "int.right_shift"; fn Negate(a: i32) -> i32 = "int.snegate"; @@ -36,7 +36,7 @@ let arr2_p: [i32; 3]* = &arr2; // --- fail_bad_shift.carbon -package BadShift api; +package BadShift; fn RightShift(a: i32, b: i32) -> i32 = "int.right_shift"; fn Negate(a: i32) -> i32 = "int.snegate"; diff --git a/toolchain/check/testdata/builtins/int/sadd.carbon b/toolchain/check/testdata/builtins/int/sadd.carbon index 5d70428ad174..d14faa99be13 100644 --- a/toolchain/check/testdata/builtins/int/sadd.carbon +++ b/toolchain/check/testdata/builtins/int/sadd.carbon @@ -17,7 +17,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: ERROR: Invalid signature for builtin function "int.sadd". // CHECK:STDERR: fn TooFew(a: i32) -> i32 = "int.sadd"; @@ -75,7 +75,7 @@ fn RuntimeCallBadReturnType(a: i32, b: i32) -> bool { // --- fail_overflow.carbon -package FailOverflow api; +package FailOverflow; fn Add(a: i32, b: i32) -> i32 = "int.sadd"; diff --git a/toolchain/check/testdata/builtins/int/sdiv.carbon b/toolchain/check/testdata/builtins/int/sdiv.carbon index 88e903dff310..93a490dabb5c 100644 --- a/toolchain/check/testdata/builtins/int/sdiv.carbon +++ b/toolchain/check/testdata/builtins/int/sdiv.carbon @@ -17,7 +17,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- fail_overflow.carbon -package FailOverflow api; +package FailOverflow; fn Div(a: i32, b: i32) -> i32 = "int.sdiv"; fn Sub(a: i32, b: i32) -> i32 = "int.ssub"; @@ -38,7 +38,7 @@ let c: i32 = Div(Sub(Negate(0x7FFF_FFFF), 1), Negate(1)); // --- fail_div_by_zero.carbon -package FailDivByZero api; +package FailDivByZero; fn Div(a: i32, b: i32) -> i32 = "int.sdiv"; diff --git a/toolchain/check/testdata/builtins/int/smod.carbon b/toolchain/check/testdata/builtins/int/smod.carbon index 9c2ac109e23f..36f572295597 100644 --- a/toolchain/check/testdata/builtins/int/smod.carbon +++ b/toolchain/check/testdata/builtins/int/smod.carbon @@ -17,7 +17,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- fail_overflow.carbon -package FailOverflow api; +package FailOverflow; fn Mod(a: i32, b: i32) -> i32 = "int.smod"; fn Sub(a: i32, b: i32) -> i32 = "int.ssub"; @@ -39,7 +39,7 @@ let c: i32 = Mod(Sub(Negate(0x7FFF_FFFF), 1), Negate(1)); // --- fail_div_by_zero.carbon -package FailDivByZero api; +package FailDivByZero; fn Mod(a: i32, b: i32) -> i32 = "int.smod"; diff --git a/toolchain/check/testdata/builtins/int/smul.carbon b/toolchain/check/testdata/builtins/int/smul.carbon index b537ccfaf8f3..f879239f6aa5 100644 --- a/toolchain/check/testdata/builtins/int/smul.carbon +++ b/toolchain/check/testdata/builtins/int/smul.carbon @@ -17,7 +17,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- fail_overflow.carbon -package FailOverflow api; +package FailOverflow; fn Mul(a: i32, b: i32) -> i32 = "int.smul"; diff --git a/toolchain/check/testdata/builtins/int/snegate.carbon b/toolchain/check/testdata/builtins/int/snegate.carbon index 5c88bfa59093..788d54037695 100644 --- a/toolchain/check/testdata/builtins/int/snegate.carbon +++ b/toolchain/check/testdata/builtins/int/snegate.carbon @@ -19,7 +19,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: ERROR: Invalid signature for builtin function "int.snegate". // CHECK:STDERR: fn TooFew() -> i32 = "int.snegate"; @@ -98,7 +98,7 @@ fn RuntimeCallBadReturnType(a: i32, b: i32) -> bool { // --- fail_overflow.carbon -package FailOverflow api; +package FailOverflow; fn Negate(a: i32) -> i32 = "int.snegate"; fn Sub(a: i32, b: i32) -> i32 = "int.ssub"; diff --git a/toolchain/check/testdata/builtins/int/ssub.carbon b/toolchain/check/testdata/builtins/int/ssub.carbon index 7197b15330f1..71a953c9d9da 100644 --- a/toolchain/check/testdata/builtins/int/ssub.carbon +++ b/toolchain/check/testdata/builtins/int/ssub.carbon @@ -17,7 +17,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- fail_overflow.carbon -package FailOverflow api; +package FailOverflow; fn Sub(a: i32, b: i32) -> i32 = "int.ssub"; diff --git a/toolchain/check/testdata/builtins/int/uadd.carbon b/toolchain/check/testdata/builtins/int/uadd.carbon index 66f0c43be040..69f7c8d4f06a 100644 --- a/toolchain/check/testdata/builtins/int/uadd.carbon +++ b/toolchain/check/testdata/builtins/int/uadd.carbon @@ -17,7 +17,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: ERROR: Invalid signature for builtin function "int.uadd". // CHECK:STDERR: fn TooFew(a: i32) -> i32 = "int.uadd"; @@ -74,7 +74,7 @@ fn RuntimeCallBadReturnType(a: i32, b: i32) -> bool { // --- overflow.carbon -package Overflow api; +package Overflow; fn Add(a: i32, b: i32) -> i32 = "int.uadd"; diff --git a/toolchain/check/testdata/builtins/int/udiv.carbon b/toolchain/check/testdata/builtins/int/udiv.carbon index 3f5a18e21509..674a3c0f9b94 100644 --- a/toolchain/check/testdata/builtins/int/udiv.carbon +++ b/toolchain/check/testdata/builtins/int/udiv.carbon @@ -17,7 +17,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- overflow.carbon -package Overflow api; +package Overflow; fn Div(a: i32, b: i32) -> i32 = "int.udiv"; fn Sub(a: i32, b: i32) -> i32 = "int.usub"; @@ -34,7 +34,7 @@ let c: i32 = Div(Sub(Negate(0x7FFF_FFFF), 1), Negate(1)); // --- fail_div_by_zero.carbon -package FailDivByZero api; +package FailDivByZero; fn Div(a: i32, b: i32) -> i32 = "int.udiv"; diff --git a/toolchain/check/testdata/builtins/int/umod.carbon b/toolchain/check/testdata/builtins/int/umod.carbon index 305dbf472622..af8cb16c4d8d 100644 --- a/toolchain/check/testdata/builtins/int/umod.carbon +++ b/toolchain/check/testdata/builtins/int/umod.carbon @@ -17,7 +17,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- overflow.carbon -package Overflow api; +package Overflow; fn Mod(a: i32, b: i32) -> i32 = "int.umod"; fn Sub(a: i32, b: i32) -> i32 = "int.usub"; @@ -34,7 +34,7 @@ let c: i32 = Mod(Sub(Negate(0x7FFF_FFFF), 1), Negate(1)); // --- fail_div_by_zero.carbon -package FailDivByZero api; +package FailDivByZero; fn Mod(a: i32, b: i32) -> i32 = "int.umod"; diff --git a/toolchain/check/testdata/builtins/int/umul.carbon b/toolchain/check/testdata/builtins/int/umul.carbon index 792630216c20..faaff2776f47 100644 --- a/toolchain/check/testdata/builtins/int/umul.carbon +++ b/toolchain/check/testdata/builtins/int/umul.carbon @@ -17,7 +17,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- overflow.carbon -package Overflow api; +package Overflow; fn Mul(a: i32, b: i32) -> i32 = "int.umul"; diff --git a/toolchain/check/testdata/builtins/int/unegate.carbon b/toolchain/check/testdata/builtins/int/unegate.carbon index 8b30041b807f..742cda4447e5 100644 --- a/toolchain/check/testdata/builtins/int/unegate.carbon +++ b/toolchain/check/testdata/builtins/int/unegate.carbon @@ -19,7 +19,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- fail_bad_decl.carbon -package FailBadDecl api; +package FailBadDecl; // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: ERROR: Invalid signature for builtin function "int.unegate". // CHECK:STDERR: fn TooFew() -> i32 = "int.unegate"; @@ -97,7 +97,7 @@ fn RuntimeCallBadReturnType(a: i32, b: i32) -> bool { // --- overflow.carbon -package Overflow api; +package Overflow; fn Negate(a: i32) -> i32 = "int.unegate"; fn Sub(a: i32, b: i32) -> i32 = "int.usub"; diff --git a/toolchain/check/testdata/builtins/int/usub.carbon b/toolchain/check/testdata/builtins/int/usub.carbon index 563a8b8efa1a..0bb446e07451 100644 --- a/toolchain/check/testdata/builtins/int/usub.carbon +++ b/toolchain/check/testdata/builtins/int/usub.carbon @@ -17,7 +17,7 @@ fn RuntimeCall(a: i32, b: i32) -> i32 { // --- overflow.carbon -package Overflow api; +package Overflow; fn Sub(a: i32, b: i32) -> i32 = "int.usub"; diff --git a/toolchain/check/testdata/class/adapt.carbon b/toolchain/check/testdata/class/adapt.carbon index bab1decc321e..a88b2fa293fc 100644 --- a/toolchain/check/testdata/class/adapt.carbon +++ b/toolchain/check/testdata/class/adapt.carbon @@ -6,7 +6,7 @@ // --- basic.carbon -library "basic" api; +library "basic"; class SomeClass { var a: i32; @@ -23,7 +23,7 @@ class StructAdapter { // --- fail_not_extend.carbon -library "fail_not_extend" api; +library "fail_not_extend"; class Adapted { fn F(); diff --git a/toolchain/check/testdata/class/cross_package_import.carbon b/toolchain/check/testdata/class/cross_package_import.carbon index ee1f7e1486d7..b3897794910d 100644 --- a/toolchain/check/testdata/class/cross_package_import.carbon +++ b/toolchain/check/testdata/class/cross_package_import.carbon @@ -10,19 +10,19 @@ // --- other_define.carbon -package Other library "define" api; +package Other library "define"; class C {} // --- other_extern.carbon -package Other library "extern" api; +package Other library "extern"; extern class C; // --- other_conflict.carbon -package Other library "conflict" api; +package Other library "conflict"; fn C() {} @@ -32,7 +32,7 @@ fn C() {} // --- define.carbon -library "define" api; +library "define"; import Other library "define"; @@ -40,7 +40,7 @@ var c: Other.C = {}; // --- fail_extern.carbon -library "extern" api; +library "extern"; import Other library "extern"; @@ -58,7 +58,7 @@ var c: Other.C = {}; // --- fail_todo_merge_define_extern.carbon -library "merge_define_extern" api; +library "merge_define_extern"; import Other library "define"; // CHECK:STDERR: fail_todo_merge_define_extern.carbon:[[@LINE+12]]:1: In import. @@ -83,7 +83,7 @@ var c: Other.C = {}; // --- fail_conflict.carbon -library "conflict" api; +library "conflict"; import Other library "define"; // CHECK:STDERR: fail_conflict.carbon:[[@LINE+12]]:1: In import. diff --git a/toolchain/check/testdata/class/extend_adapt.carbon b/toolchain/check/testdata/class/extend_adapt.carbon index 5cded64494b3..bf26a841d092 100644 --- a/toolchain/check/testdata/class/extend_adapt.carbon +++ b/toolchain/check/testdata/class/extend_adapt.carbon @@ -6,7 +6,7 @@ // --- basic.carbon -library "basic" api; +library "basic"; class SomeClassAdapter; @@ -33,7 +33,7 @@ fn TestAdapterMethod(a: SomeClassAdapter) { // --- fail_todo_method_access.carbon -library "fail_todo_method_access" api; +library "fail_todo_method_access"; class SomeClass { fn F[self: Self](); @@ -56,7 +56,7 @@ fn F(a: SomeClassAdapter) { // --- fail_todo_field_access.carbon -library "fail_todo_field_access" api; +library "fail_todo_field_access"; class SomeClass { var a: i32; @@ -77,7 +77,7 @@ fn F(a: SomeClassAdapter) -> i32 { // --- fail_todo_adapt_non_class.carbon -library "fail_todo_adapt_non_class" api; +library "fail_todo_adapt_non_class"; class StructAdapter { // CHECK:STDERR: fail_todo_adapt_non_class.carbon:[[@LINE+3]]:3: ERROR: Semantics TODO: `extending non-class type`. diff --git a/toolchain/check/testdata/class/extern.carbon b/toolchain/check/testdata/class/extern.carbon index b959e1a34a14..2633f4c0c839 100644 --- a/toolchain/check/testdata/class/extern.carbon +++ b/toolchain/check/testdata/class/extern.carbon @@ -10,25 +10,25 @@ // --- decl.carbon -library "decl" api; +library "decl"; class C; // --- extern_decl.carbon -library "extern_decl" api; +library "extern_decl"; extern class C; // --- extern_decl_copy.carbon -library "extern_decl_copy" api; +library "extern_decl_copy"; extern class C; // --- def.carbon -library "def" api; +library "def"; class C {} @@ -38,7 +38,7 @@ class C {} // --- fail_decl_fn_in_extern.carbon -library "fail_decl_fn_in_extern" api; +library "fail_decl_fn_in_extern"; extern class C; // CHECK:STDERR: fail_decl_fn_in_extern.carbon:[[@LINE+7]]:4: ERROR: Cannot declare a member of incomplete class `C`. @@ -52,7 +52,7 @@ fn C.F(); // --- fail_extern_def.carbon -library "fail_extern_def" api; +library "fail_extern_def"; // CHECK:STDERR: fail_extern_def.carbon:[[@LINE+4]]:1: ERROR: `extern` not allowed on `class` declaration that provides a definition. // CHECK:STDERR: extern class C {} @@ -62,7 +62,7 @@ extern class C {} // --- fail_extern_decl_after_extern_decl.carbon -library "fail_extern_decl_after_extern_decl" api; +library "fail_extern_decl_after_extern_decl"; extern class C; // CHECK:STDERR: fail_extern_decl_after_extern_decl.carbon:[[@LINE+7]]:1: ERROR: Redeclaration of `class C` is redundant. @@ -76,7 +76,7 @@ extern class C; // --- fail_decl_after_extern_decl.carbon -library "fail_decl_after_extern_decl" api; +library "fail_decl_after_extern_decl"; extern class C; // CHECK:STDERR: fail_decl_after_extern_decl.carbon:[[@LINE+7]]:1: ERROR: Redeclaration of `class C` is redundant. @@ -90,7 +90,7 @@ class C; // --- fail_extern_member_class.carbon -library "fail_extern_member_class" api; +library "fail_extern_member_class"; class C { // CHECK:STDERR: fail_extern_member_class.carbon:[[@LINE+4]]:3: ERROR: `extern` not allowed on `class` declaration that is a member. @@ -102,14 +102,14 @@ class C { // --- todo_fail_def_after_extern_decl.carbon -library "fail_def_after_extern_decl" api; +library "fail_def_after_extern_decl"; extern class C; class C {} // --- fail_extern_decl_after_decl.carbon -library "fail_extern_decl_after_decl" api; +library "fail_extern_decl_after_decl"; class C; // CHECK:STDERR: fail_extern_decl_after_decl.carbon:[[@LINE+7]]:1: ERROR: Redeclaration of `class C` is redundant. @@ -123,7 +123,7 @@ extern class C; // --- fail_todo_import_extern_decl_then_decl.carbon -library "import_extern_decl_then_decl" api; +library "import_extern_decl_then_decl"; import library "extern_decl"; // CHECK:STDERR: fail_todo_import_extern_decl_then_decl.carbon:[[@LINE+13]]:1: In import. @@ -143,7 +143,7 @@ import library "decl"; // --- fail_todo_import_decl_then_extern_decl.carbon -library "import_decl_then_extern_decl" api; +library "import_decl_then_extern_decl"; import library "decl"; // CHECK:STDERR: fail_todo_import_decl_then_extern_decl.carbon:[[@LINE+13]]:1: In import. @@ -163,7 +163,7 @@ import library "extern_decl"; // --- fail_todo_import_extern_decl_then_def.carbon -library "import_extern_decl_then_def" api; +library "import_extern_decl_then_def"; import library "extern_decl"; // CHECK:STDERR: fail_todo_import_extern_decl_then_def.carbon:[[@LINE+13]]:1: In import. @@ -183,7 +183,7 @@ import library "def"; // --- fail_import_ownership_conflict.carbon -library "fail_import_ownership_conflict" api; +library "fail_import_ownership_conflict"; import library "extern_decl"; // CHECK:STDERR: fail_import_ownership_conflict.carbon:[[@LINE+13]]:1: In import. @@ -217,7 +217,7 @@ import library "def"; // --- fail_todo_import_extern_decl_copy.carbon -library "import_extern_decl_copy" api; +library "import_extern_decl_copy"; import library "extern_decl"; // CHECK:STDERR: fail_todo_import_extern_decl_copy.carbon:[[@LINE+12]]:1: In import. @@ -236,7 +236,7 @@ import library "extern_decl_copy"; // --- extern_decl_after_import_extern_decl.carbon -library "extern_decl_after_import_extern_decl" api; +library "extern_decl_after_import_extern_decl"; import library "extern_decl"; @@ -244,7 +244,7 @@ extern class C; // --- decl_after_import_extern_decl.carbon -library "decl_after_import_extern_decl" api; +library "decl_after_import_extern_decl"; import library "decl"; @@ -252,7 +252,7 @@ extern class C; // --- def_after_import_extern_decl.carbon -library "def_after_import_extern_decl" api; +library "def_after_import_extern_decl"; import library "def"; @@ -260,7 +260,7 @@ extern class C; // --- extern_decl_after_import_def.carbon -library "extern_decl_after_import_def" api; +library "extern_decl_after_import_def"; import library "def"; diff --git a/toolchain/check/testdata/class/fail_adapt_bad_decl.carbon b/toolchain/check/testdata/class/fail_adapt_bad_decl.carbon index 2e0178470973..d9a09b658a0e 100644 --- a/toolchain/check/testdata/class/fail_adapt_bad_decl.carbon +++ b/toolchain/check/testdata/class/fail_adapt_bad_decl.carbon @@ -6,7 +6,7 @@ // --- fail_not_type.carbon -library "not_type" api; +library "not_type"; class Bad { // CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:3: ERROR: Cannot implicitly convert from `i32` to `type`. @@ -24,7 +24,7 @@ fn Use(b: Bad) { b.F(); } // --- fail_extend_not_type.carbon -library "extend_not_type" api; +library "extend_not_type"; class Bad { // CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+4]]:3: ERROR: Cannot implicitly convert from `i32` to `type`. @@ -39,7 +39,7 @@ fn Use(b: Bad) { b.F(); } // --- fail_repeated.carbon -library "fail_repeated" api; +library "fail_repeated"; class MultipleAdapts { adapt (); @@ -67,7 +67,7 @@ class MultipleAdaptsSameType { // --- fail_bad_scope.carbon -library "fail_bad_scope" api; +library "fail_bad_scope"; // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:1: ERROR: `adapt` declaration can only be used in a class. // CHECK:STDERR: adapt {}; diff --git a/toolchain/check/testdata/class/fail_adapt_bad_type.carbon b/toolchain/check/testdata/class/fail_adapt_bad_type.carbon index 1761ba513177..2c3607dbd876 100644 --- a/toolchain/check/testdata/class/fail_adapt_bad_type.carbon +++ b/toolchain/check/testdata/class/fail_adapt_bad_type.carbon @@ -6,7 +6,7 @@ // --- fail_incomplete_type.carbon -library "incomplete_type" api; +library "incomplete_type"; class Incomplete; diff --git a/toolchain/check/testdata/class/fail_adapt_with_subobjects.carbon b/toolchain/check/testdata/class/fail_adapt_with_subobjects.carbon index f67db46a4854..c7cf29a8f491 100644 --- a/toolchain/check/testdata/class/fail_adapt_with_subobjects.carbon +++ b/toolchain/check/testdata/class/fail_adapt_with_subobjects.carbon @@ -6,7 +6,7 @@ // --- fail_adapt_with_base.carbon -library "fail_adapt_with_base" api; +library "fail_adapt_with_base"; base class Base {} @@ -24,7 +24,7 @@ class AdaptWithBase { // --- fail_adapt_with_fields.carbon -library "fail_adapt_with_fields" api; +library "fail_adapt_with_fields"; class AdaptWithField { // CHECK:STDERR: fail_adapt_with_fields.carbon:[[@LINE+3]]:3: ERROR: Adapter cannot have fields. @@ -54,7 +54,7 @@ class AdaptWithFields { // --- fail_adapt_with_base_and_fields.carbon -library "fail_adapt_with_base_and_fields" api; +library "fail_adapt_with_base_and_fields"; base class Base {} diff --git a/toolchain/check/testdata/class/fail_import_misuses.carbon b/toolchain/check/testdata/class/fail_import_misuses.carbon index 5c357c479621..d2716f7f72f3 100644 --- a/toolchain/check/testdata/class/fail_import_misuses.carbon +++ b/toolchain/check/testdata/class/fail_import_misuses.carbon @@ -6,7 +6,7 @@ // --- a.carbon -library "a" api; +library "a"; class Empty { } @@ -15,7 +15,7 @@ class Incomplete; // --- fail_b.carbon -library "b" api; +library "b"; import library "a"; diff --git a/toolchain/check/testdata/class/fail_redeclaration_introducer.carbon b/toolchain/check/testdata/class/fail_redeclaration_introducer.carbon index 0dd1366ebd75..8ee5f5f564fc 100644 --- a/toolchain/check/testdata/class/fail_redeclaration_introducer.carbon +++ b/toolchain/check/testdata/class/fail_redeclaration_introducer.carbon @@ -6,7 +6,7 @@ // --- fail_add_base.carbon -library "fail_add_base" api; +library "fail_add_base"; class A; // CHECK:STDERR: fail_add_base.carbon:[[@LINE+7]]:1: ERROR: Class redeclared with different inheritance kind. @@ -20,7 +20,7 @@ base class A {} // --- fail_add_abstract.carbon -library "fail_add_abstract" api; +library "fail_add_abstract"; class B; // CHECK:STDERR: fail_add_abstract.carbon:[[@LINE+7]]:1: ERROR: Class redeclared with different inheritance kind. @@ -34,7 +34,7 @@ abstract class B {} // --- fail_remove_base.carbon -library "fail_remove_base" api; +library "fail_remove_base"; base class C; // CHECK:STDERR: fail_remove_base.carbon:[[@LINE+7]]:1: ERROR: Class redeclared with different inheritance kind. @@ -48,7 +48,7 @@ class C {} // --- fail_base_to_abstract.carbon -library "fail_base_to_abstract" api; +library "fail_base_to_abstract"; base class D; // CHECK:STDERR: fail_base_to_abstract.carbon:[[@LINE+7]]:1: ERROR: Class redeclared with different inheritance kind. @@ -62,7 +62,7 @@ abstract class D {} // --- fail_remove_abstract.carbon -library "fail_remove_abstract" api; +library "fail_remove_abstract"; abstract class E; // CHECK:STDERR: fail_remove_abstract.carbon:[[@LINE+7]]:1: ERROR: Class redeclared with different inheritance kind. @@ -76,7 +76,7 @@ class E {} // --- fail_abstract_to_base.carbon -library "fail_abstract_to_base" api; +library "fail_abstract_to_base"; abstract class F; // CHECK:STDERR: fail_abstract_to_base.carbon:[[@LINE+6]]:1: ERROR: Class redeclared with different inheritance kind. diff --git a/toolchain/check/testdata/class/generic/call.carbon b/toolchain/check/testdata/class/generic/call.carbon index 4d3cd46eea3a..e25c11b0c49d 100644 --- a/toolchain/check/testdata/class/generic/call.carbon +++ b/toolchain/check/testdata/class/generic/call.carbon @@ -6,7 +6,7 @@ // --- call.carbon -library "call" api; +library "call"; class Class(T:! type, N:! i32) {} @@ -17,7 +17,7 @@ var b: Class((), 0); // --- fail_too_few.carbon -library "too_few" api; +library "too_few"; class Class(T:! type, N:! i32) {} @@ -32,7 +32,7 @@ var a: Class(i32*); // --- fail_too_many.carbon -library "too_many" api; +library "too_many"; class Class(T:! type, N:! i32) {} @@ -47,7 +47,7 @@ var a: Class(i32*, 1, 2); // --- fail_no_conversion.carbon -library "no_conversion" api; +library "no_conversion"; class Class(T:! type, N:! i32) {} diff --git a/toolchain/check/testdata/class/generic/import.carbon b/toolchain/check/testdata/class/generic/import.carbon index f7f04cc88b2e..17d7008fde80 100644 --- a/toolchain/check/testdata/class/generic/import.carbon +++ b/toolchain/check/testdata/class/generic/import.carbon @@ -6,13 +6,13 @@ // --- foo.carbon -library "foo" api; +library "foo"; class Class(T:! type); // --- foo.impl.carbon -library "foo" impl; +impl library "foo"; class Class(T:! type) { var x: T; @@ -20,7 +20,7 @@ class Class(T:! type) { // --- fail_bad_foo.impl.carbon -library "foo" impl; +impl library "foo"; // CHECK:STDERR: fail_bad_foo.impl.carbon:[[@LINE+5]]:13: ERROR: Redeclaration differs at parameter 1. // CHECK:STDERR: class Class(U:! type) { diff --git a/toolchain/check/testdata/class/generic/redeclare.carbon b/toolchain/check/testdata/class/generic/redeclare.carbon index b91cd1a7d045..69b742b8ea2e 100644 --- a/toolchain/check/testdata/class/generic/redeclare.carbon +++ b/toolchain/check/testdata/class/generic/redeclare.carbon @@ -6,7 +6,7 @@ // --- valid.carbon -library "valid" api; +library "valid"; class Generic(T:! type); @@ -15,7 +15,7 @@ class Generic(T:! type) { // --- fail_mismatch_param_list.carbon -library "mismatch_param_list" api; +library "mismatch_param_list"; class A; // CHECK:STDERR: fail_mismatch_param_list.carbon:[[@LINE+7]]:1: ERROR: Redeclaration differs because of parameter list. @@ -29,7 +29,7 @@ class A(T:! type) {} // --- fail_mismatch_implicit_param_list.carbon -library "implicit_mismatch_param_list" api; +library "implicit_mismatch_param_list"; class B(N:! i32); // CHECK:STDERR: fail_mismatch_implicit_param_list.carbon:[[@LINE+7]]:1: ERROR: Redeclaration differs because of implicit parameter list. @@ -43,7 +43,7 @@ class B[T:! type](N:! T) {} // --- fail_mismatch_param_count.carbon -library "mismatch_param_count" api; +library "mismatch_param_count"; class C(T:! type); // CHECK:STDERR: fail_mismatch_param_count.carbon:[[@LINE+7]]:1: ERROR: Redeclaration differs because of parameter count of 2. @@ -57,7 +57,7 @@ class C(T:! type, U:! i32) {} // --- fail_mismatch_param_type.carbon -library "mismatch_param_type" api; +library "mismatch_param_type"; class D(T:! type); // CHECK:STDERR: fail_mismatch_param_type.carbon:[[@LINE+7]]:9: ERROR: Redeclaration differs at parameter 1. @@ -71,7 +71,7 @@ class D(T:! i32) {} // --- fail_mismatch_param_name.carbon -library "mismatch_param_name" api; +library "mismatch_param_name"; class E(T:! type); // CHECK:STDERR: fail_mismatch_param_name.carbon:[[@LINE+6]]:9: ERROR: Redeclaration differs at parameter 1. diff --git a/toolchain/check/testdata/class/import.carbon b/toolchain/check/testdata/class/import.carbon index f72c3e15c99d..75436e63dbef 100644 --- a/toolchain/check/testdata/class/import.carbon +++ b/toolchain/check/testdata/class/import.carbon @@ -6,7 +6,7 @@ // --- a.carbon -library "a" api; +library "a"; class Empty { } @@ -26,7 +26,7 @@ class Incomplete; // --- b.carbon -library "b" api; +library "b"; import library "a"; diff --git a/toolchain/check/testdata/class/import_base.carbon b/toolchain/check/testdata/class/import_base.carbon index c89176264f0d..7809dfa16429 100644 --- a/toolchain/check/testdata/class/import_base.carbon +++ b/toolchain/check/testdata/class/import_base.carbon @@ -6,7 +6,7 @@ // --- a.carbon -library "a" api; +library "a"; base class Base { fn F[self: Self](); @@ -22,7 +22,7 @@ class Child { // --- b.carbon -library "b" api; +library "b"; import library "a"; diff --git a/toolchain/check/testdata/class/import_forward_decl.carbon b/toolchain/check/testdata/class/import_forward_decl.carbon index c7a57a638abc..890e6939d78c 100644 --- a/toolchain/check/testdata/class/import_forward_decl.carbon +++ b/toolchain/check/testdata/class/import_forward_decl.carbon @@ -6,13 +6,13 @@ // --- a.carbon -library "a" api; +library "a"; class ForwardDecl; // --- a.impl.carbon -library "a" impl; +impl library "a"; class ForwardDecl { } diff --git a/toolchain/check/testdata/class/import_indirect.carbon b/toolchain/check/testdata/class/import_indirect.carbon index 5aeab598855f..96a810d7cb05 100644 --- a/toolchain/check/testdata/class/import_indirect.carbon +++ b/toolchain/check/testdata/class/import_indirect.carbon @@ -26,13 +26,13 @@ // --- a.carbon -library "a" api; +library "a"; class C {} // --- b.carbon -library "b" api; +library "b"; import library "a"; @@ -43,7 +43,7 @@ var b_ptr: D* = &b_val; // --- c.carbon -library "c" api; +library "c"; import library "a"; @@ -58,7 +58,7 @@ var c_ptr: E* = &c_val; // --- triangle.carbon -library "triangle" api; +library "triangle"; import library "a"; import library "b"; @@ -68,7 +68,7 @@ var ptr: D* = &val; // --- triangle_reverse.carbon -library "triangle_reverse" api; +library "triangle_reverse"; import library "b"; import library "a"; @@ -78,7 +78,7 @@ var ptr: D* = &val; // --- diamond.carbon -library "diamond" api; +library "diamond"; import library "b"; import library "c"; @@ -88,7 +88,7 @@ var ptr: E* = &val; // --- diamond_reverse.carbon -library "diamond_reverse" api; +library "diamond_reverse"; import library "c"; import library "b"; diff --git a/toolchain/check/testdata/class/import_member_cycle.carbon b/toolchain/check/testdata/class/import_member_cycle.carbon index c29db6dd8048..5737bad160e4 100644 --- a/toolchain/check/testdata/class/import_member_cycle.carbon +++ b/toolchain/check/testdata/class/import_member_cycle.carbon @@ -6,7 +6,7 @@ // --- a.carbon -library "a" api; +library "a"; class Cycle { var a: Cycle*; @@ -14,7 +14,7 @@ class Cycle { // --- b.carbon -library "b" api; +library "b"; import library "a"; diff --git a/toolchain/check/testdata/class/import_struct_cyle.carbon b/toolchain/check/testdata/class/import_struct_cyle.carbon index 21a16a0cd9c4..72a0dd2f626f 100644 --- a/toolchain/check/testdata/class/import_struct_cyle.carbon +++ b/toolchain/check/testdata/class/import_struct_cyle.carbon @@ -6,7 +6,7 @@ // --- a.carbon -library "a" api; +library "a"; class Cycle; @@ -19,7 +19,7 @@ class Cycle { // --- b.carbon -library "b" api; +library "b"; import library "a"; diff --git a/toolchain/check/testdata/class/init_adapt.carbon b/toolchain/check/testdata/class/init_adapt.carbon index d9d9d75ea57f..48812a2366a7 100644 --- a/toolchain/check/testdata/class/init_adapt.carbon +++ b/toolchain/check/testdata/class/init_adapt.carbon @@ -6,7 +6,7 @@ // --- init_adapt.carbon -library "init_adapt" api; +library "init_adapt"; class C { var a: i32; @@ -33,7 +33,7 @@ var e: C = MakeAdaptC() as C; // --- fail_not_implicit.carbon -library "fail_not_implicit" api; +library "fail_not_implicit"; class C { var a: i32; diff --git a/toolchain/check/testdata/class/no_prelude/export_name.carbon b/toolchain/check/testdata/class/no_prelude/export_name.carbon index e1f0a2269954..648e555e38d0 100644 --- a/toolchain/check/testdata/class/no_prelude/export_name.carbon +++ b/toolchain/check/testdata/class/no_prelude/export_name.carbon @@ -10,13 +10,13 @@ // --- base.carbon -library "base" api; +library "base"; class C {} // --- export.carbon -library "export" api; +library "export"; import library "base"; @@ -28,7 +28,7 @@ export C; // --- use_export.carbon -library "use_export" api; +library "use_export"; import library "export"; diff --git a/toolchain/check/testdata/class/no_prelude/implicit_import.carbon b/toolchain/check/testdata/class/no_prelude/implicit_import.carbon index fa29f4404fd0..7936f7eeb47b 100644 --- a/toolchain/check/testdata/class/no_prelude/implicit_import.carbon +++ b/toolchain/check/testdata/class/no_prelude/implicit_import.carbon @@ -6,32 +6,32 @@ // --- basic.carbon -library "basic" api; +library "basic"; class C; // --- basic.impl.carbon -library "basic" impl; +impl library "basic"; class C {} // --- redecl_after_def.carbon -library "redecl_after_def" api; +library "redecl_after_def"; class C {} // --- fail_redecl_after_def.impl.carbon -library "redecl_after_def" impl; +impl library "redecl_after_def"; // CHECK:STDERR: fail_redecl_after_def.impl.carbon:[[@LINE+10]]:1: ERROR: Redeclaration of `class C` is redundant. // CHECK:STDERR: class C; // CHECK:STDERR: ^~~~~~~~ -// CHECK:STDERR: fail_redecl_after_def.impl.carbon:[[@LINE-5]]:1: In import. -// CHECK:STDERR: library "redecl_after_def" impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_redecl_after_def.impl.carbon:[[@LINE-5]]:6: In import. +// CHECK:STDERR: impl library "redecl_after_def"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: redecl_after_def.carbon:4:1: Previously declared here. // CHECK:STDERR: class C {} // CHECK:STDERR: ^~~~~~~~~ @@ -40,20 +40,20 @@ class C; // --- redef_after_def.carbon -library "redef_after_def" api; +library "redef_after_def"; class C {} // --- fail_redef_after_def.impl.carbon -library "redef_after_def" impl; +impl library "redef_after_def"; // CHECK:STDERR: fail_redef_after_def.impl.carbon:[[@LINE+10]]:1: ERROR: Redefinition of `class C`. // CHECK:STDERR: class C {} // CHECK:STDERR: ^~~~~~~~~ -// CHECK:STDERR: fail_redef_after_def.impl.carbon:[[@LINE-5]]:1: In import. -// CHECK:STDERR: library "redef_after_def" impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_redef_after_def.impl.carbon:[[@LINE-5]]:6: In import. +// CHECK:STDERR: impl library "redef_after_def"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: redef_after_def.carbon:4:1: Previously defined here. // CHECK:STDERR: class C {} // CHECK:STDERR: ^~~~~~~~~ @@ -62,21 +62,21 @@ class C {} // --- def_alias.carbon -library "def_alias" api; +library "def_alias"; class C; alias B = C; // --- fail_def_alias.impl.carbon -library "def_alias" impl; +impl library "def_alias"; // CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE+9]]:1: ERROR: Duplicate name being declared in the same scope. // CHECK:STDERR: class 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: fail_def_alias.impl.carbon:[[@LINE-5]]:6: In import. +// CHECK:STDERR: impl library "def_alias"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: def_alias.carbon:5:7: Name is previously declared here. // CHECK:STDERR: alias B = C; // CHECK:STDERR: ^ diff --git a/toolchain/check/testdata/const/import.carbon b/toolchain/check/testdata/const/import.carbon index a0a72542c511..98a2fc4c4017 100644 --- a/toolchain/check/testdata/const/import.carbon +++ b/toolchain/check/testdata/const/import.carbon @@ -6,7 +6,7 @@ // --- implicit.carbon -package Implicit api; +package Implicit; fn F() -> const i32; @@ -15,7 +15,7 @@ var a_ptr_ref: const i32* = &a_ref; // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; // Take a reference to avoid unsupported copy logic. This still validates the // `const` is handled. diff --git a/toolchain/check/testdata/function/builtin/call_from_operator.carbon b/toolchain/check/testdata/function/builtin/call_from_operator.carbon index 140664b9e708..56beeb5f17d9 100644 --- a/toolchain/check/testdata/function/builtin/call_from_operator.carbon +++ b/toolchain/check/testdata/function/builtin/call_from_operator.carbon @@ -6,7 +6,7 @@ // --- core.carbon -package Core api; +package Core; interface Add { fn Op[self: Self](other: Self) -> Self; diff --git a/toolchain/check/testdata/function/builtin/import.carbon b/toolchain/check/testdata/function/builtin/import.carbon index 235e10ea8a09..273873ece8d0 100644 --- a/toolchain/check/testdata/function/builtin/import.carbon +++ b/toolchain/check/testdata/function/builtin/import.carbon @@ -6,7 +6,7 @@ // --- core.carbon -package Core api; +package Core; import library "prelude"; diff --git a/toolchain/check/testdata/function/declaration/import.carbon b/toolchain/check/testdata/function/declaration/import.carbon index 78df985b7126..ba2355d3b3b4 100644 --- a/toolchain/check/testdata/function/declaration/import.carbon +++ b/toolchain/check/testdata/function/declaration/import.carbon @@ -10,7 +10,7 @@ // --- api.carbon -library "api" api; +library "api"; fn A(); fn B(b: i32) -> i32; @@ -22,7 +22,7 @@ fn NS.E(); // --- extern_api.carbon -library "extern_api" api; +library "extern_api"; extern fn A(); extern fn B(b: i32) -> i32; @@ -38,7 +38,7 @@ extern fn NS.E(); // --- basics.carbon -library "basics" api; +library "basics"; import library "api"; @@ -50,7 +50,7 @@ var e: () = NS.E(); // --- redecl_api.carbon -library "redecl_api" api; +library "redecl_api"; import library "api"; @@ -68,7 +68,7 @@ var e: () = NS.E(); // --- redecl_extern_api.carbon -library "redecl_extern_api" api; +library "redecl_extern_api"; import library "extern_api"; @@ -86,7 +86,7 @@ var e: () = NS.E(); // --- fail_todo_merge.carbon -library "merge" api; +library "merge"; import library "api"; // CHECK:STDERR: fail_todo_merge.carbon:[[@LINE+65]]:1: In import. @@ -164,7 +164,7 @@ var e: () = NS.E(); // --- fail_todo_merge_reverse.carbon -library "merge_reverse" api; +library "merge_reverse"; import library "extern_api"; // CHECK:STDERR: fail_todo_merge_reverse.carbon:[[@LINE+65]]:1: In import. @@ -242,7 +242,7 @@ var e: () = NS.E(); // --- decl_after_use.carbon -library "decl_after_use" api; +library "decl_after_use"; import library "extern_api"; @@ -252,7 +252,7 @@ fn A(); // --- fail_redecl_mismatch_after_use.carbon -library "redecl_mismatch_after_use" api; +library "redecl_mismatch_after_use"; import library "extern_api"; @@ -272,7 +272,7 @@ fn A() -> i32; // --- todo_fail_extern_after_use.carbon -library "extern_after_use" api; +library "extern_after_use"; import library "api"; @@ -282,19 +282,19 @@ extern fn A(); // --- unloaded.carbon -library "unloaded" api; +library "unloaded"; import library "api"; // --- unloaded_extern.carbon -library "unloaded_extern" api; +library "unloaded_extern"; import library "extern_api"; // --- fail_todo_loaded_merge.carbon -library "loaded_merge" api; +library "loaded_merge"; import library "api"; // CHECK:STDERR: fail_todo_loaded_merge.carbon:[[@LINE+64]]:1: In import. diff --git a/toolchain/check/testdata/function/declaration/no_prelude/export_name.carbon b/toolchain/check/testdata/function/declaration/no_prelude/export_name.carbon index ee430b6534e4..cd1467ff2ef0 100644 --- a/toolchain/check/testdata/function/declaration/no_prelude/export_name.carbon +++ b/toolchain/check/testdata/function/declaration/no_prelude/export_name.carbon @@ -10,13 +10,13 @@ // --- base.carbon -library "base" api; +library "base"; fn F(); // --- export.carbon -library "export" api; +library "export"; import library "base"; @@ -28,7 +28,7 @@ export F; // --- use_export.carbon -library "use_export" api; +library "use_export"; import library "export"; diff --git a/toolchain/check/testdata/function/declaration/no_prelude/extern.carbon b/toolchain/check/testdata/function/declaration/no_prelude/extern.carbon index 6a9de2602d10..900486fd62b6 100644 --- a/toolchain/check/testdata/function/declaration/no_prelude/extern.carbon +++ b/toolchain/check/testdata/function/declaration/no_prelude/extern.carbon @@ -6,13 +6,13 @@ // --- basic.carbon -library "basic" api; +library "basic"; extern fn F(); // --- fail_redecl.carbon -library "redecl" api; +library "redecl"; extern fn F(); // CHECK:STDERR: fail_redecl.carbon:[[@LINE+7]]:1: ERROR: Redeclaration of `fn F` is redundant. @@ -26,7 +26,7 @@ extern fn F(); // --- fail_redecl_extern.carbon -library "redecl_extern" api; +library "redecl_extern"; extern fn F(); // CHECK:STDERR: fail_redecl_extern.carbon:[[@LINE+7]]:1: ERROR: Redeclaration of `fn F` is redundant. diff --git a/toolchain/check/testdata/function/declaration/no_prelude/fail_import_incomplete_return.carbon b/toolchain/check/testdata/function/declaration/no_prelude/fail_import_incomplete_return.carbon index 2eb87dcab875..8d269cbd2ceb 100644 --- a/toolchain/check/testdata/function/declaration/no_prelude/fail_import_incomplete_return.carbon +++ b/toolchain/check/testdata/function/declaration/no_prelude/fail_import_incomplete_return.carbon @@ -6,7 +6,7 @@ // --- fail_incomplete_return.carbon -library "api" api; +library "api"; class C; class D; @@ -45,7 +45,7 @@ class D {} // --- fail_use_imported.carbon -library "use_imported" api; +library "use_imported"; import library "api"; diff --git a/toolchain/check/testdata/function/declaration/no_prelude/implicit_import.carbon b/toolchain/check/testdata/function/declaration/no_prelude/implicit_import.carbon index 0591331a0558..7e3666ce73e8 100644 --- a/toolchain/check/testdata/function/declaration/no_prelude/implicit_import.carbon +++ b/toolchain/check/testdata/function/declaration/no_prelude/implicit_import.carbon @@ -6,32 +6,32 @@ // --- basic.carbon -library "basic" api; +library "basic"; fn A(); // --- basic.impl.carbon -library "basic" impl; +impl library "basic"; fn A(); // --- extern_api.carbon -library "extern_api" api; +library "extern_api"; extern fn A(); // --- fail_extern_api.impl.carbon -library "extern_api" impl; +impl library "extern_api"; // CHECK:STDERR: fail_extern_api.impl.carbon:[[@LINE+10]]:1: ERROR: Redeclarations of `fn A` in the same library must match use of `extern`. // CHECK:STDERR: fn A(); // CHECK:STDERR: ^~~~~~~ -// CHECK:STDERR: fail_extern_api.impl.carbon:[[@LINE-5]]:1: In import. -// CHECK:STDERR: library "extern_api" impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_extern_api.impl.carbon:[[@LINE-5]]:6: In import. +// CHECK:STDERR: impl library "extern_api"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: extern_api.carbon:4:1: Previously declared here. // CHECK:STDERR: extern fn A(); // CHECK:STDERR: ^~~~~~~~~~~~~~ @@ -40,20 +40,20 @@ fn A(); // --- extern_impl.carbon -library "extern_impl" api; +library "extern_impl"; fn A(); // --- fail_extern_impl.impl.carbon -library "extern_impl" impl; +impl library "extern_impl"; // CHECK:STDERR: fail_extern_impl.impl.carbon:[[@LINE+9]]:1: ERROR: Redeclarations of `fn A` in the same library must match use of `extern`. // CHECK:STDERR: extern fn A(); // CHECK:STDERR: ^~~~~~~~~~~~~~ -// CHECK:STDERR: fail_extern_impl.impl.carbon:[[@LINE-5]]:1: In import. -// CHECK:STDERR: library "extern_impl" impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_extern_impl.impl.carbon:[[@LINE-5]]:6: In import. +// CHECK:STDERR: impl library "extern_impl"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: extern_impl.carbon:4:1: Previously declared here. // CHECK:STDERR: fn A(); // CHECK:STDERR: ^~~~~~~ diff --git a/toolchain/check/testdata/function/definition/import.carbon b/toolchain/check/testdata/function/definition/import.carbon index 248524eb341f..fbfefce52c44 100644 --- a/toolchain/check/testdata/function/definition/import.carbon +++ b/toolchain/check/testdata/function/definition/import.carbon @@ -10,7 +10,7 @@ // --- fns.carbon -library "fns" api; +library "fns"; fn A() {} fn B(b: i32) -> i32 { return b; } @@ -19,7 +19,7 @@ fn D(); // --- extern.carbon -library "extern" api; +library "extern"; extern fn A(); @@ -29,7 +29,7 @@ extern fn A(); // --- basics.carbon -library "basics" api; +library "basics"; import library "fns"; @@ -39,7 +39,7 @@ var c: {.c: i32} = C((1,)); // --- fail_def_ownership.carbon -library "def_ownership" api; +library "def_ownership"; import library "fns"; @@ -68,7 +68,7 @@ fn B(b: i32) -> i32; // --- redecl_then_def.carbon -library "redecl_then_def" api; +library "redecl_then_def"; import library "extern"; @@ -77,7 +77,7 @@ fn A() {} // --- fail_mix_extern_decl.carbon -library "mix_extern_decl" api; +library "mix_extern_decl"; import library "fns"; diff --git a/toolchain/check/testdata/function/definition/no_prelude/extern.carbon b/toolchain/check/testdata/function/definition/no_prelude/extern.carbon index 3453bfabd177..b269cbf6769c 100644 --- a/toolchain/check/testdata/function/definition/no_prelude/extern.carbon +++ b/toolchain/check/testdata/function/definition/no_prelude/extern.carbon @@ -6,7 +6,7 @@ // --- fail_extern_def.carbon -library "extern_def" api; +library "extern_def"; // CHECK:STDERR: fail_extern_def.carbon:[[@LINE+4]]:1: ERROR: `extern` not allowed on `fn` declaration that provides a definition. // CHECK:STDERR: extern fn F() {} @@ -16,7 +16,7 @@ extern fn F() {} // --- fail_def_for_extern_decl.carbon -library "def_for_extern_decl" api; +library "def_for_extern_decl"; extern fn F(); // CHECK:STDERR: fail_def_for_extern_decl.carbon:[[@LINE+7]]:1: ERROR: Redeclarations of `fn F` in the same library must match use of `extern`. @@ -30,7 +30,7 @@ fn F() {} // --- fail_extern_diag_suppressed.carbon -library "extern_diag_suppressed" api; +library "extern_diag_suppressed"; extern fn F(); // CHECK:STDERR: fail_extern_diag_suppressed.carbon:[[@LINE+7]]:1: ERROR: Redeclaration of `fn F` is redundant. @@ -45,7 +45,7 @@ fn F() {} // --- fail_extern_decl_after_def.carbon -library "extern_decl_after_def" api; +library "extern_decl_after_def"; fn F() {} // CHECK:STDERR: fail_extern_decl_after_def.carbon:[[@LINE+6]]:1: ERROR: Redeclaration of `fn F` is redundant. diff --git a/toolchain/check/testdata/function/definition/no_prelude/implicit_import.carbon b/toolchain/check/testdata/function/definition/no_prelude/implicit_import.carbon index 2725e8d7601c..42074c3c7f94 100644 --- a/toolchain/check/testdata/function/definition/no_prelude/implicit_import.carbon +++ b/toolchain/check/testdata/function/definition/no_prelude/implicit_import.carbon @@ -6,32 +6,32 @@ // --- basic.carbon -library "basic" api; +library "basic"; fn A(); // --- basic.impl.carbon -library "basic" impl; +impl library "basic"; fn A() {} // --- extern_api.carbon -library "extern_api" api; +library "extern_api"; extern fn A(); // --- fail_extern_api.impl.carbon -library "extern_api" impl; +impl library "extern_api"; // CHECK:STDERR: fail_extern_api.impl.carbon:[[@LINE+10]]:1: ERROR: Redeclarations of `fn A` in the same library must match use of `extern`. // CHECK:STDERR: fn A() {} // CHECK:STDERR: ^~~~~~~~ -// CHECK:STDERR: fail_extern_api.impl.carbon:[[@LINE-5]]:1: In import. -// CHECK:STDERR: library "extern_api" impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_extern_api.impl.carbon:[[@LINE-5]]:6: In import. +// CHECK:STDERR: impl library "extern_api"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: extern_api.carbon:4:1: Previously declared here. // CHECK:STDERR: extern fn A(); // CHECK:STDERR: ^~~~~~~~~~~~~~ @@ -40,13 +40,13 @@ fn A() {} // --- extern_impl.carbon -library "extern_impl" api; +library "extern_impl"; fn A(); // --- fail_extern_impl.impl.carbon -library "extern_impl" impl; +impl library "extern_impl"; // CHECK:STDERR: fail_extern_impl.impl.carbon:[[@LINE+4]]:1: ERROR: `extern` not allowed on `fn` declaration that provides a definition. // CHECK:STDERR: extern fn A() {} @@ -56,20 +56,20 @@ extern fn A() {} // --- redecl_after_def.carbon -library "redecl_after_def" api; +library "redecl_after_def"; fn A() {} // --- fail_redecl_after_def.impl.carbon -library "redecl_after_def" impl; +impl library "redecl_after_def"; // CHECK:STDERR: fail_redecl_after_def.impl.carbon:[[@LINE+10]]:1: ERROR: Redeclaration of `fn A` is redundant. // CHECK:STDERR: fn A(); // CHECK:STDERR: ^~~~~~~ -// CHECK:STDERR: fail_redecl_after_def.impl.carbon:[[@LINE-5]]:1: In import. -// CHECK:STDERR: library "redecl_after_def" impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_redecl_after_def.impl.carbon:[[@LINE-5]]:6: In import. +// CHECK:STDERR: impl library "redecl_after_def"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: redecl_after_def.carbon:4:1: Previously declared here. // CHECK:STDERR: fn A() {} // CHECK:STDERR: ^~~~~~~~ @@ -78,20 +78,20 @@ fn A(); // --- redef_after_def.carbon -library "redef_after_def" api; +library "redef_after_def"; fn A() {} // --- fail_redef_after_def.impl.carbon -library "redef_after_def" impl; +impl library "redef_after_def"; // 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. -// CHECK:STDERR: library "redef_after_def" impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_redef_after_def.impl.carbon:[[@LINE-5]]:6: In import. +// CHECK:STDERR: impl library "redef_after_def"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: redef_after_def.carbon:4:1: Previously defined here. // CHECK:STDERR: fn A() {} // CHECK:STDERR: ^~~~~~~~ @@ -100,21 +100,21 @@ fn A() {} // --- def_alias.carbon -library "def_alias" api; +library "def_alias"; fn A(); alias B = A; // --- fail_def_alias.impl.carbon -library "def_alias" impl; +impl library "def_alias"; // 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: fail_def_alias.impl.carbon:[[@LINE-5]]:6: In import. +// CHECK:STDERR: impl library "def_alias"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: def_alias.carbon:5:7: Name is previously declared here. // CHECK:STDERR: alias B = A; // CHECK:STDERR: ^ diff --git a/toolchain/check/testdata/function/generic/redeclare.carbon b/toolchain/check/testdata/function/generic/redeclare.carbon index e634bf216561..3980770f69fe 100644 --- a/toolchain/check/testdata/function/generic/redeclare.carbon +++ b/toolchain/check/testdata/function/generic/redeclare.carbon @@ -6,7 +6,7 @@ // --- redeclare.carbon -library "redeclare" api; +library "redeclare"; fn F(T:! type) -> T*; @@ -16,7 +16,7 @@ fn F(T:! type) -> T* { // --- fail_different_return_type.carbon -library "fail_different_return_type" api; +library "fail_different_return_type"; fn F(T:! type, U:! type) -> T*; @@ -44,7 +44,7 @@ fn F(T:! type, U:! type) -> U* { // --- fail_reorder.carbon -library "fail_reorder" api; +library "fail_reorder"; fn F(T:! type, U:! type) -> T*; @@ -72,7 +72,7 @@ fn F(U:! type, T:! type) -> T* { // --- fail_rename.carbon -library "fail_rename" api; +library "fail_rename"; fn F(T:! type, U:! type) -> T*; diff --git a/toolchain/check/testdata/if_expr/fail_partial_constant.carbon b/toolchain/check/testdata/if_expr/fail_partial_constant.carbon index 60ece97855d2..ed08ccafbd3d 100644 --- a/toolchain/check/testdata/if_expr/fail_partial_constant.carbon +++ b/toolchain/check/testdata/if_expr/fail_partial_constant.carbon @@ -6,7 +6,7 @@ // --- fail_non_constant_condition.carbon -package NonConstantCondition api; +package NonConstantCondition; fn ConditionIsNonConstant(b: bool) { // We choose to not accept this even if both arms evaluate to the same @@ -21,7 +21,7 @@ fn ConditionIsNonConstant(b: bool) { // --- fail_non_constant_result.carbon -package NonConstantResult api; +package NonConstantResult; fn ChosenBranchIsNonConstant(t: type) { // CHECK:STDERR: fail_non_constant_result.carbon:[[@LINE+4]]:10: ERROR: Cannot evaluate type expression. diff --git a/toolchain/check/testdata/impl/lookup/import.carbon b/toolchain/check/testdata/impl/lookup/import.carbon index 11a2dde98532..176c38f01770 100644 --- a/toolchain/check/testdata/impl/lookup/import.carbon +++ b/toolchain/check/testdata/impl/lookup/import.carbon @@ -6,7 +6,7 @@ // --- impl.carbon -package Impl api; +package Impl; interface HasF { fn F(); diff --git a/toolchain/check/testdata/impl/lookup/no_prelude/import.carbon b/toolchain/check/testdata/impl/lookup/no_prelude/import.carbon index 3e421ef17d1c..dc977687cd68 100644 --- a/toolchain/check/testdata/impl/lookup/no_prelude/import.carbon +++ b/toolchain/check/testdata/impl/lookup/no_prelude/import.carbon @@ -6,7 +6,7 @@ // --- impl.carbon -package Impl api; +package Impl; interface HasF { fn F(); diff --git a/toolchain/check/testdata/impl/no_prelude/import_self.carbon b/toolchain/check/testdata/impl/no_prelude/import_self.carbon index 42921cbc5e66..d09bc0529135 100644 --- a/toolchain/check/testdata/impl/no_prelude/import_self.carbon +++ b/toolchain/check/testdata/impl/no_prelude/import_self.carbon @@ -6,7 +6,7 @@ // --- a.carbon -library "a" api; +library "a"; interface Add { fn Op[self: Self](other: Self) -> Self; @@ -14,7 +14,7 @@ interface Add { // --- b.carbon -library "b" api; +library "b"; import library "a"; diff --git a/toolchain/check/testdata/interface/no_prelude/export_name.carbon b/toolchain/check/testdata/interface/no_prelude/export_name.carbon index 4b8bfb690a8e..192754d1ee19 100644 --- a/toolchain/check/testdata/interface/no_prelude/export_name.carbon +++ b/toolchain/check/testdata/interface/no_prelude/export_name.carbon @@ -10,13 +10,13 @@ // --- base.carbon -library "base" api; +library "base"; interface I {} // --- export.carbon -library "export" api; +library "export"; import library "base"; @@ -28,7 +28,7 @@ export I; // --- use_export.carbon -library "use_export" api; +library "use_export"; import library "export"; diff --git a/toolchain/check/testdata/interface/no_prelude/import.carbon b/toolchain/check/testdata/interface/no_prelude/import.carbon index a999e0466323..0a6ad4251df5 100644 --- a/toolchain/check/testdata/interface/no_prelude/import.carbon +++ b/toolchain/check/testdata/interface/no_prelude/import.carbon @@ -6,7 +6,7 @@ // --- a.carbon -library "a" api; +library "a"; interface Empty { } @@ -28,7 +28,7 @@ var f_ref: {.f: ForwardDeclared}; // --- b.carbon -library "b" api; +library "b"; import library "a"; diff --git a/toolchain/check/testdata/let/fail_generic_import.carbon b/toolchain/check/testdata/let/fail_generic_import.carbon index 896836b31679..a3dd5f67baca 100644 --- a/toolchain/check/testdata/let/fail_generic_import.carbon +++ b/toolchain/check/testdata/let/fail_generic_import.carbon @@ -6,13 +6,13 @@ // --- implicit.carbon -package Implicit api; +package Implicit; let T:! type = i32; // --- fail_implicit.impl.carbon -package Implicit impl; +impl package Implicit; // TODO: Should this be valid? // CHECK:STDERR: fail_implicit.impl.carbon:[[@LINE+3]]:1: ERROR: Cannot implicitly convert from `i32` to `T`. diff --git a/toolchain/check/testdata/let/generic_import.carbon b/toolchain/check/testdata/let/generic_import.carbon index 5991226f8c61..5abd2d4274ed 100644 --- a/toolchain/check/testdata/let/generic_import.carbon +++ b/toolchain/check/testdata/let/generic_import.carbon @@ -6,13 +6,13 @@ // --- implicit.carbon -package Implicit api; +package Implicit; let T:! type = i32; // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; var a: T*; var b: T = *a; diff --git a/toolchain/check/testdata/let/import.carbon b/toolchain/check/testdata/let/import.carbon index 0a019bf5a213..06feef8755d1 100644 --- a/toolchain/check/testdata/let/import.carbon +++ b/toolchain/check/testdata/let/import.carbon @@ -6,13 +6,13 @@ // --- implicit.carbon -package Implicit api; +package Implicit; let a:! bool = true; // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; let b:! bool = a; diff --git a/toolchain/check/testdata/namespace/add_to_import.carbon b/toolchain/check/testdata/namespace/add_to_import.carbon index dcee2c13da98..086a858e3b3e 100644 --- a/toolchain/check/testdata/namespace/add_to_import.carbon +++ b/toolchain/check/testdata/namespace/add_to_import.carbon @@ -6,13 +6,13 @@ // --- implicit.carbon -package Implicit api; +package Implicit; namespace NS; // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; fn NS.A() -> i32 { return 0; } diff --git a/toolchain/check/testdata/namespace/fail_conflict_after_merge.carbon b/toolchain/check/testdata/namespace/fail_conflict_after_merge.carbon index 4aa1b4d081b0..c4377e9cd2f2 100644 --- a/toolchain/check/testdata/namespace/fail_conflict_after_merge.carbon +++ b/toolchain/check/testdata/namespace/fail_conflict_after_merge.carbon @@ -6,13 +6,13 @@ // --- namespace.carbon -package Example library "namespace" api; +package Example library "namespace"; namespace NS; // --- fail_conflict.carbon -package Example api; +package Example; import library "namespace"; diff --git a/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_first.carbon b/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_first.carbon index 41b3ff95d522..074b7ea87f4d 100644 --- a/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_first.carbon +++ b/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_first.carbon @@ -6,13 +6,13 @@ // --- namespace.carbon -package Example library "namespace" api; +package Example library "namespace"; namespace NS; // --- fail_conflict.carbon -package Example api; +package Example; import library "namespace"; diff --git a/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon b/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon index 1aa7a41b10a8..b374f303b182 100644 --- a/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon +++ b/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon @@ -6,13 +6,13 @@ // --- fn.carbon -package Example library "fn" api; +package Example library "fn"; fn NS(); // --- fail_conflict.carbon -package Example api; +package Example; import library "fn"; diff --git a/toolchain/check/testdata/namespace/fail_conflict_in_imports_namespace_first.carbon b/toolchain/check/testdata/namespace/fail_conflict_in_imports_namespace_first.carbon index 758d36802609..b43da94e01e5 100644 --- a/toolchain/check/testdata/namespace/fail_conflict_in_imports_namespace_first.carbon +++ b/toolchain/check/testdata/namespace/fail_conflict_in_imports_namespace_first.carbon @@ -6,20 +6,20 @@ // --- namespace.carbon -package Example library "namespace" api; +package Example library "namespace"; namespace NS; fn NS.Foo() {} // --- fn.carbon -package Example library "fn" api; +package Example library "fn"; fn NS() {} // --- fail_conflict.carbon -package Example library "namespace_then_fn" api; +package Example library "namespace_then_fn"; import library "namespace"; // CHECK:STDERR: fail_conflict.carbon:[[@LINE+12]]:1: In import. diff --git a/toolchain/check/testdata/namespace/fail_conflict_in_imports_namespace_second.carbon b/toolchain/check/testdata/namespace/fail_conflict_in_imports_namespace_second.carbon index 1af1c3433332..6d5c2514a9ea 100644 --- a/toolchain/check/testdata/namespace/fail_conflict_in_imports_namespace_second.carbon +++ b/toolchain/check/testdata/namespace/fail_conflict_in_imports_namespace_second.carbon @@ -6,20 +6,20 @@ // --- fn.carbon -package Example library "fn" api; +package Example library "fn"; fn NS() {} // --- namespace.carbon -package Example library "namespace" api; +package Example library "namespace"; namespace NS; fn NS.Foo() {} // --- fail_conflict.carbon -package Example library "fn_then_namespace" api; +package Example library "fn_then_namespace"; import library "fn"; // CHECK:STDERR: fail_conflict.carbon:[[@LINE+12]]:1: In import. diff --git a/toolchain/check/testdata/namespace/imported.carbon b/toolchain/check/testdata/namespace/imported.carbon index 210481b75b14..4c6cf86b3b64 100644 --- a/toolchain/check/testdata/namespace/imported.carbon +++ b/toolchain/check/testdata/namespace/imported.carbon @@ -6,7 +6,7 @@ // --- implicit.carbon -package Implicit api; +package Implicit; namespace NS; namespace NS.ChildNS; @@ -16,7 +16,7 @@ fn NS.ChildNS.B(); // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; var a: () = NS.A(); var b: () = NS.ChildNS.B(); diff --git a/toolchain/check/testdata/namespace/imported_indirect.carbon b/toolchain/check/testdata/namespace/imported_indirect.carbon index cb8bae288257..1588165ccdd9 100644 --- a/toolchain/check/testdata/namespace/imported_indirect.carbon +++ b/toolchain/check/testdata/namespace/imported_indirect.carbon @@ -6,34 +6,34 @@ // --- a.carbon -package Same library "a" api; +package Same library "a"; namespace A; // --- b.carbon -package Same library "b" api; +package Same library "b"; import library "a"; namespace A.B; // --- c.carbon -package Same library "c" api; +package Same library "c"; import library "b"; namespace A.B.C; // --- d.carbon -package Same library "d" api; +package Same library "d"; import library "c"; fn A.B.C.D() {}; // --- e.carbon -package Same library "e" api; +package Same library "e"; import library "d"; var e: () = A.B.C.D(); diff --git a/toolchain/check/testdata/namespace/merging.carbon b/toolchain/check/testdata/namespace/merging.carbon index 3decbedae932..c4aee3113aa4 100644 --- a/toolchain/check/testdata/namespace/merging.carbon +++ b/toolchain/check/testdata/namespace/merging.carbon @@ -6,7 +6,7 @@ // --- a.carbon -package Example library "a" api; +package Example library "a"; namespace NS; @@ -14,7 +14,7 @@ fn NS.A() {} // --- b.carbon -package Example library "b" api; +package Example library "b"; namespace NS; @@ -26,7 +26,7 @@ fn NS.B2() {} // --- c.carbon -package Example library "c" api; +package Example library "c"; import library "a"; import library "b"; diff --git a/toolchain/check/testdata/operators/builtin/fail_and_or_partial_constant.carbon b/toolchain/check/testdata/operators/builtin/fail_and_or_partial_constant.carbon index 2d1f7f69f357..c47c9729a417 100644 --- a/toolchain/check/testdata/operators/builtin/fail_and_or_partial_constant.carbon +++ b/toolchain/check/testdata/operators/builtin/fail_and_or_partial_constant.carbon @@ -6,7 +6,7 @@ // --- fail_non_constant_result.carbon -package FailNonConstantResult api; +package FailNonConstantResult; fn PartialConstant(x: bool) { // CHECK:STDERR: fail_non_constant_result.carbon:[[@LINE+4]]:10: ERROR: Cannot evaluate type expression. @@ -23,7 +23,7 @@ fn PartialConstant(x: bool) { // --- fail_despite_known_result.carbon -package FailDespiteKnownResult api; +package FailDespiteKnownResult; fn KnownValueButNonConstantCondition(x: bool) { // We choose not to give these cases constant values, even though we could, diff --git a/toolchain/check/testdata/operators/overloaded/add.carbon b/toolchain/check/testdata/operators/overloaded/add.carbon index 4944143a897b..ba55be034a92 100644 --- a/toolchain/check/testdata/operators/overloaded/add.carbon +++ b/toolchain/check/testdata/operators/overloaded/add.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Add { fn Op[self: Self](other: Self) -> Self; @@ -19,7 +19,7 @@ interface AddAssign { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/bit_and.carbon b/toolchain/check/testdata/operators/overloaded/bit_and.carbon index 31617d2e5013..b5f0ff6d22db 100644 --- a/toolchain/check/testdata/operators/overloaded/bit_and.carbon +++ b/toolchain/check/testdata/operators/overloaded/bit_and.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface BitAnd { fn Op[self: Self](other: Self) -> Self; @@ -19,7 +19,7 @@ interface BitAndAssign { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/bit_complement.carbon b/toolchain/check/testdata/operators/overloaded/bit_complement.carbon index e85a19d46f0d..b8279a2d0daf 100644 --- a/toolchain/check/testdata/operators/overloaded/bit_complement.carbon +++ b/toolchain/check/testdata/operators/overloaded/bit_complement.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface BitComplement { fn Op[self: Self]() -> Self; @@ -16,7 +16,7 @@ interface BitComplement { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/bit_or.carbon b/toolchain/check/testdata/operators/overloaded/bit_or.carbon index 0062721b88f9..f6692f0ecca4 100644 --- a/toolchain/check/testdata/operators/overloaded/bit_or.carbon +++ b/toolchain/check/testdata/operators/overloaded/bit_or.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface BitOr { fn Op[self: Self](other: Self) -> Self; @@ -19,7 +19,7 @@ interface BitOrAssign { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/bit_xor.carbon b/toolchain/check/testdata/operators/overloaded/bit_xor.carbon index a78bed76235a..c219bc158b8f 100644 --- a/toolchain/check/testdata/operators/overloaded/bit_xor.carbon +++ b/toolchain/check/testdata/operators/overloaded/bit_xor.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface BitXor { fn Op[self: Self](other: Self) -> Self; @@ -19,7 +19,7 @@ interface BitXorAssign { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/dec.carbon b/toolchain/check/testdata/operators/overloaded/dec.carbon index 7e9daa9e4197..41d41bc3ef58 100644 --- a/toolchain/check/testdata/operators/overloaded/dec.carbon +++ b/toolchain/check/testdata/operators/overloaded/dec.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Dec { fn Op[addr self: Self*](); @@ -16,7 +16,7 @@ interface Dec { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/div.carbon b/toolchain/check/testdata/operators/overloaded/div.carbon index b27c23d9cb1a..acd69f2529c0 100644 --- a/toolchain/check/testdata/operators/overloaded/div.carbon +++ b/toolchain/check/testdata/operators/overloaded/div.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Div { fn Op[self: Self](other: Self) -> Self; @@ -19,7 +19,7 @@ interface DivAssign { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/eq.carbon b/toolchain/check/testdata/operators/overloaded/eq.carbon index 090a5e69765f..edd3c6805f05 100644 --- a/toolchain/check/testdata/operators/overloaded/eq.carbon +++ b/toolchain/check/testdata/operators/overloaded/eq.carbon @@ -6,7 +6,7 @@ // --- prelude.carbon -package Core api; +package Core; import library "prelude"; @@ -17,7 +17,7 @@ interface Eq { // --- user.carbon -package User api; +package User; import Core; @@ -38,7 +38,7 @@ fn TestNotEqual(a: C, b: C) -> bool { // --- fail_no_impl.carbon -package FailNoImpl api; +package FailNoImpl; import Core; @@ -62,7 +62,7 @@ fn TestNotEqual(a: D, b: D) -> bool { // --- fail_no_impl_for_args.carbon -package FailNoImplForArgs api; +package FailNoImplForArgs; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/fail_assign_non_ref.carbon b/toolchain/check/testdata/operators/overloaded/fail_assign_non_ref.carbon index c56bce35fa07..68db61145c93 100644 --- a/toolchain/check/testdata/operators/overloaded/fail_assign_non_ref.carbon +++ b/toolchain/check/testdata/operators/overloaded/fail_assign_non_ref.carbon @@ -6,7 +6,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Inc { fn Op[addr self: Self*](); @@ -17,7 +17,7 @@ interface AddAssign { // --- fail_assign_non_ref.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/fail_no_impl.carbon b/toolchain/check/testdata/operators/overloaded/fail_no_impl.carbon index 99fff65c32c4..fef0bc9e7df3 100644 --- a/toolchain/check/testdata/operators/overloaded/fail_no_impl.carbon +++ b/toolchain/check/testdata/operators/overloaded/fail_no_impl.carbon @@ -6,7 +6,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Negate { fn Op[self: Self](); @@ -23,7 +23,7 @@ interface Inc { // --- fail_no_impl.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/fail_no_impl_for_arg.carbon b/toolchain/check/testdata/operators/overloaded/fail_no_impl_for_arg.carbon index a18b7b6c318d..f83234f384d0 100644 --- a/toolchain/check/testdata/operators/overloaded/fail_no_impl_for_arg.carbon +++ b/toolchain/check/testdata/operators/overloaded/fail_no_impl_for_arg.carbon @@ -6,7 +6,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Add { fn Op[self: Self](other: Self) -> Self; @@ -17,7 +17,7 @@ interface AddAssign { // --- fail_no_impl_for_arg.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/inc.carbon b/toolchain/check/testdata/operators/overloaded/inc.carbon index 203c80ef6ded..3b97b97ed88c 100644 --- a/toolchain/check/testdata/operators/overloaded/inc.carbon +++ b/toolchain/check/testdata/operators/overloaded/inc.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Inc { fn Op[addr self: Self*](); @@ -16,7 +16,7 @@ interface Inc { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/left_shift.carbon b/toolchain/check/testdata/operators/overloaded/left_shift.carbon index eea3cea9e5b2..50639c402ad7 100644 --- a/toolchain/check/testdata/operators/overloaded/left_shift.carbon +++ b/toolchain/check/testdata/operators/overloaded/left_shift.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface LeftShift { fn Op[self: Self](other: Self) -> Self; @@ -19,7 +19,7 @@ interface LeftShiftAssign { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/mod.carbon b/toolchain/check/testdata/operators/overloaded/mod.carbon index eab71dfb076b..4c7fac59c370 100644 --- a/toolchain/check/testdata/operators/overloaded/mod.carbon +++ b/toolchain/check/testdata/operators/overloaded/mod.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Mod { fn Op[self: Self](other: Self) -> Self; @@ -19,7 +19,7 @@ interface ModAssign { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/mul.carbon b/toolchain/check/testdata/operators/overloaded/mul.carbon index d1bcc84fc37b..b27ecb5ee789 100644 --- a/toolchain/check/testdata/operators/overloaded/mul.carbon +++ b/toolchain/check/testdata/operators/overloaded/mul.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Mul { fn Op[self: Self](other: Self) -> Self; @@ -19,7 +19,7 @@ interface MulAssign { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/negate.carbon b/toolchain/check/testdata/operators/overloaded/negate.carbon index 7dfcc68434f0..d2449443ee28 100644 --- a/toolchain/check/testdata/operators/overloaded/negate.carbon +++ b/toolchain/check/testdata/operators/overloaded/negate.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Negate { fn Op[self: Self]() -> Self; @@ -16,7 +16,7 @@ interface Negate { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/ordered.carbon b/toolchain/check/testdata/operators/overloaded/ordered.carbon index dedeb7a6b97d..41711f36da0f 100644 --- a/toolchain/check/testdata/operators/overloaded/ordered.carbon +++ b/toolchain/check/testdata/operators/overloaded/ordered.carbon @@ -6,7 +6,7 @@ // --- prelude.carbon -package Core api; +package Core; import library "prelude"; @@ -20,7 +20,7 @@ interface Ordered { // --- user.carbon -package User api; +package User; import Core; @@ -51,7 +51,7 @@ fn TestGreaterEqual(a: C, b: C) -> bool { // --- fail_no_impl.carbon -package FailNoImpl api; +package FailNoImpl; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/right_shift.carbon b/toolchain/check/testdata/operators/overloaded/right_shift.carbon index 05f15a040df6..d7926b97cb6d 100644 --- a/toolchain/check/testdata/operators/overloaded/right_shift.carbon +++ b/toolchain/check/testdata/operators/overloaded/right_shift.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface RightShift { fn Op[self: Self](other: Self) -> Self; @@ -19,7 +19,7 @@ interface RightShiftAssign { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/operators/overloaded/sub.carbon b/toolchain/check/testdata/operators/overloaded/sub.carbon index 08609577413f..eb3aeefab8b4 100644 --- a/toolchain/check/testdata/operators/overloaded/sub.carbon +++ b/toolchain/check/testdata/operators/overloaded/sub.carbon @@ -8,7 +8,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Sub { fn Op[self: Self](other: Self) -> Self; @@ -19,7 +19,7 @@ interface SubAssign { // --- user.carbon -package User api; +package User; import Core; diff --git a/toolchain/check/testdata/package_expr/syntax.carbon b/toolchain/check/testdata/package_expr/syntax.carbon index 960aec119534..30643b56b785 100644 --- a/toolchain/check/testdata/package_expr/syntax.carbon +++ b/toolchain/check/testdata/package_expr/syntax.carbon @@ -6,14 +6,14 @@ // --- global.carbon -package Global api; +package Global; var x: i32 = 0; var y: i32 = package.x; // --- inside_fn.carbon -package InsideFn api; +package InsideFn; var x: i32 = 0; @@ -25,7 +25,7 @@ fn Main() { // --- namespace.carbon -package Namespace api; +package Namespace; namespace NS; diff --git a/toolchain/check/testdata/packages/explicit_imports.carbon b/toolchain/check/testdata/packages/explicit_imports.carbon index 75c326e65963..b5ee9b802be3 100644 --- a/toolchain/check/testdata/packages/explicit_imports.carbon +++ b/toolchain/check/testdata/packages/explicit_imports.carbon @@ -6,29 +6,29 @@ // --- api.carbon -package Api api; +package Api; // --- api_lib.carbon -package Api library "lib" api; +package Api library "lib"; // --- same_package.carbon -package Api library "other" api; +package Api library "other"; import library default; import library "lib"; // --- different_package.carbon -package ApiOther api; +package ApiOther; import Api; import Api library "lib"; // --- main_lib_api.carbon -library "lib" api; +library "lib"; // --- main_import.carbon diff --git a/toolchain/check/testdata/packages/fail_api_not_found.carbon b/toolchain/check/testdata/packages/fail_api_not_found.carbon index 4431fa663083..439c09d126c3 100644 --- a/toolchain/check/testdata/packages/fail_api_not_found.carbon +++ b/toolchain/check/testdata/packages/fail_api_not_found.carbon @@ -6,26 +6,26 @@ // --- fail_no_api.impl.carbon -// CHECK:STDERR: fail_no_api.impl.carbon:[[@LINE+4]]:1: ERROR: Corresponding API for 'Foo' not found. -// CHECK:STDERR: package Foo impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_no_api.impl.carbon:[[@LINE+4]]:6: ERROR: Corresponding API for 'Foo' not found. +// CHECK:STDERR: impl package Foo; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package Foo impl; +impl package Foo; // --- fail_no_api_lib.impl.carbon -// CHECK:STDERR: fail_no_api_lib.impl.carbon:[[@LINE+4]]:1: ERROR: Corresponding API for 'Foo//Bar' not found. -// CHECK:STDERR: package Foo library "Bar" impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_no_api_lib.impl.carbon:[[@LINE+4]]:6: ERROR: Corresponding API for 'Foo//Bar' not found. +// CHECK:STDERR: impl package Foo library "Bar"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package Foo library "Bar" impl; +impl package Foo library "Bar"; // --- fail_no_api_main_lib.impl.carbon -// CHECK:STDERR: fail_no_api_main_lib.impl.carbon:[[@LINE+3]]:1: ERROR: Corresponding API for 'Main//Bar' not found. -// CHECK:STDERR: library "Bar" impl; -// CHECK:STDERR: ^~~~~~~ -library "Bar" impl; +// CHECK:STDERR: fail_no_api_main_lib.impl.carbon:[[@LINE+3]]:6: ERROR: Corresponding API for 'Main//Bar' not found. +// CHECK:STDERR: impl library "Bar"; +// CHECK:STDERR: ^~~~~~~ +impl library "Bar"; // CHECK:STDOUT: --- fail_no_api.impl.carbon // CHECK:STDOUT: diff --git a/toolchain/check/testdata/packages/fail_conflict_no_namespaces.carbon b/toolchain/check/testdata/packages/fail_conflict_no_namespaces.carbon index 074518cb5a54..f7a19f7c4b75 100644 --- a/toolchain/check/testdata/packages/fail_conflict_no_namespaces.carbon +++ b/toolchain/check/testdata/packages/fail_conflict_no_namespaces.carbon @@ -6,19 +6,19 @@ // --- fn.carbon -package Example library "fn" api; +package Example library "fn"; fn Foo(); // --- var.carbon -package Example library "var" api; +package Example library "var"; var Foo: i32; // --- fail_conflict.carbon -package Example library "conflict" api; +package Example library "conflict"; import library "fn"; // CHECK:STDERR: fail_conflict.carbon:[[@LINE+12]]:1: In import. diff --git a/toolchain/check/testdata/packages/fail_cycle.carbon b/toolchain/check/testdata/packages/fail_cycle.carbon index f12712c4bac0..79d4447e5bf7 100644 --- a/toolchain/check/testdata/packages/fail_cycle.carbon +++ b/toolchain/check/testdata/packages/fail_cycle.carbon @@ -6,7 +6,7 @@ // --- fail_a.carbon -package A api; +package A; // CHECK:STDERR: fail_a.carbon:[[@LINE+4]]:1: ERROR: Import cannot be used due to a cycle. Cycle must be fixed to import. // CHECK:STDERR: import B; @@ -16,7 +16,7 @@ import B; // --- fail_b.carbon -package B api; +package B; // CHECK:STDERR: fail_b.carbon:[[@LINE+4]]:1: ERROR: Import cannot be used due to a cycle. Cycle must be fixed to import. // CHECK:STDERR: import C; @@ -26,7 +26,7 @@ import C; // --- fail_c.carbon -package C api; +package C; // CHECK:STDERR: fail_c.carbon:[[@LINE+4]]:1: ERROR: Import cannot be used due to a cycle. Cycle must be fixed to import. // CHECK:STDERR: import A; @@ -36,15 +36,15 @@ import A; // --- fail_c.impl.carbon -// CHECK:STDERR: fail_c.impl.carbon:[[@LINE+4]]:1: ERROR: Import cannot be used due to a cycle. Cycle must be fixed to import. -// CHECK:STDERR: package C impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_c.impl.carbon:[[@LINE+4]]:6: ERROR: Import cannot be used due to a cycle. Cycle must be fixed to import. +// CHECK:STDERR: impl package C; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package C impl; +impl package C; // --- fail_cycle_child.carbon -package CycleChild api; +package CycleChild; // CHECK:STDERR: fail_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; diff --git a/toolchain/check/testdata/packages/fail_duplicate_api.carbon b/toolchain/check/testdata/packages/fail_duplicate_api.carbon index 59506ef83243..669e2eb26801 100644 --- a/toolchain/check/testdata/packages/fail_duplicate_api.carbon +++ b/toolchain/check/testdata/packages/fail_duplicate_api.carbon @@ -12,38 +12,38 @@ // --- main_lib1.carbon -library "lib" api; +library "lib"; // --- fail_main_lib2.carbon // CHECK:STDERR: fail_main_lib2.carbon:[[@LINE+4]]:1: ERROR: Library's API previously provided by `main_lib1.carbon`. -// CHECK:STDERR: library "lib" api; +// CHECK:STDERR: library "lib"; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -library "lib" api; +library "lib"; // --- package1.carbon -package Package api; +package Package; // --- fail_package2.carbon // CHECK:STDERR: fail_package2.carbon:[[@LINE+4]]:1: ERROR: Library's API previously provided by `package1.carbon`. -// CHECK:STDERR: package Package api; +// CHECK:STDERR: package Package; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package Package api; +package Package; // --- package_lib1.carbon -package Package library "lib" api; +package Package library "lib"; // --- fail_package_lib2.carbon // CHECK:STDERR: fail_package_lib2.carbon:[[@LINE+3]]:1: ERROR: Library's API previously provided by `package_lib1.carbon`. -// CHECK:STDERR: package Package library "lib" api; +// CHECK:STDERR: package Package library "lib"; // CHECK:STDERR: ^~~~~~~ -package Package library "lib" api; +package Package library "lib"; // CHECK:STDOUT: --- main1.carbon // CHECK:STDOUT: diff --git a/toolchain/check/testdata/packages/fail_extension.carbon b/toolchain/check/testdata/packages/fail_extension.carbon index 84285968e4d0..184958ae318d 100644 --- a/toolchain/check/testdata/packages/fail_extension.carbon +++ b/toolchain/check/testdata/packages/fail_extension.carbon @@ -18,66 +18,66 @@ // --- fail_main_lib.incorrect // CHECK:STDERR: fail_main_lib.incorrect:[[@LINE+4]]:1: ERROR: File extension of `.carbon` required for `api`. -// CHECK:STDERR: library "lib" api; +// CHECK:STDERR: library "lib"; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -library "lib" api; +library "lib"; // --- fail_main_lib_impl.incorrect -// CHECK:STDERR: fail_main_lib_impl.incorrect:[[@LINE+4]]:1: ERROR: File extension of `.impl.carbon` required for `impl`. -// CHECK:STDERR: library "lib" impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_main_lib_impl.incorrect:[[@LINE+4]]:6: ERROR: File extension of `.impl.carbon` required for `impl`. +// CHECK:STDERR: impl library "lib"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -library "lib" impl; +impl library "lib"; // --- fail_package.incorrect // CHECK:STDERR: fail_package.incorrect:[[@LINE+4]]:1: ERROR: File extension of `.carbon` required for `api`. -// CHECK:STDERR: package Package api; +// CHECK:STDERR: package Package; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package Package api; +package Package; // --- fail_package_impl.incorrect -// CHECK:STDERR: fail_package_impl.incorrect:[[@LINE+4]]:1: ERROR: File extension of `.impl.carbon` required for `impl`. -// CHECK:STDERR: package Package impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_package_impl.incorrect:[[@LINE+4]]:6: ERROR: File extension of `.impl.carbon` required for `impl`. +// CHECK:STDERR: impl package Package; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package Package impl; +impl package Package; // --- fail_package_lib.incorrect // CHECK:STDERR: fail_package_lib.incorrect:[[@LINE+4]]:1: ERROR: File extension of `.carbon` required for `api`. -// CHECK:STDERR: package Package library "lib" api; +// CHECK:STDERR: package Package library "lib"; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package Package library "lib" api; +package Package library "lib"; // --- fail_package_lib_impl.incorrect -// CHECK:STDERR: fail_package_lib_impl.incorrect:[[@LINE+4]]:1: ERROR: File extension of `.impl.carbon` required for `impl`. -// CHECK:STDERR: package Package library "lib" impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_package_lib_impl.incorrect:[[@LINE+4]]:6: ERROR: File extension of `.impl.carbon` required for `impl`. +// CHECK:STDERR: impl package Package library "lib"; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package Package library "lib" impl; +impl package Package library "lib"; // --- fail_swapped_ext.impl.carbon // CHECK:STDERR: fail_swapped_ext.impl.carbon:[[@LINE+5]]:1: ERROR: File extension of `.carbon` required for `api`. -// CHECK:STDERR: package SwappedExt api; +// CHECK:STDERR: package SwappedExt; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: fail_swapped_ext.impl.carbon: File extension of `.impl.carbon` only allowed for `impl`. // CHECK:STDERR: -package SwappedExt api; +package SwappedExt; // --- fail_swapped_ext.carbon -// CHECK:STDERR: fail_swapped_ext.carbon:[[@LINE+3]]:1: ERROR: File extension of `.impl.carbon` required for `impl`. -// CHECK:STDERR: package SwappedExt impl; -// CHECK:STDERR: ^~~~~~~ -package SwappedExt impl; +// CHECK:STDERR: fail_swapped_ext.carbon:[[@LINE+3]]:6: ERROR: File extension of `.impl.carbon` required for `impl`. +// CHECK:STDERR: impl package SwappedExt; +// CHECK:STDERR: ^~~~~~~ +impl package SwappedExt; // CHECK:STDOUT: --- fail_main.incorrect diff --git a/toolchain/check/testdata/packages/fail_import_default.carbon b/toolchain/check/testdata/packages/fail_import_default.carbon index e22f434a3e26..4ec26845b277 100644 --- a/toolchain/check/testdata/packages/fail_import_default.carbon +++ b/toolchain/check/testdata/packages/fail_import_default.carbon @@ -6,7 +6,7 @@ // --- fail_default_api.carbon -package A api; +package A; // CHECK:STDERR: fail_default_api.carbon:[[@LINE+4]]:1: ERROR: File cannot import itself. // CHECK:STDERR: import library default; @@ -16,7 +16,7 @@ import library default; // --- fail_default.impl.carbon -package A impl; +impl package A; // CHECK:STDERR: fail_default.impl.carbon:[[@LINE+4]]:1: ERROR: Explicit import of `api` from `impl` file is redundant with implicit import. // CHECK:STDERR: import library default; @@ -34,7 +34,7 @@ import library default; // --- fail_main_lib_import_default.carbon -library "lib" api; +library "lib"; // CHECK:STDERR: fail_main_lib_import_default.carbon:[[@LINE+3]]:1: ERROR: Cannot import `Main//default`. // CHECK:STDERR: import library default; diff --git a/toolchain/check/testdata/packages/fail_import_invalid.carbon b/toolchain/check/testdata/packages/fail_import_invalid.carbon index 7d0abf257a26..4b20dfde6520 100644 --- a/toolchain/check/testdata/packages/fail_import_invalid.carbon +++ b/toolchain/check/testdata/packages/fail_import_invalid.carbon @@ -20,7 +20,7 @@ import Main library "lib"; // --- fail_not_main.carbon -package NotMain api; +package NotMain; // CHECK:STDERR: fail_not_main.carbon:[[@LINE+4]]:1: ERROR: Cannot import `Main` from other packages. // CHECK:STDERR: import Main; @@ -36,7 +36,7 @@ import Main library "lib"; // --- fail_this.carbon -package This api; +package This; // CHECK:STDERR: fail_this.carbon:[[@LINE+4]]:1: ERROR: File cannot import itself. // CHECK:STDERR: import This; @@ -46,7 +46,7 @@ import This; // --- fail_this_lib.carbon -package This library "lib" api; +package This library "lib"; // CHECK:STDERR: fail_this_lib.carbon:[[@LINE+4]]:1: ERROR: File cannot import itself. // CHECK:STDERR: import library "lib"; @@ -56,11 +56,11 @@ import library "lib"; // --- implicit_api.carbon -package Implicit api; +package Implicit; // --- fail_implicit.impl.carbon -package Implicit impl; +impl package Implicit; // CHECK:STDERR: fail_implicit.impl.carbon:[[@LINE+4]]:1: ERROR: Explicit import of `api` from `impl` file is redundant with implicit import. // CHECK:STDERR: import Implicit; @@ -70,11 +70,11 @@ import Implicit; // --- implicit_lib_api.carbon -package Implicit library "lib" api; +package Implicit library "lib"; // --- fail_implicit_lib.impl.carbon -package Implicit library "lib" impl; +impl package Implicit library "lib"; // CHECK:STDERR: fail_implicit_lib.impl.carbon:[[@LINE+4]]:1: ERROR: Explicit import of `api` from `impl` file is redundant with implicit import. // CHECK:STDERR: import Implicit library "lib"; @@ -83,7 +83,7 @@ package Implicit library "lib" impl; import Implicit library "lib"; // --- fail_not_found.carbon -package NotFound api; +package NotFound; // CHECK:STDERR: fail_not_found.carbon:[[@LINE+3]]:1: ERROR: Imported API 'ImportNotFound' not found. // CHECK:STDERR: import ImportNotFound; diff --git a/toolchain/check/testdata/packages/fail_import_repeat.carbon b/toolchain/check/testdata/packages/fail_import_repeat.carbon index 0d74cfd9997d..f7fa0c9de77d 100644 --- a/toolchain/check/testdata/packages/fail_import_repeat.carbon +++ b/toolchain/check/testdata/packages/fail_import_repeat.carbon @@ -6,15 +6,15 @@ // --- api.carbon -package Api api; +package Api; // --- api_lib.carbon -package Api library "lib" api; +package Api library "lib"; // --- main_lib.carbon -library "lib" api; +library "lib"; // --- fail_import.carbon @@ -50,7 +50,7 @@ import library "lib"; // --- fail_default_import.carbon -package Api library "not_default" api; +package Api library "not_default"; import library default; // CHECK:STDERR: fail_default_import.carbon:[[@LINE+6]]:1: ERROR: Library imported more than once. diff --git a/toolchain/check/testdata/packages/fail_import_type_error.carbon b/toolchain/check/testdata/packages/fail_import_type_error.carbon index 5436578e64ce..192db1cc86e9 100644 --- a/toolchain/check/testdata/packages/fail_import_type_error.carbon +++ b/toolchain/check/testdata/packages/fail_import_type_error.carbon @@ -6,7 +6,7 @@ // --- fail_implicit.carbon -package Implicit api; +package Implicit; // CHECK:STDERR: fail_implicit.carbon:[[@LINE+4]]:12: ERROR: Name `x` not found. // CHECK:STDERR: var a_ref: x; @@ -30,7 +30,7 @@ var d_ref: x*; // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; // In each of these cases, name lookup should succeed, but they should all have // an error type. diff --git a/toolchain/check/testdata/packages/fail_name_with_import_failure.carbon b/toolchain/check/testdata/packages/fail_name_with_import_failure.carbon index 1b5b57c05b8e..37d12e47c679 100644 --- a/toolchain/check/testdata/packages/fail_name_with_import_failure.carbon +++ b/toolchain/check/testdata/packages/fail_name_with_import_failure.carbon @@ -6,10 +6,10 @@ // --- fail_implicit.impl.carbon -// CHECK:STDERR: fail_implicit.impl.carbon:[[@LINE+3]]:1: ERROR: Corresponding API for 'Implicit' not found. -// CHECK:STDERR: package Implicit impl; -// CHECK:STDERR: ^~~~~~~ -package Implicit impl; +// CHECK:STDERR: fail_implicit.impl.carbon:[[@LINE+3]]:6: ERROR: Corresponding API for 'Implicit' not found. +// CHECK:STDERR: impl package Implicit; +// CHECK:STDERR: ^~~~~~~ +impl package Implicit; var a: () = A(); diff --git a/toolchain/check/testdata/packages/fail_package_main.carbon b/toolchain/check/testdata/packages/fail_package_main.carbon index 7d10ebaba684..01575ce7203a 100644 --- a/toolchain/check/testdata/packages/fail_package_main.carbon +++ b/toolchain/check/testdata/packages/fail_package_main.carbon @@ -7,34 +7,34 @@ // --- fail_main.carbon // CHECK:STDERR: fail_main.carbon:[[@LINE+4]]:1: ERROR: `Main//default` must omit `package` declaration. -// CHECK:STDERR: package Main api; +// CHECK:STDERR: package Main; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package Main api; +package Main; // --- fail_main_impl.carbon -// CHECK:STDERR: fail_main_impl.carbon:[[@LINE+4]]:1: ERROR: `Main//default` must omit `package` declaration. -// CHECK:STDERR: package Main impl; -// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: fail_main_impl.carbon:[[@LINE+4]]:6: ERROR: `Main//default` must omit `package` declaration. +// CHECK:STDERR: impl package Main; +// CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package Main impl; +impl package Main; // --- fail_raw_main.carbon // `Main` isn't a keyword, so this fails the same way. // CHECK:STDERR: fail_raw_main.carbon:[[@LINE+4]]:1: ERROR: `Main//default` must omit `package` declaration. -// CHECK:STDERR: package r#Main api; +// CHECK:STDERR: package r#Main; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -package r#Main api; +package r#Main; // --- fail_main_lib.carbon // CHECK:STDERR: fail_main_lib.carbon:[[@LINE+3]]:1: ERROR: Use `library` declaration in `Main` package libraries. -// CHECK:STDERR: package Main library "lib" api; +// CHECK:STDERR: package Main library "lib"; // CHECK:STDERR: ^~~~~~~ -package Main library "lib" api; +package Main library "lib"; // CHECK:STDOUT: --- fail_main.carbon // CHECK:STDOUT: diff --git a/toolchain/check/testdata/packages/implicit_imports.carbon b/toolchain/check/testdata/packages/implicit_imports.carbon index 51bbeaff0fc9..a0f255a35b75 100644 --- a/toolchain/check/testdata/packages/implicit_imports.carbon +++ b/toolchain/check/testdata/packages/implicit_imports.carbon @@ -6,42 +6,42 @@ // --- api_only.carbon -package ApiOnly api; +package ApiOnly; // --- api_only_lib.carbon -package ApiOnly library "lib" api; +package ApiOnly library "lib"; // --- with_impl.carbon -package WithImpl api; +package WithImpl; // --- with_impl.impl.carbon -package WithImpl impl; +impl package WithImpl; // --- with_impl_extra.impl.carbon // Multiple impls are allowed. -package WithImpl impl; +impl package WithImpl; // --- with_impl_lib.carbon -package WithImpl library "lib" api; +package WithImpl library "lib"; // --- with_impl_lib.impl.carbon -package WithImpl library "lib" impl; +impl package WithImpl library "lib"; // --- main.carbon // --- main_lib.carbon -library "lib" api; +library "lib"; // --- main_lib.impl.carbon -library "lib" impl; +impl library "lib"; // CHECK:STDOUT: --- api_only.carbon // CHECK:STDOUT: diff --git a/toolchain/check/testdata/packages/loaded_global.carbon b/toolchain/check/testdata/packages/loaded_global.carbon index 14595574d7a6..56bda55d47c4 100644 --- a/toolchain/check/testdata/packages/loaded_global.carbon +++ b/toolchain/check/testdata/packages/loaded_global.carbon @@ -6,13 +6,13 @@ // --- implicit.carbon -package Implicit api; +package Implicit; fn A(); // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; var a: () = A(); @@ -20,13 +20,13 @@ var package_a: () = package.A(); // --- same_package.carbon -package SamePackage api; +package SamePackage; fn B(); // --- same_package_importer.carbon -package SamePackage library "importer" api; +package SamePackage library "importer"; import library default; diff --git a/toolchain/check/testdata/packages/no_prelude/cross_package_import.carbon b/toolchain/check/testdata/packages/no_prelude/cross_package_import.carbon index 4ee83956c8fb..353652abe134 100644 --- a/toolchain/check/testdata/packages/no_prelude/cross_package_import.carbon +++ b/toolchain/check/testdata/packages/no_prelude/cross_package_import.carbon @@ -10,31 +10,31 @@ // --- other_fn.carbon -package Other library "fn" api; +package Other library "fn"; fn F() {} // --- other_fn_extern.carbon -package Other library "fn_extern" api; +package Other library "fn_extern"; extern fn F(); // --- other_fn_conflict.carbon -package Other library "fn_conflict" api; +package Other library "fn_conflict"; fn F(x: ()) {} // --- other_fn2.carbon -package Other library "fn2" api; +package Other library "fn2"; fn F2() {} // --- other_fn_use.carbon -package Other library "fn_use" api; +package Other library "fn_use"; import library "fn"; @@ -42,7 +42,7 @@ fn G() { F(); } // --- main_other_ns.carbon -library "other_ns" api; +library "other_ns"; namespace Other; @@ -52,7 +52,7 @@ namespace Other; // --- main_use_other.carbon -library "use_other" api; +library "use_other"; import Other library "fn"; import Other library "fn2"; @@ -64,7 +64,7 @@ fn Run() { // --- fail_todo_main_use_other_extern.carbon -library "use_other_extern" api; +library "use_other_extern"; import Other library "fn"; // CHECK:STDERR: fail_todo_main_use_other_extern.carbon:[[@LINE+12]]:1: In import. @@ -91,14 +91,14 @@ fn Run() { // --- main_unused_other_ambiguous.carbon -library "unused_other_ambiguous" api; +library "unused_other_ambiguous"; import Other library "fn"; import Other library "fn_conflict"; // --- fail_main_use_other_ambiguous.carbon -library "use_other_ambiguous" api; +library "use_other_ambiguous"; import Other library "fn"; // CHECK:STDERR: fail_main_use_other_ambiguous.carbon:[[@LINE+12]]:1: In import. @@ -125,7 +125,7 @@ fn Run() { // --- fail_main_namespace_conflict.carbon -library "namespace_conflict" api; +library "namespace_conflict"; import library "other_ns"; // CHECK:STDERR: fail_main_namespace_conflict.carbon:[[@LINE+10]]:1: ERROR: Duplicate name being declared in the same scope. @@ -154,7 +154,7 @@ fn Other.F() {} // --- fail_main_reopen_other.carbon -library "reopen_other" api; +library "reopen_other"; import Other library "fn"; @@ -172,7 +172,7 @@ fn Other.G() {} // --- fail_main_add_to_other.carbon -library "add_to_other" api; +library "add_to_other"; import Other library "fn"; @@ -187,7 +187,7 @@ fn Other.G() {} // --- fail_use_other_fn_use.carbon -library "fail_use_other_fn_use" api; +library "fail_use_other_fn_use"; import Other library "fn_use"; diff --git a/toolchain/check/testdata/packages/no_prelude/export_import.carbon b/toolchain/check/testdata/packages/no_prelude/export_import.carbon index 45d6aaa0240c..f660f0843ed4 100644 --- a/toolchain/check/testdata/packages/no_prelude/export_import.carbon +++ b/toolchain/check/testdata/packages/no_prelude/export_import.carbon @@ -10,7 +10,7 @@ // --- base.carbon -library "base" api; +library "base"; class C { var x: (); @@ -18,31 +18,31 @@ class C { // --- export.carbon -library "export" api; +library "export"; export import library "base"; // --- export_copy.carbon -library "export_copy" api; +library "export_copy"; export import library "base"; // --- non_export.carbon -library "non_export" api; +library "non_export"; import library "export"; // --- export_export.carbon -library "export_export" api; +library "export_export"; export import library "export"; // --- import_then_export.carbon -library "import_then_export" api; +library "import_then_export"; import library "base"; export import library "export"; @@ -50,7 +50,7 @@ export import library "export"; // --- export_in_impl.carbon // This is just providing an API for the implicit import. -library "export_in_impl" api; +library "export_in_impl"; // ============================================================================ // Test files @@ -58,7 +58,7 @@ library "export_in_impl" api; // --- use_export.carbon -library "use_export" api; +library "use_export"; import library "export"; @@ -66,7 +66,7 @@ var c: C = {.x = ()}; // --- fail_export_in_impl.impl.carbon -library "export_in_impl" impl; +impl library "export_in_impl"; // CHECK:STDERR: fail_export_in_impl.impl.carbon:[[@LINE+4]]:1: ERROR: `export` is only allowed in API files. // CHECK:STDERR: export import library "base"; @@ -79,13 +79,13 @@ var c: C = {.x = ()}; // --- export_export.impl.carbon -library "export_export" impl; +impl library "export_export"; var c: C = {.x = ()}; // --- use_export_export.carbon -library "use_export_export" api; +library "use_export_export"; import library "export_export"; @@ -93,7 +93,7 @@ var c: C = {.x = ()}; // --- use_import_then_export.carbon -library "use_import_then_export" api; +library "use_import_then_export"; import library "import_then_export"; @@ -101,7 +101,7 @@ var c: C = {.x = ()}; // --- use_import_when_export.carbon -library "use_import_when_export" api; +library "use_import_when_export"; export import library "base"; @@ -109,7 +109,7 @@ var c: C = {.x = ()}; // --- use_base_and_export.carbon -library "use_base_and_export" api; +library "use_base_and_export"; import library "base"; import library "export"; @@ -118,7 +118,7 @@ var c: C = {.x = ()}; // --- use_export_and_base.carbon -library "import_both_reversed" api; +library "import_both_reversed"; import library "export"; import library "base"; @@ -127,7 +127,7 @@ var c: C = {.x = ()}; // --- use_export_copy.carbon -library "use_export_copy" api; +library "use_export_copy"; import library "export"; import library "export_copy"; @@ -136,7 +136,7 @@ var c: C = {.x = ()}; // --- fail_use_non_export.carbon -library "fail_use_non_export" api; +library "fail_use_non_export"; import library "non_export"; @@ -147,7 +147,7 @@ alias Local = C; // --- use_non_export_then_base.carbon -library "use_non_export_then_base" api; +library "use_non_export_then_base"; import library "non_export"; export import library "base"; @@ -156,7 +156,7 @@ var c: C = {.x = ()}; // --- indirect_use_non_export_then_base.carbon -library "indirect_use_non_export_then_base" api; +library "indirect_use_non_export_then_base"; import library "use_non_export_then_base"; diff --git a/toolchain/check/testdata/packages/no_prelude/export_mixed.carbon b/toolchain/check/testdata/packages/no_prelude/export_mixed.carbon index 2f640025f8e5..72e4bfc74290 100644 --- a/toolchain/check/testdata/packages/no_prelude/export_mixed.carbon +++ b/toolchain/check/testdata/packages/no_prelude/export_mixed.carbon @@ -10,7 +10,7 @@ // --- base.carbon -library "base" api; +library "base"; class C { var x: (); @@ -22,13 +22,13 @@ class D { // --- export_import.carbon -library "export_import" api; +library "export_import"; export import library "base"; // --- export_import_then_name.carbon -library "export_import_then_name" api; +library "export_import_then_name"; import library "export_import"; @@ -36,7 +36,7 @@ export C; // --- export_name.carbon -library "export_name" api; +library "export_name"; import library "base"; @@ -44,7 +44,7 @@ export C; // --- export_name_then_import.carbon -library "export_name_then_import" api; +library "export_name_then_import"; export import library "export_name"; @@ -54,7 +54,7 @@ export import library "export_name"; // --- use_export_import_then_name.carbon -library "use_export_import_then_name" api; +library "use_export_import_then_name"; import library "export_import_then_name"; @@ -62,7 +62,7 @@ var c: C = {.x = ()}; // --- use_export_name_then_import.carbon -library "use_export_name_then_import" api; +library "use_export_name_then_import"; import library "export_name_then_import"; @@ -70,7 +70,7 @@ var c: C = {.x = ()}; // --- use_both.carbon -library "use_both" api; +library "use_both"; import library "export_import_then_name"; import library "export_name_then_import"; @@ -79,7 +79,7 @@ var c: C = {.x = ()}; // --- fail_nonexport_use_both.carbon -library "fail_nonexport_use_both" api; +library "fail_nonexport_use_both"; import library "export_import_then_name"; import library "export_name_then_import"; @@ -91,7 +91,7 @@ var d: D = {.y = ()}; // --- use_both_reversed.carbon -library "use_both_reversed" api; +library "use_both_reversed"; import library "export_import_then_name"; import library "export_name_then_import"; @@ -100,7 +100,7 @@ var c: C = {.x = ()}; // --- use_both_and_export_import.carbon -library "use_both_and_export_import" api; +library "use_both_and_export_import"; import library "export_import_then_name"; import library "export_name_then_import"; diff --git a/toolchain/check/testdata/packages/no_prelude/export_name.carbon b/toolchain/check/testdata/packages/no_prelude/export_name.carbon index c7ffba3e3170..8a58a1a678cb 100644 --- a/toolchain/check/testdata/packages/no_prelude/export_name.carbon +++ b/toolchain/check/testdata/packages/no_prelude/export_name.carbon @@ -10,7 +10,7 @@ // --- base.carbon -library "base" api; +library "base"; class C { var x: (); @@ -23,7 +23,7 @@ class NS.NSC { // --- export.carbon -library "export" api; +library "export"; import library "base"; export C; @@ -31,13 +31,13 @@ export NS.NSC; // --- not_reexporting.carbon -library "not_reexporting" api; +library "not_reexporting"; import library "export"; // --- export_export.carbon -library "export_export" api; +library "export_export"; import library "export"; export C; @@ -46,7 +46,7 @@ export NS.NSC; // --- export_in_impl.carbon // This is just providing an API for the implicit import. -library "export_in_impl" api; +library "export_in_impl"; // ============================================================================ // Test files @@ -54,7 +54,7 @@ library "export_in_impl" api; // --- use_export.carbon -library "use_export" api; +library "use_export"; import library "export"; @@ -63,14 +63,14 @@ var nsc: NS.NSC = {.y = ()}; // --- export_export.impl.carbon -library "export_export" impl; +impl library "export_export"; var c: C = {.x = ()}; var nsc: NS.NSC = {.y = ()}; // --- use_export_export.carbon -library "use_export_export" api; +library "use_export_export"; import library "export_export"; @@ -79,7 +79,7 @@ var nsc: NS.NSC = {.y = ()}; // --- fail_export_ns.carbon -library "fail_export_ns" api; +library "fail_export_ns"; import library "base"; @@ -97,7 +97,7 @@ export NS; // --- fail_export_decl.carbon -library "fail_export_decl" api; +library "fail_export_decl"; class Local {} @@ -112,7 +112,7 @@ export Local; // --- fail_export_member.carbon -library "fail_export_member" api; +library "fail_export_member"; import library "base"; @@ -127,7 +127,7 @@ export C.x; // --- import_both.carbon -library "import_both" api; +library "import_both"; import library "base"; import library "export"; @@ -137,7 +137,7 @@ var nsc: NS.NSC = {.y = ()}; // --- import_both_reversed.carbon -library "import_both_reversed" api; +library "import_both_reversed"; import library "export"; import library "base"; @@ -147,7 +147,7 @@ var nsc: NS.NSC = {.y = ()}; // --- fail_use_not_reexporting.carbon -library "fail_use_not_reexporting" api; +library "fail_use_not_reexporting"; import library "not_reexporting"; @@ -164,7 +164,7 @@ alias NSLocal = NS.NSC; // --- repeat_export.carbon -library "repeat_export" api; +library "repeat_export"; import library "base"; @@ -173,7 +173,7 @@ export C; // --- use_repeat_export.carbon -library "use_repeat_export" api; +library "use_repeat_export"; import library "repeat_export"; @@ -181,7 +181,7 @@ var c: C = {.x = ()}; // --- fail_modifiers.carbon -library "fail_modifiers" api; +library "fail_modifiers"; import library "base"; diff --git a/toolchain/check/testdata/packages/no_prelude/fail_modifiers.carbon b/toolchain/check/testdata/packages/no_prelude/fail_modifiers.carbon new file mode 100644 index 000000000000..b940d52b684a --- /dev/null +++ b/toolchain/check/testdata/packages/no_prelude/fail_modifiers.carbon @@ -0,0 +1,154 @@ +// 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 + +// --- fail_export_package.carbon + +// CHECK:STDERR: fail_export_package.carbon:[[@LINE+4]]:1: ERROR: `export` not allowed on `package` declaration. +// CHECK:STDERR: export package ExportPackage; +// CHECK:STDERR: ^~~~~~ +// CHECK:STDERR: +export package ExportPackage; + +// --- fail_extend_package.carbon + +// CHECK:STDERR: fail_extend_package.carbon:[[@LINE+4]]:1: ERROR: `extend` not allowed on `package` declaration. +// CHECK:STDERR: extend package ExtendPackage; +// CHECK:STDERR: ^~~~~~ +// CHECK:STDERR: +extend package ExtendPackage; + +// --- fail_virtual_package.carbon + +// CHECK:STDERR: fail_virtual_package.carbon:[[@LINE+4]]:1: ERROR: `virtual` not allowed on `package` declaration. +// CHECK:STDERR: virtual package VirtualPackage; +// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: +virtual package VirtualPackage; + +// --- fail_private_package.carbon + +// CHECK:STDERR: fail_private_package.carbon:[[@LINE+4]]:1: ERROR: `private` not allowed on `package` declaration. +// CHECK:STDERR: private package PrivatePackage; +// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: +private package PrivatePackage; + +// --- fail_export_library.carbon + +// CHECK:STDERR: fail_export_library.carbon:[[@LINE+4]]:1: ERROR: `export` not allowed on `library` declaration. +// CHECK:STDERR: export library "export_library"; +// CHECK:STDERR: ^~~~~~ +// CHECK:STDERR: +export library "export_library"; + +// --- fail_import_modifiers.carbon + +// CHECK:STDERR: fail_import_modifiers.carbon:[[@LINE+8]]:1: ERROR: `impl` not allowed on `import` declaration. +// CHECK:STDERR: impl import ImplImport; +// CHECK:STDERR: ^~~~ +// CHECK:STDERR: +// CHECK:STDERR: fail_import_modifiers.carbon:[[@LINE+4]]:6: ERROR: Imported API 'ImplImport' not found. +// CHECK:STDERR: impl import ImplImport; +// CHECK:STDERR: ^~~~~~ +// CHECK:STDERR: +impl import ImplImport; + +// CHECK:STDERR: fail_import_modifiers.carbon:[[@LINE+8]]:1: ERROR: `extend` not allowed on `import` declaration. +// CHECK:STDERR: extend import ExtendImport; +// CHECK:STDERR: ^~~~~~ +// CHECK:STDERR: +// CHECK:STDERR: fail_import_modifiers.carbon:[[@LINE+4]]:8: ERROR: Imported API 'ExtendImport' not found. +// CHECK:STDERR: extend import ExtendImport; +// CHECK:STDERR: ^~~~~~ +// CHECK:STDERR: +extend import ExtendImport; + +// CHECK:STDERR: fail_import_modifiers.carbon:[[@LINE+8]]:1: ERROR: `virtual` not allowed on `import` declaration. +// CHECK:STDERR: virtual import VirtualImport; +// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: +// CHECK:STDERR: fail_import_modifiers.carbon:[[@LINE+4]]:9: ERROR: Imported API 'VirtualImport' not found. +// CHECK:STDERR: virtual import VirtualImport; +// CHECK:STDERR: ^~~~~~ +// CHECK:STDERR: +virtual import VirtualImport; + +// CHECK:STDERR: fail_import_modifiers.carbon:[[@LINE+8]]:1: ERROR: `base` not allowed on `import` declaration. +// CHECK:STDERR: base import BaseImport; +// CHECK:STDERR: ^~~~ +// CHECK:STDERR: +// CHECK:STDERR: fail_import_modifiers.carbon:[[@LINE+4]]:6: ERROR: Imported API 'BaseImport' not found. +// CHECK:STDERR: base import BaseImport; +// CHECK:STDERR: ^~~~~~ +// CHECK:STDERR: +base import BaseImport; + +// CHECK:STDERR: fail_import_modifiers.carbon:[[@LINE+7]]:1: ERROR: `private` not allowed on `import` declaration. +// CHECK:STDERR: private import PrivateImport; +// CHECK:STDERR: ^~~~~~~ +// CHECK:STDERR: +// CHECK:STDERR: fail_import_modifiers.carbon:[[@LINE+3]]:9: ERROR: Imported API 'PrivateImport' not found. +// CHECK:STDERR: private import PrivateImport; +// CHECK:STDERR: ^~~~~~ +private import PrivateImport; + +// CHECK:STDOUT: --- fail_export_package.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_extend_package.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_virtual_package.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_private_package.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_export_library.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_import_modifiers.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] { +// CHECK:STDOUT: .ImplImport = %ImplImport +// CHECK:STDOUT: .ExtendImport = %ExtendImport +// CHECK:STDOUT: .VirtualImport = %VirtualImport +// CHECK:STDOUT: .BaseImport = %BaseImport +// CHECK:STDOUT: .PrivateImport = %PrivateImport +// CHECK:STDOUT: } +// CHECK:STDOUT: %ImplImport: = namespace [template] { +// CHECK:STDOUT: has_error +// CHECK:STDOUT: } +// CHECK:STDOUT: %ExtendImport: = namespace [template] { +// CHECK:STDOUT: has_error +// CHECK:STDOUT: } +// CHECK:STDOUT: %VirtualImport: = namespace [template] { +// CHECK:STDOUT: has_error +// CHECK:STDOUT: } +// CHECK:STDOUT: %BaseImport: = namespace [template] { +// CHECK:STDOUT: has_error +// CHECK:STDOUT: } +// CHECK:STDOUT: %PrivateImport: = namespace [template] { +// CHECK:STDOUT: has_error +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/check/testdata/packages/unused_lazy_import.carbon b/toolchain/check/testdata/packages/unused_lazy_import.carbon index 53a90b9aab1f..1c0391741466 100644 --- a/toolchain/check/testdata/packages/unused_lazy_import.carbon +++ b/toolchain/check/testdata/packages/unused_lazy_import.carbon @@ -6,13 +6,13 @@ // --- implicit.carbon -package Implicit api; +package Implicit; fn A(); // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; // CHECK:STDOUT: --- implicit.carbon // CHECK:STDOUT: diff --git a/toolchain/check/testdata/pointer/import.carbon b/toolchain/check/testdata/pointer/import.carbon index 8a569be649da..5bc9ef7b5034 100644 --- a/toolchain/check/testdata/pointer/import.carbon +++ b/toolchain/check/testdata/pointer/import.carbon @@ -6,14 +6,14 @@ // --- implicit.carbon -package Implicit api; +package Implicit; var a_orig: i32 = 0; var a_ref: i32* = &a_orig; // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; var a: i32* = a_ref; diff --git a/toolchain/check/testdata/struct/import.carbon b/toolchain/check/testdata/struct/import.carbon index 014244f0c3b3..27aa00ca694c 100644 --- a/toolchain/check/testdata/struct/import.carbon +++ b/toolchain/check/testdata/struct/import.carbon @@ -6,7 +6,7 @@ // --- implicit.carbon -package Implicit api; +package Implicit; var a_ref: {.a: i32} = {.a = 0}; var b_ref: {.a: {.b: i32, .c: (i32,)}, .d: i32} = @@ -14,7 +14,7 @@ var b_ref: {.a: {.b: i32, .c: (i32,)}, .d: i32} = // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; var a: {.a: i32} = a_ref; var b: {.a: {.b: i32, .c: (i32,)}, .d: i32} = b_ref; diff --git a/toolchain/check/testdata/tuples/import.carbon b/toolchain/check/testdata/tuples/import.carbon index 145ce1cb76f9..71ef78031743 100644 --- a/toolchain/check/testdata/tuples/import.carbon +++ b/toolchain/check/testdata/tuples/import.carbon @@ -6,14 +6,14 @@ // --- implicit.carbon -package Implicit api; +package Implicit; var a_ref: (i32,) = (0,); var b_ref: (((i32,), i32), (i32, i32)) = (((0,), 1), (2, 3)); // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; var a: (i32,) = a_ref; var b: (((i32,), i32), (i32, i32)) = b_ref; diff --git a/toolchain/check/testdata/var/no_prelude/export_name.carbon b/toolchain/check/testdata/var/no_prelude/export_name.carbon index 70aa27ea3721..c7768fb92f38 100644 --- a/toolchain/check/testdata/var/no_prelude/export_name.carbon +++ b/toolchain/check/testdata/var/no_prelude/export_name.carbon @@ -10,13 +10,13 @@ // --- base.carbon -library "base" api; +library "base"; var v: (); // --- export.carbon -library "export" api; +library "export"; import library "base"; @@ -28,7 +28,7 @@ export v; // --- fail_todo_use_export.carbon -library "use_export" api; +library "use_export"; // CHECK:STDERR: fail_todo_use_export.carbon:[[@LINE+9]]:1: In import. // CHECK:STDERR: import library "export"; diff --git a/toolchain/check/testdata/var/no_prelude/import.carbon b/toolchain/check/testdata/var/no_prelude/import.carbon index d24b987d099c..3b0f7768176b 100644 --- a/toolchain/check/testdata/var/no_prelude/import.carbon +++ b/toolchain/check/testdata/var/no_prelude/import.carbon @@ -6,13 +6,13 @@ // --- implicit.carbon -package Implicit api; +package Implicit; var a_ref: () = (); // --- implicit.impl.carbon -package Implicit impl; +impl package Implicit; var a: () = a_ref; diff --git a/toolchain/diagnostics/diagnostic_kind.def b/toolchain/diagnostics/diagnostic_kind.def index 704864388dd8..ee89f8217cd8 100644 --- a/toolchain/diagnostics/diagnostic_kind.def +++ b/toolchain/diagnostics/diagnostic_kind.def @@ -98,7 +98,6 @@ CARBON_DIAGNOSTIC_KIND(ExpectedIdentifierAfterImport) CARBON_DIAGNOSTIC_KIND(ExpectedLibraryName) CARBON_DIAGNOSTIC_KIND(ExpectedLibraryNameOrDefault) CARBON_DIAGNOSTIC_KIND(MissingLibraryKeyword) -CARBON_DIAGNOSTIC_KIND(ExpectedApiOrImpl) CARBON_DIAGNOSTIC_KIND(ExportImportPackage) // For-specific diagnostics. diff --git a/toolchain/lex/token_kind.h b/toolchain/lex/token_kind.h index 7ca87e99acab..6db40b0a34a8 100644 --- a/toolchain/lex/token_kind.h +++ b/toolchain/lex/token_kind.h @@ -30,6 +30,9 @@ class TokenKind : public CARBON_ENUM_BASE(TokenKind) { using EnumBase::EnumBase; + // Permit conversion to integer for use as an array index. + using EnumBase::AsInt; + // Test whether this kind of token is a simple symbol sequence (punctuation, // not letters) that appears directly in the source text and can be // unambiguously lexed with `starts_with` logic. While these may appear diff --git a/toolchain/lower/testdata/builtins/overloaded_operator.carbon b/toolchain/lower/testdata/builtins/overloaded_operator.carbon index 2de33b68c790..60d9452b38c7 100644 --- a/toolchain/lower/testdata/builtins/overloaded_operator.carbon +++ b/toolchain/lower/testdata/builtins/overloaded_operator.carbon @@ -6,7 +6,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Add { fn Op[self: Self](other: Self) -> Self; diff --git a/toolchain/lower/testdata/class/adapt.carbon b/toolchain/lower/testdata/class/adapt.carbon index f18f90ea0dc8..486e8a74b141 100644 --- a/toolchain/lower/testdata/class/adapt.carbon +++ b/toolchain/lower/testdata/class/adapt.carbon @@ -6,7 +6,7 @@ // --- adapt_class.carbon -library "adapt_class" api; +library "adapt_class"; class PairOfInts { var a: i32; @@ -37,7 +37,7 @@ fn Use() -> i32 { // --- adapt_int.carbon -library "adapt_int" api; +library "adapt_int"; class Int { adapt i32; diff --git a/toolchain/lower/testdata/operators/overloaded.carbon b/toolchain/lower/testdata/operators/overloaded.carbon index 36f9cce7d771..901226efa4a3 100644 --- a/toolchain/lower/testdata/operators/overloaded.carbon +++ b/toolchain/lower/testdata/operators/overloaded.carbon @@ -6,7 +6,7 @@ // --- prelude.carbon -package Core api; +package Core; interface Negate { fn Op[self: Self]() -> Self; diff --git a/toolchain/lower/testdata/packages/cross_package_call.carbon b/toolchain/lower/testdata/packages/cross_package_call.carbon index 87c55dae42da..f7a089b88526 100644 --- a/toolchain/lower/testdata/packages/cross_package_call.carbon +++ b/toolchain/lower/testdata/packages/cross_package_call.carbon @@ -6,7 +6,7 @@ // --- a.carbon -package A api; +package A; fn F() {} diff --git a/toolchain/parse/context.h b/toolchain/parse/context.h index b0fb17747d12..fa666ba1bcc7 100644 --- a/toolchain/parse/context.h +++ b/toolchain/parse/context.h @@ -303,11 +303,10 @@ class Context { bool skip_past_likely_end) -> void; // Sets the package declaration information. Called at most once. - auto set_packaging_decl(Tree::PackagingNames packaging_names, - Tree::ApiOrImpl api_or_impl) -> void { + auto set_packaging_decl(Tree::PackagingNames packaging_names, bool is_impl) + -> void { CARBON_CHECK(!tree_->packaging_decl_); - tree_->packaging_decl_ = {.names = packaging_names, - .api_or_impl = api_or_impl}; + tree_->packaging_decl_ = {.names = packaging_names, .is_impl = is_impl}; } // Adds an import. diff --git a/toolchain/parse/handle_adapt.cpp b/toolchain/parse/handle_adapt.cpp index ac10df2a0b0d..0db847728ec4 100644 --- a/toolchain/parse/handle_adapt.cpp +++ b/toolchain/parse/handle_adapt.cpp @@ -6,6 +6,14 @@ namespace Carbon::Parse { +// Handles processing of a complete `adapt T` declaration. +auto HandleAdaptAfterIntroducer(Context& context) -> void { + auto state = context.PopState(); + state.state = State::AdaptDecl; + context.PushState(state); + context.PushState(State::Expr); +} + // Handles processing of a complete `adapt T` declaration. auto HandleAdaptDecl(Context& context) -> void { // TODO: This is identical to HandleBaseDecl other than the `NodeKind`, diff --git a/toolchain/parse/handle_base.cpp b/toolchain/parse/handle_base.cpp index 4fd7d337e109..095a9cd0fe50 100644 --- a/toolchain/parse/handle_base.cpp +++ b/toolchain/parse/handle_base.cpp @@ -6,6 +6,28 @@ namespace Carbon::Parse { +// Handles a `base` declaration after the introducer. +auto HandleBaseAfterIntroducer(Context& context) -> void { + auto state = context.PopState(); + + if (!context.ConsumeAndAddLeafNodeIf(Lex::TokenKind::Colon, + NodeKind::BaseColon)) { + // TODO: If the next token isn't a colon or `class`, try to recover + // based on whether we're in a class, whether we have an `extend` + // modifier, and the following tokens. + CARBON_DIAGNOSTIC(ExpectedAfterBase, Error, + "`class` or `:` expected after `base`."); + context.emitter().Emit(*context.position(), ExpectedAfterBase); + context.RecoverFromDeclError(state, NodeKind::BaseDecl, + /*skip_past_likely_end=*/true); + return; + } + + state.state = State::BaseDecl; + context.PushState(state); + context.PushState(State::Expr); +} + // Handles processing of a complete `base: B` declaration. auto HandleBaseDecl(Context& context) -> void { auto state = context.PopState(); diff --git a/toolchain/parse/handle_decl_scope_loop.cpp b/toolchain/parse/handle_decl_scope_loop.cpp index 9e4bcf315c18..b79a60a77c9b 100644 --- a/toolchain/parse/handle_decl_scope_loop.cpp +++ b/toolchain/parse/handle_decl_scope_loop.cpp @@ -8,53 +8,6 @@ namespace Carbon::Parse { -// Handles positions which are end of scope and packaging declarations. Returns -// true when either applies. When the position is neither, returns false, and -// may still update packaging state. -static auto TryHandleEndOrPackagingDecl(Context& context) -> bool { - switch (context.PositionKind()) { - case Lex::TokenKind::CloseCurlyBrace: - case Lex::TokenKind::FileEnd: { - // This is the end of the scope, so the loop state ends. - context.PopAndDiscardState(); - return true; - } - // Packaging-related keywords manage their packaging state. - case Lex::TokenKind::Export: { - if (!context.PositionIs(Lex::TokenKind::Import, Lookahead::NextToken)) { - break; - } - context.PushState(State::ImportAsExport); - return true; - } - case Lex::TokenKind::Import: { - context.PushState(State::ImportAsRegular); - return true; - } - case Lex::TokenKind::Library: { - context.PushState(State::Library); - return true; - } - case Lex::TokenKind::Package: { - context.PushState(State::Package); - return true; - } - default: - break; - } - - // Because a non-packaging keyword was encountered, packaging is complete. - // Misplaced packaging keywords may lead to this being re-triggered. - if (context.packaging_state() != - Context::PackagingState::AfterNonPackagingDecl) { - if (!context.first_non_packaging_token().is_valid()) { - context.set_first_non_packaging_token(*context.position()); - } - context.set_packaging_state(Context::PackagingState::AfterNonPackagingDecl); - } - return false; -} - // Finishes an invalid declaration, skipping past its end. static auto FinishAndSkipInvalidDecl(Context& context, int32_t subtree_start) -> void { @@ -88,118 +41,113 @@ static auto ApplyIntroducer(Context& context, Context::StateStackEntry state, context.PushState(state, next_state); } -// Handles `base` as a declaration. -static auto HandleBaseAsDecl(Context& context, Context::StateStackEntry state) - -> void { - // At this point, `base` has been ruled out as a modifier (`base class`). If - // it's followed by a colon, it's an introducer (`extend base: BaseType;`). - // Otherwise it's an error. - if (context.PositionIs(Lex::TokenKind::Colon, Lookahead::NextToken)) { - ApplyIntroducer(context, state, NodeKind::BaseIntroducer, State::BaseDecl); - context.PushState(State::Expr); - context.AddLeafNode(NodeKind::BaseColon, context.Consume()); - } else { - // TODO: If the next token isn't a colon or `class`, try to recover - // based on whether we're in a class, whether we have an `extend` - // modifier, and the following tokens. - context.AddLeafNode(NodeKind::InvalidParse, context.Consume(), - /*has_error=*/true); - CARBON_DIAGNOSTIC(ExpectedAfterBase, Error, - "`class` or `:` expected after `base`."); - context.emitter().Emit(*context.position(), ExpectedAfterBase); - FinishAndSkipInvalidDecl(context, state.subtree_start); - } -} +namespace { +// The kind of declaration introduced by an introducer keyword. +enum class DeclIntroducerKind : int8_t { + Unrecognized, + PackagingDecl, + NonPackagingDecl, +}; +// Information about a keyword that might be an introducer keyword. +struct DeclIntroducerInfo { + DeclIntroducerKind introducer_kind; + NodeKind node_kind; + State state; +}; +} // namespace + +static constexpr auto DeclIntroducers = [] { + DeclIntroducerInfo introducers[] = { +#define CARBON_TOKEN(Name) \ + {DeclIntroducerKind::Unrecognized, NodeKind::InvalidParse, State::Invalid}, +#include "toolchain/lex/token_kind.def" + }; + auto set = [&](Lex::TokenKind token_kind, NodeKind node_kind, State state) { + introducers[token_kind.AsInt()] = {DeclIntroducerKind::NonPackagingDecl, + node_kind, state}; + }; + auto set_packaging = [&](Lex::TokenKind token_kind, NodeKind node_kind, + State state) { + introducers[token_kind.AsInt()] = {DeclIntroducerKind::PackagingDecl, + node_kind, state}; + }; + + set(Lex::TokenKind::Adapt, NodeKind::AdaptIntroducer, + State::AdaptAfterIntroducer); + set(Lex::TokenKind::Alias, NodeKind::AliasIntroducer, State::Alias); + set(Lex::TokenKind::Base, NodeKind::BaseIntroducer, + State::BaseAfterIntroducer); + set(Lex::TokenKind::Choice, NodeKind::ChoiceIntroducer, + State::ChoiceIntroducer); + set(Lex::TokenKind::Class, NodeKind::ClassIntroducer, + State::TypeAfterIntroducerAsClass); + set(Lex::TokenKind::Constraint, NodeKind::NamedConstraintIntroducer, + State::TypeAfterIntroducerAsNamedConstraint); + set(Lex::TokenKind::Export, NodeKind::ExportIntroducer, State::ExportName); + // TODO: Treat `extend` as a declaration introducer. + set(Lex::TokenKind::Fn, NodeKind::FunctionIntroducer, + State::FunctionIntroducer); + set(Lex::TokenKind::Impl, NodeKind::ImplIntroducer, + State::ImplAfterIntroducer); + set(Lex::TokenKind::Interface, NodeKind::InterfaceIntroducer, + State::TypeAfterIntroducerAsInterface); + set(Lex::TokenKind::Namespace, NodeKind::NamespaceStart, State::Namespace); + set(Lex::TokenKind::Let, NodeKind::LetIntroducer, State::Let); + set(Lex::TokenKind::Var, NodeKind::VariableIntroducer, State::VarAsDecl); + + set_packaging(Lex::TokenKind::Package, NodeKind::PackageIntroducer, + State::Package); + set_packaging(Lex::TokenKind::Library, NodeKind::LibraryIntroducer, + State::Library); + set_packaging(Lex::TokenKind::Import, NodeKind::ImportIntroducer, + State::Import); + return std::to_array(introducers); +}(); + +// Attempts to handle the current token as a declaration introducer. // Returns true if the current position is a declaration. If we see a // declaration introducer keyword token, replace the placeholder node and switch // to a state to parse the rest of the declaration. static auto TryHandleAsDecl(Context& context, Context::StateStackEntry state, bool saw_modifier) -> bool { - switch (context.PositionKind()) { - case Lex::TokenKind::Adapt: { - ApplyIntroducer(context, state, NodeKind::AdaptIntroducer, - State::AdaptDecl); - context.PushState(State::Expr); - return true; - } - case Lex::TokenKind::Alias: { - ApplyIntroducer(context, state, NodeKind::AliasIntroducer, State::Alias); - return true; - } - case Lex::TokenKind::Base: { - HandleBaseAsDecl(context, state); - return true; - } - case Lex::TokenKind::Choice: { - ApplyIntroducer(context, state, NodeKind::ChoiceIntroducer, - State::ChoiceIntroducer); - return true; - } - case Lex::TokenKind::Class: { - ApplyIntroducer(context, state, NodeKind::ClassIntroducer, - State::TypeAfterIntroducerAsClass); - return true; - } - case Lex::TokenKind::Constraint: { - ApplyIntroducer(context, state, NodeKind::NamedConstraintIntroducer, - State::TypeAfterIntroducerAsNamedConstraint); - return true; - } - case Lex::TokenKind::Export: { - ApplyIntroducer(context, state, NodeKind::ExportIntroducer, - State::ExportName); - return true; - } - case Lex::TokenKind::Extend: { - // TODO: Treat this `extend` token as a declaration introducer - HandleUnrecognizedDecl(context, state.subtree_start); - return true; - } - case Lex::TokenKind::Fn: { - ApplyIntroducer(context, state, NodeKind::FunctionIntroducer, - State::FunctionIntroducer); - return true; - } - case Lex::TokenKind::Impl: { - ApplyIntroducer(context, state, NodeKind::ImplIntroducer, - State::ImplAfterIntroducer); - return true; - } - case Lex::TokenKind::Interface: { - ApplyIntroducer(context, state, NodeKind::InterfaceIntroducer, - State::TypeAfterIntroducerAsInterface); - return true; - } - case Lex::TokenKind::Namespace: { - ApplyIntroducer(context, state, NodeKind::NamespaceStart, - State::Namespace); - return true; - } - case Lex::TokenKind::Let: { - ApplyIntroducer(context, state, NodeKind::LetIntroducer, State::Let); - return true; - } - case Lex::TokenKind::Var: { - ApplyIntroducer(context, state, NodeKind::VariableIntroducer, - State::VarAsDecl); - return true; - } + const auto& info = DeclIntroducers[context.PositionKind().AsInt()]; - case Lex::TokenKind::Semi: { - if (saw_modifier) { - // Modifiers require an introducer keyword. - HandleUnrecognizedDecl(context, state.subtree_start); - } else { - context.ReplacePlaceholderNode(state.subtree_start, NodeKind::EmptyDecl, - context.Consume()); + switch (info.introducer_kind) { + case DeclIntroducerKind::Unrecognized: { + // A `;` with no modifiers is an empty declaration. + if (!saw_modifier) { + if (auto loc = context.ConsumeIf(Lex::TokenKind::Semi)) { + context.ReplacePlaceholderNode(state.subtree_start, + NodeKind::EmptyDecl, *loc); + return true; + } } - return true; + return false; } - default: - return false; + case DeclIntroducerKind::PackagingDecl: { + // Packaging declarations update the packaging state themselves as needed. + break; + } + + case DeclIntroducerKind::NonPackagingDecl: { + // Because a non-packaging keyword was encountered, packaging is complete. + // Misplaced packaging keywords may lead to this being re-triggered. + if (context.packaging_state() != + Context::PackagingState::AfterNonPackagingDecl) { + if (!context.first_non_packaging_token().is_valid()) { + context.set_first_non_packaging_token(*context.position()); + } + context.set_packaging_state( + Context::PackagingState::AfterNonPackagingDecl); + } + break; + } } + + ApplyIntroducer(context, state, info.node_kind, info.state); + return true; } // Returns true if position_kind could be either an introducer or modifier, and @@ -209,6 +157,7 @@ static auto ResolveAmbiguousTokenAsDeclaration(Context& context, -> bool { switch (position_kind) { case Lex::TokenKind::Base: + case Lex::TokenKind::Export: case Lex::TokenKind::Extend: case Lex::TokenKind::Impl: // This is an ambiguous token, so now we check what the next token is. @@ -222,8 +171,10 @@ static auto ResolveAmbiguousTokenAsDeclaration(Context& context, case Lex::TokenKind::Class: case Lex::TokenKind::Constraint: case Lex::TokenKind::Fn: + case Lex::TokenKind::Import: case Lex::TokenKind::Interface: case Lex::TokenKind::Let: + case Lex::TokenKind::Library: case Lex::TokenKind::Namespace: case Lex::TokenKind::Var: #define CARBON_PARSE_NODE_KIND(...) @@ -233,6 +184,11 @@ static auto ResolveAmbiguousTokenAsDeclaration(Context& context, return false; + case Lex::TokenKind::Package: + // `package.foo` is an expression; any other token after `package` is + // a `package` introducer. + return context.PositionKind(Lookahead(2)) == Lex::TokenKind::Period; + default: return true; } @@ -265,7 +221,10 @@ static auto TryHandleAsModifier(Context& context) -> bool { auto HandleDeclScopeLoop(Context& context) -> void { // This maintains the current state unless we're at the end of the scope. - if (TryHandleEndOrPackagingDecl(context)) { + if (context.PositionIs(Lex::TokenKind::CloseCurlyBrace) || + context.PositionIs(Lex::TokenKind::FileEnd)) { + // This is the end of the scope, so the loop state ends. + context.PopAndDiscardState(); return; } diff --git a/toolchain/parse/handle_import_and_package.cpp b/toolchain/parse/handle_import_and_package.cpp index 006f2950c464..fc9ce0fe62aa 100644 --- a/toolchain/parse/handle_import_and_package.cpp +++ b/toolchain/parse/handle_import_and_package.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include "toolchain/base/value_store.h" +#include "toolchain/lex/token_kind.h" #include "toolchain/lex/tokenized_buffer.h" #include "toolchain/parse/context.h" #include "toolchain/parse/node_ids.h" @@ -17,6 +18,21 @@ static auto OnParseError(Context& context, Context::StateStackEntry state, state.subtree_start, /*has_error=*/true); } +// Determines whether the specified modifier appears within the introducer of +// the given declaration. +// TODO: Restructure how we handle packaging declarations to avoid the need to +// do this. +static auto HasModifier(Context& context, Context::StateStackEntry state, + Lex::TokenKind modifier) -> bool { + for (auto it = Lex::TokenIterator(state.token); it != context.position(); + ++it) { + if (context.tokens().GetKind(*it) == modifier) { + return true; + } + } + return false; +} + // Handles parsing of the library name. Returns the name's ID on success, which // may be invalid for `default`. static auto HandleLibraryName(Context& context, bool accept_default) @@ -45,34 +61,10 @@ static auto HandleLibraryName(Context& context, bool accept_default) return std::nullopt; } -// Returns whether `api` or `impl` is provided, or prints an error and returns -// nullopt. -static auto HandleApiOrImpl(Context& context) - -> std::optional { - switch (context.PositionKind()) { - case Lex::TokenKind::Api: { - context.AddLeafNode(NodeKind::PackageApi, - context.ConsumeChecked(Lex::TokenKind::Api)); - return Tree::ApiOrImpl::Api; - break; - } - case Lex::TokenKind::Impl: { - context.AddLeafNode(NodeKind::PackageImpl, - context.ConsumeChecked(Lex::TokenKind::Impl)); - return Tree::ApiOrImpl::Impl; - break; - } - default: { - CARBON_DIAGNOSTIC(ExpectedApiOrImpl, Error, "Expected `api` or `impl`."); - context.emitter().Emit(*context.position(), ExpectedApiOrImpl); - return std::nullopt; - } - } -} - // Handles everything after the declaration's introducer. static auto HandleDeclContent(Context& context, Context::StateStackEntry state, NodeKind declaration, bool is_export, + bool is_impl, llvm::function_ref on_parse_error) -> void { Tree::PackagingNames names{ @@ -142,20 +134,11 @@ static auto HandleDeclContent(Context& context, Context::StateStackEntry state, } } - std::optional api_or_impl; - if (declaration != NodeKind::ImportDecl) { - api_or_impl = HandleApiOrImpl(context); - if (!api_or_impl) { - on_parse_error(); - return; - } - } - if (auto semi = context.ConsumeIf(Lex::TokenKind::Semi)) { if (declaration == NodeKind::ImportDecl) { context.AddImport(names); } else { - context.set_packaging_decl(names, *api_or_impl); + context.set_packaging_decl(names, is_impl); } context.AddNode(declaration, *semi, state.subtree_start, state.has_error); @@ -201,41 +184,12 @@ static auto VerifyInImports(Context& context, Lex::TokenIndex intro_token) } } -// Common logic for both `import` and `export import`, distinguished by whether -// `export_token` is valid. -static auto HandleImportHelper(Context& context, - const Context::StateStackEntry& state, - Lex::TokenIndex export_token) -> void { - auto declaration = NodeKind::ImportDecl; - auto on_parse_error = [&] { OnParseError(context, state, declaration); }; - - auto intro_token = context.ConsumeChecked(Lex::TokenKind::Import); - context.AddLeafNode(NodeKind::ImportIntroducer, intro_token); - - if (export_token.is_valid()) { - context.AddLeafNode(NodeKind::ImportExport, export_token); - } - - if (VerifyInImports(context, intro_token)) { - HandleDeclContent(context, state, declaration, export_token.is_valid(), - on_parse_error); - } else { - on_parse_error(); - } -} - -auto HandleImportAsRegular(Context& context) -> void { - auto state = context.PopState(); - - HandleImportHelper(context, state, /*export_token=*/Lex::TokenIndex::Invalid); -} - // Diagnoses if `export` is used in an `impl` file. static auto RestrictExportToApi(Context& context, Context::StateStackEntry& state) -> void { // Error for both Main//default and every implementation file. auto packaging = context.tree().packaging_decl(); - if (!packaging || packaging->api_or_impl == Tree::ApiOrImpl::Impl) { + if (!packaging || packaging->is_impl) { CARBON_DIAGNOSTIC(ExportFromImpl, Error, "`export` is only allowed in API files."); context.emitter().Emit(state.token, ExportFromImpl); @@ -243,13 +197,24 @@ static auto RestrictExportToApi(Context& context, } } -auto HandleImportAsExport(Context& context) -> void { +auto HandleImport(Context& context) -> void { auto state = context.PopState(); - context.ConsumeChecked(Lex::TokenKind::Export); - RestrictExportToApi(context, state); + auto declaration = NodeKind::ImportDecl; + auto on_parse_error = [&] { OnParseError(context, state, declaration); }; - HandleImportHelper(context, state, state.token); + if (VerifyInImports(context, state.token)) { + // Scan the modifiers to see if this import declaration is exported. + bool is_export = HasModifier(context, state, Lex::TokenKind::Export); + if (is_export) { + RestrictExportToApi(context, state); + } + + HandleDeclContent(context, state, declaration, is_export, + /*is_impl=*/false, on_parse_error); + } else { + on_parse_error(); + } } auto HandleExportName(Context& context) -> void { @@ -272,16 +237,14 @@ auto HandleExportNameFinish(Context& context) -> void { // Handles common logic for `package` and `library`. static auto HandlePackageAndLibraryDecls(Context& context, Lex::TokenKind intro_token_kind, - NodeKind intro, NodeKind declaration) - -> void { + NodeKind declaration) -> void { auto state = context.PopState(); + bool is_impl = HasModifier(context, state, Lex::TokenKind::Impl); + auto on_parse_error = [&] { OnParseError(context, state, declaration); }; - auto intro_token = context.ConsumeChecked(intro_token_kind); - context.AddLeafNode(intro, intro_token); - - if (intro_token != Lex::TokenIndex::FirstNonCommentToken) { + if (state.token != Lex::TokenIndex::FirstNonCommentToken) { CARBON_DIAGNOSTIC( PackageTooLate, Error, "The `{0}` declaration must be the first non-comment line.", @@ -289,7 +252,7 @@ static auto HandlePackageAndLibraryDecls(Context& context, CARBON_DIAGNOSTIC(FirstNonCommentLine, Note, "First non-comment line is here."); context.emitter() - .Build(intro_token, PackageTooLate, intro_token_kind) + .Build(state.token, PackageTooLate, intro_token_kind) .Note(Lex::TokenIndex::FirstNonCommentToken, FirstNonCommentLine) .Emit(); on_parse_error(); @@ -299,19 +262,17 @@ static auto HandlePackageAndLibraryDecls(Context& context, // `package`/`library` is no longer allowed, but `import` may repeat. context.set_packaging_state(Context::PackagingState::InImports); - HandleDeclContent(context, state, declaration, /*is_export=*/false, + HandleDeclContent(context, state, declaration, /*is_export=*/false, is_impl, on_parse_error); } auto HandlePackage(Context& context) -> void { HandlePackageAndLibraryDecls(context, Lex::TokenKind::Package, - NodeKind::PackageIntroducer, NodeKind::PackageDecl); } auto HandleLibrary(Context& context) -> void { HandlePackageAndLibraryDecls(context, Lex::TokenKind::Library, - NodeKind::LibraryIntroducer, NodeKind::LibraryDecl); } diff --git a/toolchain/parse/node_kind.def b/toolchain/parse/node_kind.def index 1bf8b1b6e232..10c00973c7d3 100644 --- a/toolchain/parse/node_kind.def +++ b/toolchain/parse/node_kind.def @@ -182,31 +182,28 @@ CARBON_PARSE_NODE_KIND_CHILD_COUNT(LibraryName, 0, StringLiteral) // `package`: // PackageIntroducer +// _repeated_ _external_: modifier // _optional_ _external_: PackageName // _optional_ _external_: LibrarySpecifier -// PackageApi or PackageImpl // PackageDecl CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageIntroducer, 0, Package) -CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageApi, 0, Api) -CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageImpl, 0, Impl) CARBON_PARSE_NODE_KIND_BRACKET(PackageDecl, PackageIntroducer, CARBON_IF_VALID(Semi)) // `import`: // ImportIntroducer -// _optional_: ImportExport +// _repeated_ _external_: modifier // _optional_ _external_: PackageName // _optional_ _external_: LibrarySpecifier // ImportDecl CARBON_PARSE_NODE_KIND_CHILD_COUNT(ImportIntroducer, 0, Import) -CARBON_PARSE_NODE_KIND_CHILD_COUNT(ImportExport, 0, Export) CARBON_PARSE_NODE_KIND_BRACKET(ImportDecl, ImportIntroducer, CARBON_IF_VALID(Semi)) // `library` as declaration: // LibraryIntroducer +// _repeated_ _external_: modifier // DefaultLibrary or _external_: LibraryName -// PackageApi or PackageImpl // LibraryDecl CARBON_PARSE_NODE_KIND_CHILD_COUNT(DefaultLibrary, 0, Default) CARBON_PARSE_NODE_KIND_CHILD_COUNT(LibraryIntroducer, 0, Library) @@ -646,6 +643,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(StructTypeLiteral, StructTypeLiteralStart, CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Abstract) CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Base) CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Default) +CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Export) CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Extend) CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Extern) CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Final) diff --git a/toolchain/parse/state.def b/toolchain/parse/state.def index 6646c3dedf6f..b3f3fdeebac2 100644 --- a/toolchain/parse/state.def +++ b/toolchain/parse/state.def @@ -293,6 +293,8 @@ CARBON_PARSE_STATE(DeclNameAndParamsAfterImplicit) // ^~~~ // default // ^~~~~~~ +// export import +// ^~~~~~ // extend base // ^~~~~~ // final @@ -309,8 +311,7 @@ CARBON_PARSE_STATE(DeclNameAndParamsAfterImplicit) // // adapt ... // ^~~~~ -// 1. Expr -// 2. AdaptDecl +// 2. AdaptAfterIntroducer // 3. DeclScopeLoop // // alias ... @@ -318,17 +319,21 @@ CARBON_PARSE_STATE(DeclNameAndParamsAfterImplicit) // 1. Alias // 2. DeclScopeLoop // +// base : ... +// ^~~~ +// 1. BaseAfterIntroducer +// 2. DeclScopeLoop +// +// choice ... +// ^~~~~~ +// 1. ChoiceIntroducer +// 2. DeclScopeLoop +// // class ... // ^~~~~ // 1. TypeAfterIntroducerAsClass // 2. DeclScopeLoop // -// base : ... -// ^~~~~~ -// 1. Expr -// 2. BaseDecl -// 3. DeclScopeLoop -// // constraint ... // ^~~~~~~~~~ // 1. TypeAfterIntroducerAsNamedConstraint @@ -349,35 +354,45 @@ CARBON_PARSE_STATE(DeclNameAndParamsAfterImplicit) // 1. ImplAfterIntroducer // 2. DeclScopeLoop // +// import ... (in packaging directives) +// ^~~~~~ +// 1. Import +// 2. DeclScopeLoop +// // interface ... // ^~~~~~~~~ // 1. TypeAfterIntroducerAsInterface // 2. DeclScopeLoop // -// namespace ... -// ^~~~~~~~~ -// 1. Namespace -// 2. DeclScopeLoop -// -// ; -// ^ -// 1. DeclScopeLoop -// -// var ... -// ^~~ -// 1. VarAsDecl -// 2. DeclScopeLoop -// // let ... // ^~~ // 1. Let // 2. DeclScopeLoop // -// choice ... -// ^ -// 1. ChoiceIntroducer +// library ... (in packaging directives) +// ^~~~~~~ +// 1. Library // 2. DeclScopeLoop // +// namespace ... +// ^~~~~~~~~ +// 1. Namespace +// 2. DeclScopeLoop +// +// package ... (in packaging directives) +// ^~~~~~~ +// 1. Package +// 2. DeclScopeLoop +// +// var ... +// ^~~ +// 1. VarAsDecl +// 2. DeclScopeLoop +// +// ; +// ^ +// 1. DeclScopeLoop +// // ??? ; // ^~~~~ // (state done) @@ -693,17 +708,20 @@ CARBON_PARSE_STATE(ExportNameFinish) // Handles `import`. // // import pkgname [library "libname"] ; -// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// import library "libname" ; +// ^~~~~~~~~~~~~~~~~~~ // import ??? ; -// ^~~~~~~~~~~~ -// export import library "libname" ; -// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ^~~~~ // (state done) -CARBON_PARSE_STATE_VARIANTS2(Import, Regular, Export) +CARBON_PARSE_STATE(Import) // Handles `library` in declaration form. // -// Always: +// library "libname" ; +// ^~~~~~~~~~~ +// library ??? ; +// ^~~~~ // (state done) CARBON_PARSE_STATE(Library) @@ -726,10 +744,10 @@ CARBON_PARSE_STATE(NamespaceFinish) // Handles `package`. // -// package pkgname [library "libname"] [api|impl] ; -// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// package pkgname [library "libname"] ; +// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // package ??? ; -// ^~~~~~~~~~~~~ +// ^~~~~ // (state done) CARBON_PARSE_STATE(Package) @@ -1219,6 +1237,14 @@ CARBON_PARSE_STATE_VARIANTS3(TypeAfterIntroducer, Class, Interface, CARBON_PARSE_STATE_VARIANTS4(DeclOrDefinition, Class, Impl, Interface, NamedConstraint) +// Handles processing of an `adapt T` declaration after the introducer. +// +// adapt T ; +// ^ +// 1. Expr +// 2. AdaptDecl +CARBON_PARSE_STATE(AdaptAfterIntroducer) + // Handles processing of a completed `adapt T` declaration. // // adapt T ; @@ -1228,6 +1254,17 @@ CARBON_PARSE_STATE_VARIANTS4(DeclOrDefinition, Class, Impl, Interface, // (state done) CARBON_PARSE_STATE(AdaptDecl) +// Handles processing of a `base: B` after the introducer. +// +// base: B ; +// ^ +// 1. Expr +// 2. BaseDecl +// base ??? ; +// ^~~ +// (state done) +CARBON_PARSE_STATE(BaseAfterIntroducer) + // Handles processing of a completed `base: B` declaration. // // base: B ; diff --git a/toolchain/parse/testdata/class/fail_base.carbon b/toolchain/parse/testdata/class/fail_base.carbon index 40ba64b1b5bc..6ae77227f2aa 100644 --- a/toolchain/parse/testdata/class/fail_base.carbon +++ b/toolchain/parse/testdata/class/fail_base.carbon @@ -35,9 +35,8 @@ class A { // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'A'}, // CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 3}, -// CHECK:STDOUT: {kind: 'InvalidParseStart', text: ';', has_error: yes}, -// CHECK:STDOUT: {kind: 'InvalidParse', text: 'base', has_error: yes}, -// CHECK:STDOUT: {kind: 'InvalidParseSubtree', text: ';', has_error: yes, subtree_size: 3}, +// CHECK:STDOUT: {kind: 'BaseIntroducer', text: 'base'}, +// CHECK:STDOUT: {kind: 'BaseDecl', text: ';', has_error: yes, subtree_size: 2}, // CHECK:STDOUT: {kind: 'BaseIntroducer', text: 'base'}, // CHECK:STDOUT: {kind: 'BaseColon', text: ':'}, // CHECK:STDOUT: {kind: 'InvalidParse', text: ';', has_error: yes}, @@ -49,6 +48,6 @@ class A { // CHECK:STDOUT: {kind: 'BaseDecl', text: 'var', has_error: yes, subtree_size: 5}, // CHECK:STDOUT: {kind: 'InvalidParseStart', text: 'n', has_error: yes}, // CHECK:STDOUT: {kind: 'InvalidParseSubtree', text: ';', has_error: yes, subtree_size: 2}, -// CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 18}, +// CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 17}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] diff --git a/toolchain/parse/testdata/packages/export.carbon b/toolchain/parse/testdata/packages/export.carbon index 4ac4c009d236..02d30c5b3216 100644 --- a/toolchain/parse/testdata/packages/export.carbon +++ b/toolchain/parse/testdata/packages/export.carbon @@ -6,23 +6,23 @@ // --- lib.carbon -library "lib" api; +library "lib"; // --- name.carbon -package Pkg api; +package Pkg; export Foo; // --- qual_name.carbon -package Pkg api; +package Pkg; export Foo.Bar; // --- fail_expr.carbon -package Pkg api; +package Pkg; // CHECK:STDERR: fail_expr.carbon:[[@LINE+4]]:8: ERROR: `export` introducer should be followed by a name. // CHECK:STDERR: export (); @@ -32,7 +32,7 @@ export (); // --- fail_package_in_name.carbon -package Pkg api; +package Pkg; // CHECK:STDERR: fail_package_in_name.carbon:[[@LINE+4]]:8: ERROR: `export` introducer should be followed by a name. // CHECK:STDERR: export package.Bar; @@ -42,7 +42,7 @@ export package.Bar; // --- fail_keyword_only -package Pkg api; +package Pkg; // CHECK:STDERR: fail_keyword_only:[[@LINE+4]]:1: ERROR: `export` introducer should be followed by a name. // CHECK:STDERR: export @@ -52,7 +52,7 @@ export // --- fail_no_name.carbon -package Pkg api; +package Pkg; // CHECK:STDERR: fail_no_name.carbon:[[@LINE+4]]:8: ERROR: `export` introducer should be followed by a name. // CHECK:STDERR: export ; @@ -62,7 +62,7 @@ export ; // --- fail_no_semi.carbon -package Pkg api; +package Pkg; export Foo // CHECK:STDERR: fail_no_semi.carbon:[[@LINE+4]]:1: ERROR: `export` declarations must end with a `;`. @@ -72,7 +72,7 @@ export Foo // --- fail_incomplete_qual_name.carbon -package Pkg api; +package Pkg; // CHECK:STDERR: fail_incomplete_qual_name.carbon:[[@LINE+4]]:12: ERROR: Expected identifier after `.`. // CHECK:STDERR: export Foo.; @@ -82,7 +82,7 @@ export Foo.; // --- fail_incomplete_qual_name2.carbon -package Pkg api; +package Pkg; // CHECK:STDERR: fail_incomplete_qual_name2.carbon:[[@LINE+4]]:8: ERROR: `export` introducer should be followed by a name. // CHECK:STDERR: export .Bar; @@ -92,7 +92,7 @@ export .Bar; // --- after_decl.carbon -package Pkg api; +package Pkg; class C; @@ -100,7 +100,7 @@ export Foo; // --- fail_before_import.carbon -package Pkg api; +package Pkg; export Foo; @@ -123,7 +123,7 @@ export Foo; // --- fail_in_impl.carbon -package Pkg impl; +impl package Pkg; // CHECK:STDERR: fail_in_impl.carbon:[[@LINE+3]]:1: ERROR: `export` is only allowed in API files. // CHECK:STDERR: export Foo; @@ -135,8 +135,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'LibraryIntroducer', text: 'library'}, // CHECK:STDOUT: {kind: 'LibraryName', text: '"lib"'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'LibraryDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'LibraryDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] // CHECK:STDOUT: - filename: name.carbon @@ -144,8 +143,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'Foo'}, // CHECK:STDOUT: {kind: 'ExportDecl', text: ';', subtree_size: 3}, @@ -156,8 +154,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'Foo'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'Bar'}, @@ -170,8 +167,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'InvalidParse', text: '(', has_error: yes}, // CHECK:STDOUT: {kind: 'ExportDecl', text: ';', has_error: yes, subtree_size: 3}, @@ -182,8 +178,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'InvalidParse', text: 'package', has_error: yes}, // CHECK:STDOUT: {kind: 'ExportDecl', text: ';', has_error: yes, subtree_size: 3}, @@ -194,8 +189,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'InvalidParse', text: '', has_error: yes}, // CHECK:STDOUT: {kind: 'ExportDecl', text: 'export', has_error: yes, subtree_size: 3}, @@ -206,8 +200,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'InvalidParse', text: ';', has_error: yes}, // CHECK:STDOUT: {kind: 'ExportDecl', text: ';', has_error: yes, subtree_size: 3}, @@ -218,8 +211,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'Foo'}, // CHECK:STDOUT: {kind: 'ExportDecl', text: 'Foo', has_error: yes, subtree_size: 3}, @@ -230,8 +222,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'Foo'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: ';', has_error: yes}, @@ -244,8 +235,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes}, // CHECK:STDOUT: {kind: 'ExportDecl', text: ';', has_error: yes, subtree_size: 3}, @@ -256,8 +246,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'C'}, // CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 3}, @@ -271,8 +260,7 @@ export Foo; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'Foo'}, // CHECK:STDOUT: {kind: 'ExportDecl', text: ';', subtree_size: 3}, @@ -292,8 +280,8 @@ export Foo; // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageImpl', text: 'impl'}, // CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, // CHECK:STDOUT: {kind: 'ExportIntroducer', text: 'export'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'Foo'}, diff --git a/toolchain/parse/testdata/packages/import/after_package.carbon b/toolchain/parse/testdata/packages/import/after_package.carbon index 2c2616bc3856..47ed67d0b1f7 100644 --- a/toolchain/parse/testdata/packages/import/after_package.carbon +++ b/toolchain/parse/testdata/packages/import/after_package.carbon @@ -4,7 +4,7 @@ // // AUTOUPDATE -package A api; +package A; import B; @@ -13,8 +13,7 @@ import B; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'A'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'B'}, // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', subtree_size: 3}, diff --git a/toolchain/parse/testdata/packages/import/export.carbon b/toolchain/parse/testdata/packages/import/export.carbon index ca737b104dbe..f51ac622bfa5 100644 --- a/toolchain/parse/testdata/packages/import/export.carbon +++ b/toolchain/parse/testdata/packages/import/export.carbon @@ -6,7 +6,7 @@ // --- fail_package.carbon -package Pkg api; +package Pkg; // CHECK:STDERR: fail_package.carbon:[[@LINE+4]]:15: ERROR: `export` cannot be used when importing a package. // CHECK:STDERR: export import Bar; @@ -16,27 +16,27 @@ export import Bar; // --- default.carbon -package Pkg api; +package Pkg; export import library default; // --- named.carbon -package Pkg api; +package Pkg; export import library "lib"; // --- fail_order.carbon -package Pkg api; +package Pkg; export import library "a"; class C; -// CHECK:STDERR: fail_order.carbon:[[@LINE+7]]:8: ERROR: `import` declarations must come after the `package` declaration (if present) and before any other entities in the file. +// CHECK:STDERR: fail_order.carbon:[[@LINE+7]]:1: ERROR: `import` declarations must come after the `package` declaration (if present) and before any other entities in the file. // CHECK:STDERR: export import library "b"; -// CHECK:STDERR: ^~~~~~ +// CHECK:STDERR: ^~~~~~ // CHECK:STDERR: fail_order.carbon:[[@LINE-5]]:1: First declaration is here. // CHECK:STDERR: class C; // CHECK:STDERR: ^~~~~ @@ -53,7 +53,7 @@ export import library "lib"; // --- fail_in_impl.carbon -package Pkg impl; +impl package Pkg; // CHECK:STDERR: fail_in_impl.carbon:[[@LINE+3]]:1: ERROR: `export` is only allowed in API files. // CHECK:STDERR: export import library "lib"; @@ -65,10 +65,9 @@ export import library "lib"; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'}, -// CHECK:STDOUT: {kind: 'ImportExport', text: 'export'}, +// CHECK:STDOUT: {kind: 'ExportModifier', text: 'export'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Bar'}, // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 4}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, @@ -78,10 +77,9 @@ export import library "lib"; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'}, -// CHECK:STDOUT: {kind: 'ImportExport', text: 'export'}, +// CHECK:STDOUT: {kind: 'ExportModifier', text: 'export'}, // CHECK:STDOUT: {kind: 'DefaultLibrary', text: 'default'}, // CHECK:STDOUT: {kind: 'LibrarySpecifier', text: 'library', subtree_size: 2}, // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', subtree_size: 5}, @@ -92,10 +90,9 @@ export import library "lib"; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'}, -// CHECK:STDOUT: {kind: 'ImportExport', text: 'export'}, +// CHECK:STDOUT: {kind: 'ExportModifier', text: 'export'}, // CHECK:STDOUT: {kind: 'LibraryName', text: '"lib"'}, // CHECK:STDOUT: {kind: 'LibrarySpecifier', text: 'library', subtree_size: 2}, // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', subtree_size: 5}, @@ -106,10 +103,9 @@ export import library "lib"; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'}, -// CHECK:STDOUT: {kind: 'ImportExport', text: 'export'}, +// CHECK:STDOUT: {kind: 'ExportModifier', text: 'export'}, // CHECK:STDOUT: {kind: 'LibraryName', text: '"a"'}, // CHECK:STDOUT: {kind: 'LibrarySpecifier', text: 'library', subtree_size: 2}, // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', subtree_size: 5}, @@ -117,7 +113,7 @@ export import library "lib"; // CHECK:STDOUT: {kind: 'IdentifierName', text: 'C'}, // CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'}, -// CHECK:STDOUT: {kind: 'ImportExport', text: 'export'}, +// CHECK:STDOUT: {kind: 'ExportModifier', text: 'export'}, // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 3}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] @@ -125,7 +121,7 @@ export import library "lib"; // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'}, -// CHECK:STDOUT: {kind: 'ImportExport', text: 'export'}, +// CHECK:STDOUT: {kind: 'ExportModifier', text: 'export'}, // CHECK:STDOUT: {kind: 'LibraryName', text: '"lib"'}, // CHECK:STDOUT: {kind: 'LibrarySpecifier', text: 'library', subtree_size: 2}, // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 5}, @@ -135,11 +131,11 @@ export import library "lib"; // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Pkg'}, -// CHECK:STDOUT: {kind: 'PackageImpl', text: 'impl'}, // CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'}, -// CHECK:STDOUT: {kind: 'ImportExport', text: 'export'}, +// CHECK:STDOUT: {kind: 'ExportModifier', text: 'export'}, // CHECK:STDOUT: {kind: 'LibraryName', text: '"lib"'}, // CHECK:STDOUT: {kind: 'LibrarySpecifier', text: 'library', subtree_size: 2}, // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 5}, diff --git a/toolchain/parse/testdata/packages/import/ordering.carbon b/toolchain/parse/testdata/packages/import/ordering.carbon index 35c71735f4e0..0ebf8762d8c6 100644 --- a/toolchain/parse/testdata/packages/import/ordering.carbon +++ b/toolchain/parse/testdata/packages/import/ordering.carbon @@ -11,13 +11,13 @@ import B; // --- after_library.carbon -library "A" api; +library "A"; import B; // --- after_package.carbon -package A api; +package A; import B; @@ -37,8 +37,7 @@ import B; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'LibraryIntroducer', text: 'library'}, // CHECK:STDOUT: {kind: 'LibraryName', text: '"A"'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'LibraryDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'LibraryDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'B'}, // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', subtree_size: 3}, @@ -49,8 +48,7 @@ import B; // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'A'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'B'}, // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', subtree_size: 3}, diff --git a/toolchain/parse/testdata/packages/library/basic.carbon b/toolchain/parse/testdata/packages/library/basic.carbon index 0bad672d64c1..62013ad79e02 100644 --- a/toolchain/parse/testdata/packages/library/basic.carbon +++ b/toolchain/parse/testdata/packages/library/basic.carbon @@ -6,27 +6,26 @@ // --- default.carbon -library default api; +library default; // --- named.carbon -library "Shapes" impl; +impl library "Shapes"; // CHECK:STDOUT: - filename: default.carbon // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'LibraryIntroducer', text: 'library'}, // CHECK:STDOUT: {kind: 'DefaultLibrary', text: 'default'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'LibraryDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'LibraryDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] // CHECK:STDOUT: - filename: named.carbon // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'LibraryIntroducer', text: 'library'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, // CHECK:STDOUT: {kind: 'LibraryName', text: '"Shapes"'}, -// CHECK:STDOUT: {kind: 'PackageImpl', text: 'impl'}, // CHECK:STDOUT: {kind: 'LibraryDecl', text: ';', subtree_size: 4}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] diff --git a/toolchain/parse/testdata/packages/library/fail_invalid_name.carbon b/toolchain/parse/testdata/packages/library/fail_invalid_name.carbon index 9b3394f4748e..7b419bccb563 100644 --- a/toolchain/parse/testdata/packages/library/fail_invalid_name.carbon +++ b/toolchain/parse/testdata/packages/library/fail_invalid_name.carbon @@ -7,18 +7,18 @@ // --- fail_identifier.carbon // CHECK:STDERR: fail_identifier.carbon:[[@LINE+4]]:9: ERROR: Expected `default` or a string literal to specify the library name. -// CHECK:STDERR: library Shapes api; +// CHECK:STDERR: library Shapes; // CHECK:STDERR: ^~~~~~ // CHECK:STDERR: -library Shapes api; +library Shapes; // --- fail_raw_identifier.carbon // CHECK:STDERR: fail_raw_identifier.carbon:[[@LINE+4]]:9: ERROR: Expected `default` or a string literal to specify the library name. -// CHECK:STDERR: library r#default api; +// CHECK:STDERR: library r#default; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: -library r#default api; +library r#default; // --- fail_missing.carbon @@ -30,17 +30,25 @@ library; // --- fail_missing_with_api.carbon -// CHECK:STDERR: fail_missing_with_api.carbon:[[@LINE+4]]:9: ERROR: Expected `default` or a string literal to specify the library name. -// CHECK:STDERR: library api; -// CHECK:STDERR: ^~~ +// CHECK:STDERR: fail_missing_with_api.carbon:[[@LINE+4]]:8: ERROR: Expected `default` or a string literal to specify the library name. +// CHECK:STDERR: library; +// CHECK:STDERR: ^ // CHECK:STDERR: -library api; +library; + +// --- fail_trailing_impl.carbon + +// CHECK:STDERR: fail_trailing_impl.carbon:[[@LINE+4]]:25: ERROR: `library` declarations must end with a `;`. +// CHECK:STDERR: library "trailing_impl" impl +// CHECK:STDERR: ^~~~ +// CHECK:STDERR: +library "trailing_impl" impl // --- fail_no_semi.carbon -library "NoSemi" api +library "NoSemi" -// CHECK:STDERR: fail_no_semi.carbon:[[@LINE+39]]:21: ERROR: `library` declarations must end with a `;`. +// CHECK:STDERR: fail_no_semi.carbon:[[@LINE+46]]:21: ERROR: `library` declarations must end with a `;`. // CHECK:STDERR: // CHECK:STDOUT: ] // CHECK:STDERR: ^ // CHECK:STDOUT: - filename: fail_identifier.carbon @@ -71,12 +79,19 @@ library "NoSemi" api // CHECK:STDOUT: {kind: 'LibraryDecl', text: ';', has_error: yes, subtree_size: 2}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] +// CHECK:STDOUT: - filename: fail_trailing_impl.carbon +// CHECK:STDOUT: parse_tree: [ +// CHECK:STDOUT: {kind: 'FileStart', text: ''}, +// CHECK:STDOUT: {kind: 'LibraryIntroducer', text: 'library'}, +// CHECK:STDOUT: {kind: 'LibraryName', text: '"trailing_impl"'}, +// CHECK:STDOUT: {kind: 'LibraryDecl', text: 'impl', has_error: yes, subtree_size: 3}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] // CHECK:STDOUT: - filename: fail_no_semi.carbon // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'LibraryIntroducer', text: 'library'}, // CHECK:STDOUT: {kind: 'LibraryName', text: '"NoSemi"'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'LibraryDecl', text: 'api', has_error: yes, subtree_size: 4}, +// CHECK:STDOUT: {kind: 'LibraryDecl', text: '"NoSemi"', has_error: yes, subtree_size: 3}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] diff --git a/toolchain/parse/testdata/packages/library/fail_too_late.carbon b/toolchain/parse/testdata/packages/library/fail_too_late.carbon index 0f2f2d0d2085..f25b0485d7ce 100644 --- a/toolchain/parse/testdata/packages/library/fail_too_late.carbon +++ b/toolchain/parse/testdata/packages/library/fail_too_late.carbon @@ -7,12 +7,12 @@ import Geometry; // CHECK:STDERR: fail_too_late.carbon:[[@LINE+6]]:1: ERROR: The `library` declaration must be the first non-comment line. -// CHECK:STDERR: library "Shapes" api; +// CHECK:STDERR: library "Shapes"; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: fail_too_late.carbon:[[@LINE-5]]:1: First non-comment line is here. // CHECK:STDERR: import Geometry; // CHECK:STDERR: ^~~~~~ -library "Shapes" api; +library "Shapes"; // CHECK:STDOUT: - filename: fail_too_late.carbon // CHECK:STDOUT: parse_tree: [ diff --git a/toolchain/parse/testdata/packages/package/api.carbon b/toolchain/parse/testdata/packages/package/api.carbon index e9f56ee35dbf..360c66c6bc09 100644 --- a/toolchain/parse/testdata/packages/package/api.carbon +++ b/toolchain/parse/testdata/packages/package/api.carbon @@ -4,14 +4,13 @@ // // AUTOUPDATE -package Geometry api; +package Geometry; // CHECK:STDOUT: - filename: api.carbon // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Geometry'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] diff --git a/toolchain/parse/testdata/packages/package/api_library.carbon b/toolchain/parse/testdata/packages/package/api_library.carbon index 4ec95c167240..ad20ec279329 100644 --- a/toolchain/parse/testdata/packages/package/api_library.carbon +++ b/toolchain/parse/testdata/packages/package/api_library.carbon @@ -4,7 +4,7 @@ // // AUTOUPDATE -package Geometry library "Shapes" api; +package Geometry library "Shapes"; // CHECK:STDOUT: - filename: api_library.carbon // CHECK:STDOUT: parse_tree: [ @@ -13,7 +13,6 @@ package Geometry library "Shapes" api; // CHECK:STDOUT: {kind: 'PackageName', text: 'Geometry'}, // CHECK:STDOUT: {kind: 'LibraryName', text: '"Shapes"'}, // CHECK:STDOUT: {kind: 'LibrarySpecifier', text: 'library', subtree_size: 2}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 5}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] diff --git a/toolchain/parse/testdata/packages/package/fail_after_decl.carbon b/toolchain/parse/testdata/packages/package/fail_after_decl.carbon index f4fcc268d83b..6169f62a5e88 100644 --- a/toolchain/parse/testdata/packages/package/fail_after_decl.carbon +++ b/toolchain/parse/testdata/packages/package/fail_after_decl.carbon @@ -7,12 +7,12 @@ fn A(); // CHECK:STDERR: fail_after_decl.carbon:[[@LINE+6]]:1: ERROR: The `package` declaration must be the first non-comment line. -// CHECK:STDERR: package B api; +// CHECK:STDERR: package B; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: fail_after_decl.carbon:[[@LINE-5]]:1: First non-comment line is here. // CHECK:STDERR: fn A(); // CHECK:STDERR: ^~ -package B api; +package B; // CHECK:STDOUT: - filename: fail_after_decl.carbon // CHECK:STDOUT: parse_tree: [ diff --git a/toolchain/parse/testdata/packages/package/fail_after_import.carbon b/toolchain/parse/testdata/packages/package/fail_after_import.carbon index 3423ac0ec753..f70f411a0fe4 100644 --- a/toolchain/parse/testdata/packages/package/fail_after_import.carbon +++ b/toolchain/parse/testdata/packages/package/fail_after_import.carbon @@ -7,12 +7,12 @@ import A; // CHECK:STDERR: fail_after_import.carbon:[[@LINE+6]]:1: ERROR: The `package` declaration must be the first non-comment line. -// CHECK:STDERR: package B api; +// CHECK:STDERR: package B; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: fail_after_import.carbon:[[@LINE-5]]:1: First non-comment line is here. // CHECK:STDERR: import A; // CHECK:STDERR: ^~~~~~ -package B api; +package B; // CHECK:STDOUT: - filename: fail_after_import.carbon // CHECK:STDOUT: parse_tree: [ diff --git a/toolchain/parse/testdata/packages/package/fail_after_package.carbon b/toolchain/parse/testdata/packages/package/fail_after_package.carbon index 44507608ae69..b77c939a7f8e 100644 --- a/toolchain/parse/testdata/packages/package/fail_after_package.carbon +++ b/toolchain/parse/testdata/packages/package/fail_after_package.carbon @@ -4,22 +4,21 @@ // // AUTOUPDATE -package A api; +package A; // CHECK:STDERR: fail_after_package.carbon:[[@LINE+6]]:1: ERROR: The `package` declaration must be the first non-comment line. -// CHECK:STDERR: package B api; +// CHECK:STDERR: package B; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: fail_after_package.carbon:[[@LINE-4]]:1: First non-comment line is here. -// CHECK:STDERR: package A api; +// CHECK:STDERR: package A; // CHECK:STDERR: ^~~~~~~ -package B api; +package B; // CHECK:STDOUT: - filename: fail_after_package.carbon // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'A'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageDecl', text: ';', has_error: yes, subtree_size: 2}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, diff --git a/toolchain/parse/testdata/packages/package/fail_extra_string.carbon b/toolchain/parse/testdata/packages/package/fail_extra_string.carbon index c750836d4cc5..6c3322c6871b 100644 --- a/toolchain/parse/testdata/packages/package/fail_extra_string.carbon +++ b/toolchain/parse/testdata/packages/package/fail_extra_string.carbon @@ -4,7 +4,7 @@ // // AUTOUPDATE -// CHECK:STDERR: fail_extra_string.carbon:[[@LINE+3]]:27: ERROR: Expected `api` or `impl`. +// CHECK:STDERR: fail_extra_string.carbon:[[@LINE+3]]:27: ERROR: `package` declarations must end with a `;`. // CHECK:STDERR: package Foo library "bar" "baz"; // CHECK:STDERR: ^~~~~ package Foo library "bar" "baz"; diff --git a/toolchain/parse/testdata/packages/package/fail_library_is_identifier.carbon b/toolchain/parse/testdata/packages/package/fail_library_is_identifier.carbon index 9b8f8fedaf19..7c1c818f29f2 100644 --- a/toolchain/parse/testdata/packages/package/fail_library_is_identifier.carbon +++ b/toolchain/parse/testdata/packages/package/fail_library_is_identifier.carbon @@ -5,9 +5,9 @@ // AUTOUPDATE // CHECK:STDERR: fail_library_is_identifier.carbon:[[@LINE+3]]:26: ERROR: Expected a string literal to specify the library name. -// CHECK:STDERR: package Geometry library Shapes api; +// CHECK:STDERR: package Geometry library Shapes; // CHECK:STDERR: ^~~~~~ -package Geometry library Shapes api; +package Geometry library Shapes; // CHECK:STDOUT: - filename: fail_library_is_identifier.carbon // CHECK:STDOUT: parse_tree: [ diff --git a/toolchain/parse/testdata/packages/package/fail_library_skips_name.carbon b/toolchain/parse/testdata/packages/package/fail_library_skips_name.carbon index 38de323726fb..8f39b7ba80da 100644 --- a/toolchain/parse/testdata/packages/package/fail_library_skips_name.carbon +++ b/toolchain/parse/testdata/packages/package/fail_library_skips_name.carbon @@ -5,9 +5,9 @@ // AUTOUPDATE // CHECK:STDERR: fail_library_skips_name.carbon:[[@LINE+3]]:9: ERROR: Expected identifier after `package`. -// CHECK:STDERR: package library "Shapes" api; +// CHECK:STDERR: package library "Shapes"; // CHECK:STDERR: ^~~~~~~ -package library "Shapes" api; +package library "Shapes"; // CHECK:STDOUT: - filename: fail_library_skips_name.carbon // CHECK:STDOUT: parse_tree: [ diff --git a/toolchain/parse/testdata/packages/package/fail_no_semi.carbon b/toolchain/parse/testdata/packages/package/fail_no_semi.carbon index 9b2f2737e91c..5654105d6df5 100644 --- a/toolchain/parse/testdata/packages/package/fail_no_semi.carbon +++ b/toolchain/parse/testdata/packages/package/fail_no_semi.carbon @@ -4,9 +4,9 @@ // // AUTOUPDATE -package Geometry api +package Geometry -// CHECK:STDERR: fail_no_semi.carbon:[[@LINE+11]]:21: ERROR: `package` declarations must end with a `;`. +// CHECK:STDERR: fail_no_semi.carbon:[[@LINE+10]]:21: ERROR: `package` declarations must end with a `;`. // CHECK:STDERR: // CHECK:STDOUT: ] // CHECK:STDERR: ^ // CHECK:STDOUT: - filename: fail_no_semi.carbon @@ -14,7 +14,6 @@ package Geometry api // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Geometry'}, -// CHECK:STDOUT: {kind: 'PackageApi', text: 'api'}, -// CHECK:STDOUT: {kind: 'PackageDecl', text: 'api', has_error: yes, subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: 'Geometry', has_error: yes, subtree_size: 3}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] diff --git a/toolchain/parse/testdata/packages/package/fail_omit_library_keyword.carbon b/toolchain/parse/testdata/packages/package/fail_omit_library_keyword.carbon index 344083f44e95..0458512ccf0a 100644 --- a/toolchain/parse/testdata/packages/package/fail_omit_library_keyword.carbon +++ b/toolchain/parse/testdata/packages/package/fail_omit_library_keyword.carbon @@ -5,9 +5,9 @@ // AUTOUPDATE // CHECK:STDERR: fail_omit_library_keyword.carbon:[[@LINE+3]]:18: ERROR: Missing `library` keyword. -// CHECK:STDERR: package Geometry "Shapes" api; +// CHECK:STDERR: package Geometry "Shapes"; // CHECK:STDERR: ^~~~~~~~ -package Geometry "Shapes" api; +package Geometry "Shapes"; // CHECK:STDOUT: - filename: fail_omit_library_keyword.carbon // CHECK:STDOUT: parse_tree: [ diff --git a/toolchain/parse/testdata/packages/package/fail_no_type.carbon b/toolchain/parse/testdata/packages/package/fail_trailing_impl.carbon similarity index 68% rename from toolchain/parse/testdata/packages/package/fail_no_type.carbon rename to toolchain/parse/testdata/packages/package/fail_trailing_impl.carbon index aac4c58aad78..e433aee17b2f 100644 --- a/toolchain/parse/testdata/packages/package/fail_no_type.carbon +++ b/toolchain/parse/testdata/packages/package/fail_trailing_impl.carbon @@ -4,12 +4,12 @@ // // AUTOUPDATE -// CHECK:STDERR: fail_no_type.carbon:[[@LINE+3]]:17: ERROR: Expected `api` or `impl`. -// CHECK:STDERR: package Geometry; -// CHECK:STDERR: ^ -package Geometry; +// CHECK:STDERR: fail_trailing_impl.carbon:[[@LINE+3]]:18: ERROR: `package` declarations must end with a `;`. +// CHECK:STDERR: package Geometry impl; +// CHECK:STDERR: ^~~~ +package Geometry impl; -// CHECK:STDOUT: - filename: fail_no_type.carbon +// CHECK:STDOUT: - filename: fail_trailing_impl.carbon // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, diff --git a/toolchain/parse/testdata/packages/package/impl.carbon b/toolchain/parse/testdata/packages/package/impl.carbon index 899c255ee9ff..d07f36cdcab9 100644 --- a/toolchain/parse/testdata/packages/package/impl.carbon +++ b/toolchain/parse/testdata/packages/package/impl.carbon @@ -4,14 +4,62 @@ // // AUTOUPDATE -package Geometry impl; +// --- impl.carbon + +impl package Geometry; + +// --- impl_disambiguate.carbon + +impl package DisambiguateImpl; + +impl i32 as Interface {} + +// --- impl_package_disambiguate.carbon + +impl package DisambiguateImplPackage; + +impl package.Name as package.Interface {} // CHECK:STDOUT: - filename: impl.carbon // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Geometry'}, -// CHECK:STDOUT: {kind: 'PackageImpl', text: 'impl'}, // CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] +// CHECK:STDOUT: - filename: impl_disambiguate.carbon +// CHECK:STDOUT: parse_tree: [ +// CHECK:STDOUT: {kind: 'FileStart', text: ''}, +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, +// CHECK:STDOUT: {kind: 'PackageName', text: 'DisambiguateImpl'}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'}, +// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'}, +// CHECK:STDOUT: {kind: 'TypeImplAs', text: 'as', subtree_size: 2}, +// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Interface'}, +// CHECK:STDOUT: {kind: 'ImplDefinitionStart', text: '{', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'ImplDefinition', text: '}', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] +// CHECK:STDOUT: - filename: impl_package_disambiguate.carbon +// CHECK:STDOUT: parse_tree: [ +// CHECK:STDOUT: {kind: 'FileStart', text: ''}, +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, +// CHECK:STDOUT: {kind: 'PackageName', text: 'DisambiguateImplPackage'}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'}, +// CHECK:STDOUT: {kind: 'PackageExpr', text: 'package'}, +// CHECK:STDOUT: {kind: 'IdentifierName', text: 'Name'}, +// CHECK:STDOUT: {kind: 'MemberAccessExpr', text: '.', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'TypeImplAs', text: 'as', subtree_size: 4}, +// CHECK:STDOUT: {kind: 'PackageExpr', text: 'package'}, +// CHECK:STDOUT: {kind: 'IdentifierName', text: 'Interface'}, +// CHECK:STDOUT: {kind: 'MemberAccessExpr', text: '.', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'ImplDefinitionStart', text: '{', subtree_size: 9}, +// CHECK:STDOUT: {kind: 'ImplDefinition', text: '}', subtree_size: 10}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] diff --git a/toolchain/parse/testdata/packages/package/impl_library.carbon b/toolchain/parse/testdata/packages/package/impl_library.carbon index 886b0395806f..d5bc2d6d0e8d 100644 --- a/toolchain/parse/testdata/packages/package/impl_library.carbon +++ b/toolchain/parse/testdata/packages/package/impl_library.carbon @@ -4,16 +4,16 @@ // // AUTOUPDATE -package Geometry library "Shapes" impl; +impl package Geometry library "Shapes"; // CHECK:STDOUT: - filename: impl_library.carbon // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, // CHECK:STDOUT: {kind: 'PackageName', text: 'Geometry'}, // CHECK:STDOUT: {kind: 'LibraryName', text: '"Shapes"'}, // CHECK:STDOUT: {kind: 'LibrarySpecifier', text: 'library', subtree_size: 2}, -// CHECK:STDOUT: {kind: 'PackageImpl', text: 'impl'}, // CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 6}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] diff --git a/toolchain/parse/testdata/packages/package/modifiers.carbon b/toolchain/parse/testdata/packages/package/modifiers.carbon new file mode 100644 index 000000000000..16f9dc64f34a --- /dev/null +++ b/toolchain/parse/testdata/packages/package/modifiers.carbon @@ -0,0 +1,20 @@ +// 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 + +// Diagnosed in check. +extend virtual base package Geometry; + +// CHECK:STDOUT: - filename: modifiers.carbon +// CHECK:STDOUT: parse_tree: [ +// CHECK:STDOUT: {kind: 'FileStart', text: ''}, +// CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'}, +// CHECK:STDOUT: {kind: 'ExtendModifier', text: 'extend'}, +// CHECK:STDOUT: {kind: 'VirtualModifier', text: 'virtual'}, +// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'}, +// CHECK:STDOUT: {kind: 'PackageName', text: 'Geometry'}, +// CHECK:STDOUT: {kind: 'PackageDecl', text: ';', subtree_size: 6}, +// CHECK:STDOUT: {kind: 'FileEnd', text: ''}, +// CHECK:STDOUT: ] diff --git a/toolchain/parse/tree.h b/toolchain/parse/tree.h index 1f300c78577e..6d47204e0d98 100644 --- a/toolchain/parse/tree.h +++ b/toolchain/parse/tree.h @@ -100,7 +100,7 @@ class Tree : public Printable { // The file's packaging. struct PackagingDecl { PackagingNames names; - ApiOrImpl api_or_impl; + bool is_impl; }; // Wires up the reference to the tokenized buffer. The `Parse` function should diff --git a/toolchain/parse/typed_nodes.h b/toolchain/parse/typed_nodes.h index 3d20fdfdd853..4b1d7e3dba65 100644 --- a/toolchain/parse/typed_nodes.h +++ b/toolchain/parse/typed_nodes.h @@ -155,8 +155,6 @@ using LibraryName = LeafNode; using DefaultLibrary = LeafNode; using PackageIntroducer = LeafNode; -using PackageApi = LeafNode; -using PackageImpl = LeafNode; // `library` in `package` or `import`. struct LibrarySpecifier { @@ -171,19 +169,18 @@ struct PackageDecl { static constexpr auto Kind = NodeKind::PackageDecl.Define(NodeCategory::Decl); PackageIntroducerId introducer; + llvm::SmallVector modifiers; std::optional name; std::optional library; - NodeIdOneOf api_or_impl; }; // `import TheirPackage library "TheirLibrary";` using ImportIntroducer = LeafNode; -using ImportExport = LeafNode; struct ImportDecl { static constexpr auto Kind = NodeKind::ImportDecl.Define(NodeCategory::Decl); ImportIntroducerId introducer; - std::optional export_modifier; + llvm::SmallVector modifiers; std::optional name; std::optional library; }; @@ -194,8 +191,8 @@ struct LibraryDecl { static constexpr auto Kind = NodeKind::LibraryDecl.Define(NodeCategory::Decl); LibraryIntroducerId introducer; + llvm::SmallVector modifiers; NodeIdOneOf library_name; - NodeIdOneOf api_or_impl; }; // `export` as a declaration. diff --git a/toolchain/parse/typed_nodes_test.cpp b/toolchain/parse/typed_nodes_test.cpp index a42ac0bd13f5..1252b73f0a6f 100644 --- a/toolchain/parse/typed_nodes_test.cpp +++ b/toolchain/parse/typed_nodes_test.cpp @@ -138,7 +138,7 @@ TEST_F(TypedNodeTest, For) { TEST_F(TypedNodeTest, VerifyExtractTraceLibrary) { auto* tree = &GetTree(R"carbon( - library default impl; + impl library default; )carbon"); auto file = tree->ExtractFile(); @@ -150,8 +150,11 @@ TEST_F(TypedNodeTest, VerifyExtractTraceLibrary) { // Use Regex matching to avoid hard-coding the result of `typeinfo(T).name()`. EXPECT_THAT(err.message(), testing::MatchesRegex( R"Trace(Aggregate [^:]*: begin -NodeIdOneOf PackageApi or PackageImpl: PackageImpl consumed NodeIdOneOf LibraryName or DefaultLibrary: DefaultLibrary consumed +Vector: begin +NodeIdInCategory Modifier: kind ImplModifier consumed +NodeIdInCategory Modifier error: kind LibraryIntroducer doesn't match +Vector: end NodeIdForKind: LibraryIntroducer consumed Aggregate [^:]*: success )Trace"));