Skip to content

Commit 6bacf5a

Browse files
committed
Auto merge of #111798 - GuillaumeGomez:rollup-t3bus8o, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #111450 (Use `OpaqueTypeKey` in query response) - #111726 (Migrate GUI colors test to original CSS color format) - #111746 (Merge some query impl modules into one) - #111765 (Migrate GUI colors test to original CSS color format) - #111771 (add `--remote-time` flag to curl for bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4eb5225 + a6ebaf8 commit 6bacf5a

File tree

8 files changed

+180
-182
lines changed

8 files changed

+180
-182
lines changed

compiler/rustc_infer/src/infer/canonical/query_response.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,22 @@ impl<'tcx> InferCtxt<'tcx> {
153153

154154
/// Used by the new solver as that one takes the opaque types at the end of a probe
155155
/// to deal with multiple candidates without having to recompute them.
156-
pub fn clone_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
156+
pub fn clone_opaque_types_for_query_response(
157+
&self,
158+
) -> Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)> {
157159
self.inner
158160
.borrow()
159161
.opaque_type_storage
160162
.opaque_types
161163
.iter()
162-
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty))
164+
.map(|(k, v)| (*k, v.hidden_type.ty))
163165
.collect()
164166
}
165167

166-
fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
168+
fn take_opaque_types_for_query_response(&self) -> Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)> {
167169
std::mem::take(&mut self.inner.borrow_mut().opaque_type_storage.opaque_types)
168170
.into_iter()
169-
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty))
171+
.map(|(k, v)| (k, v.hidden_type.ty))
170172
.collect()
171173
}
172174

@@ -507,8 +509,22 @@ impl<'tcx> InferCtxt<'tcx> {
507509
let a = substitute_value(self.tcx, &result_subst, a);
508510
let b = substitute_value(self.tcx, &result_subst, b);
509511
debug!(?a, ?b, "constrain opaque type");
510-
obligations
511-
.extend(self.at(cause, param_env).eq(DefineOpaqueTypes::Yes, a, b)?.obligations);
512+
// We use equate here instead of, for example, just registering the
513+
// opaque type's hidden value directly, because we may be instantiating
514+
// a query response that was canonicalized in an InferCtxt that had
515+
// a different defining anchor. In that case, we may have inferred
516+
// `NonLocalOpaque := LocalOpaque` but can only instantiate it in
517+
// the other direction as `LocalOpaque := NonLocalOpaque`. Using eq
518+
// here allows us to try both directions (in `InferCtxt::handle_opaque_type`).
519+
obligations.extend(
520+
self.at(cause, param_env)
521+
.eq(
522+
DefineOpaqueTypes::Yes,
523+
self.tcx.mk_opaque(a.def_id.to_def_id(), a.substs),
524+
b,
525+
)?
526+
.obligations,
527+
);
512528
}
513529

514530
Ok(InferOk { value: result_subst, obligations })

compiler/rustc_middle/src/infer/canonical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ pub struct QueryResponse<'tcx, R> {
280280
/// should get its hidden type inferred. So we bubble the opaque type
281281
/// and the type it was compared against upwards and let the query caller
282282
/// handle it.
283-
pub opaque_types: Vec<(Ty<'tcx>, Ty<'tcx>)>,
283+
pub opaque_types: Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>,
284284
pub value: R,
285285
}
286286

compiler/rustc_middle/src/traits/solve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'tcx> std::ops::Deref for ExternalConstraints<'tcx> {
124124
pub struct ExternalConstraintsData<'tcx> {
125125
// FIXME: implement this.
126126
pub region_constraints: QueryRegionConstraints<'tcx>,
127-
pub opaque_types: Vec<(Ty<'tcx>, Ty<'tcx>)>,
127+
pub opaque_types: Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>,
128128
}
129129

130130
// FIXME: Having to clone `region_constraints` for folding feels bad and

compiler/rustc_query_impl/src/plumbing.rs

