Skip to content

Commit

Permalink
lowering: Only try to define the method once
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Keno committed Feb 10, 2025
1 parent 8c62f42 commit f3ab146
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4131,8 +4131,9 @@ f(x) = yt(x)
`(toplevel-butfirst
;; wrap in toplevel-butfirst so it gets moved higher along with
;; closure type definitions
,(cadr e)
,e
(thunk (lambda () (() () 0 ()) (block (return ,e))))))))
(latestworld)))))
((null? cvs)
`(block
,@sp-inits
Expand Down

0 comments on commit f3ab146

Please sign in to comment.