Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 394
    • Issues 394
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 17
    • Merge requests 17
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Issues
  • #2357
Closed
Open
Created Nov 29, 2023 by Sven-Bodo Scholz@sbsOwner

Type pattern with constraint on argument types not working

If I try this example:

use Array: all;

int[m] foo ( int[n] v, int[m] w) | ( n == 2 * m)
{
   return { iv ->  v[iv*2] + w[iv]  | iv < [m]};
}

int main () {
    a = foo( [1,2,3], [1,2]);
    return _sel_VxA_([1], a);
}

using

sac2c 1.3.3-MijasCosta-1115-g81576
build-type: RELEASE
built-by: "sbs" at 2023-11-29T11:50:22

with sac2c -check c -b2:rtpf we obtain:

/****************************************************************************
 * _rtpf_2_post_foo(...) [ body ]
 ****************************************************************************/
inline
bool _rtpf_2_post_foo( int[.] v { ,NN } , int[.] w { ,NN } , int[.] _rtpf_1_ret { ,NN } )
/*
 *  _rtpf_2_post_foo ::  ---
 */
{
  _rtpf_0_pred = true;
  n = _sel_VxA_( [ 0 ], _shape_A_( v));
  m = _sel_VxA_( [ 0 ], _shape_A_( w));
  _rtpf_0_pred = ( _eq_SxS_( m, _sel_VxA_( [ 0 ], _shape_A_( _rtpf_1_ret))) ? _rtpf_0_pred : _type_error_( _|_) );
  return( _rtpf_0_pred);
}



/****************************************************************************
 * _rtpf_3_impl_foo(...) [ body ]
 ****************************************************************************/
int[.] _rtpf_3_impl_foo( int[.] v { ,NN } , int[.] w { ,NN } )
/*
 *  _rtpf_3_impl_foo ::  ---
 */
{
  n = _sel_VxA_( [ 0 ], _shape_A_( v));
  m = _sel_VxA_( [ 0 ], _shape_A_( w));
  return( { iv -> ( sel( ( iv *2) , v)  +sel( iv, w) ) | (NULL) <= ? < [ m ]  });
}



/****************************************************************************
 * foo(...) [ body ]
 ****************************************************************************/
inline
int[.] foo( int[.] v { ,NN } , int[.] w { ,NN } )
/*
 *  foo ::  ---
 */
{
  _rtpf_5_res = _rtpf_3_impl_foo( v, w) ;
  _rtpf_4_pred = _rtpf_2_post_foo( v, w, _rtpf_5_res) ;
  _rtpf_5_res = _guard_( _rtpf_5_res, _rtpf_4_pred);
  return( _rtpf_5_res);
}

Note here the missing pre-check!

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking