Skip to content

Commit 1cd47c3

Browse files
authored
lowering: Remove outerref intermediate form (#54772)
The `outerref` form was added in c3eedce, but the renaming pass for them was removed two years later in c446444, without removing the form itself. As far as I can tell, today, `outerref` is essentially equivalent to `(globalref (thismodule) name)` (which was the original form, before outteref was introduced) because it just expands to a toplevel symbol. I don't think there remains any reason to keep this form after the renaming pass was removed and moreover it is confusing as one could reasonaly infer (as I did an incorrectly wrote in a comment) that `outerref` provides outer access, which it does not. This PR removes the form entirely and replaces them with an appropriate globalref.
1 parent ee542b6 commit 1cd47c3

File tree

4 files changed

+40
-51
lines changed

4 files changed

+40
-51
lines changed

src/ast.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ static value_t fl_nothrow_julia_global(fl_context_t *fl_ctx, value_t *args, uint
195195
mod = *(jl_module_t**)cv_data((cvalue_t*)ptr(argmod));
196196
JL_GC_PROMISE_ROOTED(mod);
197197
} else {
198-
(void)tosymbol(fl_ctx, argmod, "nothrow-julia-global");
199-
if (scmsym_to_julia(fl_ctx, argmod) != jl_thismodule_sym) {
198+
if (!iscons(argmod) || !issymbol(car_(argmod)) || scmsym_to_julia(fl_ctx, car_(argmod)) != jl_thismodule_sym) {
200199
lerrorf(fl_ctx, fl_ctx->ArgError, "nothrow-julia-global: Unknown globalref module kind");
201200
}
202201
}

src/ast.scm

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
(deparse-prefix-call (cadr e) (cddr e) #\( #\)))))
115115
(($ &) (if (and (pair? (cadr e))
116116
(not (memq (caadr e)
117-
'(outerref null true false tuple $ vect braces))))
117+
'(null true false tuple $ vect braces))))
118118
(string (car e) "(" (deparse (cadr e)) ")")
119119
(string (car e) (deparse (cadr e)))))
120120
((|::|) (if (length= e 2)
@@ -254,7 +254,6 @@
254254
((top) (deparse (cadr e)))
255255
((core) (string "Core." (deparse (cadr e))))
256256
((globalref) (string (deparse (cadr e)) "." (deparse-colon-dot (caddr e))))
257-
((outerref) (string (deparse (cadr e))))
258257
((ssavalue) (string "SSAValue(" (cadr e) ")"))
259258
((line) (if (length= e 2)
260259
(string "# line " (cadr e))
@@ -298,7 +297,7 @@
298297
;; predicates and accessors
299298

300299
(define (quoted? e)
301-
(memq (car e) '(quote top core globalref outerref line break inert meta inbounds inline noinline loopinfo)))
300+
(memq (car e) '(quote top core globalref line break inert meta inbounds inline noinline loopinfo)))
302301
(define (quotify e) `',e)
303302
(define (unquote e)
304303
(if (and (pair? e) (memq (car e) '(quote inert)))
@@ -393,9 +392,6 @@
393392
(define (globalref? e)
394393
(and (pair? e) (eq? (car e) 'globalref)))
395394

396-
(define (outerref? e)
397-
(and (pair? e) (eq? (car e) 'outerref)))
398-
399395
(define (nothing? e)
400396
(and (pair? e) (eq? (car e) 'null)))
401397

src/codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6395,7 +6395,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaidx_
63956395
else if (head == jl_method_sym) {
63966396
if (nargs == 1) {
63976397
jl_value_t *mn = args[0];
6398-
assert(jl_is_symbol(mn) || jl_is_slotnumber(mn));
6398+
assert(jl_is_symbol(mn) || jl_is_slotnumber(mn) || jl_is_globalref(mn));
63996399

64006400
Value *bp = NULL, *name;
64016401
jl_binding_t *bnd = NULL;

src/julia-syntax.scm

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@
229229
(let ((name (cadr m)))
230230
(let ((name (if (or (length= m 2) (not (pair? name)) (not (quoted? name))) name (cadr name))))
231231
(cond ((not (pair? name)) name)
232-
((eq? (car name) 'outerref) (cadr name))
233-
;((eq? (car name) 'globalref) (caddr name))
232+
((eq? (car name) 'globalref) (caddr name))
234233
(else name)))))
235234

236235
;; extract static parameter names from a (method ...) expression
@@ -248,8 +247,7 @@
248247

249248
(define (nodot-sym-ref? e)
250249
(or (symbol? e)
251-
(and (length= e 3) (eq? (car e) 'globalref))
252-
(and (length= e 2) (eq? (car e) 'outerref))))
250+
(and (length= e 3) (eq? (car e) 'globalref))))
253251

254252
;; expressions of the form a.b.c... where everything is a symbol
255253
(define (sym-ref? e)
@@ -764,7 +762,7 @@
764762
,@(map make-decl field-names field-types))
765763
(block
766764
,@locs
767-
(new (outerref ,name) ,@field-names)))
765+
(new (globalref (thismodule) ,name) ,@field-names)))
768766
#f))
769767
(any-ctor (if (or (not all-ctor) (any (lambda (t) (not (equal? t '(core Any))))
770768
field-types))
@@ -816,10 +814,10 @@
816814
(if (> nnv (length params))
817815
(error "too many type parameters specified in \"new{...}\"")))
818816
(let* ((Texpr (if (null? type-params)
819-
`(outerref ,Tname)
817+
`(globalref (thismodule) ,Tname)
820818
(if selftype?
821819
'|#ctor-self#|
822-
`(curly (outerref ,Tname)
820+
`(curly (globalref (thismodule) ,Tname)
823821
,@type-params))))
824822
(tn (if (symbol? Texpr) Texpr (make-ssavalue)))
825823
(field-convert (lambda (fld fty val)
@@ -994,15 +992,15 @@
994992
(local-def ,name)
995993
,@(map (lambda (v) `(local ,v)) params)
996994
,@(map (lambda (n v) (make-assignment n (bounds-to-TypeVar v #t))) params bounds)
997-
(toplevel-only struct (outerref ,name))
995+
(toplevel-only struct (globalref (thismodule) ,name))
998996
(= ,name (call (core _structtype) (thismodule) (inert ,name) (call (core svec) ,@params)
999997
(call (core svec) ,@(map quotify field-names))
1000998
(call (core svec) ,@attrs)
1001999
,mut ,min-initialized))
10021000
(call (core _setsuper!) ,name ,super)
1003-
(if (isdefined (outerref ,name))
1001+
(if (isdefined (globalref (thismodule) ,name))
10041002
(block
1005-
(= ,prev (outerref ,name))
1003+
(= ,prev (globalref (thismodule) ,name))
10061004
(if (call (core _equiv_typedef) ,prev ,name)
10071005
;; if this is compatible with an old definition, use the existing type object
10081006
;; and its parameters
@@ -1015,8 +1013,8 @@
10151013
(quote parameters))))
10161014
'()))
10171015
;; otherwise do an assignment to trigger an error
1018-
(= (outerref ,name) ,name)))
1019-
(= (outerref ,name) ,name))
1016+
(= (globalref (thismodule) ,name) ,name)))
1017+
(= (globalref (thismodule) ,name) ,name))
10201018
(call (core _typebody!) ,name (call (core svec) ,@field-types))
10211019
(null)))
10221020
;; "inner" constructors
@@ -1063,10 +1061,10 @@
10631061
(= ,name (call (core _abstracttype) (thismodule) (inert ,name) (call (core svec) ,@params)))
10641062
(call (core _setsuper!) ,name ,super)
10651063
(call (core _typebody!) ,name)
1066-
(if (&& (isdefined (outerref ,name))
1067-
(call (core _equiv_typedef) (outerref ,name) ,name))
1064+
(if (&& (isdefined (globalref (thismodule) ,name))
1065+
(call (core _equiv_typedef) (globalref (thismodule) ,name) ,name))
10681066
(null)
1069-
(= (outerref ,name) ,name))
1067+
(= (globalref (thismodule) ,name) ,name))
10701068
(null))))))
10711069

10721070
(define (primitive-type-def-expr n name params super)
@@ -1083,10 +1081,10 @@
10831081
(= ,name (call (core _primitivetype) (thismodule) (inert ,name) (call (core svec) ,@params) ,n))
10841082
(call (core _setsuper!) ,name ,super)
10851083
(call (core _typebody!) ,name)
1086-
(if (&& (isdefined (outerref ,name))
1087-
(call (core _equiv_typedef) (outerref ,name) ,name))
1084+
(if (&& (isdefined (globalref (thismodule) ,name))
1085+
(call (core _equiv_typedef) (globalref (thismodule) ,name) ,name))
10881086
(null)
1089-
(= (outerref ,name) ,name))
1087+
(= (globalref (thismodule) ,name) ,name))
10901088
(null))))))
10911089

10921090
;; take apart a type signature, e.g. T{X} <: S{Y}
@@ -2371,7 +2369,7 @@
23712369
`(= ,lhs ,rhs)))
23722370

23732371
(define (expand-forms e)
2374-
(if (or (atom? e) (memq (car e) '(quote inert top core globalref outerref module toplevel ssavalue null true false meta using import export public thismodule toplevel-only)))
2372+
(if (or (atom? e) (memq (car e) '(quote inert top core globalref module toplevel ssavalue null true false meta using import export public thismodule toplevel-only)))
23752373
e
23762374
(let ((ex (get expand-table (car e) #f)))
23772375
(if ex
@@ -2502,7 +2500,7 @@
25022500
lhss)
25032501
(unnecessary ,rr)))))))
25042502
((or (and (symbol-like? lhs) (valid-name? lhs))
2505-
(globalref? lhs) (outerref? lhs))
2503+
(globalref? lhs))
25062504
(sink-assignment lhs (expand-forms (caddr e))))
25072505
((atom? lhs)
25082506
(error (string "invalid assignment location \"" (deparse lhs) "\"")))
@@ -2968,7 +2966,7 @@
29682966
((=)
29692967
(let ((v (decl-var (cadr e))))
29702968
(find-assigned-vars- (caddr e))
2971-
(if (or (ssavalue? v) (globalref? v) (outerref? v) (underscore-symbol? v))
2969+
(if (or (ssavalue? v) (globalref? v) (underscore-symbol? v))
29722970
'()
29732971
(set! vars (cons v vars)))))
29742972
(else
@@ -3016,7 +3014,7 @@
30163014
(for-each (lambda (v) (push-var! tab v v)) sp)
30173015
(for-each (lambda (v) (push-var! tab v v)) locals)
30183016
(for-each (lambda (pair) (push-var! tab (car pair) (cdr pair))) renames)
3019-
(for-each (lambda (v) (push-var! tab v `(outerref ,v))) globals)
3017+
(for-each (lambda (v) (push-var! tab v `(globalref (thismodule) ,v))) globals)
30203018
(for-each (lambda (v) (push-var! tab v v)) args)
30213019
(vector lam args locals globals sp renames prev soft? hard? implicit-globals warn-vars tab)))
30223020

@@ -3080,7 +3078,7 @@
30803078
(let ((val (and scope (get (scope:table scope) e #f))))
30813079
(cond (val (car val))
30823080
((underscore-symbol? e) e)
3083-
(else `(outerref ,e)))))
3081+
(else `(globalref (thismodule) ,e)))))
30843082
((or (not (pair? e)) (quoted? e) (memq (car e) '(toplevel symbolicgoto symboliclabel toplevel-only)))
30853083
e)
30863084
((eq? (car e) 'global)
@@ -3090,6 +3088,9 @@
30903088
(check-valid-name (cadr e))
30913089
;; remove local decls
30923090
'(null))
3091+
((memq (car e) '(using import export public))
3092+
;; no scope resolution - identifiers remain raw symbols
3093+
e)
30933094
((eq? (car e) 'require-existing-local)
30943095
(if (not (in-scope? (cadr e) scope))
30953096
(error "no outer local variable declaration exists for \"for outer\""))
@@ -3268,7 +3269,7 @@
32683269
(define (free-vars- e tab)
32693270
(cond ((or (eq? e UNUSED) (underscore-symbol? e)) tab)
32703271
((symbol? e) (put! tab e #t))
3271-
((and (pair? e) (eq? (car e) 'outerref)) tab)
3272+
((and (pair? e) (eq? (car e) 'globalref)) tab)
32723273
((and (pair? e) (eq? (car e) 'break-block)) (free-vars- (caddr e) tab))
32733274
((and (pair? e) (eq? (car e) 'with-static-parameters)) (free-vars- (cadr e) tab))
32743275
((or (atom? e) (quoted? e)) tab)
@@ -3440,7 +3441,7 @@ f(x) = yt(x)
34403441
(call (core svec))
34413442
(false) ,(length fields)))
34423443
(call (core _setsuper!) ,s ,super)
3443-
(= (outerref ,name) ,s)
3444+
(= (globalref (thismodule) ,name) ,s)
34443445
(call (core _typebody!) ,s (call (core svec) ,@types))
34453446
(return (null)))))))))
34463447

@@ -3454,7 +3455,7 @@ f(x) = yt(x)
34543455
(call (core svec))
34553456
(false) ,(length fields)))
34563457
(call (core _setsuper!) ,s ,super)
3457-
(= (outerref ,name) ,s)
3458+
(= (globalref (thismodule) ,name) ,s)
34583459
(call (core _typebody!) ,s
34593460
(call (core svec) ,@(map (lambda (v) '(core Box)) fields)))
34603461
(return (null)))))))))
@@ -3599,7 +3600,7 @@ f(x) = yt(x)
35993600
`(block (= ,rhs1 ,rhs0)
36003601
,ex
36013602
,rhs1))))))
3602-
((or (outerref? var) (globalref? var))
3603+
((globalref? var)
36033604
(convert-global-assignment var rhs0 globals lam))
36043605
((ssavalue? var)
36053606
`(= ,var ,rhs0))
@@ -3710,7 +3711,7 @@ f(x) = yt(x)
37103711
(Set '(quote top core lineinfo line inert local-def unnecessary copyast
37113712
meta inbounds boundscheck loopinfo decl aliasscope popaliasscope
37123713
thunk with-static-parameters toplevel-only
3713-
global globalref outerref const-if-global thismodule
3714+
global globalref const-if-global thismodule
37143715
const atomic null true false ssavalue isdefined toplevel module lambda
37153716
error gc_preserve_begin gc_preserve_end import using export public inline noinline purity)))
37163717

@@ -3935,7 +3936,7 @@ f(x) = yt(x)
39353936
((atom? e) e)
39363937
(else
39373938
(case (car e)
3938-
((quote top core globalref outerref thismodule lineinfo line break inert module toplevel null true false meta) e)
3939+
((quote top core globalref thismodule lineinfo line break inert module toplevel null true false meta) e)
39393940
((toplevel-only)
39403941
;; hack to avoid generating a (method x) expr for struct types
39413942
(if (eq? (cadr e) 'struct)
@@ -4008,7 +4009,7 @@ f(x) = yt(x)
40084009
(vis (if short '(() () ()) (lam:vinfo lam2)))
40094010
(cvs (map car (cadr vis)))
40104011
(local? (lambda (s) (and lam (symbol? s) (local-in? s lam locals))))
4011-
(local (and (not (outerref? (cadr e))) (local? name)))
4012+
(local (and (not (globalref? (cadr e))) (local? name)))
40124013
(sig (and (not short) (caddr e)))
40134014
(sp-inits (if (or short (not (eq? (car sig) 'block)))
40144015
'()
@@ -4257,11 +4258,8 @@ f(x) = yt(x)
42574258
(else (for-each linearize (cdr e))))
42584259
e)
42594260

4260-
;; N.B.: This assumes that resolve-scopes has run, so outerref is equivalent to
4261-
;; a global in the current scope.
42624261
(define (valid-ir-argument? e)
42634262
(or (simple-atom? e)
4264-
(and (outerref? e) (nothrow-julia-global (cadr e)))
42654263
(and (globalref? e) (nothrow-julia-global (cadr e) (caddr e)))
42664264
(and (pair? e)
42674265
(memq (car e) '(quote inert top core
@@ -4271,7 +4269,7 @@ f(x) = yt(x)
42714269
(or (ssavalue? lhs)
42724270
(valid-ir-argument? e)
42734271
(and (symbol? lhs) (pair? e)
4274-
(memq (car e) '(new splatnew the_exception isdefined call invoke foreigncall cfunction gc_preserve_begin copyast new_opaque_closure globalref outerref)))))
4272+
(memq (car e) '(new splatnew the_exception isdefined call invoke foreigncall cfunction gc_preserve_begin copyast new_opaque_closure globalref)))))
42754273

42764274
(define (valid-ir-return? e)
42774275
;; returning lambda directly is needed for @generated
@@ -4458,7 +4456,7 @@ f(x) = yt(x)
44584456
;; left-to-right evaluation semantics.
44594457
(let ((simple? (every (lambda (x) (or (simple-atom? x) (symbol? x)
44604458
(and (pair? x)
4461-
(memq (car x) '(quote inert top core globalref outerref)))))
4459+
(memq (car x) '(quote inert top core globalref)))))
44624460
lst)))
44634461
(let loop ((lst lst)
44644462
(vals '()))
@@ -4528,19 +4526,17 @@ f(x) = yt(x)
45284526
;; from the current function.
45294527
(define (compile e break-labels value tail)
45304528
(if (or (not (pair? e)) (memq (car e) '(null true false ssavalue quote inert top core copyast the_exception $
4531-
globalref outerref thismodule cdecl stdcall fastcall thiscall llvmcall)))
4529+
globalref thismodule cdecl stdcall fastcall thiscall llvmcall)))
45324530
(let ((e1 (if (and arg-map (symbol? e))
45334531
(get arg-map e e)
45344532
e)))
45354533
(if (and value (or (underscore-symbol? e)
4536-
(and (pair? e) (or (eq? (car e) 'outerref)
4537-
(eq? (car e) 'globalref))
4534+
(and (pair? e) (eq? (car e) 'globalref)
45384535
(underscore-symbol? (cadr e)))))
45394536
(error (string "all-underscore identifiers are write-only and their values cannot be used in expressions" (format-loc current-loc))))
45404537
(cond (tail (emit-return tail e1))
45414538
(value e1)
45424539
((symbol? e1) (emit e1) #f) ;; keep symbols for undefined-var checking
4543-
((and (pair? e1) (eq? (car e1) 'outerref)) (emit e1) #f) ;; keep globals for undefined-var checking
45444540
((and (pair? e1) (eq? (car e1) 'globalref)) (emit e1) #f) ;; keep globals for undefined-var checking
45454541
(else #f)))
45464542
(case (car e)
@@ -4574,7 +4570,7 @@ f(x) = yt(x)
45744570
;; NOTE: 1st argument to cglobal treated same as for ccall
45754571
((and (length> e 2)
45764572
(or (eq? (cadr e) 'cglobal)
4577-
(equal? (cadr e) '(outerref cglobal))))
4573+
(equal? (cadr e) '(globalref (thismodule) cglobal))))
45784574
(append (list (cadr e))
45794575
(if (atom-or-not-tuple-call? (caddr e))
45804576
(compile-args (list (caddr e)) break-labels)
@@ -5125,8 +5121,6 @@ f(x) = yt(x)
51255121
(if idx
51265122
`(static_parameter ,idx)
51275123
e)))))
5128-
((and (pair? e) (eq? (car e) 'outerref))
5129-
(cadr e))
51305124
((nospecialize-meta? e)
51315125
;; convert nospecialize vars to slot numbers
51325126
`(meta ,(cadr e) ,@(map renumber-stuff (cddr e))))

0 commit comments

Comments
 (0)