dev: shrink size of tag types (#686)

* dev: shrink size of tag types

* update: testing
This commit is contained in:
Myriad-Dreamin 2024-10-16 14:32:17 +08:00 committed by GitHub
parent b9da92175e
commit 1f5be314a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 7 deletions

View file

@ -326,7 +326,10 @@ impl<'a, 'w> DocsChecker<'a, 'w> {
return None;
};
let pkg_id = PackageId::try_from(self.fid).ok();
Ty::Builtin(BuiltinTy::Tag(s.get().into(), pkg_id.map(From::from)))
Ty::Builtin(BuiltinTy::Tag(Box::new((
s.get().into(),
pkg_id.map(From::from),
))))
}),
_ => None,
}

View file

@ -223,7 +223,7 @@ pub enum BuiltinTy {
Outset,
Radius,
Tag(StrRef, Option<Interned<PackageId>>),
Tag(Box<(StrRef, Option<Interned<PackageId>>)>),
Type(typst::foundations::Type),
Element(typst::foundations::Element),
Path(PathPreference),
@ -259,11 +259,12 @@ impl fmt::Debug for BuiltinTy {
BuiltinTy::Radius => write!(f, "Radius"),
BuiltinTy::Type(ty) => write!(f, "Type({})", ty.long_name()),
BuiltinTy::Element(e) => e.fmt(f),
BuiltinTy::Tag(tag, id) => {
BuiltinTy::Tag(tag) => {
let (name, id) = tag.as_ref();
if let Some(id) = id {
write!(f, "Tag({tag:?}) of {id:?}")
write!(f, "Tag({name:?}) of {id:?}")
} else {
write!(f, "Tag({tag:?})")
write!(f, "Tag({name:?})")
}
}
BuiltinTy::Path(p) => write!(f, "Path({p:?})"),
@ -335,12 +336,13 @@ impl BuiltinTy {
BuiltinTy::Radius => "radius",
BuiltinTy::Type(ty) => ty.short_name(),
BuiltinTy::Element(ty) => ty.name(),
BuiltinTy::Tag(name, id) => {
BuiltinTy::Tag(tag) => {
let (name, id) = tag.as_ref();
return if let Some(id) = id {
format!("tag {name} of {id:?}")
} else {
format!("tag {name}")
}
};
}
BuiltinTy::Path(s) => match s {
PathPreference::None => "[any]",

View file

@ -1161,6 +1161,13 @@ mod tests {
use insta::{assert_debug_snapshot, assert_snapshot};
use crate::ty::tests::*;
#[test]
fn test_ty_size() {
use super::*;
assert!(size_of::<Ty>() == 16);
}
#[test]
fn test_ty() {
use super::*;