Skip to content
New issue

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

Use of imported type/enum crashes the front end #1540

Closed
meheff opened this issue Aug 15, 2024 · 4 comments · Fixed by #1548
Closed

Use of imported type/enum crashes the front end #1540

meheff opened this issue Aug 15, 2024 · 4 comments · Fixed by #1548
Assignees
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end
Milestone

Comments

@meheff
Copy link
Collaborator

meheff commented Aug 15, 2024

Repro:

my_enum.x:

pub enum MyEnum : bits[1] {
  kA = 0,
  kB = 1,
}

my_lib.x:

import my_enum;

pub type MyEnumAlias = my_enum::MyEnum;

my_top.x:

import my_lib;

fn Foo () -> my_lib::MyEnumAlias {
  my_lib::MyEnumAlias::kA
}

Building my_top:

$ bazel build my_top
ERROR: /google/src/cloud/meheff/verilog/google3/experimental/users/meheff/xls/dslx_errors/BUILD:19:17: Parsing and type checking DSLX source files of target my_top failed: (Exit 255) bash failed: error executing ParseAndTypeCheckDSLXSourceFile command (from target //experimental/users/meheff/xls/dslx_errors:my_top) /usr/buildtools/buildhelpers/v4/bin/bash -c ... (remaining 1 argument skipped).  [forge_remote_host=javk34]
F0814 17:22:54.693965    9610 type_info.cc:534] Check failed: import->owner() == module_ (0x13a7bfe20138 vs. 0x13a7bfe20270) Import node from: google3.experimental.users.meheff.xls.dslx_errors.my_lib vs TypeInfo for my_top
*** Check failure stack trace: ***
    @     0x558602707904  absl::log_internal::LogMessage::SendToLog()
    @     0x558602707436  absl::log_internal::LogMessage::Flush()
    @     0x558602707d29  absl::log_internal::LogMessageFatal::~LogMessageFatal()
    @     0x5585ff7c8432  xls::dslx::TypeInfo::GetImported()
    @     0x5585ff664f0a  xls::dslx::ResolveColonRefSubjectForTypeChecking()
    @     0x5585ff666d0b  xls::dslx::ResolveTypeAliasToDirectColonRefSubject()
    @     0x5585ff66726a  std::__u::__variant_detail::__visitation::__base::__dispatcher<>::__dispatch<>()
    @     0x5585ff665061  xls::dslx::ResolveColonRefSubjectForTypeChecking()
    @     0x5585ff5d1431  xls::dslx::(anonymous namespace)::DeduceVisitor::HandleColonRef()
    @     0x5585ff5c6341  xls::dslx::Deduce()
    @     0x5585ff59a7d4  std::__u::__function::__policy_invoker<>::__call_impl<>()
    @     0x5585ff6688de  xls::dslx::DeduceCtx::Deduce()
    @     0x5585ff5caf6b  xls::dslx::(anonymous namespace)::DeduceVisitor::HandleStatement()
    @     0x5585ff5c6341  xls::dslx::Deduce()
    @     0x5585ff59a7d4  std::__u::__function::__policy_invoker<>::__call_impl<>()
    @     0x5585ff6688de  xls::dslx::DeduceCtx::Deduce()
    @     0x5585ff5cf6b3  xls::dslx::(anonymous namespace)::DeduceVisitor::HandleStatementBlock()
    @     0x5585ff5c6341  xls::dslx::Deduce()
    @     0x5585ff59a7d4  std::__u::__function::__policy_invoker<>::__call_impl<>()
    @     0x5585ff6688de  xls::dslx::DeduceCtx::Deduce()
    @     0x5585ff5c6722  xls::dslx::DeduceAndResolve()
    @     0x5585ff59f294  xls::dslx::TypecheckFunction()
    @     0x5585ff597e37  xls::dslx::TypecheckModule()
    @     0x5585ff53ac05  xls::dslx::TypecheckModule()
    @     0x5585ff53a1b4  xls::dslx::ParseAndTypecheck()
    @     0x5585ff531633  xls::dslx::ParseAndTest()
    @     0x5585ff51e71f  main
    @     0x7f22d42993d4  __libc_start_main
    @     0x5585ff51d02a  _start

Internally, repro is available at experimental/users/meheff/xls/dslx_errors:my_top

@meheff meheff added bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end labels Aug 15, 2024
@richmckeever richmckeever added this to the DSLX Next milestone Aug 15, 2024
@meheff
Copy link
Collaborator Author

meheff commented Aug 15, 2024

Maybe related error with use of MAX attribute of imported type.

