Remove other references to private tags in code

This commit is contained in:
Ayaz Hafiz 2022-04-25 11:50:00 -04:00
parent 2ab01107d3
commit 55706ae5c4
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
8 changed files with 32 additions and 99 deletions

View file

@ -70,10 +70,9 @@ xor : Bool, Bool -> Bool
## Structural equality works as follows: ## Structural equality works as follows:
## ##
## 1. Global tags are equal if they are the same tag, and also their contents (if any) are equal. ## 1. Global tags are equal if they are the same tag, and also their contents (if any) are equal.
## 2. Private tags are equal if they are the same tag, in the same module, and also their contents (if any) are equal. ## 2. Records are equal if all their fields are equal.
## 3. Records are equal if all their fields are equal. ## 3. Collections ([Str], [List], [Dict], and [Set]) are equal if they are the same length, and also all their corresponding elements are equal.
## 4. Collections ([Str], [List], [Dict], and [Set]) are equal if they are the same length, and also all their corresponding elements are equal. ## 4. [Num] values are equal if their numbers are equal, with one exception: if both arguments to `isEq` are *NaN*, then `isEq` returns `False`. See `Num.isNaN` for more about *NaN*.
## 5. [Num] values are equal if their numbers are equal, with one exception: if both arguments to `isEq` are *NaN*, then `isEq` returns `False`. See `Num.isNaN` for more about *NaN*.
## ##
## Note that `isEq` takes `'val` instead of `val`, which means `isEq` does not ## Note that `isEq` takes `'val` instead of `val`, which means `isEq` does not
## accept arguments whose types contain functions. ## accept arguments whose types contain functions.

View file

