Skip to content

Commit ca5dd1f

Browse files
committed
Fix.
1 parent 848a2ca commit ca5dd1f

12 files changed

Lines changed: 315 additions & 232 deletions

File tree

monoruby/src/builtins/dir.rs

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,11 @@ fn glob_impl(
524524
}
525525
// Matches inherit the pattern's encoding (glob_spec.rb
526526
// "preserves the encoding of the path").
527-
all_matches
528-
.extend(matches.into_iter().map(|m| {
529-
RStringInner::from_encoding(m.as_bytes(), *enc)
530-
}));
527+
all_matches.extend(
528+
matches
529+
.into_iter()
530+
.map(|m| RStringInner::from_encoding(m.as_bytes(), *enc)),
531+
);
531532
}
532533
}
533534
Ok(all_matches)
@@ -817,7 +818,10 @@ fn home(vm: &mut Executor, globals: &mut Globals, lfp: Lfp, _: BytecodePtr) -> R
817818
if let Some(arg) = lfp.try_arg(0)
818819
&& !arg.is_nil()
819820
{
820-
let user = arg.coerce_to_path_rstring(vm, globals)?.to_str()?.to_string();
821+
let user = arg
822+
.coerce_to_path_rstring(vm, globals)?
823+
.to_str()?
824+
.to_string();
821825
let c_user = std::ffi::CString::new(user.as_bytes())
822826
.map_err(|_| MonorubyErr::argumenterr("user name cannot contain NUL"))?;
823827
// SAFETY: `getpwnam` reads the passwd DB for the NUL-terminated name
@@ -970,7 +974,12 @@ fn entries(vm: &mut Executor, globals: &mut Globals, lfp: Lfp, _: BytecodePtr) -
970974
/// Open `path` with `O_RDONLY|O_DIRECTORY|O_CLOEXEC` and return the fd.
971975
/// Backs `Dir#initialize` in builtins/dir.rb.
972976
#[monoruby_builtin]
973-
fn dir_open_fd(vm: &mut Executor, globals: &mut Globals, lfp: Lfp, _: BytecodePtr) -> Result<Value> {
977+
fn dir_open_fd(
978+
vm: &mut Executor,
979+
globals: &mut Globals,
980+
lfp: Lfp,
981+
_: BytecodePtr,
982+
) -> Result<Value> {
974983
let path = lfp.arg(0).coerce_to_path_rstring(vm, globals)?;
975984
super::file::check_path_encoding(globals, &path)?;
976985
if path.as_bytes().contains(&0) {
@@ -1004,13 +1013,22 @@ fn dir_open_fd(vm: &mut Executor, globals: &mut Globals, lfp: Lfp, _: BytecodePt
10041013
/// close(2) a directory fd, surfacing failures the way CRuby's
10051014
/// `closedir` does (`Errno::EBADF: Bad file descriptor - closedir`).
10061015
#[monoruby_builtin]
1007-
fn dir_close_fd(vm: &mut Executor, globals: &mut Globals, lfp: Lfp, _: BytecodePtr) -> Result<Value> {
1016+
fn dir_close_fd(
1017+
vm: &mut Executor,
1018+
globals: &mut Globals,
1019+
lfp: Lfp,
1020+
_: BytecodePtr,
1021+
) -> Result<Value> {
10081022
let fd = lfp.arg(0).coerce_to_int_i64(vm, globals)? as i32;
10091023
// SAFETY: close(2); an invalid fd is reported via errno, not UB.
10101024
let rc = unsafe { libc::close(fd) };
10111025
if rc != 0 {
10121026
let err = std::io::Error::last_os_error();
1013-
return Err(MonorubyErr::errno_with_msg(&globals.store, &err, "closedir"));
1027+
return Err(MonorubyErr::errno_with_msg(
1028+
&globals.store,
1029+
&err,
1030+
"closedir",
1031+
));
10141032
}
10151033
Ok(Value::nil())
10161034
}
@@ -1035,25 +1053,22 @@ fn dir_entries_fd(
10351053

10361054
/// Read the `@path` ivar set by Ruby-side `Dir#initialize`.
10371055
fn dir_path_ivar(globals: &Globals, self_: Value) -> Result<String> {
1038-
match globals
1039-
.store
1040-
.get_ivar(self_, IdentId::get_id("@path"))
1041-
{
1056+
match globals.store.get_ivar(self_, IdentId::get_id("@path")) {
10421057
Some(v) if !v.is_nil() => Ok(v.to_s(&globals.store)),
10431058
_ => Err(MonorubyErr::ioerr("uninitialized Dir")),
10441059
}
10451060
}
10461061

1047-
fn dir_check_closed(globals: &Globals, self_: Value) -> Result<()> {
1048-
let v = globals
1049-
.store
1050-
.get_ivar(self_, IdentId::get_id("@closed"));
1051-
if v.map(|v| v.as_bool()).unwrap_or(false) {
1052-
Err(MonorubyErr::ioerr("closed directory"))
1053-
} else {
1054-
Ok(())
1055-
}
1056-
}
1062+
//fn dir_check_closed(globals: &Globals, self_: Value) -> Result<()> {
1063+
// let v = globals
1064+
// .store
1065+
// .get_ivar(self_, IdentId::get_id("@closed"));
1066+
// if v.map(|v| v.as_bool()).unwrap_or(false) {
1067+
// Err(MonorubyErr::ioerr("closed directory"))
1068+
// } else {
1069+
// Ok(())
1070+
// }
1071+
//}
10571072

10581073
///
10591074
/// ### Dir#chdir
@@ -1080,9 +1095,8 @@ fn dir_inst_chdir(
10801095
} else {
10811096
None
10821097
};
1083-
std::env::set_current_dir(&path).map_err(|e| {
1084-
MonorubyErr::errno_with_path(&globals.store, &e, "rb_dir_s_chdir", &path)
1085-
})?;
1098+
std::env::set_current_dir(&path)
1099+
.map_err(|e| MonorubyErr::errno_with_path(&globals.store, &e, "rb_dir_s_chdir", &path))?;
10861100
if let Some(bh) = lfp.block() {
10871101
let result = vm.invoke_block_once(globals, bh, &[lfp.self_val()]);
10881102
if let Some(prev) = saved {
@@ -1636,9 +1650,7 @@ mod tests {
16361650

16371651
#[test]
16381652
fn dir_foreach_missing_path_raises() {
1639-
run_test_error(
1640-
r#"Dir.foreach("/no_such_dir_xyz_qq_foreach") { |_| }"#,
1641-
);
1653+
run_test_error(r#"Dir.foreach("/no_such_dir_xyz_qq_foreach") { |_| }"#);
16421654
}
16431655

16441656
#[test]

monoruby/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ struct InstanceVarCache {
14511451
}
14521452

14531453
extern "C" fn get_instance_var_with_cache(
1454-
mut base: Value,
1454+
base: Value,
14551455
name: IdentId,
14561456
globals: &mut Globals,
14571457
cache: &mut InstanceVarCache,

monoruby/src/codegen/arch/x86_64/compile/mod.rs

Lines changed: 92 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ mod init_method;
1010
mod method_call;
1111
mod variables;
1212

13-
use crate::alloc::{BUMP_INLINE_LIMIT, CELL_SIZE_SHIFT, PAGE_DATA_OFFSET};
1413
use super::compile_shared::{extend_ivar, unreachable};
14+
use crate::alloc::{BUMP_INLINE_LIMIT, CELL_SIZE_SHIFT, PAGE_DATA_OFFSET};
1515
use crate::codegen::jitgen::lir::{LAluOp, LCond, LInst, LMem, LOperand, LReg, LSideExitKind};
1616

1717
/// Resolve a LIR register operand to its x86 register number. The scratch
@@ -600,7 +600,10 @@ impl Codegen {
600600
jne deopt;
601601
}
602602
}
603-
LInst::GuardConstVersion { const_version, deopt } => {
603+
LInst::GuardConstVersion {
604+
const_version,
605+
deopt,
606+
} => {
604607
self.guard_const_version(const_version, &deopt);
605608
}
606609
// Fixnum fast-path arithmetic with an overflow deopt.
@@ -648,7 +651,10 @@ impl Codegen {
648651
// ---- FP transfer / convert (spill-aware) -------------------------
649652
LInst::FprMove { src, dst, base } => {
650653
if src != dst {
651-
match (PhysMap::new(base).resolve(src), PhysMap::new(base).resolve(dst)) {
654+
match (
655+
PhysMap::new(base).resolve(src),
656+
PhysMap::new(base).resolve(dst),
657+
) {
652658
(FPRegLoc::Xmm(s), FPRegLoc::Xmm(d)) => monoasm!( &mut self.jit,
653659
movq xmm(d), xmm(s);
654660
),
@@ -658,10 +664,12 @@ impl Codegen {
658664
(FPRegLoc::Spill(s_off), FPRegLoc::Xmm(d)) => monoasm!( &mut self.jit,
659665
movq xmm(d), [rbp - (s_off)];
660666
),
661-
(FPRegLoc::Spill(s_off), FPRegLoc::Spill(d_off)) => monoasm!( &mut self.jit,
662-
movq xmm0, [rbp - (s_off)];
663-
movq [rbp - (d_off)], xmm0;
664-
),
667+
(FPRegLoc::Spill(s_off), FPRegLoc::Spill(d_off)) => {
668+
monoasm!( &mut self.jit,
669+
movq xmm0, [rbp - (s_off)];
670+
movq [rbp - (d_off)], xmm0;
671+
)
672+
}
665673
}
666674
}
667675
}
@@ -694,7 +702,10 @@ impl Codegen {
694702
}
695703
LInst::FprSwap { lhs, rhs, base } => {
696704
if lhs != rhs {
697-
match (PhysMap::new(base).resolve(lhs), PhysMap::new(base).resolve(rhs)) {
705+
match (
706+
PhysMap::new(base).resolve(lhs),
707+
PhysMap::new(base).resolve(rhs),
708+
) {
698709
(FPRegLoc::Xmm(lp), FPRegLoc::Xmm(rp)) => monoasm!( &mut self.jit,
699710
movq xmm0, xmm(lp);
700711
movq xmm(lp), xmm(rp);
@@ -710,16 +721,23 @@ impl Codegen {
710721
movq [rbp - (l_off)], xmm(rp);
711722
movq xmm(rp), xmm0;
712723
),
713-
(FPRegLoc::Spill(l_off), FPRegLoc::Spill(r_off)) => monoasm!( &mut self.jit,
714-
movq xmm0, [rbp - (l_off)];
715-
movq xmm1, [rbp - (r_off)];
716-
movq [rbp - (r_off)], xmm0;
717-
movq [rbp - (l_off)], xmm1;
718-
),
724+
(FPRegLoc::Spill(l_off), FPRegLoc::Spill(r_off)) => {
725+
monoasm!( &mut self.jit,
726+
movq xmm0, [rbp - (l_off)];
727+
movq xmm1, [rbp - (r_off)];
728+
movq [rbp - (r_off)], xmm0;
729+
movq [rbp - (l_off)], xmm1;
730+
)
731+
}
719732
}
720733
}
721734
}
722-
LInst::FloatToFpr { src, dst, deopt, base } => {
735+
LInst::FloatToFpr {
736+
src,
737+
dst,
738+
deopt,
739+
base,
740+
} => {
723741
let (work, spill_off) = match PhysMap::new(base).resolve(dst) {
724742
FPRegLoc::Xmm(p) => (p, None),
725743
FPRegLoc::Spill(off) => (0u64, Some(off)),
@@ -747,7 +765,13 @@ impl Codegen {
747765
}
748766
}
749767
// ---- FP arithmetic / comparison ----------------------------------
750-
LInst::FloatBinOp { kind, lhs, rhs, dst, base } => {
768+
LInst::FloatBinOp {
769+
kind,
770+
lhs,
771+
rhs,
772+
dst,
773+
base,
774+
} => {
751775
self.float_binop(kind, dst, (lhs, rhs), base);
752776
}
753777
LInst::FloatUnOp { kind, dst, base } => match kind {
@@ -767,7 +791,12 @@ impl Codegen {
767791
UnOpK::Pos => {}
768792
_ => unreachable!(),
769793
},
770-
LInst::FloatCmp { kind, lhs, rhs, base } => {
794+
LInst::FloatCmp {
795+
kind,
796+
lhs,
797+
rhs,
798+
base,
799+
} => {
771800
monoasm! { &mut self.jit,
772801
xorq rax, rax;
773802
};
@@ -788,7 +817,13 @@ impl Codegen {
788817
// ---- FP pool save/restore + FP C-calls ---------------------------
789818
LInst::FprSave { using_fpr, cont } => self.fpr_save_with_cont(using_fpr, cont),
790819
LInst::FprRestore { using_fpr, cont } => self.fpr_restore_with_cont(using_fpr, cont),
791-
LInst::CFunc_F_F { f, src, dst, using_fpr, base } => {
820+
LInst::CFunc_F_F {
821+
f,
822+
src,
823+
dst,
824+
using_fpr,
825+
base,
826+
} => {
792827
self.fpr_save(using_fpr);
793828
self.load_fpr_into_xmm0(src, base);
794829
monoasm!( &mut self.jit,
@@ -798,7 +833,14 @@ impl Codegen {
798833
self.fpr_restore(using_fpr);
799834
self.store_fpr_into_xmm(dst, base);
800835
}
801-
LInst::CFunc_FF_F { f, lhs, rhs, dst, using_fpr, base } => {
836+
LInst::CFunc_FF_F {
837+
f,
838+
lhs,
839+
rhs,
840+
dst,
841+
using_fpr,
842+
base,
843+
} => {
802844
self.fpr_save(using_fpr);
803845
self.load_fpr_into_xmm0(lhs, base);
804846
self.load_fpr_into_xmm1(rhs, base);
@@ -967,7 +1009,11 @@ impl Codegen {
9671009
// overflow).
9681010

9691011
/// rax <- Array of the `len` slots starting at `src`.
970-
pub(in crate::codegen::jitgen) fn emit_create_array(&mut self, src: SlotId, len: usize) -> bool {
1012+
pub(in crate::codegen::jitgen) fn emit_create_array(
1013+
&mut self,
1014+
src: SlotId,
1015+
len: usize,
1016+
) -> bool {
9711017
monoasm!( &mut self.jit,
9721018
lea rdi, [r14 - (conv(src))];
9731019
movq rsi, (len);
@@ -1140,9 +1186,9 @@ impl Codegen {
11401186
using_fpr: UsingFpr,
11411187
) -> bool {
11421188
let f = if min {
1143-
runtime::opt_array_min as usize
1189+
runtime::opt_array_min as *const () as usize
11441190
} else {
1145-
runtime::opt_array_max as usize
1191+
runtime::opt_array_max as *const () as usize
11461192
};
11471193
self.fpr_save(using_fpr);
11481194
monoasm!( &mut self.jit,
@@ -1227,7 +1273,11 @@ impl Codegen {
12271273
}
12281274

12291275
/// rax <- `src` coerced to an Array (`Array(x)` / splat).
1230-
pub(in crate::codegen::jitgen) fn emit_to_a(&mut self, src: SlotId, using_fpr: UsingFpr) -> bool {
1276+
pub(in crate::codegen::jitgen) fn emit_to_a(
1277+
&mut self,
1278+
src: SlotId,
1279+
using_fpr: UsingFpr,
1280+
) -> bool {
12311281
self.to_a(src, using_fpr);
12321282
true
12331283
}
@@ -1669,7 +1719,6 @@ impl Codegen {
16691719
true
16701720
}
16711721

1672-
16731722
/// Method epilogue: tear down the frame and return.
16741723
pub(in crate::codegen::jitgen) fn emit_ret(&mut self) {
16751724
self.epilogue();
@@ -1823,7 +1872,10 @@ impl Codegen {
18231872
}
18241873

18251874
/// Loop-JIT entry: reserve the loop body's spill area on the native stack.
1826-
pub(in crate::codegen::jitgen) fn emit_loop_jit_rsp_bump(&mut self, offset: LoopRspOffset) -> bool {
1875+
pub(in crate::codegen::jitgen) fn emit_loop_jit_rsp_bump(
1876+
&mut self,
1877+
offset: LoopRspOffset,
1878+
) -> bool {
18271879
let bytes = offset.unwrap_concrete();
18281880
if bytes > 0 {
18291881
monoasm! { &mut self.jit, subq rsp, (bytes as i32); }
@@ -1845,7 +1897,11 @@ impl Codegen {
18451897
}
18461898

18471899
/// `undef`-method via runtime::undef_method(vm, globals, id).
1848-
pub(in crate::codegen::jitgen) fn emit_undef_method(&mut self, undef: IdentId, using_fpr: UsingFpr) -> bool {
1900+
pub(in crate::codegen::jitgen) fn emit_undef_method(
1901+
&mut self,
1902+
undef: IdentId,
1903+
using_fpr: UsingFpr,
1904+
) -> bool {
18491905
self.fpr_save(using_fpr);
18501906
monoasm!( &mut self.jit,
18511907
movq rdi, rbx;
@@ -1859,7 +1915,12 @@ impl Codegen {
18591915
}
18601916

18611917
/// Alias a global var via runtime::alias_global_var(globals, new, old).
1862-
pub(in crate::codegen::jitgen) fn emit_alias_gvar(&mut self, new: IdentId, old: IdentId, using_fpr: UsingFpr) -> bool {
1918+
pub(in crate::codegen::jitgen) fn emit_alias_gvar(
1919+
&mut self,
1920+
new: IdentId,
1921+
old: IdentId,
1922+
using_fpr: UsingFpr,
1923+
) -> bool {
18631924
self.fpr_save(using_fpr);
18641925
monoasm!( &mut self.jit,
18651926
movq rdi, r12; // &mut Globals
@@ -2243,7 +2304,10 @@ impl Codegen {
22432304
true
22442305
}
22452306

2246-
pub(in crate::codegen::jitgen) fn emit_ensure_end(&mut self, _loop_jit_spill_bytes: usize) -> bool {
2307+
pub(in crate::codegen::jitgen) fn emit_ensure_end(
2308+
&mut self,
2309+
_loop_jit_spill_bytes: usize,
2310+
) -> bool {
22472311
let raise = self.entry_raise();
22482312
monoasm! { &mut self.jit,
22492313
movq rdi, rbx;
@@ -2270,7 +2334,6 @@ impl Codegen {
22702334
true
22712335
}
22722336

2273-
22742337
// ---- &block forwarding (former per-arch arms) ----
22752338

22762339
pub(in crate::codegen::jitgen) fn emit_block_arg_proxy(

0 commit comments

Comments
 (0)