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

Update toolchain #913

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ hashbrown = "0.14.3"
home = "0.5.9"
itertools = "0.13.0"
pad-adapter = "0.1.1"
rustc-hash = "2.0.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.8"
Expand Down
2 changes: 2 additions & 0 deletions crates/flux-arc-interner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version = "0.1.0"
dashmap.workspace = true
hashbrown.workspace = true

rustc-hash.workspace = true

[lints]
workspace = true

Expand Down
1 change: 0 additions & 1 deletion crates/flux-arc-interner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#![feature(rustc_private)]

extern crate rustc_hash;
extern crate rustc_serialize;
extern crate rustc_target;

Expand Down
2 changes: 2 additions & 0 deletions crates/flux-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ edition.workspace = true
[dependencies]
flux-config.workspace = true

rustc-hash.workspace = true

[package.metadata.rust-analyzer]
rustc_private = true

Expand Down
2 changes: 1 addition & 1 deletion crates/flux-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

extern crate rustc_borrowck;
extern crate rustc_errors;
extern crate rustc_hash;

extern crate rustc_hir;
extern crate rustc_index;
extern crate rustc_middle;
Expand Down
2 changes: 2 additions & 0 deletions crates/flux-desugar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ flux-errors.workspace = true
flux-macros.workspace = true
flux-middle.workspace = true
flux-syntax.workspace = true

itertools.workspace = true
rustc-hash.workspace = true

[package.metadata.rust-analyzer]
rustc_private = true
Expand Down
124 changes: 46 additions & 78 deletions crates/flux-desugar/src/desugar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use flux_syntax::{
walk_list,
};
use hir::{def::DefKind, ItemKind};
use rustc_data_structures::{fx::FxIndexSet, unord::UnordMap};
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{Diagnostic, ErrorGuaranteed};
use rustc_hash::FxHashSet;
use rustc_hir::{self as hir, OwnerId};
Expand Down Expand Up @@ -104,7 +104,7 @@ pub(crate) struct RustItemCtxt<'a, 'genv, 'tcx> {
owner: MaybeExternId<OwnerId>,
fn_sig_scope: Option<NodeId>,
resolver_output: &'genv ResolverOutput,
opaque_tys: Option<&'a mut UnordMap<LocalDefId, fhir::Item<'genv>>>,
opaque_tys: Option<&'a mut Vec<&'genv fhir::OpaqueTy<'genv>>>,
}

struct FluxItemCtxt<'genv, 'tcx> {
Expand All @@ -119,7 +119,7 @@ impl<'a, 'genv, 'tcx: 'genv> RustItemCtxt<'a, 'genv, 'tcx> {
genv: GlobalEnv<'genv, 'tcx>,
owner: MaybeExternId<OwnerId>,
resolver_output: &'genv ResolverOutput,
opaque_tys: Option<&'a mut UnordMap<LocalDefId, fhir::Item<'genv>>>,
opaque_tys: Option<&'a mut Vec<&'genv fhir::OpaqueTy<'genv>>>,
) -> Self {
RustItemCtxt {
genv,
Expand All @@ -131,13 +131,6 @@ impl<'a, 'genv, 'tcx: 'genv> RustItemCtxt<'a, 'genv, 'tcx> {
}
}

fn with_new_owner<'b>(
&'b mut self,
owner: MaybeExternId<OwnerId>,
) -> RustItemCtxt<'b, 'genv, 'tcx> {
RustItemCtxt::new(self.genv, owner, self.resolver_output, self.opaque_tys.as_deref_mut())
}

fn as_lift_cx<'b>(&'b mut self) -> LiftCtxt<'b, 'genv, 'tcx> {
LiftCtxt::new(self.genv, self.owner, &self.local_id_gen, self.opaque_tys.as_deref_mut())
}
Expand Down Expand Up @@ -248,10 +241,7 @@ impl<'a, 'genv, 'tcx: 'genv> RustItemCtxt<'a, 'genv, 'tcx> {
bounds: &[surface::TraitRef],
) -> Result<fhir::GenericBounds<'genv>> {
try_alloc_slice!(self.genv, bounds, |bound| {
Ok(fhir::GenericBound::Trait(
self.desugar_trait_ref(bound)?,
fhir::TraitBoundModifier::None,
))
Ok(fhir::GenericBound::Trait(self.desugar_trait_ref(bound)?))
})
}

