simplified lifetime

This commit is contained in:
pca006132 2021-01-11 11:12:37 +08:00
parent b6e4e68587
commit d466b7bc2b
2 changed files with 30 additions and 30 deletions

View File

@ -215,7 +215,7 @@ impl TypeEnum {
}
}
pub fn get_base<'b: 'a, 'a>(&'a self, ctx: &'b InferenceContext) -> Option<&'b TypeDef> {
pub fn get_base<'a>(&'a self, ctx: &'a InferenceContext) -> Option<&'a TypeDef> {
match self {
TypeEnum::PrimitiveType(id) => Some(ctx.get_primitive_def(*id)),
TypeEnum::ClassType(id) | TypeEnum::VirtualClassType(id) => {

View File

@ -11,9 +11,9 @@ use std::convert::TryInto;
type ParserResult = Result<Option<Type>, String>;
pub fn infer_expr<'b: 'a, 'a>(
pub fn infer_expr<'a>(
ctx: &mut InferenceContext<'a>,
expr: &'b Expression,
expr: &'a Expression,
) -> ParserResult {
match &expr.node {
ExpressionType::Number { value } => infer_constant(ctx, value),
@ -83,9 +83,9 @@ fn infer_identifier(ctx: &mut InferenceContext, name: &str) -> ParserResult {
Ok(Some(ctx.resolve(name)?))
}
fn infer_list<'b: 'a, 'a>(
fn infer_list<'a>(
ctx: &mut InferenceContext<'a>,
elements: &'b [Expression],
elements: &'a [Expression],
) -> ParserResult {
if elements.is_empty() {
return Ok(Some(ParametricType(LIST_TYPE, vec![BotType.into()]).into()));
@ -105,9 +105,9 @@ fn infer_list<'b: 'a, 'a>(
Ok(Some(ParametricType(LIST_TYPE, vec![head.unwrap()]).into()))
}
fn infer_tuple<'b: 'a, 'a>(
fn infer_tuple<'a>(
ctx: &mut InferenceContext<'a>,
elements: &'b [Expression],
elements: &'a [Expression],
) -> ParserResult {
let types: Result<Option<Vec<_>>, String> =
elements.iter().map(|v| infer_expr(ctx, v)).collect();
@ -164,11 +164,11 @@ fn infer_bool_ops<'a>(ctx: &mut InferenceContext<'a>, values: &'a [Expression])
}
}
fn infer_bin_ops<'b: 'a, 'a>(
fn infer_bin_ops<'a>(
ctx: &mut InferenceContext<'a>,
op: &Operator,
left: &'b Expression,
right: &'b Expression,
left: &'a Expression,
right: &'a Expression,
) -> ParserResult {
let left = infer_expr(ctx, left)?.ok_or_else(|| "no value".to_string())?;
let right = infer_expr(ctx, right)?.ok_or_else(|| "no value".to_string())?;
@ -176,10 +176,10 @@ fn infer_bin_ops<'b: 'a, 'a>(
resolve_call(ctx, Some(left), fun, &[right])
}
fn infer_unary_ops<'b: 'a, 'a>(
fn infer_unary_ops<'a>(
ctx: &mut InferenceContext<'a>,
op: &UnaryOperator,
obj: &'b Expression,
obj: &'a Expression,
) -> ParserResult {
let ty = infer_expr(ctx, obj)?.ok_or_else(|| "no value".to_string())?;
if let UnaryOperator::Not = op {
@ -193,10 +193,10 @@ fn infer_unary_ops<'b: 'a, 'a>(
}
}
fn infer_compare<'b: 'a, 'a>(
fn infer_compare<'a>(
ctx: &mut InferenceContext<'a>,
vals: &'b [Expression],
ops: &'b [Comparison],
vals: &'a [Expression],
ops: &'a [Comparison],
) -> ParserResult {
let types: Result<Option<Vec<_>>, _> = vals.iter().map(|v| infer_expr(ctx, v)).collect();
let types = types?;
@ -218,10 +218,10 @@ fn infer_compare<'b: 'a, 'a>(
Ok(Some(boolean))
}
fn infer_call<'b: 'a, 'a>(
fn infer_call<'a>(
ctx: &mut InferenceContext<'a>,
args: &'b [Expression],
function: &'b Expression,
args: &'a [Expression],
function: &'a Expression,
) -> ParserResult {
let types: Result<Option<Vec<_>>, _> = args.iter().map(|v| infer_expr(ctx, v)).collect();
let types = types?;
@ -240,10 +240,10 @@ fn infer_call<'b: 'a, 'a>(
resolve_call(ctx, obj, fun.as_str(), &types.unwrap())
}
fn infer_subscript<'b: 'a, 'a>(
fn infer_subscript<'a>(
ctx: &mut InferenceContext<'a>,
a: &'b Expression,
b: &'b Expression,
a: &'a Expression,
b: &'a Expression,
) -> ParserResult {
let a = infer_expr(ctx, a)?.ok_or_else(|| "no value".to_string())?;
let t = if let ParametricType(LIST_TYPE, ls) = a.as_ref() {
@ -283,11 +283,11 @@ fn infer_subscript<'b: 'a, 'a>(
}
}
fn infer_if_expr<'b: 'a, 'a>(
fn infer_if_expr<'a>(
ctx: &mut InferenceContext<'a>,
test: &'b Expression,
body: &'b Expression,
orelse: &'b Expression,
test: &'a Expression,
body: &'a Expression,
orelse: &'a Expression,
) -> ParserResult {
let test = infer_expr(ctx, test)?.ok_or_else(|| "no value".to_string())?;
if test != ctx.get_primitive(BOOL_TYPE) {
@ -303,8 +303,8 @@ fn infer_if_expr<'b: 'a, 'a>(
}
}
pub fn infer_simple_binding<'a: 'b, 'b>(
ctx: &mut InferenceContext<'b>,
pub fn infer_simple_binding<'a>(
ctx: &mut InferenceContext<'a>,
name: &'a Expression,
ty: Type,
) -> Result<(), String> {
@ -337,10 +337,10 @@ pub fn infer_simple_binding<'a: 'b, 'b>(
}
}
fn infer_list_comprehension<'b: 'a, 'a>(
fn infer_list_comprehension<'a>(
ctx: &mut InferenceContext<'a>,
element: &'b Expression,
comprehension: &'b Comprehension,
element: &'a Expression,
comprehension: &'a Comprehension,
) -> ParserResult {
if comprehension.is_async {
return Err("async is not supported".into());