Files
carbon-lang/toolchain/check/testdata/packages/fail_import_repeat.carbon
T
Jon Ross-Perkins 032c0e017b Start adding lazy import references to name lookup. (#3475)
Adds a `LazyImportRef` instruction. Versus `CrossRef`, this is intended
to represent an instruction which cannot be used directly, and must be
replaced when it comes up due to name lookup. The intent is to use this
to avoid recursive loading of imported IR instructions.

Note, under this model, when `ResolveIfLazyImportRef` is called, it
essentially needs to load both inst and type information to a sufficient
point where any further attempts would hit name lookup again. That will
probably be complex, and the current implementation is just touching the
surface of the issue. I was heading down this route because it would
mean we have a limited number of points that need to consider whether
they're going to talk about a `LazyImportRef`.

I'm considering whether `CrossRef` should be dropped in favor of more
specific `Builtin` special-casing, due to the divergence of desired
behaviors. This could mean dropping the `builtins` IR since it's not
looking useful right now.

Modify `NameScope` to track whether the scope is associated with a load
error. This is to handle cases where one or more imports failed, so we
do not want to issue warnings for related scopes.

The 0-size on `ValueStore` comes up due to the changes to `NameScope`,
which make it too large for the default handling. After discussion with
zygoloid, the thought was we might want to try reserving a roughly
correct value based on parse node counts, but the stack default wasn't
buying much.

Fixes a bug where the implicit import used the package name instead of
the invalid identifier.
2023-12-12 00:13:25 +00:00

93 lines
2.6 KiB
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// --- api.carbon
package Api api;
// --- api_lib.carbon
package Api library "lib" api;
// --- main_lib.carbon
library "lib" api;
// --- import.carbon
import Api;
// CHECK:STDERR: import.carbon:[[@LINE+6]]:1: ERROR: Library imported more than once.
// CHECK:STDERR: import Api;
// CHECK:STDERR: ^~~~~~
// CHECK:STDERR: import.carbon:[[@LINE-4]]:1: First import here.
// CHECK:STDERR: import Api;
// CHECK:STDERR: ^~~~~~
import Api;
import Api library "lib";
// CHECK:STDERR: import.carbon:[[@LINE+6]]:1: ERROR: Library imported more than once.
// CHECK:STDERR: import Api library "lib";
// CHECK:STDERR: ^~~~~~
// CHECK:STDERR: import.carbon:[[@LINE-4]]:1: First import here.
// CHECK:STDERR: import Api library "lib";
// CHECK:STDERR: ^~~~~~
import Api library "lib";
import library "lib";
// CHECK:STDERR: import.carbon:[[@LINE+6]]:1: ERROR: Library imported more than once.
// CHECK:STDERR: import library "lib";
// CHECK:STDERR: ^~~~~~
// CHECK:STDERR: import.carbon:[[@LINE-4]]:1: First import here.
// CHECK:STDERR: import library "lib";
// CHECK:STDERR: ^~~~~~
import library "lib";
// --- default_import.carbon
package Api library "not_default" api;
import library default;
// CHECK:STDERR: default_import.carbon:[[@LINE+6]]:1: ERROR: Library imported more than once.
// CHECK:STDERR: import library default;
// CHECK:STDERR: ^~~~~~
// CHECK:STDERR: default_import.carbon:[[@LINE-4]]:1: First import here.
// CHECK:STDERR: import library default;
// CHECK:STDERR: ^~~~~~
import library default;
// CHECK:STDOUT: --- api.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- api_lib.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- main_lib.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- import.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace {}
// CHECK:STDOUT: %import: <namespace> = import ir2, ir3
// CHECK:STDOUT: %Api: <namespace> = bind_name Api, %import
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- default_import.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace {}
// CHECK:STDOUT: }
// CHECK:STDOUT: