Skip to content

Commit 3f2213f

Browse files
committed
lower prologue attributes to the kwarg function definition sans keywords
1 parent fbf18de commit 3f2213f

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

base/irrationals.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ end
6464
@pure function rationalize{T<:Integer}(::Type{T}, x::Irrational; tol::Real=0)
6565
return rationalize(T, big(x), tol=tol)
6666
end
67-
@pure function rationalize{T<:Integer}(::Type{T}, x::Irrational)
68-
return rationalize(T, big(x), tol=0)
69-
end
7067
@pure function lessrational{T<:Integer}(rx::Rational{T}, x::Irrational)
7168
# an @pure version of `<` for determining if the rationalization of
7269
# an irrational number required rounding up or down

src/julia-syntax.scm

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,10 @@
403403
(lambda (x) (eq? x v))
404404
vals))
405405
keynames))
406-
;; 1-element list of function's line number node, or empty if none
407-
(lno (if (and (pair? (cdr body))
408-
(pair? (cadr body)) (eq? (caadr body) 'line))
409-
(list (cadr body))
410-
'()))
411-
;; body statements, minus line number node
412-
(stmts (if (null? lno) (cdr body) (cddr body)))
406+
;; list of function's initial line number and meta nodes (empty if none)
407+
(prologue (extract-method-prologue body))
408+
;; body statements
409+
(stmts (cdr body))
413410
(positional-sparams
414411
(filter (lambda (s)
415412
(let ((name (if (symbol? s) s (cadr s))))
@@ -434,12 +431,12 @@
434431
,(method-def-expr-
435432
name positional-sparams (append pargl vararg)
436433
`(block
437-
,@lno
434+
,@prologue
438435
,@(if (not ordered-defaults)
439436
'()
440437
(append! (map (lambda (kwname) `(local ,kwname)) keynames)
441438
(map make-assignment keynames vals)))
442-
;; call mangled(vals..., [rest_kw ,]pargs..., [vararg]...)
439+
;; call mangled(vals..., [rest_kw,] pargs..., [vararg]...)
443440
(return (call ,mangled
444441
,@(if ordered-defaults keynames vals)
445442
,@(if (null? restkw) '() (list empty-vector-any))
@@ -463,7 +460,6 @@
463460
(car not-optional))
464461
,@(cdr not-optional) ,@vararg)
465462
`(block
466-
,@lno
467463
,@stmts) isstaged rett)
468464

469465
;; call with unsorted keyword args. this sorts and re-dispatches.
@@ -550,13 +546,16 @@
550546
,(if (or (not (symbol? name)) (is-call-name? name))
551547
'(null) name)))))
552548

549+
;; prologue includes line number node and eventual meta nodes
550+
(define (extract-method-prologue body)
551+
(if (pair? body)
552+
(take-while (lambda (e)
553+
(and (pair? e) (or (eq? (car e) 'line) (eq? (car e) 'meta))))
554+
(cdr body))
555+
'()))
556+
553557
(define (optional-positional-defs name sparams req opt dfl body isstaged overall-argl rett)
554-
;; prologue includes line number node and eventual meta nodes
555-
(let ((prologue (if (pair? body)
556-
(take-while (lambda (e)
557-
(and (pair? e) (or (eq? (car e) 'line) (eq? (car e) 'meta))))
558-
(cdr body))
559-
'())))
558+
(let ((prologue (extract-method-prologue body)))
560559
`(block
561560
,@(map (lambda (n)
562561
(let* ((passed (append req (list-head opt n)))

test/inference.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,20 @@ f18450() = ifelse(true, Tuple{Vararg{Int}}, Tuple{Vararg})
371371

372372
# issue #18569
373373
@test Core.Inference.isconstType(Type{Tuple},true)
374+
375+
# ensure pure attribute applies correctly to all signatures of fpure
376+
Base.@pure function fpure(a=rand(); b=rand())
377+
# use the `rand` function since it is known to be `@inline`
378+
# but would be too big to inline
379+
return a + b + rand()
380+
end
381+
gpure() = fpure()
382+
gpure(x::Irrational) = fpure(x)
383+
@test which(fpure, ()).source.pure
384+
@test which(fpure, (typeof(pi),)).source.pure
385+
@test !which(gpure, ()).source.pure
386+
@test !which(gpure, (typeof(pi),)).source.pure
387+
@test @code_typed(gpure())[1].pure
388+
@test @code_typed(gpure(π))[1].pure
389+
@test gpure() == gpure() == gpure()
390+
@test gpure(π) == gpure(π) == gpure(π)

0 commit comments

Comments
 (0)