@@ -25,6 +25,50 @@ static int is10digit(char c) JL_NOTSAFEPOINT
2525 return (c >= '0' && c <= '9' );
2626}
2727
28+ // return whether this is a canonicalized anonymous function name
29+ // we will basically check if the name starts with `#` and the first character after `#` is a digit
30+ // or is of the form `#f_...#f..._` where the two `f`s are the same and the ... are digits
31+ static int is_canonicalized_anonfn_typename (char * name ) JL_NOTSAFEPOINT
32+ {
33+ assert (strlen (name ) > 1 );
34+ assert (name [0 ] == '#' );
35+ // first character after '#' is a digit: canonicalized anonymous function name
36+ if (is10digit (name [1 ])) {
37+ return 1 ;
38+ }
39+ char * outermost_func_name2 = NULL ;
40+ // go backwards from name + strlen(name) to find the first `_`
41+ for (char * c = name + strlen (name ); c > name ; c -- ) {
42+ if (* c == '_' ) {
43+ outermost_func_name2 = c ;
44+ break ;
45+ }
46+ }
47+ if (outermost_func_name2 == NULL ) {
48+ return 0 ;
49+ }
50+ char * end = strrchr (name , '#' );
51+ char * outermost_func_name = NULL ;
52+ // go backwards from end to find the first `_`
53+ for (char * c = end ; c > name ; c -- ) {
54+ if (* c == '_' ) {
55+ outermost_func_name = c ;
56+ break ;
57+ }
58+ }
59+ if (outermost_func_name == NULL ) {
60+ return 0 ;
61+ }
62+ char * s1 = name ;
63+ char * s2 = end ;
64+ for (; s1 < outermost_func_name && s2 < outermost_func_name2 ; s1 ++ , s2 ++ ) {
65+ if (* s1 != * s2 ) {
66+ return 0 ;
67+ }
68+ }
69+ return 1 ;
70+ }
71+
2872static jl_sym_t * jl_demangle_typename (jl_sym_t * s ) JL_NOTSAFEPOINT
2973{
3074 char * n = jl_symbol_name (s );
@@ -36,7 +80,7 @@ static jl_sym_t *jl_demangle_typename(jl_sym_t *s) JL_NOTSAFEPOINT
3680 len = strlen (n ) - 1 ;
3781 else
3882 len = (end - n ) - 1 ; // extract `f` from `#f#...`
39- if (is10digit ( n [ 1 ]) || n [ 1 ] == '<' ) {
83+ if (is_canonicalized_anonfn_typename ( n ) ) {
4084 return _jl_symbol (n , len + 1 );
4185 }
4286 return _jl_symbol (& n [1 ], len );
0 commit comments