Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/latest'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wck-iipi committed May 31, 2024
2 parents c425830 + 87c53c5 commit 9d5ad49
Show file tree
Hide file tree
Showing 22 changed files with 384 additions and 157 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/wasm_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: build-and-test-wasm
on: ["push", "pull_request"]
jobs:
build-and-test:
# Ref: https://github.com/actions/runner-images/tree/main/images/linux
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
submodules: "true"

- name: Install rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.76
override: true
components: clippy, rustfmt

- name: Unit test
working-directory: ./kclvm
run: rustup target add wasm32-wasi && make build-wasm
shell: bash

- uses: actions/upload-artifact@v3
with:
name: kcl-wasm
path: kclvm/target/wasm32-wasi/release/kclvm_cli_cdylib.wasm
2 changes: 2 additions & 0 deletions kclvm/api/src/service/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub(crate) fn kclvm_get_service_fn_ptr_by_name(name: &str) -> u64 {
"KclvmService.Rename" => rename as *const () as u64,
"KclvmService.RenameCode" => rename_code as *const () as u64,
"KclvmService.Test" => test as *const () as u64,
#[cfg(not(target_arch = "wasm32"))]
"KclvmService.UpdateDependencies" => update_dependencies as *const () as u64,
_ => panic!("unknown method name : {name}"),
}
Expand Down Expand Up @@ -524,6 +525,7 @@ pub(crate) fn test(
call!(serv, args, result_len, TestArgs, test)
}

#[cfg(not(target_arch = "wasm32"))]
/// Service for the dependencies updating
/// calling information.
///
Expand Down
6 changes: 4 additions & 2 deletions kclvm/api/src/service/service_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::string::String;

use crate::gpyrpc::*;
Expand All @@ -9,7 +9,6 @@ use anyhow::anyhow;
use kcl_language_server::rename;
use kclvm_config::settings::build_settings_pathbuf;
use kclvm_driver::canonicalize_input_files;
use kclvm_driver::client::ModClient;
use kclvm_loader::option::list_options;
use kclvm_loader::{load_packages_with_cache, LoadPackageOptions};
use kclvm_parser::load_program;
Expand Down Expand Up @@ -957,6 +956,7 @@ impl KclvmServiceImpl {
Ok(result)
}

