-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UPW[WIP]: faster, lightweight, more flexible and concisely implemented pattern matching #83
Conversation
…de) & Sugars module(Q, And, Or) & LambdaCases & pattern_compile->pattern_uncall & add pattern_unref
add |
uncomprehension patterns |
* support 'MLStyle.Modules.*' * all tests passing - add '@testcase' macro and '@lift' marker in "runtests.jl". works perfectly for our cases. * restore MLStyle.Render but deprecate it * no need of 'MLStyle.Modules.AST.Compat' as now our pattern totally can somehow understand the scope info. * fix duplicate @Label issues in when patterns('@when' from 'MLStyle.StandardPatterns.WhenCases'): - add 'CFGItem' and 'CFGSpec' types to MLStyle.AbstractPattern. - use CFGJump(CFGJump(:x) = CFGItem(:symbolicgoto, :x)) and CFGLabel(works the same way as CFGJump) - 'MLStyle.AbstractPattern.init_cfg': every time, when using generator functions from MLStyle APIs, such as 'gen_match', 'gen_switch', you should invoke 'MLStyle.AbstractPattern.init_cfg' before splicing it into your code. * record matching: support 4 kinds of matching for records: 1. positional: S(a, b, c) 2. field punning: S(; a, b=b_, c=c_), 'a, b, c' are names, 'b_, c_' are patterns 3. wildcard constructor: S(_), if type of S matches. for compatibility, and consistency with active patterns 4. just type check(same as 3): S() * active pattern clarification: - S() : if '@Active S(x)' returns true, otherwise(fail) returns false - S(v) : if '@Active S(x)' returns Some(v), otherwise(fail) returns nothing - S(a, b): more than 2 arguments, '@Active S(x)' returns a tuple * fix some typos in documentations(cuture->cultural, etc)
Codecov Report
@@ Coverage Diff @@
## master #83 +/- ##
==========================================
+ Coverage 78.57% 85.57% +7.00%
==========================================
Files 20 31 +11
Lines 658 1442 +784
==========================================
+ Hits 517 1234 +717
- Misses 141 208 +67
Continue to review full report at Codecov.
|
I'd merge it to master to show the dev status. |
generating more stably typed code, hence sometimes can be ~x2 faster than the the previous
MLStyle as a dev-only dep
Expr
to julia code library?)more intuitive pattern objects(top-level first-class patterns)
pattern_compile(::Type{P}, self::Function, type_params, type_args, args)
pattern_uncall(::Type{P}, self::Function, type_params, type_args, args)
Defining
pattern_compile
pattern_uncall
for typeP
will control the code generation when P is used as a pattern.self
is given by our compiler, andself(::Expr)
will return a pattern.Within the following code, pattern syntax
(a, b, c)
will be equivalent toMyTuplePat(a, b, c)
.is_enum
In the following code, pattern
S
is equivalent toS()
:Above designs deprecate some redundant/non-intuitive things, e.g., MLStyle Extension List
new features
- [x] according to real world practice, things like
@switch
can be productive:Breakage&Deprecation
Before merging this, we shall make sure all of the downstream uses of MLStyle are concerned and well compatible. If not, workaround PRs should be created for fixing the corresponding issues.
Most stuffs can be compatible, except the following ones need attentions:
def_pattern
,def_app_pattern
, etc., will be removed.@data public
,@data internal
, etc., will be deprecated as they now just do nothing.The new visibility is the same as julia scopes, i.e, an object implements
pattern_compile
is visible in current module, you can use it as a pattern when matching.@active
macro. Using@active
to define view patterns will be deprecated, and note that the view patterns defined by@active
cannot be statically generated, i.e., if you use@active
, you cannot use MLStyle as a dev-only dependency.