-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix functionloc #35138
Fix functionloc #35138
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,7 +231,7 @@ | |
(let ((type-ex (caddr m))) | ||
(if (eq? (car type-ex) 'block) | ||
;; extract ssavalue labels of sparams from the svec-of-sparams argument to `method` | ||
(let ((sp-ssavals (cddr (last (last type-ex))))) | ||
(let ((sp-ssavals (cddr (cadddr (last type-ex))))) | ||
(map (lambda (a) ;; extract T from (= v (call (core TypeVar) (quote T) ...)) | ||
(cadr (caddr (caddr a)))) | ||
(filter (lambda (e) | ||
|
@@ -293,6 +293,24 @@ | |
(define (non-generated-version body) | ||
(generated-part- body #f)) | ||
|
||
;; Remove and return the line number for the start of the function definition | ||
(define (maybe-remove-functionloc! body) | ||
(let* ((prologue (extract-method-prologue body)) | ||
(prologue-lnos (filter linenum? prologue)) | ||
(functionloc (if (pair? prologue-lnos) | ||
(car prologue-lnos) | ||
; Fallback - take first line anywhere in body | ||
(let ((lnos (filter linenum? body))) | ||
(if (null? lnos) '(line 0 none) (car lnos)))))) | ||
(if (length> prologue-lnos 1) | ||
; First of two line numbers in prologue is function definition location | ||
; which should be removed from the body. | ||
(let loop ((stmts body)) | ||
(if (eq? functionloc (cadr stmts)) | ||
(set-cdr! stmts (cddr stmts)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt like using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Taking into account that we'll need to return both the line number and the body if this is pure.) |
||
(loop (cdr body))))) | ||
functionloc)) | ||
|
||
;; construct the (method ...) expression for one primitive method definition, | ||
;; assuming optional and keyword args are already handled | ||
(define (method-def-expr- name sparams argl body (rett '(core Any))) | ||
|
@@ -328,12 +346,12 @@ | |
(error "function argument and static parameter names must be distinct")) | ||
(if (or (and name (not (sym-ref? name))) (not (valid-name? name))) | ||
(error (string "invalid function name \"" (deparse name) "\""))) | ||
(let* ((generator (if (expr-contains-p if-generated? body (lambda (x) (not (function-def? x)))) | ||
(let* ((loc (maybe-remove-functionloc! body)) | ||
(generator (if (expr-contains-p if-generated? body (lambda (x) (not (function-def? x)))) | ||
(let* ((gen (generated-version body)) | ||
(nongen (non-generated-version body)) | ||
(gname (symbol (string (gensy) "#" (current-julia-module-counter)))) | ||
(gf (make-generator-function gname names anames gen)) | ||
(loc (function-body-lineno body))) | ||
(gf (make-generator-function gname names anames gen))) | ||
(set! body (insert-after-meta | ||
nongen | ||
`((meta generated | ||
|
@@ -343,8 +361,8 @@ | |
,(if (null? sparams) | ||
'nothing | ||
(cons 'list (map car sparams))) | ||
,(if (null? loc) 0 (cadr loc)) | ||
(inert ,(if (null? loc) 'none (caddr loc))) | ||
,(cadr loc) | ||
(inert ,(caddr loc)) | ||
(false)))))) | ||
(list gf)) | ||
'())) | ||
|
@@ -356,7 +374,11 @@ | |
(renames (map cons names temps)) | ||
(mdef | ||
(if (null? sparams) | ||
`(method ,name (call (core svec) (call (core svec) ,@(dots->vararg types)) (call (core svec))) | ||
`(method ,name | ||
(call (core svec) | ||
(call (core svec) ,@(dots->vararg types)) | ||
(call (core svec)) | ||
(inert ,loc)) | ||
,body) | ||
`(method ,name | ||
(block | ||
|
@@ -377,7 +399,8 @@ | |
(map (lambda (ty) | ||
(replace-vars ty renames)) | ||
types))) | ||
(call (core svec) ,@temps))) | ||
(call (core svec) ,@temps) | ||
(inert ,loc))) | ||
,body)))) | ||
(if (or (symbol? name) (globalref? name)) | ||
`(block ,@generator (method ,name) ,mdef (unnecessary ,name)) ;; return the function | ||
|
@@ -793,10 +816,6 @@ | |
wheres) | ||
,(ctor-body body curlyargs sparams)))))) | ||
|
||
(define (function-body-lineno body) | ||
(let ((lnos (filter linenum? body))) | ||
(if (null? lnos) '() (car lnos)))) | ||
|
||
;; rewrite calls to `new( ... )` to `new` expressions on the appropriate | ||
;; type, determined by the containing constructor definition. | ||
(define (rewrite-ctor ctor Tname params field-names field-types) | ||
|
@@ -3021,9 +3040,12 @@ f(x) = yt(x) | |
(newtypes | ||
(if iskw | ||
`(,(car types) ,(cadr types) ,closure-type ,@(cdddr types)) | ||
`(,closure-type ,@(cdr types))))) | ||
`(call (core svec) (call (core svec) ,@newtypes) | ||
(call (core svec) ,@(append (cddr (cadddr te)) type-sp))))) | ||
`(,closure-type ,@(cdr types)))) | ||
(loc (caddddr te))) | ||
`(call (core svec) | ||
(call (core svec) ,@newtypes) | ||
(call (core svec) ,@(append (cddr (cadddr te)) type-sp)) | ||
,loc))) | ||
|
||
;; collect all toplevel-butfirst expressions inside `e`, and return | ||
;; (ex . stmts), where `ex` is the expression to evaluated and | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ DA:9,5 | |
DA:11,1 | ||
DA:12,1 | ||
DA:14,0 | ||
LH:6 | ||
LF:8 | ||
DA:17,1 | ||
LH:7 | ||
LF:9 | ||
end_of_record |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this coverage stuff for the reasons explained in the commit message: It seems like a workaround for an old bug #17442, and now we have this double-counting workaround which appears to be a workaround-workaround. So I just deleted this. I also found
coverageVisitStmt
a bit confusing so I added some comments above, which I hope correctly state what is going on.