Skip to content

Commit

Permalink
[NFC] C code clearn up (JuliaLang#37185)
Browse files Browse the repository at this point in the history
* Remove unused functions that are not obviously kept for debugging
* Make functions/variables not used in other files static
* Move non-static declarations of function and variables to headers
* Remove non-exported API and it's users from `julia.h` (moved to `julia_internal.h`)

  This removes `jl_vararg_kind_t` from public header. It's technically breaking.
  But since no one could actually use its value due to the function that produces this being not callable,
  this shouldn't break any actual/useful code.
  • Loading branch information
yuyichao authored Aug 28, 2020
1 parent 3d053d3 commit 0b0e219
Show file tree
Hide file tree
Showing 26 changed files with 166 additions and 229 deletions.
6 changes: 3 additions & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {
// without risk of creating pointers out of thin air
// TODO: replace with LLVM's llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32
// aka `__llvm_memmove_element_unordered_atomic_8` (for 64 bit)
void memmove_refs(void **dstp, void *const *srcp, size_t n) JL_NOTSAFEPOINT
static void memmove_refs(void **dstp, void *const *srcp, size_t n) JL_NOTSAFEPOINT
{
size_t i;
if (dstp < srcp || dstp > srcp + n) {
Expand All @@ -40,7 +40,7 @@ void memmove_refs(void **dstp, void *const *srcp, size_t n) JL_NOTSAFEPOINT
}
}

void memmove_safe(int hasptr, char *dst, const char *src, size_t nb) JL_NOTSAFEPOINT
static void memmove_safe(int hasptr, char *dst, const char *src, size_t nb) JL_NOTSAFEPOINT
{
if (hasptr)
memmove_refs((void**)dst, (void**)src, nb / sizeof(void*));
Expand All @@ -49,7 +49,7 @@ void memmove_safe(int hasptr, char *dst, const char *src, size_t nb) JL_NOTSAFEP
}

// array constructors ---------------------------------------------------------
char *jl_array_typetagdata(jl_array_t *a) JL_NOTSAFEPOINT
JL_DLLEXPORT char *jl_array_typetagdata(jl_array_t *a) JL_NOTSAFEPOINT
{
assert(jl_array_isbitsunion(a));
return ((char*)jl_array_data(a)) + ((jl_array_ndims(a) == 1 ? (a->maxsize - a->offset) : jl_array_len(a)) * a->elsize) + a->offset;
Expand Down
16 changes: 8 additions & 8 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static jl_value_t *scm_to_julia(fl_context_t *fl_ctx, value_t e, jl_module_t *mo
static value_t julia_to_scm(fl_context_t *fl_ctx, jl_value_t *v);
static jl_value_t *jl_expand_macros(jl_value_t *expr, jl_module_t *inmodule, struct macroctx_stack *macroctx, int onelevel);

value_t fl_defined_julia_global(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
static value_t fl_defined_julia_global(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
// tells whether a var is defined in and *by* the current module
argcount(fl_ctx, "defined-julia-global", nargs, 1);
Expand All @@ -145,27 +145,27 @@ value_t fl_defined_julia_global(fl_context_t *fl_ctx, value_t *args, uint32_t na
return (b != NULL && b->owner == ctx->module) ? fl_ctx->T : fl_ctx->F;
}

value_t fl_current_module_counter(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
static value_t fl_current_module_counter(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
jl_ast_context_t *ctx = jl_ast_ctx(fl_ctx);
assert(ctx->module);
return fixnum(jl_module_next_counter(ctx->module));
}

value_t fl_julia_current_file(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
static value_t fl_julia_current_file(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
return symbol(fl_ctx, jl_filename);
}

value_t fl_julia_current_line(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
static value_t fl_julia_current_line(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
return fixnum(jl_lineno);
}

// Check whether v is a scalar for purposes of inlining fused-broadcast
// arguments when lowering; should agree with broadcast.jl on what is a
// scalar. When in doubt, return false, since this is only an optimization.
value_t fl_julia_scalar(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
static value_t fl_julia_scalar(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
argcount(fl_ctx, "julia-scalar?", nargs, 1);
if (fl_isnumber(fl_ctx, args[0]) || fl_isstring(fl_ctx, args[0]))
Expand All @@ -180,7 +180,7 @@ value_t fl_julia_scalar(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)

static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, jl_module_t *mod);

value_t fl_julia_logmsg(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
static value_t fl_julia_logmsg(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
int kwargs_len = (int)nargs - 6;
if (nargs < 6 || kwargs_len % 2 != 0) {
Expand Down Expand Up @@ -860,8 +860,8 @@ jl_value_t *jl_call_scm_on_ast(const char *funcname, jl_value_t *expr, jl_module
return result;
}

jl_value_t *jl_call_scm_on_ast_and_loc(const char *funcname, jl_value_t *expr, jl_module_t *inmodule,
const char *file, int line)
static jl_value_t *jl_call_scm_on_ast_and_loc(const char *funcname, jl_value_t *expr,
jl_module_t *inmodule, const char *file, int line)
{
jl_ast_context_t *ctx = jl_ast_ctx_enter();
fl_context_t *fl_ctx = &ctx->fl;
Expand Down
8 changes: 1 addition & 7 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ typedef struct _varidx {
struct _varidx *prev;
} jl_varidx_t;

JL_DLLEXPORT uintptr_t jl_object_id_(jl_value_t *tv, jl_value_t *v) JL_NOTSAFEPOINT;

static uintptr_t type_object_id_(jl_value_t *v, jl_varidx_t *env) JL_NOTSAFEPOINT
{
if (v == NULL)
Expand Down Expand Up @@ -1025,8 +1023,6 @@ JL_CALLABLE(jl_f_invoke)
return res;
}

JL_DLLEXPORT jl_value_t *jl_get_keyword_sorter(jl_value_t *f);

JL_CALLABLE(jl_f_invoke_kwsorter)
{
JL_NARGSV(invoke, 3);
Expand Down Expand Up @@ -1239,7 +1235,7 @@ JL_CALLABLE(jl_f__primitivetype)
return dt->name->wrapper;
}

void jl_set_datatype_super(jl_datatype_t *tt, jl_value_t *super)
static void jl_set_datatype_super(jl_datatype_t *tt, jl_value_t *super)
{
if (!jl_is_datatype(super) || !jl_is_abstracttype(super) ||
tt->super != NULL ||
Expand All @@ -1265,8 +1261,6 @@ JL_CALLABLE(jl_f__setsuper)
return jl_nothing;
}

void jl_reinstantiate_inner_types(jl_datatype_t *t);

static int equiv_field_types(jl_value_t *old, jl_value_t *ft)
{
size_t nf = jl_svec_len(ft);
Expand Down
6 changes: 0 additions & 6 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1833,8 +1833,6 @@ extern "C" JL_DLLEXPORT void jl_clear_malloc_data(void)
jl_gc_sync_total_bytes(0);
}

extern "C" int isabspath(const char *in);

static void write_log_data(logdata_t &logData, const char *extension)
{
std::string base = std::string(jl_options.julia_bindir);
Expand Down Expand Up @@ -1890,8 +1888,6 @@ static void write_log_data(logdata_t &logData, const char *extension)
}
}

extern "C" int jl_getpid();

static void write_lcov_data(logdata_t &logData, const std::string &outfile)
{
std::ofstream outf(outfile.c_str(), std::ofstream::ate | std::ofstream::out | std::ofstream::binary);
Expand Down Expand Up @@ -1960,8 +1956,6 @@ static void show_source_loc(jl_codectx_t &ctx, JL_STREAM *out)
jl_printf(out, "in %s at %s", ctx.name, ctx.file.str().c_str());
}

extern "C" void jl_binding_deprecation_warning(jl_module_t *m, jl_binding_t *b);

static void cg_bdw(jl_codectx_t &ctx, jl_binding_t *b)
{
jl_binding_deprecation_warning(ctx.module, b);
Expand Down
4 changes: 2 additions & 2 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static int is10digit(char c) JL_NOTSAFEPOINT
return (c >= '0' && c <= '9');
}

jl_sym_t *jl_demangle_typename(jl_sym_t *s) JL_NOTSAFEPOINT
static jl_sym_t *jl_demangle_typename(jl_sym_t *s) JL_NOTSAFEPOINT
{
char *n = jl_symbol_name(s);
if (n[0] != '#')
Expand Down Expand Up @@ -730,7 +730,7 @@ PERMBOXN_FUNC(64, 2)
#define UNBOX_FUNC(j_type,c_type) \
JL_DLLEXPORT c_type jl_unbox_##j_type(jl_value_t *v) \
{ \
assert(jl_is_primitivetype(jl_typeof(v))); \
assert(jl_is_primitivetype(jl_typeof(v))); \
assert(jl_datatype_size(jl_typeof(v)) == sizeof(c_type)); \
return *(c_type*)jl_data_ptr(v); \
}
Expand Down
2 changes: 0 additions & 2 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,6 @@ static object::SectionRef getModuleSectionForAddress(const object::ObjectFile *o
}


extern "C" void jl_refresh_dbg_module_list(void);

bool jl_dylib_DI_for_fptr(size_t pointer, object::SectionRef *Section, int64_t *slide, llvm::DIContext **context,
bool onlySysImg, bool *isSysImg, void **saddr, char **name, char **filename) JL_NOTSAFEPOINT
{
Expand Down
3 changes: 0 additions & 3 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1809,8 +1809,6 @@ static void jl_insert_methods(jl_array_t *list)
}
}

extern jl_array_t *_jl_debug_method_invalidation JL_GLOBALLY_ROOTED;

// verify that these edges intersect with the same methods as before
static void jl_verify_edges(jl_array_t *targets, jl_array_t **pvalids)
{
Expand Down Expand Up @@ -2408,7 +2406,6 @@ static void jl_recache_other(void)
flagref_list.len = 0;
}

extern tracer_cb jl_newmeth_tracer;
static int trace_method(jl_typemap_entry_t *entry, void *closure)
{
jl_call_tracer(jl_newmeth_tracer, (jl_value_t*)entry->func.method);
Expand Down
4 changes: 0 additions & 4 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2638,10 +2638,6 @@ mark: {
}
}

extern jl_typemap_entry_t *call_cache[N_CALL_CACHE];
extern jl_array_t *jl_all_methods;
extern jl_array_t *_jl_debug_method_invalidation;

static void jl_gc_queue_thread_local(jl_gc_mark_cache_t *gc_cache, jl_gc_mark_sp_t *sp,
jl_ptls_t ptls2)
{
Expand Down
16 changes: 5 additions & 11 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ void jl_call_tracer(tracer_cb callback, jl_value_t *tracee)

/// ----- Definitions for various internal TypeMaps ----- ///

const struct jl_typemap_info method_defs = {
static const struct jl_typemap_info method_defs = {
1, &jl_method_type
};
const struct jl_typemap_info lambda_cache = {
static const struct jl_typemap_info lambda_cache = {
0, &jl_method_instance_type
};

Expand Down Expand Up @@ -1762,7 +1762,7 @@ jl_tupletype_t *arg_type_tuple(jl_value_t *arg1, jl_value_t **args, size_t nargs
return jl_inst_arg_tuple_type(arg1, args, nargs, 1);
}

jl_tupletype_t *lookup_arg_type_tuple(jl_value_t *arg1 JL_PROPAGATES_ROOT, jl_value_t **args, size_t nargs)
static jl_tupletype_t *lookup_arg_type_tuple(jl_value_t *arg1 JL_PROPAGATES_ROOT, jl_value_t **args, size_t nargs)
{
return jl_lookup_arg_tuple_type(arg1, args, nargs, 1);
}
Expand Down Expand Up @@ -2040,7 +2040,7 @@ static void _generate_from_hint(jl_method_instance_t *mi, size_t world)
}
}

void jl_compile_now(jl_method_instance_t *mi)
static void jl_compile_now(jl_method_instance_t *mi)
{
size_t world = jl_world_counter;
size_t tworld = jl_typeinf_world;
Expand Down Expand Up @@ -2092,7 +2092,7 @@ JL_DLLEXPORT int jl_compile_hint(jl_tupletype_t *types)
}

// add type of `f` to front of argument tuple type
jl_value_t *jl_argtype_with_function(jl_function_t *f, jl_value_t *types0)
static jl_value_t *jl_argtype_with_function(jl_function_t *f, jl_value_t *types0)
{
jl_value_t *types = jl_unwrap_unionall(types0);
size_t l = jl_nparams(types);
Expand Down Expand Up @@ -2335,12 +2335,6 @@ STATIC_INLINE jl_method_instance_t *jl_lookup_generic_(jl_value_t *F, jl_value_t
return mfunc;
}

jl_method_instance_t *jl_lookup_generic(jl_value_t **args, uint32_t nargs, uint32_t callsite,
size_t world)
{
return jl_lookup_generic_(args[0], &args[1], nargs - 1, callsite, world);
}

JL_DLLEXPORT jl_value_t *jl_apply_generic(jl_value_t *F, jl_value_t **args, uint32_t nargs)
{
size_t world = jl_get_ptls_states()->world_age;
Expand Down
14 changes: 3 additions & 11 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,13 @@ static void jl_uv_exitcleanup_walk(uv_handle_t *handle, void *arg)
jl_uv_exitcleanup_add(handle, (struct uv_shutdown_queue*)arg);
}

void jl_write_coverage_data(const char*);
void jl_write_malloc_log(void);
void jl_write_compiler_output(void);

static struct uv_shutdown_queue_item *next_shutdown_queue_item(struct uv_shutdown_queue_item *item)
{
struct uv_shutdown_queue_item *rv = item->next;
free(item);
return rv;
}

void jl_init_timing(void);
void jl_destroy_timing(void);
void jl_uv_call_close_callback(jl_value_t *val);

static void jl_close_item_atexit(uv_handle_t *handle)
{
if (handle->type != UV_FILE && uv_is_closing(handle))
Expand Down Expand Up @@ -309,7 +301,7 @@ void *jl_winsock_handle;
uv_loop_t *jl_io_loop;

#ifdef _OS_WINDOWS_
int uv_dup(uv_os_fd_t fd, uv_os_fd_t* dupfd) {
static int uv_dup(uv_os_fd_t fd, uv_os_fd_t* dupfd) {
HANDLE current_process;

if (fd == UV_STDIN_FD || fd == UV_STDOUT_FD || fd == UV_STDERR_FD)
Expand Down Expand Up @@ -343,7 +335,7 @@ int uv_dup(uv_os_fd_t fd, uv_os_fd_t* dupfd) {
return 0;
}
#else
int uv_dup(uv_os_fd_t fd, uv_os_fd_t* dupfd) {
static int uv_dup(uv_os_fd_t fd, uv_os_fd_t* dupfd) {
if ((*dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 3)) == -1)
return -errno;
return 0;
Expand Down Expand Up @@ -424,7 +416,7 @@ static void *init_stdio_handle(const char *stdio, uv_os_fd_t fd, int readable)
return handle;
}

void init_stdio(void)
static void init_stdio(void)
{
JL_STDIN = (uv_stream_t*)init_stdio_handle("stdin", UV_STDIN_FD, 1);
JL_STDOUT = (uv_stream_t*)init_stdio_handle("stdout", UV_STDOUT_FD, 0);
Expand Down
2 changes: 0 additions & 2 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ extern void JL_GC_ENABLEFRAME(interpreter_state*) JL_NOTSAFEPOINT;
static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s);
static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip, int toplevel);

int jl_is_toplevel_only_expr(jl_value_t *e);

// method definition form

static jl_value_t *eval_methoddef(jl_expr_t *ex, interpreter_state *s)
Expand Down
18 changes: 3 additions & 15 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ STATIC_INLINE int cmp_(int a, int b) JL_NOTSAFEPOINT
}

// a/b are jl_datatype_t* & not NULL
int datatype_name_cmp(jl_value_t *a, jl_value_t *b) JL_NOTSAFEPOINT
static int datatype_name_cmp(jl_value_t *a, jl_value_t *b) JL_NOTSAFEPOINT
{
if (!jl_is_datatype(a))
return jl_is_datatype(b) ? 1 : 0;
Expand Down Expand Up @@ -437,7 +437,7 @@ int datatype_name_cmp(jl_value_t *a, jl_value_t *b) JL_NOTSAFEPOINT

// sort singletons first, then DataTypes, then UnionAlls,
// ties broken alphabetically including module name & type parameters
int union_sort_cmp(const void *ap, const void *bp) JL_NOTSAFEPOINT
static int union_sort_cmp(const void *ap, const void *bp) JL_NOTSAFEPOINT
{
jl_value_t *a = *(jl_value_t**)ap;
jl_value_t *b = *(jl_value_t**)bp;
Expand Down Expand Up @@ -861,7 +861,7 @@ jl_datatype_t *jl_lookup_cache_type_(jl_datatype_t *type)
return (jl_datatype_t*)lookup_type(type->name, key, n);
}

int jl_type_equality_is_identity(jl_value_t *t1, jl_value_t *t2)
JL_DLLEXPORT int jl_type_equality_is_identity(jl_value_t *t1, jl_value_t *t2)
{
if (t1 == t2)
return 1;
Expand Down Expand Up @@ -1514,16 +1514,6 @@ JL_DLLEXPORT jl_tupletype_t *jl_apply_tuple_type_v(jl_value_t **p, size_t np)
return jl_apply_tuple_type_v_(p, np, NULL);
}

jl_datatype_t *jl_inst_concrete_tupletype(jl_svec_t *p)
{
return (jl_datatype_t*)inst_datatype_inner(jl_anytuple_type, p, jl_svec_data(p), jl_svec_len(p), 1, NULL, NULL);
}

jl_datatype_t *jl_inst_concrete_tupletype_v(jl_value_t **p, size_t np)
{
return (jl_datatype_t*)inst_datatype_inner(jl_anytuple_type, NULL, p, np, 1, NULL, NULL);
}

jl_tupletype_t *jl_lookup_arg_tuple_type(jl_value_t *arg1, jl_value_t **args, size_t nargs, int leaf)
{
return (jl_datatype_t*)lookup_typevalue(jl_tuple_typename, arg1, args, nargs, leaf);
Expand Down Expand Up @@ -1854,8 +1844,6 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!

// initialization -------------------------------------------------------------

extern void jl_init_int32_int64_cache(void);

static jl_tvar_t *tvar(const char *name)
{
return jl_new_typevar(jl_symbol(name), (jl_value_t*)jl_bottom_type,
Expand Down
Loading

0 comments on commit 0b0e219

Please sign in to comment.