Skip to content

Commit

Permalink
frontend: Add ConstPoolEntry::GenericSelf
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Feb 4, 2025
1 parent 8769a55 commit d3efa7e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dora-bytecode/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<'a> BytecodeTraitTypePrinter<'a> {
format!("{}", self)
}

pub fn name(
fn name(
&self,
trait_ty: &BytecodeTraitType,
fmt: &mut std::fmt::Formatter,
Expand Down
7 changes: 4 additions & 3 deletions dora-bytecode/src/dumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,11 @@ impl<'a> BytecodeDumper<'a> {

fn get_fct_name(&mut self, idx: ConstPoolIdx) -> String {
let fct_id = match self.bc.const_pool(idx) {
ConstPoolEntry::Fct(fct_id, _) => fct_id,
ConstPoolEntry::Generic(_, fct_id, _) => fct_id,
ConstPoolEntry::Fct(fct_id, _)
| ConstPoolEntry::Generic(_, fct_id, _)
| ConstPoolEntry::GenericSelf(fct_id, ..)
| ConstPoolEntry::TraitObjectMethod(_, fct_id) => fct_id,
ConstPoolEntry::Lambda(_, _) => return "lambda".into(),
ConstPoolEntry::TraitObjectMethod(_, trait_fct_id) => trait_fct_id,
_ => unreachable!(),
};

Expand Down
22 changes: 13 additions & 9 deletions dora-frontend/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1761,14 +1761,17 @@ impl<'a> AstBytecodeGen<'a> {
match *call_type {
CallType::Method(..)
| CallType::GenericMethod(..)
| CallType::GenericMethodSelf(..)
| CallType::TraitObjectMethod(..) => {
let obj_expr = expr.object().unwrap_or(expr.callee());
let reg = gen_expr(self, obj_expr, DataDest::Alloc);

Some(reg)
}
CallType::Expr(_, _, _) => Some(gen_expr(self, &expr.callee, DataDest::Alloc)),
CallType::GenericStaticMethod(..) | CallType::Fct(..) => None,
CallType::GenericStaticMethod(..)
| CallType::GenericStaticMethodSelf(..)
| CallType::Fct(..) => None,
_ => panic!("unexpected call type {:?}", call_type),
}
}
Expand Down Expand Up @@ -1883,21 +1886,19 @@ impl<'a> AstBytecodeGen<'a> {
self.builder
.emit_invoke_virtual(return_reg, callee_idx, location);
}
CallType::GenericMethod(..) => {
CallType::GenericMethod(..) | CallType::GenericMethodSelf(..) => {
self.builder
.emit_invoke_generic_direct(return_reg, callee_idx, location);
}
CallType::GenericStaticMethod(..) => {
CallType::GenericStaticMethod(..) | CallType::GenericStaticMethodSelf(..) => {
self.builder
.emit_invoke_generic_static(return_reg, callee_idx, location);
}
CallType::NewClass(..)
| CallType::NewStruct(..)
| CallType::NewEnum(..)
| CallType::Intrinsic(..)
| CallType::Lambda(..)
| CallType::GenericMethodSelf(..)
| CallType::GenericStaticMethodSelf(..) => unreachable!(),
| CallType::Lambda(..) => unreachable!(),
}
}

Expand Down Expand Up @@ -3264,13 +3265,16 @@ impl<'a> AstBytecodeGen<'a> {
)
}

CallType::GenericMethodSelf(_trait_id, _fct_id, type_params)
| CallType::GenericStaticMethodSelf(_trait_id, _fct_id, type_params) => {
replace_type(self.sa, ty, Some(type_params), None)
}

CallType::Lambda(..)
| CallType::NewClass(..)
| CallType::NewStruct(..)
| CallType::NewEnum(..)
| CallType::Intrinsic(..)
| CallType::GenericMethodSelf(..)
| CallType::GenericStaticMethodSelf(..) => {
| CallType::Intrinsic(..) => {
unreachable!()
}
}
Expand Down
33 changes: 22 additions & 11 deletions dora-runtime/src/compiler/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl<'a> TransitiveClosureComputation<'a> {
&mut self,
bytecode_function: &BytecodeFunction,
type_params: BytecodeTypeArray,
_specialize_self: Option<BytecodeType>,
specialize_self: Option<BytecodeType>,
) {
let reader = BytecodeReader::new(bytecode_function.code());

Expand All @@ -278,13 +278,26 @@ impl<'a> TransitiveClosureComputation<'a> {

BytecodeInstruction::InvokeGenericDirect { fct, .. }
| BytecodeInstruction::InvokeGenericStatic { fct, .. } => {
let (id, callee_trait_fct_id, callee_type_params) =
match bytecode_function.const_pool(fct) {
ConstPoolEntry::Generic(id, fct_id, type_params) => {
(*id, *fct_id, type_params.clone())
}
_ => unreachable!(),
};
let generic_ty;
let callee_trait_fct_id;
let callee_type_params;

match bytecode_function.const_pool(fct) {
ConstPoolEntry::Generic(id, fct_id, fct_type_params) => {
generic_ty = type_params[*id as usize].clone();
callee_trait_fct_id = *fct_id;
callee_type_params = fct_type_params.clone();
}

ConstPoolEntry::GenericSelf(fct_id, fct_type_params) => {
generic_ty = specialize_self.clone().expect("missing Self type");
callee_trait_fct_id = *fct_id;
callee_type_params = fct_type_params.clone();
}

_ => unreachable!(),
}

let fct = self.vm.fct(callee_trait_fct_id);

let trait_id = match fct.kind {
Expand All @@ -297,10 +310,8 @@ impl<'a> TransitiveClosureComputation<'a> {
bindings: Vec::new(),
};

let ty = type_params[id as usize].clone();

let (callee_id, callee_type_params) =
find_trait_impl(self.vm, callee_trait_fct_id, trait_ty, ty);
find_trait_impl(self.vm, callee_trait_fct_id, trait_ty, generic_ty);

let callee_type_params =
specialize_bty_array(&callee_type_params, &type_params);
Expand Down

0 comments on commit d3efa7e

Please sign in to comment.