Skip to content

Commit

Permalink
Update rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Jun 25, 2024
1 parent bbbd02d commit e1439bf
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 66 deletions.
2 changes: 1 addition & 1 deletion cli/driver/src/callbacks_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct CallbacksWrapper<'a> {
impl<'a> Callbacks for CallbacksWrapper<'a> {
fn config(&mut self, config: &mut interface::Config) {
let options = self.options.clone();
config.parse_sess_created = Some(Box::new(move |parse_sess| {
config.psess_created = Some(Box::new(move |parse_sess| {
parse_sess.env_depinfo.get_mut().insert((
Symbol::intern(hax_cli_options::ENV_VAR_OPTIONS_FRONTEND),
Some(Symbol::intern(&serde_json::to_string(&options).unwrap())),
Expand Down
12 changes: 1 addition & 11 deletions cli/driver/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,29 +365,19 @@ impl Callbacks for ExtractionCallbacks {
include_extra,
};
mod from {
pub use hax_cli_options::ExportBodyKind::{
MirBuilt as MB, MirConst as MC, Thir as T,
};
pub use hax_cli_options::ExportBodyKind::{MirBuilt as MB, Thir as T};
}
mod to {
pub type T = hax_frontend_exporter::ThirBody;
pub type MB =
hax_frontend_exporter::MirBody<hax_frontend_exporter::mir_kinds::Built>;
pub type MC =
hax_frontend_exporter::MirBody<hax_frontend_exporter::mir_kinds::Const>;
}
kind.sort();
kind.dedup();
match kind.as_slice() {
[from::MB] => driver.to_json::<to::MB>(),
[from::MC] => driver.to_json::<to::MC>(),
[from::T] => driver.to_json::<to::T>(),
[from::MB, from::MC] => driver.to_json::<(to::MB, to::MC)>(),
[from::T, from::MB] => driver.to_json::<(to::MB, to::T)>(),
[from::T, from::MC] => driver.to_json::<(to::MC, to::T)>(),
[from::T, from::MB, from::MC] => {
driver.to_json::<(to::MB, (to::MC, to::T))>()
}
[] => driver.to_json::<()>(),
_ => panic!("Unsupported kind {:#?}", kind),
}
Expand Down
1 change: 0 additions & 1 deletion cli/options/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ pub enum ExporterCommand {
pub enum ExportBodyKind {
Thir,
MirBuilt,
MirConst,
}

#[derive(JsonSchema, Subcommand, Debug, Clone, Serialize, Deserialize)]
Expand Down
9 changes: 7 additions & 2 deletions engine/lib/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,14 @@ let show_int_kind { size; signedness } =
|> Option.map ~f:Int.to_string
|> Option.value ~default:"size")

type float_kind = F32 | F64 [@@deriving show, yojson, hash, compare, eq]
type float_kind = F16 | F32 | F64 | F128
[@@deriving show, yojson, hash, compare, eq]

let show_float_kind = function F32 -> "f32" | F64 -> "f64"
let show_float_kind = function
| F16 -> "f16"
| F32 -> "f32"
| F64 -> "f64"
| F128 -> "f128"

type literal =
| String of string
Expand Down
6 changes: 2 additions & 4 deletions engine/lib/generic_printer/generic_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ module Make (F : Features.T) (View : Concrete_ident.VIEW_API) = struct
| Float { value; kind; negative } ->
string value
|> precede (if negative then minus else empty)
|> terminate
(string (match kind with F32 -> "f32" | F64 -> "f64"))
|> terminate (string (show_float_kind kind))
| Bool b -> OCaml.bool b

method generic_value : generic_value fn =
Expand Down Expand Up @@ -101,8 +100,7 @@ module Make (F : Features.T) (View : Concrete_ident.VIEW_API) = struct
in
string signedness ^^ size

method ty_float : float_kind fn =
(function F32 -> "f32" | F64 -> "f64") >> string
method ty_float : float_kind fn = show_float_kind >> string

method generic_values : generic_value list fn =
function
Expand Down
18 changes: 11 additions & 7 deletions engine/lib/import_thir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ let c_borrow_kind span : Thir.borrow_kind -> borrow_kind = function
| Fake -> unimplemented [ span ] "Shallow borrows"
| Mut _ -> Mut W.mutable_reference

let c_binding_mode span : Thir.binding_mode -> binding_mode = function
| ByValue -> ByValue
| ByRef k -> ByRef (c_borrow_kind span k, W.reference)
let c_binding_mode : Thir.by_ref -> binding_mode = function
| No -> ByValue
| Yes true -> ByRef (Mut W.mutable_reference, W.reference)
| Yes false -> ByRef (Shared, W.reference)

let unit_typ : ty = TApp { ident = `TupleType 0; args = [] }

Expand Down Expand Up @@ -800,13 +801,13 @@ end) : EXPR = struct
let typ, typ_span = c_canonical_user_type_annotation annotation in
let pat = c_pat subpattern in
PAscription { typ; typ_span; pat }
| Binding { mode; mutability; subpattern; ty; var; _ } ->
let mut = c_mutability W.mutable_variable mutability in
| Binding { mode; subpattern; ty; var; _ } ->
let mut = c_mutability W.mutable_variable mode.mutability in
let subpat =
Option.map ~f:(c_pat &&& Fn.const W.as_pattern) subpattern
in
let typ = c_ty pat.span ty in
let mode = c_binding_mode pat.span mode in
let mode = c_binding_mode mode.by_ref in
let var = local_ident Expr var in
PBinding { mut; mode; var; typ; subpat }
| Variant { info; subpatterns; _ } ->
Expand Down Expand Up @@ -844,6 +845,7 @@ end) : EXPR = struct
| Or { pats } -> POr { subpats = List.map ~f:c_pat pats }
| Slice _ -> unimplemented [ pat.span ] "pat Slice"
| Range _ -> unimplemented [ pat.span ] "pat Range"
| DerefPattern _ -> unimplemented [ pat.span ] "pat DerefPattern"
| Never -> unimplemented [ pat.span ] "pat Never"
| Error _ -> unimplemented [ pat.span ] "pat Error"
in
Expand Down Expand Up @@ -918,7 +920,9 @@ end) : EXPR = struct
| Char -> TChar
| Int k -> TInt (c_int_ty k)
| Uint k -> TInt (c_uint_ty k)
| Float k -> TFloat (match k with F32 -> F32 | F64 -> F64)
| Float k ->
TFloat
(match k with F16 -> F16 | F32 -> F32 | F64 -> F64 | F128 -> F128)
| Arrow value ->
let ({ inputs; output; _ } : Thir.ty_fn_sig) = value.value in
let inputs =
Expand Down
6 changes: 2 additions & 4 deletions engine/lib/print_rust.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ module Raw = struct
| String s -> "\"" ^ String.escaped s ^ "\""
| Char c -> "'" ^ Char.to_string c ^ "'"
| Int { value; _ } -> value
| Float { value; kind = F32; negative } ->
pnegative negative ^ value ^ "f32"
| Float { value; kind = F64; negative } ->
pnegative negative ^ value ^ "f64"
| Float { value; kind; negative } ->
pnegative negative ^ value ^ show_float_kind kind
| Bool b -> Bool.to_string b

let pprimitive_ident span : _ -> AnnotatedString.t =
Expand Down
8 changes: 6 additions & 2 deletions frontend/exporter/src/constant_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,18 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {
}
impl<'tcx> ConstantExt<'tcx> for ty::Const<'tcx> {
fn eval_constant<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Option<Self> {
let evaluated = self.eval(s.base().tcx, s.param_env(), None).ok()?;
let evaluated = self
.eval(s.base().tcx, s.param_env(), rustc_span::DUMMY_SP)
.ok()?;
let evaluated = ty::Const::new(s.base().tcx, ty::ConstKind::Value(evaluated), self.ty());
(&evaluated != self).then_some(evaluated)
}
}
impl<'tcx> ConstantExt<'tcx> for mir::Const<'tcx> {
fn eval_constant<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Option<Self> {
let evaluated = self.eval(s.base().tcx, s.param_env(), None).ok()?;
let evaluated = self
.eval(s.base().tcx, s.param_env(), rustc_span::DUMMY_SP)
.ok()?;
let evaluated = mir::Const::Val(evaluated, self.ty());
(&evaluated != self).then_some(evaluated)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/exporter/src/rustc_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub(crate) fn read_span_from_file(span: &Span) -> Result<String, ReadSpanErr> {

#[tracing::instrument(skip(sess))]
pub fn translate_span(span: rustc_span::Span, sess: &rustc_session::Session) -> Span {
let smap: &rustc_span::source_map::SourceMap = sess.parse_sess.source_map();
let smap: &rustc_span::source_map::SourceMap = sess.psess.source_map();
let filename = smap.span_to_filename(span);

let lo = smap.lookup_char_pos(span.lo());
Expand Down
52 changes: 34 additions & 18 deletions frontend/exporter/src/types/copied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,13 +981,24 @@ pub struct Block {
pub safety_mode: BlockSafety,
}

/// Reflects [`rustc_middle::thir::BindingMode`]
/// Reflects [`rustc_ast::ast::BindingAnnotation`]
#[derive(AdtInto)]
#[args(<S>, from: rustc_middle::thir::BindingMode, state: S as s)]
#[args(<S>, from: rustc_ast::ast::BindingAnnotation, state: S as s)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub enum BindingMode {
ByValue,
ByRef(BorrowKind),
pub struct BindingAnnotation {
#[value(self.0.sinto(s))]
pub by_ref: ByRef,
#[value(self.1.sinto(s))]
pub mutability: Mutability,
}

/// Reflects [`rustc_ast::ast::ByRef`]
#[derive(AdtInto)]
#[args(<S>, from: rustc_ast::ast::ByRef, state: S as s)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub enum ByRef {
Yes(Mutability),
No,
}

/// Reflects [`rustc_middle::thir::Stmt`]
Expand Down Expand Up @@ -1391,16 +1402,20 @@ pub enum IntTy {
Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, Hash, PartialEq, Eq, PartialOrd, Ord,
)]
pub enum FloatTy {
F16,
F32,
F64,
F128,
}

impl<'tcx, S> SInto<S, FloatTy> for rustc_ast::ast::FloatTy {
fn sinto(&self, _: &S) -> FloatTy {
use rustc_ast::ast::FloatTy as T;
match self {
T::F16 => FloatTy::F16,
T::F32 => FloatTy::F32,
T::F64 => FloatTy::F64,
T::F128 => FloatTy::F128,
}
}
}
Expand Down Expand Up @@ -1676,7 +1691,7 @@ pub enum Ty {
Str,
Array(Box<Ty>, #[map(Box::new(x.sinto(state)))] Box<ConstantExpr>),
Slice(Box<Ty>),
RawPtr(TypeAndMut),
RawPtr(Box<Ty>, Mutability),
Ref(Region, Box<Ty>, Mutability),
Dynamic(Vec<Binder<ExistentialPredicate>>, Region, DynKind),
Coroutine(DefId, Vec<GenericArg>),
Expand Down Expand Up @@ -1879,11 +1894,10 @@ pub enum PatKind {
subpattern: Pat,
},
#[custom_arm(
rustc_middle::thir::PatKind::Binding {mutability, name, mode, var, ty, subpattern, is_primary} => {
rustc_middle::thir::PatKind::Binding {name, mode, var, ty, subpattern, is_primary} => {
let local_ctx = gstate.base().local_ctx;
local_ctx.borrow_mut().vars.insert(var.clone(), name.to_string());
PatKind::Binding {
mutability: mutability.sinto(gstate),
mode: mode.sinto(gstate),
var: var.sinto(gstate),
ty: ty.sinto(gstate),
Expand All @@ -1893,8 +1907,7 @@ pub enum PatKind {
}
)]
Binding {
mutability: Mutability,
mode: BindingMode,
mode: BindingAnnotation,
var: LocalIdent, // name VS var? TODO
ty: Ty,
subpattern: Option<Pat>,
Expand Down Expand Up @@ -1929,6 +1942,9 @@ pub enum PatKind {
Deref {
subpattern: Pat,
},
DerefPattern {
subpattern: Pat,
},
Constant {
value: ConstantExpr,
},
Expand Down Expand Up @@ -2070,8 +2086,8 @@ pub struct MacroInvokation {
pub enum ImplicitSelfKind {
Imm,
Mut,
ImmRef,
MutRef,
RefImm,
RefMut,
None,
}

Expand Down Expand Up @@ -2612,7 +2628,7 @@ impl<'x: 'tcx, 'tcx, S: UnderOwnerState<'tcx>> SInto<S, Ty> for rustc_hir::Ty<'x
// access to the HIR of external objects, only their MIR).
let ctx =
rustc_hir_analysis::collect::ItemCtxt::new(s.base().tcx, s.owner_id().expect_local());
ctx.to_ty(self).sinto(s)
ctx.lower_ty(self).sinto(s)
}
}

Expand Down Expand Up @@ -2711,7 +2727,7 @@ pub enum ParamName {
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub enum LifetimeParamKind {
Explicit,
Elided,
Elided(MissingLifetimeKind),
Error,
}

Expand Down Expand Up @@ -2959,12 +2975,12 @@ pub struct UsePath {
pub res: Vec<Res>,
pub segments: Vec<PathSegment>,
#[value(self.segments.iter().last().map_or(None, |segment| {
match s.base().tcx.opt_hir_node_by_def_id(segment.hir_id.owner.def_id) {
Some(rustc_hir::Node::Item(rustc_hir::Item {
match s.base().tcx.hir_node_by_def_id(segment.hir_id.owner.def_id) {
rustc_hir::Node::Item(rustc_hir::Item {
ident,
kind: rustc_hir::ItemKind::Use(_, _),
..
})) if ident.name.to_ident_string() != "" => Some(ident.name.to_ident_string()),
}) if ident.name.to_ident_string() != "" => Some(ident.name.to_ident_string()),
_ => None,
}
}))]
Expand Down Expand Up @@ -3238,7 +3254,7 @@ pub struct TraitRef {
)]
pub struct TraitPredicate {
pub trait_ref: TraitRef,
#[map(x.clone() == rustc_middle::ty::ImplPolarity::Positive)]
#[map(x.clone() == rustc_middle::ty::PredicatePolarity::Positive)]
#[from(polarity)]
pub is_positive: bool,
}
Expand Down
16 changes: 4 additions & 12 deletions frontend/exporter/src/types/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,12 @@ pub mod mir_kinds {
fn get_mir<'tcx>(tcx: TyCtxt<'tcx>, id: LocalDefId) -> &'tcx Steal<Body<'tcx>>;
}
#[derive(Clone, Copy, Debug, JsonSchema, Serialize, Deserialize)]
pub struct Const;
impl IsMirKind for Const {
fn get_mir<'tcx>(tcx: TyCtxt<'tcx>, id: LocalDefId) -> &'tcx Steal<Body<'tcx>> {
tcx.mir_const(id)
}
}
#[derive(Clone, Copy, Debug, JsonSchema, Serialize, Deserialize)]
pub struct Built;
impl IsMirKind for Built {
fn get_mir<'tcx>(tcx: TyCtxt<'tcx>, id: LocalDefId) -> &'tcx Steal<Body<'tcx>> {
tcx.mir_built(id)
}
}
// TODO: Add [Promoted] MIR
}
pub use mir_kinds::IsMirKind;

Expand Down Expand Up @@ -585,7 +577,7 @@ pub enum TerminatorKind {
operands: Vec<InlineAsmOperand>,
options: InlineAsmOptions,
line_spans: Vec<Span>,
destination: Option<BasicBlock>,
targets: Vec<BasicBlock>,
unwind: UnwindAction,
},
}
Expand Down Expand Up @@ -613,7 +605,7 @@ pub enum StatementKind {
Retag(RetagKind, Place),
PlaceMention(Place),
AscribeUserType((Place, UserTypeProjection), Variance),
Coverage(Coverage),
Coverage(CoverageKind),
Intrinsic(NonDivergingIntrinsic),
ConstEvalCounter,
Nop,
Expand Down Expand Up @@ -925,7 +917,7 @@ pub enum NullOp {
SizeOf,
AlignOf,
OffsetOf(Vec<(usize, FieldIdx)>),
DebugAssertions,
UbChecks,
}

#[derive(AdtInto, Clone, Debug, Serialize, Deserialize, JsonSchema)]
Expand Down Expand Up @@ -981,11 +973,11 @@ sinto_todo!(rustc_middle::mir, AssertMessage<'tcx>);
sinto_todo!(rustc_middle::mir, UnwindAction);
sinto_todo!(rustc_middle::mir, FakeReadCause);
sinto_todo!(rustc_middle::mir, RetagKind);
sinto_todo!(rustc_middle::mir, Coverage);
sinto_todo!(rustc_middle::mir, NonDivergingIntrinsic<'tcx>);
sinto_todo!(rustc_middle::mir, UserTypeProjection);
sinto_todo!(rustc_middle::mir, MirSource<'tcx>);
sinto_todo!(rustc_middle::mir, CoroutineInfo<'tcx>);
sinto_todo!(rustc_middle::mir, VarDebugInfo<'tcx>);
sinto_todo!(rustc_middle::mir, CallSource);
sinto_todo!(rustc_middle::mir::coverage, CoverageKind);
sinto_todo!(rustc_span, ErrorGuaranteed);
1 change: 1 addition & 0 deletions frontend/exporter/src/types/todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sinto_todo!(rustc_hir::def, DefKind);
sinto_todo!(rustc_hir, GenericArgs<'a> as HirGenericArgs);
sinto_todo!(rustc_hir, InlineAsm<'a>);
sinto_todo!(rustc_target::spec::abi, Abi);
sinto_todo!(rustc_hir, MissingLifetimeKind);
sinto_todo!(rustc_hir, WhereRegionPredicate<'tcx>);
sinto_todo!(rustc_hir, WhereEqPredicate<'tcx>);
sinto_todo!(rustc_hir, OwnerId);
Loading

0 comments on commit e1439bf

Please sign in to comment.