lfortran / lfortran

Official main repository for LFortran
https://lfortran.org/
Other
933 stars 145 forks source link

associate for arrays error in fill_array_details #2056

Open certik opened 1 year ago

certik commented 1 year ago
associate (tmlp_fc_w => mlp_fc_w(:,:), tmlp_fc_b => mlp_fc_b(:), &
        tmlp_proj_w => mlp_proj_w(:,:), tmlp_proj_b => mlp_proj_b(:))
    call ffn(x, y, tmlp_fc_w, tmlp_fc_b, tmlp_proj_w, tmlp_proj_b)
end associate

gives:

Traceback (most recent call last):
  File "/Users/ondrej/repos/lfortran/lfortran/src/bin/lfortran.cpp", line 2141
    return compile_to_object_file(arg_file, outfile, false,
  File "/Users/ondrej/repos/lfortran/lfortran/src/bin/lfortran.cpp", line 917
    res = fe.get_llvm3(*asr, lpm, diagnostics, infile);
  File "/Users/ondrej/repos/lfortran/lfortran/src/lfortran/fortran_evaluator.cpp", line 345
    compiler_options, run_fn, infile);
  File "/Users/ondrej/repos/lfortran/lfortran/src/libasr/codegen/asr_to_llvm.cpp", line 8230
    pass_manager.apply_passes(al, &asr, pass_options, diagnostics);
  File "../libasr/asr.h", line 5024
  File "../libasr/asr.h", line 5000
  File "../libasr/asr.h", line 5025
  File "../libasr/asr.h", line 4734
  File "/Users/ondrej/repos/lfortran/lfortran/src/libasr/codegen/asr_to_llvm.cpp", line 869
    ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
  File "../libasr/asr.h", line 5027
  File "../libasr/asr.h", line 4743
  File "/Users/ondrej/repos/lfortran/lfortran/src/libasr/codegen/asr_to_llvm.cpp", line 2619
    finish_module_init_function_prototype(x);
  File "/Users/ondrej/repos/lfortran/lfortran/src/libasr/codegen/asr_to_llvm.cpp", line 3418
    ASR::Function_t *s = ASR::down_cast<ASR::Function_t>(item.second);
  File "/Users/ondrej/repos/lfortran/lfortran/src/libasr/codegen/asr_to_llvm.cpp", line 3190
    visit_procedures(x);
  File "/Users/ondrej/repos/lfortran/lfortran/src/libasr/codegen/asr_to_llvm.cpp", line 3371
    this->visit_stmt(*x.m_body[i]);
  File "../libasr/asr.h", line 5044
  File "../libasr/asr.h", line 4799
  File "/Users/ondrej/repos/lfortran/lfortran/src/libasr/codegen/asr_to_llvm.cpp", line 4403
    declare_vars(*associate_block);
  File "/Users/ondrej/repos/lfortran/lfortran/src/libasr/codegen/asr_to_llvm.cpp", line 3036
    ASR::expr_t* init_expr = v->m_symbolic_value;
  File "/Users/ondrej/repos/lfortran/lfortran/src/libasr/codegen/asr_to_llvm.cpp", line 2732
    fill_array_details(ptr, llvm_data_type, m_dims, n_dims, is_data_only);
  File "/Users/ondrej/repos/lfortran/lfortran/src/libasr/codegen/asr_to_llvm.cpp", line 402
    visit_expr(*(m_dim.m_start));
  File "../libasr/asr.h", line 5090
  File "../libasr/asr.h", line 5090
  Binary file "/usr/lib/system/libsystem_platform.dylib", local address: 0x1803244e3
certik commented 1 year ago

Same error for:

associate ( &  
        q => x2((1-1)*n_embd+1:1*n_embd,:), & 
        k => x2((2-1)*n_embd+1:2*n_embd,:), & 
        v => x2((3-1)*n_embd+1:3*n_embd,:)  & 
    ) 
    if (use_kv_cache) then 
        kv_cache(:,n_seq,1) = k(:,1) 
        kv_cache(:,n_seq,2) = v(:,1) 
    else 
        kv_cache(:,:,1) = k 
        kv_cache(:,:,2) = v 
    end if 
end associate 
Thirumalai-Shaktivel commented 1 year ago

Minimal example:

program test
    implicit none
    integer :: x(2)
    integer :: i, j
    x = 123
    associate(a=>x(:))
        print *, a
    end associate
end program test

I think we have to handle this: https://github.com/lcompilers/lpython/issues/1599#issuecomment-1621157646 to fix this issue.