this repo has no description

Deprecation message

+117 -67
+5 -5
compiler-core/build.rs
··· 1 1 fn main() { 2 - capnpc::CompilerCommand::new() 3 - .file("schema.capnp") 4 - .output_path("generated/") 5 - .run() 6 - .expect("compiling schema.capnp"); 2 + // capnpc::CompilerCommand::new() 3 + // .file("schema.capnp") 4 + // .output_path("generated/") 5 + // .run() 6 + // .expect("compiling schema.capnp"); 7 7 }
+19 -7
compiler-core/generated/schema_capnp.rs
··· 2052 2052 self.reader.get_bool_field(0) 2053 2053 } 2054 2054 #[inline] 2055 - pub fn get_deprecated(self) -> bool { 2056 - self.reader.get_bool_field(1) 2055 + pub fn get_deprecated(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { 2056 + ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(2), ::core::option::Option::None) 2057 + } 2058 + #[inline] 2059 + pub fn has_deprecated(&self) -> bool { 2060 + !self.reader.get_pointer_field(2).is_null() 2057 2061 } 2058 2062 } 2059 2063 ··· 2146 2150 self.builder.set_bool_field(0, value); 2147 2151 } 2148 2152 #[inline] 2149 - pub fn get_deprecated(self) -> bool { 2150 - self.builder.get_bool_field(1) 2153 + pub fn get_deprecated(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { 2154 + ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(2), ::core::option::Option::None) 2151 2155 } 2152 2156 #[inline] 2153 - pub fn set_deprecated(&mut self, value: bool) { 2154 - self.builder.set_bool_field(1, value); 2157 + pub fn set_deprecated(&mut self, value: ::capnp::text::Reader<'_>) { 2158 + self.builder.get_pointer_field(2).set_text(value); 2159 + } 2160 + #[inline] 2161 + pub fn init_deprecated(self, size: u32) -> ::capnp::text::Builder<'a> { 2162 + self.builder.get_pointer_field(2).init_text(size) 2163 + } 2164 + #[inline] 2165 + pub fn has_deprecated(&self) -> bool { 2166 + !self.builder.get_pointer_field(2).is_null() 2155 2167 } 2156 2168 } 2157 2169 ··· 2171 2183 } 2172 2184 mod _private { 2173 2185 use capnp::private::layout; 2174 - pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 1, pointers: 2 }; 2186 + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { data: 1, pointers: 3 }; 2175 2187 pub const TYPE_ID: u64 = 0xd4c6_d8f1_a8fb_051c; 2176 2188 } 2177 2189 }
+1 -1
compiler-core/schema.capnp
··· 76 76 type @0 :Type; 77 77 variant @1 :ValueConstructorVariant; 78 78 public @2 :Bool; 79 - deprecated @3 :Bool; 79 + deprecated @3 :Text; 80 80 } 81 81 82 82 struct ValueConstructorVariant {
+20 -13
compiler-core/src/analyse.rs
··· 3 3 4 4 use crate::ast::{UntypedArg, UntypedStatement}; 5 5 use crate::type_::error::MissingAnnotation; 6 + use crate::type_::Deprecation; 6 7 use crate::{ 7 8 ast::{ 8 9 self, BitStringSegmentOption, CustomType, Definition, DefinitionLocation, Function, ··· 286 287 value.variant.clone(), 287 288 value.type_.clone(), 288 289 true, 289 - false, 290 + Deprecation::NotDeprecated, 290 291 ); 291 292 variant = Some(&value.variant); 292 293 value_imported = true; ··· 538 539 environment.insert_module_value( 539 540 constructor.name.clone(), 540 541 ValueConstructor { 541 - deprecated: false, 542 + deprecation: Deprecation::NotDeprecated, 542 543 public: *public && !opaque, 543 544 type_: typ.clone(), 544 545 variant: constructor_info.clone(), ··· 558 559 constructor_info, 559 560 typ, 560 561 *public, 561 - false, 562 + Deprecation::NotDeprecated, 562 563 ); 563 564 } 564 565 Ok(()) ··· 580 581 documentation, 581 582 external_erlang, 582 583 external_javascript, 583 - deprecated, 584 + deprecation, 584 585 end_position: _, 585 586 body: _, 586 587 return_type: _, ··· 618 619 arity: args.len(), 619 620 location: *location, 620 621 }; 621 - environment.insert_variable(name.clone(), variant, typ, *public, *deprecated); 622 + environment.insert_variable(name.clone(), variant, typ, *public, deprecation.clone()); 622 623 if !public { 623 624 environment.init_usage(name.clone(), EntityKind::PrivateFunction, *location); 624 625 }; ··· 672 673 body, 673 674 return_annotation, 674 675 end_position: end_location, 675 - deprecated, 676 + deprecation, 676 677 external_erlang, 677 678 external_javascript, 678 679 return_type: (), ··· 733 734 arity: args.len(), 734 735 location, 735 736 }; 736 - environment.insert_variable(name.clone(), variant, type_.clone(), public, deprecated); 737 + environment.insert_variable( 738 + name.clone(), 739 + variant, 740 + type_.clone(), 741 + public, 742 + deprecation.clone(), 743 + ); 737 744 738 745 Ok(Definition::Function(Function { 739 746 documentation: doc, 740 747 location, 741 748 name, 742 749 public, 743 - deprecated, 750 + deprecation, 744 751 arguments: args, 745 752 end_position: end_location, 746 753 return_annotation, ··· 997 1004 let type_ = typed_expr.type_(); 998 1005 let variant = ValueConstructor { 999 1006 public, 1000 - deprecated: false, 1007 + deprecation: Deprecation::NotDeprecated, 1001 1008 variant: ValueConstructorVariant::ModuleConstant { 1002 1009 documentation: doc.clone(), 1003 1010 location, ··· 1012 1019 variant.variant.clone(), 1013 1020 type_.clone(), 1014 1021 public, 1015 - false, 1022 + Deprecation::NotDeprecated, 1016 1023 ); 1017 1024 environment.insert_module_value(name.clone(), variant); 1018 1025 ··· 1124 1131 location, 1125 1132 name, 1126 1133 public, 1127 - deprecated, 1134 + deprecation, 1128 1135 arguments: args, 1129 1136 body, 1130 1137 return_annotation, ··· 1151 1158 name.clone(), 1152 1159 ValueConstructor { 1153 1160 public, 1154 - deprecated, 1161 + deprecation: deprecation.clone(), 1155 1162 type_: typ, 1156 1163 variant: ValueConstructorVariant::ModuleFn { 1157 1164 documentation: doc.clone(), ··· 1169 1176 location, 1170 1177 name, 1171 1178 public, 1172 - deprecated, 1179 + deprecation, 1173 1180 arguments: args, 1174 1181 end_position: end_location, 1175 1182 return_annotation,
+4 -2
compiler-core/src/ast.rs
··· 12 12 13 13 use crate::analyse::Inferred; 14 14 use crate::build::{Located, Target}; 15 - use crate::type_::{self, ModuleValueConstructor, PatternConstructor, Type, ValueConstructor}; 15 + use crate::type_::{ 16 + self, Deprecation, ModuleValueConstructor, PatternConstructor, Type, ValueConstructor, 17 + }; 16 18 use std::sync::Arc; 17 19 18 20 #[cfg(test)] ··· 343 345 pub arguments: Vec<Arg<T>>, 344 346 pub body: Vec1<Statement<T, Expr>>, 345 347 pub public: bool, 346 - pub deprecated: bool, 348 + pub deprecation: Deprecation, 347 349 pub return_annotation: Option<TypeAst>, 348 350 pub return_type: T, 349 351 pub documentation: Option<SmolStr>,
+4 -4
compiler-core/src/ast/tests.rs
··· 1 1 use std::sync::Arc; 2 2 3 3 use crate::build::Target; 4 - use crate::type_::PRELUDE_MODULE_NAME; 4 + use crate::type_::{Deprecation, PRELUDE_MODULE_NAME}; 5 5 use crate::{ 6 6 ast::{SrcSpan, TypedExpr}, 7 7 build::Located, ··· 85 85 variant, 86 86 type_::fn_(vec![type_::string(), type_::int()], cat_type.clone()), 87 87 true, 88 - false, 88 + Deprecation::NotDeprecated, 89 89 ); 90 90 91 91 environment.insert_accessors( ··· 182 182 let var = TypedExpr::Var { 183 183 location: SrcSpan { start: 16, end: 22 }, 184 184 constructor: ValueConstructor { 185 - deprecated: false, 185 + deprecation: Deprecation::NotDeprecated, 186 186 public: false, 187 187 variant: ValueConstructorVariant::LocalVariable { 188 188 location: SrcSpan { start: 5, end: 11 }, ··· 467 467 let bool = TypedExpr::Var { 468 468 location: SrcSpan { start: 1, end: 5 }, 469 469 constructor: ValueConstructor { 470 - deprecated: false, 470 + deprecation: Deprecation::NotDeprecated, 471 471 public: true, 472 472 variant: ValueConstructorVariant::Record { 473 473 documentation: None,
+5 -2
compiler-core/src/call_graph/into_dependency_order_tests.rs
··· 1 1 use super::*; 2 - use crate::ast::{Arg, Function}; 2 + use crate::{ 3 + ast::{Arg, Function}, 4 + type_::Deprecation, 5 + }; 3 6 use smol_str::SmolStr; 4 7 5 8 type Input = (&'static str, &'static [&'static str], &'static str); ··· 22 25 location: Default::default(), 23 26 return_annotation: None, 24 27 public: true, 25 - deprecated: false, 28 + deprecation: Deprecation::NotDeprecated, 26 29 end_position: src.len() as u32, 27 30 return_type: (), 28 31 documentation: None,
+9 -4
compiler-core/src/metadata/module_decoder.rs
··· 11 11 build::Origin, 12 12 schema_capnp::{self as schema, *}, 13 13 type_::{ 14 - self, AccessorsMap, FieldMap, ModuleInterface, RecordAccessor, Type, TypeConstructor, 15 - ValueConstructor, ValueConstructorVariant, 14 + self, AccessorsMap, Deprecation, FieldMap, ModuleInterface, RecordAccessor, Type, 15 + TypeConstructor, ValueConstructor, ValueConstructorVariant, 16 16 }, 17 17 uid::UniqueIdGenerator, 18 18 Result, ··· 149 149 let type_ = self.type_(&reader.get_type()?)?; 150 150 let variant = self.value_constructor_variant(&reader.get_variant()?)?; 151 151 let public = reader.get_public(); 152 - let deprecated = reader.get_deprecated(); 152 + let deprecation = match reader.get_deprecated()? { 153 + "" => Deprecation::NotDeprecated, 154 + message => Deprecation::Deprecated { 155 + message: message.into(), 156 + }, 157 + }; 153 158 Ok(ValueConstructor { 154 - deprecated, 159 + deprecation, 155 160 public, 156 161 type_, 157 162 variant,
+5 -2
compiler-core/src/metadata/module_encoder.rs
··· 7 7 }, 8 8 schema_capnp::{self as schema, *}, 9 9 type_::{ 10 - self, AccessorsMap, FieldMap, RecordAccessor, Type, TypeConstructor, TypeVar, 10 + self, AccessorsMap, Deprecation, FieldMap, RecordAccessor, Type, TypeConstructor, TypeVar, 11 11 ValueConstructor, ValueConstructorVariant, 12 12 }, 13 13 }; ··· 152 152 constructor: &ValueConstructor, 153 153 ) { 154 154 builder.set_public(constructor.public); 155 - builder.set_deprecated(constructor.deprecated); 155 + builder.set_deprecated(match &constructor.deprecation { 156 + Deprecation::NotDeprecated => "", 157 + Deprecation::Deprecated { message } => message, 158 + }); 156 159 self.build_type(builder.reborrow().init_type(), &constructor.type_); 157 160 self.build_value_constructor_variant(builder.init_variant(), &constructor.variant); 158 161 }
+15 -12
compiler-core/src/metadata/tests.rs
··· 9 9 }, 10 10 build::Origin, 11 11 type_::{ 12 - self, ModuleInterface, Type, TypeConstructor, ValueConstructor, ValueConstructorVariant, 12 + self, Deprecation, ModuleInterface, Type, TypeConstructor, ValueConstructor, 13 + ValueConstructorVariant, 13 14 }, 14 15 uid::UniqueIdGenerator, 15 16 }; ··· 37 38 "one".into(), 38 39 ValueConstructor { 39 40 public: true, 40 - deprecated: false, 41 + deprecation: Deprecation::NotDeprecated, 41 42 type_: type_::int(), 42 43 variant: ValueConstructorVariant::ModuleConstant { 43 44 documentation: Some("Some documentation".into()), ··· 268 269 "one".into(), 269 270 ValueConstructor { 270 271 public: true, 271 - deprecated: false, 272 + deprecation: Deprecation::NotDeprecated, 272 273 type_: type_::int(), 273 274 variant: ValueConstructorVariant::ModuleFn { 274 275 documentation: Some("wobble!".into()), ··· 301 302 "one".into(), 302 303 ValueConstructor { 303 304 public: true, 304 - deprecated: true, 305 + deprecation: Deprecation::Deprecated { 306 + message: "wibble wobble".into(), 307 + }, 305 308 type_: type_::int(), 306 309 variant: ValueConstructorVariant::ModuleFn { 307 310 documentation: Some("wobble!".into()), ··· 334 337 "one".into(), 335 338 ValueConstructor { 336 339 public: false, 337 - deprecated: false, 340 + deprecation: Deprecation::NotDeprecated, 338 341 type_: type_::int(), 339 342 variant: ValueConstructorVariant::ModuleFn { 340 343 documentation: Some("wobble!".into()), ··· 369 372 "one".into(), 370 373 ValueConstructor { 371 374 public: true, 372 - deprecated: false, 375 + deprecation: Deprecation::NotDeprecated, 373 376 type_: type_::int(), 374 377 variant: ValueConstructorVariant::ModuleFn { 375 378 documentation: Some("wabble!".into()), ··· 403 406 "one".into(), 404 407 ValueConstructor { 405 408 public: true, 406 - deprecated: false, 409 + deprecation: Deprecation::NotDeprecated, 407 410 type_: type_::int(), 408 411 variant: ValueConstructorVariant::ModuleFn { 409 412 documentation: Some("wubble!".into()), ··· 439 442 "one".into(), 440 443 ValueConstructor { 441 444 public: true, 442 - deprecated: false, 445 + deprecation: Deprecation::NotDeprecated, 443 446 type_: type_::int(), 444 447 variant: ValueConstructorVariant::Record { 445 448 documentation: Some("webble!".into()), ··· 476 479 "one".into(), 477 480 ValueConstructor { 478 481 public: true, 479 - deprecated: false, 482 + deprecation: Deprecation::NotDeprecated, 480 483 type_: type_::int(), 481 484 variant: ValueConstructorVariant::Record { 482 485 documentation: Some("wybble!".into()), ··· 694 697 typ: type_::int(), 695 698 constructor: Some(Box::from(ValueConstructor { 696 699 public: true, 697 - deprecated: false, 700 + deprecation: Deprecation::NotDeprecated, 698 701 type_: type_::int(), 699 702 variant: ValueConstructorVariant::ModuleConstant { 700 703 documentation: Some("some doc".into()), ··· 717 720 "one".into(), 718 721 ValueConstructor { 719 722 public: true, 720 - deprecated: false, 723 + deprecation: Deprecation::NotDeprecated, 721 724 type_: type_::int(), 722 725 variant: ValueConstructorVariant::ModuleConstant { 723 726 documentation: Some("some doc!!!!!!!!!".into()), ··· 731 734 "one_original".into(), 732 735 ValueConstructor { 733 736 public: true, 734 - deprecated: false, 737 + deprecation: Deprecation::NotDeprecated, 735 738 type_: type_::int(), 736 739 variant: ValueConstructorVariant::ModuleConstant { 737 740 documentation: Some("some doc yeah".into()),
+5 -3
compiler-core/src/parse.rs
··· 66 66 }; 67 67 use crate::build::Target; 68 68 use crate::parse::extra::ModuleExtra; 69 + use crate::type_::Deprecation; 69 70 use error::{LexicalError, ParseError, ParseErrorType}; 70 71 use lexer::{LexResult, Spanned}; 71 72 use smol_str::SmolStr; ··· 88 89 #[derive(Debug, Default)] 89 90 struct Attributes { 90 91 target: Option<Target>, 91 - deprecated: bool, 92 + deprecated: Deprecation, 92 93 external_erlang: Option<(SmolStr, SmolStr)>, 93 94 external_javascript: Option<(SmolStr, SmolStr)>, 94 95 } ··· 1437 1438 body, 1438 1439 return_type: (), 1439 1440 return_annotation, 1440 - deprecated: attributes.deprecated, 1441 + deprecation: std::mem::take(&mut attributes.deprecated), 1441 1442 external_erlang: attributes.external_erlang.take(), 1442 1443 external_javascript: attributes.external_javascript.take(), 1443 1444 }))) ··· 2738 2739 &mut self, 2739 2740 attributes: &mut Attributes, 2740 2741 ) -> Result<(), ParseError> { 2742 + let (_, message, _) = self.expect_string()?; 2741 2743 let (_, _) = self.expect_one(&Token::RightParen)?; 2742 - attributes.deprecated = true; 2744 + attributes.deprecated = Deprecation::Deprecated { message }; 2743 2745 Ok(()) 2744 2746 } 2745 2747 }
+13 -1
compiler-core/src/type_.rs
··· 621 621 #[derive(Debug, Clone, PartialEq, Eq)] 622 622 pub struct ValueConstructor { 623 623 pub public: bool, 624 - pub deprecated: bool, 624 + pub deprecation: Deprecation, 625 625 pub variant: ValueConstructorVariant, 626 626 pub type_: Arc<Type>, 627 + } 628 + 629 + #[derive(Debug, Clone, PartialEq, Eq)] 630 + pub enum Deprecation { 631 + NotDeprecated, 632 + Deprecated { message: SmolStr }, 633 + } 634 + 635 + impl Default for Deprecation { 636 + fn default() -> Self { 637 + Self::NotDeprecated 638 + } 627 639 } 628 640 629 641 impl ValueConstructor {
+3 -3
compiler-core/src/type_/environment.rs
··· 168 168 let _ = self.scope.insert( 169 169 name, 170 170 ValueConstructor { 171 - deprecated: false, 171 + deprecation: Deprecation::NotDeprecated, 172 172 public: false, 173 173 variant: ValueConstructorVariant::LocalVariable { location }, 174 174 type_: typ, ··· 184 184 variant: ValueConstructorVariant, 185 185 typ: Arc<Type>, 186 186 public: bool, 187 - deprecated: bool, 187 + deprecation: Deprecation, 188 188 ) { 189 189 let _ = self.scope.insert( 190 190 name, 191 191 ValueConstructor { 192 192 public, 193 - deprecated, 193 + deprecation, 194 194 variant, 195 195 type_: typ, 196 196 },
+2 -2
compiler-core/src/type_/expression.rs
··· 1605 1605 public, 1606 1606 variant, 1607 1607 type_: typ, 1608 - deprecated, 1608 + deprecation: deprecated, 1609 1609 } = constructor; 1610 1610 1611 1611 // Instantiate generic variables into unbound variables for this usage 1612 1612 let typ = self.instantiate(typ, &mut hashmap![]); 1613 1613 Ok(ValueConstructor { 1614 1614 public, 1615 - deprecated, 1615 + deprecation: deprecated, 1616 1616 variant, 1617 1617 type_: typ, 1618 1618 })
+1 -1
compiler-core/src/type_/pipe.rs
··· 134 134 name: PIPE_VARIABLE.into(), 135 135 constructor: ValueConstructor { 136 136 public: true, 137 - deprecated: false, 137 + deprecation: Deprecation::NotDeprecated, 138 138 type_: self.argument_type.clone(), 139 139 variant: ValueConstructorVariant::LocalVariable { 140 140 location: self.argument_location,
+3 -2
compiler-core/src/type_/prelude.rs
··· 3 3 use crate::{ast::SrcSpan, build::Origin, uid::UniqueIdGenerator}; 4 4 5 5 use super::{ 6 - ModuleInterface, Type, TypeConstructor, TypeVar, ValueConstructor, ValueConstructorVariant, 6 + Deprecation, ModuleInterface, Type, TypeConstructor, TypeVar, ValueConstructor, 7 + ValueConstructorVariant, 7 8 }; 8 9 use std::{cell::RefCell, collections::HashMap, sync::Arc}; 9 10 ··· 163 164 pub fn build_prelude(ids: &UniqueIdGenerator) -> ModuleInterface { 164 165 let value = |variant, type_| ValueConstructor { 165 166 public: true, 166 - deprecated: false, 167 + deprecation: Deprecation::NotDeprecated, 167 168 variant, 168 169 type_, 169 170 };
+3 -3
compiler-core/src/type_/tests/functions.rs
··· 144 144 #[test] 145 145 fn deprecated_function() { 146 146 assert_module_infer!( 147 - " 148 - @deprecated() 147 + r#" 148 + @deprecated("use wibble instead") 149 149 pub fn main() { 150 150 Nil 151 - }", 151 + }"#, 152 152 vec![(r#"main"#, r#"fn() -> Nil"#)] 153 153 ); 154 154 }