From 7e8124f002cf33d4bb5204e8bcbeb263aef37004 Mon Sep 17 00:00:00 2001 From: peefy Date: Tue, 7 May 2024 16:49:00 +0800 Subject: [PATCH 1/3] feat: top level variable back reference Signed-off-by: peefy --- VERSION | 2 +- kclvm/compiler/src/codegen/error.rs | 9 +-- kclvm/compiler/src/codegen/llvm/context.rs | 66 +++++++++++++++++- kclvm/compiler/src/codegen/llvm/module.rs | 4 +- kclvm/compiler/src/codegen/llvm/node.rs | 14 +++- kclvm/runtime/src/_kcl_run.rs | 15 ++-- kclvm/runtime/src/_kclvm.bc | Bin 14412 -> 14416 bytes kclvm/runtime/src/_kclvm.h | 2 +- kclvm/runtime/src/_kclvm.ll | 2 +- kclvm/runtime/src/_kclvm.rs | 2 +- kclvm/runtime/src/_kclvm_addr.rs | 2 +- kclvm/runtime/src/_kclvm_api_spec.rs | 6 +- kclvm/runtime/src/_kclvm_main_win.c | 18 ----- kclvm/runtime/src/context/api.rs | 2 +- .../schema/irrelevant_order/simple_10/main.k | 15 ++++ .../irrelevant_order/simple_10/stdout.golden | 6 ++ .../schema/irrelevant_order/simple_7/main.k | 2 + .../irrelevant_order/simple_7/stdout.golden | 2 + .../schema/irrelevant_order/simple_8/main.k | 3 + .../irrelevant_order/simple_8/stdout.golden | 3 + .../schema/irrelevant_order/simple_9/kcl.mod | 0 .../schema/irrelevant_order/simple_9/main.k | 3 + .../irrelevant_order/simple_9/pkg/base.k | 4 ++ .../irrelevant_order/simple_9/pkg/input.k | 5 ++ .../irrelevant_order/simple_9/pkg/versions.k | 3 + .../irrelevant_order/simple_9/stdout.golden | 4 ++ 26 files changed, 150 insertions(+), 44 deletions(-) delete mode 100644 kclvm/runtime/src/_kclvm_main_win.c create mode 100644 test/grammar/schema/irrelevant_order/simple_10/main.k create mode 100644 test/grammar/schema/irrelevant_order/simple_10/stdout.golden create mode 100644 test/grammar/schema/irrelevant_order/simple_7/main.k create mode 100644 test/grammar/schema/irrelevant_order/simple_7/stdout.golden create mode 100644 test/grammar/schema/irrelevant_order/simple_8/main.k create mode 100644 test/grammar/schema/irrelevant_order/simple_8/stdout.golden create mode 100644 test/grammar/schema/irrelevant_order/simple_9/kcl.mod create mode 100644 test/grammar/schema/irrelevant_order/simple_9/main.k create mode 100644 test/grammar/schema/irrelevant_order/simple_9/pkg/base.k create mode 100644 test/grammar/schema/irrelevant_order/simple_9/pkg/input.k create mode 100644 test/grammar/schema/irrelevant_order/simple_9/pkg/versions.k create mode 100644 test/grammar/schema/irrelevant_order/simple_9/stdout.golden diff --git a/VERSION b/VERSION index 35864a97f..ac39a106c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.8.7 \ No newline at end of file +0.9.0 diff --git a/kclvm/compiler/src/codegen/error.rs b/kclvm/compiler/src/codegen/error.rs index 4aa51b47d..dcf2b2406 100644 --- a/kclvm/compiler/src/codegen/error.rs +++ b/kclvm/compiler/src/codegen/error.rs @@ -3,11 +3,12 @@ use std::error; use std::fmt::{self, Debug}; -pub const VALUE_TYPE_NOT_FOUND_MSG: &str = "Type is not found"; -pub const CONTEXT_VAR_NOT_FOUND_MSG: &str = "Context variable is not found"; -pub const FUNCTION_RETURN_VALUE_NOT_FOUND_MSG: &str = "Function return value is not found"; -pub const COMPILE_ERROR_MSG: &str = "Compile error"; +pub const VALUE_TYPE_NOT_FOUND_MSG: &str = "Internal error, value type is not found"; +pub const CONTEXT_VAR_NOT_FOUND_MSG: &str = "Internal error, context variable is not found"; pub const INTERNAL_ERROR_MSG: &str = "Internal error, please report a bug to us"; +pub const FUNCTION_RETURN_VALUE_NOT_FOUND_MSG: &str = + "Internal error, function return value is not found"; +pub const COMPILE_ERROR_MSG: &str = "Compile error"; pub const CODE_GEN_ERROR_MSG: &str = "Code gen error"; pub const INVALID_OPERATOR_MSG: &str = "Invalid operator"; pub const INVALID_JOINED_STR_MSG: &str = "Invalid AST JoinedString value"; diff --git a/kclvm/compiler/src/codegen/llvm/context.rs b/kclvm/compiler/src/codegen/llvm/context.rs index 1f4459454..f1a60bac4 100644 --- a/kclvm/compiler/src/codegen/llvm/context.rs +++ b/kclvm/compiler/src/codegen/llvm/context.rs @@ -1311,8 +1311,10 @@ impl<'ctx> LLVMCodeGenContext<'ctx> { let tpe = self.value_ptr_type().into_pointer_type(); let void_type = self.context.void_type(); let context_ptr_type = self.context_ptr_type(); - let fn_type = tpe.fn_type(&[context_ptr_type.into()], false); - let void_fn_type = void_type.fn_type(&[context_ptr_type.into()], false); + let scope_ptr_type = self.scope_ptr_type(); + let fn_type = tpe.fn_type(&[context_ptr_type.into(), scope_ptr_type.into()], false); + let void_fn_type = + void_type.fn_type(&[context_ptr_type.into(), scope_ptr_type.into()], false); let has_main_pkg = self.program.pkgs.contains_key(MAIN_PKG_PATH); let function = if self.no_link { let mut modules = self.modules.borrow_mut(); @@ -1756,6 +1758,18 @@ impl<'ctx> LLVMCodeGenContext<'ctx> { let variables = last.variables.borrow(); if let Some(var) = variables.get(&name.to_string()) { self.builder.build_store(*var, value); + if save_scope { + self.build_void_call( + &ApiFunc::kclvm_scope_set.name(), + &[ + self.current_runtime_ctx_ptr(), + self.current_scope_ptr(), + self.native_global_string(¤t_pkgpath, "").into(), + self.native_global_string(name, "").into(), + value, + ], + ); + } existed = true; } } @@ -1766,6 +1780,18 @@ impl<'ctx> LLVMCodeGenContext<'ctx> { let var_name = format!("${}.${}", pkgpath_without_prefix!(pkgpath), name); let pointer = self.new_global_kcl_value_ptr(&var_name); self.builder.build_store(pointer, value); + if save_scope { + self.build_void_call( + &ApiFunc::kclvm_scope_set.name(), + &[ + self.current_runtime_ctx_ptr(), + self.current_scope_ptr(), + self.native_global_string(¤t_pkgpath, "").into(), + self.native_global_string(name, "").into(), + value, + ], + ); + } if !variables.contains_key(name) { variables.insert(name.to_string(), pointer); } @@ -1993,7 +2019,41 @@ impl<'ctx> LLVMCodeGenContext<'ctx> { } } } else { - self.builder.build_load(*var, name) + // Not a local schema attribute or a global type. + let key = format!("{}.{name}", pkgpath_without_prefix!(pkgpath)); + let is_in_lambda = self.is_in_lambda(); + if !is_in_schema + && !is_in_lambda + && index <= GLOBAL_LEVEL + && !self.local_vars.borrow().contains(name) + && self.setter_keys.borrow().contains(&key) + { + let target = self + .target_vars + .borrow_mut() + .last() + .expect(kcl_error::INTERNAL_ERROR_MSG) + .clone(); + self.build_call( + &ApiFunc::kclvm_scope_get.name(), + &[ + // Runtime context ptr + self.current_runtime_ctx_ptr(), + // Scope ptr + self.current_scope_ptr(), + // Package path + self.native_global_string(&pkgpath, "").into(), + // Attribute name + self.native_global_string(name, "").into(), + // Target + self.native_global_string(&target, "").into(), + // Default + self.builder.build_load(*var, name), + ], + ) + } else { + self.builder.build_load(*var, name) + } }; result = Ok(value); break; diff --git a/kclvm/compiler/src/codegen/llvm/module.rs b/kclvm/compiler/src/codegen/llvm/module.rs index a0f100339..6a8146ac0 100644 --- a/kclvm/compiler/src/codegen/llvm/module.rs +++ b/kclvm/compiler/src/codegen/llvm/module.rs @@ -38,7 +38,7 @@ impl<'ctx> LLVMCodeGenContext<'ctx> { }; } // Pre define global variables with setter functions. - // self.predefine_global_setters(module); + self.predefine_global_setters(module); } pub fn predefine_global_types(&self, name: &str) { @@ -59,7 +59,7 @@ impl<'ctx> LLVMCodeGenContext<'ctx> { /// Predefine all global variables. pub fn predefine_global_setters(&self, module: &'ctx ast::Module) { - // New a function block to the global setter constrcution process. + // New a function block to the global setter construction process. let global_setter_block = self.append_block(""); self.br(global_setter_block); self.builder.position_at_end(global_setter_block); diff --git a/kclvm/compiler/src/codegen/llvm/node.rs b/kclvm/compiler/src/codegen/llvm/node.rs index 108379ddc..de2f1d2c9 100644 --- a/kclvm/compiler/src/codegen/llvm/node.rs +++ b/kclvm/compiler/src/codegen/llvm/node.rs @@ -317,7 +317,10 @@ impl<'ctx> TypedResultWalker<'ctx> for LLVMCodeGenContext<'ctx> { PKG_INIT_FUNCTION_SUFFIX ); let tpe = self.context.void_type(); - let fn_type = tpe.fn_type(&[self.context_ptr_type().into()], false); + let fn_type = tpe.fn_type( + &[self.context_ptr_type().into(), self.scope_ptr_type().into()], + false, + ); let function = module.add_function( // Function name &module_name, @@ -367,10 +370,14 @@ impl<'ctx> TypedResultWalker<'ctx> for LLVMCodeGenContext<'ctx> { ); } let tpe = self.context.void_type(); - let fn_type = tpe.fn_type(&[self.context_ptr_type().into()], false); + let fn_type = tpe.fn_type( + &[self.context_ptr_type().into(), self.scope_ptr_type().into()], + false, + ); module.add_function(&name, fn_type, Some(Linkage::External)) }; let ctx = self.current_runtime_ctx_ptr(); + let scope = self.current_scope_ptr(); let pkgpath_value = self.native_global_string_value(&name); let is_imported = self .build_call( @@ -389,7 +396,8 @@ impl<'ctx> TypedResultWalker<'ctx> for LLVMCodeGenContext<'ctx> { self.builder .build_conditional_branch(is_not_imported, then_block, else_block); self.builder.position_at_end(then_block); - self.builder.build_call(function, &[ctx.into()], ""); + self.builder + .build_call(function, &[ctx.into(), scope.into()], ""); self.br(else_block); self.builder.position_at_end(else_block); } diff --git a/kclvm/runtime/src/_kcl_run.rs b/kclvm/runtime/src/_kcl_run.rs index 6c20449e1..a9ab2cbb0 100644 --- a/kclvm/runtime/src/_kcl_run.rs +++ b/kclvm/runtime/src/_kcl_run.rs @@ -103,6 +103,7 @@ pub unsafe extern "C" fn _kcl_run( ) -> kclvm_size_t { // Init runtime context with options let ctx = Box::new(new_ctx_with_opts(opts, &c2str_vec(path_selector))).into_raw(); + let scope = kclvm_scope_new(); let option_keys = std::slice::from_raw_parts(option_keys, option_len as usize); let option_values = std::slice::from_raw_parts(option_values, option_len as usize); for i in 0..(option_len as usize) { @@ -130,9 +131,7 @@ pub unsafe extern "C" fn _kcl_run( } }) })); - // let scope = Box::into_raw(Box::new(LazyEvalScope::default())); - // let result = std::panic::catch_unwind(|| _kcl_run_in_closure(ctx, scope, kclvm_main_ptr)); - let result = std::panic::catch_unwind(|| _kcl_run_in_closure(ctx, kclvm_main_ptr)); + let result = std::panic::catch_unwind(|| _kcl_run_in_closure(ctx, scope, kclvm_main_ptr)); std::panic::set_hook(prev_hook); KCL_RUNTIME_PANIC_RECORD.with(|record| { let record = record.borrow(); @@ -162,20 +161,26 @@ pub unsafe extern "C" fn _kcl_run( copy_str_to(&json_panic_info, err_buffer, err_buffer_len); // Delete the context kclvm_context_delete(ctx); + // Delete the scope + kclvm_scope_delete(scope); result.is_err() as kclvm_size_t } unsafe fn _kcl_run_in_closure( ctx: *mut Context, + scope: *mut LazyEvalScope, kclvm_main_ptr: u64, // main.k => kclvm_main ) { let kclvm_main = (&kclvm_main_ptr as *const u64) as *const () - as *const extern "C" fn(ctx: *mut kclvm_context_t) -> *mut kclvm_value_ref_t; + as *const extern "C" fn( + ctx: *mut kclvm_context_t, + scope: *mut kclvm_eval_scope_t, + ) -> *mut kclvm_value_ref_t; unsafe { if kclvm_main.is_null() { panic!("kcl program main function not found"); } - (*kclvm_main)(ctx); + (*kclvm_main)(ctx, scope); } } diff --git a/kclvm/runtime/src/_kclvm.bc b/kclvm/runtime/src/_kclvm.bc index 69a8306c68ca21a3397030a1db0d5220819ae387..6752000fdf69f152aeb7346822740671c1a4f3ef 100644 GIT binary patch delta 2189 zcmZXVdq`7p6vyw~W;&J9jX4#vX(@GmFBK7~`E1TKwJq{(+JaQbz*Hi-qb$@V7&L81W`z)_Oc9U<&dsX(36p-En zTo=sx$93+^YpnW!J6J;+{HpR-b0HCCYU7LkHu9NTAvhwmdE z$X2S5@i&W-^!HKK)utMO#F`A-=AL0Ba92)BMP9Z#!M1s)~ z9el$s4WlmN)6Gc~n?GI*z3=Cy#T)KaZf z4xZgxi*E+civRLM;WO1GJD81d*4Ay`%*LmA5S_XacN3DaBl;{j)|JBUNgmkI@7;ri z9AMp$%t*^t(MgeYFZ7hbrRr9D!=+jt*Hh-A=554G%Qtxne+R3M_Es%npz3m_vJ_qh zVPIqg&~o~Qn+oh75glj%mw{B?&yus6FgCy@UX+}GO-N^Bp^$cc32^k(8EpW#47x9F zxfZf5H~tA^9j(BeQtXs0R#9 z*`BL}WED?dLbBJDEV7Irv9@Gnfqdkn9kg}bl+!*qv`%q`WoRa|p$#T-g4-b3LLN)a z)q%lz=%KLuf^ynJ`)T8v)Aa=h9e^g97iXt}xs5f(cnHane+h5kZWqUJ7vV1H?y%hd zIBqw~INHQSd)X$7=^wfjibF-tEbxHSW^l{i&~xYslSTn>RlcWqCjhUDsMlJq09^_l z0b^@o0xZl)AJ%gv^b7Nc>6gIZYU6(r0Y)9YYbz$wvLg}xG*YU10&3asnGLk0E{1nO zEyGIUq07c*3}%;kZQ>!c&ksUv&=6U1?>EnMuEXVR7$)F0t@p~kCSB}Ks!P@7z3#zb HeB}B68p2iu delta 2184 zcmZXVdq`7p6vyw~=3^+O8#)_gbEVYG*HRIanvdC>nPyw$%twks8fD^8gt|jCbVD$7 z_5veQn*$|X3nPuOu!p7;lu!_qA<0xKa}Z{a-|n2dJJ&xZ9DY0JbI$jB&R*BNs<}^a z2z-JWfVuye{)4K{hI!oA9n#=e6ysSbKQWd&X2H^p_B}m~7{eVa)r9FUb51fmpNT@k zAFx2SD!GKcS(G5ZkE*V9wQ>aRWSDnI{*VX{mrz3fv3(zuLb-+#3MrLM4zs#2+#QRx zbZAT3_Trvo%4tp>AT#!a_p%6pc0PLxjZBHiHo9qK6VWuX^&$o&vp=Dc*$DPxD766s zbzrw(wXA1!gJ+@*b{u?`(BuWP*?e@`ZJXKHBoCsKcH+TYLOj{4f@57N8<}B&9bF!= zlreyHqYIK;TSX>C)@>NAflD=55eAoPe!AD_Eb81w%&~lvmH0%mH}f1-m?25=b&g;6D=HDT_6O+2bT1Dg=OPlG}(n51y@RTp&o!DR?q z2`+MxZMpGR6zyn5o<0T1tYe=bnf)S-?B;?MUIzVaiynB#cH1u!C&1Cl;lXoiG)Iqu zp(*-`6p*a;@e4@yvYtkk_9M-cj3|}$fANC0me2a_gF_qS<-3OFFdN!nQDICUBwH+| zskt^`S%e-Emz36#9y&l8*O|^76MYDpXpvWV49rd2nYx2Z^#7B-g}bdvWiG*8YQIBs zzcGC`%{bc3OdrW6i{l@<6v;=*{b}H$vrcf=-jH(`i5DjW@OQ<0-cA56Pi)t@t^ipI z9RYn$rW6)l&3)R-6p$~RAC6xFL!gKM2?QuQao1B!q~*O#_|sUWY!^W-$M}UnOXH=4 zVW_3JIs>}w*_^@Yvd~RDg!XwT&I1jRsZ8Ja$C u64 { "kclvm_schema_value_check" => crate::kclvm_schema_value_check as *const () as u64, "kclvm_schema_value_new" => crate::kclvm_schema_value_new as *const () as u64, "kclvm_scope_add_setter" => crate::kclvm_scope_add_setter as *const () as u64, - "kclvm_scope_free" => crate::kclvm_scope_free as *const () as u64, + "kclvm_scope_delete" => crate::kclvm_scope_delete as *const () as u64, "kclvm_scope_get" => crate::kclvm_scope_get as *const () as u64, "kclvm_scope_new" => crate::kclvm_scope_new as *const () as u64, "kclvm_scope_set" => crate::kclvm_scope_set as *const () as u64, diff --git a/kclvm/runtime/src/_kclvm_api_spec.rs b/kclvm/runtime/src/_kclvm_api_spec.rs index 5662ccb94..15da4b435 100644 --- a/kclvm/runtime/src/_kclvm_api_spec.rs +++ b/kclvm/runtime/src/_kclvm_api_spec.rs @@ -38,9 +38,9 @@ // api-spec(c): kclvm_eval_scope_t* kclvm_scope_new(); // api-spec(llvm): declare %kclvm_eval_scope_t* @kclvm_scope_new(); -// api-spec: kclvm_scope_free -// api-spec(c): void kclvm_scope_free(kclvm_eval_scope_t* scope); -// api-spec(llvm): declare void @kclvm_scope_free(%kclvm_eval_scope_t* %scope); +// api-spec: kclvm_scope_delete +// api-spec(c): void kclvm_scope_delete(kclvm_eval_scope_t* scope); +// api-spec(llvm): declare void @kclvm_scope_delete(%kclvm_eval_scope_t* %scope); // api-spec: kclvm_scope_add_setter // api-spec(c): void kclvm_scope_add_setter(kclvm_context_t* _ctx, kclvm_eval_scope_t* scope, char* pkg, char* name, uint64_t* setter); diff --git a/kclvm/runtime/src/_kclvm_main_win.c b/kclvm/runtime/src/_kclvm_main_win.c deleted file mode 100644 index 4e6473fdb..000000000 --- a/kclvm/runtime/src/_kclvm_main_win.c +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright The KCL Authors. All rights reserved. - -extern void* kclvm_main(void* ctx); - -extern void kclvm_debug_hello(); -extern void kclvm_debug_print(const char* s); - -__declspec(dllexport) void* kclvm_main_win(void* ctx) { - return kclvm_main(ctx); -} - -__declspec(dllexport) void kclvm_debug_hello_win() { - kclvm_debug_hello(); -} - -__declspec(dllexport) void kclvm_debug_print_win(const char* s) { - kclvm_debug_print(s); -} diff --git a/kclvm/runtime/src/context/api.rs b/kclvm/runtime/src/context/api.rs index 2b3253c4c..aaeb77687 100644 --- a/kclvm/runtime/src/context/api.rs +++ b/kclvm/runtime/src/context/api.rs @@ -148,7 +148,7 @@ pub unsafe extern "C" fn kclvm_scope_new() -> *mut kclvm_eval_scope_t { #[no_mangle] #[runtime_fn] -pub unsafe extern "C" fn kclvm_scope_free(scope: *mut kclvm_eval_scope_t) { +pub unsafe extern "C" fn kclvm_scope_delete(scope: *mut kclvm_eval_scope_t) { drop(Box::from_raw(scope)); } diff --git a/test/grammar/schema/irrelevant_order/simple_10/main.k b/test/grammar/schema/irrelevant_order/simple_10/main.k new file mode 100644 index 000000000..0e59f687f --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_10/main.k @@ -0,0 +1,15 @@ +schema Data: + name: str + version?: str + +data1 = Data { + name = data2.name +} + +data2 = Data { + name = "1" + version = version +} + +# Global version +version = "v0.1.0" diff --git a/test/grammar/schema/irrelevant_order/simple_10/stdout.golden b/test/grammar/schema/irrelevant_order/simple_10/stdout.golden new file mode 100644 index 000000000..70d941e06 --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_10/stdout.golden @@ -0,0 +1,6 @@ +data1: + name: '1' +data2: + name: '1' + version: v0.1.0 +version: v0.1.0 diff --git a/test/grammar/schema/irrelevant_order/simple_7/main.k b/test/grammar/schema/irrelevant_order/simple_7/main.k new file mode 100644 index 000000000..c090b2995 --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_7/main.k @@ -0,0 +1,2 @@ +b = a +a = 1 diff --git a/test/grammar/schema/irrelevant_order/simple_7/stdout.golden b/test/grammar/schema/irrelevant_order/simple_7/stdout.golden new file mode 100644 index 000000000..1bcc2448b --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_7/stdout.golden @@ -0,0 +1,2 @@ +b: 1 +a: 1 diff --git a/test/grammar/schema/irrelevant_order/simple_8/main.k b/test/grammar/schema/irrelevant_order/simple_8/main.k new file mode 100644 index 000000000..e7dc4200f --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_8/main.k @@ -0,0 +1,3 @@ +b = a + c +a = 1 +c = a + 1 diff --git a/test/grammar/schema/irrelevant_order/simple_8/stdout.golden b/test/grammar/schema/irrelevant_order/simple_8/stdout.golden new file mode 100644 index 000000000..2befd0fca --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_8/stdout.golden @@ -0,0 +1,3 @@ +b: 3 +a: 1 +c: 2 diff --git a/test/grammar/schema/irrelevant_order/simple_9/kcl.mod b/test/grammar/schema/irrelevant_order/simple_9/kcl.mod new file mode 100644 index 000000000..e69de29bb diff --git a/test/grammar/schema/irrelevant_order/simple_9/main.k b/test/grammar/schema/irrelevant_order/simple_9/main.k new file mode 100644 index 000000000..af2d1b5a0 --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_9/main.k @@ -0,0 +1,3 @@ +import pkg + +output = pkg.output diff --git a/test/grammar/schema/irrelevant_order/simple_9/pkg/base.k b/test/grammar/schema/irrelevant_order/simple_9/pkg/base.k new file mode 100644 index 000000000..17f5d750f --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_9/pkg/base.k @@ -0,0 +1,4 @@ +schema MyApp: + name: str + versions: {str:str} + version = versions[name] diff --git a/test/grammar/schema/irrelevant_order/simple_9/pkg/input.k b/test/grammar/schema/irrelevant_order/simple_9/pkg/input.k new file mode 100644 index 000000000..d5b3ec80d --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_9/pkg/input.k @@ -0,0 +1,5 @@ +output = MyApp{ + name = name + versions = my_versions +} +name = "my_app" diff --git a/test/grammar/schema/irrelevant_order/simple_9/pkg/versions.k b/test/grammar/schema/irrelevant_order/simple_9/pkg/versions.k new file mode 100644 index 000000000..f65fa4fdf --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_9/pkg/versions.k @@ -0,0 +1,3 @@ +my_versions = { + "my-app": "1.0.0" +} \ No newline at end of file diff --git a/test/grammar/schema/irrelevant_order/simple_9/stdout.golden b/test/grammar/schema/irrelevant_order/simple_9/stdout.golden new file mode 100644 index 000000000..56277907c --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_9/stdout.golden @@ -0,0 +1,4 @@ +output: + name: my_app + versions: + my-app: 1.0.0 From 6fc7c9aba056b243e46ddb3c96da2cf1102a3e61 Mon Sep 17 00:00:00 2001 From: peefy Date: Tue, 7 May 2024 17:51:11 +0800 Subject: [PATCH 2/3] chore: bump version to 0.9.0-alpha.1 Signed-off-by: peefy --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ac39a106c..46cc97e6b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.0 +0.9.0-alpha.1 \ No newline at end of file From 6132e8df0117dabdf76354bece37f1a759f845dc Mon Sep 17 00:00:00 2001 From: peefy Date: Tue, 7 May 2024 19:20:03 +0800 Subject: [PATCH 3/3] fix: potential overflow Signed-off-by: peefy --- kclvm/error/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kclvm/error/src/lib.rs b/kclvm/error/src/lib.rs index a45797b2d..ce25667d0 100644 --- a/kclvm/error/src/lib.rs +++ b/kclvm/error/src/lib.rs @@ -460,7 +460,13 @@ impl SessionDiagnostic for Diagnostic { match Session::new_with_file_and_code(&msg.range.0.filename, None) { Ok(sess) => { let source = sess.sm.lookup_source_file(new_byte_pos(0)); - let line = source.get_line((msg.range.0.line - 1) as usize); + let line = source.get_line( + (if msg.range.0.line >= 1 { + msg.range.0.line - 1 + } else { + 0 + }) as usize, + ); match line.as_ref() { Some(content) => { let length = content.chars().count();