Skip to content

make preference loading a bit more type stable#38285

Merged
KristofferC merged 3 commits intomasterfrom
kc/stability_preferences
Nov 3, 2020
Merged

make preference loading a bit more type stable#38285
KristofferC merged 3 commits intomasterfrom
kc/stability_preferences

Conversation

@KristofferC
Copy link
Copy Markdown
Member

Also, while at it:

  • Use get(f, d, v) instead of get(d, v, f()) in some places
  • Use get instead of haskey + reindex.

Comment thread base/loading.jl
end

function collect_preferences!(project_toml::String, uuid::UUID)
function collect_preferences(project_toml::String, uuid::UUID)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be a mutating operation but that got rebased out I suppose. Good catch!

Comment thread base/loading.jl
Comment thread base/loading.jl Outdated
new_base = Base._typeddict(base, overrides...)

for override in overrides
override isa Dict{String, Any} || continue # error here?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've constrained overrides already, I don't think this check is necessary.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, agree.

Comment thread base/loading.jl
get_compiletime_preferences(uuid::UUID) = collect(get(COMPILETIME_PREFERENCES, uuid, String[]))
get_compiletime_preferences(uuid::UUID) = collect(get(Vector{String}, COMPILETIME_PREFERENCES, uuid))
get_compiletime_preferences(m::Module) = get_compiletime_preferences(PkgId(m).uuid)
get_compiletime_preferences(::Nothing) = String[]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use nothing as a sentinel value anymore, so you can drop the ::Nothing method here as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like it: https://build.julialang.org/#/builders/20/builds/5814/steps/7/logs/stdio. It happens when PkgId(m) doesn't identify a uuid, just a name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good call. Thank God for tests!

Comment thread base/loading.jl
end

get_preferences_hash(m::Module, prefs_list::Vector{String}) = get_preferences_hash(PkgId(m).uuid, prefs_list)
get_preferences_hash(::Nothing, prefs_list::Vector{String}) = UInt64(0x6e65726566657250)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is quite valuable to have you comb over this after me, because I forget that I have eliminated the nothing sentinel value from the control flow.

Copy link
Copy Markdown
Member

@timholy timholy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment on the functionality the way @staticfloat can, but the inference improvements seem solid 👍

Comment thread base/loading.jl
timholy added a commit that referenced this pull request Nov 3, 2020
Aside from the preferences system (xref #38285) and TOML parsing,
these appear to trigger the only remaining sources of vulnerability to
invalidation of `Base.require` among Julia's *exported* names,
which are the main names we can expect to be specialized by packages.
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.

3 participants