解析器崩溃,附加了错误的最小(ish)再现。
重现步骤
crash.mojo:
from memory.unsafe import Pointer
struct Config:
var a: Int
fn main() raises:
let fd = open("nevermind", "r")
let data = fd.read()
fd.close()
var pc = Pointer[Config]
pc.address = data._buffer.data.address_of
解析器在尝试编译/运行文件时崩溃。
mojo crash.mojo
Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h, line 572.
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: mojo crash.mojo
1. Crash resolving decl body at loc("/path_to_file/crash.mojo":6:1)
>> fn main() raises:
^................
>> let fd = open("nevermind", "r")
>> let data = fd.read()
>> fd.close()
>> var pc = Pointer[Config]
2. Crash parsing statement at loc("/path_to_file/crash.mojo":11:5)
>> pc.address = data._buffer.data.address_of
^........................................<
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 mojo 0x0000000102c4afc0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 mojo 0x0000000102c49120 llvm::sys::RunSignalHandlers() + 112
2 mojo 0x0000000102c4b65c SignalHandler(int) + 344
3 libsystem_platform.dylib 0x000000019fc0f2a4 _sigtramp + 56
4 libsystem_pthread.dylib 0x000000019fbe0cec pthread_kill + 288
5 libsystem_c.dylib 0x000000019fb1a2c8 abort + 180
6 libsystem_c.dylib 0x000000019fb19620 err + 0
7 mojo 0x00000001055b43d0 M::KGEN::LIT::RefStructGEROp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::Value, M::KGEN::LIT::StructFieldOp) (.cold.4) + 0
8 mojo 0x0000000103f74828 M::KGEN::LIT::RefStructGEROp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::Type, mlir::StringAttr, mlir::Value) + 0
9 mojo 0x0000000102f8777c M::KGEN::LIT::RefStructGEROp mlir::OpBuilder::create<M::KGEN::LIT::RefStructGEROp, M::KGEN::LIT::XLValue&, M::KGEN::LIT::StructFieldOp&>(mlir::Location, M::KGEN::LIT::XLValue&, M::KGEN::LIT::StructFieldOp&) + 136
10 mojo 0x0000000102f87118 M::KGEN::LIT::AttributeRefNode::emitStoredFieldRef(M::KGEN::LIT::ASTExprAnd<M::KGEN::LIT::CValue>, M::KGEN::LIT::StructFieldOp, M::KGEN::LIT::ExprNode const*, M::KGEN::LIT::ValueDest&, M::KGEN::LIT::ExprEmitter&) + 368
11 mojo 0x0000000102f88c40 M::KGEN::LIT::AttributeRefNode::emitIR(M::KGEN::LIT::ValueDest&, M::KGEN::LIT::ExprEmitter&) const + 4124
12 mojo 0x0000000102f74450 M::KGEN::LIT::ValueDest::resolveImpliedType(llvm::SMLoc, mlir::Type, M::KGEN::LIT::ExprEmitter&) + 488
13 mojo 0x0000000102f7875c M::KGEN::LIT::ExprEmitter::emitResult(M::KGEN::LIT::AnyValue, M::KGEN::LIT::ExprNode const*, M::KGEN::LIT::ValueDest&) + 1540
14 mojo 0x0000000102f768d4 M::KGEN::LIT::ExprEmitter::emitCResult(M::KGEN::LIT::CValue, M::KGEN::LIT::ExprNode const*, M::KGEN::LIT::ValueDest&) + 188
15 mojo 0x0000000102f41128 M::KGEN::LIT::OverloadSet::emitAsCValue(M::KGEN::LIT::ExprEmitter&, M::KGEN::LIT::ValueDest&) + 708
16 mojo 0x0000000102f785b4 M::KGEN::LIT::ExprEmitter::emitResult(M::KGEN::LIT::AnyValue, M::KGEN::LIT::ExprNode const*, M::KGEN::LIT::ValueDest&) + 1116
17 mojo 0x0000000102f888e8 M::KGEN::LIT::AttributeRefNode::emitIR(M::KGEN::LIT::ValueDest&, M::KGEN::LIT::ExprEmitter&) const + 3268
18 mojo 0x0000000102f90a94 M::KGEN::LIT::BinOpNode::emitAssign(M::KGEN::LIT::ValueDest&, M::KGEN::LIT::ExprEmitter&) const + 104
19 mojo 0x0000000102f7df78 M::KGEN::LIT::ExprEmitter::emitExprCValue(M::KGEN::LIT::ExprNode const*, M::KGEN::LIT::ExprContext) + 104
20 mojo 0x0000000102faf9b4 (anonymous namespace)::StmtParser::parseSuite(long)::$_6::operator()(bool, unsigned long) const + 13204
21 mojo 0x0000000102fac4c4 (anonymous namespace)::StmtParser::parseSuite(long) + 84
22 mojo 0x0000000102fac394 M::KGEN::LIT::ParserBase::parseSuite(M::KGEN::LIT::ASTDecl&) + 60
23 mojo 0x0000000102f5cd28 M::KGEN::LIT::DeclResolver::resolveBody(M::KGEN::LIT::FuncOp, M::KGEN::LIT::Lexer&, M::KGEN::LIT::ASTDecl&) + 1508
24 mojo 0x0000000102f55a44 M::KGEN::LIT::DeclResolver::resolve(M::KGEN::LIT::ASTDecl&, M::KGEN::LIT::DeclResolvedness, llvm::SMLoc) + 1552
25 mojo 0x0000000102f543a4 M::KGEN::LIT::DeclResolver::resolveAllReferencedFrom(M::KGEN::LIT::ASTDecl&) + 284
26 mojo 0x0000000102f6fb20 importMojoImpl(llvm::StringRef, llvm::SourceMgr&, M::KGEN::LIT::SharedState&, mlir::TimingScope&, llvm::SmallVectorImpl<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>*, llvm::function_ref<M::KGEN::LIT::ASTDecl& (mlir::ModuleOp)>) + 296
27 mojo 0x0000000102f70350 M::KGEN::LIT::importMojoFile(llvm::SourceMgr&, M::KGEN::LIT::ParserConfig&, mlir::TimingScope&, llvm::SmallVectorImpl<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>*) + 204
28 mojo 0x0000000102b9496c M::invokeMojoParser(M::State const&, llvm::opt::InputArgList const&, M::KGEN::CompilationOptions&, mlir::MLIRContext*, M::LLCL::Runtime&, llvm::opt::OptSpecifier, llvm::opt::OptSpecifier, llvm::opt::OptSpecifier, llvm::opt::OptSpecifier, llvm::function_ref<mlir::OwningOpRef<mlir::ModuleOp> (M::KGEN::LIT::ParserConfig&, mlir::TimingScope&)>) + 392
29 mojo 0x0000000102ba4884 run(M::State const&) + 1608
30 mojo 0x0000000102b8ee78 main + 1672
31 dyld 0x000000019f8b7e50 start + 2544
[69986:4532748:20231115,165108.948284:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)
[1] 69984 abort mojo crash.mojo