diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 280dd2a510..acc0da68b6 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -454,7 +454,7 @@ fn can_annotation_help( None => Type::EmptyTagUnion, } } else { - let tag_types = can_tags( + let mut tag_types = can_tags( env, tags.items, region, @@ -465,6 +465,11 @@ fn can_annotation_help( references, ); + // sort here; we later instantiate type aliases, so this type might get duplicated + // many times. Then, when inserting into the subs, the tags are sorted. + // in theory we save a lot of time by sorting once here + tag_types.sort_by(|a, b| a.0.cmp(&b.0)); + Type::TagUnion(tag_types, Box::new(ext_type)) } } diff --git a/compiler/solve/src/solve.rs b/compiler/solve/src/solve.rs index 68185f1551..c4a4eb98dc 100644 --- a/compiler/solve/src/solve.rs +++ b/compiler/solve/src/solve.rs @@ -1004,7 +1004,7 @@ fn type_to_union_tags<'a>( for (tag, tag_argument_types) in tags { let new_slice = VariableSubsSlice::reserve_into_subs(subs, tag_argument_types.len()); - for (i, arg) in (new_slice.slice.start as usize..).zip(tag_argument_types) { + for (i, arg) in (new_slice.indices()).zip(tag_argument_types) { let var = type_to_variable(subs, rank, pools, arena, arg); subs.variables[i] = var; }