Commit 52e14cc
authored
Don't create a type parameter in the closure for captured @nospecialize arguments (JuliaLang#58426)
When we capture a variable without boxing, we always generate a type
parameter for the closure. This probably isn't what the user wants if
the captured variable is an argument marked `@nospecialize`.
Before:
```
julia> K(@nospecialize(x)) = @nospecialize(y) -> x
K (generic function with 1 method)
julia> f, g = K(1), K("a")
(var"#K##0#K##1"{Int64}(1), var"#K##0#K##1"{String}("a"))
julia> f(2), g(2)
(1, "a")
julia> methods(f)[1].specializations
svec(MethodInstance for (::var"#K##0#K##1"{Int64})(::Any), MethodInstance for (::var"#K##0#K##1"{String})(::Any), nothing, nothing, nothing, nothing, nothing)
julia> fieldtypes(typeof(f)), fieldtypes(typeof(g))
((Int64,), (String,))
```
After:
```
julia> K(@nospecialize(x)) = @nospecialize(y) -> x
K (generic function with 1 method)
julia> f, g = K(1), K("a")
(var"#K##0#K##1"(1), var"#K##0#K##1"("a"))
julia> f(2), g(2)
(1, "a")
julia> methods(f)[1].specializations
MethodInstance for (::var"#K##0#K##1")(::Any)
julia> fieldtypes(typeof(f)), fieldtypes(typeof(g))
((Any,), (Any,))
```1 parent 34070fa commit 52e14cc
3 files changed
+29
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
| 496 | + | |
496 | 497 | | |
497 | 498 | | |
498 | 499 | | |
| |||
507 | 508 | | |
508 | 509 | | |
509 | 510 | | |
| 511 | + | |
510 | 512 | | |
511 | 513 | | |
512 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3492 | 3492 | | |
3493 | 3493 | | |
3494 | 3494 | | |
3495 | | - | |
3496 | | - | |
3497 | | - | |
3498 | | - | |
| 3495 | + | |
| 3496 | + | |
| 3497 | + | |
| 3498 | + | |
| 3499 | + | |
| 3500 | + | |
| 3501 | + | |
| 3502 | + | |
| 3503 | + | |
3499 | 3504 | | |
3500 | 3505 | | |
3501 | 3506 | | |
| |||
3594 | 3599 | | |
3595 | 3600 | | |
3596 | 3601 | | |
3597 | | - | |
3598 | | - | |
3599 | | - | |
3600 | | - | |
3601 | | - | |
3602 | | - | |
3603 | | - | |
3604 | | - | |
3605 | | - | |
3606 | | - | |
3607 | | - | |
3608 | | - | |
3609 | | - | |
3610 | | - | |
3611 | | - | |
3612 | 3602 | | |
3613 | 3603 | | |
3614 | 3604 | | |
| |||
4022 | 4012 | | |
4023 | 4013 | | |
4024 | 4014 | | |
| 4015 | + | |
| 4016 | + | |
| 4017 | + | |
| 4018 | + | |
4025 | 4019 | | |
4026 | 4020 | | |
4027 | 4021 | | |
| |||
4313 | 4307 | | |
4314 | 4308 | | |
4315 | 4309 | | |
4316 | | - | |
4317 | | - | |
4318 | | - | |
| 4310 | + | |
| 4311 | + | |
| 4312 | + | |
4319 | 4313 | | |
4320 | 4314 | | |
4321 | 4315 | | |
4322 | 4316 | | |
4323 | | - | |
4324 | | - | |
4325 | | - | |
| 4317 | + | |
4326 | 4318 | | |
4327 | 4319 | | |
4328 | 4320 | | |
| |||
4352 | 4344 | | |
4353 | 4345 | | |
4354 | 4346 | | |
4355 | | - | |
| 4347 | + | |
4356 | 4348 | | |
4357 | 4349 | | |
4358 | 4350 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4330 | 4330 | | |
4331 | 4331 | | |
4332 | 4332 | | |
| 4333 | + | |
| 4334 | + | |
| 4335 | + | |
| 4336 | + | |
| 4337 | + | |
| 4338 | + | |
| 4339 | + | |
| 4340 | + | |
| 4341 | + | |
0 commit comments