Skip to content

Commit f7ed4cd

Browse files
committed
Updated rustc version
1 parent f514381 commit f7ed4cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+112
-366
lines changed

cargo_tests/fastrand_test/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(start, core_intrinsics, lang_items)]
1+
#![feature( core_intrinsics, lang_items)]
22
use fastrand::*;
33
use mycorrhiza::{panic_handler, start};
44
use std::hint::black_box;

cargo_tests/hello_world/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
adt_const_params,
1212
associated_type_defaults,
1313
core_intrinsics,
14-
start
1514
)]
1615

1716
use mycorrhiza::{panic_handler, start};

cargo_tests/std_hello_world/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(internal_features,unused_imports,incomplete_features,unused_variables,dead_code,improper_ctypes_definitions)]
2-
#![feature(lang_items,adt_const_params,associated_type_defaults,core_intrinsics,start)]
2+
#![feature(lang_items,adt_const_params,associated_type_defaults,core_intrinsics)]
33
use mycorrhiza::{start,panic_handler};
44
fn main() {
55
let sb = mycorrhiza::system::text::StringBuilder::empty();

cilly/src/v2/c_exporter/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn escape_ident(ident: &str) -> String {
7171
match escaped.as_str() {
7272
"int" | "default" | "float" | "double" | "long" | "short" | "register" | "stderr"
7373
| "environ" | "struct" | "union" | "linux" | "inline" | "asm" | "signed" | "unsigned"
74-
| "bool" | "char" | "case" | "switch" | "volatile" | "auto" | "void" | "unix" => {
74+
| "bool" | "char" | "case" | "switch" | "volatile" | "auto" | "void" | "unix" => {
7575
format!("i{}", encode(hash64(&escaped)))
7676
}
7777
_ => escaped,
@@ -1426,10 +1426,10 @@ pub fn name_sig_class_to_mangled(
14261426
None => todo!(),
14271427
};
14281428
}
1429-
fn escape_nonfn_name(name:&str)->String{
1429+
fn escape_nonfn_name(name: &str) -> String {
14301430
let res = escape_ident(name);
1431-
match res.as_ref(){
1432-
"sigaction"=>"sigactn".to_owned(),
1433-
_=>res,
1431+
match res.as_ref() {
1432+
"sigaction" => "sigactn".to_owned(),
1433+
_ => res,
14341434
}
1435-
}
1435+
}

src/aggregate.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
operand::handle_operand,
44
place::{place_get, place_set},
55
r#type::{get_type, pointer_to_is_fat},
6-
utilis::{adt::set_discr, field_name},
6+
utilis::{adt::set_discr, field_name, instance_try_resolve},
77
};
88
use cilly::{
99
cil_node::CILNode,
@@ -40,11 +40,8 @@ pub fn handle_aggregate<'tcx>(
4040
let penv = rustc_middle::ty::TypingEnv::fully_monomorphized();
4141
let subst = ctx.monomorphize(*subst);
4242
//eprintln!("Preparing to resolve {adt_def:?} {subst:?}");
43-
let adt_type = Instance::try_resolve(ctx.tcx(), penv, *adt_def, subst);
44-
43+
let adt_type = instance_try_resolve(*adt_def,ctx.tcx(), subst);
4544
let adt_type = adt_type
46-
.expect("Could not resolve instance")
47-
.expect("Could not resolve instance")
4845
.ty(ctx.tcx(), penv);
4946
let adt_type = ctx.monomorphize(adt_type);
5047
let TyKind::Adt(adt_def, subst) = adt_type.kind() else {

src/assembly.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,7 @@ pub fn add_allocation(alloc_id: u64, asm: &mut cilly::v2::Assembly, tcx: TyCtxt<
725725
let byte_hash = calculate_hash(&bytes);
726726
match (align, bytes.len()) {
727727
// Assumes this constant is not a pointer.
728-
(0..=1, 1) | (0..=2, 1..=2) | (0..=4, 1..=4) | (0..=8, 1..=16)
729-
=>
730-
{
728+
(0..=1, 1) | (0..=2, 1..=2) | (0..=4, 1..=4) | (0..=8, 1..=16) => {
731729
let alloc_name: IString = if let Some(krate) = krate {
732730
format!(
733731
"s_{}_{}_{}_{thread_local}_{}",

src/binop/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,7 @@ pub(crate) fn binop<'tcx>(
141141
.get_lang_items(())
142142
.get(LangItem::OrderingEnum)
143143
.unwrap();
144-
let ordering = Instance::try_resolve(
145-
ctx.tcx(),
146-
rustc_middle::ty::TypingEnv::fully_monomorphized(),
147-
ordering,
148-
List::empty(),
149-
)
150-
.unwrap()
151-
.unwrap();
144+
let ordering = crate::utilis::instance_try_resolve(ordering, ctx.tcx(), List::empty());
152145
let ordering_ty = ordering.ty(
153146
ctx.tcx(),
154147
rustc_middle::ty::TypingEnv::fully_monomorphized(),

src/compile_test.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ fn test_lib(args: &[&str], test_name: &str) {
101101
RUSTC_BUILD_STATUS.as_ref().expect("Could not build rustc!");
102102
// Compiles the test project
103103
let mut command = std::process::Command::new("rustc");
104+
command.arg("-Ctarget-feature=+x87+sse");
104105
let command = command
105106
.current_dir("./test/out")
106107
//.env("RUST_TARGET_PATH","../../")
@@ -113,7 +114,7 @@ fn test_lib(args: &[&str], test_name: &str) {
113114
command
114115
};
115116
let out = command.output().expect("failed to execute process");
116-
if !out.stderr.is_empty() {
117+
if String::from_utf8(out.stderr.clone()).unwrap().contains("error:") {
117118
let stdout =
118119
String::from_utf8(out.stdout).expect("rustc error contained non-UTF8 characters.");
119120
let stderr =
@@ -164,7 +165,7 @@ macro_rules! compare_tests {
164165
let copy = format!("{cmd:?}");
165166
let out = cmd.output().expect("failed to execute process");
166167
// If stderr is not empty, then something went wrong, so print the stdout and stderr for debuging.
167-
if !out.stderr.is_empty() {
168+
if String::from_utf8(out.stderr.clone()).unwrap().contains("error:") {
168169
let stdout = String::from_utf8(out.stdout)
169170
.expect("rustc error contained non-UTF8 characters.");
170171
let stderr = String::from_utf8(out.stderr)
@@ -195,11 +196,12 @@ macro_rules! compare_tests {
195196
concat!("./", stringify!($test_name), ".a"),
196197
"--edition",
197198
"2021",
199+
"-Ctarget-feature=+x87+sse",
198200
]);
199201
let copy = format!("{cmd:?}");
200202
let out = cmd.output().expect("failed to execute process");
201203
// If stderr is not empty, then something went wrong, so print the stdout and stderr for debuging.
202-
if !out.stderr.is_empty() {
204+
if String::from_utf8(out.stderr.clone()).unwrap().contains("error:") {
203205
let stdout = String::from_utf8(out.stdout)
204206
.expect("rustc error contained non-UTF8 characters.");
205207
let stderr = String::from_utf8(out.stderr)
@@ -242,7 +244,7 @@ macro_rules! compare_tests {
242244
let mut cmd = super::super::compiler(stringify!($test_name), test_dir, true);
243245
let out = cmd.output().expect("failed to execute process");
244246
// If stderr is not empty, then something went wrong, so print the stdout and stderr for debuging.
245-
if !out.stderr.is_empty() {
247+
if String::from_utf8(out.stderr.clone()).unwrap().contains("error:") {
246248
let stdout = String::from_utf8(out.stdout)
247249
.expect("rustc error contained non-UTF8 characters.");
248250
let stderr = String::from_utf8(out.stderr)
@@ -273,10 +275,11 @@ macro_rules! compare_tests {
273275
concat!("./", stringify!($test_name), ".a"),
274276
"--edition",
275277
"2021",
278+
"-Ctarget-feature=+x87+sse",
276279
]);
277280
let out = cmd.output().expect("failed to execute process");
278281
// If stderr is not empty, then something went wrong, so print the stdout and stderr for debuging.
279-
if !out.stderr.is_empty() {
282+
if String::from_utf8(out.stderr.clone()).unwrap().contains("error:") {
280283
let stdout = String::from_utf8(out.stdout)
281284
.expect("rustc error contained non-UTF8 characters.");
282285
let stderr = String::from_utf8(out.stderr)
@@ -384,6 +387,7 @@ fn compiler(test_name: &str, test_dir: &str, release: bool) -> std::process::Com
384387
if *crate::config::DRY_RUN {
385388
cmd.args(["-Z", "no-codegen"]);
386389
}
390+
cmd.arg("-Ctarget-feature=+x87+sse",);
387391
cmd
388392
}
389393
macro_rules! run_test {
@@ -410,7 +414,7 @@ macro_rules! run_test {
410414
eprintln!("Command: {cmd:?}");
411415
let out = cmd.output().expect("failed to execute process");
412416
// If stderr is not empty, then something went wrong, so print the stdout and stderr for debuging.
413-
if !out.stderr.is_empty() {
417+
if String::from_utf8(out.stderr.clone()).unwrap().contains("error:") {
414418
let stdout = String::from_utf8(out.stdout)
415419
.expect("rustc error contained non-UTF8 characters.");
416420
let stderr = String::from_utf8(out.stderr)
@@ -444,7 +448,7 @@ macro_rules! run_test {
444448
eprintln!("test_name:{test_name:?}");
445449
let out = cmd.output().expect("failed to execute process");
446450
// If stderr is not empty, then something went wrong, so print the stdout and stderr for debuging.
447-
if !out.stderr.is_empty() {
451+
if String::from_utf8(out.stderr.clone()).unwrap().contains("error:") {
448452
let stdout = String::from_utf8(out.stdout)
449453
.expect("rustc error contained non-UTF8 characters.");
450454
let stderr = String::from_utf8(out.stderr)
@@ -732,6 +736,7 @@ run_test! {alloc,abox,stable}
732736
run_test! {alloc,raw_vec,stable}
733737
run_test! {alloc,slice_to_owned,stable}
734738
run_test! {arthm,add,stable}
739+
run_test! {arthm,ptr,stable}
735740
run_test! {arthm,cmp,stable}
736741
run_test! {arthm,greater_than,stable}
737742
run_test! {arthm,max,stable}
@@ -764,7 +769,7 @@ run_test! {intrinsics,cmp_bytes,stable}
764769
run_test! {intrinsics,copy_nonoverlaping,stable}
765770
run_test! {intrinsics,ctpop,stable}
766771
run_test! {intrinsics,malloc,stable}
767-
run_test! {intrinsics,offset_of,unstable}
772+
run_test! {intrinsics,offset_of,stable}
768773
run_test! {intrinsics,overflow_ops,stable}
769774
run_test! {intrinsics,pow_sqrt,stable}
770775
run_test! {intrinsics,printf,stable}
@@ -783,11 +788,11 @@ run_test! {std,const_error,stable}
783788
run_test! {std,cell_test,unstable}
784789
run_test! {std,cstr,unstable}
785790
run_test! {std,format,unstable}
786-
run_test! {std,futex_test,unstable}
787-
run_test! {std,futexrw_test,unstable}
791+
run_test! {std,futex_test,stable}
792+
run_test! {std,futexrw_test,stable}
788793
run_test! {std,main,stable}
789794
run_test! {std,mutithreading,stable}
790-
run_test! {std,once_lock_test,unstable}
795+
run_test! {std,once_lock_test,stable}
791796
run_test! {std,tlocal_key_test,stable}
792797
run_test! {std,uninit_fill,stable}
793798

@@ -797,7 +802,7 @@ run_test! {types,f16,stable}
797802
run_test! {types,aligned,stable}
798803
run_test! {types,any,stable}
799804
run_test! {types,arr,stable}
800-
run_test! {types,async_types,unstable}
805+
run_test! {types,async_types,stable}
801806
run_test! {types,dst,stable}
802807
run_test! {types,dyns,stable}
803808
run_test! {types,enums,stable}
@@ -951,7 +956,7 @@ compare_tests! {fuzz,fail8,stable}
951956

952957
compare_tests! {fuzz,fail9,stable}
953958
// TODO: fix this test. It is a NaN issue, so it is a very low prioity, but it should still get fixed or something.
954-
compare_tests! {fuzz,fail10,unstable}
959+
compare_tests! {fuzz,fail10,stable}
955960
compare_tests! {fuzz,fail11,stable}
956961

957962
cargo_test! {hello_world,stable}

src/lib.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl CodegenBackend for MyBackend {
204204
need_metadata_module: bool,
205205
) -> Box<dyn Any> {
206206
{
207-
let (_defid_set, cgus) = tcx.collect_and_partition_mono_items(());
207+
let cgus = tcx.collect_and_partition_mono_items(());
208208

209209
let mut asm = Assembly::default();
210210
if need_metadata_module {
@@ -218,7 +218,7 @@ impl CodegenBackend for MyBackend {
218218
}
219219
let _ = cilly::utilis::get_environ(&mut asm);
220220

221-
for cgu in cgus {
221+
for cgu in cgus.codegen_units {
222222
//println!("codegen {} has {} items.", cgu.name(), cgu.items().len());
223223
for (item, _data) in cgu.items() {
224224
assembly::add_item(&mut asm, *item, tcx).expect("Could not add function");
@@ -256,7 +256,14 @@ impl CodegenBackend for MyBackend {
256256
.generic_activity("insert .NET FFI functions/types");
257257
//builtin::insert_ffi_functions(&mut asm, tcx);
258258
drop(ffi_compile_timer);
259-
let name: IString = cgus.iter().next().unwrap().name().to_string().into();
259+
let name: IString = cgus
260+
.codegen_units
261+
.iter()
262+
.next()
263+
.unwrap()
264+
.name()
265+
.to_string()
266+
.into();
260267

261268
Box::new((name, asm, metadata, CrateInfo::new(tcx, "clr".to_string())))
262269
}

src/rvalue.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,36 @@ pub fn handle_rvalue<'tcx>(
5555
ctx: &mut MethodCompileCtx<'tcx, '_>,
5656
) -> (Vec<CILRoot>, CILNode) {
5757
match rvalue {
58+
Rvalue::Len(operand) => {
59+
let ty = ctx.monomorphize(operand.ty(ctx.body(), ctx.tcx()));
60+
match ty.ty.kind() {
61+
TyKind::Slice(inner) => {
62+
let slice_tpe = fat_ptr_to(*inner, ctx);
63+
let descriptor = FieldDesc::new(
64+
slice_tpe,
65+
ctx.alloc_string(crate::METADATA),
66+
cilly::v2::Type::Int(Int::USize),
67+
);
68+
let addr = crate::place::place_address_raw(operand, ctx);
69+
assert!(
70+
!matches!(addr, CILNode::LDLoc(_)),
71+
"improper addr {addr:?}. operand:{operand:?}"
72+
);
73+
(vec![], ld_field!(addr, ctx.alloc_field(descriptor)))
74+
}
75+
TyKind::Array(_ty, length) => {
76+
let len =
77+
crate::utilis::try_resolve_const_size(ctx.monomorphize(*length)).unwrap();
78+
(
79+
vec![],
80+
CILNode::V2(ctx.alloc_node(Const::USize(len as u64))),
81+
)
82+
}
83+
_ => todo!("Get length of type {ty:?}"),
84+
}
85+
}
5886
Rvalue::Use(operand) => (vec![], handle_operand(operand, ctx)),
5987
Rvalue::CopyForDeref(place) => (vec![], crate::place::place_get(place, ctx)),
60-
6188
Rvalue::Ref(_region, _borrow_kind, place) => {
6289
(vec![], crate::place::place_adress(place, ctx))
6390
}

src/type/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub fn get_type<'tcx>(ty: Ty<'tcx>, ctx: &mut MethodCompileCtx<'tcx, '_>) -> Typ
172172
if pointer_to_is_fat(*inner, ctx.tcx(), ctx.instance()) {
173173
let inner = match inner.kind() {
174174
TyKind::Slice(inner) => ctx.monomorphize(*inner),
175-
TyKind::Str => Ty::new(ctx.tcx(), TyKind::Uint(UintTy::U8)),
175+
TyKind::Str => Ty::new_uint(ctx.tcx(), UintTy::U8),
176176
_ => ctx.monomorphize(*inner),
177177
};
178178
Type::ClassRef(fat_ptr_to(inner, ctx))

src/unsize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn unsize2<'tcx>(
3737
ctx.layout_of(operand.ty(ctx.body(), ctx.tcx())),
3838
ctx.layout_of(target),
3939
);
40-
let fat_ptr_type = fat_ptr_to(Ty::new(ctx.tcx(), TyKind::Uint(UintTy::U8)), ctx);
40+
let fat_ptr_type = fat_ptr_to(Ty::new_uint(ctx.tcx(), (UintTy::U8)), ctx);
4141

4242
let metadata_field = FieldDesc::new(
4343
fat_ptr_type,

src/utilis/mod.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ use cilly::{
33
utilis::escape_class_name,
44
v2::{FieldDesc, FieldIdx},
55
};
6+
use rustc_hir::def_id::DefId;
67
use rustc_middle::{
78
mir::interpret::AllocId,
89
ty::{
910
AdtDef, Const, ConstKind, EarlyBinder, GenericArg, Instance, List, ParamEnv,
1011
PseudoCanonicalInput, SymbolName, Ty, TyCtxt, TyKind, TypeFoldable,
1112
},
1213
};
14+
1315
pub mod adt;
1416
pub const CTOR_FN_NAME: &str = "rustc_clr_interop_managed_ctor";
1517
pub const MANAGED_CALL_FN_NAME: &str = "rustc_clr_interop_managed_call";
@@ -28,29 +30,27 @@ pub fn as_adt(ty: Ty) -> Option<(AdtDef, &List<GenericArg>)> {
2830
_ => None,
2931
}
3032
}
33+
// WARNING: this is *wrong*: For some reason, `Instance::try_resolve` should not operate on structs(why?), and this just silences the newly introduced warning.
34+
pub fn instance_try_resolve<'tcx>(
35+
adt: DefId,
36+
tcx: TyCtxt<'tcx>,
37+
gargs: &'tcx List<GenericArg<'tcx>>,
38+
) -> Instance<'tcx> {
39+
tcx.resolve_instance_raw(PseudoCanonicalInput {
40+
typing_env: rustc_middle::ty::TypingEnv::fully_monomorphized(),
41+
value: (adt, gargs),
42+
})
43+
.unwrap()
44+
.unwrap()
45+
}
3146
pub fn adt_name<'tcx>(
3247
adt: AdtDef<'tcx>,
3348
tcx: TyCtxt<'tcx>,
3449
gargs: &'tcx List<GenericArg<'tcx>>,
3550
) -> crate::IString {
36-
//TODO: find a better way to get adt name!
37-
let _gdef_str = if gargs
38-
.iter()
39-
.any(|garg| garg.as_type().is_some() || garg.as_const().is_some())
40-
{
41-
rustc_middle::ty::print::with_no_trimmed_paths! {tcx.def_path_str_with_args(adt.did(),gargs)}
42-
} else {
43-
rustc_middle::ty::print::with_no_trimmed_paths! {tcx.def_path_str(adt.did())}
44-
};
51+
//TODO: find a better way to get adt instances!
4552
let krate = adt.did().krate;
46-
let adt_instance = Instance::try_resolve(
47-
tcx,
48-
rustc_middle::ty::TypingEnv::fully_monomorphized(),
49-
adt.did(),
50-
gargs,
51-
)
52-
.unwrap()
53-
.unwrap();
53+
let adt_instance = instance_try_resolve(adt.did(), tcx, gargs);
5454
// Get the mangled path: it is absolute, and not poluted by types being rexported
5555
let auto_mangled =
5656
rustc_symbol_mangling::symbol_name_for_instance_in_crate(tcx, adt_instance, krate);

0 commit comments

Comments
 (0)