Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance schema optional attr check time and put it before the check expressions #1341

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions kclvm/evaluator/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use generational_arena::Index;
use kclvm_ast::ast::{self, CallExpr, ConfigEntry, NodeRef};
use kclvm_ast::walker::TypedResultWalker;
use kclvm_runtime::val_func::invoke_function;
use kclvm_runtime::walker::walk_value_mut;
use kclvm_runtime::{
schema_assert, schema_runtime_type, ConfigEntryOperationKind, DecoratorValue, RuntimeErrorType,
UnionOptions, ValueRef, PKG_PATH_PREFIX,
Expand Down Expand Up @@ -138,16 +137,7 @@ impl<'ctx> TypedResultWalker<'ctx> for Evaluator<'ctx> {
let mut value = self.walk_expr(&assign_stmt.value)?;
// Runtime type cast if exists the type annotation.
if let Some(ty) = &assign_stmt.ty {
let is_in_schema = self.is_in_schema() || self.is_in_schema_expr();
value = type_pack_and_check(self, &value, vec![&ty.node.to_string()], false);
// Schema required attribute validating.
if !is_in_schema {
walk_value_mut(&value, &mut |value: &ValueRef| {
if value.is_schema() {
value.schema_check_attr_optional(&mut self.runtime_ctx.borrow_mut(), true);
}
})
}
}
if assign_stmt.targets.len() == 1 {
// Store the single target
Expand Down Expand Up @@ -843,7 +833,6 @@ impl<'ctx> TypedResultWalker<'ctx> for Evaluator<'ctx> {
fn walk_schema_expr(&self, schema_expr: &'ctx ast::SchemaExpr) -> Self::Result {
// Check the required attributes only when the values of all attributes
// in the final schema are solved.
let is_in_schema = self.is_in_schema() || self.is_in_schema_expr();
self.push_schema_expr();
let config_value = self.walk_expr(&schema_expr.config)?;
let schema_type = self.walk_identifier_with_ctx(
Expand Down Expand Up @@ -888,7 +877,6 @@ impl<'ctx> TypedResultWalker<'ctx> for Evaluator<'ctx> {
&list_value,
&dict_value,
);
{}
self.pop_backtrace();
self.pop_pkgpath();
value
Expand Down Expand Up @@ -916,9 +904,6 @@ impl<'ctx> TypedResultWalker<'ctx> for Evaluator<'ctx> {
&UnionOptions::default(),
)
};
if !is_in_schema {
schema.schema_check_attr_optional(&mut self.runtime_ctx.borrow_mut(), true)
}
self.pop_schema_expr();
Ok(schema)
}
Expand Down
3 changes: 2 additions & 1 deletion kclvm/evaluator/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub(crate) fn call_schema_body_from_rule(
pub(crate) fn call_schema_check(
s: &Evaluator,
func: &ValueRef,
schema_value: &ValueRef,
args: &ValueRef,
kwargs: &ValueRef,
ctx: Option<&SchemaEvalContextRef>,
Expand All @@ -125,7 +126,7 @@ pub(crate) fn call_schema_check(
if let Some(ctx) = ctx {
schema.ctx.borrow_mut().set_info_with_schema(&ctx.borrow())
}
(schema.check)(s, &schema.ctx, args, kwargs);
(schema.check)(s, &schema.ctx, schema_value, args, kwargs);
s.pop_backtrace();
s.pop_pkgpath();
}
Expand Down
Loading
Loading