modular icon indicating copy to clipboard operation
modular copied to clipboard

[BUG] Type checking crash with `Self`-typed parameters in trait requirements

Open Mogball opened this issue 8 months ago • 1 comments

Bug description

mojo /tmp/broken.mojo
Please submit a bug report to https://github.com/modular/modular/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0.	Program arguments: mojo /tmp/broken.mojo
[2864286:2864287:20250509,194816.343007:ERROR directory_reader_posix.cc:42] opendir /root/code/onegpu/mojo/.magic/envs/default/share/max/crashdb/attachments/b5cff984-c325-4057-9359-0ad4adfcaf4c: No such file or directory (2)
[2864286:2864287:20250509,194816.595549:ERROR http_transport_libcurl.cc:483] HTTP status 503
 #0 0x000055b79609964b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) Signals.cpp:0:0
 #1 0x000055b7960974b9 llvm::sys::RunSignalHandlers() Signals.cpp:0:0
 #2 0x000055b796099cba SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x000077e8e2833330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #4 0x000055b792d5fbb0 (anonymous namespace)::SingletonTypeHelper::lookupStructSingletonFields(mlir::SymbolRefAttr) LowerLIT.cpp:0:0
 #5 0x000055b792d5f89b (anonymous namespace)::SingletonTypeHelper::isSingletonType(mlir::Type) LowerLIT.cpp:0:0
 #6 0x000055b792d5cf73 removeSingletonParamDecls((anonymous namespace)::SingletonTypeHelper&, llvm::SmallVectorImpl<M::KGEN::ParamDeclAttr>&) LowerLIT.cpp:0:0
 #7 0x000055b792d5c6de (anonymous namespace)::LITLowerer::lowerLITFunc(M::KGEN::LIT::FnOp, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, false, false, void, false, void>, false, false>, llvm::Twine const&, llvm::ArrayRef<M::KGEN::ParamDeclAttr>, llvm::ArrayRef<bool>) LowerLIT.cpp:0:0
 #8 0x000055b792d5a5b5 (anonymous namespace)::LITLowerer::lowerModuleDecl(mlir::Block*, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, false, false, void, false, void>, false, false>, llvm::Twine const&) LowerLIT.cpp:0:0
 #9 0x000055b792d5ab4b (anonymous namespace)::LITLowerer::lowerModuleDecl(mlir::Block*, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, false, false, void, false, void>, false, false>, llvm::Twine const&) LowerLIT.cpp:0:0
