carbon-language / carbon-lang

Carbon Language's main repository: documents, design, implementation, and related tools. (NOTE: Carbon Language is experimental; see README)
https://github.com/carbon-language/carbon-lang/blob/trunk/README.md
Other
32.31k stars 1.48k forks source link

Toolchain crash on import of impl of undefined interface #4080

Open geoffromer opened 5 days ago

geoffromer commented 5 days ago

Description of the bug:

The toolchain crashes when importing an API file containing an undefined interface and an impl of that interface. The import in question can be the implicit import of an API file from its impl file.

What did you do, or what's a simple way to reproduce the bug?

The following file_test input reproduces the issue:

// --- a.carbon
library "a";
interface A;
impl () as A;

// --- a.impl.carbon
impl library "a";

I'm not sure whether this kind of thing should be valid, but I didn't expect it to crash.

What did you expect to happen?

I'm not sure whether this kind of thing should be valid, but I didn't expect it to crash.

What actually happened?

The compiler crashed.

Any other information, logs, or outputs that you want to share?

This may be related to #4071, but the crash logs are different. Here's the crash log for this one:

[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from ToolchainFileTest
[ RUN      ] ToolchainFileTest.toolchain/check/testdata/impl/temp.carbon

To test this file alone, run:
  bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/temp.carbon

Please report issues to https://github.com/carbon-language/carbon-lang/issues and include the crash backtrace.
Stack dump:
0.      Program arguments: /usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test --test_targets_file=toolch
ain/testing/file_test.tests.txt --file_tests=toolchain/check/testdata/impl/temp.carbon
1.      bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/temp.carbon
2.      Program arguments: compile --phase=check --dump-sem-ir --exclude-dump-file-prefix=/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfil
es/_main/toolchain/install/prefix_root/lib/carbon/../../lib/carbon/core a.carbon a.impl.carbon
3.      NodeStack:
inst_block_stack_:
        0.      block<invalid>  {inst+0, inst+1, inst+2}
param_and_arg_refs_stack:
args_type_info_stack_:
 #0 0x000055f7c9f3ae9d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolc
hain/testing/file_test+0x71fae9d)
 #1 0x000055f7c9f3b3db PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #2 0x000055f7c9f38ab6 llvm::sys::RunSignalHandlers() (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_tes
t+0x71f8ab6)
 #3 0x000055f7c9f3bda5 SignalHandler(int) Signals.cpp:0:0
 #4 0x00007fb846452510 (/lib/x86_64-linux-gnu/libc.so.6+0x3c510)
 #5 0x00007fb8464a016c __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
 #6 0x00007fb846452472 raise ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007fb84643c4b2 abort ./stdlib/./stdlib/abort.c:81:7
 #8 0x000055f7c9a18b75 (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x6cd8b75)
 #9 0x000055f7c5c22c15 (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2ee2c15)