+125-143
Original file line numberDiff line numberDiff line change
@@ -506,169 +506,151 @@ macro_rules! define_queries {
506506
(
507507
$($(#[$attr:meta])*
508508
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
509-
mod get_query_incr {
510-
use super::*;
511509

512-
$(
510+
pub(crate) mod query_impl { $(pub mod $name {
511+
use super::super::*;
512+
use std::marker::PhantomData;
513+
514+
pub mod get_query_incr {
515+
use super::*;
516+
513517
// Adding `__rust_end_short_backtrace` marker to backtraces so that we emit the frames
514518
// when `RUST_BACKTRACE=1`, add a new mod with `$name` here is to allow duplicate naming
515-
pub mod $name {
516-
use super::*;
517-
#[inline(never)]
518-
pub fn __rust_end_short_backtrace<'tcx>(
519-
tcx: TyCtxt<'tcx>,
520-
span: Span,
521-
key: queries::$name::Key<'tcx>,
522-
mode: QueryMode,
523-
) -> Option<Erase<queries::$name::Value<'tcx>>> {
524-
get_query_incr(
525-
query_config::$name::config(tcx),
526-
QueryCtxt::new(tcx),
527-
span,
528-
key,
529-
mode
519+
#[inline(never)]
520+
pub fn __rust_end_short_backtrace<'tcx>(
521+
tcx: TyCtxt<'tcx>,
522+
span: Span,
523+
key: queries::$name::Key<'tcx>,
524+
mode: QueryMode,
525+
) -> Option<Erase<queries::$name::Value<'tcx>>> {
526+
get_query_incr(
527+
QueryType::config(tcx),
528+
QueryCtxt::new(tcx),
529+
span,
530+
key,
531+
mode
532+
)
533+
}
534+
}
535+
536+
pub mod get_query_non_incr {
537+
use super::*;
538+
539+
#[inline(never)]
540+
pub fn __rust_end_short_backtrace<'tcx>(
541+
tcx: TyCtxt<'tcx>,
542+
span: Span,
543+
key: queries::$name::Key<'tcx>,
544+
__mode: QueryMode,
545+
) -> Option<Erase<queries::$name::Value<'tcx>>> {
546+
Some(get_query_non_incr(
547+
QueryType::config(tcx),
548+
QueryCtxt::new(tcx),
549+
span,
550+
key,
551+
))
552+
}
553+
}
554+
555+
pub fn dynamic_query<'tcx>() -> DynamicQuery<'tcx, queries::$name::Storage<'tcx>> {
556+
DynamicQuery {
557+
name: stringify!($name),
558+
eval_always: is_eval_always!([$($modifiers)*]),
559+
dep_kind: dep_graph::DepKind::$name,
560+
handle_cycle_error: handle_cycle_error!([$($modifiers)*]),
561+
query_state: offset_of!(QueryStates<'tcx> => $name),
562+
query_cache: offset_of!(QueryCaches<'tcx> => $name),
563+
cache_on_disk: |tcx, key| ::rustc_middle::query::cached::$name(tcx, key),
564+
execute_query: |tcx, key| erase(tcx.$name(key)),
565+
compute: |tcx, key| {
566+
__rust_begin_short_backtrace(||
567+
queries::$name::provided_to_erased(
568+
tcx,
569+
call_provider!([$($modifiers)*][tcx, $name, key])
570+
)
530571
)
531-
}
572+
},
573+
can_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] true false),
574+
try_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] {
575+
|tcx, key, prev_index, index| {
576+
if ::rustc_middle::query::cached::$name(tcx, key) {
577+
let value = $crate::plumbing::try_load_from_disk::<
578+
queries::$name::ProvidedValue<'tcx>
579+
>(
580+
tcx,
581+
prev_index,
582+
index,
583+
);
584+
value.map(|value| queries::$name::provided_to_erased(tcx, value))
585+
} else {
586+
None
587+
}
588+
}
589+
} {
590+
|_tcx, _key, _prev_index, _index| None
591+
}),
592+
value_from_cycle_error: |tcx, cycle| {
593+
let result: queries::$name::Value<'tcx> = Value::from_cycle_error(tcx, cycle);
594+
erase(result)
595+
},
596+
loadable_from_disk: |_tcx, _key, _index| {
597+
should_ever_cache_on_disk!([$($modifiers)*] {
598+
::rustc_middle::query::cached::$name(_tcx, _key) &&
599+
$crate::plumbing::loadable_from_disk(_tcx, _index)
600+
} {
601+
false
602+
})
603+
},
604+
hash_result: hash_result!([$($modifiers)*][queries::$name::Value<'tcx>]),
605+
format_value: |value| format!("{:?}", restore::<queries::$name::Value<'tcx>>(*value)),
532606
}
533-
)*
534-
}
607+
}
535608

536-
mod get_query_non_incr {
537-
use super::*;
609+
#[derive(Copy, Clone, Default)]
610+
pub struct QueryType<'tcx> {
611+
data: PhantomData<&'tcx ()>
612+
}
538613

539-
$(
540-
pub mod $name {
541-
use super::*;
542-
#[inline(never)]
543-
pub fn __rust_end_short_backtrace<'tcx>(
544-
tcx: TyCtxt<'tcx>,
545-
span: Span,
546-
key: queries::$name::Key<'tcx>,
547-
__mode: QueryMode,
548-
) -> Option<Erase<queries::$name::Value<'tcx>>> {
549-
Some(get_query_non_incr(
550-
query_config::$name::config(tcx),
551-
QueryCtxt::new(tcx),
552-
span,
553-
key,
554-
))
614+
impl<'tcx> QueryConfigRestored<'tcx> for QueryType<'tcx> {
615+
type RestoredValue = queries::$name::Value<'tcx>;
616+
type Config = DynamicConfig<
617+
'tcx,
618+
queries::$name::Storage<'tcx>,
619+
{ is_anon!([$($modifiers)*]) },
620+
{ depth_limit!([$($modifiers)*]) },
621+
{ feedable!([$($modifiers)*]) },
622+
>;
623+
624+
#[inline(always)]
625+
fn config(tcx: TyCtxt<'tcx>) -> Self::Config {
626+
DynamicConfig {
627+
dynamic: &tcx.query_system.dynamic_queries.$name,
555628
}
556629
}
557-
)*
558-
}
630+
631+
#[inline(always)]
632+
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue {
633+
restore::<queries::$name::Value<'tcx>>(value)
634+
}
635+
}
636+
})*}
559637

