Support const args in type dependent paths#71154
Closed
lcnr wants to merge 14 commits intorust-lang:masterfrom
Closed
Support const args in type dependent paths#71154lcnr wants to merge 14 commits intorust-lang:masterfrom
lcnr wants to merge 14 commits intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When calling
type_offor generic const arguments, we now use theTypeckTablesof the surrounding body to get the expected type.This alone causes cycle errors though, as we now have
typeck_tables_of(main)->...->type_of(main_ANON0 := 7)->typeck_tables_of(main)⚡ (see #68400 (comment))To prevent this we must not call
type_of(const_arg)duringtypeck_tables_of. This is achieved bycalling
type_of(param_def_id)instead. As thisDefIdcan't always be easily known, I changed someDefIds toty::WithOptParam<DefId>which contains the relevant param id. This also changes some queries which may be called during typeck.To prevent us from computing these queries twice,
WithOptParammust always use the correctDefIdof the parameter. This means that it is either constructed using the new methodtcx.with_opt_param(def_id)or manually if and only if a paramDefIdis available.To simplify
WithOptParamcreation, I changedIntoQueryParamfrom private topub(crate).I only use the existing definition of
LocalDefId -> DefId.const_param_ofrequires the HIR, meaning that it can only return the correct parameterDefIdwhile compiling the crate containing the const argument.To fix this,
const_param_ofis called for all const arguments during analysis. (I currently usepar_body_ownerhere, as all const arguments should be a body afaik)This PR may have missed some
type_of(const_arg)during typeck. While this is unfortunate, these cases should only introduce cycle errors and not lead to miscompilations.We should not have to worry about these cases while merging this IMO.
r? @varkor
fixes #70507, fixes #69816, fixes #63695, fixes #61936, fixes #71516