From 55ad0ee8936f79c04e6e58ffa81293eec0e79998 Mon Sep 17 00:00:00 2001 From: NeverRaR <44917563+NeverRaR@users.noreply.github.com> Date: Mon, 13 Nov 2023 19:39:57 +0800 Subject: [PATCH] perf: infer dict attr ty in config entries (#875) Signed-off-by: never --- kclvm/sema/src/resolver/config.rs | 6 +++--- kclvm/sema/src/ty/context.rs | 15 ++------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/kclvm/sema/src/resolver/config.rs b/kclvm/sema/src/resolver/config.rs index d9c22962d..f8dbfc96a 100644 --- a/kclvm/sema/src/resolver/config.rs +++ b/kclvm/sema/src/resolver/config.rs @@ -4,7 +4,7 @@ use super::{ scope::{ScopeKind, ScopeObject, ScopeObjectKind}, Resolver, }; -use crate::ty::{sup, DictType, TypeRef}; +use crate::ty::{sup, DictType, TypeInferMethods, TypeRef}; use crate::ty::{Attr, SchemaType}; use crate::ty::{Type, TypeKind}; use indexmap::IndexMap; @@ -431,7 +431,7 @@ impl<'ctx> Resolver<'ctx> { attrs.insert( name.to_string(), Attr { - ty: ty.clone(), + ty: self.ctx.ty_ctx.infer_to_variable_type(ty.clone()), range: key.get_span_pos(), }, ); @@ -476,7 +476,7 @@ impl<'ctx> Resolver<'ctx> { attrs.insert( string_lit.value.clone(), Attr { - ty: ty.clone(), + ty: self.ctx.ty_ctx.infer_to_variable_type(ty.clone()), range: key.get_span_pos(), }, ); diff --git a/kclvm/sema/src/ty/context.rs b/kclvm/sema/src/ty/context.rs index 7bbe04030..66ad71c01 100644 --- a/kclvm/sema/src/ty/context.rs +++ b/kclvm/sema/src/ty/context.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::sync::Arc; -use super::{sup, Attr, DictType, Type, TypeFlags, TypeKind, TypeRef}; +use super::{sup, DictType, Type, TypeFlags, TypeKind, TypeRef}; use petgraph::algo::is_cyclic_directed; use petgraph::graph::{DiGraph, NodeIndex}; @@ -173,18 +173,7 @@ impl TypeInferMethods for TypeContext { }) => Type::dict_ref_with_attrs( self.infer_to_variable_type(key_ty.clone()), self.infer_to_variable_type(val_ty.clone()), - attrs - .into_iter() - .map(|(key, attr)| { - ( - key.to_string(), - Attr { - ty: self.infer_to_variable_type(attr.ty.clone()), - range: attr.range.clone(), - }, - ) - }) - .collect(), + attrs.clone(), ), // Union type e.g., 1|2|"s" -> int|str TypeKind::Union(types) => sup(&types