Expand All @@ -263,7 +253,12 @@ impl<'a, 'genv, 'tcx: 'genv> RustItemCtxt<'a, 'genv, 'tcx> {
span_bug!(trait_ref.path.span, "desugar_alias_reft: unexpected qpath")
};
let span = path.span;
Ok(fhir::PolyTraitRef { bound_generic_params: &[], trait_ref: path, span })
Ok(fhir::PolyTraitRef {
bound_generic_params: &[],
modifiers: fhir::TraitBoundModifier::None,
trait_ref: path,
span,
})
}

fn desugar_refined_by(
Expand Down Expand Up @@ -638,21 +633,13 @@ impl<'a, 'genv, 'tcx: 'genv> RustItemCtxt<'a, 'genv, 'tcx> {
) -> Result<fhir::Ty<'genv>> {
match asyncness {
surface::Async::Yes { node_id, span } => {
let item_id = self.resolver_output.impl_trait_res_map[&node_id];
let def_id = item_id.owner_id.def_id;
let res = Res::Def(DefKind::OpaqueTy, def_id.to_def_id());

let def_id = self.resolver_output.impl_trait_res_map[&node_id];
// FIXME(nilehmann) since we can only pass local ids for opaque types it means we
// can't support extern specs with opaque types.
let opaque_ty = self
.with_new_owner(MaybeExternId::Local(item_id.owner_id))
.desugar_opaque_ty_for_async(returns)?;
self.insert_opaque_ty(item_id.owner_id.def_id, opaque_ty);

let (args, _) = self.desugar_generic_args(res, &[])?;
let item_id = hir::ItemId { owner_id: hir::OwnerId { def_id } };
let refine_args = self.implicit_params_to_args(self.fn_sig_scope.unwrap());
let kind = fhir::TyKind::OpaqueDef(item_id, args, refine_args, false);
let opaque_ty = self.desugar_opaque_ty_for_async(def_id, returns)?;
let opaque_ty = self.insert_opaque_ty(opaque_ty);

let kind = fhir::TyKind::OpaqueDef(opaque_ty);
Ok(fhir::Ty { kind, span })
}
surface::Async::No => Ok(self.desugar_fn_ret_ty(returns)?),
Expand All @@ -661,11 +648,10 @@ impl<'a, 'genv, 'tcx: 'genv> RustItemCtxt<'a, 'genv, 'tcx> {

fn desugar_opaque_ty_for_async(
&mut self,
def_id: LocalDefId,
returns: &surface::FnRetTy,
) -> Result<fhir::Item<'genv>> {
) -> Result<fhir::OpaqueTy<'genv>> {
let output = self.desugar_fn_ret_ty(returns)?;
// Does this opaque type have any generics?
let generics = self.as_lift_cx().lift_generics()?;
let trait_ref = self.make_lang_item_path(
hir::LangItem::Future,
DUMMY_SP,
Expand All @@ -675,13 +661,17 @@ impl<'a, 'genv, 'tcx: 'genv> RustItemCtxt<'a, 'genv, 'tcx> {
kind: fhir::AssocItemConstraintKind::Equality { term: output },
}]),
);
let bound = fhir::GenericBound::Trait(
fhir::PolyTraitRef { bound_generic_params: &[], trait_ref, span: trait_ref.span },
fhir::TraitBoundModifier::None,
);
let opaque_ty = fhir::OpaqueTy { bounds: self.genv.alloc_slice(&[bound]) };

Ok(fhir::Item { generics, kind: fhir::ItemKind::OpaqueTy(opaque_ty), owner_id: self.owner })
let bound = fhir::GenericBound::Trait(fhir::PolyTraitRef {
bound_generic_params: &[],
modifiers: fhir::TraitBoundModifier::None,
trait_ref,
span: trait_ref.span,
});
let opaque_ty = fhir::OpaqueTy {
def_id: MaybeExternId::Local(def_id),
bounds: self.genv.alloc_slice(&[bound]),
};
Ok(opaque_ty)
}

