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 rustc all at once #735

Merged
merged 18 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
26 changes: 12 additions & 14 deletions cli/driver/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,26 @@ use rustc_middle::{
thir,
thir::{Block, BlockId, Expr, ExprId, ExprKind, Pat, PatKind, Stmt, StmtId, StmtKind, Thir},
};
use rustc_session::parse::ParseSess;
use rustc_span::symbol::Symbol;
use serde::Serialize;
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::rc::Rc;

fn report_diagnostics(
tcx: TyCtxt<'_>,
output: &hax_cli_options_engine::Output,
session: &rustc_session::Session,
mapping: &Vec<(hax_frontend_exporter::Span, rustc_span::Span)>,
) {
for d in &output.diagnostics {
use hax_diagnostics::*;
session.span_hax_err(d.convert(mapping).into());
tcx.dcx().span_hax_err(d.convert(mapping).into());
}
}

fn write_files(
tcx: TyCtxt<'_>,
output: &hax_cli_options_engine::Output,
session: &rustc_session::Session,
backend: hax_cli_options::Backend,
) {
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
Expand All @@ -43,9 +42,9 @@ fn write_files(
for file in output.files.clone() {
let path = out_dir.join(&file.path);
std::fs::create_dir_all(&path.parent().unwrap()).unwrap();
session.note_without_error(format!("Writing file {:#?}", path));
tcx.dcx().note(format!("Writing file {:#?}", path));
std::fs::write(&path, file.contents).unwrap_or_else(|e| {
session.fatal(format!(
tcx.dcx().fatal(format!(
"Unable to write to file {:#?}. Error: {:#?}",
path, e
))
Expand Down Expand Up @@ -127,11 +126,11 @@ fn precompute_local_thir_bodies<'tcx>(
.filter(|ldid| hir.maybe_body_owned_by(*ldid).is_some())
.map(|ldid| {
tracing::debug!("⏳ Type-checking THIR body for {:#?}", ldid);
let span = hir.span(hir.local_def_id_to_hir_id(ldid));
let span = hir.span(tcx.local_def_id_to_hir_id(ldid));
let (thir, expr) = match tcx.thir_body(ldid) {
Ok(x) => x,
Err(e) => {
tcx.sess.span_err(
tcx.dcx().span_err(
span,
"While trying to reach a body's THIR defintion, got a typechecking error.",
);
Expand All @@ -143,7 +142,7 @@ fn precompute_local_thir_bodies<'tcx>(
})) {
Ok(x) => x,
Err(e) => {
tcx.sess.span_err(span, format!("The THIR body of item {:?} was stolen.\nThis is not supposed to happen.\nThis is a bug in Hax's frontend.\nThis is discussed in issue https://github.com/hacspec/hax/issues/27.\nPlease comment this issue if you see this error message!", ldid));
tcx.dcx().span_err(span, format!("The THIR body of item {:?} was stolen.\nThis is not supposed to happen.\nThis is a bug in Hax's frontend.\nThis is discussed in issue https://github.com/hacspec/hax/issues/27.\nPlease comment this issue if you see this error message!", ldid));
return (ldid, dummy_thir_body(tcx, span));
}
};
Expand Down Expand Up @@ -298,7 +297,7 @@ impl Callbacks for ExtractionCallbacks {
.into_iter()
.map(|(k, v)| {
use hax_frontend_exporter::*;
let sess = compiler.session();
let sess = &compiler.sess;
(
translate_span(k, sess),
translate_span(argument_span_of_mac_call(&v), sess),
Expand Down Expand Up @@ -432,9 +431,8 @@ impl Callbacks for ExtractionCallbacks {
.unwrap();

let out = engine_subprocess.wait_with_output().unwrap();
let session = compiler.session();
if !out.status.success() {
session.fatal(format!(
tcx.dcx().fatal(format!(
"{} exited with non-zero code {}\nstdout: {}\n stderr: {}",
ENGINE_BINARY_NAME,
out.status.code().unwrap_or(-1),
Expand All @@ -456,8 +454,8 @@ impl Callbacks for ExtractionCallbacks {
let state =
hax_frontend_exporter::state::State::new(tcx, options_frontend.clone());
report_diagnostics(
tcx,
&output,
&session,
&spans
.into_iter()
.map(|span| (span.sinto(&state), span.clone()))
Expand All @@ -467,7 +465,7 @@ impl Callbacks for ExtractionCallbacks {
serde_json::to_writer(std::io::BufWriter::new(std::io::stdout()), &output)
.unwrap()
} else {
write_files(&output, &session, backend.backend);
write_files(tcx, &output, backend.backend);
}
if let Some(debug_json) = &output.debug_json {
use hax_cli_options::DebugEngineMode;
Expand Down
3 changes: 1 addition & 2 deletions cli/driver/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ impl Callbacks for LinterCallbacks {
compiler: &Compiler,
queries: &'tcx Queries<'tcx>,
) -> Compilation {
let session = compiler.session();
queries
.global_ctxt()
.unwrap()
.enter(|tcx| hax_lint::Linter::register(tcx, session, self.ltype));
.enter(|tcx| hax_lint::Linter::register(tcx, self.ltype));

Compilation::Continue
}
Expand Down
10 changes: 4 additions & 6 deletions engine/lib/concrete_ident/concrete_ident.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ module Imported = struct
| ForeignMod
| Use
| GlobalAsm
| ClosureExpr
| Closure
| Ctor
| AnonConst
| ImplTrait
| ImplTraitAssocTy
| OpaqueTy
| TypeNs of string
| ValueNs of string
| MacroNs of string
Expand All @@ -32,11 +31,10 @@ module Imported = struct
| ForeignMod -> ForeignMod
| Use -> Use
| GlobalAsm -> GlobalAsm
| ClosureExpr -> ClosureExpr
| Closure -> Closure
| Ctor -> Ctor
| AnonConst -> AnonConst
| ImplTrait -> ImplTrait
| ImplTraitAssocTy -> ImplTraitAssocTy
| OpaqueTy -> OpaqueTy
| TypeNs s -> TypeNs s
| ValueNs s -> ValueNs s
| MacroNs s -> MacroNs s
Expand Down
11 changes: 7 additions & 4 deletions engine/lib/import_thir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,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"
| Never -> unimplemented [ pat.span ] "pat Never"
| Error _ -> unimplemented [ pat.span ] "pat Error"
in
{ p = v; span; typ }
Expand Down Expand Up @@ -1359,19 +1360,21 @@ and c_item_unwrapped ~ident ~drop_body (item : Thir.item) : item list =
List.for_all
~f:(fun { data; _ } ->
match data with
| Unit _ | Tuple ([], _, _) | Struct ([], _) -> true
| Unit _ | Tuple ([], _, _) | Struct { fields = []; _ } -> true
| _ -> false)
variants
in
let variants =
List.map
~f:
(fun ({ data; def_id = variant_id; attributes; _ } as original) ->
let is_record = [%matches? Types.Struct (_ :: _, _)] data in
let is_record =
[%matches? Types.Struct { fields = _ :: _; _ }] data
in
let name = Concrete_ident.of_def_id kind variant_id in
let arguments =
match data with
| Tuple (fields, _, _) | Struct (fields, _) ->
| Tuple (fields, _, _) | Struct { fields; _ } ->
List.map
~f:(fun { def_id = id; ty; span; attributes; _ } ->
( Concrete_ident.of_def_id Field id,
Expand Down Expand Up @@ -1415,7 +1418,7 @@ and c_item_unwrapped ~ident ~drop_body (item : Thir.item) : item list =
in
match v with
| Tuple (fields, _, _) -> mk fields false
| Struct ((_ :: _ as fields), _) -> mk fields true
| Struct { fields = _ :: _ as fields; _ } -> mk fields true
| _ -> { name; arguments = []; is_record = false; attrs }
in
let variants = [ v ] in
Expand Down
5 changes: 2 additions & 3 deletions engine/names/extract/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ fn def_path_item_to_str(path_item: DefPathItem) -> String {
DefPathItem::ForeignMod => "ForeignMod".into(),
DefPathItem::Use => "Use".into(),
DefPathItem::GlobalAsm => "GlobalAsm".into(),
DefPathItem::ClosureExpr => "ClosureExpr".into(),
DefPathItem::Closure => "Closure".into(),
DefPathItem::Ctor => "Ctor".into(),
DefPathItem::AnonConst => "AnonConst".into(),
DefPathItem::ImplTrait => "ImplTrait".into(),
DefPathItem::ImplTraitAssocTy => "ImplTraitAssocTy".into(),
DefPathItem::OpaqueTy => "OpaqueTy".into(),
}
}

Expand Down
9 changes: 9 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@
check-toolchain = checks.toolchain;
check-examples = checks.examples;
check-readme-coherency = checks.readme-coherency;

# The commit that corresponds to our nightly pin, helpful when updating rusrc.
toolchain_commit = pkgs.runCommand "hax-toolchain-commit" { } ''
# This is sad but I don't know a better way.
cat ${rustc}/share/doc/rust/html/version_info.html \
| grep 'github.com' \
| sed 's#.*"https://github.com/rust-lang/rust/commit/\([^"]*\)".*#\1#' \
> $out
'';
};
checks = {
toolchain = packages.hax.tests;
Expand Down
Loading
Loading