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

Ty check #981

Merged
merged 88 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
8cbdeed
Add `bot` type
Y-Nak Jan 30, 2024
f6213dc
Let unification table describe a reason for unification failure
Y-Nak Jan 31, 2024
d32f8f9
Add utility methods to `PathId`
Y-Nak Jan 31, 2024
b84d590
Implement `TyCheckEnv`
Y-Nak Jan 31, 2024
b0b6880
ty_check: lit int
Y-Nak Jan 31, 2024
d6e383b
Add uitest runner for ty check
Y-Nak Jan 31, 2024
44f9b77
Escalate `String` to primitive type
Y-Nak Feb 1, 2024
b5edec0
ty_check: lit string
Y-Nak Feb 1, 2024
357c5b2
ty_check: wildcard, rest, lit, tuple, or pattern
Y-Nak Feb 1, 2024
3d9d648
Change early name path analysis to check paths in expr, pat and stmt
Y-Nak Feb 2, 2024
21294f6
ty_check: simple path pat and let stmt
Y-Nak Feb 2, 2024
40c63d0
ty_check: make `expr` module to isolate logics for expression type ch…
Y-Nak Feb 13, 2024
5457322
ty_check: path tuple pat
Y-Nak Feb 13, 2024
58c6748
ty_check: record pat
Y-Nak Feb 16, 2024
44a630d
ty_check: `if` expr
Y-Nak Feb 16, 2024
e86ff8c
Refactor `PathResolver` to resolve paths in several contexts
Y-Nak Feb 17, 2024
20a2b69
Implement basic expr path resolution
Y-Nak Feb 17, 2024
406fc49
Change function type param representation to include parent generic p…
Y-Nak Feb 19, 2024
9226394
ty_check: path expression and binding resolution
Y-Nak Feb 20, 2024
6e05401
ty_check: record init expression
Y-Nak Feb 21, 2024
07d3caf
Fix a bug in parsing record init with implicit label
Y-Nak Feb 22, 2024
97eb128
Add record field visibility check
Y-Nak Feb 22, 2024
cc29e12
ty_check: tuple expression
Y-Nak Feb 23, 2024
223f3fa
Fix path resolution in pattern for shadowing to work properly
Y-Nak Feb 23, 2024
16b9b58
ty_check: array expression
Y-Nak Feb 23, 2024
14a33ad
ty_check: array repeat expression
Y-Nak Feb 23, 2024
a15fd10
Fix hir visitor bug in span conversion into path tuple pattern
Y-Nak Feb 25, 2024
969fae7
Fix early path resolver to handle paths starting with `Self` properly
Y-Nak Feb 25, 2024
d62fa52
Refine late path resolution by abstracting resolved types
Y-Nak Feb 25, 2024
cdd430e
ty_check: match expression
Y-Nak Feb 25, 2024
87acbf2
Remove unnecessary and fragile usage of unification table from constr…
Y-Nak Feb 26, 2024
5ac90b1
Add bot(never) type in type system, also add workaround in unificatio…
Y-Nak Feb 26, 2024
8edee2e
ty_check: return expression
Y-Nak Feb 26, 2024
87b59d5
ty_check: field access expresssion
Y-Nak Feb 26, 2024
121f2e6
ty_check: index expression
Y-Nak Feb 27, 2024
4a5b46c
ty_check: unary expression
Y-Nak Feb 27, 2024
61194ea
ty_check: binary expression
Y-Nak Feb 27, 2024
38a7c2c
ty_check: Add a property to indicate mutability to `TypedExpr`
Y-Nak Feb 28, 2024
6b90c6a
ty_check: assign and aug assign expression
Y-Nak Feb 28, 2024
fa11f46
ty_check: while statement
Y-Nak Feb 28, 2024
addfa9e
ty_check: break and continue statement
Y-Nak Feb 29, 2024
414c89d
ty_check: `for` statement
Y-Nak Feb 29, 2024
1a82fb8
Bumpup `dir-test` version to 0.2
Y-Nak Mar 2, 2024
ab3280c
ty_check: function call
Y-Nak Mar 3, 2024
5c2d329
ty_check: Fix bug in type inference in match expr
Y-Nak Apr 6, 2024
56ad272
Fix missing scope information for unnamed imports
Y-Nak Apr 6, 2024
a727642
Enable to find all impls of a given type
Y-Nak Apr 6, 2024
680aedf
Add function to collect available traits in the given scope
Y-Nak Apr 7, 2024
1fbdaca
Rename `TyVarUniverse` to `TyVarSort`
Y-Nak Apr 8, 2024
dfb434d
Add `TypeFoldable/TypeFolder`
Y-Nak Apr 8, 2024
7473460
Implement `TypeFolder` to `UnificationTable`
Y-Nak Apr 8, 2024
ec62ef2
Add `TypeVisitable`
Y-Nak Apr 8, 2024
d145aa9
Implement `Binder`
Y-Nak Apr 8, 2024
9c057ed
Cleanup `Implementor` by wrapping it by `Binder`
Y-Nak Apr 8, 2024
df5d530
Wrap up types by `Binder` more
Y-Nak Apr 9, 2024
32095d5
Cleanup trait impl method comparison
Y-Nak Apr 9, 2024
789e4b3
Cleanup binder usage
Y-Nak Apr 10, 2024
ad3961f
Remove subst in favor of `TypeFoldable`
Y-Nak Apr 10, 2024
735e53d
Remove unnecessary types
Y-Nak Apr 10, 2024
42cae75
ty_check: inherent method call
Y-Nak Apr 11, 2024
86f5575
Fix missing visibility check in field access
Y-Nak Apr 12, 2024
6c1a289
Modify `FuncDef` definition to allow lowering an enum unit variant in…
Y-Nak Apr 14, 2024
fc4ecf1
Add lowering from tuple varaint to func def
Y-Nak Apr 14, 2024
1201d1b
Allow users to specify `!` type
Y-Nak Apr 14, 2024
3722455
Add tests for method call
Y-Nak Apr 14, 2024
41df1f1
Fix meaningless type application in method call
Y-Nak Apr 15, 2024
3e957ec
Improve error message in method selection
Y-Nak Apr 15, 2024
5c99db5
ty_check: trait method call
Y-Nak Apr 15, 2024
81aa403
ty_check: bitnot op
Y-Nak Apr 15, 2024
f748981
ty_check: static trait method
Y-Nak Apr 15, 2024
b382899
ty_check: const
Y-Nak Apr 16, 2024
a08494a
Add check for foreign/non-nominal type in inherent impl
Y-Nak Apr 16, 2024
d79ab5a
Fix missing instantiation in method selection
Y-Nak Apr 16, 2024
ff34c65
Fix impl method stricter bound check so that it ignores parental assu…
Y-Nak Apr 16, 2024
9436e7a
Cleanup path resolution in body
Y-Nak Apr 16, 2024
356a613
Resolve const generics as a term
Y-Nak Apr 17, 2024
e2677e7
Cleanup `ty_def` module
Y-Nak Apr 18, 2024
b609ab7
Add `TyFlags`
Y-Nak Apr 18, 2024
48d37e9
Improve error messages
Y-Nak Apr 18, 2024
f921fee
Improve representation of trait constraints
Y-Nak Apr 19, 2024
8813f69
Handle unexpected missing self type in trait method check
Y-Nak Apr 19, 2024
e311f2b
Allow missing `self` label
Y-Nak Apr 19, 2024
0e5779f
Stop visiting block internal items when finalizing type checking
Y-Nak Apr 20, 2024
8690082
Fix missing instantiation in method selection
Y-Nak Apr 20, 2024
bfd4fdd
Fix missing string type variable fallback
Y-Nak Apr 20, 2024
9344ba8
Update old tests
Y-Nak Apr 20, 2024
fa08726
Add more tests
Y-Nak Apr 20, 2024
2cfa44c
Canonicalize more
Y-Nak Apr 21, 2024
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
38 changes: 23 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/analyzer/src/traversal/matching_anomaly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fmt::Write;
use fe_common::Span;
use fe_parser::{ast::MatchArm, node::Node, Label};

