Skip to content

Commit e418e4c

Browse files
committed
lowering: Only try to define the method once
Before: ``` :($(Expr(:thunk, CodeInfo( 1 ─ $(Expr(:thunk, CodeInfo( 1 ─ return $(Expr(:method, :(Main.f))) ))) │ $(Expr(:method, :(Main.f))) │ %3 = Main.f │ %4 = dynamic Core.Typeof(%3) │ %5 = builtin Core.svec(%4, Core.Any) │ %6 = builtin Core.svec() │ %7 = builtin Core.svec(%5, %6, $(QuoteNode(:(#= REPL[2]:1 =#)))) │ $(Expr(:method, :(Main.f), :(%7), CodeInfo( 1 ─ return 1 ))) │ $(Expr(:latestworld)) │ %10 = Main.f └── return %10 )))) ``` After: ``` julia> @Meta.lower f(x)=1 :($(Expr(:thunk, CodeInfo( 1 ─ $(Expr(:method, :(Main.f))) │ $(Expr(:latestworld)) │ Main.f │ $(Expr(:latestworld)) │ %5 = Main.f │ %6 = dynamic Core.Typeof(%5) │ %7 = builtin Core.svec(%6, Core.Any) │ %8 = builtin Core.svec() │ %9 = builtin Core.svec(%7, %8, $(QuoteNode(:(#= REPL[1]:1 =#)))) │ $(Expr(:method, :(Main.f), :(%9), CodeInfo( 1 ─ return 1 ))) │ $(Expr(:latestworld)) │ %12 = Main.f └── return %12 )))) ``` This doesn't really make a semantic difference, but if `f` is a type, we may now give a warning, so the prior definition would give the warning twice (#57311 (comment)). We may want to consider rate-limiting the warning independently, but for now at least give the correct number of warnings.
1 parent 866c61d commit e418e4c

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

doc/src/manual/modules.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ julia> nice(::Cat) = "nice 😸"
192192
ERROR: invalid method definition in Main: function NiceStuff.nice must be explicitly imported to be extended
193193
Stacktrace:
194194
[1] top-level scope
195-
@ none:0
196-
[2] top-level scope
197195
@ none:1
198196
```
199197

src/julia-syntax.scm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4131,8 +4131,9 @@ f(x) = yt(x)
41314131
`(toplevel-butfirst
41324132
;; wrap in toplevel-butfirst so it gets moved higher along with
41334133
;; closure type definitions
4134+
(unnecessary ,(cadr e))
41344135
,e
4135-
(thunk (lambda () (() () 0 ()) (block (return ,e))))))))
4136+
(latestworld)))))
41364137
((null? cvs)
41374138
`(block
41384139
,@sp-inits

0 commit comments

Comments
 (0)