@@ -1373,7 +1373,9 @@ JL_CALLABLE(jl_f__typevar)
13731373JL_CALLABLE (jl_f_arraysize )
13741374{
13751375 JL_NARGS (arraysize , 2 , 2 );
1376- JL_TYPECHK (arraysize , array , args [0 ]);
1376+ if (!jl_is_arrayish (args [0 ])) {
1377+ jl_type_error ("arraysize" , (jl_value_t * )jl_array_type , args [0 ]);
1378+ }
13771379 jl_array_t * a = (jl_array_t * )args [0 ];
13781380 size_t nd = jl_array_ndims (a );
13791381 JL_TYPECHK (arraysize , long , args [1 ]);
@@ -1412,7 +1414,9 @@ JL_CALLABLE(jl_f_arrayref)
14121414{
14131415 JL_NARGSV (arrayref , 3 );
14141416 JL_TYPECHK (arrayref , bool , args [0 ]);
1415- JL_TYPECHK (arrayref , array , args [1 ]);
1417+ if (!jl_is_arrayish (args [1 ])) {
1418+ jl_type_error ("arrayref" , (jl_value_t * )jl_array_type , args [1 ]);
1419+ }
14161420 jl_array_t * a = (jl_array_t * )args [1 ];
14171421 size_t i = array_nd_index (a , & args [2 ], nargs - 2 , "arrayref" );
14181422 return jl_arrayref (a , i );
@@ -1735,6 +1739,54 @@ JL_CALLABLE(jl_f_set_binding_type)
17351739 return jl_nothing ;
17361740}
17371741
1742+ JL_CALLABLE (jl_f_arrayfreeze )
1743+ {
1744+ JL_NARGSV (arrayfreeze , 1 );
1745+ JL_TYPECHK (arrayfreeze , array , args [0 ]);
1746+ jl_array_t * a = (jl_array_t * )args [0 ];
1747+ jl_datatype_t * it = (jl_datatype_t * )jl_apply_type2 ((jl_value_t * )jl_immutable_array_type ,
1748+ jl_tparam0 (jl_typeof (a )), jl_tparam1 (jl_typeof (a )));
1749+ JL_GC_PUSH1 (& it );
1750+ // The idea is to elide this copy if the compiler or runtime can prove that
1751+ // doing so is safe to do.
1752+ jl_array_t * na = jl_array_copy (a );
1753+ jl_set_typeof (na , it );
1754+ JL_GC_POP ();
1755+ return (jl_value_t * )na ;
1756+ }
1757+
1758+ JL_CALLABLE (jl_f_mutating_arrayfreeze )
1759+ {
1760+ // N.B.: These error checks pretend to be arrayfreeze since this is a drop
1761+ // in replacement and we don't want to change the visible error type in the
1762+ // optimizer
1763+ JL_NARGSV (arrayfreeze , 1 );
1764+ JL_TYPECHK (arrayfreeze , array , args [0 ]);
1765+ jl_array_t * a = (jl_array_t * )args [0 ];
1766+ jl_datatype_t * it = (jl_datatype_t * )jl_apply_type2 ((jl_value_t * )jl_immutable_array_type ,
1767+ jl_tparam0 (jl_typeof (a )), jl_tparam1 (jl_typeof (a )));
1768+ jl_set_typeof (a , it );
1769+ return (jl_value_t * )a ;
1770+ }
1771+
1772+ JL_CALLABLE (jl_f_arraythaw )
1773+ {
1774+ JL_NARGSV (arraythaw , 1 );
1775+ if (((jl_datatype_t * )jl_typeof (args [0 ]))-> name != jl_immutable_array_typename ) {
1776+ jl_type_error ("arraythaw" , (jl_value_t * )jl_immutable_array_type , args [0 ]);
1777+ }
1778+ jl_array_t * a = (jl_array_t * )args [0 ];
1779+ jl_datatype_t * it = (jl_datatype_t * )jl_apply_type2 ((jl_value_t * )jl_array_type ,
1780+ jl_tparam0 (jl_typeof (a )), jl_tparam1 (jl_typeof (a )));
1781+ JL_GC_PUSH1 (& it );
1782+ // The idea is to elide this copy if the compiler or runtime can prove that
1783+ // doing so is safe to do.
1784+ jl_array_t * na = jl_array_copy (a );
1785+ jl_set_typeof (na , it );
1786+ JL_GC_POP ();
1787+ return (jl_value_t * )na ;
1788+ }
1789+
17381790// IntrinsicFunctions ---------------------------------------------------------
17391791
17401792static void (* runtime_fp [num_intrinsics ])(void );
@@ -1890,6 +1942,10 @@ void jl_init_primitives(void) JL_GC_DISABLED
18901942 jl_builtin_arrayset = add_builtin_func ("arrayset" , jl_f_arrayset );
18911943 jl_builtin_arraysize = add_builtin_func ("arraysize" , jl_f_arraysize );
18921944
1945+ jl_builtin_arrayfreeze = add_builtin_func ("arrayfreeze" , jl_f_arrayfreeze );
1946+ jl_builtin_mutating_arrayfreeze = add_builtin_func ("mutating_arrayfreeze" , jl_f_mutating_arrayfreeze );
1947+ jl_builtin_arraythaw = add_builtin_func ("arraythaw" , jl_f_arraythaw );
1948+
18931949 // method table utils
18941950 jl_builtin_applicable = add_builtin_func ("applicable" , jl_f_applicable );
18951951 jl_builtin_invoke = add_builtin_func ("invoke" , jl_f_invoke );
@@ -1965,6 +2021,7 @@ void jl_init_primitives(void) JL_GC_DISABLED
19652021 add_builtin ("AbstractArray" , (jl_value_t * )jl_abstractarray_type );
19662022 add_builtin ("DenseArray" , (jl_value_t * )jl_densearray_type );
19672023 add_builtin ("Array" , (jl_value_t * )jl_array_type );
2024+ add_builtin ("ImmutableArray" , (jl_value_t * )jl_immutable_array_type );
19682025
19692026 add_builtin ("Expr" , (jl_value_t * )jl_expr_type );
19702027 add_builtin ("LineNumberNode" , (jl_value_t * )jl_linenumbernode_type );
0 commit comments