fn make_lang_item_path(
Expand Down Expand Up @@ -719,12 +709,12 @@ impl<'a, 'genv, 'tcx: 'genv> RustItemCtxt<'a, 'genv, 'tcx> {

fn desugar_opaque_ty_for_impl_trait(
&mut self,
def_id: LocalDefId,
bounds: &[surface::TraitRef],
) -> Result<fhir::Item<'genv>> {
let generics = self.as_lift_cx().lift_generics()?;
) -> Result<fhir::OpaqueTy<'genv>> {
let bounds = self.desugar_generic_bounds(bounds)?;
let opaque_ty = fhir::OpaqueTy { bounds };
Ok(fhir::Item { generics, kind: fhir::ItemKind::OpaqueTy(opaque_ty), owner_id: self.owner })
let opaque_ty = fhir::OpaqueTy { def_id: MaybeExternId::Local(def_id), bounds };
Ok(opaque_ty)
}

fn desugar_variant_ret(
Expand Down Expand Up @@ -772,11 +762,16 @@ impl<'a, 'genv, 'tcx: 'genv> RustItemCtxt<'a, 'genv, 'tcx> {
Some(resolved_id)
}

fn insert_opaque_ty(&mut self, def_id: LocalDefId, opaque_ty: fhir::Item<'genv>) {
fn insert_opaque_ty(
&mut self,
opaque_ty: fhir::OpaqueTy<'genv>,
) -> &'genv fhir::OpaqueTy<'genv> {
let opaque_ty = self.genv.alloc(opaque_ty);
self.opaque_tys
.as_mut()
.unwrap_or_else(|| bug!("`impl Trait` not supported in this item {def_id:?}"))
.insert(def_id, opaque_ty);
.unwrap_or_else(|| bug!("`impl Trait` not supported in this item `{:?}`", self.owner))
.push(opaque_ty);
opaque_ty
}

#[track_caller]
Expand Down Expand Up @@ -897,27 +892,6 @@ trait DesugarCtxt<'genv, 'tcx: 'genv> {
})
}

fn implicit_params_to_args(&self, scope: NodeId) -> &'genv [fhir::Expr<'genv>] {
self.genv()
.alloc_slice_fill_iter(
self.resolve_implicit_params(scope)
.map(|(ident, id, kind)| {
let span = ident.span;
let path = fhir::PathExpr {
segments: self.genv().alloc_slice(&[ident]),
res: ExprRes::Param(kind, id),
fhir_id: self.next_fhir_id(),
span: ident.span,
};
fhir::Expr {
kind: fhir::ExprKind::Var(path, Some(kind)),
fhir_id: self.next_fhir_id(),
span,
}
}),
)
}

fn desugar_refine_params(
&self,
params: &[surface::RefineParam],
Expand Down Expand Up @@ -1512,7 +1486,7 @@ fn desugar_base_sort<'genv>(
}
}

impl<'a, 'genv, 'tcx> DesugarCtxt<'genv, 'tcx> for RustItemCtxt<'a, 'genv, 'tcx> {
impl<'genv, 'tcx> DesugarCtxt<'genv, 'tcx> for RustItemCtxt<'_, 'genv, 'tcx> {
fn next_fhir_id(&self) -> FhirId {
FhirId {
owner: FluxOwnerId::Rust(self.owner.local_id()),
Expand All @@ -1533,20 +1507,14 @@ impl<'a, 'genv, 'tcx> DesugarCtxt<'genv, 'tcx> for RustItemCtxt<'a, 'genv, 'tcx>
node_id: NodeId,
bounds: &[surface::TraitRef],
) -> Result<fhir::TyKind<'genv>> {
let item_id = self.resolver_output().impl_trait_res_map[&node_id];
let def_id = item_id.owner_id.def_id;
let res = Res::Def(DefKind::OpaqueTy, def_id.to_def_id());
let def_id = self.resolver_output().impl_trait_res_map[&node_id];

// FIXME(nilehmann) since we can only pass local ids for opaque types it means we can't
// support extern specs with opaque types.
let opaque_ty = self
.with_new_owner(MaybeExternId::Local(item_id.owner_id))
.desugar_opaque_ty_for_impl_trait(bounds)?;
self.insert_opaque_ty(def_id, opaque_ty);

let (args, _) = self.desugar_generic_args(res, &[])?;
let refine_args = self.implicit_params_to_args(self.fn_sig_scope.unwrap());
Ok(fhir::TyKind::OpaqueDef(item_id, args, refine_args, false))
let opaque_ty = self.desugar_opaque_ty_for_impl_trait(def_id, bounds)?;
let opaque_ty = self.insert_opaque_ty(opaque_ty);

Ok(fhir::TyKind::OpaqueDef(opaque_ty))
}
}

Expand Down
Loading