use super::pattern_analysis::{PatternMatrix, SimplifiedPattern};
use crate::{
context::AnalyzerContext,
display::Displayable,
Expand All @@ -11,8 +12,6 @@ use crate::{
AnalyzerDb,
};

use super::pattern_analysis::{PatternMatrix, SimplifiedPattern};

pub(super) fn check_match_exhaustiveness(
scope: &mut BlockScope,
arms: &[Node<MatchArm>],
Expand Down
2 changes: 2 additions & 0 deletions crates/common2/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub enum DiagnosticPass {
ImplTraitDefinition,
TraitSatisfaction,
MethodDefinition,
TyCheck,

ExternalAnalysis(ExternalAnalysisKey),
}
Expand All @@ -163,6 +164,7 @@ impl DiagnosticPass {
Self::ImplTraitDefinition => 5,
Self::TraitSatisfaction => 6,
Self::MethodDefinition => 7,
Self::TyCheck => 8,

Self::ExternalAnalysis(_) => std::u16::MAX,
}
Expand Down
3 changes: 1 addition & 2 deletions crates/driver2/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use std::ops::Range;

use camino::Utf8Path;
use codespan_reporting as cs;
use cs::{diagnostic as cs_diag, files as cs_files};

use common::{
diagnostics::{LabelStyle, Severity},
InputDb, InputFile,
};
use cs::{diagnostic as cs_diag, files as cs_files};
use hir::diagnostics::DiagnosticVoucher;

use crate::{DriverDataBase, DriverDb};
Expand Down
5 changes: 3 additions & 2 deletions crates/driver2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use hir::{
use hir_analysis::{
name_resolution::{DefConflictAnalysisPass, ImportAnalysisPass, PathAnalysisPass},
ty::{
FuncAnalysisPass, ImplAnalysisPass, ImplTraitAnalysisPass, TraitAnalysisPass,
TypeAliasAnalysisPass, TypeDefAnalysisPass,
BodyAnalysisPass, FuncAnalysisPass, ImplAnalysisPass, ImplTraitAnalysisPass,
TraitAnalysisPass, TypeAliasAnalysisPass, TypeDefAnalysisPass,
},
HirAnalysisDb,
};
Expand Down Expand Up @@ -154,5 +154,6 @@ fn initialize_analysis_pass(db: &DriverDataBase) -> AnalysisPassManager<'_> {
pass_manager.add_module_pass(Box::new(ImplAnalysisPass::new(db)));
pass_manager.add_module_pass(Box::new(ImplTraitAnalysisPass::new(db)));
pass_manager.add_module_pass(Box::new(FuncAnalysisPass::new(db)));
pass_manager.add_module_pass(Box::new(BodyAnalysisPass::new(db)));
pass_manager
}
4 changes: 3 additions & 1 deletion crates/hir-analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ fe-compiler-test-utils = { path = "../test-utils" }
num-bigint = "0.4"
once_cell = "1.18"
regex = "1.10"
if_chain = "1.0"
bitflags = "2.5"

[dev-dependencies]
codespan-reporting = "0.11"
dir-test = "0.1"
dir-test = "0.2"
52 changes: 30 additions & 22 deletions crates/hir-analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,84 @@ use hir::{span::DynLazySpan, HirDb};

#[salsa::jar(db = HirAnalysisDb)]
pub struct Jar(
/// Functions for import/name resolutions.
// Functions for import/name resolutions.
name_resolution::resolve_path_early_impl,
name_resolution::resolve_imports,
name_resolution::diagnostics::NameResolutionDiagAccumulator,
name_resolution::diagnostics::ImportResolutionDiagAccumulator,
/// Type system.
name_resolution::traits_in_scope::available_traits_in_scope_impl,
name_resolution::traits_in_scope::TraitScope,
// Type system.
ty::ty_def::TyId,
ty::ty_def::ty_kind,
ty::ty_def::free_inference_keys,
ty::ty_def::collect_type_params,
ty::ty_def::pretty_print_ty,
ty::ty_def::AdtDef,
ty::ty_def::FuncDef,
ty::ty_def::AdtRefId,
/// Const types.
ty::ty_def::decompose_ty_app,
ty::ty_def::ty_flags,
// Adt types.
ty::adt_def::AdtDef,
ty::adt_def::AdtRefId,
ty::adt_def::lower_adt,
// Func type.
ty::func_def::FuncDef,
ty::func_def::lower_func,
// Const types.
ty::const_ty::ConstTyId,
ty::const_ty::evaluate_const_ty,
/// Type lowering.
// Type lowering.
ty::ty_lower::lower_hir_ty,
ty::ty_lower::lower_adt,
ty::ty_lower::lower_func,
ty::ty_lower::lower_type_alias,
ty::ty_lower::collect_generic_params,
ty::ty_lower::GenericParamOwnerId,
ty::ty_lower::GenericParamTypeSet,
ty::ty_lower::evaluate_params_precursor,
/// Trait lowering.
// Trait lowering.
ty::trait_lower::lower_trait,
ty::trait_lower::lower_trait_ref,
ty::trait_lower::collect_trait_impls,
ty::trait_lower::lower_impl_trait,
ty::trait_lower::collect_implementor_methods,
/// Method collection.
// Method collection.
ty::method_table::collect_methods,
/// Item Definition analysis.
ty::method_table::probe_method,
// Item Definition analysis.
ty::def_analysis::check_recursive_adt,
ty::def_analysis::analyze_adt,
ty::def_analysis::analyze_type_alias,
ty::def_analysis::analyze_trait,
ty::def_analysis::analyze_impl,
ty::def_analysis::analyze_impl_trait,
ty::def_analysis::analyze_func,
/// Trait system.
// Trait system.
ty::trait_def::TraitDef,
ty::trait_def::TraitInstId,
ty::trait_def::Implementor,
ty::trait_def::ingot_trait_env,
ty::trait_def::trait_implementors,
ty::trait_def::impls_of_trait,
ty::trait_def::impls_of_ty,
// Trait constraints
ty::constraint::collect_super_traits,
ty::constraint::collect_trait_constraints,
ty::constraint::collect_adt_constraints,
ty::constraint::collect_implementor_constraints,
ty::constraint::collect_impl_block_constraints,
ty::constraint::collect_func_def_constraints,
ty::constraint::super_trait_insts,
ty::constraint::compute_super_assumptions,
ty::constraint::collect_func_def_constraints_impl,
ty::constraint::ty_constraints,
ty::constraint::trait_inst_constraints,
ty::constraint::PredicateId,
ty::constraint::PredicateListId,
ty::constraint_solver::is_goal_satisfiable,
ty::constraint_solver::check_ty_app_sat,
ty::constraint_solver::check_trait_inst_sat,
/// Diagnostic accumulators.
ty::constraint_solver::check_ty_wf,
ty::constraint_solver::check_trait_inst_wf,
// Type checking.
ty::ty_check::check_func_body,
// Diagnostic accumulators.
ty::diagnostics::AdtDefDiagAccumulator,
ty::diagnostics::TypeAliasDefDiagAccumulator,
ty::diagnostics::TraitDefDiagAccumulator,
ty::diagnostics::ImplTraitDefDiagAccumulator,
ty::diagnostics::ImplDefDiagAccumulator,
ty::diagnostics::FuncDefDiagAccumulator,
ty::diagnostics::FuncBodyDiagAccumulator,
);

pub trait HirAnalysisDb: salsa::DbWithJar<Jar> + HirDb {
Expand Down
16 changes: 8 additions & 8 deletions crates/hir-analysis/src/name_resolution/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ impl NameResDiag {
}
}

pub(crate) fn invisible(
span: DynLazySpan,
name: IdentId,
invisible_span: Option<DynLazySpan>,
) -> Self {
Self::Invisible(span, name, invisible_span)
}

pub(super) fn conflict(name: IdentId, conflict_with: Vec<DynLazySpan>) -> Self {
Self::Conflict(name, conflict_with)
}
Expand All @@ -74,14 +82,6 @@ impl NameResDiag {
Self::NotFound(span, ident)
}

pub(super) fn invisible(
span: DynLazySpan,
name: IdentId,
invisible_span: Option<DynLazySpan>,
) -> Self {
Self::Invisible(span, name, invisible_span)
}

pub(super) fn ambiguous(
db: &dyn HirAnalysisDb,
span: DynLazySpan,
Expand Down
Loading
Loading