#10 0x000055b792d587c0 (anonymous namespace)::LowerLITPass::runOnOperation() LowerLIT.cpp:0:0
#11 0x000055b793900a0b mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) Pass.cpp:0:0
#12 0x000055b793903640 mlir::PassManager::run(mlir::Operation*) Pass.cpp:0:0
#13 0x000055b79319606d void llvm::detail::UniqueFunctionBase<void, M::AsyncRT::AnyAsyncValueRef&&>::CallImpl<M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0::operator()(mlir::Operation*, M::RCRef<M::WriteableBuffer>, M::AsyncRT::AnyAsyncValueRef) const::'lambda'(M::AsyncRT::AnyAsyncValueRef&&)>(void*, M::AsyncRT::AnyAsyncValueRef&) CachedTransform.cpp:0:0
#14 0x000055b792c5aec7 void M::AsyncRT::AnyAsyncValueRef::andThen<false>(llvm::unique_function<void (M::AsyncRT::AnyAsyncValueRef&&)>&&) && ObjectCompiler.cpp:0:0
#15 0x000055b793195c67 M::AsyncRT::AnyAsyncValueRef llvm::detail::UniqueFunctionBase<M::AsyncRT::AnyAsyncValueRef, M::RCRef<M::WriteableBuffer>, M::AsyncRT::AnyAsyncValueRef>::CallImpl<M::AsyncRT::AnyAsyncValueRef M::Cache::cachedTransform<M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_1>(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, M::RCRef<M::WriteableBuffer>, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0&&, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_1&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*)::'lambda'(M::RCRef<M::WriteableBuffer>, M::AsyncRT::AnyAsyncValueRef)>(void*, M::RCRef<M::WriteableBuffer>&, M::AsyncRT::AnyAsyncValueRef&) CachedTransform.cpp:0:0
#16 0x000055b793195768 void llvm::detail::UniqueFunctionBase<void, M::AsyncRT::AsyncValueRef<std::optional<M::RCRef<M::Buffer>>>&&>::CallImpl<M::AsyncRT::AnyAsyncValueRef M::Cache::cachedTransform<M::AsyncRT::AnyAsyncValueRef M::Cache::cachedTransform<M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_1>(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, M::RCRef<M::WriteableBuffer>, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0&&, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_1&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*)::'lambda'(M::RCRef<M::WriteableBuffer>, M::AsyncRT::AnyAsyncValueRef)>(M::AsyncRT::EncodedLocation, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>> const&, M::AsyncRT::AnyAsyncValueRef, M::RCRef<M::WriteableBuffer>, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0, llvm::unique_function<M::AsyncRT::AnyAsyncValueRef (M::RCRef<M::Buffer>)>, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*)::'lambda'(M::AsyncRT::AsyncValueRef<std::optional<M::RCRef<M::Buffer>>>&&)>(void*, M::AsyncRT::AsyncValueRef<std::optional<M::RCRef<M::Buffer>>>&) CachedTransform.cpp:0:0
#17 0x000055b79319f42d void (anonymous namespace)::WorkQueueThread::runItemsImpl<(anonymous namespace)::ThreadPoolWorkQueue::await(llvm::ArrayRef<M::AsyncRT::AnyAsyncValueRef>)::$_2, (anonymous namespace)::ThreadPoolWorkQueue::await(llvm::ArrayRef<M::AsyncRT::AnyAsyncValueRef>)::$_3>((anonymous namespace)::ThreadPoolWorkQueue::await(llvm::ArrayRef<M::AsyncRT::AnyAsyncValueRef>)::$_2, (anonymous namespace)::ThreadPoolWorkQueue::await(llvm::ArrayRef<M::AsyncRT::AnyAsyncValueRef>)::$_3, bool, llvm::StringLiteral, llvm::StringLiteral) ThreadPoolWorkQueue.cpp:0:0
#18 0x000055b7938f9dd9 M::Detail::runWithThreadAffinityLinux(unsigned long, llvm::function_ref<void ()>&) ThreadAffinity.cpp:0:0
#19 0x000055b7938fa18d M::runWithThreadAffinity(unsigned long, llvm::function_ref<void ()>) ThreadAffinity.cpp:0:0
#20 0x000055b7931a058c M::AsyncRT::runWithThreadAffinity(unsigned long, llvm::function_ref<void ()>) ThreadAffinity.cpp:0:0
#21 0x000055b79319e05d (anonymous namespace)::ThreadPoolWorkQueue::await(llvm::ArrayRef<M::AsyncRT::AnyAsyncValueRef>) ThreadPoolWorkQueue.cpp:0:0
#22 0x000055b792c9cb13 M::KGEN::KGENCompiler::runKGENPipeline(mlir::ModuleOp, M::TargetInfoAttr, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, M::AsyncRT::AnyAsyncValueRef, std::function<void (mlir::Operation*)>, std::function<void (mlir::Operation*)>) KGENCompiler.cpp:0:0
#23 0x000055b792c9c294 M::KGEN::KGENCompiler::runKGENPipeline(mlir::ModuleOp, M::TargetInfoAttr) KGENCompiler.cpp:0:0
#24 0x000055b792adcff0 run(M::State const&) mojo-run.cpp:0:0
#25 0x000055b792ae7c6e main mojo.cpp:0:0
#26 0x000077e8e28181ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#27 0x000077e8e281828b call_init ./csu/../csu/libc-start.c:128:20
#28 0x000077e8e281828b __libc_start_main ./csu/../csu/libc-start.c:347:5
#29 0x000055b792aba3e5 _start (/root/code/onegpu/mojo/.magic/envs/default/bin/mojo+0x26a43e5)
mojo crashed!
Please file a bug report.
Segmentation fault (core dumped)

Steps to reproduce

trait CaseA:
    @staticmethod
    fn whatever[s: Self](): ...


struct ImplA(CaseA):
    @staticmethod
    fn whatever[s: ImplA](): return

@export
fn anchor(x: ImplA): pass

System information

mojo 25.4.0.dev2025050405 (0e8f7772)

Mogball avatar May 09 '25 19:05 Mogball

Repro'd, thanks for the snippet! (And hi Jeff!) Moving to the backlog to be considered for next cycle, but please DM me if this issue is time-sensitive.

Marking high priority since it's a crash, we can consider lower priority once we get a good error message.

VerdagonModular avatar May 12 '25 15:05 VerdagonModular

Should be fixed in nightly

PeimingLiu avatar Jul 15 '25 18:07 PeimingLiu