/
githubmirror
/
sway
Обзор
Документация
Войти
/
githubmirror
/
sway
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
sway-core/src/language/ty/code_block.rs
103 строки
3 KB
Igor Rončević
Use `HasChanges` to propagate information about in-place mutations (#7662)
20 июн 2026, 13:06
Не верифицирован
20 июн 2026, 13:06
088068c
Код
Авторство
О чём код?
use crate::{ decl_engine::*, engine_threading::*, language::ty::*, semantic_analysis::TypeCheckContext, transform::AllowDeprecatedState, type_system::*, HasChanges, }; use serde::{Deserialize, Serialize}; use std::hash::Hasher; use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::Span; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyCodeBlock { pub contents: Vec<TyAstNode>, pub(crate) whole_block_span: Span, } impl TyCodeBlock { pub(crate) fn check_deprecated( &self, engines: &Engines, handler: &Handler, allow_deprecated: &mut AllowDeprecatedState, ) { for n in self.contents.iter() { n.check_deprecated(engines, handler, allow_deprecated); } } } impl Default for TyCodeBlock { fn default() -> Self { Self { contents: Default::default(), whole_block_span: Span::dummy(), } } } impl EqWithEngines for TyCodeBlock {} impl PartialEqWithEngines for TyCodeBlock { fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool { self.contents.eq(&other.contents, ctx) } } impl HashWithEngines for TyCodeBlock { fn hash<H: Hasher>(&self, state: &mut H, engines: &Engines) { let TyCodeBlock { contents, .. } = self; contents.hash(state, engines); } } impl SubstTypes for TyCodeBlock { fn subst_inner(&mut self, ctx: &SubstTypesContext) -> HasChanges { self.contents.subst(ctx) } } impl ReplaceDecls for TyCodeBlock { fn replace_decls_inner( &mut self, decl_mapping: &DeclMapping, handler: &Handler, ctx: &mut TypeCheckContext, ) -> Result<HasChanges, ErrorEmitted> { handler.scope(|handler| { let mut has_changes = HasChanges::No; for node in self.contents.iter_mut() { if let Ok(r) = node.replace_decls(decl_mapping, handler, ctx) { has_changes |= r; } } Ok(has_changes) }) } } impl UpdateConstantExpression for TyCodeBlock { fn update_constant_expression( &mut self, engines: &Engines, implementing_type: &TyDecl, ) -> HasChanges { self.contents.iter_mut().fold(HasChanges::No, |acc, x| { acc | x.update_constant_expression(engines, implementing_type) }) } } impl MaterializeConstGenerics for TyCodeBlock { fn materialize_const_generics( &mut self, engines: &Engines, handler: &Handler, name: &str, value: &TyExpression, ) -> Result<HasChanges, ErrorEmitted> { let mut has_changes = HasChanges::No; for x in self.contents.iter_mut() { has_changes |= x.materialize_const_generics(engines, handler, name, value)?; } Ok(has_changes) } }