Struct erg_compiler::artifact::IncompleteArtifact
source · pub struct IncompleteArtifact<Inner = HIR> {
pub object: Option<Inner>,
pub errors: CompileErrors,
pub warns: CompileErrors,
}
Fields§
§object: Option<Inner>
§errors: CompileErrors
§warns: CompileErrors
Implementations§
source§impl<Inner> IncompleteArtifact<Inner>
impl<Inner> IncompleteArtifact<Inner>
sourcepub const fn new(
object: Option<Inner>,
errors: CompileErrors,
warns: CompileErrors
) -> Self
pub const fn new(
object: Option<Inner>,
errors: CompileErrors,
warns: CompileErrors
) -> Self
Examples found in repository?
More examples
lower.rs (lines 1889-1893)
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
fn return_incomplete_artifact(&mut self, hir: HIR) -> IncompleteArtifact {
self.ctx.clear_invalid_vars();
IncompleteArtifact::new(
Some(hir),
LowerErrors::from(self.errs.take_all()),
LowerWarnings::from(self.warns.take_all()),
)
}
pub fn lower(&mut self, ast: AST, mode: &str) -> Result<CompleteArtifact, IncompleteArtifact> {
log!(info "the AST lowering process has started.");
log!(info "the type-checking process has started.");
let ast = Reorderer::new(self.cfg.clone())
.reorder(ast)
.map_err(|errs| {
IncompleteArtifact::new(None, errs, LowerWarnings::from(self.warns.take_all()))
})?;
if mode == "declare" {
let hir = self.declare_module(ast);
if self.errs.is_empty() {
log!(info "HIR:\n{hir}");
log!(info "the declaring process has completed.");
return Ok(CompleteArtifact::new(
hir,
LowerWarnings::from(self.warns.take_all()),
));
} else {
log!(err "the declaring process has failed.");
return Err(self.return_incomplete_artifact(hir));
}
}
let mut module = hir::Module::with_capacity(ast.module.len());
if let Err(errs) = self.ctx.preregister(ast.module.block()) {
self.errs.extend(errs);
}
for chunk in ast.module.into_iter() {
match self.lower_expr(chunk) {
Ok(chunk) => {
module.push(chunk);
}
Err(errs) => {
self.errs.extend(errs);
}
}
}
self.ctx.clear_invalid_vars();
self.ctx.check_decls().unwrap_or_else(|mut errs| {
self.errs.append(&mut errs);
});
let hir = HIR::new(ast.name, module);
log!(info "HIR (not resolved, current errs: {}):\n{hir}", self.errs.len());
let hir = match self.ctx.resolve(hir) {
Ok(hir) => {
log!(info "HIR (resolved):\n{hir}");
hir
}
Err((hir, errs)) => {
self.errs.extend(errs);
log!(err "the resolving process has failed. errs: {}", self.errs.len());
return Err(self.return_incomplete_artifact(hir));
}
};
// TODO: recursive check
for chunk in hir.module.iter() {
if let Err(warns) = self.use_check(chunk, mode) {
self.warns.extend(warns);
}
}
if self.errs.is_empty() {
log!(info "the AST lowering process has completed.");
Ok(CompleteArtifact::new(
hir,
LowerWarnings::from(self.warns.take_all()),
))
} else {
log!(err "the AST lowering process has failed. errs: {}", self.errs.len());
Err(self.return_incomplete_artifact(hir))
}
}
build_hir.rs (line 127)
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
pub fn check(&mut self, ast: AST, mode: &str) -> Result<CompleteArtifact, IncompleteArtifact> {
let artifact = self.lowerer.lower(ast, mode)?;
let effect_checker = SideEffectChecker::new(self.cfg().clone());
let hir = effect_checker
.check(artifact.object)
.map_err(|(hir, errs)| {
self.lowerer.ctx.clear_invalid_vars();
IncompleteArtifact::new(Some(hir), errs, artifact.warns.clone())
})?;
let hir = self.ownership_checker.check(hir).map_err(|(hir, errs)| {
self.lowerer.ctx.clear_invalid_vars();
IncompleteArtifact::new(Some(hir), errs, artifact.warns.clone())
})?;
Ok(CompleteArtifact::new(hir, artifact.warns))
}
pub fn build(
&mut self,
src: String,
mode: &str,
) -> Result<CompleteArtifact, IncompleteArtifact> {
let mut ast_builder = ASTBuilder::new(self.cfg().copy());
let ast = ast_builder.build(src).map_err(|errs| {
IncompleteArtifact::new(None, CompileErrors::from(errs), CompileErrors::empty())
})?;
self.check(ast, mode)
}
Trait Implementations§
source§impl<Inner: Debug> Debug for IncompleteArtifact<Inner>
impl<Inner: Debug> Debug for IncompleteArtifact<Inner>
source§impl Display for IncompleteArtifact
impl Display for IncompleteArtifact
source§impl Error for IncompleteArtifact
impl Error for IncompleteArtifact
1.30.0 · source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
source§impl From<IncompleteArtifact<HIR>> for ErrorArtifact
impl From<IncompleteArtifact<HIR>> for ErrorArtifact
source§fn from(artifact: IncompleteArtifact) -> Self
fn from(artifact: IncompleteArtifact) -> Self
Converts to this type from the input type.