560638
pub(crate) fn engine(incremental: bool) -> QueryEngine {
561639
if incremental {
562640
QueryEngine {
563-
$($name: get_query_incr::$name::__rust_end_short_backtrace,)*
641+
$($name: query_impl::$name::get_query_incr::__rust_end_short_backtrace,)*
564642
}
565643
} else {
566644
QueryEngine {
567-
$($name: get_query_non_incr::$name::__rust_end_short_backtrace,)*
645+
$($name: query_impl::$name::get_query_non_incr::__rust_end_short_backtrace,)*
568646
}
569647
}
570648
}
571649

572-
#[allow(nonstandard_style)]
573-
mod query_config {
574-
use std::marker::PhantomData;
575-
576-
$(
577-
#[derive(Copy, Clone, Default)]
578-
pub struct $name<'tcx> {
579-
data: PhantomData<&'tcx ()>
580-
}
581-
)*
582-
}
583-
584-
#[allow(nonstandard_style)]
585-
mod dynamic_query {
586-
use super::*;
587-
588-
$(
589-
pub(super) fn $name<'tcx>() -> DynamicQuery<'tcx, queries::$name::Storage<'tcx>> {
590-
DynamicQuery {
591-
name: stringify!($name),
592-
eval_always: is_eval_always!([$($modifiers)*]),
593-
dep_kind: dep_graph::DepKind::$name,
594-
handle_cycle_error: handle_cycle_error!([$($modifiers)*]),
595-
query_state: offset_of!(QueryStates<'tcx> => $name),
596-
query_cache: offset_of!(QueryCaches<'tcx> => $name),
597-
cache_on_disk: |tcx, key| ::rustc_middle::query::cached::$name(tcx, key),
598-
execute_query: |tcx, key| erase(tcx.$name(key)),
599-
compute: |tcx, key| {
600-
__rust_begin_short_backtrace(||
601-
queries::$name::provided_to_erased(
602-
tcx,
603-
call_provider!([$($modifiers)*][tcx, $name, key])
604-
)
605-
)
606-
},
607-
can_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] true false),
608-
try_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] {
609-
|tcx, key, prev_index, index| {
610-
if ::rustc_middle::query::cached::$name(tcx, key) {
611-
let value = $crate::plumbing::try_load_from_disk::<
612-
queries::$name::ProvidedValue<'tcx>
613-
>(
614-
tcx,
615-
prev_index,
616-
index,
617-
);
618-
value.map(|value| queries::$name::provided_to_erased(tcx, value))
619-
} else {
620-
None
621-
}
622-
}
623-
} {
624-
|_tcx, _key, _prev_index, _index| None
625-
}),
626-
value_from_cycle_error: |tcx, cycle| {
627-
let result: queries::$name::Value<'tcx> = Value::from_cycle_error(tcx, cycle);
628-
erase(result)
629-
},
630-
loadable_from_disk: |_tcx, _key, _index| {
631-
should_ever_cache_on_disk!([$($modifiers)*] {
632-
::rustc_middle::query::cached::$name(_tcx, _key) &&
633-
$crate::plumbing::loadable_from_disk(_tcx, _index)
634-
} {
635-
false
636-
})
637-
},
638-
hash_result: hash_result!([$($modifiers)*][queries::$name::Value<'tcx>]),
639-
format_value: |value| format!("{:?}", restore::<queries::$name::Value<'tcx>>(*value)),
640-
}
641-
}
642-
)*
643-
}
644-
645-
$(impl<'tcx> QueryConfigRestored<'tcx> for query_config::$name<'tcx> {
646-
type RestoredValue = queries::$name::Value<'tcx>;
647-
type Config = DynamicConfig<
648-
'tcx,
649-
queries::$name::Storage<'tcx>,
650-
{ is_anon!([$($modifiers)*]) },
651-
{ depth_limit!([$($modifiers)*]) },
652-
{ feedable!([$($modifiers)*]) },
653-
>;
654-
655-
#[inline(always)]
656-
fn config(tcx: TyCtxt<'tcx>) -> Self::Config {
657-
DynamicConfig {
658-
dynamic: &tcx.query_system.dynamic_queries.$name,
659-
}
660-
}
661-
662-
#[inline(always)]
663-
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue {
664-
restore::<queries::$name::Value<'tcx>>(value)
665-
}
666-
})*
667-
668650
pub fn dynamic_queries<'tcx>() -> DynamicQueries<'tcx> {
669651
DynamicQueries {
670652
$(
671-
$name: dynamic_query::$name(),
653+
$name: query_impl::$name::dynamic_query(),
672654
)*
673655
}
674656
}
@@ -731,7 +713,7 @@ macro_rules! define_queries {
731713
}
732714