#10 0x000055f7c8a02428 Carbon::SemIR::ConstantValueStore::Get(Carbon::SemIR::InstId) const (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runf
iles/_main/toolchain/testing/file_test+0x5cc2428)
#11 0x000055f7c8ae993d Carbon::Check::ImportRefResolver::GetLocalConstantInstId(Carbon::SemIR::InstId) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/fi
le_test.runfiles/_main/toolchain/testing/file_test+0x5da993d)
#12 0x000055f7c8ae723d Carbon::Check::ImportRefResolver::TryResolveTypedInst(Carbon::SemIR::InterfaceDecl, Carbon::SemIR::ConstantId) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fas
tbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x5da723d)
#13 0x000055f7c8ae33f4 Carbon::Check::ImportRefResolver::TryResolveInst(Carbon::SemIR::InstId, Carbon::SemIR::ConstantId) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/t
oolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x5da33f4)
#14 0x000055f7c8adfe7e Carbon::Check::ImportRefResolver::Resolve(Carbon::SemIR::InstId) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfile
s/_main/toolchain/testing/file_test+0x5d9fe7e)
#15 0x000055f7c8adfbb0 Carbon::Check::ImportRefResolver::ResolveType(Carbon::SemIR::TypeId) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.run
files/_main/toolchain/testing/file_test+0x5d9fbb0)
#16 0x000055f7c8ae090d Carbon::Check::ImportImpl(Carbon::Check::Context&, Carbon::SemIR::ImportIRId, Carbon::SemIR::File const&, Carbon::SemIR::ImplId) import_ref.cpp:0:0
#17 0x000055f7c8ae0661 Carbon::Check::ImportImpls(Carbon::Check::Context&) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolc
hain/testing/file_test+0x5da0661)
#18 0x000055f7c89b577c Carbon::Check::CheckParseTree(llvm::MutableArrayRef<Carbon::Parse::NodeLocConverter*>, Carbon::Check::(anonymous namespace)::UnitInfo&, int, llvm::raw_ostream*) check.cpp:0:0
#19 0x000055f7c89b33ad Carbon::Check::CheckParseTrees(llvm::MutableArrayRef<Carbon::Check::Unit>, bool, llvm::raw_ostream*) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin
/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x5c733ad)
#20 0x000055f7c5e439e5 Carbon::Driver::Compile(Carbon::Driver::CompileOptions const&, Carbon::Driver::CodegenOptions const&) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bi
n/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x31039e5)
#21 0x000055f7c5e42fb6 Carbon::Driver::RunCommand(llvm::ArrayRef<llvm::StringRef>) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_ma
in/toolchain/testing/file_test+0x3102fb6)
#22 0x000055f7c5c21a10 Carbon::Testing::(anonymous namespace)::ToolchainFileTest::Run(llvm::SmallVector<llvm::StringRef, 3u> const&, llvm::vfs::InMemoryFileSystem&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream&) file_test.cpp:0:0
#23 0x000055f7c5c48ca4 Carbon::Testing::FileTestBase::ProcessTestFileAndRun(Carbon::Testing::FileTestBase::TestContext&) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/to
olchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2f08ca4)
#24 0x000055f7c5c46b2b Carbon::Testing::FileTestBase::TestBody() (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testi
ng/file_test+0x2f06b2b)
#25 0x000055f7c5ce631b void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/ex
ecroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2fa631b)
#26 0x000055f7c5ca75ca void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execr
oot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2f675ca)
#27 0x000055f7c5ca7513 testing::Test::Run() (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2f6751
3)
#28 0x000055f7c5ca8502 testing::TestInfo::Run() (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2f
68502)
#29 0x000055f7c5ca976c testing::TestSuite::Run() (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2
f6976c)
#30 0x000055f7c5cb98bf testing::internal::UnitTestImpl::RunAllTests() (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/
testing/file_test+0x2f798bf)
#31 0x000055f7c5ceaebb bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8
ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2faaebb)
#32 0x000055f7c5cb923a bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddb
dbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2f7923a)
#33 0x000055f7c5cb9063 testing::UnitTest::Run() (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2f
79063)
#34 0x000055f7c5c62c31 RUN_ALL_TESTS() (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2f22c31)
#35 0x000055f7c5c51be8 Carbon::Testing::Main(int, char**) file_test_base.cpp:0:0
#36 0x000055f7c5c50fc2 main (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2f10fc2)
#37 0x00007fb84643d6ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#38 0x00007fb84643d785 call_init ./csu/../csu/libc-start.c:128:20
#39 0x00007fb84643d785 __libc_start_main ./csu/../csu/libc-start.c:347:5
#40 0x000055f7c5c1f721 _start (/usr/local/google/home/gromer/.cache/bazel/_bazel_gromer/6b556be8ddbdbba287a2e1ef86f733d5/sandbox/linux-sandbox/1373/execroot/_main/bazel-out/k8-fastbuild/bin/toolchain/testing/file_test.runfiles/_main/toolchain/testing/file_test+0x2edf721)
CHECK failure at ./toolchain/sem_ir/constant.h:24: inst_id.index >= 0