Constants

This commit is contained in:
Ayaz Hafiz 2022-04-22 16:16:21 -04:00
parent fe8eb38d89
commit 03deec23c3
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 8 additions and 16 deletions

View file

@ -10,6 +10,9 @@ use roc_types::types::AliasKind;
pub use roc_exhaustive::Context as ExhaustiveContext;
pub const GUARD_CTOR: &'static str = "#Guard";
pub const NONEXHAUSIVE_CTOR: &'static str = "#Open";
pub fn check(
subs: &Subs,
sketched_rows: SketchedRows,
@ -215,7 +218,7 @@ pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch]
render_as: RenderAs::Guard,
alternatives: vec![Ctor {
tag_id,
name: TagName::Global("#Guard".into()),
name: TagName::Global(GUARD_CTOR.into()),
arity: 2,
}],
};
@ -298,7 +301,7 @@ fn convert_tag(subs: &Subs, whole_var: Variable, this_tag: &TagName) -> (Union,
// be matched unless there's an `Anything` pattern.
let opt_openness_tag = match subs.get_content_without_compacting(ext) {
FlexVar(_) | RigidVar(_) => {
let openness_tag = TagName::Global("#Open".into());
let openness_tag = TagName::Global(NONEXHAUSIVE_CTOR.into());
num_tags += 1;
Some((openness_tag, &[] as _))
}

View file

@ -2118,18 +2118,6 @@ impl Content {
self
}
pub fn unroll_structural_alias<'a>(&'a self, subs: &'a Subs) -> &'a Self {
let mut result = self;
loop {
match result {
Self::Alias(_, _, real_var, AliasKind::Structural) => {
result = subs.get_content_without_compacting(*real_var)
}
_ => return result,
}
}
}
}
#[derive(Clone, Copy, Debug)]

View file

@ -3632,6 +3632,7 @@ fn pattern_to_doc_help<'b>(
pattern: roc_exhaustive::Pattern,
in_type_param: bool,
) -> RocDocBuilder<'b> {
use roc_can::exhaustive::{GUARD_CTOR, NONEXHAUSIVE_CTOR};
use roc_exhaustive::Literal::*;
use roc_exhaustive::Pattern::*;
use roc_exhaustive::RenderAs;
@ -3654,7 +3655,7 @@ fn pattern_to_doc_help<'b>(
// #Guard <fake-condition-tag> <unexhausted-pattern>
debug_assert_eq!(
union.alternatives[tag_id.0 as usize].name,
TagName::Global("#Guard".into())
TagName::Global(GUARD_CTOR.into())
);
debug_assert!(args.len() == 2);
let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param);
@ -3693,7 +3694,7 @@ fn pattern_to_doc_help<'b>(
RenderAs::Tag | RenderAs::Opaque => {
let tag = &union.alternatives[tag_id.0 as usize];
match &tag.name {
TagName::Global(name) if name.as_str() == "#Open" => {
TagName::Global(name) if name.as_str() == NONEXHAUSIVE_CTOR => {
return pattern_to_doc_help(
alloc,
roc_exhaustive::Pattern::Anything,