Skip to content

Commit

Permalink
Merge branch 'main' into perf_or_type
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Sep 15, 2024
2 parents b0c3137 + d87c5d5 commit a0810ad
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Notify

on:
push:
branches: [main]
branches: [main, notify-*]
paths-ignore:
- "doc/**"
- ".github/**"
Expand All @@ -28,12 +28,12 @@ jobs:
-H "Authorization: token ${{ secrets.TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/mtshiba/ergscripts/dispatches \
-d '{"event_type":"notification-push-main","client_payload":{"msg": "a change has been pushed to main"}}'
-d '{"event_type":"notification-push-main","client_payload":{"msg": "A change has been pushed", "branch": "${{ github.ref_name }}"}}'
- name: notify to pytypes
run: |
curl \
-X POST \
-H "Authorization: token ${{ secrets.TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/erg-lang/pytypes/dispatches \
-d '{"event_type":"notification-push-main","client_payload":{"msg": "a change has been pushed to main"}}'
-d '{"event_type":"notification-push-main","client_payload":{"msg": "A change has been pushed", "branch": "${{ github.ref_name }}"}}'
17 changes: 13 additions & 4 deletions crates/erg_compiler/context/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,24 @@ impl Context {
};
// () -> Never <: () -> Int <: () -> Object
// (Object) -> Int <: (Int) -> Int <: (Never) -> Int
// (Int, Int) -> Int <!: (Int) -> Int
// (Int, n := Int) -> Int <: (Int, Int) -> Int
// (Int, Int, n := Int) -> Int <!: (Int, n := Int) -> Int
// (Int, n := Int, m := Int) -> Int <: (Int, Int) -> Int
// (Int, n := Int) -> Int <!: (Int, Int, Int) -> Int
// (*Int) -> Int <: (Int, Int) -> Int
// (*Int) -> Int !<: (n := Int, m := Int) -> Int
// (self: Self, T) -> U <: T -> U
let len_judge = ls.non_default_params.len()
<= rs.non_default_params.len() + rs.default_params.len()
|| rs.var_params.is_some();
// && ls.default_params.len() <= rs.default_params.len();
let len_judge = (if rs.default_params.is_empty() {
ls.non_default_params.len() == rs.non_default_params.len()
} else {
ls.non_default_params.len() >= rs.non_default_params.len()
&& ls.non_default_params.len()
<= rs.non_default_params.len() + rs.default_params.len()
} && ls.default_params.len() <= rs.default_params.len())
|| (ls.default_params.is_empty() && rs.var_params.is_some())
|| (ls.non_default_params.is_empty() && rs.kw_var_params.is_some())
|| (rs.var_params.is_some() && rs.kw_var_params.is_some());
let rhs_ret = rs
.return_t
.clone()
Expand Down
12 changes: 6 additions & 6 deletions crates/erg_compiler/context/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1687,8 +1687,8 @@ impl Context {
lhs: TyParam,
rhs: TyParam,
) -> EvalResult<TyParam> {
let lhs = self.eval_tp(lhs).map_err(|(_, es)| es)?;
let rhs = self.eval_tp(rhs).map_err(|(_, es)| es)?;
// let lhs = self.eval_tp(lhs).map_err(|(_, es)| es)?;
// let rhs = self.eval_tp(rhs).map_err(|(_, es)| es)?;
match (lhs, rhs) {
(TyParam::Value(lhs), TyParam::Value(rhs)) => {
self.eval_bin(op, lhs, rhs).map(TyParam::value)
Expand Down Expand Up @@ -1807,7 +1807,7 @@ impl Context {

/// val: may be unevaluated
pub(crate) fn eval_unary_tp(&self, op: OpKind, val: TyParam) -> EvalResult<TyParam> {
let val = self.eval_tp(val).map_err(|(_, es)| es)?;
// let val = self.eval_tp(val).map_err(|(_, es)| es)?;
match val {
TyParam::Value(c) => self.eval_unary_val(op, c).map(TyParam::Value),
TyParam::FreeVar(fv) if fv.is_linked() => {
Expand All @@ -1824,9 +1824,9 @@ impl Context {

/// args: may be unevaluated
pub(crate) fn eval_app(&self, name: Str, args: Vec<TyParam>) -> Failable<TyParam> {
let args = self
.eval_type_args(args)
.map_err(|(args, es)| (TyParam::app(name.clone(), args), es))?;
/*let args = self
.eval_type_args(args)
.map_err(|(args, es)| (TyParam::app(name.clone(), args), es))?;*/
if let Ok(value_args) = args
.iter()
.map(|tp| self.convert_tp_into_value(tp.clone()))
Expand Down
19 changes: 8 additions & 11 deletions crates/erg_compiler/context/instantiate_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,17 +484,14 @@ impl Context {
}
};
if let Some(decl_pt) = opt_decl_t {
if kind.is_var_params() {
let spec_t = unknown_len_list_t(spec_t.clone());
if let Err(es) = self.sub_unify(
decl_pt.typ(),
&spec_t,
&sig.t_spec.as_ref().ok_or(sig),
None,
) {
return Err((spec_t, errs.concat(es)));
}
} else if let Err(es) = self.sub_unify(
let spec_t = if kind.is_var_params() {
unknown_len_list_t(spec_t.clone())
} else if kind.is_kw_var_params() {
str_dict_t(spec_t.clone())
} else {
spec_t.clone()
};
if let Err(es) = self.sub_unify(
decl_pt.typ(),
&spec_t,
&sig.t_spec.as_ref().ok_or(sig),
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl Context {
}
}
if let Some(kw_var_params) = &mut params.kw_var_params {
if let Some(pt) = &subr_t.var_params {
if let Some(pt) = &subr_t.kw_var_params {
let pt = pt.clone().map_type(&mut str_dict_t);
if let Err(es) = self.assign_param(
kw_var_params,
Expand Down
11 changes: 11 additions & 0 deletions tests/should_err/default_param.er
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ _: Int -> Str = id_or_int # ERR

g x: Int := 1, y: Int := "a" = x + y # ERR
_: (Int, Int) -> Int = g

check f: (Int, n := Int) -> Int = f(1)
check2 f: (m := Int, n := Int) -> Int = f(m:=1, n:=2)
f1(x: Int, y, n := 1) = x + y + n
f2(x: Int, y: Int) = x + y
f3(*x: Int) = x[0]
f4(**x: Int) = x["a"]
_ = check f1 # ERR
_ = check2 f2 # ERR
_ = check2 f3 # ERR
_ = check f4 # ERR
8 changes: 8 additions & 0 deletions tests/should_ok/default_param.er
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ _: (Int, Int, Nat) -> Int = f
_: (Int, Int, _: {1}) -> Int = f
_: Int -> Int = id_or_int
_: Str -> Str = id_or_int

check f: (Int, n := Int) -> Int = f(1)
check2 f: (m := Int, n := Int) -> Int = f(m:=1, n:=2)
f2(m: Int := 1, n := 1, l := 1) = m + n + l
f3(*x: Int, **y: Int) = len(x) + y.get("n", 0)
_ = check2 f2
_ = check f3
_ = check2 f3
13 changes: 13 additions & 0 deletions tests/should_ok/dependent_refinement.er
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ndarray = pyimport "ndarray"

a as ndarray.NDArray(Int, [2, 3]) = todo()

check|T, Shape: {A: [Nat; _] | all(map((X -> X > 1), A))}|(
_: ndarray.NDArray(T, Shape)
) = None
check a

check2|T, Shape: [Nat; _]|(
_: {_: ndarray.NDArray(T, Shape) | all(map((X -> X > 1), Shape))}
) = None
check2 a
3 changes: 3 additions & 0 deletions tests/should_ok/ndarray.d.er
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.NDArray: (T: Type, Shape: [Nat; _]) -> ClassType
.NDArray(T, _) <: Output T
.NDArray(_, _) <: Num
9 changes: 7 additions & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ fn exec_dependent() -> Result<(), ()> {
expect_success("tests/should_ok/dependent.er", 0)
}

#[test]
fn exec_dependent_refinement() -> Result<(), ()> {
expect_compile_success("tests/should_ok/dependent_refinement.er", 0)
}

#[test]
fn exec_dict() -> Result<(), ()> {
expect_success("examples/dict.er", 0)
Expand Down Expand Up @@ -504,7 +509,7 @@ fn exec_advanced_type_spec_err() -> Result<(), ()> {

#[test]
fn exec_args() -> Result<(), ()> {
expect_failure("tests/should_err/args.er", 0, 19)
expect_failure("tests/should_err/args.er", 0, 20)
}

#[test]
Expand Down Expand Up @@ -554,7 +559,7 @@ fn exec_collection_err() -> Result<(), ()> {

#[test]
fn exec_default_param_err() -> Result<(), ()> {
expect_failure("tests/should_err/default_param.er", 0, 4)
expect_failure("tests/should_err/default_param.er", 0, 8)
}

#[test]
Expand Down

0 comments on commit a0810ad

Please sign in to comment.