Skip to content

Commit

Permalink
Merge pull request #7179 from JRI98/unused_emptytuple
Browse files Browse the repository at this point in the history
Remove unused EmptyTuple variant from FlatType enum
  • Loading branch information
ayazhafiz authored Oct 25, 2024
2 parents 06996d8 + edd0bb5 commit e1183e5
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 111 deletions.
2 changes: 1 addition & 1 deletion crates/compiler/can/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ fn deep_copy_type_vars<C: CopyEnv>(

// Everything else is a mechanical descent.
Structure(flat_type) => match flat_type {
EmptyRecord | EmptyTuple | EmptyTagUnion => Structure(flat_type),
EmptyRecord | EmptyTagUnion => Structure(flat_type),
Apply(symbol, arguments) => {
descend_slice!(arguments);

Expand Down
3 changes: 0 additions & 3 deletions crates/compiler/can/src/exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ fn index_var(
};
return Ok(std::iter::repeat(Variable::NULL).take(num_fields).collect());
}
FlatType::EmptyTuple => {
return Ok(std::iter::repeat(Variable::NULL).take(0).collect());
}
FlatType::EmptyTagUnion => {
internal_error!("empty tag unions are not indexable")
}
Expand Down
14 changes: 0 additions & 14 deletions crates/compiler/checkmate/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,20 +496,6 @@
}
}
},
{
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"EmptyTuple"
]
}
}
},
{
"type": "object",
"required": [
Expand Down
1 change: 0 additions & 1 deletion crates/compiler/checkmate/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ impl AsSchema<Content> for subs::FlatType {
ext.as_schema(subs),
),
subs::FlatType::EmptyRecord => Content::EmptyRecord(),
subs::FlatType::EmptyTuple => Content::EmptyTuple(),
subs::FlatType::EmptyTagUnion => Content::EmptyTagUnion(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,6 @@ export default function DrawHeadConstructor({
case "EmptyRecord": {
return <>{"{}"}</>;
}
case "EmptyTuple": {
return <>()</>;
}
case "EmptyTagUnion": {
return <>[]</>;
}
Expand Down
2 changes: 0 additions & 2 deletions crates/compiler/checkmate/www/src/components/Content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ export function contentStyles(desc: TypeDescriptor | undefined): ContentStyles {
return { name: "ℕ", bg: "bg-lime-400" };
case "EmptyRecord":
return { name: "{}", bg: "bg-purple-400" };
case "EmptyTuple":
return { name: "()", bg: "bg-deep-purple-400" };
case "EmptyTagUnion":
return { name: "[]", bg: "bg-cyan-200" };
case "Error":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ function VariableNodeContent(
return {};
}
case "EmptyRecord":
case "EmptyTuple":
case "EmptyTagUnion":
case "Error": {
return {};
Expand Down
4 changes: 0 additions & 4 deletions crates/compiler/checkmate/www/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ export type Content =
type: "EmptyRecord";
[k: string]: unknown;
}
| {
type: "EmptyTuple";
[k: string]: unknown;
}
| {
type: "EmptyTagUnion";
[k: string]: unknown;
Expand Down
1 change: 0 additions & 1 deletion crates/compiler/checkmate_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ impl_content! {
extension: TagUnionExtension,
},
EmptyRecord {},
EmptyTuple {},
EmptyTagUnion {},
RangedNumber {
range: NumericRange,
Expand Down
5 changes: 1 addition & 4 deletions crates/compiler/derive_key/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ impl FlatDecodable {
FlatType::Tuple(elems, ext) => {
let (elems_iter, ext) = elems.sorted_iterator_and_ext(subs, ext);

check_derivable_ext_var(subs, ext, |ext| {
matches!(ext, Content::Structure(FlatType::EmptyTuple))
})?;
check_derivable_ext_var(subs, ext, |_| false)?;

Ok(Key(FlatDecodableKey::Tuple(elems_iter.count() as _)))
}
Expand All @@ -79,7 +77,6 @@ impl FlatDecodable {
Err(Underivable) // yet
}
FlatType::EmptyRecord => Ok(Key(FlatDecodableKey::Record(vec![]))),
FlatType::EmptyTuple => todo!(),
FlatType::EmptyTagUnion => {
Err(Underivable) // yet
}
Expand Down
5 changes: 1 addition & 4 deletions crates/compiler/derive_key/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ impl FlatEncodable {
let (elems_iter, ext) = elems.sorted_iterator_and_ext(subs, ext);

// TODO someday we can put #[cfg(debug_assertions)] around this, but for now let's always do it.
check_derivable_ext_var(subs, ext, |ext| {
matches!(ext, Content::Structure(FlatType::EmptyTuple))
})?;
check_derivable_ext_var(subs, ext, |_| false)?;

Ok(Key(FlatEncodableKey::Tuple(elems_iter.count() as _)))
}
Expand Down Expand Up @@ -120,7 +118,6 @@ impl FlatEncodable {
FlatType::EmptyRecord => Ok(Key(FlatEncodableKey::Record(vec![]))),
FlatType::EmptyTagUnion => Ok(Key(FlatEncodableKey::TagUnion(vec![]))),
FlatType::Func(..) => Err(Underivable),
FlatType::EmptyTuple => unreachable!("Somehow Encoding derivation got an expression that's an empty tuple, which shouldn't be possible!"),
},
Content::Alias(sym, _, real_var, _) => match from_builtin_symbol(sym) {
Some(lambda) => lambda,
Expand Down
5 changes: 1 addition & 4 deletions crates/compiler/derive_key/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ impl FlatHash {
FlatType::Tuple(elems, ext) => {
let (elems_iter, ext) = elems.sorted_iterator_and_ext(subs, ext);

check_derivable_ext_var(subs, ext, |ext| {
matches!(ext, Content::Structure(FlatType::EmptyTuple))
})?;
check_derivable_ext_var(subs, ext, |_| false)?;

Ok(Key(FlatHashKey::Tuple(elems_iter.count() as _)))
}
Expand Down Expand Up @@ -112,7 +110,6 @@ impl FlatHash {
.collect(),
))),
FlatType::EmptyRecord => Ok(Key(FlatHashKey::Record(vec![]))),
FlatType::EmptyTuple => todo!(),
FlatType::EmptyTagUnion => Ok(Key(FlatHashKey::TagUnion(vec![]))),
//
FlatType::Func(..) => Err(Underivable),
Expand Down
28 changes: 13 additions & 15 deletions crates/compiler/derive_key/src/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ impl FlatInspectable {
let (elems_iter, ext) = elems.sorted_iterator_and_ext(subs, ext);

// TODO someday we can put #[cfg(debug_assertions)] around this, but for now let's always do it.
check_derivable_ext_var(subs, ext, |ext| {
matches!(ext, Content::Structure(FlatType::EmptyTuple))
check_derivable_ext_var(subs, ext, |_| {
false
}).expect("Compiler error: unexpected nonempty ext var when deriving Inspect for tuple");

Key(FlatInspectableKey::Tuple(elems_iter.count() as _))
Expand Down Expand Up @@ -128,26 +128,24 @@ impl FlatInspectable {
}
FlatType::EmptyRecord => Key(FlatInspectableKey::Record(Vec::new())),
FlatType::EmptyTagUnion => Key(FlatInspectableKey::TagUnion(Vec::new())),
FlatType::Func(..) => {
Immediate(Symbol::INSPECT_FUNCTION)
}
FlatType::EmptyTuple => unreachable!("Somehow Inspect derivation got an expression that's an empty tuple, which shouldn't be possible!"),
FlatType::Func(..) => Immediate(Symbol::INSPECT_FUNCTION),
},
Content::Alias(sym, _, real_var, kind) => match Self::from_builtin_alias(sym) {
Some(lambda) => lambda,

_ => {
match kind {
AliasKind::Structural => {
Self::from_var(subs, real_var)
}
AliasKind::Structural => Self::from_var(subs, real_var),
// Special case, an unbound `Frac *` will become a `Dec`.
AliasKind::Opaque if matches!(*subs.get_content_without_compacting(real_var), Content::FlexVar(_) | Content::FlexAbleVar(_, _)) => {
AliasKind::Opaque
if matches!(
*subs.get_content_without_compacting(real_var),
Content::FlexVar(_) | Content::FlexAbleVar(_, _)
) =>
{
Immediate(Symbol::INSPECT_DEC)
}
AliasKind::Opaque if sym.is_builtin() => {
Self::from_var(subs, real_var)
}
AliasKind::Opaque if sym.is_builtin() => Self::from_var(subs, real_var),
AliasKind::Opaque => {
// There are two cases in which `Inspect` can be derived for an opaque
// type.
Expand All @@ -169,7 +167,6 @@ impl FlatInspectable {
}
}
}

},
Content::RangedNumber(range) => {
Self::from_var(subs, range.default_compilation_variable())
Expand All @@ -180,7 +177,8 @@ impl FlatInspectable {
| Content::RigidVar(_)
| Content::FlexAbleVar(_, _)
| Content::RigidAbleVar(_, _)
| Content::LambdaSet(_) | Content::ErasedLambda => {
| Content::LambdaSet(_)
| Content::ErasedLambda => {
unreachable!("There must have been a bug in the solver, because we're trying to derive Inspect on a non-concrete type.");
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/compiler/mono/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10149,7 +10149,6 @@ fn find_lambda_sets_help(
}
}
FlatType::EmptyRecord => {}
FlatType::EmptyTuple => {}
FlatType::EmptyTagUnion => {}
},
Content::Alias(_, _, actual, _) => {
Expand Down
3 changes: 1 addition & 2 deletions crates/compiler/mono/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ fn lambda_set_size(subs: &Subs, var: Variable) -> (usize, usize, usize) {
}
stack.push((ext.var(), depth_any + 1, depth_lset));
}
FlatType::EmptyRecord | FlatType::EmptyTuple | FlatType::EmptyTagUnion => {}
FlatType::EmptyRecord | FlatType::EmptyTagUnion => {}
},
Content::FlexVar(_)
| Content::RigidVar(_)
Expand Down Expand Up @@ -3459,7 +3459,6 @@ fn layout_from_flat_type<'a>(
}
EmptyTagUnion => cacheable(Ok(Layout::VOID)),
EmptyRecord => cacheable(Ok(Layout::UNIT)),
EmptyTuple => cacheable(Ok(Layout::UNIT)),
}
}

Expand Down
9 changes: 0 additions & 9 deletions crates/compiler/solve/src/ability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,6 @@ trait DerivableVisitor {
})
}

#[inline(always)]
fn visit_empty_tuple(var: Variable) -> Result<(), NotDerivable> {
Err(NotDerivable {
var,
context: NotDerivableContext::NoContext,
})
}

#[inline(always)]
fn visit_empty_tag_union(var: Variable) -> Result<(), NotDerivable> {
Err(NotDerivable {
Expand Down Expand Up @@ -786,7 +778,6 @@ trait DerivableVisitor {
}
}
EmptyRecord => Self::visit_empty_record(var)?,
EmptyTuple => Self::visit_empty_tuple(var)?,
EmptyTagUnion => Self::visit_empty_tag_union(var)?,
},
Alias(
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/solve/src/deep_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn deep_copy_var_help(
Func(new_arguments, new_closure_var, new_ret_var)
}

same @ EmptyRecord | same @ EmptyTuple | same @ EmptyTagUnion => same,
same @ EmptyRecord | same @ EmptyTagUnion => same,

Record(fields, ext_var) => {
let record_fields = {
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/solve/src/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,7 @@ fn adjust_rank_content(
rank
}

EmptyRecord | EmptyTuple => {
EmptyRecord => {
// from elm-compiler: THEORY: an empty record never needs to get generalized
//
// But for us, that theory does not hold, because there might be type variables hidden
Expand Down
29 changes: 7 additions & 22 deletions crates/compiler/types/src/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ pub static WILDCARD: &str = "*";
static EMPTY_RECORD: &str = "{}";
static EMPTY_TAG_UNION: &str = "[]";

// TODO: since we technically don't support empty tuples at the source level, this should probably be removed
static EMPTY_TUPLE: &str = "()";

/// Requirements for parentheses.
///
/// If we're inside a function (that is, this is either an argument or a return
Expand Down Expand Up @@ -402,11 +399,7 @@ fn find_names_needed(
find_under_alias,
);
}
Error
| Structure(EmptyRecord)
| Structure(EmptyTuple)
| Structure(EmptyTagUnion)
| ErasedLambda => {
Error | Structure(EmptyRecord) | Structure(EmptyTagUnion) | ErasedLambda => {
// Errors and empty records don't need names.
}
}
Expand Down Expand Up @@ -1113,7 +1106,6 @@ fn write_flat_type<'a>(
pol,
),
EmptyRecord => buf.push_str(EMPTY_RECORD),
EmptyTuple => buf.push_str(EMPTY_TUPLE),
EmptyTagUnion => buf.push_str(EMPTY_TAG_UNION),
Func(args, closure, ret) => write_fn(
env,
Expand Down Expand Up @@ -1220,19 +1212,12 @@ fn write_flat_type<'a>(

buf.push_str(" )");

match subs.get_content_without_compacting(ext_var) {
Content::Structure(EmptyTuple) => {
// This is a closed tuple. We're done!
}
_ => {
// This is an open tuple, so print the variable
// right after the ')'
//
// e.g. the "*" at the end of `( I64, I64 )*`
// or the "r" at the end of `( I64, I64 )r`
write_content(env, ctx, ext_var, subs, buf, parens, pol)
}
}
// This is an open tuple, so print the variable
// right after the ')'
//
// e.g. the "*" at the end of `( I64, I64 )*`
// or the "r" at the end of `( I64, I64 )r`
write_content(env, ctx, ext_var, subs, buf, parens, pol)
}
TagUnion(tags, ext_var) => {
buf.push('[');
Expand Down
Loading

0 comments on commit e1183e5

Please sign in to comment.