Skip to content

Improve type-stability in reconstruct#160

Open
jishnub wants to merge 3 commits intomauro3:masterfrom
jishnub:jishnub/reconstruct_type_stability
Open

Improve type-stability in reconstruct#160
jishnub wants to merge 3 commits intomauro3:masterfrom
jishnub:jishnub/reconstruct_type_stability

Conversation

@jishnub
Copy link
Copy Markdown

@jishnub jishnub commented Jan 23, 2026

On master

julia> @with_kw struct A
       a::Int
       b::String
       end
A

julia> a = A(1, "a")
A
  a: Int64 1
  b: String "a"

julia> @code_warntype A(a)
MethodInstance for A(::A)
  from A(pp::A; kws...) @ Main ~/Dropbox/JuliaPackages/Parameters.jl/src/Parameters.jl:571
Arguments
  #self#::Core.Const(A)
  pp::A
Body::Any
1%1 = Main.:(var"#A#5")::Core.Const(Main.var"#A#5")
│   %2 = Core.NamedTuple()::Core.Const(NamedTuple())
│   %3 = Base.pairs(%2)::Core.Const(Base.Pairs{Symbol, Union{}, Nothing, @NamedTuple{}}())
│   %4 = (%1)(%3, #self#, pp)::Any
└──      return %4

This PR uses a tuple of fields to construct the type, so we obtain

julia> @code_warntype A(a)
MethodInstance for A(::A)
  from A(pp::A; kws...) @ Main ~/Dropbox/JuliaPackages/Parameters.jl/src/Parameters.jl:571
Arguments
  #self#::Core.Const(A)
  pp::A
Body::A
1%1 = Main.:(var"#A#5")::Core.Const(Main.var"#A#5")
│   %2 = Core.NamedTuple()::Core.Const(NamedTuple())
│   %3 = Base.pairs(%2)::Core.Const(Base.Pairs{Symbol, Union{}, Nothing, @NamedTuple{}}())
│   %4 = (%1)(%3, #self#, pp)::A
└──      return %4

The return type is inferred in this case.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.75%. Comparing base (501b47b) to head (d80e84f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #160   +/-   ##
=======================================
  Coverage   93.75%   93.75%           
=======================================
  Files           1        1           
  Lines         304      304           
=======================================
  Hits          285      285           
  Misses         19       19           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant