Skip to content

Commit

Permalink
perf: infer dict attr ty in config entries (kcl-lang#875)
Browse files Browse the repository at this point in the history
Signed-off-by: never <[email protected]>
  • Loading branch information
NeverRaR authored Nov 13, 2023
1 parent 441a2f5 commit 55ad0ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
6 changes: 3 additions & 3 deletions kclvm/sema/src/resolver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
},
);
Expand Down Expand Up @@ -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(),
},
);
Expand Down
15 changes: 2 additions & 13 deletions kclvm/sema/src/ty/context.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 55ad0ee

Please sign in to comment.