733715
$(pub(crate) fn $name<'tcx>()-> DepKindStruct<'tcx> {
734-
$crate::plumbing::query_callback::<query_config::$name<'tcx>>(
716+
$crate::plumbing::query_callback::<query_impl::$name::QueryType<'tcx>>(
735717
is_anon!([$($modifiers)*]),
736718
is_eval_always!([$($modifiers)*]),
737719
)
@@ -786,8 +768,8 @@ macro_rules! define_queries {
786768
)
787769
},
788770
encode_query_results: expand_if_cached!([$($modifiers)*], |tcx, encoder, query_result_index|
789-
$crate::plumbing::encode_query_results::<super::query_config::$name<'tcx>>(
790-
super::query_config::$name::config(tcx),
771+
$crate::plumbing::encode_query_results::<query_impl::$name::QueryType<'tcx>>(
772+
query_impl::$name::QueryType::config(tcx),
791773
QueryCtxt::new(tcx),
792774
encoder,
793775
query_result_index,

src/bootstrap/bootstrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _download(path, url, probably_big, verbose, exception):
109109
"-L", # Follow redirect.
110110
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
111111
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
112-
"--retry", "3", "-Sf", url],
112+
"--retry", "3", "-SRf", url],
113113
stdout=outfile, #Implements cli redirect operator '>'
114114
verbose=verbose,
115115
exception=True, # Will raise RuntimeError on failure

src/bootstrap/download.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl Config {
219219
"30", // timeout if cannot connect within 30 seconds
220220
"--retry",
221221
"3",
222-
"-Sf",
222+
"-SRf",
223223
]);
224224
curl.arg(url);
225225
let f = File::create(tempfile).unwrap();

0 commit comments

Comments
 (0)