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 { match self {
TypeEnum::PrimitiveType(id) => Some(ctx.get_primitive_def(*id)), TypeEnum::PrimitiveType(id) => Some(ctx.get_primitive_def(*id)),
TypeEnum::ClassType(id) | TypeEnum::VirtualClassType(id) => { TypeEnum::ClassType(id) | TypeEnum::VirtualClassType(id) => {

View File

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