We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When running some code making use of generics and interfaces, explorer fails with a stack trace ending with
CHECK failure at explorer/interpreter/interpreter.cpp:281: v->kind() == Value::Kind::LValue
On commit 5709014, add a file hello.carbon with the following content:
hello.carbon
package Hello api; class Rng { fn Create(seed: i32) -> Self { return {.seed = seed}; } fn NextInt[addr me: Self*]() -> i32 { let a: i32 = (8121*(*me).seed + 28411) & 32767; (*me).seed = a; return a; } var seed: i32; } interface Roller { fn This[me: Self]() -> Self; fn RollNumber[addr me: Self*]() -> i32; } class DiceRoller { fn Create(seed: i32, sides: i32) -> Self { return {.rng = Rng.Create(seed), .sides = sides}; } impl DiceRoller as Roller { fn This[me: Self]() -> Self { return me; } fn RollNumber[addr me: Self*]() -> i32 { return (*me).rng.NextInt()%((*me).sides); } } var rng: Rng; var sides: i32; } class SerialRoller { fn Create(total: i32) -> Self { return {.current = 0, .total = total}; } impl SerialRoller as Roller { fn This[me: Self]() -> Self { return me; } fn RollNumber[addr me: Self*]() -> i32 { let ans: i32 = (*me).current; (*me).current = (*me).current + 1; if ((*me).current == (*me).total) { (*me).current = 0; } return ans; } } var current: i32; var total: i32; } interface Mapper { fn This[me: Self]() -> Self; fn MapString[me: Self](i: i32) -> String; } class NameMapper { fn Create(arr: [String; 6]) -> Self { return {.arr = arr}; } impl NameMapper as Mapper { fn This[me: Self]() -> Self { return me; } fn MapString[me: Self](i: i32) -> String { return me.arr[i]; } } var arr: [String; 6]; } class ParityMapper { fn Create(param: i32) -> Self { return {.param = param}; } impl ParityMapper as Mapper { fn This[me: Self]() -> Self { return me; } fn MapString[me: Self](i: i32) -> String { let x: i32 = me.param*me.param + i; if (x % 2 == 0) { return "even"; } else { return "odd"; } } } var param: i32; } class StringRoller(R:! Roller, M:! Mapper) { fn Create(roller: R, mapper: M) -> Self { return {.roller = roller.This(), .mapper = mapper.This()}; } fn RollString[me: Self]() -> String { return me.mapper.MapString(me.roller.RollNumber()); } var roller: R; var mapper: M; } fn Main() -> i32 { var diceRoller: DiceRoller = DiceRoller.Create(314, 6); var nameMapper: NameMapper = NameMapper.Create( ("one", "two", "three", "four", "five", "six") ); var nameRoller: StringRoller(DiceRoller, NameMapper) = StringRoller(DiceRoller, NameMapper).Create(diceRoller, nameMapper); var i: i32 = 0; while (i < 30) { Print(nameRoller.RollString()); i = i + 1; } var parityMapper: ParityMapper = ParityMapper.Create(0); var serialRoller: SerialRoller = SerialRoller.Create(5); return 0; }
and run it with bazel run //explorer -- hello.carbon
bazel run //explorer -- hello.carbon
I expected it to print an output or report a failed compilation.
The following error is displayed:
Stack trace: #0 0x0000556883bf506b backtrace (/root/.cache/bazel/_bazel_root/924e82cb53c08cf8a432318b2f0f4261/execroot/carbon/bazel-out/k8-fastbuild/bin/explorer/explorer+0x52306b) #1 0x0000556883fda54d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:13 #2 0x0000556883c83451 Carbon::Internal::ExitingStream::ExitingStream() /proc/self/cwd/./common/check_internal.h:35:3 #3 0x0000556883dd247a Carbon::PatternMatch(Carbon::Value const*, Carbon::Value const*, Carbon::SourceLocation, std::__1::optional<Carbon::RuntimeScope*>, std::__1::map<Carbon::GenericBinding const*, Carbon::Value const*, std::__1::less<Carbon::GenericBinding const*>, std::__1::allocator<std::__1::pair<Carbon::GenericBinding const* const, Carbon::Value const*>>>&, std::__1::optional<llvm::raw_ostream*>, Carbon::Arena*) /proc/self/cwd/explorer/interpreter/interpreter.cpp:281:7 #4 0x0000556883de937a Carbon::Interpreter::CallFunction(Carbon::CallExpression const&, Carbon::Value const*, Carbon::Value const*, std::__1::map<Carbon::ImplBinding const*, Carbon::Value const*, std::__1::less<Carbon::ImplBinding const*>, std::__1::allocator<std::__1::pair<Carbon::ImplBinding const* const, Carbon::Value const*>>>&&) /proc/self/cwd/explorer/interpreter/interpreter.cpp:903:7 #5 0x0000556883df17c9 Carbon::Interpreter::StepExp() /proc/self/cwd/explorer/interpreter/interpreter.cpp:1246:7 #6 0x0000556883de0028 index /usr/lib/llvm-15/bin/../include/c++/v1/variant:797:12 #7 0x0000556883de0028 index /usr/lib/llvm-15/bin/../include/c++/v1/variant:1450:59 #8 0x0000556883de0028 __holds_alternative<1UL, Carbon::Error, Carbon::Success> /usr/lib/llvm-15/bin/../include/c++/v1/variant:1476:14 #9 0x0000556883de0028 holds_alternative<Carbon::Success, Carbon::Error, Carbon::Success> /usr/lib/llvm-15/bin/../include/c++/v1/variant:1482:10 #10 0x0000556883de0028 ok /proc/self/cwd/./common/error.h:80:36 #11 0x0000556883de0028 Carbon::Interpreter::Step() /proc/self/cwd/explorer/interpreter/interpreter.cpp:2055:7 #12 0x0000556883e12a4f index /usr/lib/llvm-15/bin/../include/c++/v1/variant:797:12 #13 0x0000556883e12a4f index /usr/lib/llvm-15/bin/../include/c++/v1/variant:1450:59 #14 0x0000556883e12a4f __holds_alternative<1UL, Carbon::Error, Carbon::Success> /usr/lib/llvm-15/bin/../include/c++/v1/variant:1476:14 #15 0x0000556883e12a4f holds_alternative<Carbon::Success, Carbon::Error, Carbon::Success> /usr/lib/llvm-15/bin/../include/c++/v1/variant:1482:10 #16 0x0000556883e12a4f ok /proc/self/cwd/./common/error.h:80:36 #17 0x0000556883e12a4f Carbon::Interpreter::RunAllSteps(std::__1::unique_ptr<Carbon::Action, std::__1::default_delete<Carbon::Action>>) /proc/self/cwd/explorer/interpreter/interpreter.cpp:2087:5 #18 0x0000556883e1398a reset /usr/lib/llvm-15/bin/../include/c++/v1/__memory/unique_ptr.h:302:28 #19 0x0000556883e1398a ~unique_ptr /usr/lib/llvm-15/bin/../include/c++/v1/__memory/unique_ptr.h:259:19 #20 0x0000556883e1398a Carbon::InterpProgram(Carbon::AST const&, Carbon::Arena*, std::__1::optional<llvm::raw_ostream*>) /proc/self/cwd/explorer/interpreter/interpreter.cpp:2112:3 #21 0x0000556883c86dd2 Carbon::ExecProgram(Carbon::Arena*, Carbon::AST, std::__1::optional<llvm::raw_ostream*>) /proc/self/cwd/explorer/interpreter/exec_program.cpp:67:3 #22 0x0000556883c7b503 Carbon::ExplorerMain(int, char**, void*, llvm::StringRef) /proc/self/cwd/explorer/main.cpp:108:34 #23 0x0000556883c79af7 main /proc/self/cwd/explorer/main_bin.cpp:12:3 #24 0x00007f7cd45b0d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #25 0x00007f7cd45b0e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #26 0x0000556883bb7885 _start (/root/.cache/bazel/_bazel_root/924e82cb53c08cf8a432318b2f0f4261/execroot/carbon/bazel-out/k8-fastbuild/bin/explorer/explorer+0x4e5885) CHECK failure at explorer/interpreter/interpreter.cpp:281: v->kind() == Value::Kind::LValue
No response
The text was updated successfully, but these errors were encountered:
I believe the issue here is that addr me: Self* does not currently work for interface methods, only for class methods.
addr me: Self*
interface
class
Sorry, something went wrong.
Confirmed this is a duplicate of #2223.
No branches or pull requests
Description of the bug:
When running some code making use of generics and interfaces, explorer fails with a stack trace ending with
What did you do, or what's a simple way to reproduce the bug?
On commit 5709014, add a file
hello.carbon
with the following content:and run it with
bazel run //explorer -- hello.carbon
What did you expect to happen?
I expected it to print an output or report a failed compilation.
What actually happened?
The following error is displayed:
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: