Merge branch 'main' into shape

This commit is contained in:
Shunsuke Shibayama 2023-08-02 10:51:16 +09:00
commit 0b63e037ec
4 changed files with 20 additions and 5 deletions

View file

@ -274,7 +274,7 @@ impl ErgConfig {
.parse::<u8>()
.expect("the value of `-o` is not a number");
}
"--output-dir" | "--dest" => {
"--output-dir" | "--dest" | "--dist" | "--dest-dir" | "--dist-dir" => {
let output_dir = args
.next()
.expect("the value of `--output-dir` is not passed")
@ -317,7 +317,7 @@ impl ErgConfig {
.parse::<u64>()
.expect("the value of `--py-server-timeout` is not a number");
}
"--quiet-startup" | "--quiet-repl" => {
"-q" | "--quiet-startup" | "--quiet-repl" => {
cfg.quiet_repl = true;
}
"-t" | "--show-type" => {
@ -331,7 +331,7 @@ impl ErgConfig {
.expect("the value of `--target-version` is not a valid Python version");
cfg.target_version = Some(target_version);
}
"--verbose" => {
"-v" | "--verbose" => {
cfg.verbose = args
.next()
.expect("the value of `--verbose` is not passed")

View file

@ -599,6 +599,11 @@ impl Context {
pub(crate) fn instantiate(&self, quantified: Type, callee: &hir::Expr) -> TyCheckResult<Type> {
match quantified {
FreeVar(fv) if fv.is_linked() => self.instantiate(fv.crack().clone(), callee),
And(lhs, rhs) => {
let lhs = self.instantiate(*lhs, callee)?;
let rhs = self.instantiate(*rhs, callee)?;
Ok(lhs & rhs)
}
Quantified(quant) => {
let mut tmp_tv_cache = TyVarCache::new(self.level, self);
let ty = self.instantiate_t_inner(*quant, &mut tmp_tv_cache, callee)?;
@ -656,6 +661,11 @@ impl Context {
pub(crate) fn instantiate_dummy(&self, quantified: Type) -> TyCheckResult<Type> {
match quantified {
FreeVar(fv) if fv.is_linked() => self.instantiate_dummy(fv.crack().clone()),
And(lhs, rhs) => {
let lhs = self.instantiate_dummy(*lhs)?;
let rhs = self.instantiate_dummy(*rhs)?;
Ok(lhs & rhs)
}
Quantified(quant) => {
let mut tmp_tv_cache = TyVarCache::new(self.level, self);
let ty = self.instantiate_t_inner(*quant, &mut tmp_tv_cache, &())?;

View file

@ -1513,6 +1513,7 @@ impl Context {
mode,
not_found_is_qvar,
)?;
// no quantification at this point (in `generalize_t`)
Ok(subr_t(
SubrKind::from(subr.arrow.kind),
non_defaults,

View file

@ -1667,7 +1667,10 @@ impl Type {
pub fn quantify(self) -> Self {
debug_assert!(self.is_subr(), "{self} is not subr");
Self::Quantified(Box::new(self))
match self {
Self::And(lhs, rhs) => lhs.quantify() & rhs.quantify(),
other => Self::Quantified(Box::new(other)),
}
}
pub fn proj<S: Into<Str>>(self, attr: S) -> Self {
@ -2469,7 +2472,8 @@ impl Type {
Self::Subr(subr) => subr.qvars(),
Self::Record(r) => r.values().fold(set! {}, |acc, t| acc.concat(t.qvars())),
Self::Refinement(refine) => refine.t.qvars().concat(refine.pred.qvars()),
Self::Quantified(quant) => quant.qvars(),
// ((|T| T -> T) and U).qvars() == U.qvars()
// Self::Quantified(quant) => quant.qvars(),
Self::Poly { params, .. } => params
.iter()
.fold(set! {}, |acc, tp| acc.concat(tp.qvars())),