1

CFI: Change type transformation to use TypeFolder by rcvalle · Pull Request #123...

 1 month ago
source link: https://github.com/rust-lang/rust/pull/123212
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Member

@compiler-errors compiler-errors

left a comment

I got kinda lazy near the end -- any time I've written "trivial", I mean fold them into a mega arm at the end like:

ty::Never
| ty::Bool
| ty::Array
| ty::Slice
...
...
| whatever => t.super_fold_with(self)

Since most of the benefit of using a folder is the super_fold_with which defers to a "fold this type the normal way".

@@ -1057,7 +1059,8 @@ pub fn typeid_for_fnabi<'tcx>(

// Encode the return type

let transform_ty_options = TransformTyOptions::from_bits(options.bits())

.unwrap_or_else(|| bug!("typeid_for_fnabi: invalid option(s) `{:?}`", options.bits()));

let ty = transform_ty(tcx, fn_abi.ret.layout.ty, &mut Vec::new(), transform_ty_options);

let mut type_folder = TransformTyTypeFolder::new(tcx, transform_ty_options);

let ty = type_folder.fold_ty(fn_abi.ret.layout.ty);

I personally prefer

Suggested change
let ty = type_folder.fold_ty(fn_abi.ret.layout.ty);
let ty = fn_abi.ret.layout.ty.fold_with(&mut type_folder);
@@ -1069,7 +1072,7 @@ pub fn typeid_for_fnabi<'tcx>(

let mut pushed_arg = false;

for arg in fn_abi.args.iter().filter(|arg| arg.mode != PassMode::Ignore) {

pushed_arg = true;

let ty = transform_ty(tcx, arg.layout.ty, &mut Vec::new(), transform_ty_options);

let ty = type_folder.fold_ty(arg.layout.ty);

Same as above, arg.layout.ty.fold_with(&mut type_folder)

@@ -1082,8 +1085,7 @@ pub fn typeid_for_fnabi<'tcx>(

if fn_abi.args[n].mode == PassMode::Ignore {

continue;

}

let ty =

transform_ty(tcx, fn_abi.args[n].layout.ty, &mut Vec::new(), transform_ty_options);

let ty = type_folder.fold_ty(fn_abi.args[n].layout.ty);


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK