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

parser+source: improvements and cleanups #934

Merged
merged 15 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
77 changes: 66 additions & 11 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions compiler/hash-ast-expand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ edition = "2021"
doctest = false

[dependencies]
derive_more = "0.99"

hash-ast = { path = "../hash-ast" }
hash-attrs = { path = "../hash-attrs" }
hash-fmt = { path = "../hash-fmt" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/hash-ast-expand/src/diagnostics/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Definitions of the various kinds of errors that can occur during the
//! expansion phase of the compiler.
use derive_more::Constructor;
use hash_ast::ast::AstNodeId;
use hash_attrs::{
attr::{AttrArgIdx, AttrValueKind},
Expand All @@ -14,6 +13,7 @@ use hash_reporting::{
};
use hash_source::identifier::Identifier;
use hash_tir::{tys::TyId, utils::params::ParamError};
use hash_utils::derive_more::Constructor;

#[derive(Constructor, Debug)]
pub struct ExpansionError {
Expand Down
2 changes: 1 addition & 1 deletion compiler/hash-ast-expand/src/diagnostics/warning.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Compiler warnings that are emitted during AST expansion.

use derive_more::{Constructor, From};
use hash_ast::ast::AstNodeId;
use hash_attrs::diagnostics::AttrWarning;
use hash_reporting::reporter::{Reporter, Reports};
use hash_utils::derive_more::{Constructor, From};

#[derive(Constructor, Debug)]
pub struct ExpansionWarning {
Expand Down
1 change: 0 additions & 1 deletion compiler/hash-attrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ edition = "2021"
doctest = false

[dependencies]
derive_more = "0.99"
paste = "1.0.14"

hash-ast = { path = "../hash-ast" }
Expand Down
3 changes: 1 addition & 2 deletions compiler/hash-attrs/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::{fmt, sync::OnceLock};

use derive_more::From;
use hash_ast::{ast, ast::AstNodeId};
use hash_source::{
constant::{InternedFloat, InternedInt, InternedStr},
Expand All @@ -11,7 +10,7 @@ use hash_source::{
use hash_storage::store::{DefaultPartialStore, PartialStore};
use hash_target::{abi::Integer, data_layout::HasDataLayout, primitives::IntTy};
use hash_tir::params::ParamIndex;
use hash_utils::{fxhash::FxHashMap, lazy_static::lazy_static};
use hash_utils::{derive_more::From, fxhash::FxHashMap, lazy_static::lazy_static};

use crate::{
diagnostics::{AttrError, AttrResult},
Expand Down
10 changes: 4 additions & 6 deletions compiler/hash-codegen-llvm/src/translation/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use hash_codegen::{
traits::{constants::ConstValueBuilderMethods, layout::LayoutMethods, ty::TypeBuilderMethods},
};
use hash_ir::{ir::Const, ty::COMMON_IR_TYS};
use hash_source::constant::{InternedStr, CONSTANT_MAP};
use hash_source::constant::InternedStr;
use inkwell::{module::Linkage, types::BasicTypeEnum, values::AnyValueEnum};

use super::ty::ExtendedTyBuilderMethods;
Expand Down Expand Up @@ -143,8 +143,8 @@ impl<'b, 'm> ConstValueBuilderMethods<'b> for CodeGenCtx<'b, 'm> {
Const::Zero(_) => unreachable!("`const_scalar_value` should not be called on a ZST"),
Const::Bool(val) => self.const_bool(val),
Const::Char(ch) => self.const_u32(ch as u32),
Const::Int(interned_int) => {
let const_int = CONSTANT_MAP.lookup_int(interned_int);
Const::Int(int) => {
let const_int = int.value();

// Convert the constant into a u128 and then emit the
// correct LLVM constant for it.
Expand All @@ -157,9 +157,7 @@ impl<'b, 'm> ConstValueBuilderMethods<'b> for CodeGenCtx<'b, 'm> {
unimplemented!()
})
}
Const::Float(interned_float) => {
self.const_float(ty, CONSTANT_MAP.lookup_float(interned_float).as_f64())
}
Const::Float(interned_float) => self.const_float(ty, interned_float.value().as_f64()),
Const::Str(str) => self.const_str(str).0,
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/hash-codegen/src/lower/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use hash_abi::{ArgAbi, FnAbiId, PassMode};
use hash_ir::{intrinsics::Intrinsic, ir, lang_items::LangItem, ty::COMMON_IR_TYS};
use hash_pipeline::settings::{CodeGenBackend, OptimisationLevel};
use hash_source::constant::CONSTANT_MAP;
use hash_storage::store::{statics::StoreId, Store};
use hash_target::abi::{AbiRepresentation, ValidScalarRange};

Expand Down Expand Up @@ -577,7 +576,7 @@ impl<'a, 'b, Builder: BlockBuilderMethods<'a, 'b>> FnBuilder<'a, 'b, Builder> {
builder.switch_to_block(failure_block);

// we need to convert the assert into a message.
let (bytes, len) = builder.const_str(CONSTANT_MAP.create_string(assert_kind.message()));
let (bytes, len) = builder.const_str(assert_kind.message().into());
let args: [Builder::Value; 2] = (bytes, len).into();

// Get the `panic` lang item.
Expand Down
2 changes: 1 addition & 1 deletion compiler/hash-driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<I: CompilerInterface> Driver<I> {
}

// Print compiler stage metrics if specified in the settings.
if self.compiler.settings().output_metrics && !self.bootstrapping {
if self.compiler.settings().show_timings && !self.bootstrapping {
self.report_metrics();
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/hash-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl CompilerBuilder {
Self::build(
interface,
vec![
Box::new(Parser),
Box::<Parser>::default(),
Box::new(AstExpansionPass),
Box::new(AstDesugaringPass),
Box::new(UntypedSemanticAnalysis),
Expand Down
4 changes: 2 additions & 2 deletions compiler/hash-exhaustiveness/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! to represent literals, and convert them into a `ConstantValue` which is
//! used within the exhaustiveness sub-system to represent these values within
//! a single data type.
use hash_source::constant::{InternedInt, CONSTANT_MAP};
use hash_source::constant::InternedInt;
use hash_tir::tys::TyId;

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -31,7 +31,7 @@ impl Constant {
pub fn from_int(constant: InternedInt, ty: TyId) -> Self {
// Get the associated bytes with the interned-int so we can convert
// into a constant.
let data = CONSTANT_MAP.lookup_int(constant).value.as_u128().unwrap();
let data = constant.value().value.as_u128().unwrap();
Constant { data, ty }
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/hash-fmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use hash_ast::{
ast::{self, walk_mut_self, AstVisitorMutSelf, ParamOrigin},
ast_visitor_mut_self_default_impl,
};
use hash_source::constant::{IntConstant, CONSTANT_MAP};
use hash_source::constant::IntConstant;
use hash_token::delimiter::Delimiter;
use state::AstPrinterState;

Expand Down Expand Up @@ -701,7 +701,7 @@ where
&mut self,
node: ast::AstNodeRef<ast::IntLit>,
) -> Result<Self::IntLitRet, Self::Error> {
CONSTANT_MAP.map_int(node.body.value, |value| {
node.body.value.map(|value| {
let IntConstant { value, suffix } = value;

self.write(format!("{}", value))?;
Expand Down
1 change: 0 additions & 1 deletion compiler/hash-intrinsics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ edition = "2021"
doctest = false

[dependencies]
derive_more = "0.99"
num-bigint = "0.4"
num_enum = "0.5"

Expand Down
9 changes: 5 additions & 4 deletions compiler/hash-intrinsics/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use hash_ast::ast::{self};
use hash_source::constant::{
FloatTy, IntConstant, IntConstantValue, IntTy, SIntTy, UIntTy, CONSTANT_MAP,
FloatConstant, FloatConstantValue, FloatTy, IntConstant, IntConstantValue, IntTy, InternedInt,
SIntTy, UIntTy,
};
use hash_storage::store::statics::{SequenceStoreValue, SingleStoreValue, StoreId};
use hash_tir::{
Expand Down Expand Up @@ -227,11 +228,11 @@ pub trait PrimitiveUtils: AccessToEnv {
}

/// Get the given term as a float literal if possible.
fn create_term_from_float_lit<L: Into<f64>>(&self, lit: L) -> TermId {
fn create_term_from_float_lit<L: Into<FloatConstantValue>>(&self, lit: L) -> TermId {
Term::create(Term::Lit(Lit::Float(FloatLit {
underlying: ast::FloatLit {
kind: ast::FloatLitKind::Unsuffixed,
value: CONSTANT_MAP.create_f64_float(lit.into(), None),
value: FloatConstant::new(lit.into(), None).into(),
},
})))
}
Expand All @@ -249,7 +250,7 @@ pub trait PrimitiveUtils: AccessToEnv {
Term::create(Term::Lit(Lit::Int(IntLit {
underlying: ast::IntLit {
kind: ast::IntLitKind::Unsuffixed,
value: CONSTANT_MAP.create_int(IntConstant::new(
value: InternedInt::create(IntConstant::new(
IntConstantValue::Big(Box::new(lit.into())),
None,
)),
Expand Down
Loading
Loading