#[cfg(not(target_arch = "wasm32"))]
/// update_dependencies provides users with the ability to update kcl module dependencies.
///
/// # Examples
Expand Down Expand Up @@ -986,6 +986,8 @@ impl KclvmServiceImpl {
&self,
args: &UpdateDependenciesArgs,
) -> anyhow::Result<UpdateDependenciesResult> {
use kclvm_driver::client::ModClient;
use std::path::Path;
let mut client = ModClient::new(&args.manifest_path)?;
if args.vendor {
client.set_vendor(&Path::new(&args.manifest_path).join("vendor"));
Expand Down
6 changes: 4 additions & 2 deletions kclvm/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ walkdir = "2"
serde = { version = "1.0", features = ["derive"] }
anyhow = { version = "1.0.70", features = ["backtrace"] }
glob = "0.3.1"
oci-distribution = { default-features = false, version = "0.11.0", features = ["rustls-tls"] }
flate2 = "1.0.30"
tar = "0.4.40"
tokio = { version = "1.37.0", features = ["full"] }
indexmap = "2.2.6"
once_cell = "1.19.0"
parking_lot = "0.12.3"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
oci-distribution = { default-features = false, version = "0.11.0", features = ["rustls-tls"] }
tokio = { version = "1.37.0", features = ["full"] }
1 change: 1 addition & 0 deletions kclvm/driver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod arguments;
#[cfg(not(target_arch = "wasm32"))]
pub mod client;
pub mod toolchain;

Expand Down
7 changes: 4 additions & 3 deletions kclvm/driver/src/toolchain.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::client::ModClient;
use crate::{kcl, lookup_the_nearest_file_dir};
use anyhow::{bail, Result};
use kclvm_config::modfile::KCL_MOD_FILE;
use kclvm_parser::LoadProgramOptions;
use kclvm_utils::pkgpath::rm_external_pkg_name;
use parking_lot::Mutex;
use serde::{Deserialize, Serialize};
use std::ffi::OsStr;
use std::sync::Arc;
use std::{collections::HashMap, path::PathBuf, process::Command};
#[cfg(not(target_arch = "wasm32"))]
use {crate::client::ModClient, parking_lot::Mutex, std::sync::Arc};

/// `Toolchain` is a trait that outlines a standard set of operations that must be
/// implemented for a KCL module (mod), typically involving fetching metadata from,
Expand Down Expand Up @@ -99,11 +98,13 @@ impl<S: AsRef<OsStr> + Send + Sync> Toolchain for CommandToolchain<S> {
}
}

#[cfg(not(target_arch = "wasm32"))]
#[derive(Default)]
pub struct NativeToolchain {
client: Arc<Mutex<ModClient>>,
}

#[cfg(not(target_arch = "wasm32"))]
impl Toolchain for NativeToolchain {
fn fetch_metadata(&self, manifest_path: PathBuf) -> Result<Metadata> {
let mut client = self.client.lock();
Expand Down
3 changes: 1 addition & 2 deletions kclvm/sema/src/resolver/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'ctx> Resolver<'ctx> {
return;
}
};
self.must_assignable_to(ty.clone(), expected_ty, args[i].get_span_pos(), None, true)
self.must_assignable_to(ty.clone(), expected_ty, args[i].get_span_pos(), None)
}
// Do keyword argument type check
for (i, (arg_name, kwarg_ty)) in kwarg_types.iter().enumerate() {
Expand Down Expand Up @@ -144,7 +144,6 @@ impl<'ctx> Resolver<'ctx> {
expected_types[0].clone(),
kwargs[i].get_span_pos(),
None,
true,
);
};
}
Expand Down
70 changes: 56 additions & 14 deletions kclvm/sema/src/resolver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,38 @@ impl<'ctx> Resolver<'ctx> {
},
}
}
TypeKind::Union(types) => {
let mut possible_types = vec![];
for ty in types {
match &ty.kind {
TypeKind::Schema(schema_ty) => {
match schema_ty.get_obj_of_attr(key_name) {
Some(attr_ty_obj) => {
possible_types.push(attr_ty_obj.ty.clone());
}
None => match &schema_ty.index_signature {
Some(index_signature) => {
possible_types
.push(index_signature.val_ty.clone());
}
None => continue,
},
}
}
TypeKind::Dict(DictType { val_ty, .. }) => {
possible_types.push(val_ty.clone());
}
_ => continue,
}
}

Some(self.new_config_expr_context_item(
key_name,
crate::ty::sup(&possible_types).into(),
obj.start.clone(),
obj.end.clone(),
))
}
_ => None,
},
None => None,
Expand Down Expand Up @@ -320,7 +352,6 @@ impl<'ctx> Resolver<'ctx> {
ty,
key.get_span_pos(),
Some(obj_last.get_span_pos()),
true,
);
}
self.clear_config_expr_context(stack_depth, false);
Expand Down Expand Up @@ -350,19 +381,23 @@ impl<'ctx> Resolver<'ctx> {
let mut schema_names = vec![];
let mut total_suggs = vec![];
for ty in types {
if let TypeKind::Schema(schema_ty) = &ty.kind {
if schema_ty.get_obj_of_attr(attr).is_none()
&& !schema_ty.is_mixin
&& schema_ty.index_signature.is_none()
{
let mut suggs =
suggestions::provide_suggestions(attr, schema_ty.attrs.keys());
total_suggs.append(&mut suggs);
schema_names.push(schema_ty.name.clone());
} else {
// If there is a schema attribute that meets the condition, the type check passes
return;
match &ty.kind {
TypeKind::Schema(schema_ty) => {
if schema_ty.get_obj_of_attr(attr).is_none()
&& !schema_ty.is_mixin
&& schema_ty.index_signature.is_none()
{
let mut suggs =
suggestions::provide_suggestions(attr, schema_ty.attrs.keys());
total_suggs.append(&mut suggs);
schema_names.push(schema_ty.name.clone());
} else {
// If there is a schema attribute that meets the condition, the type check passes
return;
}
}
TypeKind::Dict(..) => return,
_ => continue,
}
}
if !schema_names.is_empty() {
Expand Down Expand Up @@ -497,7 +532,11 @@ impl<'ctx> Resolver<'ctx> {
let key_ty = if identifier.names.len() == 1 {
let name = &identifier.names[0].node;
let key_ty = if self.ctx.local_vars.contains(name) {
self.expr(key)
// set key context expected schema as None
self.ctx.config_expr_context.push(None);
let key_ty = self.expr(key);
self.ctx.config_expr_context.pop();
key_ty
} else {
Arc::new(Type::str_lit(name))
};
Expand Down Expand Up @@ -543,7 +582,10 @@ impl<'ctx> Resolver<'ctx> {
val_ty
}
_ => {
// set key context expected schema as None
self.ctx.config_expr_context.push(None);
let key_ty = self.expr(key);
self.ctx.config_expr_context.pop();
let val_ty = self.expr(value);
self.check_attr_ty(&key_ty, key.get_span_pos());
if let ast::Expr::StringLit(string_lit) = &key.node {
Expand Down
14 changes: 1 addition & 13 deletions kclvm/sema/src/resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
expected_ty.clone(),
unification_stmt.target.get_span_pos(),
None,
true,
);
if !ty.is_any() && expected_ty.is_any() {
self.set_type_to_scope(&names[0].node, ty, &names[0]);
Expand Down Expand Up @@ -185,7 +184,6 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
expected_ty.clone(),
target.get_span_pos(),
None,
true,
);

let upgrade_schema_type = self.upgrade_dict_to_schema(
Expand Down Expand Up @@ -221,7 +219,6 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
expected_ty.clone(),
target.get_span_pos(),
None,
true,
);

let upgrade_schema_type = self.upgrade_dict_to_schema(
Expand Down Expand Up @@ -290,7 +287,6 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
expected_ty,
aug_assign_stmt.target.get_span_pos(),
None,
true,
);
self.ctx.l_value = false;
new_target_ty
Expand Down Expand Up @@ -457,7 +453,6 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
expected_ty,
schema_attr.name.get_span_pos(),
None,
true,
);
}
// Assign
Expand All @@ -466,7 +461,6 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
expected_ty,
schema_attr.name.get_span_pos(),
None,
true,
),
},
None => bug!("invalid ast schema attr op kind"),
Expand Down Expand Up @@ -1117,13 +1111,7 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
let real_ret_ty = self.stmts(&lambda_expr.body);
self.leave_scope();
self.ctx.in_lambda_expr.pop();
self.must_assignable_to(
real_ret_ty.clone(),
ret_ty.clone(),
(start, end),
None,
true,
);
self.must_assignable_to(real_ret_ty.clone(), ret_ty.clone(), (start, end), None);
if !real_ret_ty.is_any() && ret_ty.is_any() && lambda_expr.return_ty.is_none() {
ret_ty = real_ret_ty;
}
Expand Down
1 change: 0 additions & 1 deletion kclvm/sema/src/resolver/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ impl<'ctx> Resolver<'ctx> {
expected_ty,
index_signature_node.get_span_pos(),
None,
true,
);
}
}
Expand Down
Loading

0 comments on commit 9d5ad49

Please sign in to comment.