@@ -1997,6 +1997,9 @@ JL_DLLEXPORT void jl_method_instance_add_backedge(jl_method_instance_t *callee,
1997
1997
jl_gc_wb (callee , backedges );
1998
1998
}
1999
1999
else {
2000
+ #ifndef JL_NDEBUG
2001
+ // It is the caller's (inference's) responsibility to de-duplicate edges. Here we are only
2002
+ // checking its work.
2000
2003
size_t i = 0 , l = jl_array_nrows (backedges );
2001
2004
for (i = 0 ; i < l ; i ++ ) {
2002
2005
// optimized version of while (i < l) i = get_next_edge(callee->backedges, i, &invokeTypes, &mi);
@@ -2012,6 +2015,8 @@ JL_DLLEXPORT void jl_method_instance_add_backedge(jl_method_instance_t *callee,
2012
2015
break ;
2013
2016
}
2014
2017
}
2018
+ assert (!found && "duplicate back-edge registered" );
2019
+ #endif
2015
2020
}
2016
2021
if (!found )
2017
2022
push_edge (backedges , invokesig , caller );
@@ -2037,14 +2042,20 @@ JL_DLLEXPORT void jl_method_table_add_backedge(jl_methtable_t *mt, jl_value_t *t
2037
2042
else {
2038
2043
// check if the edge is already present and avoid adding a duplicate
2039
2044
size_t i , l = jl_array_nrows (mt -> backedges );
2045
+ #ifndef JL_NDEBUG
2046
+ // It is the caller's (inference's) responsibility to de-duplicate edges. Here we are only
2047
+ // checking its work.
2048
+ int found = 0 ;
2040
2049
for (i = 1 ; i < l ; i += 2 ) {
2041
2050
if (jl_array_ptr_ref (mt -> backedges , i ) == (jl_value_t * )caller ) {
2042
2051
if (jl_types_equal (jl_array_ptr_ref (mt -> backedges , i - 1 ), typ )) {
2043
- JL_UNLOCK ( & mt -> writelock ) ;
2044
- return ;
2052
+ found = 1 ;
2053
+ break ;
2045
2054
}
2046
2055
}
2047
2056
}
2057
+ assert (!found && "duplicate back-edge registered" );
2058
+ #endif
2048
2059
// reuse an already cached instance of this type, if possible
2049
2060
// TODO: use jl_cache_type_(tt) like cache_method does, instead of this linear scan?
2050
2061
for (i = 1 ; i < l ; i += 2 ) {
0 commit comments