my_lib.x:

pub const W = s32:16;
pub type T = bits[W as u32];

my_test.x:

import my_lib;

fn Bar () -> my_lib::T {
  my_lib::T::MAX
}

Repro (needs to be test!):

bazel test my_test

Error message:

F0815 10:27:44.941148    9883 type_info.cc:323] Check failed: key->owner() == module_ (0x12bdffe20138 vs. 0x12bdffe209c0) google3.experimental.users.meheff.xls.dslx_errors.my_lib vs my_test key: bits[W as u32]
*** Check failure stack trace: ***
    @     0x564e40510d04  absl::log_internal::LogMessage::SendToLog()
    @     0x564e40510836  absl::log_internal::LogMessage::Flush()
    @     0x564e40511129  absl::log_internal::LogMessageFatal::~LogMessageFatal()
    @     0x564e3d5d107b  xls::dslx::TypeInfo::GetItem()
    @     0x564e3d34c9d0  xls::dslx::FunctionConverter::ResolveType()
    @     0x564e3d34f080  xls::dslx::FunctionConverter::ResolveTypeToIr()
    @     0x564e3d379fce  std::__u::__variant_detail::__visitation::__base::__dispatcher<>::__dispatch<>()
    @     0x564e3d36ef37  xls::dslx::FunctionConverter::HandleColonRef()
    @     0x564e3d349cb6  xls::dslx::FunctionConverterVisitor::Visit()
    @     0x564e3d37a5d5  std::__u::__variant_detail::__visitation::__base::__dispatcher<>::__dispatch<>()
    @     0x564e3d37207c  xls::dslx::FunctionConverter::HandleStatement()
    @     0x564e3d349cb6  xls::dslx::FunctionConverterVisitor::Visit()
    @     0x564e3d371d44  xls::dslx::FunctionConverter::HandleStatementBlock()
    @     0x564e3d349cb6  xls::dslx::FunctionConverterVisitor::Visit()
    @     0x564e3d36c0b3  xls::dslx::FunctionConverter::HandleFunction()
    @     0x564e3d344ff1  xls::dslx::(anonymous namespace)::ConvertCallGraph()
    @     0x564e3d342c89  xls::dslx::ConvertModuleIntoPackage()
    @     0x564e3d34599a  xls::dslx::ConvertModuleToPackage()
    @     0x564e3d3387b7  xls::dslx::ParseAndTest()
    @     0x564e3d32571f  main
    @     0x7f62428633d4  __libc_start_main
    @     0x564e3d32402a  _start

@meheff
Copy link
Collaborator Author

meheff commented Aug 19, 2024

@cdleary it looks like PR #1548 fixes the first example in #1540 (comment). Thanks! We're working on landing it internally.

The second example #1540 (comment) looks like it still fails.

Also another example of use of imported types which fail is:

my_enum.x

pub enum MyEnum : bits[1] {
  kA = 0,
  kB = 1,
}

my_param_proc.x

import my_enum;

proc foo_proc<N: my_enum::MyEnum> {
    config() { () }
    init { () }
    next(state: ()) { () }
}

proc bar_proc {
    config() {
      spawn foo_proc<my_enum::MyEnum::kA>();
      ()
    }
    init { () }
    next(state: ()) { () }
}

Repro: bazel test my_param_proc

Making a type alias for my_enum::MyEnum fixes the issue.

Stack trace:

