Skip to content

Refinement #266

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

Merged
merged 2 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion corpus/types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def cloneAndReset(obj: Cloneable with Resetable): Cloneable = {

class F extends Cloneable with Resetable with Serializable {}

type G = H[A1] {
def foo[A2 <: Stepper[_]]: A2
}

--------------------------------------------------------------------------------

(compilation_unit
Expand All @@ -213,7 +217,25 @@ class F extends Cloneable with Resetable with Serializable {}
(type_identifier)
(type_identifier)
(type_identifier))
(template_body)))
(template_body))
(type_definition
(type_identifier)
(compound_type
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))
(refinement
(function_declaration
(identifier)
(type_parameters
(identifier)
(upper_bound
(generic_type
(type_identifier)
(type_arguments
(wildcard)))))
(type_identifier))))))

================================================================================
Infix types
Expand Down
28 changes: 21 additions & 7 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,14 +682,14 @@ module.exports = grammar({
* DefParam ::= {Annotation} [‘inline’] Param
* Param ::= id ‘:’ ParamType [‘=’ Expr]
*/
parameter: $ => seq(
parameter: $ => prec.left(PREC.control, seq(
repeat($.annotation),
optional($.inline_modifier),
field('name', $._identifier),
':',
field('type', $._param_type),
optional(seq('=', field('default_value', $.expression)))
),
)),

_block: $ => prec.left(seq(
sep1($._semicolon, choice(
Expand Down Expand Up @@ -760,11 +760,25 @@ module.exports = grammar({
$.wildcard,
),

compound_type: $ => prec(PREC.compound, seq(
field('base', $._annotated_type),
repeat1(seq('with', field('extra', $._annotated_type))),
// TODO: Refinement.
)),
compound_type: $ => choice(
prec.left(PREC.compound, seq(
field('base', $._annotated_type),
repeat1(seq('with', field('extra', $._annotated_type))),
)),
prec.left(-1, seq(
field('base', $._annotated_type),
$._refinement,
)),
prec.left(-1, seq(
prec.left(PREC.compound, seq(
field('base', $._annotated_type),
repeat1(seq('with', field('extra', $._annotated_type))),
)),
$._refinement,
)),
),

_refinement: $ => alias($.template_body, $.refinement),

// This does not include _simple_type since _annotated_type covers it.
_infix_type_choice: $ => prec.left(PREC.infix, choice(
Expand Down
4 changes: 2 additions & 2 deletions script/smoke_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# This is an integration test to generally check the quality of parsing.

SCALA_SCALA_LIBRARY_EXPECTED=95
SCALA_SCALA_COMPILER_EXPECTED=84
SCALA_SCALA_COMPILER_EXPECTED=87
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scala 2 compiler bumps to 87% with this change.

DOTTY_COMPILER_EXPECTED=81
SYNTAX_COMPLEXITY_CEILING=2300
SYNTAX_COMPLEXITY_CEILING=2800
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an idea of how much is too much here? Like when should it cause refactoring to account for the bump?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess when we observe compilation time or memory usage to degrade?


if [ ! -d "$SCALA_SCALA_DIR" ]; then
echo "\$SCALA_SCALA_DIR must be set"
Expand Down