Skip to content

Commit

Permalink
Use GlobalReference for named constants in WireReference too
Browse files Browse the repository at this point in the history
This finally concludes the shift to HM for abstract typing
  • Loading branch information
VonTum committed Nov 5, 2024
1 parent 10e4d0b commit 96a50c3
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/dev_aid/lsp/tree_walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl<'linker, Visitor: FnMut(Span, LocationInfo<'linker>), Pruner: Fn(Span) -> b
);
}
WireReferenceRoot::NamedConstant(cst, span) => {
self.visit(*span, LocationInfo::Global(NameElem::Constant(*cst)))
self.visit(*span, LocationInfo::Global(NameElem::Constant(cst.id)))
}
WireReferenceRoot::SubModulePort(port) => {
if let Some(span) = port.port_name_span {
Expand Down
2 changes: 1 addition & 1 deletion src/flattening/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ impl<'l, 'errs> FlatteningContext<'l, 'errs> {
}
},
LocalOrGlobal::Constant(cst_ref) => {
let root = WireReferenceRoot::NamedConstant(cst_ref.id, expr_span); // TODO Constants with templates
let root = WireReferenceRoot::NamedConstant(cst_ref, expr_span);
PartialWireReference::WireReference(WireReference {
root,
is_generative: true,
Expand Down
4 changes: 2 additions & 2 deletions src/flattening/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ impl WireReferencePathElement {
}


#[derive(Debug, Clone, Copy)]
#[derive(Debug)]
pub enum WireReferenceRoot {
LocalDecl(FlatID, Span),
NamedConstant(ConstantUUID, Span),
NamedConstant(GlobalReference<ConstantUUID>, Span),
SubModulePort(PortInfo),
}

Expand Down
12 changes: 9 additions & 3 deletions src/flattening/typechecking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'l, 'errs> TypeCheckingContext<'l, 'errs> {
(decl_root.decl_span, self.errors.file)
}
WireReferenceRoot::NamedConstant(cst, _) => {
let linker_cst = &self.globals[*cst];
let linker_cst = &self.globals[cst.id];
linker_cst.link_info.get_span_file()
}
WireReferenceRoot::SubModulePort(port) => {
Expand Down Expand Up @@ -143,8 +143,14 @@ impl<'l, 'errs> TypeCheckingContext<'l, 'errs> {
decl_root.typ.clone()
}
WireReferenceRoot::NamedConstant(cst, _) => {
let linker_cst = &self.globals[*cst];
linker_cst.get_full_type()
let linker_cst = &self.globals[cst.id];
let decl = linker_cst.link_info.instructions[linker_cst.output_decl].unwrap_wire_declaration();
let typ = AbstractType::Unknown(self.type_checker.alloc_typ_variable());
self.type_checker.unify_with_written_type_substitute_templates_must_succeed(&decl.typ_expr, &typ, &cst.template_arg_types);
FullType {
typ,
domain: DomainType::Generative
}
}
WireReferenceRoot::SubModulePort(port) => {
self.get_type_of_port(port.port, port.submodule_decl)
Expand Down
8 changes: 4 additions & 4 deletions src/instantiation/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ impl<'fl, 'l> InstantiationContext<'fl, 'l> {
SubModuleOrWire::SubModule(_) => unreachable!(),
SubModuleOrWire::Unnasigned => unreachable!(),
},
WireReferenceRoot::NamedConstant(cst_id, _) => {
let cst = &self.linker.constants[*cst_id];
WireReferenceRoot::NamedConstant(cst, _) => {
let cst = &self.linker.constants[cst.id];
RealWireRefRoot::Constant(cst.val.clone())
}
WireReferenceRoot::SubModulePort(port) => {
Expand Down Expand Up @@ -357,8 +357,8 @@ impl<'fl, 'l> InstantiationContext<'fl, 'l> {
&WireReferenceRoot::LocalDecl(decl_id, _span) => {
self.generation_state.get_generation_value(decl_id)?.clone()
}
WireReferenceRoot::NamedConstant(const_id, _span) => {
self.linker.constants[*const_id].get_value().clone()
WireReferenceRoot::NamedConstant(cst, _span) => {
self.linker.constants[cst.id].get_value().clone()
}
&WireReferenceRoot::SubModulePort(_) => {
todo!("Don't yet support compile time functions")
Expand Down
15 changes: 1 addition & 14 deletions src/linker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ use crate::errors::{CompileError, ErrorInfo, ErrorLevel, ErrorStore};

use crate::flattening::{StructType, TypingAllocator};

use crate::typing::{
abstract_type::{DomainType, FullType},
concrete_type::ConcreteType,
template::TemplateInputs,
};
use crate::typing::template::TemplateInputs;

use self::checkpoint::CheckPoint;

Expand Down Expand Up @@ -138,15 +134,6 @@ pub struct NamedConstant {
}

impl NamedConstant {
pub fn get_concrete_type(&self) -> &ConcreteType {
&self.val.typ
}
pub fn get_full_type(&self) -> FullType {
FullType {
typ: self.get_concrete_type().into(),
domain: DomainType::Generative,
}
}
pub fn get_value(&self) -> &TypedValue {
&self.val
}
Expand Down
1 change: 1 addition & 0 deletions src/typing/abstract_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl TypeUnifier {
self.type_substitutor.alloc()
}

#[allow(dead_code)]
pub fn alloc_domain_variable(&self) -> DomainVariableID {
self.domain_substitutor.alloc()
}
Expand Down
20 changes: 0 additions & 20 deletions src/typing/concrete_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::prelude::*;

use std::ops::{Deref, Index};

use super::abstract_type::AbstractType;
use super::type_inference::TypeVariableID;
use crate::linker::get_builtin_type;
use crate::{
flattening::{BinaryOperator, UnaryOperator},
Expand All @@ -23,24 +21,6 @@ pub enum ConcreteType {
Error,
}

impl Into<AbstractType> for &ConcreteType {
fn into(self) -> AbstractType {
match self {
ConcreteType::Named(name) => AbstractType::Named(*name),
ConcreteType::Value(_) => {
unreachable!("Turning a ConcreteType::Value into an AbstractType");
}
ConcreteType::Array(arr) => {
let (sub, _sz) = arr.deref();
let concrete_sub: AbstractType = sub.into();
AbstractType::Array(Box::new(concrete_sub))
}
ConcreteType::Unknown => AbstractType::Unknown(TypeVariableID::PLACEHOLDER),
ConcreteType::Error => AbstractType::Error,
}
}
}

/// Panics on Type Errors that should have been caught by [AbstractType]
///
/// TODO Add checks for array sizes being equal etc.
Expand Down

0 comments on commit 96a50c3

Please sign in to comment.