@ -7,7 +7,7 @@ use roc_region::all::{Loc, Region};
/// The canonicalization environment for a particular module. /// The canonicalization environment for a particular module.
pub struct Env<'a> { pub struct Env<'a> {
/// The module's path. Private tags and unqualified references to identifiers /// The module's path. Opaques and unqualified references to identifiers
/// are assumed to be relative to this path. /// are assumed to be relative to this path.
pub home: ModuleId, pub home: ModuleId,

View file

@ -1,7 +1,5 @@
use crate::docs::DocEntry::DetachedDoc; use crate::docs::DocEntry::DetachedDoc;
use crate::docs::TypeAnnotation::{ use crate::docs::TypeAnnotation::{Apply, BoundVariable, Function, NoTypeAnn, Record, TagUnion};
Apply, BoundVariable, Function, NoTypeAnn, ObscuredRecord, ObscuredTagUnion, Record, TagUnion,
};
use crate::file::LoadedModule; use crate::file::LoadedModule;
use roc_can::scope::Scope; use roc_can::scope::Scope;
use roc_error_macros::todo_abilities; use roc_error_macros::todo_abilities;
@ -274,36 +272,20 @@ fn type_to_docs(in_func_type_ann: bool, type_annotation: ast::TypeAnnotation) ->
ast::TypeAnnotation::TagUnion { tags, ext } => { ast::TypeAnnotation::TagUnion { tags, ext } => {
let mut tags_to_render: Vec<Tag> = Vec::new(); let mut tags_to_render: Vec<Tag> = Vec::new();
let mut any_tags_are_private = false;
for tag in tags.iter() { for tag in tags.iter() {
match tag_to_doc(in_func_type_ann, tag.value) { if let Some(tag_ann) = tag_to_doc(in_func_type_ann, tag.value) {
None => { tags_to_render.push(tag_ann);
any_tags_are_private = true;
break;
}
Some(tag_ann) => {
tags_to_render.push(tag_ann);
}
} }
} }
if any_tags_are_private { let extension = match ext {
if in_func_type_ann { None => NoTypeAnn,
ObscuredTagUnion Some(ext_type_ann) => type_to_docs(in_func_type_ann, ext_type_ann.value),
} else { };
NoTypeAnn
}
} else {
let extension = match ext {
None => NoTypeAnn,
Some(ext_type_ann) => type_to_docs(in_func_type_ann, ext_type_ann.value),
};
TagUnion { TagUnion {
tags: tags_to_render, tags: tags_to_render,
extension: Box::new(extension), extension: Box::new(extension),
}
} }
} }
ast::TypeAnnotation::BoundVariable(var_name) => BoundVariable(var_name.to_string()), ast::TypeAnnotation::BoundVariable(var_name) => BoundVariable(var_name.to_string()),
@ -328,35 +310,19 @@ fn type_to_docs(in_func_type_ann: bool, type_annotation: ast::TypeAnnotation) ->
ast::TypeAnnotation::Record { fields, ext } => { ast::TypeAnnotation::Record { fields, ext } => {
let mut doc_fields = Vec::new(); let mut doc_fields = Vec::new();
let mut any_fields_include_private_tags = false;
for field in fields.items { for field in fields.items {
match record_field_to_doc(in_func_type_ann, field.value) { if let Some(doc_field) = record_field_to_doc(in_func_type_ann, field.value) {
None => { doc_fields.push(doc_field);
any_fields_include_private_tags = true;
break;
}
Some(doc_field) => {
doc_fields.push(doc_field);
}
} }
} }
if any_fields_include_private_tags { let extension = match ext {
if in_func_type_ann { None => NoTypeAnn,
ObscuredRecord Some(ext_type_ann) => type_to_docs(in_func_type_ann, ext_type_ann.value),
} else { };
NoTypeAnn
}
} else {
let extension = match ext {
None => NoTypeAnn,
Some(ext_type_ann) => type_to_docs(in_func_type_ann, ext_type_ann.value),
};
Record { Record {
fields: doc_fields, fields: doc_fields,
extension: Box::new(extension), extension: Box::new(extension),
}
} }
} }
ast::TypeAnnotation::SpaceBefore(&sub_type_ann, _) => { ast::TypeAnnotation::SpaceBefore(&sub_type_ann, _) => {

View file

@ -392,7 +392,7 @@ pub struct Subs {
pub struct TagNameCache { pub struct TagNameCache {
globals: Vec<Uppercase>, globals: Vec<Uppercase>,
globals_slices: Vec<SubsSlice<TagName>>, globals_slices: Vec<SubsSlice<TagName>>,
/// Currently private tags and closure tags; in the future just closure tags /// Just closure tags
symbols: Vec<Symbol>, symbols: Vec<Symbol>,
symbols_slices: Vec<SubsSlice<TagName>>, symbols_slices: Vec<SubsSlice<TagName>>,
} }

View file

@ -70,8 +70,6 @@ pub enum Token {
Malformed, Malformed,
MalformedOperator, MalformedOperator,
PrivateTag,
String, String,
NumberBase, NumberBase,
@ -149,7 +147,6 @@ fn consume_all_tokens(state: &mut LexState, bytes: &[u8], consumer: &mut impl Co
b']' => (Token::CloseSquare, 1), b']' => (Token::CloseSquare, 1),
b',' => (Token::Comma, 1), b',' => (Token::Comma, 1),
b'_' => lex_underscore(bytes), b'_' => lex_underscore(bytes),
b'@' => lex_private_tag(bytes),
b'a'..=b'z' => lex_ident(false, bytes), b'a'..=b'z' => lex_ident(false, bytes),
b'A'..=b'Z' => lex_ident(true, bytes), b'A'..=b'Z' => lex_ident(true, bytes),
b'0'..=b'9' => lex_number(bytes), b'0'..=b'9' => lex_number(bytes),
@ -408,15 +405,6 @@ fn is_ident_continue(ch: u8) -> bool {
matches!(ch, b'a'..=b'z'|b'A'..=b'Z'|b'0'..=b'9'|b'_') matches!(ch, b'a'..=b'z'|b'A'..=b'Z'|b'0'..=b'9'|b'_')
} }
fn lex_private_tag(bytes: &[u8]) -> (Token, usize) {
debug_assert!(bytes[0] == b'@');
let mut i = 1;
while i < bytes.len() && is_ident_continue(bytes[i]) {
i += 1;
}
(Token::PrivateTag, i)
}
fn lex_ident(uppercase: bool, bytes: &[u8]) -> (Token, usize) { fn lex_ident(uppercase: bool, bytes: &[u8]) -> (Token, usize) {
let mut i = 0; let mut i = 0;
while i < bytes.len() && is_ident_continue(bytes[i]) { while i < bytes.len() && is_ident_continue(bytes[i]) {

View file

@ -72,10 +72,7 @@ mod test_peg_grammar {
rule tag() = rule tag() =
private_tag() [T::UppercaseIdent]
/ [T::UppercaseIdent]
rule private_tag() = [T::PrivateTag] {}
rule list() = empty_list() rule list() = empty_list()

View file

@ -1253,9 +1253,9 @@ fn pretty_runtime_error<'b>(
EmptySingleQuote | MultipleCharsInSingleQuote | Unknown | BadIdent(_) => { EmptySingleQuote | MultipleCharsInSingleQuote | Unknown | BadIdent(_) => {
alloc.nil() alloc.nil()
} }
QualifiedIdentifier => alloc.tip().append( QualifiedIdentifier => alloc
alloc.reflow("In patterns, only private and global tags can be qualified"), .tip()
), .append(alloc.reflow("In patterns, only global tags can be qualified")),
}; };
doc = alloc.stack([ doc = alloc.stack([

View file

@ -417,21 +417,6 @@ impl<'a> RocDocAllocator<'a> {
.annotate(Annotation::Symbol) .annotate(Annotation::Symbol)
} }
pub fn private_tag_name(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> {
if symbol.module_id() == self.home {
// Render it unqualified if it's in the current module.
self.text(format!("{}", symbol.ident_str(self.interns)))
.annotate(Annotation::PrivateTag)
} else {
self.text(format!(
"{}.{}",
symbol.module_string(self.interns),
symbol.ident_str(self.interns),
))
.annotate(Annotation::PrivateTag)
}
}
pub fn global_tag_name(&'a self, uppercase: Uppercase) -> DocBuilder<'a, Self, Annotation> { pub fn global_tag_name(&'a self, uppercase: Uppercase) -> DocBuilder<'a, Self, Annotation> {
self.text(format!("{}", uppercase)) self.text(format!("{}", uppercase))
.annotate(Annotation::GlobalTag) .annotate(Annotation::GlobalTag)
@ -807,7 +792,6 @@ pub enum Annotation {
Url, Url,
Keyword, Keyword,
GlobalTag, GlobalTag,
PrivateTag,
RecordField, RecordField,
TypeVariable, TypeVariable,
Alias, Alias,
@ -899,8 +883,7 @@ where
Url => { Url => {
self.write_str("<")?; self.write_str("<")?;
} }
GlobalTag | PrivateTag | Keyword | RecordField | Symbol | Typo | TypoSuggestion GlobalTag | Keyword | RecordField | Symbol | Typo | TypoSuggestion | TypeVariable
| TypeVariable
if !self.in_type_block && !self.in_code_block => if !self.in_type_block && !self.in_code_block =>
{ {
self.write_str("`")?; self.write_str("`")?;
@ -930,7 +913,7 @@ where
Url => { Url => {
self.write_str(">")?; self.write_str(">")?;
} }
GlobalTag | PrivateTag | Keyword | RecordField | Symbol | Typo | TypoSuggestion GlobalTag | Keyword | RecordField | Symbol | Typo | TypoSuggestion
| TypeVariable | TypeVariable
if !self.in_type_block && !self.in_code_block => if !self.in_type_block && !self.in_code_block =>
{ {
@ -1023,7 +1006,7 @@ where
ParserSuggestion => { ParserSuggestion => {
self.write_str(self.palette.parser_suggestion)?; self.write_str(self.palette.parser_suggestion)?;
} }
TypeBlock | GlobalTag | PrivateTag | RecordField => { /* nothing yet */ } TypeBlock | GlobalTag | RecordField => { /* nothing yet */ }
} }
self.style_stack.push(*annotation); self.style_stack.push(*annotation);
Ok(()) Ok(())
@ -1041,7 +1024,7 @@ where
self.write_str(self.palette.reset)?; self.write_str(self.palette.reset)?;
} }
TypeBlock | GlobalTag | PrivateTag | Opaque | RecordField => { /* nothing yet */ } TypeBlock | GlobalTag | Opaque | RecordField => { /* nothing yet */ }
}, },
} }
Ok(()) Ok(())