Skip to content
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

make preference loading a bit more type stable #38285

Merged
merged 3 commits into from
Nov 3, 2020

Conversation

KristofferC
Copy link
Sponsor 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.

@@ -1556,7 +1557,7 @@ function get_uuid_name(project_toml::String, uuid::UUID)
return get_uuid_name(project, uuid)
end

function collect_preferences!(project_toml::String, uuid::UUID)
function collect_preferences(project_toml::String, uuid::UUID)
Copy link
Sponsor 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!

base/loading.jl Show resolved Hide resolved
base/loading.jl Outdated
new_base = Base._typeddict(base, overrides...)

for override in overrides
override isa Dict{String, Any} || continue # error here?
Copy link
Sponsor 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
Sponsor 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.

return nothing
end
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
Sponsor 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
Sponsor 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
Sponsor 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!

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
Sponsor 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
Sponsor 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 👍

base/loading.jl Show resolved Hide resolved
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.

None yet

3 participants