Skip to content

Commit

Permalink
Support renaming of old types
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Jul 9, 2017
1 parent e1def10 commit 250822b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ function resolve(g::GlobalRef; force::Bool=false)
return g
end

function rename_binding(mod::Module, oldname::Symbol, newname::Symbol)
T = getfield(mod, oldname)
ccall(:jl_rename_binding, Void, (Any, Any, Any), mod, oldname, newname)
T.name.name = newname
T
end

function shunt_binding(mod::Module, oldname::Symbol)
i = oldbinding_counter[] + 1 # oldbinding_counter created in refpointer.jl
oldbinding_counter[] = i
newname = Symbol(oldname, '#', i)
rename_binding(mod, oldname, newname)
end

"""
fieldname(x::DataType, i::Integer)
Expand Down
2 changes: 2 additions & 0 deletions base/refpointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ setindex!(b::RefValue, x) = (b.x = x; b)
setindex!(b::RefArray, x) = (b.x[b.i] = x; b)

###

const oldbinding_counter = Ref(0)
10 changes: 10 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,16 @@ void jl_binding_deprecation_warning(jl_binding_t *b)
}
}

JL_DLLEXPORT void jl_rename_binding(jl_module_t *m, jl_sym_t *oldvar, jl_sym_t *newvar)
{
jl_binding_t *b = jl_get_binding(m, oldvar);
if (b) {
b->name = newvar;
ptrhash_remove(&m->bindings, oldvar);
ptrhash_put(&m->bindings, newvar, b);
}
}

JL_DLLEXPORT void jl_checked_assignment(jl_binding_t *b, jl_value_t *rhs)
{
if (b->constp && b->value != NULL) {
Expand Down

0 comments on commit 250822b

Please sign in to comment.