*** SIGABRT received by PID 1543330 (TID 1543330) on cpu 7 from PID 1543330; stack trace: ***
PC: @     0x7f3123ff7981  (unknown)  gsignal
    @     0x55d3b067fdd2        288  FailureSignalHandler()
    @     0x7f312416ae80  (unknown)  (unknown)
    @     0x55d3b0abb77b        288  std::__u::__libcpp_verbose_abort()
    @     0x55d3a9226ca2        240  xls::dslx::(anonymous namespace)::DeduceVisitor::HandleColonRef()
    @     0x55d3abba0f23         16  xls::dslx::ColonRef::Accept()
    @     0x55d3a9213f86        256  xls::dslx::Deduce()
    @     0x55d3a91aa3ae         32  std::__u::__function::__policy_invoker<>::__call_impl<>()
    @     0x55d3a935b505        192  xls::dslx::DeduceCtx::Deduce()
    @     0x55d3a921b665        208  xls::dslx::(anonymous namespace)::DeduceVisitor::HandleTypeRef()
    @     0x55d3abba0af3         16  xls::dslx::TypeRef::Accept()
    @     0x55d3a9213f86        256  xls::dslx::Deduce()
    @     0x55d3a91aa3ae         32  std::__u::__function::__policy_invoker<>::__call_impl<>()
    @     0x55d3a935b505        192  xls::dslx::DeduceCtx::Deduce()
    @     0x55d3a92204a7        464  xls::dslx::(anonymous namespace)::DeduceVisitor::HandleTypeRefTypeAnnotation()
    @     0x55d3abba1703         16  xls::dslx::TypeRefTypeAnnotation::Accept()
    @     0x55d3a9213f86        256  xls::dslx::Deduce()
    @     0x55d3a91aa3ae         32  std::__u::__function::__policy_invoker<>::__call_impl<>()
    @     0x55d3a935b505        192  xls::dslx::DeduceCtx::Deduce()
    @     0x55d3a93552a0        160  xls::dslx::ParametricBindingToType()
    @     0x55d3a91d2ab1        848  xls::dslx::InstantiateParametricFunction()
    @     0x55d3a91c5911        752  xls::dslx::TypecheckInvocation()
    @     0x55d3a91aa491         32  std::__u::__function::__policy_invoker<>::__call_impl<>()
    @     0x55d3a925f431        224  xls::dslx::DeduceInstantiation()
    @     0x55d3a926b0f5        736  xls::dslx::DeduceSpawn()
    @     0x55d3a922f862        144  xls::dslx::(anonymous namespace)::DeduceVisitor::HandleSpawn()
    @     0x55d3abba2193         16  xls::dslx::Spawn::Accept()
    @     0x55d3a9213f86        256  xls::dslx::Deduce()
    @     0x55d3a91aa3ae         32  std::__u::__function::__policy_invoker<>::__call_impl<>()
    @     0x55d3a935b505        192  xls::dslx::DeduceCtx::Deduce()
    @     0x55d3a921ab74        176  xls::dslx::(anonymous namespace)::DeduceVisitor::HandleStatement()
    @     0x55d3abba35f3         16  xls::dslx::Statement::Accept()
    @     0x55d3a9213f86        256  xls::dslx::Deduce()
    @     0x55d3a91aa3ae         32  std::__u::__function::__policy_invoker<>::__call_impl<>()
    @     0x55d3a935b505        192  xls::dslx::DeduceCtx::Deduce()
    @     0x55d3a9223089        336  xls::dslx::(anonymous namespace)::DeduceVisitor::HandleStatementBlock()
    @     0x55d3abba29a3         16  xls::dslx::StatementBlock::Accept()
    @     0x55d3a9213f86        256  xls::dslx::Deduce()
    @     0x55d3a91aa3ae         32  std::__u::__function::__policy_invoker<>::__call_impl<>()
    @     0x55d3a935b505        192  xls::dslx::DeduceCtx::Deduce()
    @     0x55d3a9214794        128  xls::dslx::DeduceAndResolve()
    @     0x55d3a91b48da        320  xls::dslx::TypecheckFunction()
    @     0x55d3a91a6ee4       1568  xls::dslx::TypecheckModule()
    @     0x55d3a909b1ca        256  xls::dslx::TypecheckModule()
    @     0x55d3a909a505        224  xls::dslx::ParseAndTypecheck()
    @     0x55d3a907c42e       1232  xls::dslx::ParseAndTest()
    @     0x55d3a901c925        464  main
    @     0x7f3123fe33d4        192  __libc_start_main
    @     0x55d3a8f440aa  (unknown)  _start

@meheff meheff changed the title Importing and using an alias of an enum crashes the front end Use of imported type/enum crashes the front end Aug 19, 2024
@meheff meheff reopened this Aug 20, 2024
@proppy proppy moved this to Todo in XLS usability Aug 20, 2024
@richmckeever richmckeever moved this from Todo to In Progress in XLS usability Aug 20, 2024
@cdleary
Copy link
Collaborator

cdleary commented Aug 23, 2024

@richmckeever I assume I still have the assignment on this one? Can look at what's still failing if you confirm, thanks!

@meheff
Copy link
Collaborator Author

meheff commented Aug 23, 2024

@cdleary go for it. Rich is OOO.

cdleary added a commit to xlsynth/xlsynth that referenced this issue Sep 1, 2024
Towards google#1540 -- in particular fixes the example given in this
comment:

google#1540 (comment)
cdleary added a commit to xlsynth/xlsynth that referenced this issue Sep 1, 2024
Towards google#1540 -- in particular fixes the example given in this
comment:

google#1540 (comment)
@meheff meheff closed this as completed Sep 13, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in XLS usability Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants