Skip to content

Commit 30177d0

Browse files
authored
cleanup: Remove fallback post-lowering global resolution (#57051)
After recent changes, essentially all global symbol scopes are resolved by lowering, so the code in method.c that replaces symbols by globalrefs is no longer necessary. The one small exception to this were symbols resulting from closure conversion, because these get inserted after the point at which lowering converts symbols to globalrefs. However, in the current design, I think that's basically a bug (and easily addressed by inserting `globalref`s where appropriate). Removing this extra resolution step is not particularly necessary, but for the upcoming binding partition backedges, it removes an ambiguity as to which version of the lowered code to scan. It also partially resolves a very old todo about not performing post-hoc mutation of lowered code (although we still do this for ccall).
1 parent 6cf2b14 commit 30177d0

File tree

6 files changed

+156
-225
lines changed

6 files changed

+156
-225
lines changed

src/jl_exported_funcs.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@
388388
XX(jl_read_verify_header) \
389389
XX(jl_realloc) \
390390
XX(jl_register_newmeth_tracer) \
391-
XX(jl_resolve_globals_in_ir) \
391+
XX(jl_resolve_definition_effects_in_ir) \
392392
XX(jl_restore_excstack) \
393393
XX(jl_restore_incremental) \
394394
XX(jl_restore_package_image_from_file) \

src/julia-syntax.scm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,11 +3683,17 @@ f(x) = yt(x)
36833683
(else
36843684
(error (string "invalid assignment location \"" (deparse var) "\"")))))
36853685

3686+
(define (sig-type-expr namemap name expr)
3687+
(let ((newname (get namemap name expr)))
3688+
(if (symbol? newname)
3689+
`(globalref (thismodule) ,newname)
3690+
newname)))
3691+
36863692
(define (rename-sig-types ex namemap)
36873693
(pattern-replace
36883694
(pattern-set
36893695
(pattern-lambda (call (core (-/ Typeof)) name)
3690-
(get namemap name __)))
3696+
(sig-type-expr namemap name __)))
36913697
ex))
36923698

36933699
;; replace leading (function) argument type with `typ`
@@ -4242,7 +4248,7 @@ f(x) = yt(x)
42424248
(contains (lambda (x) (eq? x 'kwftype)) sig))
42434249
(renamemap (map cons closure-param-names closure-param-syms))
42444250
(arg-defs (replace-vars
4245-
(fix-function-arg-type sig type-name iskw namemap closure-param-syms)
4251+
(fix-function-arg-type sig `(globalref (thismodule) ,type-name) iskw namemap closure-param-syms)
42464252
renamemap)))
42474253
(append (map (lambda (gs tvar)
42484254
(make-assignment gs `(call (core TypeVar) ',tvar (core Any))))
@@ -4270,8 +4276,8 @@ f(x) = yt(x)
42704276
`(call (core _typeof_captured_variable) ,ve)))
42714277
capt-vars var-exprs)))))
42724278
`(new ,(if (null? P)
4273-
type-name
4274-
`(call (core apply_type) ,type-name ,@P))
4279+
`(globalref (thismodule) ,type-name)
4280+
`(call (core apply_type) (globalref (thismodule) ,type-name) ,@P))
42754281
,@var-exprs))))
42764282
(if (pair? moved-vars)
42774283
(set-car! (lam:vinfo lam)

src/julia_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ jl_value_t *jl_code_or_ci_for_interpreter(jl_method_instance_t *lam JL_PROPAGATE
717717
int jl_code_requires_compiler(jl_code_info_t *src, int include_force_compile);
718718
jl_code_info_t *jl_new_code_info_from_ir(jl_expr_t *ast);
719719
JL_DLLEXPORT jl_code_info_t *jl_new_code_info_uninit(void);
720-
JL_DLLEXPORT void jl_resolve_globals_in_ir(jl_array_t *stmts, jl_module_t *m, jl_svec_t *sparam_vals,
721-
int binding_effects);
720+
JL_DLLEXPORT void jl_resolve_definition_effects_in_ir(jl_array_t *stmts, jl_module_t *m, jl_svec_t *sparam_vals,
721+
int binding_effects);
722722

723723
int get_next_edge(jl_array_t *list, int i, jl_value_t** invokesig, jl_code_instance_t **caller) JL_NOTSAFEPOINT;
724724
int set_next_edge(jl_array_t *list, int i, jl_value_t *invokesig, jl_code_instance_t *caller);

0 commit comments

Comments
 (0)