Skip to content

Commit e0474e4

Browse files
committed
changing naming scheme to avoid angled brackets
1 parent 05efd70 commit e0474e4

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/ast.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,12 @@ static value_t fl_current_module_counter(fl_context_t *fl_ctx, value_t *args, ui
215215
jl_ast_context_t *ctx = jl_ast_ctx(fl_ctx);
216216
jl_module_t *m = ctx->module;
217217
assert(m != NULL);
218-
// Create a string of the form <$outermost_func_name>$counter
219218
// Get the outermost function name from the `parsed_method_stack` top
220219
char *funcname = NULL;
221220
value_t funcname_v = parsed_method_stack.len > 0 ? (value_t)parsed_method_stack.items[0] : fl_ctx->NIL;
222221
if (funcname_v != fl_ctx->NIL) {
223222
funcname = symbol_name(fl_ctx, funcname_v);
224223
}
225-
// Create the string
226224
char buf[(funcname != NULL ? strlen(funcname) : 0) + 20];
227225
if (funcname != NULL && funcname[0] != '#') {
228226
uint32_t nxt;
@@ -242,7 +240,7 @@ static value_t fl_current_module_counter(fl_context_t *fl_ctx, value_t *args, ui
242240
// to avoid the counter being 0 or 1, which are reserved
243241
ptrhash_put(mod_table, funcname, (void*)(uintptr_t)((nxt + 1) << 2 | 3));
244242
jl_mutex_unlock_nogc(&m->lock);
245-
snprintf(buf, sizeof(buf), "<%s>%d", funcname, nxt);
243+
snprintf(buf, sizeof(buf), "%s_%d", funcname, nxt);
246244
}
247245
else {
248246
snprintf(buf, sizeof(buf), "%d", jl_module_next_counter(ctx->module));

src/datatype.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
2872
static 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

Comments
 (0)