mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Auto merge of #15986 - davidbarsky:david/move-to-arc-iter, r=lnicola
internal: move to `Arc::from_iter` Builds atop of https://github.com/rust-lang/rust-analyzer/pull/15985, will rebase.
This commit is contained in:
commit
311a5e9253
7 changed files with 114 additions and 160 deletions
|
@ -44,21 +44,18 @@ impl RawAttrs {
|
|||
owner: &dyn ast::HasAttrs,
|
||||
span_map: SpanMapRef<'_>,
|
||||
) -> Self {
|
||||
let entries = collect_attrs(owner)
|
||||
.filter_map(|(id, attr)| match attr {
|
||||
Either::Left(attr) => {
|
||||
attr.meta().and_then(|meta| Attr::from_src(db, meta, span_map, id))
|
||||
}
|
||||
Either::Right(comment) => comment.doc_comment().map(|doc| Attr {
|
||||
id,
|
||||
input: Some(Interned::new(AttrInput::Literal(SmolStr::new(doc)))),
|
||||
path: Interned::new(ModPath::from(crate::name!(doc))),
|
||||
ctxt: span_map.span_for_range(comment.syntax().text_range()).ctx,
|
||||
}),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
let entries: Arc<[Attr]> = Arc::from(entries);
|
||||
let entries = collect_attrs(owner).filter_map(|(id, attr)| match attr {
|
||||
Either::Left(attr) => {
|
||||
attr.meta().and_then(|meta| Attr::from_src(db, meta, span_map, id))
|
||||
}
|
||||
Either::Right(comment) => comment.doc_comment().map(|doc| Attr {
|
||||
id,
|
||||
input: Some(Interned::new(AttrInput::Literal(SmolStr::new(doc)))),
|
||||
path: Interned::new(ModPath::from(crate::name!(doc))),
|
||||
ctxt: span_map.span_for_range(comment.syntax().text_range()).ctx,
|
||||
}),
|
||||
});
|
||||
let entries: Arc<[Attr]> = Arc::from_iter(entries);
|
||||
|
||||
Self { entries: if entries.is_empty() { None } else { Some(entries) } }
|
||||
}
|
||||
|
@ -79,19 +76,13 @@ impl RawAttrs {
|
|||
(Some(a), Some(b)) => {
|
||||
let last_ast_index = a.last().map_or(0, |it| it.id.ast_index() + 1) as u32;
|
||||
Self {
|
||||
entries: Some(Arc::from(
|
||||
a.iter()
|
||||
.cloned()
|
||||
.chain(b.iter().map(|it| {
|
||||
let mut it = it.clone();
|
||||
it.id.id = it.id.ast_index() as u32 + last_ast_index
|
||||
| (it.id.cfg_attr_index().unwrap_or(0) as u32)
|
||||
<< AttrId::AST_INDEX_BITS;
|
||||
it
|
||||
}))
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
.collect::<Vec<_>>(),
|
||||
)),
|
||||
entries: Some(Arc::from_iter(a.iter().cloned().chain(b.iter().map(|it| {
|
||||
let mut it = it.clone();
|
||||
it.id.id = it.id.ast_index() as u32 + last_ast_index
|
||||
| (it.id.cfg_attr_index().unwrap_or(0) as u32)
|
||||
<< AttrId::AST_INDEX_BITS;
|
||||
it
|
||||
})))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,49 +99,43 @@ impl RawAttrs {
|
|||
}
|
||||
|
||||
let crate_graph = db.crate_graph();
|
||||
let new_attrs = Arc::from(
|
||||
self.iter()
|
||||
.flat_map(|attr| -> SmallVec<[_; 1]> {
|
||||
let is_cfg_attr =
|
||||
attr.path.as_ident().map_or(false, |name| *name == crate::name![cfg_attr]);
|
||||
if !is_cfg_attr {
|
||||
return smallvec![attr.clone()];
|
||||
}
|
||||
let new_attrs = Arc::from_iter(self.iter().flat_map(|attr| -> SmallVec<[_; 1]> {
|
||||
let is_cfg_attr =
|
||||
attr.path.as_ident().map_or(false, |name| *name == crate::name![cfg_attr]);
|
||||
if !is_cfg_attr {
|
||||
return smallvec![attr.clone()];
|
||||
}
|
||||
|
||||
let subtree = match attr.token_tree_value() {
|
||||
Some(it) => it,
|
||||
_ => return smallvec![attr.clone()],
|
||||
let subtree = match attr.token_tree_value() {
|
||||
Some(it) => it,
|
||||
_ => return smallvec![attr.clone()],
|
||||
};
|
||||
|
||||
let (cfg, parts) = match parse_cfg_attr_input(subtree) {
|
||||
Some(it) => it,
|
||||
None => return smallvec![attr.clone()],
|
||||
};
|
||||
let index = attr.id;
|
||||
let attrs =
|
||||
parts.enumerate().take(1 << AttrId::CFG_ATTR_BITS).filter_map(|(idx, attr)| {
|
||||
let tree = Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
token_trees: attr.to_vec(),
|
||||
};
|
||||
Attr::from_tt(db, &tree, index.with_cfg_attr(idx))
|
||||
});
|
||||
|
||||
let (cfg, parts) = match parse_cfg_attr_input(subtree) {
|
||||
Some(it) => it,
|
||||
None => return smallvec![attr.clone()],
|
||||
};
|
||||
let index = attr.id;
|
||||
let attrs = parts.enumerate().take(1 << AttrId::CFG_ATTR_BITS).filter_map(
|
||||
|(idx, attr)| {
|
||||
let tree = Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
token_trees: attr.to_vec(),
|
||||
};
|
||||
Attr::from_tt(db, &tree, index.with_cfg_attr(idx))
|
||||
},
|
||||
);
|
||||
let cfg_options = &crate_graph[krate].cfg_options;
|
||||
let cfg = Subtree { delimiter: subtree.delimiter, token_trees: cfg.to_vec() };
|
||||
let cfg = CfgExpr::parse(&cfg);
|
||||
if cfg_options.check(&cfg) == Some(false) {
|
||||
smallvec![]
|
||||
} else {
|
||||
cov_mark::hit!(cfg_attr_active);
|
||||
|
||||
let cfg_options = &crate_graph[krate].cfg_options;
|
||||
let cfg = Subtree { delimiter: subtree.delimiter, token_trees: cfg.to_vec() };
|
||||
let cfg = CfgExpr::parse(&cfg);
|
||||
if cfg_options.check(&cfg) == Some(false) {
|
||||
smallvec![]
|
||||
} else {
|
||||
cov_mark::hit!(cfg_attr_active);
|
||||
|
||||
attrs.collect()
|
||||
}
|
||||
})
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
attrs.collect()
|
||||
}
|
||||
}));
|
||||
|
||||
RawAttrs { entries: Some(new_attrs) }
|
||||
}
|
||||
|
|
|
@ -322,8 +322,7 @@ impl CallableSig {
|
|||
pub fn from_fn_ptr(fn_ptr: &FnPointer) -> CallableSig {
|
||||
CallableSig {
|
||||
// FIXME: what to do about lifetime params? -> return PolyFnSig
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
params_and_return: Arc::from(
|
||||
params_and_return: Arc::from_iter(
|
||||
fn_ptr
|
||||
.substitution
|
||||
.clone()
|
||||
|
@ -332,8 +331,7 @@ impl CallableSig {
|
|||
.0
|
||||
.as_slice(Interner)
|
||||
.iter()
|
||||
.map(|arg| arg.assert_ty_ref(Interner).clone())
|
||||
.collect::<Vec<_>>(),
|
||||
.map(|arg| arg.assert_ty_ref(Interner).clone()),
|
||||
),
|
||||
is_varargs: fn_ptr.sig.variadic,
|
||||
safety: fn_ptr.sig.safety,
|
||||
|
|
|
@ -1459,8 +1459,7 @@ pub(crate) fn generic_predicates_for_param_recover(
|
|||
_param_id: &TypeOrConstParamId,
|
||||
_assoc_name: &Option<Name>,
|
||||
) -> Arc<[Binders<QuantifiedWhereClause>]> {
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
Arc::from(vec![])
|
||||
Arc::from_iter(None)
|
||||
}
|
||||
|
||||
pub(crate) fn trait_environment_for_body_query(
|
||||
|
@ -1603,44 +1602,35 @@ pub(crate) fn generic_defaults_query(
|
|||
let generic_params = generics(db.upcast(), def);
|
||||
let parent_start_idx = generic_params.len_self();
|
||||
|
||||
let defaults = Arc::from(
|
||||
generic_params
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, (id, p))| {
|
||||
match p {
|
||||
TypeOrConstParamData::TypeParamData(p) => {
|
||||
let mut ty = p
|
||||
.default
|
||||
.as_ref()
|
||||
.map_or(TyKind::Error.intern(Interner), |t| ctx.lower_ty(t));
|
||||
// Each default can only refer to previous parameters.
|
||||
// Type variable default referring to parameter coming
|
||||
// after it is forbidden (FIXME: report diagnostic)
|
||||
ty = fallback_bound_vars(ty, idx, parent_start_idx);
|
||||
crate::make_binders(db, &generic_params, ty.cast(Interner))
|
||||
}
|
||||
TypeOrConstParamData::ConstParamData(p) => {
|
||||
let mut val = p.default.as_ref().map_or_else(
|
||||
|| {
|
||||
unknown_const_as_generic(
|
||||
db.const_param_ty(ConstParamId::from_unchecked(id)),
|
||||
)
|
||||
},
|
||||
|c| {
|
||||
let c = ctx.lower_const(c, ctx.lower_ty(&p.ty));
|
||||
c.cast(Interner)
|
||||
},
|
||||
);
|
||||
// Each default can only refer to previous parameters, see above.
|
||||
val = fallback_bound_vars(val, idx, parent_start_idx);
|
||||
make_binders(db, &generic_params, val)
|
||||
}
|
||||
}
|
||||
})
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
let defaults = Arc::from_iter(generic_params.iter().enumerate().map(|(idx, (id, p))| {
|
||||
match p {
|
||||
TypeOrConstParamData::TypeParamData(p) => {
|
||||
let mut ty =
|
||||
p.default.as_ref().map_or(TyKind::Error.intern(Interner), |t| ctx.lower_ty(t));
|
||||
// Each default can only refer to previous parameters.
|
||||
// Type variable default referring to parameter coming
|
||||
// after it is forbidden (FIXME: report diagnostic)
|
||||
ty = fallback_bound_vars(ty, idx, parent_start_idx);
|
||||
crate::make_binders(db, &generic_params, ty.cast(Interner))
|
||||
}
|
||||
TypeOrConstParamData::ConstParamData(p) => {
|
||||
let mut val = p.default.as_ref().map_or_else(
|
||||
|| {
|
||||
unknown_const_as_generic(
|
||||
db.const_param_ty(ConstParamId::from_unchecked(id)),
|
||||
)
|
||||
},
|
||||
|c| {
|
||||
let c = ctx.lower_const(c, ctx.lower_ty(&p.ty));
|
||||
c.cast(Interner)
|
||||
},
|
||||
);
|
||||
// Each default can only refer to previous parameters, see above.
|
||||
val = fallback_bound_vars(val, idx, parent_start_idx);
|
||||
make_binders(db, &generic_params, val)
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
defaults
|
||||
}
|
||||
|
@ -1653,19 +1643,13 @@ pub(crate) fn generic_defaults_recover(
|
|||
let generic_params = generics(db.upcast(), *def);
|
||||
// FIXME: this code is not covered in tests.
|
||||
// we still need one default per parameter
|
||||
let defaults = Arc::from(
|
||||
generic_params
|
||||
.iter_id()
|
||||
.map(|id| {
|
||||
let val = match id {
|
||||
Either::Left(_) => TyKind::Error.intern(Interner).cast(Interner),
|
||||
Either::Right(id) => unknown_const_as_generic(db.const_param_ty(id)),
|
||||
};
|
||||
crate::make_binders(db, &generic_params, val)
|
||||
})
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
let defaults = Arc::from_iter(generic_params.iter_id().map(|id| {
|
||||
let val = match id {
|
||||
Either::Left(_) => TyKind::Error.intern(Interner).cast(Interner),
|
||||
Either::Right(id) => unknown_const_as_generic(db.const_param_ty(id)),
|
||||
};
|
||||
crate::make_binders(db, &generic_params, val)
|
||||
}));
|
||||
|
||||
defaults
|
||||
}
|
||||
|
|
|
@ -168,12 +168,9 @@ impl TraitImpls {
|
|||
) -> Arc<[Arc<Self>]> {
|
||||
let _p = profile::span("trait_impls_in_deps_query").detail(|| format!("{krate:?}"));
|
||||
let crate_graph = db.crate_graph();
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
Arc::from(
|
||||
crate_graph
|
||||
.transitive_deps(krate)
|
||||
.map(|krate| db.trait_impls_in_crate(krate))
|
||||
.collect::<Vec<_>>(),
|
||||
|
||||
Arc::from_iter(
|
||||
crate_graph.transitive_deps(krate).map(|krate| db.trait_impls_in_crate(krate)),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -187,11 +187,9 @@ impl GlobalState {
|
|||
config_errors: Default::default(),
|
||||
|
||||
proc_macro_changed: false,
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
proc_macro_clients: Arc::from(Vec::new()),
|
||||
proc_macro_clients: Arc::from_iter([]),
|
||||
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
flycheck: Arc::from(Vec::new()),
|
||||
flycheck: Arc::from_iter([]),
|
||||
flycheck_sender,
|
||||
flycheck_receiver,
|
||||
last_flycheck_error: None,
|
||||
|
@ -202,7 +200,7 @@ impl GlobalState {
|
|||
vfs_progress_n_total: 0,
|
||||
vfs_progress_n_done: 0,
|
||||
|
||||
workspaces: Arc::new(Vec::new()),
|
||||
workspaces: Arc::from(Vec::new()),
|
||||
crate_graph_file_dependencies: FxHashSet::default(),
|
||||
fetch_workspaces_queue: OpQueue::default(),
|
||||
fetch_build_data_queue: OpQueue::default(),
|
||||
|
|
|
@ -51,8 +51,7 @@ use crate::{
|
|||
};
|
||||
|
||||
pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> anyhow::Result<()> {
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
state.proc_macro_clients = Arc::from(Vec::new());
|
||||
state.proc_macro_clients = Arc::from_iter([]);
|
||||
state.proc_macro_changed = false;
|
||||
|
||||
state.fetch_workspaces_queue.request_op("reload workspace request".to_string(), false);
|
||||
|
@ -60,8 +59,7 @@ pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> anyhow:
|
|||
}
|
||||
|
||||
pub(crate) fn handle_proc_macros_rebuild(state: &mut GlobalState, _: ()) -> anyhow::Result<()> {
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
state.proc_macro_clients = Arc::from(Vec::new());
|
||||
state.proc_macro_clients = Arc::from_iter([]);
|
||||
state.proc_macro_changed = false;
|
||||
|
||||
state.fetch_build_data_queue.request_op("rebuild proc macros request".to_string(), ());
|
||||
|
|
|
@ -437,28 +437,22 @@ impl GlobalState {
|
|||
if self.config.expand_proc_macros() {
|
||||
tracing::info!("Spawning proc-macro servers");
|
||||
|
||||
// FIXME: use `Arc::from_iter` when it becomes available
|
||||
self.proc_macro_clients = Arc::from(
|
||||
self.workspaces
|
||||
.iter()
|
||||
.map(|ws| {
|
||||
let path = match self.config.proc_macro_srv() {
|
||||
Some(path) => path,
|
||||
None => ws.find_sysroot_proc_macro_srv()?,
|
||||
};
|
||||
self.proc_macro_clients = Arc::from_iter(self.workspaces.iter().map(|ws| {
|
||||
let path = match self.config.proc_macro_srv() {
|
||||
Some(path) => path,
|
||||
None => ws.find_sysroot_proc_macro_srv()?,
|
||||
};
|
||||
|
||||
tracing::info!("Using proc-macro server at {path}");
|
||||
ProcMacroServer::spawn(path.clone()).map_err(|err| {
|
||||
tracing::error!(
|
||||
"Failed to run proc-macro server from path {path}, error: {err:?}",
|
||||
);
|
||||
anyhow::format_err!(
|
||||
"Failed to run proc-macro server from path {path}, error: {err:?}",
|
||||
)
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
tracing::info!("Using proc-macro server at {path}");
|
||||
ProcMacroServer::spawn(path.clone()).map_err(|err| {
|
||||
tracing::error!(
|
||||
"Failed to run proc-macro server from path {path}, error: {err:?}",
|
||||
);
|
||||
anyhow::format_err!(
|
||||
"Failed to run proc-macro server from path {path}, error: {err:?}",
|
||||
)
|
||||
})
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue